Revision: 14722
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14722
Author:   campbellbarton
Date:     2008-05-07 17:38:40 +0200 (Wed, 07 May 2008)

Log Message:
-----------
* added support for exporting dupli objects
* option to export modifier applied objects
* option to export quads as tri's
* added back compress option (will default to enabled if you use .x3dz as the 
extension)

Modified Paths:
--------------
    trunk/blender/release/scripts/x3d_export.py
    trunk/blender/source/blender/blenkernel/intern/blender.c
    trunk/blender/source/blender/makesdna/DNA_userdef_types.h
    trunk/blender/source/blender/src/space.c

Modified: trunk/blender/release/scripts/x3d_export.py
===================================================================
--- trunk/blender/release/scripts/x3d_export.py 2008-05-07 14:58:33 UTC (rev 
14721)
+++ trunk/blender/release/scripts/x3d_export.py 2008-05-07 15:38:40 UTC (rev 
14722)
@@ -57,6 +57,8 @@
 from Blender import Object, Lamp, Draw, Image, Text, sys, Mesh
 from Blender.Scene import Render
 import math
+import BPyObject
+import BPyMesh
 
 # 
 DEG2RAD=0.017453292519943295
@@ -68,14 +70,14 @@
 
 filename = Blender.Get('filename')
 _safeOverwrite = True
-ARG=''
+
 extension = ''
 
 ##########################################################
 # Functions for writing output file
 ##########################################################
 
-class VRML2Export:
+class x3d_class:
 
        def __init__(self, filename):
                #--- public you can change these ---
@@ -101,7 +103,18 @@
                self.meshNames={}   # dictionary of meshNames
                self.indentLevel=0 # keeps track of current indenting
                self.filename=filename
-               self.file = open(filename, "w")
+               self.file = None
+               if filename.lower().endswith('.x3dz'):
+                       try:
+                               import gzip
+                               self.file = gzip.open(filename, "w")            
                
