forked from bartvdbraak/blender
Collada: Added option for how rot,loc,trans data is exported (improves flexibility for support of other 3D tools)
This commit is contained in:
parent
65869589b6
commit
8664d4b98b
@ -36,9 +36,10 @@ void forEachObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set)
|
||||
}
|
||||
}
|
||||
|
||||
void AnimationExporter::exportAnimations(Scene *sce)
|
||||
bool AnimationExporter::exportAnimations(Scene *sce)
|
||||
{
|
||||
if (hasAnimations(sce)) {
|
||||
bool has_animations = hasAnimations(sce);
|
||||
if (has_animations) {
|
||||
this->scene = sce;
|
||||
|
||||
openLibrary();
|
||||
@ -47,6 +48,7 @@ void AnimationExporter::exportAnimations(Scene *sce)
|
||||
|
||||
closeLibrary();
|
||||
}
|
||||
return has_animations;
|
||||
}
|
||||
|
||||
// called for each exported object
|
||||
|
@ -98,7 +98,7 @@ public:
|
||||
{ this->sw = sw; }
|
||||
|
||||
|
||||
void exportAnimations(Scene *sce);
|
||||
bool exportAnimations(Scene *sce);
|
||||
|
||||
// called for each exported object
|
||||
void operator() (Object *ob);
|
||||
|
@ -266,7 +266,7 @@ void DocumentExporter::exportCurrentScene(Scene *sce)
|
||||
|
||||
// <library_animations>
|
||||
AnimationExporter ae(&sw, this->export_settings);
|
||||
ae.exportAnimations(sce);
|
||||
bool has_animations = ae.exportAnimations(sce);
|
||||
|
||||
// <library_controllers>
|
||||
ArmatureExporter arm_exporter(&sw, this->export_settings);
|
||||
@ -279,6 +279,19 @@ void DocumentExporter::exportCurrentScene(Scene *sce)
|
||||
// <library_visual_scenes>
|
||||
|
||||
SceneExporter se(&sw, &arm_exporter, this->export_settings);
|
||||
|
||||
if (has_animations && this->export_settings->export_transformation_type == BC_TRANSFORMATION_TYPE_MATRIX) {
|
||||
// channels adressing <matrix> objects is not (yet) supported
|
||||
// So we force usage of <location>, <translation> and <scale>
|
||||
fprintf(stdout,
|
||||
"For animated Ojects we must use decomposed <matrix> elements,\n" \
|
||||
"Forcing usage of TransLocRot transformation type.");
|
||||
se.setExportTransformationType(BC_TRANSFORMATION_TYPE_TRANSROTLOC);
|
||||
}
|
||||
else {
|
||||
se.setExportTransformationType(this->export_settings->export_transformation_type);
|
||||
}
|
||||
|
||||
se.exportScene(sce);
|
||||
|
||||
// <scene>
|
||||
|
@ -27,6 +27,7 @@
|
||||
#ifndef __EXPORTSETTINGS_H__
|
||||
#define __EXPORTSETTINGS_H__
|
||||
|
||||
#include "collada.h"
|
||||
#include "collada.h"
|
||||
|
||||
struct ExportSettings {
|
||||
@ -48,6 +49,7 @@ public:
|
||||
bool triangulate;
|
||||
bool use_object_instantiation;
|
||||
bool sort_by_name;
|
||||
BC_export_transformation_type export_transformation_type;
|
||||
bool second_life;
|
||||
|
||||
char *filepath;
|
||||
|
@ -36,7 +36,12 @@ SceneExporter::SceneExporter(COLLADASW::StreamWriter *sw, ArmatureExporter *arm,
|
||||
: COLLADASW::LibraryVisualScenes(sw), arm_exporter(arm), export_settings(export_settings)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SceneExporter::setExportTransformationType(BC_export_transformation_type transformation_type)
|
||||
{
|
||||
this->transformation_type = transformation_type;
|
||||
}
|
||||
|
||||
void SceneExporter::exportScene(Scene *sce)
|
||||
{
|
||||
// <library_visual_scenes> <visual_scene>
|
||||
@ -84,6 +89,7 @@ void SceneExporter::exportHierarchy(Scene *sce)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SceneExporter::writeNodes(Object *ob, Scene *sce)
|
||||
{
|
||||
// Add associated armature first if available
|
||||
@ -130,8 +136,9 @@ void SceneExporter::writeNodes(Object *ob, Scene *sce)
|
||||
if (ob->type == OB_MESH && armature_exported)
|
||||
// for skinned mesh we write obmat in <bind_shape_matrix>
|
||||
TransformWriter::add_node_transform_identity(colladaNode);
|
||||
else
|
||||
TransformWriter::add_node_transform_ob(colladaNode, ob);
|
||||
else {
|
||||
TransformWriter::add_node_transform_ob(colladaNode, ob, this->transformation_type);
|
||||
}
|
||||
|
||||
// <instance_geometry>
|
||||
if (ob->type == OB_MESH) {
|
||||
|
@ -97,8 +97,10 @@ class SceneExporter: COLLADASW::LibraryVisualScenes, protected TransformWriter,
|
||||
public:
|
||||
SceneExporter(COLLADASW::StreamWriter *sw, ArmatureExporter *arm, const ExportSettings *export_settings);
|
||||
void exportScene(Scene *sce);
|
||||
void setExportTransformationType(BC_export_transformation_type transformation_type);
|
||||
|
||||
private:
|
||||
BC_export_transformation_type transformation_type;
|
||||
// required for writeNodes() for bone-parented objects
|
||||
friend class ArmatureExporter;
|
||||
void exportHierarchy(Scene *sce);
|
||||
|
@ -51,13 +51,16 @@ void TransformWriter::add_node_transform(COLLADASW::Node& node, float mat[4][4],
|
||||
converter->mat4_to_dae_double(dmat, local);
|
||||
|
||||
TransformBase::decompose(local, loc, rot, NULL, scale);
|
||||
//if (node.getType() == COLLADASW::Node::JOINT)
|
||||
node.addMatrix("transform", dmat);
|
||||
//else
|
||||
//add_transform(node, loc, rot, scale);
|
||||
|
||||
if (node.getType() == COLLADASW::Node::JOINT) {
|
||||
// XXX Why are joints handled differently ?
|
||||
node.addMatrix("transform", dmat);
|
||||
}
|
||||
else
|
||||
add_transform(node, loc, rot, scale);
|
||||
}
|
||||
|
||||
void TransformWriter::add_node_transform_ob(COLLADASW::Node& node, Object *ob)
|
||||
void TransformWriter::add_node_transform_ob(COLLADASW::Node& node, Object *ob, BC_export_transformation_type transformation_type)
|
||||
{
|
||||
#if 0
|
||||
float rot[3], loc[3], scale[3];
|
||||
@ -114,8 +117,23 @@ void TransformWriter::add_node_transform_ob(COLLADASW::Node& node, Object *ob)
|
||||
|
||||
double d_obmat[4][4];
|
||||
converter.mat4_to_dae_double(d_obmat, ob->obmat);
|
||||
node.addMatrix("transform",d_obmat);
|
||||
//add_transform(node, ob->loc, ob->rot, ob->size);
|
||||
|
||||
switch (transformation_type) {
|
||||
case BC_TRANSFORMATION_TYPE_MATRIX : {
|
||||
node.addMatrix("transform",d_obmat);
|
||||
break;
|
||||
}
|
||||
case BC_TRANSFORMATION_TYPE_TRANSROTLOC: {
|
||||
add_transform(node, ob->loc, ob->rot, ob->size);
|
||||
break;
|
||||
}
|
||||
case BC_TRANSFORMATION_TYPE_BOTH : {
|
||||
node.addMatrix("transform",d_obmat);
|
||||
add_transform(node, ob->loc, ob->rot, ob->size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void TransformWriter::add_node_transform_identity(COLLADASW::Node& node)
|
||||
|
@ -33,13 +33,14 @@
|
||||
#include "DNA_object_types.h"
|
||||
|
||||
#include "collada_internal.h"
|
||||
#include "collada.h"
|
||||
|
||||
class TransformWriter : protected TransformBase
|
||||
{
|
||||
protected:
|
||||
void add_node_transform(COLLADASW::Node& node, float mat[4][4], float parent_mat[4][4]);
|
||||
|
||||
void add_node_transform_ob(COLLADASW::Node& node, Object *ob);
|
||||
void add_node_transform_ob(COLLADASW::Node& node, Object *ob, BC_export_transformation_type transformation_type);
|
||||
|
||||
void add_node_transform_identity(COLLADASW::Node& node);
|
||||
|
||||
|
@ -78,6 +78,7 @@ int collada_export(Scene *sce,
|
||||
int triangulate,
|
||||
int use_object_instantiation,
|
||||
int sort_by_name,
|
||||
BC_export_transformation_type export_transformation_type,
|
||||
int second_life)
|
||||
{
|
||||
ExportSettings export_settings;
|
||||
@ -107,10 +108,11 @@ int collada_export(Scene *sce,
|
||||
export_settings.include_material_textures= include_material_textures != 0;
|
||||
export_settings.use_texture_copies = use_texture_copies != 0;
|
||||
|
||||
export_settings.triangulate = triangulate != 0;
|
||||
export_settings.use_object_instantiation = use_object_instantiation != 0;
|
||||
export_settings.sort_by_name = sort_by_name != 0;
|
||||
export_settings.second_life = second_life != 0;
|
||||
export_settings.triangulate = triangulate != 0;
|
||||
export_settings.use_object_instantiation = use_object_instantiation != 0;
|
||||
export_settings.sort_by_name = sort_by_name != 0;
|
||||
export_settings.export_transformation_type = export_transformation_type;
|
||||
export_settings.second_life = second_life != 0;
|
||||
|
||||
|
||||
int includeFilter = OB_REL_NONE;
|
||||
|
@ -41,6 +41,12 @@ typedef enum BC_export_mesh_type {
|
||||
BC_MESH_TYPE_RENDER
|
||||
} BC_export_mesh_type;
|
||||
|
||||
typedef enum BC_export_transformation_type {
|
||||
BC_TRANSFORMATION_TYPE_MATRIX,
|
||||
BC_TRANSFORMATION_TYPE_TRANSROTLOC,
|
||||
BC_TRANSFORMATION_TYPE_BOTH
|
||||
} BC_export_transformation_type;
|
||||
|
||||
struct bContext;
|
||||
struct Scene;
|
||||
|
||||
@ -70,6 +76,7 @@ int collada_export(Scene *sce,
|
||||
int triangulate,
|
||||
int use_object_instantiation,
|
||||
int sort_by_name,
|
||||
BC_export_transformation_type export_transformation_type,
|
||||
int second_life);
|
||||
|
||||
|
||||
|
@ -95,6 +95,7 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
|
||||
int triangulate;
|
||||
int use_object_instantiation;
|
||||
int sort_by_name;
|
||||
int export_transformation_type;
|
||||
int second_life;
|
||||
|
||||
if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
|
||||
@ -119,10 +120,11 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
|
||||
use_texture_copies = RNA_boolean_get(op->ptr, "use_texture_copies");
|
||||
active_uv_only = RNA_boolean_get(op->ptr, "active_uv_only");
|
||||
|
||||
triangulate = RNA_boolean_get(op->ptr, "triangulate");
|
||||
use_object_instantiation = RNA_boolean_get(op->ptr, "use_object_instantiation");
|
||||
sort_by_name = RNA_boolean_get(op->ptr, "sort_by_name");
|
||||
second_life = RNA_boolean_get(op->ptr, "second_life");
|
||||
triangulate = RNA_boolean_get(op->ptr, "triangulate");
|
||||
use_object_instantiation = RNA_boolean_get(op->ptr, "use_object_instantiation");
|
||||
sort_by_name = RNA_boolean_get(op->ptr, "sort_by_name");
|
||||
export_transformation_type = RNA_enum_get(op->ptr, "export_transformation_type_selection");
|
||||
second_life = RNA_boolean_get(op->ptr, "second_life");
|
||||
|
||||
/* get editmode results */
|
||||
ED_object_exit_editmode(C, 0); /* 0 = does not exit editmode */
|
||||
@ -145,6 +147,7 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
|
||||
triangulate,
|
||||
use_object_instantiation,
|
||||
sort_by_name,
|
||||
export_transformation_type,
|
||||
second_life))
|
||||
{
|
||||
return OPERATOR_FINISHED;
|
||||
@ -224,6 +227,12 @@ static void uiCollada_exportSettings(uiLayout *layout, PointerRNA *imfptr)
|
||||
uiItemR(row, imfptr, "triangulate", 0, NULL, ICON_NONE);
|
||||
row = uiLayoutRow(box, FALSE);
|
||||
uiItemR(row, imfptr, "use_object_instantiation", 0, NULL, ICON_NONE);
|
||||
|
||||
row = uiLayoutRow(box, FALSE);
|
||||
split = uiLayoutSplit(row, 0.6f, UI_LAYOUT_ALIGN_RIGHT);
|
||||
uiItemL(split, IFACE_("Transformation Type"), ICON_NONE);
|
||||
uiItemR(split, imfptr, "export_transformation_type_selection", 0, "", ICON_NONE);
|
||||
|
||||
row = uiLayoutRow(box, FALSE);
|
||||
uiItemR(row, imfptr, "sort_by_name", 0, NULL, ICON_NONE);
|
||||
|
||||
@ -245,6 +254,13 @@ void WM_OT_collada_export(wmOperatorType *ot)
|
||||
{0, NULL, 0, NULL, NULL}
|
||||
};
|
||||
|
||||
static EnumPropertyItem prop_bc_export_transformation_type[] = {
|
||||
{BC_TRANSFORMATION_TYPE_MATRIX, "matrix", 0, "Matrix", "Use <matrix> to specify transformations"},
|
||||
{BC_TRANSFORMATION_TYPE_TRANSROTLOC, "transrotloc", 0, "TransRotLoc", "Use <translate>, <rotate>, <scale> to specify transformations"},
|
||||
{BC_TRANSFORMATION_TYPE_BOTH, "both", 0, "Both", "Use <matrix> AND <translate>, <rotate>, <scale> to specify transformations"},
|
||||
{0, NULL, 0, NULL, NULL}
|
||||
};
|
||||
|
||||
ot->name = "Export COLLADA";
|
||||
ot->description = "Save a Collada file";
|
||||
ot->idname = "WM_OT_collada_export";
|
||||
@ -308,6 +324,12 @@ void WM_OT_collada_export(wmOperatorType *ot)
|
||||
RNA_def_boolean(ot->srna, "sort_by_name", 0, "Sort by Object name",
|
||||
"Sort exported data by Object name");
|
||||
|
||||
RNA_def_int(ot->srna, "export_transformation_type", 0, INT_MIN, INT_MAX,
|
||||
"Transform", "Transformation type for translation, scale and rotation", INT_MIN, INT_MAX);
|
||||
|
||||
RNA_def_enum(ot->srna, "export_transformation_type_selection", prop_bc_export_transformation_type, 0,
|
||||
"Transform", "Transformation type for translation, scale and rotation");
|
||||
|
||||
RNA_def_boolean(ot->srna, "second_life", 0, "Export for Second Life",
|
||||
"Compatibility mode for Second Life");
|
||||
}
|
||||
|
@ -115,12 +115,13 @@ static void rna_Scene_collada_export(
|
||||
int use_ngons,
|
||||
int use_object_instantiation,
|
||||
int sort_by_name,
|
||||
int export_transformation_type,
|
||||
int second_life)
|
||||
{
|
||||
collada_export(scene, filepath, apply_modifiers, export_mesh_type, selected,
|
||||
include_children, include_armatures, include_shapekeys, deform_bones_only,
|
||||
active_uv_only, include_uv_textures, include_material_textures,
|
||||
use_texture_copies, use_ngons, use_object_instantiation, sort_by_name, second_life);
|
||||
use_texture_copies, use_ngons, use_object_instantiation, sort_by_name, export_transformation_type, second_life);
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -166,6 +167,10 @@ void RNA_api_scene(StructRNA *srna)
|
||||
parm = RNA_def_boolean(func, "use_object_instantiation", 1, "Use Object Instances", "Instantiate multiple Objects from same Data");
|
||||
parm = RNA_def_boolean(func, "sort_by_name", 0, "Sort by Object name", "Sort exported data by Object name");
|
||||
parm = RNA_def_boolean(func, "second_life", 0, "Export for Second Life", "Compatibility mode for Second Life");
|
||||
|
||||
parm = RNA_def_int(func, "export_transformation_type", 0, INT_MIN, INT_MAX,
|
||||
"Transformation", "Transformation type for translation, scale and rotation", INT_MIN, INT_MAX);
|
||||
|
||||
RNA_def_function_ui_description(func, "Export to collada file");
|
||||
#endif
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user