Cover TOC Chap Prev Chap Prev Fig Next Fig Next Chap

Chapter 13: Building Shapes with Points, Lines, and Faces

../ch13/13fig17.gif
Figure 13.17

A morphing box shape.

13fig17.wrl
Click on the image to view the VRML scene.

#VRML V2.0 utf8
# The VRML 2.0 Sourcebook
# Copyright (c) 1997
# Andrea L. Ames, David R. Nadeau, and John L. Moreland
Group {
    children [
    # Morphing shape
        Shape {
            appearance Appearance {
                material Material {
                    diffuseColor 0.0 1.0 1.0
                }
            }
            geometry IndexedFaceSet {
                coord DEF CubeCoordinates Coordinate {
                    point [
                    # Coordinates around top of cube
                        -1.0  1.0  1.0,
                         1.0  1.0  1.0,
                         1.0  1.0 -1.0,
                        -1.0  1.0 -1.0,
                    # Coordinates around bottom of cube
                        -1.0 -1.0  1.0,
                         1.0 -1.0  1.0,
                         1.0 -1.0 -1.0,
                        -1.0 -1.0 -1.0
                    ]
                }
                coordIndex [
                    # top
                    0, 1, 2, 3, -1,
                    # bottom
                    7, 6, 5, 4, -1,
                    # front
                    0, 4, 5, 1, -1,
                    # right
                    1, 5, 6, 2, -1,
                    # back
                    2, 6, 7, 3, -1,
                    # left
                    3, 7, 4, 0
                ]
            }
        },
    # Animation clock
        DEF Clock TimeSensor {
            cycleInterval 4.0
            loop TRUE
        },
    # Animation morph
        DEF CubeMorph CoordinateInterpolator {
            key [ 0.0, 0.5, 1.0 ]
            keyValue [
            # time 0.0 coordinates (cube)
                -1.0  1.0  1.0,   1.0  1.0  1.0,
                 1.0  1.0 -1.0,  -1.0  1.0 -1.0,
                -1.0 -1.0  1.0,   1.0 -1.0  1.0,
                 1.0 -1.0 -1.0,  -1.0 -1.0 -1.0,
            # time 0.5 coordinates (warped cube)
                -1.5  1.0  1.5,   1.5  1.0  1.5,
                 1.5  1.0 -1.5,  -1.5  1.0 -1.5,
                -0.5 -1.0  0.5,   0.5 -1.0  0.5,
                 0.5 -1.0 -0.5,  -0.5 -1.0 -0.5,
            # time 1.0 coordinates (cube)
                -1.0  1.0  1.0,   1.0  1.0  1.0,
                 1.0  1.0 -1.0,  -1.0  1.0 -1.0,
                -1.0 -1.0  1.0,   1.0 -1.0  1.0,
                 1.0 -1.0 -1.0,  -1.0 -1.0 -1.0
            ]
        }
    ]
}
ROUTE Clock.fraction_changed  TO CubeMorph.set_fraction
ROUTE CubeMorph.value_changed TO CubeCoordinates.set_point