+                       except:
+                               print "failed to import compression modules, 
exporting uncompressed"
+                               self.filename = filename[:-1] # remove trailing 
z
+               
+               if self.file == None:
+                       self.file = open(self.filename, "w")
+
                self.bNav=0
                self.nodeID=0
                self.namesReserved=[ 
"Anchor","Appearance","Arc2D","ArcClose2D","AudioClip","Background","Billboard",
@@ -169,7 +182,7 @@
                                        nameinline = nameinline+".x3d"
                                        self.file.write("url=\"%s\" />" % 
nameinline)
                                        self.file.write("\n\n")
-       '''
+
        
        def writeScript(self):
                textEditor = Blender.Text.Get() 
@@ -190,15 +203,17 @@
                                        for j in xrange(nalllines):
                                                self.writeIndented(alllines[j] 
+ "\n")
                self.writeIndented("\n")
-
-       def writeViewpoint(self, ob, scene):
+       '''
+       
+       def writeViewpoint(self, ob, mat, scene):
                context = scene.render
                ratio = float(context.imageSizeY())/float(context.imageSizeX())
                lens = (360* (math.atan(ratio *16 / ob.data.getLens()) / 
math.pi))*(math.pi/180)
                lens = min(lens, math.pi) 
                
                # get the camera location, subtract 90 degress from X to orient 
like X3D does
-               mat = ob.matrixWorld
+               # mat = ob.matrixWorld - mat is now passed!
+               
                loc = self.rotatePointForVRML(mat.translationPart())
                rot = mat.toEuler()
                rot = (((rot[0]-90)*DEG2RAD), rot[1]*DEG2RAD, rot[2]*DEG2RAD)
@@ -229,23 +244,11 @@
                        self.file.write("visibilityRange=\"%s\" />\n\n" % 
round(mparam[2],self.cp))
                else:
                        return
-       '''
+       
        def writeNavigationInfo(self, scene):
-               allObj = []
-               allObj = list(scene.objects)
-               headlight = "true"
-               vislimit = 0.0
-               for ob in allObj:
-                       objType=ob.type
-                       if objType == "Camera":
-                               vislimit = ob.data.clipEnd
-                       elif objType == "Lamp":
-                               headlight = "false"
-               self.file.write("<NavigationInfo headlight=\"%s\" " % headlight)
-               self.file.write("visibilityLimit=\"%s\" " % 
(round(vislimit,self.cp)))
-               self.file.write("type=\"EXAMINE\", \"ANY\" avatarSize=\"0.25, 
1.75, 0.75\" />\n\n")
-       '''
-       def writeSpotLight(self, ob, lamp, world):
+               self.file.write('<NavigationInfo headlight="FALSE" 
visibilityLimit="0.0" type=\'"EXAMINE","ANY"\' avatarSize="0.25, 1.75, 0.75" 
/>\n')
+       
+       def writeSpotLight(self, ob, mtx, lamp, world):
                safeName = self.cleanStr(ob.name)
                if world:
                        ambi = world.amb
@@ -259,12 +262,14 @@
                beamWidth=((lamp.spotSize*math.pi)/180.0)*.37;
                cutOffAngle=beamWidth*1.3
 
-               dx,dy,dz=self.computeDirection(ob)
+               dx,dy,dz=self.computeDirection(mtx)
                # note -dx seems to equal om[3][0]
                # note -dz seems to equal om[3][1]
                # note  dy seems to equal om[3][2]
 
-               location=(ob.matrixWorld*MATWORLD).translationPart()
+               #location=(ob.matrixWorld*MATWORLD).translationPart() # now 
passed
+               location=(mtx*MATWORLD).translationPart()
+               
                radius = lamp.dist*math.cos(beamWidth)
                self.file.write("<SpotLight DEF=\"%s\" " % safeName)
                self.file.write("radius=\"%s\" " % (round(radius,self.cp)))
@@ -277,7 +282,7 @@
                self.file.write("location=\"%s %s %s\" />\n\n" % 
(round(location[0],3), round(location[1],3), round(location[2],3)))
                
                
-       def writeDirectionalLight(self, ob, lamp, world):
+       def writeDirectionalLight(self, ob, mtx, lamp, world):
                safeName = self.cleanStr(ob.name)
                if world:
                        ambi = world.amb
@@ -287,14 +292,14 @@
                        ambientIntensity = 0
 
                intensity=min(lamp.energy/1.75,1.0) 
-               (dx,dy,dz)=self.computeDirection(ob)
+               (dx,dy,dz)=self.computeDirection(mtx)
                self.file.write("<DirectionalLight DEF=\"%s\" " % safeName)
                self.file.write("ambientIntensity=\"%s\" " % 
(round(ambientIntensity,self.cp)))
                self.file.write("color=\"%s %s %s\" " % 
(round(lamp.col[0],self.cp), round(lamp.col[1],self.cp), 
round(lamp.col[2],self.cp)))
                self.file.write("intensity=\"%s\" " % 
(round(intensity,self.cp)))
                self.file.write("direction=\"%s %s %s\" />\n\n" % 
(round(dx,4),round(dy,4),round(dz,4)))
 
-       def writePointLight(self, ob, lamp, world):
+       def writePointLight(self, ob, mtx, lamp, world):
                safeName = self.cleanStr(ob.name)
                if world:
                        ambi = world.amb
@@ -303,29 +308,30 @@
                        ambi = 0
                        ambientIntensity = 0
                
-               location=(ob.matrixWorld*MATWORLD).translationPart()
-               intensity=min(lamp.energy/1.75,1.0) 
-               radius = lamp.dist
+               # location=(ob.matrixWorld*MATWORLD).translationPart() # now 
passed
+               location= (mtx*MATWORLD).translationPart()
+               
                self.file.write("<PointLight DEF=\"%s\" " % safeName)
                self.file.write("ambientIntensity=\"%s\" " % 
(round(ambientIntensity,self.cp)))
                self.file.write("color=\"%s %s %s\" " % 
(round(lamp.col[0],self.cp), round(lamp.col[1],self.cp), 
round(lamp.col[2],self.cp)))
-               self.file.write("intensity=\"%s\" " % 
(round(intensity,self.cp)))
-               self.file.write("radius=\"%s\" " % radius )
+               self.file.write("intensity=\"%s\" " % (round( 
min(lamp.energy/1.75,1.0) ,self.cp)))
+               self.file.write("radius=\"%s\" " % lamp.dist )
                self.file.write("location=\"%s %s %s\" />\n\n" % 
(round(location[0],3), round(location[1],3), round(location[2],3)))
-
-       def writeNode(self, ob):
+       '''
+       def writeNode(self, ob, mtx):
                obname=str(ob.name)
                if obname in self.namesStandard:
                        return
                else:
-                       dx,dy,dz = self.computeDirection(ob)
-                       location=(ob.matrixWorld*MATWORLD).translationPart()
+                       dx,dy,dz = self.computeDirection(mtx)
+                       # location=(ob.matrixWorld*MATWORLD).translationPart()
+                       location=(mtx*MATWORLD).translationPart()
                        self.writeIndented("<%s\n" % obname,1)
-                       self.writeIndented("# direction %s %s %s\n" % 
(round(dx,3),round(dy,3),round(dz,3)))
-                       self.writeIndented("# location %s %s %s\n" % 
(round(location[0],3), round(location[1],3), round(location[2],3)))
+                       self.writeIndented("direction=\"%s %s %s\"\n" % 
(round(dx,3),round(dy,3),round(dz,3)))
+                       self.writeIndented("location=\"%s %s %s\"\n" % 
(round(location[0],3), round(location[1],3), round(location[2],3)))
                        self.writeIndented("/>\n",-1)
                        self.writeIndented("\n")
-
+       '''
        def secureName(self, name):
                name = name + str(self.nodeID)
                self.nodeID=self.nodeID+1
@@ -345,13 +351,13 @@
                                newname = name
                                return "%s" % (newname)
 
-       def writeIndexedFaceSet(self, ob, world, normals = 0):
+       def writeIndexedFaceSet(self, ob, mesh, mtx, world, EXPORT_TRI = False):
                imageMap={}   # set of used images
                sided={}          # 'one':cnt , 'two':cnt
                vColors={}      # 'multi':1
                meshName = self.cleanStr(ob.name)
-               mesh=ob.getData(mesh=1)
-               meshME = self.cleanStr(mesh.name)
+               
+               meshME = self.cleanStr(ob.getData(mesh=1).name) # We dont care 
if its the mesh name or not
                if len(mesh.faces) == 0: return
                mode = 0
                if mesh.faceUV:
@@ -371,7 +377,7 @@
                elif not mode & Mesh.FaceModes.DYNAMIC and self.collnode == 0:
                        self.writeIndented("<Collision enabled=\"false\">\n",1)
                        self.collnode = 1
-
+               
                nIFSCnt=self.countIFSSetsNeeded(mesh, imageMap, sided, vColors)
                
                if nIFSCnt > 1:
@@ -382,7 +388,8 @@
                else:
                        bTwoSided=0
 
-               mtx = ob.matrixWorld * MATWORLD
+               # mtx = ob.matrixWorld * MATWORLD # mtx is now passed
+               mtx = mtx * MATWORLD
                
                loc= mtx.translationPart()
                sca= mtx.scalePart()
@@ -456,12 +463,12 @@
                                elif hasImageTexture == 1:
                                        self.writeTextureCoordinates(mesh)
                        #--- output coordinates
-                       self.writeCoordinates(ob, mesh, meshName)
+                       self.writeCoordinates(ob, mesh, meshName, EXPORT_TRI)
 
                        self.writingcoords = 1
                        self.writingtexture = 1
                        self.writingcolor = 1
-                       self.writeCoordinates(ob, mesh, meshName)
+                       self.writeCoordinates(ob, mesh, meshName, EXPORT_TRI)
                        
                        #--- output textureCoordinates if UV texture used
                        if mesh.faceUV:
@@ -498,17 +505,23 @@
 
                self.file.write("\n")
 
-       def writeCoordinates(self, ob, mesh, meshName):
+       def writeCoordinates(self, ob, mesh, meshName, EXPORT_TRI = False):
                # create vertex list and pre rotate -90 degrees X for VRML
                
                if self.writingcoords == 0:
                        self.file.write('coordIndex="')
                        for face in mesh.faces:
                                fv = face.v
-                               if len(face)==4:
-                                       self.file.write("%i %i %i %i -1, " % 
(fv[0].index, fv[1].index, fv[2].index, fv[3].index))
+                               
+                               if len(face)==3:
+                                               self.file.write("%i %i %i -1, " 
% (fv[0].index, fv[1].index, fv[2].index))
                                else:
-                                       self.file.write("%i %i %i -1, " % 
(fv[0].index, fv[1].index, fv[2].index))
+                                       if EXPORT_TRI:
+                                               self.file.write("%i %i %i -1, " 
% (fv[0].index, fv[1].index, fv[2].index))
+                                               self.file.write("%i %i %i -1, " 
% (fv[0].index, fv[2].index, fv[3].index))
+                                       else:
+                                               self.file.write("%i %i %i %i 
-1, " % (fv[0].index, fv[1].index, fv[2].index, fv[3].index))
+                       
                        self.file.write("\">\n")
                else:
                        #-- vertices
@@ -679,43 +692,74 @@
 # export routine
 ##########################################################
 
-       def export(self, scene, world, alltextures):
+       def export(self, scene, world, alltextures,\
+                       EXPORT_APPLY_MODIFIERS = False,\
+                       EXPORT_TRI=                             False,\
+               ):
+               
                print "Info: starting X3D export to " + self.filename + "..."
                self.writeHeader()
-               self.writeScript()
-               # self.writeNavigationInfo(scene) # This seems to position me 
in some strange area I cant see the model (with BS Contact) - Campbell
+               # self.writeScript()
+               self.writeNavigationInfo(scene)
                self.writeBackground(world, alltextures)
                self.writeFog(world)
                self.proto = 0
                
-               for ob in scene.objects.context:
-                       objType=ob.type
-                       objName=ob.name
-                       self.matonly = 0
-                       if objType == "Camera":
-                               self.writeViewpoint(ob, scene)

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to