VRML Indexed FaceSet

2.4k views Asked by At

Hi I'm trying to make a solid with Indexed FaceSet on VRML. The problem is 2 faces aren't showing up and I really don't know why.

The code is:

Shape {
                    geometry IndexedFaceSet {
                        coord Coordinate {
                            point [0 0 0,     #0
                                0.3 0 0,      #1
                                0 1.2 0,      #2
                                0.3 1.2 0,    #3
                                0 0 -1,       #4
                                0.3 0 -1,     #5
                                0 1.2 -1,     #6
                                0.3 1.2 -1,   #7
                                0.6 1.2 -0.3, #8
                                0.6 1.2 -0.7] #9
                            }   
                            coordIndex [6 7 9 8 3 2 -1,
                                0 1 5 4 -1,
                                1 5 9 8 -1,
                                0 1 3 2 -1,
                                4 5 7 6 -1,
                                0 4 6 2 -1,
                                3 1 8 -1,
                                7 5 9 -1
                            ]

                        }

                    appearance Appearance { material Material { diffuseColor 0 0 0.8 }}
                }

The 2 sides not appearing are the last ones. Any thoughts?

1

There are 1 answers

0
wildpeaks On BEST ANSWER

First, each side has to be defined in counter-clockwise order to be visible because IndexedFaceSet objects are one-sided unless you use solid FALSE, that's why some faces in your model look like they're missing, but they're actually visible from the other side instead.


Solution 1: solid FALSE

Faces are visible from both sides, so it doesn't matter if they were defined clockwise or counter-clockwise. That's the easy hack, but it doubles the number of polygons that the viewer renders internally.

#VRML V2.0 utf8

Shape {
    appearance Appearance {
        material Material {
            diffuseColor 0 0 0.8
        }
    }
    geometry IndexedFaceSet {
        solid FALSE
        coord Coordinate {
            point [0 0 0, 0.3 0 0, 0 1.2 0, 0.3 1.2 0, 0 0 -1 0.3 0 -1, 0 1.2 -1, 0.3 1.2 -1, 0.6 1.2 -0.3, 0.6 1.2 -0.7]
        }
        coordIndex [
            6 7 9 8 3 2 -1,
            0 1 5 4 -1,
            1 5 9 8 -1,
            0 1 3 2 -1,
            4 5 7 6 -1,
            0 4 6 2 -1,
            3 1 8 -1,
            7 5 9 -1
        ]
    }
}

Solution 2: flip the faulty faces

Reverse the order of the vertexes for the specific faces that should be flipped.

#VRML V2.0 utf8

Shape {
    appearance Appearance {
        material Material {
            diffuseColor 0 0 0.8
        }
    }
    geometry IndexedFaceSet {
        coord Coordinate {
            point [0 0 0, 0.3 0 0, 0 1.2 0, 0.3 1.2 0, 0 0 -1 0.3 0 -1, 0 1.2 -1, 0.3 1.2 -1, 0.6 1.2 -0.3, 0.6 1.2 -0.7]
        }
        coordIndex [
            2 3 8 9 7 6 -1, # flipped
            4 5 1 0 -1,     # flipped
            1 5 9 8 -1,
            0 1 3 2 -1,
            6 7 5 4 -1,     # flipped
            2 6 4 0 -1,     # flipped
            3 1 8 -1,
            9 5 7 -1        # flipped
        ]
    }
}