Page MenuHome

collada-fix-boneasparent.patch

collada-fix-boneasparent.patch

Index: source/blender/collada/SceneExporter.cpp
===================================================================
--- source/blender/collada/SceneExporter.cpp (revision 44040)
+++ source/blender/collada/SceneExporter.cpp (working copy)
@@ -70,6 +70,10 @@
void SceneExporter::writeNodes(Object *ob, Scene *sce)
{
+ // skip nodes with bone as parent, they will be exported during armature export as child of the bone
+ // (TODO: could be done with COLLADA node instancing, but would probably break poor COLLADA implementations)
+ if (ob->partype==PARBONE) return;
+
COLLADASW::Node node(mSW);
node.setNodeId(translate_id(id_name(ob)));
node.setType(COLLADASW::Node::NODE);
Index: source/blender/collada/ArmatureExporter.cpp
===================================================================
--- source/blender/collada/ArmatureExporter.cpp (revision 44040)
+++ source/blender/collada/ArmatureExporter.cpp (working copy)
@@ -28,6 +28,7 @@
#include "COLLADASWBaseInputElement.h"
#include "COLLADASWInstanceController.h"
+#include "COLLADASWInstanceGeometry.h"
#include "COLLADASWPrimitves.h"
#include "COLLADASWSource.h"
@@ -37,6 +38,7 @@
#include "BKE_action.h"
#include "BKE_armature.h"
+#include "BKE_object.h"
#include "ED_armature.h"
#include "BLI_listbase.h"
@@ -57,7 +59,7 @@
for (Bone *bone = (Bone*)arm->bonebase.first; bone; bone = bone->next) {
// start from root bones
if (!bone->parent)
- add_bone_node(bone, ob_arm);
+ add_bone_node(bone, ob_arm,sce);
}
}
@@ -162,8 +164,87 @@
return get_joint_id(bone, ob_arm);
}
+void ArmatureExporter::write_nodes_with_bone_as_parent(Scene *sce, Object *arm, Bone *bone)
+{
+ Base *b = (Base*) sce->base.first;
+ while (b)
+ {
+ Object *ob = b->object;
+ if (ob && ob->partype==PARBONE && 0==strcmp(bone->name,ob->parsubstr))
+ {
+ COLLADASW::Node node(mSW);
+ node.setNodeId(translate_id(id_name(ob)));
+ node.setType(COLLADASW::Node::NODE);
+ node.start();
+
+ // transform the node into bonespace
+
+ float boneInverse[4][4];
+ bPoseChannel* pchan = get_pose_channel(arm->pose,ob->parsubstr);
+ if (pchan)
+ invert_m4_m4(boneInverse,pchan->pose_mat);
+ else
+ unit_m4(boneInverse);
+
+ UnitConverter converter;
+ double dmat[4][4];
+
+ bool bake = true;
+
+ // TODO: make baking a setting
+ if (bake)
+ {
+ float obTrans[4][4];
+ unit_m4(obTrans);
+ translate_m4(obTrans,ob->loc[0],ob->loc[1],ob->loc[2]);
+
+ float obRotZ[4][4];
+ unit_m4(obRotZ);
+ rotate_m4(obRotZ,'Z',ob->rot[2]);
+
+ float obRotY[4][4];
+ unit_m4(obRotY);
+ rotate_m4(obRotY,'Y',ob->rot[1]);
+
+ float obRotX[4][4];
+ unit_m4(obRotX);
+ rotate_m4(obRotX,'X',ob->rot[0]);
+
+ float obScale[4][4];
+ unit_m4(obScale);
+ obScale[0][0] = ob->size[0];
+ obScale[1][1] = ob->size[1];
+ obScale[2][2] = ob->size[2];
+
+ float trfm[4][4];
+ mul_serie_m4(trfm,boneInverse,obTrans,obRotX,obRotY,obRotZ,obScale,0,0);
+ converter.mat4_to_dae_double(dmat, trfm);
+ node.addMatrix(dmat);
+ }
+ else
+ {
+ converter.mat4_to_dae_double(dmat, boneInverse);
+ node.addMatrix(dmat);
+ TransformWriter::add_node_transform_ob(node, ob);
+ }
+
+ if (ob->type == OB_MESH)
+ {
+ COLLADASW::InstanceGeometry instGeom(mSW);
+ instGeom.setUrl(COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, get_geometry_id(ob)));
+ InstanceWriter::add_material_bindings(instGeom.getBindMaterial(), ob);
+ instGeom.add();
+ }
+ // TODO: other object types additional data (attach light, camera, etc. to bone)
+
+ node.end();
+ }
+ b = b->next;
+ }
+}
+
// parent_mat is armature-space
-void ArmatureExporter::add_bone_node(Bone *bone, Object *ob_arm)
+void ArmatureExporter::add_bone_node(Bone *bone, Object *ob_arm, Scene *sce)
{
std::string node_id = get_joint_id(bone, ob_arm);
std::string node_name = std::string(bone->name);
@@ -184,8 +265,12 @@
add_bone_transform(ob_arm, bone, node);
for (Bone *child = (Bone*)bone->childbase.first; child; child = child->next) {
- add_bone_node(child, ob_arm);
+ add_bone_node(child, ob_arm,sce);
}
+
+ /* write all nodes with partype=PARBONE */
+ write_nodes_with_bone_as_parent(sce,ob_arm,bone);
+
node.end();
//}
}
@@ -201,7 +286,7 @@
node.addExtraTechniqueParameter("blender", "tip_z", bone->tail[2] );
for (Bone *child = (Bone*)bone->childbase.first; child; child = child->next) {
- add_bone_node(child, ob_arm);
+ add_bone_node(child, ob_arm,0);
}
node.end();
Index: source/blender/collada/ArmatureExporter.h
===================================================================
--- source/blender/collada/ArmatureExporter.h (revision 44040)
+++ source/blender/collada/ArmatureExporter.h (working copy)
@@ -85,8 +85,11 @@
std::string get_joint_sid(Bone *bone, Object *ob_arm);
+ // write nodes attached to bones
+ void write_nodes_with_bone_as_parent(Scene* sce, Object* arm, Bone* bone);
+
// parent_mat is armature-space
- void add_bone_node(Bone *bone, Object *ob_arm);
+ void add_bone_node(Bone *bone, Object *ob_arm, Scene* sce);
void add_bone_transform(Object *ob_arm, Bone *bone, COLLADASW::Node& node);

File Metadata

Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
04/92/72188a4df5cc35857bef74f7a32d

Event Timeline