Generate primitives at runtime

If you have the VastPark Player installed, download the example IMML file below and open the demo in the VastPark Player.

Overview

Shows generation of primitives at runtime. The entire visual of this scene is generated at runtime, as well as some logic for triggers on the primitives. This is useful when you have large amounts of content to download that you don’t want to delay the load of your document waiting for (lazy loading), ie: Video that isn’t streaming and isn’t used immediately after the document is loaded.

Instructions

Use left mouse button to generate and fire a box from the camera forwards. Hold down right mouse button to pivot the camera using the mouse.

Walkthrough

This code chunk is a loop which generates primitives calling the VastPark Player's interface through LUA.

 1 while(i < 50) do
 2         v.x = math.random(-10,10)
 3         v.z = math.random(-10,10)
 4 
 5         sphere = primitive()
 6         sphere.type = primitivetype.sphere
 7         sphere.position = v
 8         sphere.physics.enabled = true
 9         sphere.physics.movable = true
10         sphere.physics.weight = 20
11 
12         --put the trigger onto the generated spheres as well
13         t = trigger()
14         t.event = eventtype.mouseclick
15         t.target = 'GeneratePrim'
16 
17         sphere:add(t)
18         scene:add(sphere)
19 
20         i = i+1
21         end

What happens in this loop is that a primitive is created 50 times and a trigger is also created and added to each of those 50 primitives.

1 sphere = primitive()

This is a method call to the VastPark Player to create a new primitive. The primitive is created however it's properties have not been defined, those have to be defined as seen in this chunk.

1 sphere.type = primitivetype.sphere
2 sphere.position = v
3 sphere.physics.enabled = true
4 sphere.physics.movable = true
5 sphere.physics.weight = 20

Once those properties have been defined it is also important to add the primitive to the scene. If this is not done, the primitive won't be in the scene.

1 scene:add(sphere)

See Also

Primitive Help
Physics Help

generate-prims-runtime.imml - Requires Player v1.2 (2.4 kB) Tim Glew, 01/13/2011 07:36 am