Vizard 8 » Tutorials & Examples » 3D models » Creating 3D models on-the-fly » Tutorial: Adding shapes
8.0

Tutorial: Adding shapes

The vizshape library has commands for adding various shapes that you can treat as standard node3D objects. Unlike OTF primitives, their vertices can't be accessed or manipulated.

 

In this section of the tutorial we'll place three shapes within the maze that the user will have to find. Add the following code to randomly select positions for the shapes from a list of hard coded positions:

#Choose random locations for shapes
import random
locations = [ [9,1.5,-9.5] , [-9.3,1.5,-10] , [7.5,1.5,5.5] , [3,1.5,-9.5] , [-9.4,1.5,3] , [8.8,1.5,10.5] ]
positions = random.sample(locations,3)

The first shape is a yellow pyramid:

pyramid = vizshape.addPyramid(base=(0.5,0.5),height=0.5,pos=positions[0],color=viz.YELLOW)

The second shape is a textured torus:

torus = vizshape.addTorus(axis=vizshape.AXIS_X, pos=positions[1])
torus.texture(viz.addTexture('images/tile_wood.jpg'))

The third shape is a box whose left and right faces are individually colored:

box = vizshape.addBox(pos=positions[2],splitFaces=True)
box.color(viz.SKYBLUE)
box.color(viz.PURPLE,'left')
box.color(viz.PURPLE,'right')

Next, the shapes get animated and added to a shapes list:

#Animate shapes
pyramid.addAction(vizact.sequence([vizact.sizeTo(size=[2,2,2],time=1),vizact.sizeTo(size=[1,1,1],time=1)], viz.FOREVER))
x,y,z = box.getPosition()
box.addAction(vizact.sequence([vizact.moveTo(pos=[x,y+0.5,z],time=2),vizact.moveTo(pos=[x,y-0.5,z],time=2)], viz.FOREVER))
torus.addAction(vizact.spin(0,1,0,45))

shapes = [pyramid,torus,box]

If you run the script right now you'll see that the shapes get rendered to both the main window and birds eye window. Since the point of the game is for the user to navigate through the maze and find the shapes, we'll prevent them from rendering to the birds eye window:

# Prevent shapes from rendering to birds eye window
for s in shapes:
    s.renderToAllWindowsExcept([BirdEyeWindow])

Run the script and see if you can find the shapes.

Creating an on-the-fly object

Changing vertices on-the-fly

Adding shapes

Finding Shapes