I’m having trouble with associating data across multiple COLLADA ~source~ elements occuring under mesh instances in COLLADA instance documents. I have thoroughly read the the wiki documentation on “Using accessors” at: https://collada.org/mediawiki/index.php/Using_accessors but it does not seem to address the requirements of my application.
Given collada instance document test cases with ~source~ element instances exemplified as follows…
<geometry id="mesh1-geometry" name="mesh1-geometry">
<mesh>
<source id="mesh1-geometry-position">
<float_array id="mesh1-geometry-position-array" count="846">1.634429 51.875743 ... 28.753150 </float_array>
<technique_common>
<accessor source="#mesh1-geometry-position-array" count="282" stride="3">
<param name="X" type="float"/>
<param name="Y" type="float"/>
<param name="Z" type="float"/>
</accessor>
</technique_common>
</source>
<source id="mesh1-geometry-normal">
<float_array id="mesh1-geometry-normal-array" count="606">0.0 0.0 -1.0 -0.0 -0.0 1.0 ... -0.4499 0.0 -0.8931 </float_array>
<technique_common>
<accessor source="#mesh1-geometry-normal-array" count="202" stride="3">
<param name="X" type="float"/>
<param name="Y" type="float"/>
<param name="Z" type="float"/>
</accessor>
</technique_common>
</source>
<source id="mesh1-geometry-uv">
<float_array id="mesh1-geometry-uv-array" count="488">-0.893716 28.366001 -1.552262 27.707456 ... -18.082695 -14.795389 </float_array>
<technique_common>
<accessor source="#mesh1-geometry-uv-array" count="244" stride="2">
<param name="S" type="float"/>
<param name="T" type="float"/>
</accessor>
</technique_common>
</source>
<vertices id="mesh1-geometry-vertex">
<input semantic="POSITION" source="#mesh1-geometry-position"/>
</vertices>
<triangles material="material_0_1_8" count="64">
<input semantic="VERTEX" source="#mesh1-geometry-vertex" offset="0"/>
<input semantic="NORMAL" source="#mesh1-geometry-normal" offset="1"/>
<input semantic="TEXCOORD" source="#mesh1-geometry-uv" offset="2" set="0"/>
0 0 0 1 0 1 ... 130 26 101 </p>
</triangles>
<triangles material="material_1_24" count="542">
<input semantic="VERTEX" source="#mesh1-geometry-vertex" offset="0"/>
<input semantic="NORMAL" source="#mesh1-geometry-normal" offset="1"/>
2 1 1 1 ... 277 199 </p>
</triangles>
<triangles material="material_3_24" count="366">
<input semantic="VERTEX" source="#mesh1-geometry-vertex" offset="0"/>
<input semantic="NORMAL" source="#mesh1-geometry-normal" offset="1"/>
15 12 27 12 ... 276 167 </p>
</triangles>
<triangles material="material_2_2_8" count="80">
<input semantic="VERTEX" source="#mesh1-geometry-vertex" offset="0"/>
<input semantic="NORMAL" source="#mesh1-geometry-normal" offset="1"/>
<input semantic="TEXCOORD" source="#mesh1-geometry-uv" offset="2" set="0"/>
61 40 75 84 40 76 ... 281 198 243 </p>
</triangles>
<triangles material="material_4_24" count="92">
<input semantic="VERTEX" source="#mesh1-geometry-vertex" offset="0"/>
<input semantic="NORMAL" source="#mesh1-geometry-normal" offset="1"/>
62 46 49 46 ... 258 187 </p>
</triangles>
</mesh>
My application needs to:
(1) Generate a vertex buffer with the following structure:
x1 y1 z1 nx1 ny1 nz1 tu1 tv1
x2 y2 z2 nx2 ny2 nz2 tu2 tv2
...
xN yN zN nxN nyN nzN tuN tvN
Where
- xi, yi, and zi are position coordinates
- nxi nyi nzi are normals, and
- tui and tvi are texture coordinates on a UV coordinate system
and each position/normal/texture-coordinate tupple corresponds to a triangle vertex, and
(2) Generate a vertex index describing a set of triangles over the vertex buffer.
The “Using Accessors” wiki documentation describes how to create vertex data structures similar the one required by my application. However, the documentation shows how to create such structures only for cases where the position, normal and texture coordinate data are interleaved within a single source array. My problem is that all my test cases involve three sources corresponding to the position, normal and texture coordinate data respectively. My issue is that I can see no way of identifying which position, normal and texture coordinate tuples relate to one another across the disparate source elements based on the information explicit in the accessors associated with the sources. So, given the collada accessor arrangement described in my test cases, how would an application generate a vertex buffer as described above with the correct associations between position, normal and texture coordinate data points? And once the vertex buffer is generated, how might the vertices be indexed so as to correctly describe the triangles in the mesh?
Thank you in advance for any input you might be able to offer.