Importing COLLADA model with per-vertex colors; how to read them?

72 views
Skip to first unread message

Gary Oberbrunner

unread,
Mar 30, 2018, 3:33:16 PM3/30/18
to pycollada
I have a COLLADA model with colors, like this:

        <geometry> ...
        <mesh>
        <triangles count="8" material="geom0-material">
          <input offset="0" semantic="VERTEX" source="#geom0-mesh-vertices"/>
          <input offset="1" semantic="NORMAL" source="#geom0-mesh-normals"/>
          <input offset="2" semantic="COLOR" source="#geom0-mesh-colors"/>
          <p>18 9 0 0 0 0 2 1 0 18 9 0 2 1 0 4 2 0 18 9 0 4 2 0 6 3 0 18 9 0 6 3 0 8 4 0 18 9 0 8 4 0 10 5 0 18 9 0 10 5 0 12 6 0 18 9 0 12 6 0 14 7 0 18 9 0 14 7 0 16 8 0 </p>
        </triangles>
        ...

How do I get those per-vertex colors in pycollada? I assume I start with mesh.scene.objects('geometry') but iterating through the primitives of the geometries in the scene, I only seem to get the vertex and normal arrays.
    >>> [x for x in dir(prims[0]) if not x.startswith('_')]
    ['generateNormals', 'index', 'inputmap', 'material', 'normal', 'normal_index', 'ntriangles', 
    'original', 'shapes', 'texcoord_indexset', 'texcoordset', 'triangles', 'vertex', 'vertex_index']

thanks,
Gary

Jeff Terrace

unread,
Mar 30, 2018, 3:42:41 PM3/30/18
to pyco...@googlegroups.com
I don't think I ever added parsing support for the COLOR semantic.

I think the TriangleSet has .sources which should have 'COLOR' as a key in the dictionary. If you're iterating through the scene, you'll have a BoundTriangleSet, so try .original.sources['COLOR'].

I'd be happy to review a patch to add parsing support, the place to start would be here:
https://github.com/pycollada/pycollada/blob/master/collada/triangleset.py#L111

--
You received this message because you are subscribed to the Google Groups "pycollada" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pycollada+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gary Oberbrunner

unread,
Mar 31, 2018, 5:59:20 PM3/31/18
to pyco...@googlegroups.com
OK, I'm looking into that. I assume it's OK to add the color to the triangleset, but not add it to the triangle object (and same for polylist)?

Also I'm having problems parsing a very basic (?) collada file: https://github.com/assimp/assimp/blob/master/test/models/Collada/cube_triangulate.dae
Is it just me? It says: collada.common.DaeMalformedError: DaeMalformedError: Indexes (maxindex=23) for source 'box-lib-positions' (len=8) go beyond the limits of the source

It seems to be getting confused by the interleaved vertex/normal indexing. Here's the lines in question:

<source id="box-lib-positions" name="position">
    <float_array id="box-lib-positions-array" count="24">-50 50 50 50 50 50 -50 -50 50 50 -50 50 -50 50 -50 50 50 -50 -50 -50 -50 50 -50 -50</float_array>
    <technique_common>
        <accessor count="8" offset="0" source="#box-lib-positions-array" stride="3">
            <param name="X" type="float"></param>
            <param name="Y" type="float"></param>
            <param name="Z" type="float"></param>
        </accessor>
    </technique_common>
</source>
<source id="box-lib-normals" name="normal">
    <float_array id="box-lib-normals-array" count="72">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 -1 0 0 -1 0 0 -1 0 0 -1 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 0 0 -1 0 0 -1 0 0 -1 0 0 -1</float_array>
    <technique_common>
        <accessor count="24" offset="0" source="#box-lib-normals-array" stride="3">
            <param name="X" type="float"></param>
            <param name="Y" type="float"></param>
            <param name="Z" type="float"></param>
        </accessor>
    </technique_common>
</source>
<vertices id="box-lib-vertices">
    <input semantic="POSITION" source="#box-lib-positions"/>
</vertices>
<triangles count="12" material="BlueSG">
    <input offset="0" semantic="VERTEX" source="#box-lib-vertices"/>
    <input offset="1" semantic="NORMAL" source="#box-lib-normals"/>
    <p>0 0 2 1 3 2 0 0 3 2 1 3 0 4 1 5 5 6 0 4 5 6 4 7 6 8 7 9 3 10 6 8 3 10 2 11 0 12 4 13 6 14 0 12 6 14 2 15 3 16 7 17 5 18 3 16 5 18 1 19 5 20 7 21 6 22 5 20 6 22 4 23</p>
</triangles>

If you look at it, the VERTEX indices never go beyond 8 so pycollada shouldn't complain (I marked them in bold above.) But if I print self._vertex_instance in the TriangleSet constructor, it's got the whole index array, not the proper slice.

-- Gary


--
Gary

Gary Oberbrunner

unread,
Mar 31, 2018, 6:19:03 PM3/31/18
to pyco...@googlegroups.com
Never mind, this seems to be something I broke by adding color support. I'll keep poking at it.

-- Gary
--
Gary
Reply all
Reply to author
Forward
0 new messages