Beispiel #1
0
    def write(self, file):
        file.write('      <material bmat="%s">\n' % self.name)
        self._iwrite(file, "enum", "Type", self.attributes["Type"])
        self._iwrite(file, "color", "Ambient", self.attributes["AmbientColor"])
        self._iwrite(file, "color", "Diffuse", self.attributes["DiffuseColor"])
        self._iwrite(file, "color", "Emissive", self.attributes["EmissiveColor"])
        self._iwrite(file, "color", "Specular", self.attributes["SpecularColor"])
        self._iwrite(file, "float", "Shininess", self.attributes["Shininess"])
        self._iwrite(file, "float", "Param1", self.attributes["MaterialTypeParam"])
        self._iwrite(file, "float", "Param2", self.attributes["MaterialTypeParam2"])
        self._iwrite(file, "bool", "Wireframe", self.attributes["WireFrame"])
        self._iwrite(file, "bool", "GouraudShading", self.attributes["GouraudShading"])
        self._iwrite(file, "bool", "Lighting", self.attributes["Lighting"])
        self._iwrite(file, "bool", "ZWriteEnable", self.attributes["ZWriteEnable"])
        self._iwrite(file, "int", "ZBuffer", self.attributes["ZBuffer"])
        self._iwrite(file, "bool", "BackfaceCulling", self.attributes["BackfaceCulling"])
        self._iwrite(file, "bool", "FrontfaceCulling", self.attributes["FrontfaceCulling"])
        self._iwrite(file, "bool", "FogEnable", self.attributes["FogEnable"])
        self._iwrite(file, "bool", "NormalizeNormals", self.attributes["NormalizeNormals"])
        self._iwrite(file, "int", "AntiAliasing", self.attributes["AntiAliasing"])
        self._iwrite(file, "int", "ColorMask", self.attributes["ColorMask"])

        stype = "bool"
        if self.exporter.gIrrlichtVersion >= 16:
            stype = "int"

        tex = iUtils.flattenPath(self.attributes["Layer1"]["Texture"])
        self._iwrite(file, "texture", "Texture1", tex)
        self._iwrite(file, "enum", "TextureWrap1", self.attributes["Layer1"]["TextureWrap"])
        self._iwrite(file, "bool", "BilinearFilter1", self.attributes["Layer1"]["BilinearFilter"])
        self._iwrite(file, "bool", "TrilinearFilter1", self.attributes["Layer1"]["TrilinearFilter"])
        self._iwrite(file, stype, "AnisotropicFilter1", self.attributes["Layer1"]["AnisotropicFilter"])
        self._iwrite(file, "int", "LODBias1", self.attributes["Layer1"]["LODBias"])

        tex = iUtils.flattenPath(self.attributes["Layer2"]["Texture"])
        self._iwrite(file, "texture", "Texture2", tex)
        self._iwrite(file, "enum", "TextureWrap2", self.attributes["Layer2"]["TextureWrap"])
        self._iwrite(file, "bool", "BilinearFilter2", self.attributes["Layer2"]["BilinearFilter"])
        self._iwrite(file, "bool", "TrilinearFilter2", self.attributes["Layer2"]["TrilinearFilter"])
        self._iwrite(file, stype, "AnisotropicFilter2", self.attributes["Layer2"]["AnisotropicFilter"])
        self._iwrite(file, "int", "LODBias2", self.attributes["Layer2"]["LODBias"])

        tex = iUtils.flattenPath(self.attributes["Layer3"]["Texture"])
        self._iwrite(file, "texture", "Texture3", tex)
        self._iwrite(file, "enum", "TextureWrap3", self.attributes["Layer3"]["TextureWrap"])
        self._iwrite(file, "bool", "BilinearFilter3", self.attributes["Layer3"]["BilinearFilter"])
        self._iwrite(file, "bool", "TrilinearFilter3", self.attributes["Layer3"]["TrilinearFilter"])
        self._iwrite(file, stype, "AnisotropicFilter3", self.attributes["Layer3"]["AnisotropicFilter"])
        self._iwrite(file, "int", "LODBias3", self.attributes["Layer3"]["LODBias"])

        tex = iUtils.flattenPath(self.attributes["Layer4"]["Texture"])
        self._iwrite(file, "texture", "Texture4", tex)
        self._iwrite(file, "enum", "TextureWrap4", self.attributes["Layer4"]["TextureWrap"])
        self._iwrite(file, "bool", "BilinearFilter4", self.attributes["Layer4"]["BilinearFilter"])
        self._iwrite(file, "bool", "TrilinearFilter4", self.attributes["Layer4"]["TrilinearFilter"])
        self._iwrite(file, stype, "AnisotropicFilter4", self.attributes["Layer4"]["AnisotropicFilter"])
        self._iwrite(file, "int", "LODBias4", self.attributes["Layer4"]["LODBias"])

        file.write("      </material>\n")
