コード例 #1
0
ファイル: iScene.py プロジェクト: bdbdonp/tubras
    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)
コード例 #2
0
ファイル: iExporter.py プロジェクト: rxantos/tubras
    def _exportObject(self, bObject):

        inVisibleLayer = False
        for l in bObject.layers:
            if l in self.gSceneLayers:
                inVisibleLayer = True
                break

        if not inVisibleLayer:
            return

        type = bObject.getType()

        writeObject = True
        if type == "Mesh" and self.gSelectedMeshesOnly == 1 and not bObject.sel:
            writeObject = False

        itype = iUtils.getProperty("inodetype", bObject)
        if itype != None:
            itype = itype.lower()
            if itype == "default":
                itype = None

        writeTail = True

        if writeObject:
            if itype != None:
                if itype == "skybox":
                    sImages = self._validateSkyBox(bObject)
                    if sImages == None:
                        writeTail = False
                    else:
                        self.iScene.writeNodeHead(self.sfile, self.gObjectLevel, "skyBox")
                        self.iScene.writeSkyBoxNodeData(self.sfile, bObject, sImages, self.gObjectLevel)
                        for image in sImages:
                            self._saveImage(image)

                elif itype == "billboard":
                    bbImage = self._validateBillboard(bObject)
                    if bbImage == None:
                        writeTail = False
                    else:
                        self.iScene.writeNodeHead(self.sfile, self.gObjectLevel, "billBoard")
                        self.iScene.writeBillboardNodeData(self.sfile, bObject, bbImage, self.gObjectLevel)
                        self._saveImage(bbImage)

                else:
                    # display invalid "inodetype" warning
                    addWarning('Object "%s", has invalid "inodetype."' % bObject.name)
                    writeTail = False
            elif type == "Mesh":
                if self.sfile != None:
                    #
                    # should check if mesh actually contains animations...
                    #
                    self.iScene.writeNodeHead(self.sfile, self.gObjectLevel, "mesh")
                self._exportMesh(bObject)
                self.gObjectCount += 1
            elif type == "Lamp":
                if (self.sfile != None) and self.gExportLights:
                    self.iScene.writeNodeHead(self.sfile, self.gObjectLevel, "light")
                    self.iScene.writeLightNodeData(self.sfile, bObject, self.gObjectLevel)
                    self.gLightCount += 1
                else:
                    writeTail = False
            elif type == "Camera":
                if (self.sfile != None) and self.gExportCameras:
                    self.iScene.writeNodeHead(self.sfile, self.gObjectLevel, "camera")
                    self.iScene.writeCameraNodeData(self.sfile, bObject, self.gObjectLevel)
                    self.gCameraCount += 1
                else:
                    writeTail = False
            elif type == "Empty" or type == "Armature":
                if self.sfile != None:
                    self.iScene.writeNodeHead(self.sfile, self.gObjectLevel, "empty")
                    self.iScene.writeEmptyObject(self.sfile, bObject, self.gObjectLevel)
                else:
                    writeTail = False
            else:
                writeTail = False

        self.gObjectLevel += 1
        cObjects = self._getChildren(bObject)
        for cObject in cObjects:
            self._exportObject(cObject)
        self.gObjectLevel -= 1

        if writeObject and (self.sfile != None) and writeTail:
            self.iScene.writeNodeTail(self.sfile, self.gObjectLevel)