예제 #1
0
파일: light.py 프로젝트: phaeta/pycollada
    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,
            )
예제 #2
0
    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)
예제 #3
0
    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)
예제 #4
0
    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)
예제 #5
0
 def getPropNode(prop, value):
     propnode = E(prop)
     if type(value) is Map:
         propnode.append(copy.deepcopy(value.xmlnode))
     elif type(value) is float:
         propnode.append(E.float(str(value)))
     else:
         propnode.append(E.color(' '.join(map(str, value) )))
     return propnode
예제 #6
0
파일: light.py 프로젝트: phaeta/pycollada
    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,
            )
예제 #7
0
파일: light.py 프로젝트: phaeta/pycollada
    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
            )
예제 #8
0
    def __init__(self, id, params, shadingtype, bumpmap = None, double_sided = False,
                       emission = (0.0, 0.0, 0.0, 1.0),
                       ambient = (0.0, 0.0, 0.0, 1.0),
                       diffuse = (0.0, 0.0, 0.0, 1.0),
                       specular = (0.0, 0.0, 0.0, 1.0),
                       shininess = 0.0,
                       reflective = (0.0, 0.0, 0.0, 1.0),
                       reflectivity = 0.0,
                       transparent = (0.0, 0.0, 0.0, 1.0),
                       transparency = 0.0,
                       index_of_refraction = None,
                       xmlnode = None):
        """Create an effect instance out of properties.

        :param str id:
          A string identifier for the effect
        :param list params:
          A list containing elements of type :class:`collada.material.Sampler2D`
          and :class:`collada.material.Surface`
        :param str shadingtype:
          The type of shader to be used for this effect. Right now, we
          only supper the shaders listed in :attr:`shaders`
        :param `collada.material.Map` bumpmap:
          The bump map for this effect, or None if there isn't one
        :param bool double_sided:
          Whether or not the material should be rendered double sided
        :param emission:
          Either an RGBA-format tuple of four floats or an instance
          of :class:`collada.material.Map`
        :param ambient:
          Either an RGBA-format tuple of four floats or an instance
          of :class:`collada.material.Map`
        :param diffuse:
          Either an RGBA-format tuple of four floats or an instance
          of :class:`collada.material.Map`
        :param specular:
          Either an RGBA-format tuple of four floats or an instance
          of :class:`collada.material.Map`
        :param shininess:
          Either a single float or an instance of :class:`collada.material.Map`
        :param reflective:
          Either an RGBA-format tuple of four floats or an instance
          of :class:`collada.material.Map`
        :param reflectivity:
          Either a single float or an instance of :class:`collada.material.Map`
        :param tuple transparent:
          Either an RGBA-format tuple of four floats or an instance
          of :class:`collada.material.Map`
        :param transparency:
          Either a single float or an instance of :class:`collada.material.Map`
        :param float index_of_refraction:
          A single float indicating the index of refraction for perfectly
          refracted light
        :param xmlnode:
          If loaded from xml, the xml node

        """
        self.id = id
        """The string identifier for the effect"""
        self.params = params
        """A list containing elements of type :class:`collada.material.Sampler2D`
          and :class:`collada.material.Surface`"""
        self.shadingtype = shadingtype
        """String with the type of the shading."""
        self.bumpmap = bumpmap
        """Either the bump map of the effect of type :class:`collada.material.Map`
        or None if there is none."""
        self.double_sided = double_sided
        """A boolean indicating whether or not the material should be rendered double sided"""
        self.emission = emission
        """Either an RGB-format tuple of three floats or an instance
          of :class:`collada.material.Map`"""
        self.ambient = ambient
        """Either an RGB-format tuple of three floats or an instance
          of :class:`collada.material.Map`"""
        self.diffuse = diffuse
        """Either an RGB-format tuple of three floats or an instance
          of :class:`collada.material.Map`"""
        self.specular = specular
        """Either an RGB-format tuple of three floats or an instance
          of :class:`collada.material.Map`"""
        self.shininess = shininess
        """Either a single float or an instance of :class:`collada.material.Map`"""
        self.reflective = reflective
        """Either an RGB-format tuple of three floats or an instance
          of :class:`collada.material.Map`"""
        self.reflectivity = reflectivity
        """Either a single float or an instance of :class:`collada.material.Map`"""
        self.transparent = transparent
        """Either an RGB-format tuple of three floats or an instance
          of :class:`collada.material.Map`"""
        self.transparency = transparency
        """Either a single float or an instance of :class:`collada.material.Map`"""
        self.index_of_refraction = index_of_refraction
        """A single float indicating the index of refraction for perfectly
          refracted light"""
        
        self._fixColorValues()
        
        if xmlnode is not None:
            self.xmlnode = xmlnode
            """ElementTree representation of the effect"""
        else:
            shadnode = E(self.shadingtype)
            
            for prop in self.supported:
                value = getattr(self, prop)
                if value is None: continue
                propnode = E(prop)
                shadnode.append( propnode )
                if type(value) is Map:
                    propnode.append(value.xmlnode)
                elif type(value) is float:
                    propnode.append(E.float(str(value)))
                else:
                    propnode.append(E.color(' '.join(map(str, value) )))
            
            effect_nodes = [param.xmlnode for param in self.params]
            effect_nodes.append(E.technique(shadnode, sid='common'))
            self.xmlnode = E.effect(
                E.profile_COMMON(*effect_nodes)
            , id=self.id, name=self.id)
예제 #9
0
파일: light.py 프로젝트: timknip/pycollada
    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)