Beispiel #2
0
 def _dumpOptions(self):
     debug("\n[options]")
     debug("   Create Scene: " + ("True" if self.gCreateScene else "False"))
     debug(" Base Directory: " + self.gBaseDir)
     debug("Scene Directory: " + self.gSceneDir)
     debug(" Mesh Directory: " + self.gMeshDir)
     debug("Image Directory: " + self.gTexDir)
     debug("     meshOutDir: " + iUtils.defScriptOptions["meshOutDir"])
     debug("      texOutDir: " + iUtils.defScriptOptions["texOutDir"])
     debug("         Binary: " + ("True" if self.gBinary else "False"))
     debug(" Export Cameras: " + ("True" if self.gExportCameras else "False"))
     debug("  Export Lights: " + ("True" if self.gExportLights else "False"))
     debug(" Export Physics: " + ("True" if self.gExportPhysics else "False"))
     debug("    Copy Images: " + ("True" if self.gCopyImages else "False"))
     debug("Image Extension: " + ("Original" if self.gTexExtension == ".???" else self.gTexExtension))
     debug("  Selected Only: " + ("True" if self.gSelectedMeshesOnly else "False"))
     debug("   Irrlicht Ver: " + str(self.gIrrlichtVersion))
     debug("  iwalktest Env: " + iGUI.gWalkTestPath)
     debug("   imeshcvt Env: " + iGUI.gMeshCvtPath)
     debug(
         "  iwalktest Cmd: "
         + iGUI.gWalkTestPath.replace("$1", iUtils.flattenPath(self.gSceneFileName)).replace(
             "$2", iUtils.filterPath(self.gBaseDir)
         )
     )
Beispiel #3
0
def runWalkTest(sceneFileName):


    directory = Blender.sys.dirname(gWalkTestPath)

    cmdline = gWalkTestPath.replace('$1',
            iUtils.flattenPath(sceneFileName)).replace('$2',iUtils.filterPath(gBaseDir))

    subprocess.Popen(cmdline, shell=True, cwd=directory)
Beispiel #4
0
    def _writeSBImageAttributes(self,file,indent,mat,matType,bImage,bObject,lightingOverride=None):

        i2 = indent + '    '
        imageName = self.exporter.getImageFileName(bObject.getData().name,bImage,0)
        file.write(indent + '<attributes>\n')
        self._iwrite(file,'enum','Type',matType, i2)
        self._iwrite(file,'color','Ambient',mat.attributes['AmbientColor'],i2)
        self._iwrite(file,'color','Diffuse',mat.attributes['DiffuseColor'],i2)
        self._iwrite(file,'color','Emissive',mat.attributes['EmissiveColor'],i2)
        self._iwrite(file,'color','Specular',mat.attributes['SpecularColor'],i2)
        self._iwrite(file,'float','Shininess',mat.attributes['Shininess'],i2)
        self._iwrite(file,'float','Param1',mat.attributes['MaterialTypeParam'],i2)
        self._iwrite(file,'float','Param2',mat.attributes['MaterialTypeParam2'],i2)
        self._iwrite(file,'bool','Wireframe',mat.attributes['WireFrame'],i2)
        self._iwrite(file,'bool','GouraudShading',mat.attributes['GouraudShading'],i2)
        if lightingOverride == None:
            self._iwrite(file,'bool','Lighting',mat.attributes['Lighting'],i2)
        else:
            self._iwrite(file,'bool','Lighting',lightingOverride,i2)
            
        self._iwrite(file,'bool','ZWriteEnable',mat.attributes['ZWriteEnable'],i2)
        self._iwrite(file,'int','ZBuffer',mat.attributes['ZBuffer'],i2)
        self._iwrite(file,'bool','BackfaceCulling',mat.attributes['BackfaceCulling'],i2)
        self._iwrite(file,'bool','FogEnable',mat.attributes['FogEnable'],i2)
        self._iwrite(file,'bool','NormalizeNormals',mat.attributes['NormalizeNormals'],i2)
        self._iwrite(file,'int','ColorMask',mat.attributes['ColorMask'],i2)
        self._iwrite(file,'int','AntiAliasing',mat.attributes['AntiAliasing'],i2)
        
        self._iwrite(file,'texture','Texture1',iUtils.flattenPath(imageName),i2)
        self._iwrite(file,'enum','TextureWrap1','texture_clamp_clamp',i2)
        self._iwrite(file,'bool','BilinearFilter1',mat.attributes['Layer1']['BilinearFilter'],i2)
        self._iwrite(file,'bool','TrilinearFilter1',mat.attributes['Layer1']['TrilinearFilter'],i2)
        if self.exporter.gIrrlichtVersion >= 16:
            self._iwrite(file,'int','AnisotropicFilter1',mat.attributes['Layer1']['AnisotropicFilter'],i2)
        else:
            self._iwrite(file,'bool','AnisotropicFilter1',mat.attributes['Layer1']['AnisotropicFilter'],i2)
        file.write(indent + '</attributes>\n')
Beispiel #5
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')