Search code examples
x3d

X3D - How to color polygon faces in X3D


How do I color a polygon face - as in just color 1 face all red for example. I don't want linear interpolation occuring when I move on to color a neighboring face. I am able to color it with the following codes but the colors merge. When I turn colorPerVertex to false, the coloring looks weird. Please advice. Thank you.

<X3D>
<Scene>
<Shape>

    <IndexedFaceSet solid="false" colorPerVertex="true"
        coordIndex="0 3 4 1 -1
                    1 4 5 2 -1
                    3 6 7 4 -1
                    4 7 8 5 -1">
    <Coordinate
        point= "0 0 0, 1 0 0, 2 0 0
                0 0 1, 1 3 1, 2 0 1
                0 0 2, 1 0 2, 2 0 2" />

        <Color color= "0 0 0, 1 0 0, 2 0 0
                0 0 1, 1 3 1, 2 0 1
                0 0 2, 1 0 2, 2 0 2" />

    </IndexedFaceSet>

    <Appearance>
        <Material diffuseColor='1 0 0' />
    </Appearance>

</Shape>
</Scene>
</X3D>

Solution

  • If colorPerVertex is FALSE AND the colorIndex field is not empty, then one colour is applied for each face of the IndexedFaceSet.

    Therefore if you set colorPerVertex to FALSE in your example you should NOT have color interpolation between faces (tested).