maybe some simple questions

Hi,
i’m new to COLLADA and i met some problmes. I download one .skp file and export it to .dae file. i want to find some useful message about the 3D models.
i puzzled with the texture coordinates. There are the codes for these:


<source id="mesh1-geometry-uv">
               <float_array id="mesh1-geometry-uv-array" count="1844">-1.191028 2.957980 -1.185935 2.449309 -1.179625 2.703733 -1.209927 2.195939 -84.932999 194.668789 -85.387306 176.350217 -85.754021 212.974592 -2.673656 -0.221199 -2.419153 -0.221199 -2.612304 0.078701 -188.085897 5.666468 -174.179025 ..........</float_array>
               <technique_common>
                  <accessor source="#mesh1-geometry-uv-array" count="922" stride="2">
                     <param name="S" type="float"/>
                     <param name="T" type="float"/>
                  </accessor>
               </technique_common>
            </source>

There are the triangles codes:



<triangles material="material0" count="284">
               <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 2 0 2 1 0 1 0 0 0 3 0 3.......</p>

i count the number of values in

</p>. It is 2556. So every triangle is consisted of nine values. For example, 0 0 0 1 0 1 2 0 2 defines the first triagnle. My questions are:

1, In opengl , texture coordinate is set to [0,1]. why dose these texture coordinates go too far?
1, Since every texture coordinate is consited of two values s and t, how can i understand the triagnle defined in

</p>? For example, for the first triangle 0 0 0 1 0 1 2 0 2, the vertext index is 0,1,2 the normal is 0,0,0 the texture is 0,1,2 which is equal to -1.191028 2.957980 -1.185935 2.449309 -1.179625 2.703733 , am i right?

Yes.

I figured I post my question as a reply on this one as my question is similar. I’ve been messing around with COLLADA files exported from MAX for a couple of days now. Although I’m getting the basic idea and file format, the answer to the following question would surely help me get on with writing my loader. I’m basically just trying to read the geometry for now. I understand I need 2 fields, the vertex positions and in my particular case the tristrips (working on iPhone/OpenGL ES, no quads…).

Ok here’s my sample (just a simple cube, left out the 24 positions)

 <tristrips count="9" material="_5_-_Default">
                    <input offset="0" semantic="VERTEX" source="#Box01-mesh-vertices"/>
                    <input offset="1" semantic="TEXCOORD" source="#Box01-mesh-map-channel1" set="1"/>
                    

1 8 2 11 3 10</p>
                    

2 11 1 8 0 9</p>
                    

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

4 6 1 5 5 7</p>
                    

1 5 4 6 0 4</p>
                    

1 8 3 1 1 8 7 11 5 2</p>
                    

7 6 2 5 6 7</p>
                    

2 5 7 6 3 4</p>
                    

2 0 0 9 2 0 4 3 6 10</p>
                </tristrips>

Could someone please tell me how I can distinquish the textcoords from the vertexes? Are the last 3 of every

the texcoords and hence do I need to use the ones before it? I want to call drawarray for each triangle_strip in opengl / each

above. Does the SET=“1” have influence in my example?

TIA.

Ok, now that I read my own post again I see it has to be alternate as in the first is vertex second is texcoord, third vertex, fourth texcoord. Because there are only 8 vertexes/positions/3d coords (0-7). Let’s hope my models will now finally look like they do in 3dsmax :smiley:

Thanks.

Input 0 (e.g. your VERTEX semantic) samples from your “mesh-vertices” <source>. The <vertex> element is a logical <source> for mesh vertex identity.
Input 1 (e.g your TEXCOORD semantic) samples from your “mesh-channel1” <source>.

The

element supplies the sampling indexes for the inputs, e.g. in pairs: (input 0, input 1), (0,1), (0,1), … etc. for the count indicated.

Hope that helps

Thanks for the reply.

That (the fact textcoord is sampled from mesh-channel1 instead of mesh-vertices) clears up a bit (not sure how aI read over that), I’m however still in the dark as to what information and how to combine it to get all the coords to draw a tristrip.

1 8 2 11 3 10</p

Does this mean the XYZ coord of the first vertex to draw as part of the geometry =

1,2,3</p>, meaning the first 3 values in mesh-vertices are the xyz of the first vertex? And 8, 11 ,10 would refer to the 8th,11th, and 10th position of map-channel1, hence from:
<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 0 0 1 0 0 0 1 0 1 1 0</float_array>

that would be 1,1,1

