[#31607] Collada: (Exporter) Implementation of 'use Object Instantiation' Option
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ struct ExportSettings
|
||||
bool selected;
|
||||
bool apply_modifiers;
|
||||
bool include_bone_children;
|
||||
bool use_object_instantiation;
|
||||
bool second_life;
|
||||
char *filepath;
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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] */
|
||||
|
||||
@@ -43,6 +43,7 @@ extern "C" {
|
||||
int selected,
|
||||
int apply_modifiers,
|
||||
int include_bone_children,
|
||||
int use_object_instantiation,
|
||||
int second_life);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user