Reputation: 85
I am trying to understand the structure of a collada file. Specifically I am using the library pycollada (https://github.com/pycollada/pycollada). I have 2 questions.
Question 1:
Having a look to the tutorial to create a file from scratch (http://pycollada.github.io/creating.html), what I don't understand is the structure of the Collada object. In particular, having a look to the following lines of code seems that the mesh is used to create the geometry, and the geometry is included in the mesh:
>>> mesh = Collada()
>>> geom = geometry.Geometry(mesh, "geometry0", "mycube", [vert_src, normal_src])
and few lines after
>>> triset = geom.createTriangleSet(indices, input_list, "materialref")
>>> geom.primitives.append(triset)
>>> mesh.geometries.append(geom)
Someone has a clear structure of a Collada file? Possibly a visual representation to understand what is where.
Question 2:
If I want to have 2 different objects (here I mean 2 different 3D objects inside of the Collada file, e.g. a cube and a sphere) where should I add the second one? Is a second geometry object inside of the mesh, or maybe a second TriangleSet inside of the geometry, or is defined in a different way?
Upvotes: 2
Views: 3877
Reputation: 1128
The <geometry>
element in COLLADA is the container of the information that describes a geometric shape. There are possible representations of 3D objects when creating digital assets. And polygonal mesh is only one of these representation possibilities. Another possibility could be for example <brep>
.
Polygon-based geometry descriptions are included as child elements of <mesh>
element under the <geometry>
. These elements are <lines>
, <linestrips>
, <polygons>
, <polylists>
, <triangles>
, <trifans>
and <tristrips>
.
So the structure looks like: I have a <geometry>
-> Which kind of? -> i.e. <mesh>
-> Contains which polygon-based geometries? -> i.e. <triangles>
Let me show you the internal structure of the geometry in COLLADA:
You can define positions of the points in 3D space in the <source>
element with <float_array>
and your indices under <p>
element under <triangles>
. <p>
element defines not only the vertices but also the normals in this example.
For your second question, you can define it as a second <geometry>
in your geometry library, or a part of the mesh under the element. But if you have to use them later separated from each other, for example you want to create 2 instances of the cube, one is green another is blue, and 1 instance of the sphere, you should not do it under the same mesh. You should define them as two separated geometry objects. It depends on your case.
Upvotes: 3