[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2917] trunk/py/scripts/addons/ io_scene_x3d: Patch #29923 Make name decorators optional in X3D exporter

Peter Amstutz tetron at interreality.org
Wed Jan 18 22:05:22 CET 2012


Revision: 2917
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2917
Author:   tetron
Date:     2012-01-18 21:05:19 +0000 (Wed, 18 Jan 2012)
Log Message:
-----------
Patch #29923 Make name decorators optional in X3D exporter

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

Modified: trunk/py/scripts/addons/io_scene_x3d/__init__.py
===================================================================
--- trunk/py/scripts/addons/io_scene_x3d/__init__.py	2012-01-18 20:51:26 UTC (rev 2916)
+++ trunk/py/scripts/addons/io_scene_x3d/__init__.py	2012-01-18 21:05:19 UTC (rev 2917)
@@ -134,13 +134,19 @@
             description="Export parent child relationships",
             default=True,
             )
+    name_decorations = BoolProperty(
+            name="Name decorations",
+            description="Add prefixes to the names of exported nodes to indicate their type.",
+            default=True,
+            )
     use_h3d = BoolProperty(
             name="H3D Extensions",
             description="Export shaders for H3D",
             default=False,
             )
-    axis_forward = EnumProperty(
-            name="Forward",
+            
+    blender_axis_forward = EnumProperty(
+            name="Blender Forward",
             items=(('X', "X Forward", ""),
                    ('Y', "Y Forward", ""),
                    ('Z', "Z Forward", ""),
@@ -148,11 +154,35 @@
                    ('-Y', "-Y Forward", ""),
                    ('-Z', "-Z Forward", ""),
                    ),
+            default='-Y',
+            )
+            
+    blender_axis_up = EnumProperty(
+        name="Blender Up",
+        items=(('X', "X Up", ""),
+               ('Y', "Y Up", ""),
+               ('Z', "Z Up", ""),
+               ('-X', "-X Up", ""),
+               ('-Y', "-Y Up", ""),
+               ('-Z', "-Z Up", ""),
+               ),
+        default='Z',
+        )
+        
+    x3d_axis_forward = EnumProperty(
+            name="X3D Forward",
+            items=(('X', "X Forward", ""),
+                   ('Y', "Y Forward", ""),
+                   ('Z', "Z Forward", ""),
+                   ('-X', "-X Forward", ""),
+                   ('-Y', "-Y Forward", ""),
+                   ('-Z', "-Z Forward", ""),
+                   ),
             default='Z',
             )
 
-    axis_up = EnumProperty(
-            name="Up",
+    x3d_axis_up = EnumProperty(
+            name="X3D Up",
             items=(('X', "X Up", ""),
                    ('Y', "Y Up", ""),
                    ('Z', "Z Up", ""),
@@ -168,13 +198,17 @@
     def execute(self, context):
         from . import export_x3d
 
-        keywords = self.as_keywords(ignore=("axis_forward",
-                                            "axis_up",
+        keywords = self.as_keywords(ignore=("blender_axis_forward",
+                                            "blender_axis_up",
+                                            "x3d_axis_forward",
+                                            "x3d_axis_up",
                                             "check_existing",
                                             "filter_glob",
                                             ))
-        global_matrix = axis_conversion(to_forward=self.axis_forward,
-                                        to_up=self.axis_up,
+        global_matrix = axis_conversion(from_forward=self.blender_axis_forward,
+                                        from_up=self.blender_axis_up,
+                                        to_forward=self.x3d_axis_forward,
+                                        to_up=self.x3d_axis_up,
                                         ).to_4x4()
         keywords["global_matrix"] = global_matrix
 

Modified: trunk/py/scripts/addons/io_scene_x3d/export_x3d.py
===================================================================
--- trunk/py/scripts/addons/io_scene_x3d/export_x3d.py	2012-01-18 20:51:26 UTC (rev 2916)
+++ trunk/py/scripts/addons/io_scene_x3d/export_x3d.py	2012-01-18 21:05:19 UTC (rev 2917)
@@ -187,7 +187,7 @@
             lines.append("\n")
         elif l.lstrip().startswith("lamp_visibility_other("):
             w = l.split(', ')
-            last_transform = w[1] + "_transform"  # XXX - HACK!!!
+            last_transform = w[1] + _TRANSFORM  # XXX - HACK!!!
             w[1] = '(view_matrix * %s_transform * vec4(%s.x, %s.y, %s.z, 1.0)).xyz' % (w[1], w[1], w[1], w[1])
             l = ", ".join(w)
         elif l.lstrip().startswith("lamp_visibility_sun_hemi("):
@@ -246,6 +246,7 @@
            use_hierarchy=True,
            use_h3d=False,
            path_mode='AUTO',
+           name_decorations=True,
            ):
 
     # -------------------------------------------------------------------------
@@ -255,13 +256,49 @@
     from bpy_extras.io_utils import unique_name
     from xml.sax.saxutils import quoteattr, escape
 
-    uuid_cache_object = {}    # object
-    uuid_cache_lamp = {}      # 'LA_' + object.name
-    uuid_cache_view = {}      # object, different namespace
-    uuid_cache_mesh = {}      # mesh
-    uuid_cache_material = {}  # material
-    uuid_cache_image = {}     # image
-    uuid_cache_world = {}     # world
+    
+    
+    if name_decorations:
+        # If names are decorated, the uuid map can be split up
+        # by type for efficiency of collision testing
+        # since objects of different types will always have
+        # different decorated names.
+        uuid_cache_object = {}    # object
+        uuid_cache_lamp = {}      # 'LA_' + object.name
+        uuid_cache_view = {}      # object, different namespace
+        uuid_cache_mesh = {}      # mesh
+        uuid_cache_material = {}  # material
+        uuid_cache_image = {}     # image
+        uuid_cache_world = {}     # world
+        CA_ = 'CA_'
+        OB_ = 'OB_'
+        ME_ = 'ME_'
+        IM_ = 'IM_'
+        WO_ = 'WO_'
+        MA_ = 'MA_'
+        LA_ = 'LA_'
+        group_ = 'group_'
+    else:
+        # If names are not decorated, it may be possible for two objects to
+        # have the same name, so there has to be a unified dictionary to 
+        # prevent uuid collisions.
+        uuid_cache_object = {}    # object
+        uuid_cache_lamp = uuid_cache_object      # 'LA_' + object.name
+        uuid_cache_view = uuid_cache_object      # object, different namespace
+        uuid_cache_mesh = uuid_cache_object      # mesh
+        uuid_cache_material = uuid_cache_object  # material
+        uuid_cache_image = uuid_cache_object     # image
+        uuid_cache_world = uuid_cache_object     # world
+        CA_ = ''
+        OB_ = ''
+        ME_ = ''
+        IM_ = ''
+        WO_ = ''
+        MA_ = ''
+        LA_ = ''
+        group_ = ''
+    
+    _TRANSFORM = '_TRANSFORM'
 
     # store files to copy
     copy_set = set()
@@ -328,7 +365,7 @@
         return ident
 
     def writeViewpoint(ident, obj, matrix, scene):
-        view_id = quoteattr(unique_name(obj, 'CA_' + obj.name, uuid_cache_view, clean_func=clean_def, sep="_"))
+        view_id = quoteattr(unique_name(obj, CA_ + obj.name, uuid_cache_view, clean_func=clean_def, sep="_"))
 
         loc, rot, scale = matrix.decompose()
         rot = rot.to_axis_angle()
@@ -396,7 +433,7 @@
 
     def writeSpotLight(ident, obj, matrix, lamp, world):
         # note, lamp_id is not re-used
-        lamp_id = quoteattr(unique_name(obj, 'LA_' + obj.name, uuid_cache_lamp, clean_func=clean_def, sep="_"))
+        lamp_id = quoteattr(unique_name(obj, LA_ + obj.name, uuid_cache_lamp, clean_func=clean_def, sep="_"))
 
         if world:
             ambi = world.ambient_color
@@ -432,7 +469,7 @@
 
     def writeDirectionalLight(ident, obj, matrix, lamp, world):
         # note, lamp_id is not re-used
-        lamp_id = quoteattr(unique_name(obj, 'LA_' + obj.name, uuid_cache_lamp, clean_func=clean_def, sep="_"))
+        lamp_id = quoteattr(unique_name(obj, LA_ + obj.name, uuid_cache_lamp, clean_func=clean_def, sep="_"))
 
         if world:
             ambi = world.ambient_color
@@ -457,7 +494,7 @@
 
     def writePointLight(ident, obj, matrix, lamp, world):
         # note, lamp_id is not re-used
-        lamp_id = quoteattr(unique_name(obj, 'LA_' + obj.name, uuid_cache_lamp, clean_func=clean_def, sep="_"))
+        lamp_id = quoteattr(unique_name(obj, LA_ + obj.name, uuid_cache_lamp, clean_func=clean_def, sep="_"))
 
         if world:
             ambi = world.ambient_color
@@ -482,9 +519,9 @@
         fw(ident_step + '/>\n')
 
     def writeIndexedFaceSet(ident, obj, mesh, matrix, world):
-        obj_id = quoteattr(unique_name(obj, 'OB_' + obj.name, uuid_cache_object, clean_func=clean_def, sep="_"))
-        mesh_id = quoteattr(unique_name(mesh, 'ME_' + mesh.name, uuid_cache_mesh, clean_func=clean_def, sep="_"))
-        mesh_id_group = prefix_quoted_str(mesh_id, 'group_')
+        obj_id = quoteattr(unique_name(obj, OB_ + obj.name, uuid_cache_object, clean_func=clean_def, sep="_"))
+        mesh_id = quoteattr(unique_name(mesh, ME_ + mesh.name, uuid_cache_mesh, clean_func=clean_def, sep="_"))
+        mesh_id_group = prefix_quoted_str(mesh_id, group_)
         mesh_id_coords = prefix_quoted_str(mesh_id, 'coords_')
         mesh_id_normals = prefix_quoted_str(mesh_id, 'normals_')
 
@@ -501,7 +538,7 @@
 
         # use _ifs_TRANSFORM suffix so we dont collide with transform node when
         # hierarchys are used.
-        ident = writeTransform_begin(ident, matrix, suffix_quoted_str(obj_id, "_ifs_TRANSFORM"))
+        ident = writeTransform_begin(ident, matrix, suffix_quoted_str(obj_id, "_ifs" + _TRANSFORM))
 
         if mesh.tag:
             fw('%s<Group USE=%s />\n' % (ident, mesh_id_group))
@@ -918,7 +955,7 @@
             fw('%s</Collision>\n' % ident)
 
     def writeMaterial(ident, material, world):
-        material_id = quoteattr(unique_name(material, 'MA_' + material.name, uuid_cache_material, clean_func=clean_def, sep="_"))
+        material_id = quoteattr(unique_name(material, MA_ + material.name, uuid_cache_material, clean_func=clean_def, sep="_"))
 
         # look up material name, use it if available
         if material.tag:
@@ -1084,7 +1121,7 @@
                     frag_uniform_var_map[uniform['varname']] = lamp_obj
 
                     if uniform['datatype'] == gpu.GPU_DATA_3F:  # should always be true!
-                        lamp_obj_id = quoteattr(unique_name(lamp_obj, 'LA_' + lamp_obj.name, uuid_cache_lamp, clean_func=clean_def, sep="_"))
+                        lamp_obj_id = quoteattr(unique_name(lamp_obj, LA_ + lamp_obj.name, uuid_cache_lamp, clean_func=clean_def, sep="_"))

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list