[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1995] trunk/py/scripts/addons/ io_scene_x3d/export_x3d.py: minor name & syntax cleanup

Campbell Barton ideasman42 at gmail.com
Thu Jun 2 12:45:18 CEST 2011


Revision: 1995
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=1995
Author:   campbellbarton
Date:     2011-06-02 10:45:17 +0000 (Thu, 02 Jun 2011)
Log Message:
-----------
minor name & syntax cleanup

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-06-02 08:33:23 UTC (rev 1994)
+++ trunk/py/scripts/addons/io_scene_x3d/export_x3d.py	2011-06-02 10:45:17 UTC (rev 1995)
@@ -120,7 +120,6 @@
         gpu_shader_dummy_mat = bpy.data.materials.new('X3D_DYMMY_MAT')
         gpu_shader_cache[None] = gpu.export_shader(scene, gpu_shader_dummy_mat)
 
-
 ##########################################################
 # Writing nodes routines
 ##########################################################
@@ -155,17 +154,17 @@
         fw('%s</X3D>' % ident)
         return ident
 
-    def writeViewpoint(ident, ob, mat, scene):
+    def writeViewpoint(ident, obj, mat, scene):
         loc, quat, scale = mat.decompose()
 
         ident_step = ident + (' ' * (-len(ident) + \
         fw('%s<Viewpoint ' % ident)))
-        fw('DEF="%s"\n' % clean_str(ob.name))
-        fw(ident_step + 'description="%s"\n' % ob.name)
+        fw('DEF="%s"\n' % clean_str(obj.name))
+        fw(ident_step + 'description="%s"\n' % obj.name)
         fw(ident_step + 'centerOfRotation="0 0 0"\n')
         fw(ident_step + 'position="%3.2f %3.2f %3.2f"\n' % loc[:])
         fw(ident_step + 'orientation="%3.2f %3.2f %3.2f %3.2f"\n' % (quat.axis[:] + (quat.angle, )))
-        fw(ident_step + 'fieldOfView="%.3g"\n' % ob.data.angle)
+        fw(ident_step + 'fieldOfView="%.3g"\n' % obj.data.angle)
         fw(ident_step + '/>\n')
 
     def writeFog(ident, world):
@@ -194,8 +193,8 @@
         fw(ident_step + 'avatarSize="0.25, 1.75, 0.75"\n')
         fw(ident_step + '/>\n')
 
-    def writeSpotLight(ident, ob, mtx, lamp, world):
-        safeName = clean_str(ob.name)
+    def writeSpotLight(ident, obj, mtx, lamp, world):
+        safeName = clean_str(obj.name)
         if world:
             ambi = world.ambient_color
             amb_intensity = ((ambi[0] + ambi[1] + ambi[2]) / 3.0) / 2.5
@@ -228,8 +227,8 @@
         fw(ident_step + 'location="%.4g %.4g %.4g"\n' % location)
         fw(ident_step + '/>\n')
 
-    def writeDirectionalLight(ident, ob, mtx, lamp, world):
-        safeName = clean_str(ob.name)
+    def writeDirectionalLight(ident, obj, mtx, lamp, world):
+        safeName = clean_str(obj.name)
         if world:
             ambi = world.ambient_color
             # ambi = world.amb
@@ -251,9 +250,9 @@
         fw(ident_step + 'direction="%.4g %.4g %.4g"\n' % orientation)
         fw(ident_step + '/>\n')
 
-    def writePointLight(ident, ob, mtx, lamp, world):
+    def writePointLight(ident, obj, mtx, lamp, world):
 
-        safeName = clean_str(ob.name)
+        safeName = clean_str(obj.name)
         if world:
             ambi = world.ambient_color
             # ambi = world.amb
@@ -296,9 +295,9 @@
                 return "%s" % (newname)
     secureName.nodeID = 0
 
-    def writeIndexedFaceSet(ident, ob, mesh, mtx, world):
+    def writeIndexedFaceSet(ident, obj, mesh, mtx, world):
 
-        shape_name_x3d = clean_str(ob.name)
+        shape_name_x3d = clean_str(obj.name)
         mesh_name_x3d = clean_str(mesh.name)
 
         if not mesh.faces:
@@ -434,7 +433,7 @@
                         gpu_shader = gpu_shader_cache.get(material)  # material can be 'None', uses dummy cache
                         if gpu_shader is None:
                             gpu_shader = gpu_shader_cache[material] = gpu.export_shader(scene, material)
-                            
+
                             if 1:  # XXX DEBUG
                                 gpu_shader_tmp = gpu.export_shader(scene, material)
                                 import pprint
@@ -444,7 +443,6 @@
                                 pprint.pprint(gpu_shader_tmp, width=120)
                                 #pprint.pprint(val['vertex'])
                                 del gpu_shader_tmp
-                            
 
                     fw('%s<Appearance>\n' % ident)
                     ident += '\t'
@@ -483,7 +481,7 @@
                     if use_h3d:
                         mat_tmp = material if material else gpu_shader_dummy_mat
                         writeMaterialH3D(ident, mat_tmp, clean_str(mat_tmp.name, ''), world,
-                                         ob, gpu_shader)
+                                         obj, gpu_shader)
                         del mat_tmp
                     else:
                         writeMaterial(ident, material, clean_str(material.name, ''), world)
@@ -611,11 +609,10 @@
                                 fw('%.3g %.3g %.3g ' % x3d_v[0][slot_col])
                             fw('" />\n')
 
