Esempio n. 1
0
    def writeCameraNodeData(self,file,bObject,level):
        i1 = iUtils.getIndent(level,3)
        i2 = iUtils.getIndent(level,6)

        localSpace = bObject.getMatrix('localspace')

        ipos = iUtils.b2iPosition(localSpace, bObject)
        irot = iUtils.b2iRotation(localSpace, bObject)
        iscale = iUtils.b2iVector(localSpace.scalePart())
    
        spos = '%.6f, %.6f, %.6f' % (ipos.x, ipos.y, ipos.z)
        srot = '%.6f, %.6f, %.6f' % (irot.x, irot.y, irot.z)        
        sscale = '%.6f, %.6f, %.6f' % (iscale.x, iscale.y, iscale.z)    

        self.writeSTDAttributes(file,i1,i2,bObject,spos,srot,sscale)

        camera = bObject.getData()

        #
        # calculate target based on x,z rotation 
        #
        
        target = Blender.Mathutils.Vector(0.0,0.0,0.0)
        #target.normalize()
        #target = target * 100.0

        rpos = Blender.Mathutils.Vector(ipos.x,ipos.y,ipos.z)
        #target = target + rpos

        starget = '%.6f, %.6f, %.6f' % (target.x, target.z, target.y)

        #
        # override fov & aspect with logic properties if defined
        #
        fov = 2 * math.atan(16.0 / camera.lens )
        aspect = 1.25

        prop = iUtils.getProperty('fov',bObject)
        if prop != None and type(prop) == float:
            fov = prop

        prop = iUtils.getProperty('aspect',bObject)
        if prop != None and type(prop) == float:
            aspect = prop
    
        file.write(i2 + '<vector3d name="Target" value="%s"/>\n' % (starget))
        file.write(i2 + '<vector3d name="UpVector" value="0.000000,' + 
                ' 1.000000, 0.000000"/>\n')
        file.write(i2 + '<float name="Fovy" value="%.6f"/>\n' % fov)
        file.write(i2 + '<float name="Aspect" value="%.6f"/>\n' % aspect)
        file.write(i2 + '<float name="ZNear" value="%.2f"/>\n' % 
                camera.clipStart)
        file.write(i2 + '<float name="ZFar" value="%.2f"/>\n' % 
                camera.clipEnd)

        file.write(i1 + '</attributes>\n')

        writeUserData(file,i1,i2,bObject)
Esempio n. 2
0
    def writeLightNodeData(self,file,bObject,level):
        i1 = iUtils.getIndent(level,3)
        i2 = iUtils.getIndent(level,6)

        localSpace = bObject.getMatrix('localspace')

        ipos = iUtils.b2iPosition(localSpace, bObject)
        irot = iUtils.b2iRotation(localSpace, bObject)
        iscale = iUtils.b2iVector(localSpace.scalePart())

        spos = '%.6f, %.6f, %.6f' % (ipos.x, ipos.y, ipos.z)

        srot = '%.6f, %.6f, %.6f' % (irot.x, irot.y, irot.z)
        
        sscale = '%.6f, %.6f, %.6f' % (iscale.x, iscale.y, iscale.z)

        self.writeSTDAttributes(file,i1,i2,bObject,spos,srot,sscale)
    

        light = bObject.getData()

        lightType = 'Point'
        if light.type == Blender.Lamp.Types['Lamp']:
            lightType = 'Point'
        if light.type == Blender.Lamp.Types['Area']:
            lightType = 'Directional'
        if light.type == Blender.Lamp.Types['Spot']:
            lightType = 'Spot'
        if light.type == Blender.Lamp.Types['Sun']:
            lightType = 'Directional'
        if light.type == Blender.Lamp.Types['Hemi']:
            lightType = 'Directional'

        file.write(i2 + '<enum name="LightType" value="%s"/>\n' % 
                lightType)

        diffuse = '%.6f, %.6f, %.6f %.6f' % (light.R,light.G,light.B,1.0)

        file.write(i2 + '<colorf name="AmbientColor" value="0.000000,' + 
                '0.000000, 0.000000, 1.000000"/>\n')
        file.write(i2 + '<colorf name="DiffuseColor" value="%s"/>\n' % 
                diffuse)
        file.write(i2 + '<colorf name="SpecularColor" value="1.000000,' + 
                '1.000000, 1.000000, 1.000000"/>\n')

        attvalue = 0.0
        if light.energy != 0.000000:
            attvalue = 0.5 / light.energy
        satt = '0.000000 %.6f 0.000000' % attvalue
        file.write(i2 + '<vector3d name="Attenuation" value="%s"/>\n' % 
                (satt))
        
        file.write(i2 + '<float name="Radius" value="%.2f"/>\n' % 
                (light.dist * 2.0))
        file.write(i2 + '<bool name="CastShadows" value="true"/>\n')
        file.write(i1 + '</attributes>\n')

        writeUserData(file,i1,i2,bObject)