OK, I think I see where I’m going wrong…

I’m taking the i-th value instead of i (=x coord) and i+1 (=y coord) and i+3.

That way I would end up with 1,2,3 referring to 3 complete 3D xyz coords to draw a triangle(strip) instead of just 1 point in space.

Please tell me the light I’m seeing at the end of the tunnel is not a lamp indicating a different direction :smiley:

You’re welcome!

Only because your input “index=1” says so.

No sorry, each index grabs as many values as the associated <accessor> describes… You didn’t show that part in your example so I don’t know if VERTEX supplies only POSITION. However, what that

(primitive) element is doing is supplying indexes for a single tri-strip. A triangle is assembled from those

indexes as follows:


Triangle [
 P0 (1=VERTEX,  8=TEXCOORD),
 P1 (2=VERTEX, 11=TEXCOORD),
 P2 (3=VERTEX, 10=TEXCOORD)
]

… and VERTEX supplies at least POSITION (e.g. XYZ coordinate per sampling index of

) depending on what you put in it (not shown).

Hope that helps.

Thanks again, your help is much appreciated. I’m creating a simple DAE loader for the iPhone using tristrips and I’m at the point where I have the sources and counts loaded in strings/ints and need to convert the float_array string sources to objective C arrays with individual floats to feed to OpenGL functions.

The loader will only need to load my models, meaning the ones I export from 3dsmax and refine to tristrips. I’m currently only concerned about the geometry. I exported several different models and I always end up with the same strides and sources and offsets. My point is that if I understand this example (a cube), I should be able to figure it out for my other - more complex - models.

(normals left out:)

<geometry id="Box01-mesh" name="Box01">
            <mesh>
                <source id="Box01-mesh-positions">
                    <float_array id="Box01-mesh-positions-array" count="24">-10.3834 -9.10543 0 10.3834 -9.10543 0 -10.3834 9.10543 0 10.3834 9.10543 0 -10.3834 -9.10543 23.9617 10.3834 -9.10543 23.9617 -10.3834 9.10543 23.9617 10.3834 9.10543 23.9617</float_array>
                    <technique_common>
                        <accessor count="8" source="#Box01-mesh-positions-array" 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 0 0 1 0 0 0 1 0 1 1 0</float_array>
                    <technique_common>
                        <accessor count="12" source="#Box01-mesh-map-channel1-array" stride="3">
                            <param name="S" type="float"/>
                            <param name="T" type="float"/>
                            <param name="P" type="float"/>
                        </accessor>
                    </technique_common>
                </source>
                <vertices id="Box01-mesh-vertices">
                    <input semantic="POSITION" source="#Box01-mesh-positions"/>
                </vertices>
                <tristrips count="9" material="_5_-_Default">
                    <input offset="0" semantic="VERTEX" source="#Box01-mesh-vertices"/>
                    <input offset="1" semantic="TEXCOORD" source="#Box01-mesh-map-channel1" set="1"/>
                    

1 8 2 11 3 10</p>
                    

2 11 1 8 0 9</p>
                    

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

4 6 1 5 5 7</p>
                    

1 5 4 6 0 4</p>
                    

1 8 3 1 1 8 7 11 5 2</p>
                    

7 6 2 5 6 7</p>
                    

2 5 7 6 3 4</p>
                    

2 0 0 9 2 0 4 3 6 10</p>
                </tristrips>
            </mesh>
        </geometry>

Ok so the first triangle strip (in the first

just a single triangle) takes the following 3D coords for the geometry?
-10.3834, -9.10543, 0
10.3834 -9.10543 0
-10.3834, 9.10543, 0
Feeding these 9 values to a drawArray with Triangle_strip should do the trick right?

And for TEXCOORDS I take the 8th, 11th and 10th set of 3 values (according to stride value) from the Box01-mesh-map-channel1 float_array right?

Thanks for your patience :smiley:

That’s cool to see more iPhone develoers doing 3D!

Yes.

Yes you got it!

Thanks, it sure is fun to my models go from 3dsm->XML->iPhone :smiley: Though 3D+iPhone=constant fear of running into performance limitations so far so good.

I built my loader with a basic cube mesh in mind+xml and after finishing the main part of my loader today I replaced the cube.dae with a sphere.dae and guess what… I see a sphere 8)

I’m not using the normals and texcoords yet so my models aren’t showing properly yet (maybe drawing order and culling as well) but it sure seems OpenGL draws all the triangle_strips according to my DAE file.

Thanks again for the help!