[#31607] Collada: (Exporter) Implementation of 'use Object Instantiation' Option
authorGaia Clary <gaia.clary@machinimatrix.org>
Sat, 26 May 2012 22:46:28 +0000 (22:46 +0000)
committerGaia Clary <gaia.clary@machinimatrix.org>
Sat, 26 May 2012 22:46:28 +0000 (22:46 +0000)
release/scripts/presets/operator/wm.collada_export/second_life.py
source/blender/collada/ArmatureExporter.cpp
source/blender/collada/ExportSettings.h
source/blender/collada/GeometryExporter.cpp
source/blender/collada/SceneExporter.cpp
source/blender/collada/collada.cpp
source/blender/collada/collada.h
source/blender/collada/collada_internal.cpp
source/blender/collada/collada_internal.h
source/blender/makesrna/intern/rna_scene_api.c
source/blender/windowmanager/intern/wm_operators.c

index 5e04903470bd9d32e707b0a32c3baefdef11a770..151c4e556529b40d39c00c1a723294e31d9a93d9 100644 (file)
@@ -4,4 +4,5 @@ op = bpy.context.active_operator
 op.selected = True
 op.apply_modifiers = True
 op.include_bone_children = False
+op.use_object_instantiation = False
 op.second_life = True
index 38a5e9b5df4d22d06d8cffaf012d90423e12f9a3..9d59be39f33d817dd4a0441cd69c33ee51b03737 100644 (file)
@@ -324,6 +324,7 @@ void ArmatureExporter::export_controller(Object* ob, Object *ob_arm)
        } MDeformWeight;
        */
 
+       bool use_instantiation = this->export_settings->use_object_instantiation;
        Mesh *me = (Mesh*)ob->data;
        if (!me->dvert) return;
 
@@ -331,7 +332,7 @@ void ArmatureExporter::export_controller(Object* ob, Object *ob_arm)
        std::string controller_id = get_controller_id(ob_arm, ob);
 
        openSkin(controller_id, controller_name,
-                COLLADABU::URI(COLLADABU::Utils::EMPTY_STRING, get_geometry_id(ob)));
+                COLLADABU::URI(COLLADABU::Utils::EMPTY_STRING, get_geometry_id(ob, use_instantiation)));
 
        add_bind_shape_mat(ob);
 
index b875282ac336495025f7b0dbdfbd1a5f3d887be6..f0d3f8108310d62b6746f165aee0dc6ac326c1ba 100644 (file)
@@ -33,6 +33,7 @@ struct ExportSettings
  bool selected;
  bool apply_modifiers;
  bool include_bone_children;
+ bool use_object_instantiation;
  bool second_life;
  char *filepath;
 };
index f92ee1a2b792269aeabd111445cb527e2e9f8c0c..6df16165e4b1212e2a7981dceeef07e0a2d3cb63 100644 (file)
@@ -92,16 +92,20 @@ void GeometryExporter::operator()(Object *ob)
        DerivedMesh *dm = mesh_get_derived_final(mScene, ob, CD_MASK_BAREMESH);
 #endif
 
+       bool use_instantiation = this->export_settings->use_object_instantiation;
        Mesh *me = get_mesh(ob, this->export_settings->apply_modifiers);
 
-       std::string geom_id = get_geometry_id(ob);
-       std::string geom_name = id_name(ob->data);
+       std::string geom_id = get_geometry_id(ob, use_instantiation);
        std::vector<Normal> nor;
        std::vector<Face> norind;
 
        // Skip if linked geometry was already exported from another reference
-       if (exportedGeometry.find(geom_id) != exportedGeometry.end())
+       if (use_instantiation && 
+               exportedGeometry.find(geom_id) != exportedGeometry.end())
                return;
+
+       std::string geom_name = (use_instantiation) ? id_name(ob->data) : id_name(ob);
+
        exportedGeometry.insert(geom_id);
 
        bool has_color = (bool)CustomData_has_layer(&me->fdata, CD_MCOL);
index f79ae2b52a9e42c9cde04e56d0bee7cf8d008474..83ac496db0e9541c0dff1566b45ff1a4e3e66174 100644 (file)
@@ -117,7 +117,7 @@ void SceneExporter::writeNodes(Object *ob, Scene *sce)
                }
                else {
                        COLLADASW::InstanceGeometry instGeom(mSW);
-                       instGeom.setUrl(COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, get_geometry_id(ob)));
+                       instGeom.setUrl(COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, get_geometry_id(ob, this->export_settings->use_object_instantiation)));
 
                        InstanceWriter::add_material_bindings(instGeom.getBindMaterial(), ob);
 
index c947144412a7de912838e3cd260f2d4fea3945a4..951fecec0493a172734f039ed9a3acc0bc3ea5a9 100644 (file)
@@ -55,6 +55,7 @@ extern "C"
                int selected,
                int apply_modifiers,
                int include_bone_children,
+               int use_object_instantiation,
                int second_life)
        {
                ExportSettings export_settings;
@@ -63,6 +64,7 @@ extern "C"
                export_settings.apply_modifiers          = apply_modifiers != 0;
                export_settings.include_bone_children    = include_bone_children != 0;
                export_settings.second_life              = second_life != 0;
+               export_settings.use_object_instantiation = use_object_instantiation != 0;
                export_settings.filepath                 = (char *)filepath;
 
                /* annoying, collada crashes if file cant be created! [#27162] */
index d5c26bb402cb897d3e5f281d91b8fb8f0473b8f7..67aaf1ff6c7c27189e57e3f0031cffba04c68313 100644 (file)
@@ -43,6 +43,7 @@ extern "C" {
                int selected,
                int apply_modifiers,
                int include_bone_children,
+               int use_object_instantiation,
                int second_life);
 #ifdef __cplusplus
 }
