[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1944] trunk/py/scripts/addons/ io_scene_x3d/export_x3d.py: removed the class for exporting x3d completely.

Campbell Barton ideasman42 at gmail.com
Tue May 17 07:50:03 CEST 2011


Revision: 1944
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=1944
Author:   campbellbarton
Date:     2011-05-17 05:50:03 +0000 (Tue, 17 May 2011)
Log Message:
-----------
removed the class for exporting x3d completely.

Modified Paths:
--------------
    trunk/py/scripts/addons/io_scene_x3d/export_x3d.py

Modified: trunk/py/scripts/addons/io_scene_x3d/export_x3d.py
===================================================================
--- trunk/py/scripts/addons/io_scene_x3d/export_x3d.py	2011-05-17 04:49:20 UTC (rev 1943)
+++ trunk/py/scripts/addons/io_scene_x3d/export_x3d.py	2011-05-17 05:50:03 UTC (rev 1944)
@@ -68,6 +68,7 @@
                       "TriangleFanSet", "TriangleSet", "TriangleSet2D", "TriangleStripSet", "Viewpoint", "VisibilitySensor",
                       "WorldInfo", "X3D", "XvlShell", "VertexShader", "FragmentShader", "MultiShaderAppearance", "ShaderAppearance"}
 
+
 def clamp_color(col):
     return tuple([max(min(c, 1.0), 0.0) for c in col])
 
@@ -91,40 +92,27 @@
         newName = newName.replace(bad, "_")
     return newName
 
+namesFog = ("", "LINEAR", "EXPONENTIAL", "")
+
 ##########################################################
 # Functions for writing output file
 ##########################################################
 
 
-class x3d_class:
+def export(file,
+           global_matrix,
+           scene,
+           use_apply_modifiers=False,
+           use_selection=True,
+           EXPORT_TRI=False,):
 
-    namesFog = ("", "LINEAR", "EXPONENTIAL", "")
+    fw = file.write
 
-    def __init__(self, filepath):
-        #--- public you can change these ---
-        self.global_matrix = mathutils.Matrix.Rotation(-(math.pi / 2.0), 4, 'X')
-
-        #--- class private don't touch ---
-        self.filepath = filepath
-        self.file = None
-        if filepath.lower().endswith('.x3dz'):
-            try:
-                import gzip
-                self.file = gzip.open(filepath, "w")
-            except:
-                print("failed to import compression modules, exporting uncompressed")
-                self.filepath = filepath[:-1]  # remove trailing z
-
-        if self.file is None:
-            self.file = open(self.filepath, "w", encoding="utf8", newline="\n")
-        self.nodeID = 0
-
 ##########################################################
 # Writing nodes routines
 ##########################################################
 
-    @staticmethod
-    def writeHeader(fw, ident):
+    def writeHeader(ident):
         filepath = fw.__self__.name
         #bfile = sys.expandpath( Blender.Get('filepath') ).replace('<', '&lt').replace('>', '&gt')
         bfile = repr(os.path.basename(filepath).replace('<', '&lt').replace('>', '&gt'))[1:-1]  # use outfile name
@@ -143,16 +131,14 @@
         ident += "\t"
         return ident
 
-    @staticmethod
-    def writeFooter(fw, ident):
+    def writeFooter(ident):
         ident = ident[:-1]
         fw("%s</Scene>\n" % ident)
         ident = ident[:-1]
         fw("%s</X3D>" % ident)
         return ident
 
-    @staticmethod
-    def writeViewpoint(fw, ident, ob, mat, scene):
+    def writeViewpoint(ident, ob, mat, scene):
         loc, quat, scale = mat.decompose()
         fw("%s<Viewpoint DEF=\"%s\" " % (ident, clean_str(ob.name)))
         fw("description=\"%s\" " % ob.name)
@@ -162,8 +148,7 @@
         fw("fieldOfView=\"%.3g\" " % ob.data.angle)
         fw(" />\n")
 
