<s> """<STR_LIT>""" <EOL> import numpy <EOL> from collada . common import DaeObject , E , tag <EOL> from collada . common import DaeIncompleteError , DaeBrokenRefError , DaeMalformedError <EOL> from collada . xmlutil import etree as ElementTree <EOL> class Camera ( DaeObject ) : <EOL> """<STR_LIT>""" <EOL> @ staticmethod <EOL> def load ( collada , localscope , node ) : <EOL> tecnode = node . find ( '<STR_LIT>' % ( tag ( '<STR_LIT>' ) , tag ( '<STR_LIT>' ) ) ) <EOL> if tecnode is None or len ( tecnode ) == <NUM_LIT:0> : <EOL> raise DaeIncompleteError ( '<STR_LIT>' ) <EOL> camnode = tecnode [ <NUM_LIT:0> ] <EOL> if camnode . tag == tag ( '<STR_LIT>' ) : <EOL> return PerspectiveCamera . load ( collada , localscope , node ) <EOL> elif camnode . tag == tag ( '<STR_LIT>' ) : <EOL> return OrthographicCamera . load ( collada , localscope , node ) <EOL> else : <EOL> raise DaeUnsupportedError ( '<STR_LIT>' % camnode . tag ) <EOL> class PerspectiveCamera ( Camera ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , id , znear , zfar , xfov = None , yfov = None , <EOL> aspect_ratio = None , xmlnode = None ) : <EOL> """<STR_LIT>""" <EOL> self . id = id <EOL> """<STR_LIT>""" <EOL> self . xfov = xfov <EOL> """<STR_LIT>""" <EOL> self . yfov = yfov <EOL> """<STR_LIT>""" <EOL> self . aspect_ratio = aspect_ratio <EOL> """<STR_LIT>""" <EOL> self . znear = znear <EOL> """<STR_LIT>""" <EOL> self . zfar = zfar <EOL> """<STR_LIT>""" <EOL> self . _checkValidParams ( ) <EOL> if xmlnode is not None : <EOL> self . xmlnode = xmlnode <EOL> """<STR_LIT>""" <EOL> else : <EOL> self . _recreateXmlNode ( ) <EOL> def _recreateXmlNode ( self ) : <EOL> perspective_node = E . perspective ( ) <EOL> if self . xfov is not None : <EOL> perspective_node . append ( E . xfov ( str ( self . xfov ) ) ) <EOL> if self . yfov is not None : <EOL> perspective_node . append ( E . yfov ( str ( self . yfov ) ) ) <EOL> if self . aspect_ratio is not None : <EOL> perspective_node . append ( E . aspect_ratio ( str ( self . aspect_ratio ) ) ) <EOL> perspective_node . append ( E . znear ( str ( self . znear ) ) ) <EOL> perspective_node . append ( E . zfar ( str ( self . zfar ) ) ) <EOL> self . xmlnode = E . camera ( <EOL> E . optics ( <EOL> E . technique_common ( perspective_node ) <EOL> ) <EOL> , id = self . id , name = self . id ) <EOL> def _checkValidParams ( self ) : <EOL> if self . xfov is not None and self . yfov is None and self . aspect_ratio is None : <EOL> pass <EOL> elif self . xfov is None and self . yfov is not None and self . aspect_ratio is None : <EOL> pass <EOL> elif self . xfov is not None and self . yfov is None and self . aspect_ratio is not None : <EOL> pass <EOL> elif self . xfov is None and self . yfov is not None and self . aspect_ratio is not None : <EOL> pass <EOL> elif self . xfov is not None and self . yfov is not None and self . aspect_ratio is None : <EOL> pass <EOL> else : <EOL> raise DaeMalformedError ( "<STR_LIT>" % <EOL> ( str ( self . xfov ) , str ( self . yfov ) , str ( self . aspect_ratio ) ) ) <EOL> def save ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _checkValidParams ( ) <EOL> self . _recreateXmlNode ( ) <EOL> @ staticmethod <EOL> def load ( collada , localscope , node ) : <EOL> persnode = node . find ( '<STR_LIT>' % ( tag ( '<STR_LIT>' ) , tag ( '<STR_LIT>' ) , <EOL> tag ( '<STR_LIT>' ) ) ) <EOL> if persnode is None : <EOL> raise DaeIncompleteError ( '<STR_LIT>' ) <EOL> xfov = persnode . find ( tag ( '<STR_LIT>' ) ) <EOL> yfov = persnode . find ( tag ( '<STR_LIT>' ) ) <EOL> aspect_ratio = persnode . find ( tag ( '<STR_LIT>' ) ) <EOL> znearnode = persnode . find ( tag ( '<STR_LIT>' ) ) <EOL> zfarnode = persnode . find ( tag ( '<STR_LIT>' ) ) <EOL> id = node . get ( '<STR_LIT:id>' , '<STR_LIT>' ) <EOL> try : <EOL> if xfov is not None : <EOL> xfov = float ( xfov . text ) <EOL> if yfov is not None : <EOL> yfov = float ( yfov . text ) <EOL> if aspect_ratio is not None : <EOL> aspect_ratio = float ( aspect_ratio . text ) <EOL> znear = float ( znearnode . text ) <EOL> zfar = float ( zfarnode . text ) <EOL> except ( TypeError , ValueError ) as ex : <EOL> raise DaeMalformedError ( '<STR_LIT>' ) <EOL> if xfov is not None and yfov is not None and aspect_ratio is not None : <EOL> aspect_ratio = None <EOL> return PerspectiveCamera ( id , znear , zfar , xfov = xfov , yfov = yfov , <EOL> aspect_ratio = aspect_ratio , xmlnode = node ) <EOL> def bind ( self , matrix ) : <EOL> """<STR_LIT>""" <EOL> return BoundPerspectiveCamera ( self , matrix ) <EOL> def __str__ ( self ) : return '<STR_LIT>' % self . id <EOL> def __repr__ ( self ) : return str ( self ) <EOL> class OrthographicCamera ( Camera ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , id , znear , zfar , xmag = None , ymag = None , aspect_ratio = None , xmlnode = None ) : <EOL> """<STR_LIT>""" <EOL> self . id = id <EOL> """<STR_LIT>""" <EOL> self . xmag = xmag <EOL> """<STR_LIT>""" <EOL> self . ymag = ymag <EOL> """<STR_LIT>""" <EOL> self . aspect_ratio = aspect_ratio <EOL> """<STR_LIT>""" <EOL> self . znear = znear <EOL> """<STR_LIT>""" <EOL> self . zfar = zfar <EOL> """<STR_LIT>""" <EOL> self . _checkValidParams ( ) <EOL> if xmlnode is not None : <EOL> self . xmlnode = xmlnode <EOL> """<STR_LIT>""" <EOL> else : <EOL> self . _recreateXmlNode ( ) <EOL> def _recreateXmlNode ( self ) : <EOL> orthographic_node = E . orthographic ( ) <EOL> if self . xmag is not None : <EOL> orthographic_node . append ( E . xmag ( str ( self . xmag ) ) ) <EOL> if self . ymag is not None : <EOL> orthographic_node . append ( E . ymag ( str ( self . ymag ) ) ) <EOL> if self . aspect_ratio is not None : <EOL> orthographic_node . append ( E . aspect_ratio ( str ( self . aspect_ratio ) ) ) <EOL> orthographic_node . append ( E . znear ( str ( self . znear ) ) ) <EOL> orthographic_node . append ( E . zfar ( str ( self . zfar ) ) ) <EOL> self . xmlnode = E . camera ( <EOL> E . optics ( <EOL> E . technique_common ( orthographic_node ) <EOL> ) <EOL> , id = self . id , name = self . id ) <EOL> def _checkValidParams ( self ) : <EOL> if self . xmag is not None and self . ymag is None and self . aspect_ratio is None : <EOL> pass <EOL> elif self . xmag is None and self . ymag is not None and self . aspect_ratio is None : <EOL> pass <EOL> elif self . xmag is not None and self . ymag is None and self . aspect_ratio is not None : <EOL> pass <EOL> elif self . xmag is None and self . ymag is not None and self . aspect_ratio is not None : <EOL> pass <EOL> elif self . xmag is not None and self . ymag is not None and self . aspect_ratio is None : <EOL> pass <EOL> else : <EOL> raise DaeMalformedError ( "<STR_LIT>" % <EOL> ( str ( self . xmag ) , str ( self . ymag ) , str ( self . aspect_ratio ) ) ) <EOL> def save ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _checkValidParams ( ) <EOL> self . _recreateXmlNode ( ) <EOL> @ staticmethod <EOL> def load ( collada , localscope , node ) : <EOL> orthonode = node . find ( '<STR_LIT>' % ( <EOL> tag ( '<STR_LIT>' ) , <EOL> tag ( '<STR_LIT>' ) , <EOL> tag ( '<STR_LIT>' ) ) ) <EOL> if orthonode is None : raise DaeIncompleteError ( '<STR_LIT>' ) <EOL> xmag = orthonode . find ( tag ( '<STR_LIT>' ) ) <EOL> ymag = orthonode . find ( tag ( '<STR_LIT>' ) ) <EOL> aspect_ratio = orthonode . find ( tag ( '<STR_LIT>' ) ) <EOL> znearnode = orthonode . find ( tag ( '<STR_LIT>' ) ) <EOL> zfarnode = orthonode . find ( tag ( '<STR_LIT>' ) ) <EOL> id = node . get ( '<STR_LIT:id>' , '<STR_LIT>' ) <EOL> try : <EOL> if xmag is not None : <EOL> xmag = float ( xmag . text ) <EOL> if ymag is not None : <EOL> ymag = float ( ymag . text ) <EOL> if aspect_ratio is not None : <EOL> aspect_ratio = float ( aspect_ratio . text ) <EOL> znear = float ( znearnode . text ) <EOL> zfar = float ( zfarnode . text ) <EOL> except ( TypeError , ValueError ) as ex : <EOL> raise DaeMalformedError ( '<STR_LIT>' ) <EOL> if xmag is not None and ymag is not None and aspect_ratio is not None : <EOL> aspect_ratio = None <EOL> return OrthographicCamera ( id , znear , zfar , xmag = xmag , ymag = ymag , <EOL> aspect_ratio = aspect_ratio , xmlnode = node ) <EOL> def bind ( self , matrix ) : <EOL> """<STR_LIT>""" <EOL> return BoundOrthographicCamera ( self , matrix ) <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' % self . id <EOL> def __repr__ ( self ) : <EOL> return str ( self ) <EOL> class BoundCamera ( object ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class BoundPerspectiveCamera ( BoundCamera ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , cam , matrix ) : <EOL> self . xfov = cam . xfov <EOL> """<STR_LIT>""" <EOL> self . yfov = cam . yfov <EOL> """<STR_LIT>""" <EOL> self . aspect_ratio = cam . aspect_ratio <EOL> """<STR_LIT>""" <EOL> self . znear = cam . znear <EOL> """<STR_LIT>""" <EOL> self . zfar = cam . zfar <EOL> """<STR_LIT>""" <EOL> self . matrix = matrix <EOL> """<STR_LIT>""" <EOL> self . position = matrix [ : <NUM_LIT:3> , <NUM_LIT:3> ] <EOL> """<STR_LIT>""" <EOL> self . direction = - matrix [ : <NUM_LIT:3> , <NUM_LIT:2> ] <EOL> """<STR_LIT>""" <EOL> self . up = matrix [ : <NUM_LIT:3> , <NUM_LIT:1> ] <EOL> """<STR_LIT>""" <EOL> self . original = cam <EOL> """<STR_LIT>""" <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' % self . original . id <EOL> def __repr__ ( self ) : <EOL> return str ( self ) <EOL> class BoundOrthographicCamera ( BoundCamera ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , cam , matrix ) : <EOL> self . xmag = cam . xmag <EOL> """<STR_LIT>""" <EOL> self . ymag = cam . ymag <EOL> """<STR_LIT>""" <EOL> self . aspect_ratio = cam . aspect_ratio <EOL> """<STR_LIT>""" <EOL> self . znear = cam . znear <EOL> """<STR_LIT>""" <EOL> self . zfar = cam . zfar <EOL> """<STR_LIT>""" <EOL> self . matrix = matrix <EOL> """<STR_LIT>""" <EOL> self . position = matrix [ : <NUM_LIT:3> , <NUM_LIT:3> ] <EOL> """<STR_LIT>""" <EOL> self . direction = - matrix [ : <NUM_LIT:3> , <NUM_LIT:2> ] <EOL> """<STR_LIT>""" <EOL> self . up = matrix [ : <NUM_LIT:3> , <NUM_LIT:1> ] <EOL> """<STR_LIT>""" <EOL> self . original = cam <EOL> """<STR_LIT>""" <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' % self . original . id <EOL> def __repr__ ( self ) : <EOL> return str ( self ) </s>
