Search code examples
opengl-es-2.0collada

Collada skeleton and controller relation


I am developing a collada loader for android OpenGL ES2, the scene has many meshes and lights which I can load them, now I am working on loding skeletons and animations, I can parse skeletons from visual_scene node and store them in a list of Skeleton class which has an Id and a Joint list, I parse the controllers from library_controllers which I can link with the mesh throw rhe url of the instance_controller of the visual scene node, now I want to link the controller with the skeleton for example: the skeleton part in the visual_scene library is:

  <node id="Armature_001" name="Armature_001" type="NODE">
    <translate sid="location">0 5 -3.883436</translate>
    <rotate sid="rotationZ">0 0 1 0</rotate>
    <rotate sid="rotationY">0 1 0 0</rotate>
    <rotate sid="rotationX">1 0 0 0</rotate>
    <scale sid="scale">1 1 1</scale>
    <node id="Bone" name="Bone" sid="Bone" type="JOINT">
      <matrix sid="transform">1 0 0 0 0 0 -1 0 0 1 0 0 0 0 0 1</matrix>
      <node id="Bone_001" name="Bone.001" sid="Bone_001" type="JOINT">
        <matrix sid="transform">1 0 0 0 0 1 0 1 0 0 1 0 0 0 0 1</matrix>
      </node>
    </node>
  </node>

and the mesh from the visual_scene is:

  <node id="Cube" name="Cube" type="NODE">
    <translate sid="location">0 0 0</translate>
    <rotate sid="rotationZ">0 0 1 0</rotate>
    <rotate sid="rotationY">0 1 0 0</rotate>
    <rotate sid="rotationX">1 0 0 0</rotate>
    <scale sid="scale">1 1 1</scale>
    <instance_controller url="#Armature_001_Cube-skin">
      <skeleton>#Bone</skeleton>
      <bind_material>
        <technique_common>
          <instance_material symbol="Material_001-material" target="#Material_001-material"/>
        </technique_common>
      </bind_material>
    </instance_controller>
  </node>

and the controller from library_controllers is:

<controller id="Armature_Cube_001-skin" name="Armature">
  <skin source="#Cube_001-mesh">
    <bind_shape_matrix>1 0 0 0 0 1 0 -5 0 2.78181e-8 3 -1.39091e-7 0 0 0 1</bind_shape_matrix>
    <source id="Armature_Cube_001-skin-joints">
      <Name_array id="Armature_Cube_001-skin-joints-array" count="2">Bone Bone_002</Name_array>
      <technique_common>
        <accessor source="#Armature_Cube_001-skin-joints-array" count="2" stride="1">
          <param name="JOINT" type="name"/>
        </accessor>
      </technique_common>
    </source>
    <source id="Armature_Cube_001-skin-bind_poses">
      <float_array id="Armature_Cube_001-skin-bind_poses-array" count="32">1 0 0 0 0 0 -1 2.5 0 1 0 5 0 0 0 1 1 0 0 0 0 0 -1 1.5 0 1 0 5 0 0 0 1</float_array>
      <technique_common>
        <accessor source="#Armature_Cube_001-skin-bind_poses-array" count="2" stride="16">
          <param name="TRANSFORM" type="float4x4"/>
        </accessor>
      </technique_common>
    </source>
    <source id="Armature_Cube_001-skin-weights">
      <float_array id="Armature_Cube_001-skin-weights-array" count="20">1 0.9464464 0.05355352 1 0.9444246 0.05557531 1 0.9444246 0.05557531 1 0.9464464 0.05355352 0.02067142 0.9793285 0.02056819 0.9794319 0.02067142 0.9793285 0.02056819 0.9794319</float_array>
      <technique_common>
        <accessor source="#Armature_Cube_001-skin-weights-array" count="20" stride="1">
          <param name="WEIGHT" type="float"/>
        </accessor>
      </technique_common>
    </source>
    <joints>
      <input semantic="JOINT" source="#Armature_Cube_001-skin-joints"/>
      <input semantic="INV_BIND_MATRIX" source="#Armature_Cube_001-skin-bind_poses"/>
    </joints>
    <vertex_weights count="12">
      <input semantic="JOINT" source="#Armature_Cube_001-skin-joints" offset="0"/>
      <input semantic="WEIGHT" source="#Armature_Cube_001-skin-weights" offset="1"/>
      <vcount>1 2 1 2 1 2 1 2 2 2 2 2 </vcount>
      <v>1 0 0 1 1 2 1 3 0 4 1 5 1 6 0 7 1 8 1 9 0 10 1 11 0 12 1 13 0 14 1 15 0 16 1 17 0 18 1 19</v>
    </vertex_weights>
  </skin>
</controller>

my question if there are many meshes which have different skeletons and controllers can I link controller and the skeleton from Id string


Solution

  • Try AssimpLib, supports Collada with skeletal animations well, it do all the hard work