]> git.tdb.fi Git - libs/gl.git/blobdiff - blender/io_mspgl/export_scene.py
Better naming algorithm for objects in scene export
[libs/gl.git] / blender / io_mspgl / export_scene.py
index a0e4118118967e41a60ef50654c248beab6fb0a8..245d2d3efeef77db689367a2667e7eb16e341d1d 100644 (file)
@@ -18,6 +18,7 @@ class SceneExporter:
 
                object_prototypes = {}
                unique_objects = []
+               export_names = {}
                for o in objs:
                        if o.name in object_prototypes:
                                continue
@@ -36,6 +37,17 @@ class SceneExporter:
 
                                        clones.append(u)
 
+                       prefix = o.name
+                       for c in clones:
+                               while not c.name.startswith(prefix):
+                                       pos = max(prefix.rfind(' '), prefix.rfind('.'))
+                                       if pos<0:
+                                               break;
+                                       prefix = prefix[:pos]
+
+                       if prefix:
+                               export_names[o.name+".object"] = prefix.strip(" .")+".object"
+
                        unique_objects.append(o)
                        for c in clones:
                                object_prototypes[c.name] = o
@@ -45,6 +57,9 @@ class SceneExporter:
 
                resources = {}
                self.export_scene_resources(context, unique_objects, resources, progress)
+               for n, r in resources.items():
+                       if r.name in export_names:
+                               r.name = export_names[r.name]
 
                scene_res = self.export_scene(context, objs, progress, prototypes=object_prototypes, resources=resources)
                refs = scene_res.collect_references()
@@ -94,7 +109,7 @@ class SceneExporter:
 
                for o in objs:
                        obj_res = resources[prototypes[o.name].name+".object"]
-                       st = scene_res.create_reference_statement("object", obj_res)
+                       st = scene_res.create_reference_statement("object", obj_res, o.name)
                        # XXX Parent relationships screw up the location and rotation
                        st.sub.append(Statement("position", o.location[0], o.location[1], o.location[2]))
                        if o.rotation_mode=="AXIS_ANGLE":