[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34084] trunk/blender/release/scripts/op/ io_scene_x3d/export_x3d.py: X3D Export,

Campbell Barton ideasman42 at gmail.com
Wed Jan 5 06:53:49 CET 2011


Revision: 34084
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=34084
Author:   campbellbarton
Date:     2011-01-05 06:53:41 +0100 (Wed, 05 Jan 2011)

Log Message:
-----------
X3D Export,
- mesh creaseAngle was being exported as degrees, should be radians.
- remove unused vars & code.
- indenting was using a for loop, can just multiply a string instead.

Modified Paths:
--------------
    trunk/blender/release/scripts/op/io_scene_x3d/export_x3d.py

Modified: trunk/blender/release/scripts/op/io_scene_x3d/export_x3d.py
===================================================================
--- trunk/blender/release/scripts/op/io_scene_x3d/export_x3d.py	2011-01-05 05:33:27 UTC (rev 34083)
+++ trunk/blender/release/scripts/op/io_scene_x3d/export_x3d.py	2011-01-05 05:53:41 UTC (rev 34084)
@@ -40,24 +40,16 @@
 import mathutils
 
 from io_utils import create_derived_objects, free_derived_objects
+MATWORLD = mathutils.Matrix.Rotation(-(math.pi / 2.0), 4, 'X')
 
-DEG2RAD = 0.017453292519943295
-RAD_90D = -(math.pi / 2.0)
-MATWORLD = mathutils.Matrix.Rotation(RAD_90D, 4, 'X')
 
-
 def round_color(col, cp):
     return tuple([round(max(min(c, 1.0), 0.0), cp) for c in col])
 
-####################################
-# Global Variables
-####################################
+def matrix_direction(mtx):
+    return (mathutils.Vector((0.0, 0.0, -1.0)) * (MATWORLD * mtx).rotation_part()).normalize()[:]
 
-filepath = ""
-_safeOverwrite = True
 
-extension = ''
-
 ##########################################################
 # Functions for writing output file
 ##########################################################
@@ -124,11 +116,7 @@
                              "TextureTransform", "TimeSensor", "TimeTrigger", "TouchSensor", "Transform", "TransmitterPdu",
                              "TriangleFanSet", "TriangleSet", "TriangleSet2D", "TriangleStripSet", "Viewpoint", "VisibilitySensor",
                              "WorldInfo", "X3D", "XvlShell", "VertexShader", "FragmentShader", "MultiShaderAppearance", "ShaderAppearance")
-        self.namesStandard = ("Empty", "Empty.000", "Empty.001", "Empty.002", "Empty.003", "Empty.004", "Empty.005",
-                             "Empty.006", "Empty.007", "Empty.008", "Empty.009", "Empty.010", "Empty.011", "Empty.012",
-                             "Scene.001", "Scene.002", "Scene.003", "Scene.004", "Scene.005", "Scene.06", "Scene.013",
-                             "Scene.006", "Scene.007", "Scene.008", "Scene.009", "Scene.010", "Scene.011", "Scene.012",
-                             "World", "World.000", "World.001", "World.002", "World.003", "World.004", "World.005")
+
         self.namesFog = ("", "LINEAR", "EXPONENTIAL", "")
 
 ##########################################################
@@ -152,21 +140,6 @@
 
     # This functionality is poorly defined, disabling for now - campbell
     '''
-    def writeInline(self):
-        inlines = Blender.Scene.Get()
-        allinlines = len(inlines)
-        if scene != inlines[0]:
-            return
-        else:
-            for i in xrange(allinlines):
-                nameinline=inlines[i].name
-                if (nameinline not in self.namesStandard) and (i > 0):
-                    self.file.write("<Inline DEF=\"%s\" " % (self.cleanStr(nameinline)))
-                    nameinline = nameinline+".x3d"
-                    self.file.write("url=\"%s\" />" % nameinline)
-                    self.file.write("\n\n")
-
-
     def writeScript(self):
         textEditor = Blender.Text.Get()
         alltext = len(textEditor)
@@ -178,14 +151,14 @@
                     nalllines = len(textEditor[i].asLines())
                     alllines = textEditor[i].asLines()
                     for j in xrange(nalllines):
-                        self.writeIndented(alllines[j] + "\n")
+                        self.write_indented(alllines[j] + "\n")
             elif (self.proto == 0):
                 if (nametext == "route" or nametext == "route.js" or nametext == "route.txt") and (nlines != None):
                     nalllines = len(textEditor[i].asLines())
                     alllines = textEditor[i].asLines()
                     for j in xrange(nalllines):
-                        self.writeIndented(alllines[j] + "\n")
-        self.writeIndented("\n")
+                        self.write_indented(alllines[j] + "\n")
+        self.write_indented("\n")
     '''
 
     def writeViewpoint(self, ob, mat, scene):
@@ -233,7 +206,7 @@
         # beamWidth=((lamp.spotSize*math.pi)/180.0)*.37
         cutOffAngle = beamWidth * 1.3
 
-        dx, dy, dz = self.computeDirection(mtx)
+        dx, dy, dz = matrix_direction(mtx)
 
         location = (MATWORLD * mtx).translation_part()
 
@@ -260,11 +233,10 @@
             ambientIntensity = 0
 
         intensity = min(lamp.energy / 1.75, 1.0)