-    @staticmethod
-    def writeFog(fw, ident, world):
+    def writeFog(ident, world):
         if world:
             mtype = world.mist_settings.falloff
             mparam = world.mist_settings
@@ -178,12 +163,10 @@
         else:
             return
 
-    @staticmethod
-    def writeNavigationInfo(fw, ident, scene):
+    def writeNavigationInfo(ident, scene):
         fw('%s<NavigationInfo headlight="false" visibilityLimit="0.0" type=\'"EXAMINE","ANY"\' avatarSize="0.25, 1.75, 0.75" />\n' % ident)
 
-    @staticmethod
-    def writeSpotLight(fw, ident, ob, mtx, lamp, world):
+    def writeSpotLight(ident, ob, mtx, lamp, world):
         safeName = clean_str(ob.name)
         if world:
             ambi = world.ambient_color
@@ -214,8 +197,7 @@
         fw("direction=\"%.4g %.4g %.4g\" " % (dx, dy, dz))
         fw("location=\"%.4g %.4g %.4g\" />\n" % location)
 
-    @staticmethod
-    def writeDirectionalLight(fw, ident, ob, mtx, lamp, world):
+    def writeDirectionalLight(ident, ob, mtx, lamp, world):
         safeName = clean_str(ob.name)
         if world:
             ambi = world.ambient_color
@@ -233,8 +215,7 @@
         fw("intensity=\"%.4g\" " % intensity)
         fw("direction=\"%.4g %.4g %.4g\" />\n" % (dx, dy, dz))
 
-    @staticmethod
-    def writePointLight(fw, ident, ob, mtx, lamp, world):
+    def writePointLight(ident, ob, mtx, lamp, world):
 
         safeName = clean_str(ob.name)
         if world:
@@ -256,26 +237,27 @@
         fw("radius=\"%.4g\" " % lamp.distance)
         fw("location=\"%.4g %.4g %.4g\" />\n" % location)
 
-    def secureName(self, name):
-        name = name + str(self.nodeID)
-        self.nodeID = self.nodeID + 1
+    def secureName(name):
+        name = name + str(secureName.nodeID)
+        secureName.nodeID += 1
         if len(name) <= 3:
-            newname = "_" + str(self.nodeID)
+            newname = "_" + str(secureName.nodeID)
             return "%s" % (newname)
         else:
             for bad in ('"', '#', "'", ', ', '.', '[', '\\', ']', '{', '}'):
                 name = name.replace(bad, "_")
             if name in x3d_names_reserved:
-                newname = name[0:3] + "_" + str(self.nodeID)
+                newname = name[0:3] + "_" + str(secureName.nodeID)
                 return "%s" % (newname)
             elif name[0].isdigit():
-                newname = "_" + name + str(self.nodeID)
+                newname = "_" + name + str(secureName.nodeID)
                 return "%s" % (newname)
             else:
                 newname = name
                 return "%s" % (newname)
+    secureName.nodeID = 0
 
-    def writeIndexedFaceSet(self, fw, ident, ob, mesh, mtx, world, EXPORT_TRI=False):
+    def writeIndexedFaceSet(ident, ob, mesh, mtx, world, EXPORT_TRI=False):
 
         shape_name_x3d = clean_str(ob.name)
         mesh_name_x3d = clean_str(mesh.name)
@@ -408,7 +390,7 @@
                     ident += "\t"
 
                     if image:
-                        self.writeImageTexture(fw, ident, image)
+                        writeImageTexture(ident, image)
 
                         if mesh_materials_use_face_texture[material_index]:
                             if image.use_tiles:
@@ -438,7 +420,7 @@
                             fw("/>\n")
 
                     if material:
-                        self.writeMaterial(fw, ident, material, clean_str(material.name, ""), world)
+                        writeMaterial(ident, material, clean_str(material.name, ""), world)
 
                     ident = ident[:-1]
                     fw("%s</Appearance>\n" % ident)
