def __init__(self, id, color, xmlnode = None): """Create a new directional light. :param str id: A unique string identifier for the light :param tuple color: Either a tuple of size 3 containing the RGB color value of the light or a tuple of size 4 containing the RGBA color value of the light :param xmlnode: If loaded from xml, the xml node """ self.id = id """The unique string identifier for the light""" self.direction = numpy.array( [0, 0, -1], dtype=numpy.float32 ) #Not documenting this because it doesn't make sense to set the direction # of an unbound light. The direction isn't set until binding in a scene. self.color = color """Either a tuple of size 3 containing the RGB color value of the light or a tuple of size 4 containing the RGBA color value of the light""" if xmlnode != None: self.xmlnode = xmlnode """ElementTree representation of the light.""" else: self.xmlnode = E.light( E.technique_common( E.directional( E.color(' '.join(map(str, self.color))) ) ) , id=self.id, name=self.id)
def __init__(self, id, color, xmlnode=None): """Create a new sun light. :Parameters: id Id for the object color Light color xmlnode If load form xml, the xml node """ self.id = id """Id in the light library.""" # TODO: check if this is actually the initial direction self.direction = numpy.array([0, 0, 1], dtype=numpy.float32) """Incoming direction of the light.""" self.color = color """Light color.""" if xmlnode != None: self.xmlnode = xmlnode else: self.xmlnode = E.light( E.technique_common(E.directional(E.color(" ".join([str(v) for v in self.color])))), id=self.id, name=self.id, )
def __init__(self, id, color, xmlnode = None): """Create a new ambient light. :param str id: A unique string identifier for the light :param tuple color: Either a tuple of size 3 containing the RGB color value of the light or a tuple of size 4 containing the RGBA color value of the light :param xmlnode: If loaded from xml, the xml node """ self.id = id """The unique string identifier for the light""" self.color = color """Either a tuple of size 3 containing the RGB color value of the light or a tuple of size 4 containing the RGBA color value of the light""" if xmlnode != None: self.xmlnode = xmlnode """ElementTree representation of the light.""" else: self.xmlnode = E.light( E.technique_common( E.ambient( E.color(' '.join(map(str, self.color ) )) ) ) , id=self.id, name=self.id)
def save(self): """Saves the geometry node back to :attr:`xmlnode`""" self.xmlnode.set('url', "#%s" % self.geometry.id) for m in self.materials: m.save() matparent = self.xmlnode.find('%s/%s'%( tag('bind_material'), tag('technique_common') ) ) if matparent is None and len(self.materials)==0: return elif matparent is None: matparent = E.technique_common() self.xmlnode.append(E.bind_material(matparent)) elif len(self.materials) == 0 and matparent is not None: bindnode = self.xmlnode.find('%s' % tag('bind_material')) self.xmlnode.remove(bindnode) return for m in self.materials: if m.xmlnode not in matparent: matparent.append(m.xmlnode) xmlnodes = [m.xmlnode for m in self.materials] for n in matparent: if n not in xmlnodes: matparent.remove(n)
def __init__(self, geometry, materials=None, xmlnode=None): """Creates a geometry node :param collada.geometry.Geometry geometry: A geometry to instantiate in the scene :param list materials: A list containing items of type :class:`collada.scene.MaterialNode`. Each of these represents a material that the geometry should be bound to. :param xmlnode: When loaded, the xmlnode it comes from """ self.geometry = geometry """An object of type :class:`collada.geometry.Geometry` representing the geometry to bind in the scene""" self.materials = [] """A list containing items of type :class:`collada.scene.MaterialNode`. Each of these represents a material that the geometry is bound to.""" if materials is not None: self.materials = materials if xmlnode != None: self.xmlnode = xmlnode """ElementTree representation of the geometry node.""" else: self.xmlnode = E.instance_geometry(url="#%s" % self.geometry.id) if len(self.materials) > 0: self.xmlnode.append(E.bind_material( E.technique_common( *[mat.xmlnode for mat in self.materials] ) ))
def __init__(self, id, color, constant_att=None, linear_att=None, quad_att=None, zfar=None, xmlnode = None): """Create a new sun light. :param str id: A unique string identifier for the light :param tuple color: Either a tuple of size 3 containing the RGB color value of the light or a tuple of size 4 containing the RGBA color value of the light :param float constant_att: Constant attenuation factor :param float linear_att: Linear attenuation factor :param float quad_att: Quadratic attenuation factor :param float zfar: Distance to the far clipping plane :param xmlnode: If loaded from xml, the xml node """ self.id = id """The unique string identifier for the light""" self.position = numpy.array( [0, 0, 0], dtype=numpy.float32 ) #Not documenting this because it doesn't make sense to set the position # of an unbound light. The position isn't set until binding in a scene. self.color = color """Either a tuple of size 3 containing the RGB color value of the light or a tuple of size 4 containing the RGBA color value of the light""" self.constant_att = constant_att """Constant attenuation factor.""" self.linear_att = linear_att """Linear attenuation factor.""" self.quad_att = quad_att """Quadratic attenuation factor.""" self.zfar = zfar """Distance to the far clipping plane""" if xmlnode != None: self.xmlnode = xmlnode """ElementTree representation of the light.""" else: pnode = E.point( E.color(' '.join(map(str, self.color ) )) ) if self.constant_att is not None: pnode.append(E.constant_attenuation(str(self.constant_att))) if self.linear_att is not None: pnode.append(E.linear_attenuation(str(self.linear_att))) if self.quad_att is not None: pnode.append(E.quadratic_attenuation(str(self.quad_att))) if self.zfar is not None: pnode.append(E.zfar(str(self.zvar))) self.xmlnode = E.light( E.technique_common(pnode) , id=self.id, name=self.id)
def _recreateXmlNode(self): perspective_node = E.perspective() if self.xfov is not None: perspective_node.append(E.xfov(str(self.xfov))) if self.yfov is not None: perspective_node.append(E.yfov(str(self.yfov))) if self.aspect_ratio is not None: perspective_node.append(E.aspect_ratio(str(self.aspect_ratio))) perspective_node.append(E.znear(str(self.znear))) perspective_node.append(E.zfar(str(self.zfar))) self.xmlnode = E.camera( E.optics( E.technique_common(perspective_node) ) , id=self.id, name=self.id)
def _recreateXmlNode(self): orthographic_node = E.orthographic() if self.xmag is not None: orthographic_node.append(E.xmag(str(self.xmag))) if self.ymag is not None: orthographic_node.append(E.ymag(str(self.ymag))) if self.aspect_ratio is not None: orthographic_node.append(E.aspect_ratio(str(self.aspect_ratio))) orthographic_node.append(E.znear(str(self.znear))) orthographic_node.append(E.zfar(str(self.zfar))) self.xmlnode = E.camera( E.optics( E.technique_common(orthographic_node) ) , id=self.id, name=self.id)
def __init__(self, id, color, constant_att, linear_att, quad_att, xmlnode=None): """Create a new sun light. :Parameters: id Id for the object color Light color constant_att Constant attenuation factor linear_att Linear attenuation factor quad_att Quadratic attenuation factor xmlnode If load form xml, the xml node """ self.id = id """Id in the light library.""" self.position = numpy.array([0, 0, 0], dtype=numpy.float32) """Location of the light.""" self.color = color """Light color.""" self.constant_att = constant_att """Constant attenuation factor.""" self.linear_att = linear_att """Linear attenuation factor.""" self.quad_att = quad_att """Quadratic attenuation factor.""" if xmlnode != None: self.xmlnode = xmlnode else: self.xmlnode = E.light( E.technique_common( E.point( E.color(" ".join([str(v) for v in self.color])), E.constant_attenuation(str(self.constant_att)), E.linear_attenuation(str(self.linear_att)), E.quadratic_attenuation(str(self.quad_att)), ) ), id=self.id, name=self.id, )
def __init__(self, id, data, components, xmlnode=None): """Create a name source instance. :param str id: A unique string identifier for the source :param numpy.array data: Numpy array (unshaped) with the source values :param tuple components: Tuple of strings describing the semantic of the data, e.g. ``('JOINT')`` would cause :attr:`data` to be reshaped as ``(-1, 1)`` :param xmlnode: When loaded, the xmlnode it comes from. """ self.id = id """The unique string identifier for the source""" self.data = data """Numpy array with the source values. This will be shaped as ``(-1,N)`` where ``N = len(self.components)``""" self.data.shape = (-1, len(components) ) self.components = components """Tuple of strings describing the semantic of the data, e.g. ``('JOINT')``""" if xmlnode != None: self.xmlnode = xmlnode """ElementTree representation of the source.""" else: self.data.shape = (-1,) txtdata = ' '.join(map(str, self.data.tolist() )) rawlen = len( self.data ) self.data.shape = (-1, len(self.components) ) acclen = len( self.data ) stridelen = len(self.components) sourcename = "%s-array"%self.id self.xmlnode = E.source( E.Name_array(txtdata, count=str(rawlen), id=sourcename), E.technique_common( E.accessor( *[E.param(type='Name', name=c) for c in self.components] , **{'count':str(acclen), 'stride':str(stridelen), 'source':sourcename}) ) , id=self.id )
def __init__(self, id, fov, near, far, xmlnode = None): """Create a new camera. :Parameters: id Id for the object fov Y axis field of visiona in degrees near Near plane distance far Far plane distance xmlnode If load form xml, the xml node """ self.id = id """Id in the camera library.""" self.fov = fov """Field of vision in degrees.""" self.near = near """Near plane distance.""" self.far = far """Far plane distance.""" self.position = numpy.array( [0, 0, 0], dtype=numpy.float32 ) """Position in space of the point of view.""" self.direction = numpy.array( [0, 0, -1], dtype=numpy.float32 ) """Look direction of the camera.""" self.up = numpy.array( [0, 1, 0], dtype=numpy.float32 ) """Up vector of the camera.""" if xmlnode != None: self.xmlnode = xmlnode else: self.xmlnode = E.camera( E.optics( E.technique_common( E.perspective( E.yfov(str(self.fov)), E.znear(str(self.near)), E.zfar(str(self.far)) ) ) ) , id=self.id, name=self.id)
def __init__(self, id, color, xmlnode=None): """Create a new ambient light. :Parameters: id Id for the object color Light color xmlnode If load form xml, the xml node """ self.id = id """Id in the light library.""" self.color = color """Light color.""" if xmlnode != None: self.xmlnode = xmlnode else: self.xmlnode = E.light( E.technique_common(E.ambient(E.color(" ".join([str(v) for v in self.color])))), id=self.id, name=self.id )
def __init__(self, id, fov, near, far, xmlnode = None): """Create a new camera. :param str id: Id for the object :param float fov: Y axis field of vision in degrees :param float near: Near plane distance :param float far: Far plane distance :param xmlnode: If loaded from xml, the xml node """ self.id = id """Id in the camera library.""" self.fov = fov """Field of vision in degrees.""" self.near = near """Near plane distance.""" self.far = far """Far plane distance.""" if xmlnode != None: self.xmlnode = xmlnode """ElementTree representation of the data.""" else: self.xmlnode = E.camera( E.optics( E.technique_common( E.perspective( E.yfov(str(self.fov)), E.znear(str(self.near)), E.zfar(str(self.far)) ) ) ) , id=self.id, name=self.id)
def __init__( self, id, color, constant_att=None, linear_att=None, quad_att=None, falloff_ang=None, falloff_exp=None, xmlnode=None, ): """Create a new spot light. :param str id: A unique string identifier for the light :param tuple color: Either a tuple of size 3 containing the RGB color value of the light or a tuple of size 4 containing the RGBA color value of the light :param float constant_att: Constant attenuation factor :param float linear_att: Linear attenuation factor :param float quad_att: Quadratic attenuation factor :param float falloff_ang: Falloff angle :param float falloff_exp: Falloff exponent :param xmlnode: If loaded from xml, the xml node """ self.id = id """The unique string identifier for the light""" self.color = color """Either a tuple of size 3 containing the RGB color value of the light or a tuple of size 4 containing the RGBA color value of the light""" self.constant_att = constant_att """Constant attenuation factor.""" self.linear_att = linear_att """Linear attenuation factor.""" self.quad_att = quad_att """Quadratic attenuation factor.""" self.falloff_ang = falloff_ang """Falloff angle""" self.falloff_exp = falloff_exp """Falloff exponent""" if xmlnode != None: self.xmlnode = xmlnode """ElementTree representation of the light.""" else: pnode = E.spot(E.color(" ".join(map(str, self.color)))) if self.constant_att is not None: pnode.append(E.constant_attenuation(str(self.constant_att))) if self.linear_att is not None: pnode.append(E.linear_attenuation(str(self.linear_att))) if self.quad_att is not None: pnode.append(E.quadratic_attenuation(str(self.quad_att))) if self.falloff_ang is not None: pnode.append(E.falloff_angle(str(self.falloff_ang))) if self.falloff_exp is not None: pnode.append(E.falloff_exponent(str(self.falloff_exp))) self.xmlnode = E.light(E.technique_common(pnode), id=self.id, name=self.id)