#1
|
|||
|
|||
Using on-the-fly with objects
Hi-
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 |
#2
|
|||
|
|||
Hi,
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: Code:
ball = viz.add('ball.wrl') ball2 = ball.clone() ball3 = ball.clone() |
#3
|
|||
|
|||
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? |
#4
|
|||
|
|||
Hi,
This is definitely possible. Here's a sample script I wrote a while back which creates a fading trail coming from the mouse position: Code:
import viz viz.go() TRAIL_SIZE = 40 TRAIL_COLOR = viz.RED history = [] viz.startlayer(viz.LINE_STRIP) viz.vertexcolor(0,0,0,0) viz.linewidth(2) for x in range(TRAIL_SIZE): viz.vertex(x,0.5,0) trail = viz.endlayer(viz.SCREEN) trail.dynamic() trail.enable(viz.BLEND) def mytimer(num): history.append(viz.mousepos()) if len(history) > TRAIL_SIZE: del history[0] histsize = len(history) for i in range(histsize): trail.vertexcolor(i,TRAIL_COLOR+[i/float(histsize)]) trail.vertex(i,history[i][0],history[i][1]) viz.callback(viz.TIMER_EVENT,mytimer) viz.starttimer(0,0.001,viz.FOREVER) |
#5
|
|||
|
|||
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. |
#6
|
|||
|
|||
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. |
#7
|
|||
|
|||
Hi,
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? |
#8
|
|||
|
|||
Here's a section of the code I'm running in the constructor:
--- viz.startlayer(viz.LINE_STRIP) viz.vertexcolor(Color) viz.linewidth(Size) for x in range(trailSize): viz.vertex(x,0.3,0) 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. -Aaron |
#9
|
|||
|
|||
Hi,
In the following code: Code:
for x in range(trailSize): viz.vertex(x,0.3,0) Also, for the vertex color try doing the following: Code:
trail.vertexcolor((cur_vertex+1)%TRAIL_SIZE, viz.YELLOW+[0]) |
#10
|
|||
|
|||
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. |
#11
|
|||
|
|||
Hi,
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: Code:
class TrailClass: def __init__(self): viz.startlayer(viz.LINE_STRIP) viz.vertexcolor(viz.RED) viz.linewidth(1) for x in range(400): viz.vertex(x,0.3,0) self.trail = viz.endlayer(viz.SCREEN) lines = TrailClass() |
#12
|
|||
|
|||
drawing errors
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? Thanks, Aaron |
#13
|
|||
|
|||
Hi,
What position do you initialize the vertices to? Are the vertices attached to the screen? |
#14
|
|||
|
|||
They're initialized to viz.WORLD
|
#15
|
|||
|
|||
Hi,
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? |
#16
|
|||
|
|||
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. -Aaron |
|
|