@@ -476,7 +458,7 @@
 
                     if True:
                         # "coordIndex"
-                        fw('coordIndex="')
+                        fw("coordIndex=\"")
                         if EXPORT_TRI:
                             for i in face_group:
                                 fv = mesh_faces[i].vertices[:]
@@ -513,7 +495,6 @@
 
                     if is_uv:
                         fw("%s<TextureCoordinate point=\"" % ident)
-                        fw = fw
                         mesh_faces_uv = mesh.uv_textures.active.data
                         for i in face_group:
                             for uv in mesh_faces_uv[i].uv:
@@ -554,9 +535,7 @@
             ident = ident[:-1]
             fw("%s</Collision>\n" % ident)
 
-
-    @staticmethod
-    def writeMaterial(fw, ident, mat, matName, world):
+    def writeMaterial(ident, mat, matName, world):
         # look up material name, use it if available
         if mat.tag:
             fw("%s<Material USE=\"MA_%s\" />\n" % (ident, matName))
@@ -589,8 +568,7 @@
             fw("shininess=\"%.3g\" " % shininess)
             fw("transparency=\"%s\" />\n" % transp)
 
-    @staticmethod
-    def writeImageTexture(fw, ident, image):
+    def writeImageTexture(ident, image):
         name = image.name
 
         if image.tag:
@@ -614,8 +592,7 @@
 
             fw("url='%s' />\n" % " ".join(["\"%s\"" % f.replace("\\", "/") for f in images]))
 
-    def writeBackground(self, ident, world):
-        fw = self.file.write
+    def writeBackground(ident, world):
 
         if world:
             worldname = world.name
@@ -628,7 +605,7 @@
         sky_triple = clamp_color(world.zenith_color)
         mix_triple = clamp_color((grd_triple[i] + sky_triple[i]) / 2.0 for i in range(3))
 
-        fw("%s<Background DEF=\"%s\" " % (ident, self.secureName(worldname)))
+        fw("%s<Background DEF=\"%s\" " % (ident, secureName(worldname)))
         # No Skytype - just Hor color
         if blending == (False, False, False):
             fw("groundColor=\"%.3g %.3g %.3g\" " % grd_triple)
@@ -684,15 +661,7 @@
 ##########################################################
 # export routine
 ##########################################################
-
-    def export(self, scene,
-               use_apply_modifiers=False,
-               use_selection=True,
-               EXPORT_TRI=False,
-               ):
-
-        fw = self.file.write
-
+    def export_main():
         world = scene.world
 
         # tag un-exported IDs
@@ -700,14 +669,13 @@
         bpy.data.materials.tag(False)
         bpy.data.images.tag(False)
 
-        print("Info: starting X3D export to %r..." % self.filepath)
+        print("Info: starting X3D export to %r..." % file.name)
         ident = ""
-        ident = self.writeHeader(fw, ident)
+        ident = writeHeader(ident)
 
-        # self.writeScript()
-        self.writeNavigationInfo(fw, ident, scene)
-        self.writeBackground(ident, world)
-        self.writeFog(fw, ident, world)
+        writeNavigationInfo(ident, scene)
+        writeBackground(ident, world)
+        writeFog(ident, world)
 
         ident = "\t\t"
 
@@ -726,10 +694,10 @@
             for ob, ob_mat in derived:
                 objType = ob.type
                 objName = ob.name
-                ob_mat = self.global_matrix * ob_mat
+                ob_mat = global_matrix * ob_mat
 
                 if objType == 'CAMERA':
-                    self.writeViewpoint(fw, ident, ob, ob_mat, scene)
+                    writeViewpoint(ident, ob, ob_mat, scene)
                 elif objType in ('MESH', 'CURVE', 'SURF', 'FONT'):
                     if (objType != 'MESH') or (use_apply_modifiers and ob.is_modified(scene, 'PREVIEW')):
                         try:

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list