-
                         if use_h3d:
                             # write attributes
                             for gpu_attr in gpu_shader['attributes']:
-                                
+
                                 # UVs
                                 if gpu_attr['type'] == gpu.CD_MTFACE:
                                     if gpu_attr['datatype'] == gpu.GPU_DATA_2F:
@@ -702,7 +699,7 @@
                                     fw('%.6g %.6g %.6g ' % v.co[:])
                                 fw('"\n')
                                 fw(ident_step + '/>\n')
-                                
+
                                 is_coords_written = True
 
                                 if use_normals:
@@ -793,7 +790,7 @@
             fw(ident_step + '/>\n')
 
     def writeMaterialH3D(ident, mat, material_id, world,
-                         ob, gpu_shader):
+                         obj, gpu_shader):
 
         fw('%s<Material />\n' % ident)
         if mat.tag:
@@ -828,7 +825,6 @@
             #~ GPU_DYNAMIC_SAMPLER_2DIMAGE 13
             #~ GPU_DYNAMIC_SAMPLER_2DSHADOW 14
 
-
             '''
             inline const char* typeToString( X3DType t ) {
               switch( t ) {
@@ -874,7 +870,7 @@
               case  MFMATRIX3D: return "MFMatrix3d";
               case  SFMATRIX4D: return "SFMatrix4d";
               case  MFMATRIX4D: return "MFMatrix4d";
-              case UNKNOWN_X3D_TYPE: 
+              case UNKNOWN_X3D_TYPE:
               default:return "UNKNOWN_X3D_TYPE";
             '''
             import gpu
@@ -932,14 +928,14 @@
 
                 elif uniform['type'] == gpu.GPU_DYNAMIC_OBJECT_IMAT:
                     if uniform['datatype'] == gpu.GPU_DATA_16F:
-                        value = ' '.join(['%.6f' % f for v in (global_matrix * ob.matrix_world).inverted() for f in v])
+                        value = ' '.join(['%.6f' % f for v in (global_matrix * obj.matrix_world).inverted() for f in v])
                         fw('%s<field name="%s" type="SFMatrix4f" accessType="inputOutput" value="%s" />\n' % (ident, uniform['varname'], value))
                     else:
                         assert(0)
 
                 elif uniform['type'] == gpu.GPU_DYNAMIC_SAMPLER_2DSHADOW:
                     pass  # XXX, shadow buffers not supported.
-                
+
                 elif uniform['type'] == gpu.GPU_DYNAMIC_SAMPLER_2DBUFFER:
                     if uniform['datatype'] == gpu.GPU_DATA_1I:
                         if 1:
@@ -1082,57 +1078,56 @@
         ident = '\t\t'
 
         if use_selection:
-            objects = (o for o in scene.objects if o.is_visible(scene) and o.select)
+            objects = (obj for obj in scene.objects if obj.is_visible(scene) and o.select)
         else:
-            objects = (o for o in scene.objects if o.is_visible(scene))
+            objects = (obj for obj in scene.objects if obj.is_visible(scene))
 
-        for ob_main in objects:
+        for obj_main in objects:
 
-            free, derived = create_derived_objects(scene, ob_main)
+            free, derived = create_derived_objects(scene, obj_main)
 
             if derived is None:
                 continue
 
-            for ob, ob_mat in derived:
-                objType = ob.type
-                objName = ob.name
-                ob_mat = global_matrix * ob_mat
+            for obj, obj_matrix in derived:
+                obj_type = obj.type
+                obj_matrix = global_matrix * obj_matrix
 
-                if objType == 'CAMERA':
-                    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')):
+                if obj_type == 'CAMERA':
+                    writeViewpoint(ident, obj, obj_matrix, scene)
+                elif obj_type in ('MESH', 'CURVE', 'SURF', 'FONT'):
+                    if (obj_type != 'MESH') or (use_apply_modifiers and obj.is_modified(scene, 'PREVIEW')):
                         try:
-                            me = ob.to_mesh(scene, use_apply_modifiers, 'PREVIEW')
+                            me = obj.to_mesh(scene, use_apply_modifiers, 'PREVIEW')
                         except:
                             me = None
                     else:
-                        me = ob.data
+                        me = obj.data
 
                     if me is not None:
-                        writeIndexedFaceSet(ident, ob, me, ob_mat, world)
+                        writeIndexedFaceSet(ident, obj, me, obj_matrix, world)
 
                         # free mesh created with create_mesh()
-                        if me != ob.data:
+                        if me != obj.data:
                             bpy.data.meshes.remove(me)
 
-                elif objType == 'LAMP':
-                    data = ob.data
+                elif obj_type == 'LAMP':
+                    data = obj.data
                     datatype = data.type
                     if datatype == 'POINT':
-                        writePointLight(ident, ob, ob_mat, data, world)
+                        writePointLight(ident, obj, obj_matrix, data, world)
                     elif datatype == 'SPOT':
-                        writeSpotLight(ident, ob, ob_mat, data, world)
+                        writeSpotLight(ident, obj, obj_matrix, data, world)
                     elif datatype == 'SUN':
-                        writeDirectionalLight(ident, ob, ob_mat, data, world)
+                        writeDirectionalLight(ident, obj, obj_matrix, data, world)
                     else:
-                        writeDirectionalLight(ident, ob, ob_mat, data, world)

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list