From: Mikko Rasa Date: Fri, 24 May 2019 15:27:50 +0000 (+0300) Subject: Try to simplify object names when exporting a scene X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=f1555f34a787949894025cce908f08ca3ff60633;p=libs%2Fgl.git Try to simplify object names when exporting a scene 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. --- diff --git a/blender/io_mspgl/export_scene.py b/blender/io_mspgl/export_scene.py index a0e41181..3b2147d1 100644 --- a/blender/io_mspgl/export_scene.py +++ b/blender/io_mspgl/export_scene.py @@ -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()