Wednesday, March 26, 2008

Understanding Collada

After lots of digging finally I came across an article which allows me to understand Collada clearly.
Here are the main portion

To study how meshes are retrieved, I will use a cube created using 3ds Max 8. Five facesare red and one face is yellow.28/74Figure 11. Just a cube.This cube in COLLADA generates these lines:

<library_geometries>

<geometry id="Box01-mesh" name="Box01">

<mesh>

<source id="Box01-mesh-positions">

<float_array id="Box01-mesh-positions-array" count="24">

-8.353 -9.42876 0 8.353 -9.42876 0 -8.353 9.42876 08.353 9.42876 0 -8.353 -9.42876 8.78867 8.353 -9.42876 8.78867 -8.353 9.42876 8.78867 8.353 9.428768.78867

</float_array>

<technique_common>

<accessor source="#Box01-mesh-positions-array" count="8" stride="3">

<param name="X" type="float"/>

<param name="Y" type="float"/>

<param name="Z" type="float"/>

</accessor>

</technique_common>

</source>

<source id="Box01-mesh-normals">

<float_array id="Box01-mesh-normals-array" count="72">

0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 1 0 0 1 0 0 1 0 0 1 0 -1 00 -1 0 0 -1 0 0 -1 0 1 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 1 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0

</float_array>

<technique_common>

<accessor source="#Box01-mesh-normals-array" count="24" stride="3"><param name="X" type="float"/>

<param name="Y" type="float"/>

<param name="Z" type="float"/>

</accessor>

</technique_common>

</source>

<source id="Box01-mesh-map-channel1">

<float_array id="Box01-mesh-map-channel1-array" count="36">

0 0 0 1 0 0 0 1 0 1 1 0 0 0 0 1 0 0 0 1 0 1 1 0 0 00 1 0 0 0 1 0 1 1 0

</float_array>

<technique_common>

<accessor source="#Box01-mesh-map-channel1-array" count="12" stride="3">

<param name="S" type="float"/>

<param name="T" type="float"/>

<param name="P" type="float"/>

</accessor>

29/74

</technique_common>

</source>

<vertices id="Box01-mesh-vertices">

<input semantic="POSITION" source="#Box01-mesh-positions"/>

</vertices>

<triangles material="red" count="10">

<input semantic="VERTEX" source="#Box01-mesh-vertices" offset="0"/>

<input semantic="NORMAL" source="#Box01-mesh-normals" offset="1"/>

<input semantic="TEXCOORD" source="#Box01-mesh-map-channel1" offset="2" set="1"/>

<p>0 0 9 2 1 11 3 2 10 3 2 10 1 3 8 0 0 9 0 8 4 1 9 5 5 10 7 5 10 7 4 11 6 0 8 4 1 12 0 3 13 1 7 14 3 7 14 3 5 15 21 12 0 3 16 4 2 17 5 6 18 7 6 18 7 7 19 6 3 16 4 2 20 0 0 21 1 4 22 3 4 22 3 6 23 2 2 20 0</p>

</triangles>

<triangles material="yellow" count="2">

<input semantic="VERTEX" source="#Box01-mesh-vertices" offset="0"/>

<input semantic="NORMAL" source="#Box01-mesh-normals" offset="1"/>

<input semantic="TEXCOORD" source="#Box01-mesh-map-channel1" offset="2" set="1"/>

<p>4 4 8 5 5 9 7 6 11 7 6 11 6 7 10 4 4 8</p>

</triangles>

</mesh>

</geometry>

</library_geometries>



This cube is made of sets of polygons, one of them has an associated red material and theother one is a yellow material. The key to retrieve the triangles, the vertices and the texturecoordinates is the indices. The following code is the indices to five red faces:

<p>0 0 9 2 1 11 3 2 10 3 2 10 1 3 8 0 0 9 0 8 4 1 9 5 5 10 7 5 10 7 4 11 6 0 8 4 1 12 0 3 13 1 7 14 3 7 14 3 515 2 1 12 0 3 16 4 2 17 5 6 18 7 6 18 7 7 19 6 3 16 4 2 20 0 0 21 1 4 22 3 4 22 3 6 23 2 2 20 0</p>

And this is the code of the yellow face:

<triangles material="yellow" count="2"><input semantic="VERTEX" source="#Box01-mesh-vertices" offset="0"/><input semantic="NORMAL" source="#Box01-mesh-normals" offset="1"/><input semantic="TEXCOORD" source="#Box01-mesh-map-channel1" offset="2" set="1"/><p>4 4 8 5 5 9 7 6 11 7 6 11 6 7 10 4 4 8</p></triangles>

The yellow face is built using two triangles, and each triangle is composed of threevertices, due to that, the yellow face has six vertices (some of them are duplicated). Andone vertex has three coordinates (x, y and z).The vertices are here:

<float_array id="Box01-mesh-positions-array" count="24">-8.353 -9.42876 0 8.353 -9.42876 0 -8.3539.42876 0 8.353 9.42876 0 -8.353 -9.42876 8.78867 8.353 -9.42876 8.78867 -8.353 9.42876 8.78867 8.3539.42876 8.78867</float_array>

We can retrieve the vertices which form triangles, and draw them using OpenGL. Theindices point out to the data which is stored is three lists, VERTEX, NORMAL andTEXCOORD.For instance, the vertex and triangles of the yellow face are:

vertex 0-8.3529997 -> 4*3=12

and the float in the 12th position is

-8.352999730/74-9.4287596 -> 5*3=158.7886696 -> 7*3=21

The numbers 4, 5 and 7 are from here:

<p>4 4 8 5 5 9 7 6 11 7 6 11 6 7 10 4 4 8</p>

And the floats from here:

<float_array id="Box01-mesh-positions-array" count="24">
-8.353 -9.42876 0 8.353 -9.42876 0 -8.3539.42876 0 8.353 9.42876 0 -8.353 -9.42876 8.78867 8.353 -9.42876 8.78867 -8.353 9.42876 8.78867 8.3539.42876 8.78867
</float_array>

vertex 1 8.3529997-9.42875968.7886696
vertex 2 8.35299979.42875968.7886696
vertex 3 8.35299979.42875968.7886696
vertex 4 -8.35299979.42875968.7886696
vertex 5 -8.3529997-9.42875968.7886696

At the beginning this process is very strange and it takes a while to understand it. Toretrieve normals and textures coordinates we do a similar process.

Source: Project Work.pdf

Wednesday, March 12, 2008

Working with CDC

I recently bought Sony Ericsson P990i with the intension to work on CDC. After the initial setup with the netbeans, I concentrate on building a code editor. It would have quick text facility like notepad++.

With the initiative of porting phoneME advance on Android and iphone, the CDC will cover great ground as a mobile platform.