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;
|
this->scene = sce;
|
||||||
|
|
||||||
openLibrary();
|
openLibrary();
|
||||||
@ -47,6 +48,7 @@ void AnimationExporter::exportAnimations(Scene *sce)
|
|||||||
|
|
||||||
closeLibrary();
|
closeLibrary();
|
||||||
}
|
}
|
||||||
|
return has_animations;
|
||||||
}
|
}
|
||||||
|
|
||||||
// called for each exported object
|
// called for each exported object
|
||||||
|
@ -98,7 +98,7 @@ public:
|
|||||||
{ this->sw = sw; }
|
{ this->sw = sw; }
|
||||||
|
|
||||||
|
|
||||||
void exportAnimations(Scene *sce);
|
bool exportAnimations(Scene *sce);
|
||||||
|
|
||||||
// called for each exported object
|
// called for each exported object
|
||||||
void operator() (Object *ob);
|
void operator() (Object *ob);
|
||||||
|
@ -266,7 +266,7 @@ void DocumentExporter::exportCurrentScene(Scene *sce)
|
|||||||
|
|
||||||
// <library_animations>
|
// <library_animations>
|
||||||
AnimationExporter ae(&sw, this->export_settings);
|
AnimationExporter ae(&sw, this->export_settings);
|
||||||
ae.exportAnimations(sce);
|
bool has_animations = ae.exportAnimations(sce);
|
||||||
|
|
||||||
// <library_controllers>
|
// <library_controllers>
|
||||||
ArmatureExporter arm_exporter(&sw, this->export_settings);
|
ArmatureExporter arm_exporter(&sw, this->export_settings);
|
||||||
@ -279,6 +279,19 @@ void DocumentExporter::exportCurrentScene(Scene *sce)
|
|||||||
// <library_visual_scenes>
|
// <library_visual_scenes>
|
||||||
|
|
||||||
SceneExporter se(&sw, &arm_exporter, this->export_settings);
|
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);
|
se.exportScene(sce);
|
||||||
|
|
||||||
// <scene>
|
// <scene>
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#ifndef __EXPORTSETTINGS_H__
|
#ifndef __EXPORTSETTINGS_H__
|
||||||
#define __EXPORTSETTINGS_H__
|
#define __EXPORTSETTINGS_H__
|
||||||
|
|
||||||
|
#include "collada.h"
|
||||||
#include "collada.h"
|
#include "collada.h"
|
||||||
|
|
||||||
struct ExportSettings {
|
struct ExportSettings {
|
||||||
@ -48,6 +49,7 @@ public:
|
|||||||
bool triangulate;
|
bool triangulate;
|
||||||
bool use_object_instantiation;
|
bool use_object_instantiation;
|
||||||
bool sort_by_name;
|
bool sort_by_name;
|
||||||
|
BC_export_transformation_type export_transformation_type;
|
||||||
bool second_life;
|
bool second_life;
|
||||||
|
|
||||||
char *filepath;
|
char *filepath;
|
||||||
|
@ -37,6 +37,11 @@ SceneExporter::SceneExporter(COLLADASW::StreamWriter *sw, ArmatureExporter *arm,
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SceneExporter::setExportTransformationType(BC_export_transformation_type transformation_type)
|
||||||
|
{
|
||||||
|
this->transformation_type = transformation_type;
|
||||||
|
}
|
||||||
|
|
||||||
void SceneExporter::exportScene(Scene *sce)
|
void SceneExporter::exportScene(Scene *sce)
|
||||||
{
|
{
|
||||||
// <library_visual_scenes> <visual_scene>
|
// <library_visual_scenes> <visual_scene>
|
||||||
@ -84,6 +89,7 @@ void SceneExporter::exportHierarchy(Scene *sce)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SceneExporter::writeNodes(Object *ob, Scene *sce)
|
void SceneExporter::writeNodes(Object *ob, Scene *sce)
|
||||||
{
|
{
|
||||||
// Add associated armature first if available
|
// Add associated armature first if available
|
||||||
@ -130,8 +136,9 @@ void SceneExporter::writeNodes(Object *ob, Scene *sce)
|
|||||||
if (ob->type == OB_MESH && armature_exported)
|
if (ob->type == OB_MESH && armature_exported)
|
||||||
// for skinned mesh we write obmat in <bind_shape_matrix>
|
// for skinned mesh we write obmat in <bind_shape_matrix>
|
||||||
TransformWriter::add_node_transform_identity(colladaNode);
|
TransformWriter::add_node_transform_identity(colladaNode);
|
||||||
else
|
else {
|
||||||
TransformWriter::add_node_transform_ob(colladaNode, ob);
|
TransformWriter::add_node_transform_ob(colladaNode, ob, this->transformation_type);
|
||||||
|
}
|
||||||
|
|
||||||
// <instance_geometry>
|
// <instance_geometry>
|
||||||
if (ob->type == OB_MESH) {
|
if (ob->type == OB_MESH) {
|
||||||
|
@ -97,8 +97,10 @@ class SceneExporter: COLLADASW::LibraryVisualScenes, protected TransformWriter,
|
|||||||
public:
|
public:
|
||||||
SceneExporter(COLLADASW::StreamWriter *sw, ArmatureExporter *arm, const ExportSettings *export_settings);
|
SceneExporter(COLLADASW::StreamWriter *sw, ArmatureExporter *arm, const ExportSettings *export_settings);
|
||||||
void exportScene(Scene *sce);
|
void exportScene(Scene *sce);
|
||||||
|
void setExportTransformationType(BC_export_transformation_type transformation_type);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
BC_export_transformation_type transformation_type;
|
||||||
// required for writeNodes() for bone-parented objects
|
// required for writeNodes() for bone-parented objects
|
||||||
friend class ArmatureExporter;
|
friend class ArmatureExporter;
|
||||||
void exportHierarchy(Scene *sce);
|
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);
|
converter->mat4_to_dae_double(dmat, local);
|
||||||
|
|
||||||
TransformBase::decompose(local, loc, rot, NULL, scale);
|
TransformBase::decompose(local, loc, rot, NULL, scale);
|
||||||
//if (node.getType() == COLLADASW::Node::JOINT)
|
|
||||||
|
if (node.getType() == COLLADASW::Node::JOINT) {
|
||||||
|
// XXX Why are joints handled differently ?
|
||||||
node.addMatrix("transform", dmat);
|
node.addMatrix("transform", dmat);
|
||||||
//else
|
}
|
||||||
//add_transform(node, loc, rot, scale);
|
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
|
#if 0
|
||||||
float rot[3], loc[3], scale[3];
|
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];
|
double d_obmat[4][4];
|
||||||
converter.mat4_to_dae_double(d_obmat, ob->obmat);
|
converter.mat4_to_dae_double(d_obmat, ob->obmat);
|
||||||
|
|
||||||
|
switch (transformation_type) {
|
||||||
|
case BC_TRANSFORMATION_TYPE_MATRIX : {
|
||||||
node.addMatrix("transform",d_obmat);
|
node.addMatrix("transform",d_obmat);
|
||||||
//add_transform(node, ob->loc, ob->rot, ob->size);
|
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)
|
void TransformWriter::add_node_transform_identity(COLLADASW::Node& node)
|
||||||
|
@ -33,13 +33,14 @@
|
|||||||
#include "DNA_object_types.h"
|
#include "DNA_object_types.h"
|
||||||
|
|
||||||
#include "collada_internal.h"
|
#include "collada_internal.h"
|
||||||
|
#include "collada.h"
|
||||||
|
|
||||||
class TransformWriter : protected TransformBase
|
class TransformWriter : protected TransformBase
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
void add_node_transform(COLLADASW::Node& node, float mat[4][4], float parent_mat[4][4]);
|
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);
|
void add_node_transform_identity(COLLADASW::Node& node);
|
||||||
|
|
||||||
|
@ -78,6 +78,7 @@ int collada_export(Scene *sce,
|
|||||||
int triangulate,
|
int triangulate,
|
||||||
int use_object_instantiation,
|
int use_object_instantiation,
|
||||||
int sort_by_name,
|
int sort_by_name,
|
||||||
|
BC_export_transformation_type export_transformation_type,
|
||||||
int second_life)
|
int second_life)
|
||||||
{
|
{
|
||||||
ExportSettings export_settings;
|
ExportSettings export_settings;
|
||||||
@ -110,6 +111,7 @@ int collada_export(Scene *sce,
|
|||||||
export_settings.triangulate = triangulate != 0;
|
export_settings.triangulate = triangulate != 0;
|
||||||
export_settings.use_object_instantiation = use_object_instantiation != 0;
|
export_settings.use_object_instantiation = use_object_instantiation != 0;
|
||||||
export_settings.sort_by_name = sort_by_name != 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;
|
export_settings.second_life = second_life != 0;
|
||||||
|
|
||||||
|
|
||||||
|
@ -41,6 +41,12 @@ typedef enum BC_export_mesh_type {
|
|||||||
BC_MESH_TYPE_RENDER
|
BC_MESH_TYPE_RENDER
|
||||||
} BC_export_mesh_type;
|
} 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 bContext;
|
||||||
struct Scene;
|
struct Scene;
|
||||||
|
|
||||||
@ -70,6 +76,7 @@ int collada_export(Scene *sce,
|
|||||||
int triangulate,
|
int triangulate,
|
||||||
int use_object_instantiation,
|
int use_object_instantiation,
|
||||||
int sort_by_name,
|
int sort_by_name,
|
||||||
|
BC_export_transformation_type export_transformation_type,
|
||||||
int second_life);
|
int second_life);
|
||||||
|
|
||||||
|
|
||||||
|
@ -95,6 +95,7 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
|
|||||||
int triangulate;
|
int triangulate;
|
||||||
int use_object_instantiation;
|
int use_object_instantiation;
|
||||||
int sort_by_name;
|
int sort_by_name;
|
||||||
|
int export_transformation_type;
|
||||||
int second_life;
|
int second_life;
|
||||||
|
|
||||||
if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
|
if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
|
||||||
@ -122,6 +123,7 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
|
|||||||
triangulate = RNA_boolean_get(op->ptr, "triangulate");
|
triangulate = RNA_boolean_get(op->ptr, "triangulate");
|
||||||
use_object_instantiation = RNA_boolean_get(op->ptr, "use_object_instantiation");
|
use_object_instantiation = RNA_boolean_get(op->ptr, "use_object_instantiation");
|
||||||
sort_by_name = RNA_boolean_get(op->ptr, "sort_by_name");
|
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");
|
second_life = RNA_boolean_get(op->ptr, "second_life");
|
||||||
|
|
||||||
/* get editmode results */
|
/* get editmode results */
|
||||||
@ -145,6 +147,7 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
|
|||||||
triangulate,
|
triangulate,
|
||||||
use_object_instantiation,
|
use_object_instantiation,
|
||||||
sort_by_name,
|
sort_by_name,
|
||||||
|
export_transformation_type,
|
||||||
second_life))
|
second_life))
|
||||||
{
|
{
|
||||||
return OPERATOR_FINISHED;
|
return OPERATOR_FINISHED;
|
||||||
@ -224,6 +227,12 @@ static void uiCollada_exportSettings(uiLayout *layout, PointerRNA *imfptr)
|
|||||||
uiItemR(row, imfptr, "triangulate", 0, NULL, ICON_NONE);
|
uiItemR(row, imfptr, "triangulate", 0, NULL, ICON_NONE);
|
||||||
row = uiLayoutRow(box, FALSE);
|
row = uiLayoutRow(box, FALSE);
|
||||||
uiItemR(row, imfptr, "use_object_instantiation", 0, NULL, ICON_NONE);
|
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);
|
row = uiLayoutRow(box, FALSE);
|
||||||
uiItemR(row, imfptr, "sort_by_name", 0, NULL, ICON_NONE);
|
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}
|
{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->name = "Export COLLADA";
|
||||||
ot->description = "Save a Collada file";
|
ot->description = "Save a Collada file";
|
||||||
ot->idname = "WM_OT_collada_export";
|
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",
|
RNA_def_boolean(ot->srna, "sort_by_name", 0, "Sort by Object name",
|
||||||
"Sort exported data 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",
|
RNA_def_boolean(ot->srna, "second_life", 0, "Export for Second Life",
|
||||||
"Compatibility mode for Second Life");
|
"Compatibility mode for Second Life");
|
||||||
}
|
}
|
||||||
|
@ -115,12 +115,13 @@ static void rna_Scene_collada_export(
|
|||||||
int use_ngons,
|
int use_ngons,
|
||||||
int use_object_instantiation,
|
int use_object_instantiation,
|
||||||
int sort_by_name,
|
int sort_by_name,
|
||||||
|
int export_transformation_type,
|
||||||
int second_life)
|
int second_life)
|
||||||
{
|
{
|
||||||
collada_export(scene, filepath, apply_modifiers, export_mesh_type, selected,
|
collada_export(scene, filepath, apply_modifiers, export_mesh_type, selected,
|
||||||
include_children, include_armatures, include_shapekeys, deform_bones_only,
|
include_children, include_armatures, include_shapekeys, deform_bones_only,
|
||||||
active_uv_only, include_uv_textures, include_material_textures,
|
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
|
#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, "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, "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_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");
|
RNA_def_function_ui_description(func, "Export to collada file");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user