-        dx, dy, dz = self.computeDirection(mtx)
+        dx, dy, dz = matrix_direction(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.color[0], self.cp), round(lamp.color[1], self.cp), round(lamp.color[2], 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)))
 
@@ -283,26 +255,11 @@
         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.color[0], self.cp), round(lamp.color[1], self.cp), round(lamp.color[2], 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(min(lamp.energy / 1.75, 1.0), self.cp)))
         self.file.write("radius=\"%s\" " % lamp.distance)
-        # 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, mtx):
-        obname=str(ob.name)
-        if obname in self.namesStandard:
-            return
-        else:
-            dx,dy,dz = self.computeDirection(mtx)
-            # location=(MATWORLD * ob.matrix_world).translation_part()
-            location=(MATWORLD * mtx).translation_part()
-            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("/>\n",-1)
-            self.writeIndented("\n")
-    '''
+
     def secureName(self, name):
         name = name + str(self.nodeID)
         self.nodeID = self.nodeID + 1
@@ -349,24 +306,24 @@
 
         if 'HALO' in mode and self.halonode == 0:
         # if mode & Mesh.FaceModes.HALO and self.halonode == 0:
-            self.writeIndented("<Billboard axisOfRotation=\"0 0 0\">\n", 1)
+            self.write_indented("<Billboard axisOfRotation=\"0 0 0\">\n", 1)
             self.halonode = 1
         elif 'BILLBOARD' in mode and self.billnode == 0:
         # elif mode & Mesh.FaceModes.BILLBOARD and self.billnode == 0:
-            self.writeIndented("<Billboard axisOfRotation=\"0 1 0\">\n", 1)
+            self.write_indented("<Billboard axisOfRotation=\"0 1 0\">\n", 1)
             self.billnode = 1
         # TF_TILES is marked as deprecated in DNA_meshdata_types.h
         # elif mode & Mesh.FaceModes.TILES and self.tilenode == 0:
         # 	self.tilenode = 1
         elif 'COLLISION' not in mode and self.collnode == 0:
         # elif not mode & Mesh.FaceModes.DYNAMIC and self.collnode == 0:
-            self.writeIndented("<Collision enabled=\"false\">\n", 1)
+            self.write_indented("<Collision enabled=\"false\">\n", 1)
             self.collnode = 1
 
         nIFSCnt = self.countIFSSetsNeeded(mesh, imageMap, sided)
 
         if nIFSCnt > 1:
-            self.writeIndented("<Group DEF=\"%s%s\">\n" % ("G_", meshName), 1)
+            self.write_indented("<Group DEF=\"%s%s\">\n" % ("G_", meshName), 1)
 
         if 'two' in sided and sided['two'] > 0:
             bTwoSided = 1
@@ -380,12 +337,10 @@
         quat = mtx.to_quat()
         rot = quat.axis
 
-        self.writeIndented('<Transform DEF="%s" translation="%.6f %.6f %.6f" scale="%.6f %.6f %.6f" rotation="%.6f %.6f %.6f %.6f">\n' % \
+        self.write_indented('<Transform DEF="%s" translation="%.6f %.6f %.6f" scale="%.6f %.6f %.6f" rotation="%.6f %.6f %.6f %.6f">\n' % \
                            (meshName, loc[0], loc[1], loc[2], sca[0], sca[1], sca[2], rot[0], rot[1], rot[2], quat.angle))
-        # self.writeIndented('<Transform DEF="%s" translation="%.6f %.6f %.6f" scale="%.6f %.6f %.6f" rotation="%.6f %.6f %.6f %.6f">\n' % \
-        #   (meshName, loc[0], loc[1], loc[2], sca[0], sca[1], sca[2], rot[0], rot[1], rot[2], quat.angle*DEG2RAD) )
 
-        self.writeIndented("<Shape>\n", 1)
+        self.write_indented("<Shape>\n", 1)
         is_smooth = False
 
         # XXX, lame, only exports first material.
@@ -395,7 +350,7 @@
                 break
 
         if mat_first or mesh.uv_textures.active:
-            self.writeIndented("<Appearance>\n", 1)
+            self.write_indented("<Appearance>\n", 1)
             # right now this script can only handle a single material per mesh.
             if mat_first and mat_first.use_face_texture == False:
                 self.writeMaterial(mat_first, self.cleanStr(mat_first.name, ""), world)
@@ -427,21 +382,21 @@
                 self.writeImageTexture(image)
 
                 if self.tilenode == 1:
-                    self.writeIndented("<TextureTransform	scale=\"%s %s\" />\n" % (image.xrep, image.yrep))
+                    self.write_indented("<TextureTransform	scale=\"%s %s\" />\n" % (image.xrep, image.yrep))
                     self.tilenode = 0
 
-            self.writeIndented("</Appearance>\n", -1)
+            self.write_indented("</Appearance>\n", -1)
 
         #-- IndexedFaceSet or IndexedLineSet
 
         # user selected BOUNDS=1, SOLID=3, SHARED=4, or TEXTURE=5
         # look up mesh name, use it if available
         if mesh.tag:
-            self.writeIndented("<IndexedFaceSet USE=\"ME_%s\">" % meshME, 1)
+            self.write_indented("<IndexedFaceSet USE=\"ME_%s\">" % meshME, 1)
         else:
             mesh.tag = True
 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list