index fa99d460184a2a6460b4a5ec4b39665b66a59804..81e5f88a3f8bdc714a1d09bd96ff9310fa3b8b8a 100644 (file)
@@ -251,6 +251,13 @@ std::string get_geometry_id(Object *ob)
        return translate_id(id_name(ob->data)) + "-mesh";
 }
 
+std::string get_geometry_id(Object *ob, bool use_instantiation)
+{
+       std::string geom_name = (use_instantiation) ? id_name(ob->data) : id_name(ob);
+
+       return translate_id(geom_name) + "-mesh";
+}
+
 std::string get_light_id(Object *ob)
 {
        return translate_id(id_name(ob)) + "-light";
index 4f555acb882919b1e9dd04d639763b074af4b051..d00af791a1fe0f7248809ef32e8f5b61e37e17cf 100644 (file)
@@ -86,7 +86,7 @@ extern std::string translate_id(const std::string &id);
 
 extern std::string id_name(void *id);
 
-extern std::string get_geometry_id(Object *ob);
+extern std::string get_geometry_id(Object *ob, bool use_instantiation);
 
 extern std::string get_light_id(Object *ob);
 
index 439335e69b4f8527b3295ed8a1886e6c2feb9ba3..09e0428058a83d90042ab0da8aabc03b717b092b 100644 (file)
@@ -91,9 +91,10 @@ static void rna_Scene_collada_export(
        int selected,
        int apply_modifiers,
        int include_bone_children,
+       int use_object_instantiation,
        int second_life)
 {
-       collada_export(scene, filepath, selected, apply_modifiers, include_bone_children, second_life);
+       collada_export(scene, filepath, selected, apply_modifiers, include_bone_children, use_object_instantiation, second_life);
 }
 
 #endif
@@ -124,6 +125,7 @@ void RNA_api_scene(StructRNA *srna)
        parm = RNA_def_boolean(func, "selected", 0, "Selection Only", "Export only selected elements");
        parm = RNA_def_boolean(func, "apply_modifiers", 0, "Apply Modifiers", "Apply modifiers (in Preview resolution)");
        parm = RNA_def_boolean(func, "include_bone_children", 0, "Include Bone Children", "Include all objects attached to bones of selected Armature(s)");
+       parm = RNA_def_boolean(func, "use_object_instantiation", 1, "Use Object Instantiation", "Instantiate multiple Objects from same Data");
        parm = RNA_def_boolean(func, "second_life", 0, "Export for Second Life", "Compatibility mode for Second Life");
        RNA_def_function_ui_description(func, "Export to collada file");
 #endif
index 05af3c045730a7e334145261425a577db4757b7a..8ce882e887ebcd2d58a93f4b01068c42e0f91f22 100644 (file)
@@ -2155,7 +2155,7 @@ static int wm_collada_export_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED
 static int wm_collada_export_exec(bContext *C, wmOperator *op)
 {
        char filename[FILE_MAX];
-       int selected, second_life, apply_modifiers, include_bone_children;
+       int selected, second_life, apply_modifiers, include_bone_children, use_object_instantiation;
        
        if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
                BKE_report(op->reports, RPT_ERROR, "No filename given");
@@ -2165,11 +2165,11 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
        RNA_string_get(op->ptr, "filepath", filename);
 
        /* Options panel */
-       selected              = RNA_boolean_get(op->ptr, "selected");
-       apply_modifiers       = RNA_boolean_get(op->ptr, "apply_modifiers");
-    include_bone_children = RNA_boolean_get(op->ptr, "include_bone_children");
-
-       second_life           = RNA_boolean_get(op->ptr, "second_life");
+       selected                 = RNA_boolean_get(op->ptr, "selected");
+       apply_modifiers          = RNA_boolean_get(op->ptr, "apply_modifiers");
+    include_bone_children    = RNA_boolean_get(op->ptr, "include_bone_children");
+    use_object_instantiation = RNA_boolean_get(op->ptr, "use_object_instantiation");
+       second_life              = RNA_boolean_get(op->ptr, "second_life");
 
        /* get editmode results */
        ED_object_exit_editmode(C, 0);  /* 0 = does not exit editmode */
@@ -2180,6 +2180,7 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
                selected,
                apply_modifiers,
                include_bone_children,
+               use_object_instantiation,
                second_life)) {
                return OPERATOR_FINISHED;
        }
@@ -2211,6 +2212,9 @@ static void WM_OT_collada_export(wmOperatorType *ot)
        RNA_def_boolean(ot->srna, "include_bone_children", 0, "Include Bone Children",
                        "Include all objects attached to bones of selected Armature(s)");
 
+       RNA_def_boolean(ot->srna, "use_object_instantiation", 1, "Use Object Instantiation",
+                           "Instantiate multiple Objects from same Data");
+
        RNA_def_boolean(ot->srna, "second_life", 0, "Export for Second Life",
                        "Compatibility mode for Second Life");
 }