View Full Version : Using on-the-fly with objects

10-01-2004, 08:57 PM

Is it possible to create on-the-fly objects using another object? Say I have a soccer ball object, and I want to create a string of them using on-the-fly. Is that allowed, or is OTF restricted to simple points and vertexes?

- thanks

10-04-2004, 09:51 AM

Do you just want to make a copy of an existing object? If this is the case then you can use the either the clone or copy command. Example:ball = viz.add('ball.wrl')
ball2 = ball.clone()
ball3 = ball.clone()Let me know if I misunderstood your question.

10-05-2004, 02:27 PM
Thanks for the reply.

Sorry about the vagueness - I was thinking more on the lines of using on-the-fly to create a sort of "3D paint" world. I'm tracking a second light for this world, which the user holds in his/her hand, and theoretically a stream of paint appears wherever the user moves the light.

My problem now is deciding on the implementation. I thought about creating small "paint pellet" spheres where the hand is every second, but I was concerned about clogging vizard with too many objects and polygons. Instead, I was wondering if I could use on-the-fly to create a kind of "paint tube" object. Theoretically, on-the-fly will constantly update the shape of this tube compared to the user's hand movements.

Is that possible?

10-05-2004, 02:37 PM

This is definitely possible. Here's a sample script I wrote a while back which creates a fading trail coming from the mouse position:import viz



history = []

for x in range(TRAIL_SIZE):
trail = viz.endlayer(viz.SCREEN)


def mytimer(num):
if len(history) > TRAIL_SIZE:
del history[0]

histsize = len(history)

for i in range(histsize):

viz.starttimer(0,0.001,viz.FOREVER)This probably doesn't do exactly what you want, but I think it should definitely be a good starting point.

10-08-2004, 12:11 AM
Thanks, the code works beautifully.

One question left: can I change the alpha level for a particular vertex to be transparent? Right now the code draws the line in one big circle, connecting the end of the line (where the mouse is) with the beginning of the line. I need a way to turn off that last segment, so the line appears to have a beginning and end.

I was looking at the .alpha function, but it seems to work only on the object as a whole. Any suggestions?

Thanks again.

10-08-2004, 04:27 AM
One more question:

Vizard seems to have trouble creating on-the-fly objects within the constructor of a class. Whenever I try (simply initializing all the vertex points) in the class, vizard complains that the type 'x' in viz.vertex(x, 0.3,0) must be of type float instead of type ([]).

I'm using code pretty close to what you provided, simply tailored a bit to a class constructor.

Thanks much for all your help.

10-08-2004, 09:49 AM

The code I gave you should already be setting the alpha value at each vertex. The alpha fades from 1 to 0 from the beginning of the trail to the end. The vertexcolor command has an optional fourth argument which represents the alpha value at that vertex. Be sure to enable viz.BLEND on the object in order for the alpha to work correctly.

Also, the trail should not be a loop. I've attached a screen shot of what the program above should look like when you run it.

There should be no problem with creating an OTF object in a class constructor. How are you initializing the value x?

10-08-2004, 03:50 PM
Here's a section of the code I'm running in the constructor:


for x in range(trailSize):
self.trail = viz.endlayer(viz.SCREEN)

Spot anything?

Secondly, I can't seem to get the transparency working right.
With this line of code:

trail.vertexcolor((cur_vertex+1)%TRAIL_SIZE, viz.YELLOW, 0)

The line still shows up bright yellow. viz.BLEND has been enabled. Spot anything here?

Sorry for the spam, and thanks for your help.


10-08-2004, 03:55 PM

In the following code:for x in range(trailSize):
viz.vertex(x,0.3,0) How is the variable trailSize initialized?

Also, for the vertex color try doing the following:trail.vertexcolor((cur_vertex+1)%TRAIL_S IZE, viz.YELLOW+[0])

10-08-2004, 04:29 PM
Vertex code works now - thanks. That's kind of random syntax though... :)

trailSize is passed in as a parameter. Right now I'm passing in the integer 400 for this field.

10-08-2004, 04:37 PM

Yeah, it is kind of weird. I've fixed it so that your previous code will work in future versions.

Regarding your other problem, the following code works fine over here:class TrailClass:
def __init__(self):


for x in range(400):
self.trail = viz.endlayer(viz.SCREEN)

lines = TrailClass()In the for loop where you declare each vertex will you try printing out the value of x and let me know what the output is?

10-12-2004, 05:48 PM
Hi farshizzo,

Thanks for all your help - I've managed to use the on-the-fly functionality like you've described and so far it shows potential. It's tempermental, but it works. :]

Now, however, I seem to be having openGL drawing errors with the on-the-fly. In VR the line draws exactly as it should, but occasionally a slight movement of the head will cause the line to disappear altogether, only to reappear when the head is moved back to it's original position. We're talking about a cm of movement here.

Any ideas?



10-13-2004, 10:16 AM

What position do you initialize the vertices to? Are the vertices attached to the screen?

10-13-2004, 10:32 AM
They're initialized to viz.WORLD

10-13-2004, 10:37 AM

That's what I figured. This is definitely a bug. In the meantime, initialize at least 2 of the vertices to a large range of values, like (100,100,100) to (-100,-100,-100). After they are initialized you can change their positions back to the original values.

I know this sounds weird, but it will take care of the disappearing problem. Is this the only problem you are having?

10-14-2004, 06:54 PM
OK, that worked - pretty weird hack. :]

I believe that's the last of the problems. Thanks for all your help; I should be set for a while.