]> git.tdb.fi Git - libs/gl.git/commitdiff
Try to simplify object names when exporting a scene
authorMikko Rasa <tdb@tdb.fi>
Fri, 24 May 2019 15:27:50 +0000 (18:27 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 24 May 2019 15:35:57 +0000 (18:35 +0300)
The exporter now tries to find the longest common prefix for objects
sharing the same prototype and exports the prototype using that name.
This avoids having randomly numbered object names.

blender/io_mspgl/export_scene.py

index a0e4118118967e41a60ef50654c248beab6fb0a8..3b2147d14d061b64352602aac8bf19a987f2019a 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,16 @@ class SceneExporter:
 
                                        clones.append(u)
 
+                       prefix = o.name
+                       for c in clones:
+                               for i in range(min(len(c.name), len(prefix))):
+                                       if c.name[i]!=prefix[i]:
+                                               prefix = prefix[:i]
+                                               break
+
+                       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 +56,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()