]> 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 d4e6b78f021154cba46388c53cc2c28ad5f1cf1b..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()
@@ -54,7 +69,8 @@ class SceneExporter:
                        keywords = { ".mat": "material",
                                ".mesh": "mesh",
                                ".object": "object",
-                               ".tech": "technique" }
+                               ".tech": "technique",
+                               ".tex2d": "texture2d" }
                        with open(os.path.join(path, base+"_resources.mdc"), "w") as res_out:
                                for r in refs:
                                        st = Statement(keywords[os.path.splitext(r.name)[1]], r.name)
@@ -78,9 +94,11 @@ class SceneExporter:
                object_export = ObjectExporter()
                object_export.single_file = False
 
+               material_maps = {}
+
                for i, o in enumerate(objs):
                        progress.push_task_slice(o.name, i, len(objs))
-                       object_export.export_object_resources(context, o, resources, progress)
+                       object_export.export_object_resources(context, o, resources, progress, material_maps=material_maps)
                        obj_name = o.name+".object"
                        resources[obj_name] = object_export.export_object(context, o, progress, resources=resources)
                        progress.pop_task()
@@ -91,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":