Esempio n. 3
0
    def writeEmptyObject(self,file,bObject,level):
        i1 = iUtils.getIndent(level,3)
        i2 = iUtils.getIndent(level,6)

        localSpace = bObject.getMatrix('localspace')

        ipos = iUtils.b2iPosition(localSpace, bObject)
        irot = iUtils.b2iRotation(localSpace, bObject)
        iscale = iUtils.b2iVector(localSpace.scalePart())
                
        spos = '%.6f, %.6f, %.6f' % (ipos.x, ipos.y, ipos.z)

        srot = '%.6f, %.6f, %.6f' % (irot.x, irot.y, irot.z)
        
        sscale = '%.6f, %.6f, %.6f' % (iscale.x, iscale.y, iscale.z)

        self.writeSTDAttributes(file,i1,i2,bObject,spos,srot,sscale)

        file.write(i1 + '</attributes>\n')
    
        writeUserData(file,i1,i2,bObject)
Esempio n. 4
0
    def writeMeshObject(self, file, meshFileName, bObject, level, physicsEnabled):

        i1 = iUtils.getIndent(level,3)
        i2 = iUtils.getIndent(level,6)

        localSpace = bObject.getMatrix('localspace')

        ipos = iUtils.b2iPosition(localSpace, bObject)
        irot = iUtils.b2iRotation(localSpace, bObject)
        iscale = iUtils.b2iVector(localSpace.scalePart())
        
        spos = '%.6f, %.6f, %.6f' % (ipos.x, ipos.y, ipos.z)
        srot = '%.6f, %.6f, %.6f' % (irot.x, irot.y, irot.z)        
        sscale = '%.6f, %.6f, %.6f' % (iscale.x, iscale.y, iscale.z)

        self.writeSTDAttributes(file,i1,i2,bObject,spos,srot,sscale)

        file.write(i2 + '<string name="Mesh" value="%s"/>\n' % 
                (iUtils.flattenPath(meshFileName)))
        file.write(i1 + '</attributes>\n')

        if physicsEnabled == 0:
            writeUserData(file,i1,i2,bObject, True)
            return

        writeUserData(file,i1,i2,bObject, False)
        ctype = 'none'
        hasBounds = False
        rbFlags = bObject.rbFlags

        # from DNA_Object_types.h
        OB_OCCLUDER		= 0x40000
        OB_SENSOR		= 0x80000

        addMass = False
        if (rbFlags & 0x10000) == 0x10000:
            ctype = 'static'
            if rbFlags & Blender.Object.RBFlags['DYNAMIC']:
                addMass = True
                ctype = 'dynamic'
            if rbFlags & Blender.Object.RBFlags['RIGIDBODY']:
                addMass = True
                ctype = 'rigid'
            if rbFlags & Blender.Object.RBFlags['BOUNDS']:
                hasBounds = True
            if bObject.isSoftBody:
                ctype = 'soft'
            if rbFlags & OB_SENSOR:
                ctype = 'sensor'
            if rbFlags & OB_OCCLUDER:
                ctype = 'occluder'

        if ctype == 'static':
            addMass = False

        i3 = i2 + '   '
        sout = '<string name="Physics.BodyType" value="%s"/>\n' % ctype
        file.write(i3 + sout)

        sShapeType = 'concavemesh' #default shape - concave mesh
        if hasBounds:
            ShapeType = bObject.rbShapeBoundType
            if ShapeType == 0:      # OB_BOUND_BOX - "Box"
                sShapeType = 'box'
            elif ShapeType == 1:    # OB_BOUND_SPHERE - "Sphere"
                sShapeType = 'sphere'
            elif ShapeType == 2:    # OB_BOUND_CYLINDER - "Cylinder"
                sShapeType = 'cylinder'
            elif ShapeType == 3:    # OB_BOUND_CONE - "Cone"
                sShapeType = 'cone'
            elif ShapeType == 4:    # OB_BOUND_POLYH - "Concave TriangleMesh"
                sShapeType = 'concavemesh'
            elif ShapeType == 5:    # OB_BOUND_POLYT - "Convex Hull"
                sShapeType = 'convexmesh'
            if rbFlags & Blender.Object.RBFlags['CHILD']:
                sout = '<bool name="Physics.Compound" value="true"/>\n'
                file.write(i3 + sout)
        sout = '<string name="Physics.BodyShape" value="%s"/>\n' % sShapeType
        file.write(i3 + sout)
        
        if bObject.restrictRender:
            sout = '<bool name="Physics.Visible" value="false"/>\n'
        else:
            sout = '<bool name="Physics.Visible" value="true"/>\n'
        file.write(i3 + sout)

        if addMass:
            sout = '<float name="Physics.Mass" value="%.2f"/>\n' % bObject.rbMass
            file.write(i3 + sout)

        if sShapeType == 'sphere':
            sout = '<float name="Physics.Radius" value="%.2f"/>\n' % bObject.rbRadius
            file.write(i3 + sout)


        if rbFlags & Blender.Object.RBFlags['GHOST']:
            sout = '<bool name="Physics.Ghost" value="true"/>\n'
            file.write(i3 + sout)

        if rbFlags & Blender.Object.RBFlags['ACTOR']:
            sout = '<bool name="Physics.Actor" value="true"/>\n'
            file.write(i3 + sout)

        if rbFlags & Blender.Object.RBFlags['MAINACTOR']:
            sout = '<bool name="Physics.MainActor" value="true"/>\n'
            file.write(i3 + sout)

        if rbFlags & Blender.Object.RBFlags['COLLISION_RESPONSE']:
            sout = '<bool name="Physics.CollisionResponse" value="true"/>\n'
            file.write(i3 + sout)

        # extract friction & restitution from 1st material
        mesh =  bObject.getData(False,True)
        if (mesh.materials != None) and (len(mesh.materials) == 1):
            mat = mesh.materials[0]
            if mat != None:
                sout = '<float name="Physics.Friction" value="%.2f"/>\n' % mat.rbFriction
                file.write(i3 + sout)

                sout = '<float name="Physics.Restitution" value="%.2f"/>\n' % mat.rbRestitution
                file.write(i3 + sout)


        # write rigidbody contstraints if any
        rbconstraints = []

        # from DNA_constraint_types.h
        CONSTRAINT_RB_BALL          = 1
        CONSTRAINT_RB_HINGE         = 2
        CONSTRAINT_RB_CONETWIST     = 4
        CONSTRAINT_RB_VEHICLE       = 11
        CONSTRAINT_RB_GENERIC6DOF   = 12

        constraints = bObject.constraints
        for constraint in constraints:
            if constraint.type == Blender.Constraint.Type['RIGIDBODYJOINT']:
                rbconstraints.append(constraint)

        if len(rbconstraints) > 0:
            for constraint in rbconstraints:
                rbcType = constraint[Blender.Constraint.Settings['CONSTR_RB_TYPE']]

                srbcType = '6dof'
                if rbcType == CONSTRAINT_RB_BALL:
                    srbcType = 'Hinge'
                elif rbcType == CONSTRAINT_RB_HINGE:
                    srbcType = 'Ball'

                pivot = (constraint[Blender.Constraint.Settings['CONSTR_RB_PIVX']],
                         constraint[Blender.Constraint.Settings['CONSTR_RB_PIVY']],
                         constraint[Blender.Constraint.Settings['CONSTR_RB_PIVZ']])

                axisrot = (constraint[Blender.Constraint.Settings['CONSTR_RB_AXX']],
                           constraint[Blender.Constraint.Settings['CONSTR_RB_AXY']],
                           constraint[Blender.Constraint.Settings['CONSTR_RB_AXZ']])

                #debug('rb const: %s' % constraint.name)
                #debug('    type: %d %s' % (rbcType, srbcType))
                #debug('   pivot: %s' % str(pivot))
                #debug('     rot: %s' % str(axisrot))


        file.write(i2 + '</attributes>\n')
        file.write(i1 + '</userData>\n')