Results 1 to 3 of 3

Thread: Collada to own format converter (for C#)

  1. #1
    Junior Member
    Join Date
    Jun 2006
    Posts
    2

    Collada to own format converter (for C#)

    Hi,
    I am new to collada. I first heared about it about one week ago. I am in need of a very very simple 3D file format. There is simply no available 3D file formats supported in C# so far. And I am trying to write a very simple one myself. I allready have some basic support for X3D. But Collada is a much better format people told me.

    My simple framework:
    I made an UML diagram to illustrate what I am currently trying to program:
    • I have a B3DLibrary that is a collection of B3DObjects and B3DTextures.
      A B3DTexture is just something that links to an image file.
      A B3DObject is basicly nothing more than a collection of B3DFaces.
      A B3DFace is a collections of B3Dpoints. A B3DFace also contains a drawingmethod. This drawinmethod corresponds to the OpenGL drawingmethods such as GL_TRIANGLES, GL_POLYGONS, GL_LINES, GL_POINTS, ... etc
      There are 2 kind of B3DPoints. There are textured B3DPoints and colored B3DPoints.
      A B3DColoredPoint has an x,y,z and r,g and b values.
      A B3DTexturedPoint has a x,y,z a texturename, and the xoffset and yoffset of the texture.


    Of course that's not a standard format. And I would like to write a converter to convert from Collada to my format. I was wondering which nodes I would need to check of the Collada XML structure.

    The UML class diagram:
    [img=http://img77.imageshack.us/img77/9007/newclassdiagram6lk.th.gif]

    At the moment I am checking the following xml nodes:
    I go through the nodes like this to find the points of the models.
    • COLLADA
      => LIBRARY type='GEOMETRY'
      => geometry
      => mesh
      => source id="~-Position"
      => float-array id"~-array"

    Are those indeed the point-coordinates?
    Are there other ways where there are coordinates too?
    (Notice that I don't need normals in my format. Because I do not need to identify the top of the faces.)

    For textures:
    For the offset of the textures I guess I need these?


    0 0 41 1 42 2 1 3</p>
    Are these the ones I need? 2 coordinates for each point, right? But since there are 2x4 numbers does that mean I have to write the points like quads?

    Thank you in advance:
    Hopefully somebody can help me a bit with this. I went through a sample collada-file but to be honest I had trouble finding what I need.
    Greetings !

  2. #2
    Senior Member
    Join Date
    Jul 2004
    Location
    Santa Clara
    Posts
    356
    I do not know C#, but I understand that it is has a lot of tools to deal with XML and can easily give access to COLLADA elements by using the COLLADA schema directly, so it should be a great choice for parsing COLLADA files directly, without the need for using libraries such as the COLLADA-DOM.

    In COLLADA the raw data is stored in the <array> elements, child of the <source> element.

    The <accessor> element describes the output of the <source> element. it provides a level of abstraction over the sources so that they can store data without any semantics. For isntance, a unit sphere can share the same exact raw data for the positions and normals.

    The <param> child element of the <accessor> element provides the connection to the <source>. The count attribute indicates the number of items the source's array contains from the point of view of the <accessor> element. The offset attribute provides the index of the first value in the array that is accessed. The stride attribute indicates the separation between two consecutive values, with a default value of 1.

    The ordering of <param> elements is important as well. The output values from the <accessor> element are bound in the order that the parameters are specified.

    The <geometry> element is the container of all the information that describes a geometric shape. The <mesh> in your example is one of the possible type of geometries. The <vertices> element defines all the per vertex data that the geometry will be using. In general you will find the POSITION semantic and the NORMAL sematic there.

    The geometry is then defined with the <input> elements, using the

    indexes array to index into the sources, the offset indicates the first index to use. The stride is the same for all the inputs, it is the largest offset value + 1. The <input> with the semantic VERTEX is referencing the <vertices> element in the same <geometry>

    Here's an example of a mesh that has 2 identical texture coordinate sets.
    in pseudo C this will give you:

    VERTEX[] = { xyz[0], xyz[2] ...
    TEXCOORD1[] = { uv[1], uv[3] ...
    TEXCOORD2[] = { uv[1], uv[3] ...

    Code :
    <mesh>
     <source id="xyz" ....
     <source id="uv" ...
     <vertices id="vtx">
       <input semantic="POSITION" source="#position" />
     </vertices>
     <polygons material="xxxx" count="xx"> [or lines, or polylist....]
      <input semantic="VERTEX" source="#vtx" offset ="0">
      <input semantic="TEXCOORD" source="#uv" offset ="1">
      <input semantic="TEXCOORD" source="#uv" offset="1">
     
     
     0 1 2 3 </p>
     </polygons>
    </mesh>

  3. #3
    Junior Member
    Join Date
    Jun 2006
    Posts
    2
    Thank you remi,
    your explanations are very helpful !
    I am making slow but steady progress now.
    Greetings !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •