.net - Bind Poses, Joint Transforms in Collada -
i'm trying export custom 3d model format collada. i've built collada data classes through xsd , problems come when try fill them data, concerns matrices.
my skeleton class array of joint classes read binary file , every joint looks (values of traslation , rotation relative parent joint, or root if there no parent, always):
class joint { list<joint> children; quaternion rotation; joint parent; string name; uint32 id; vector3 traslation; }
the first thing build joint nodes in "library_visual_scenes" section of file. quite simple , correct results:
foreach (joint joint in hierarchicaljoints) writejointnodes(joint); private void writejointnodes(joint joint) { vector3 rotationeulers = quaternion.toeulers(joint.rotation, eulersorder.zyx); writestartelement("node"); writeattributestring("id", string.concat(joint.name, "_id")); writeattributestring("type", "joint"); writeattributestring("name", joint.name); { writeelementstring("translate", bone.traslation); writeelementstringattributes("rotate", string.concat("0.0 0.0 1.0 ", rotation.z.todegrees()), { "sid", "rotatez" }); writeelementstringattributes("rotate", string.concat("0.0 1.0 0.0 ", rotation.y.todegrees()), { "sid", "rotatey" }); writeelementstringattributes("rotate", string.concat("1.0 0.0 0.0 ", rotation.x.todegrees()), { "sid", "rotatex" }); writeelementstring("scale", "1.0 1.0 1.0"); joint[] children = joint.getchildren(); (int32 = 0; < children.length; ++i) writejointnodes(children[i]); } writeendelement(); }
here example of output:
<node id="bn_head_id" type="joint" name="bn_head"> <translate>0.0732510 0.0000000 0.0000000</translate> <rotate sid="rotatez">1.0 0.0 1.0 0.0</rotate> <rotate sid="rotatey">0.0 1.0 0.0 9.0</rotate> <rotate sid="rotatex">1.0 0.0 0.0 0.0</rotate> <scale>1.0 1.0 1.0</scale>
now comes tricky part, since have export weights (skinning data) "library_controllers" section looks this:
<skin source="#geometry1_id"> <bind_shape_matrix>1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1</bind_shape_matrix> <source id="skinu3d1_id-joints"> <name_array id="skinu3d1_id-joints-array" count="4">bn_head_id bn_jaw_id bn_lefteye_id bn_righteye_id</name_array> <technique_common> <accessor source="#skinu3d1_id-joints-array" count="4" stride="1"> <param name="joint" type="name"/> </accessor> </technique_common> </source> <source id="skinu3d1_id-bind_poses"> <float_array id="skinu3d1_id-bind_poses-array" count="64">0 0.999831 0.018391 -1.58086 -1 0 0 -0.000000 0 -0.018391 0.999831 0.041763 0 0 0 1 -0.00011 -0.374834 0.927092 0.564468 -1 -0.000506 -0.000323 0.000808 0.00059 -0.927092 -0.374834 1.45633 0 0 0 1 0 0.000036 1 -0.074606 1 0 0 0.032523 0 1 -0.000036 -1.638 0 0 0 1 -0.00004 0.000036 1 -0.074607 1 -0.000302 0.00004 -0.032021 0.000302 1 -0.000036 -1.63774 0 0 0 1</float_array> <technique_common> <accessor source="#skinu3d1_id-bind_poses-array" count="4" stride="16"> <param name="transform" type="float4x4"/> </accessor> </technique_common> </source> // <<weights source here>> <joints> <input semantic="joint" source="#skinu3d1_id-joints"/> <input semantic="inv_bind_matrix" source="#skinu3d1_id-bind_poses"/> </joints> // <<vertex weights here>> </skin>
here, first 16 values of "skinu3d1_id-bind_poses-array" should represent inverse bind pose of "bn_head" of example.
i can build joints array , can handle vertices weights without problems don't understand how obtain matrices being used inside skin controller. need output collada model y orientation , know collada matrices column-major.
starting data have, questions are:
- how calculate "bind_shape_matrix" (in example it's identity matrix i've seen other collada files in it's different)?
- how calculate inverse bind matrices every joint?
i know file format referring to. file format use (.anim) has 1 more skeletal file (.inv_bind_mats) extension , same name, don't need calculate read .inv_bind_mats file.
Comments
Post a Comment