WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 10-01-2004, 09:57 PM
vr_boyko vr_boyko is offline
Member
 
Join Date: Sep 2004
Posts: 19
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
Reply With Quote
  #2  
Old 10-04-2004, 10:51 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
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()
Let me know if I misunderstood your question.
Reply With Quote
  #3  
Old 10-05-2004, 03:27 PM
vr_boyko vr_boyko is offline
Member
 
Join Date: Sep 2004
Posts: 19
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?
Reply With Quote
  #4  
Old 10-05-2004, 03:37 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
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)
This probably doesn't do exactly what you want, but I think it should definitely be a good starting point.
Reply With Quote
  #5  
Old 10-08-2004, 01:11 AM
vsully vsully is offline
Member
 
Join Date: Sep 2004
Posts: 24
Send a message via AIM to vsully
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.
Reply With Quote
  #6  
Old 10-08-2004, 05:27 AM
vsully vsully is offline
Member
 
Join Date: Sep 2004
Posts: 24
Send a message via AIM to vsully
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.
Reply With Quote
  #7  
Old 10-08-2004, 10:49 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
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?
Attached Images
File Type: jpg screenshot.jpg (16.0 KB, 1877 views)
Reply With Quote
  #8  
Old 10-08-2004, 04:50 PM
vsully vsully is offline
Member
 
Join Date: Sep 2004
Posts: 24
Send a message via AIM to vsully
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
Reply With Quote
  #9  
Old 10-08-2004, 04:55 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

In the following code:
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:
Code:
trail.vertexcolor((cur_vertex+1)%TRAIL_SIZE, viz.YELLOW+[0])
Reply With Quote
  #10  
Old 10-08-2004, 05:29 PM
vsully vsully is offline
Member
 
Join Date: Sep 2004
Posts: 24
Send a message via AIM to vsully
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.
Reply With Quote
  #11  
Old 10-08-2004, 05:37 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
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()
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?
Reply With Quote
  #12  
Old 10-12-2004, 06:48 PM
vsully vsully is offline
Member
 
Join Date: Sep 2004
Posts: 24
Send a message via AIM to vsully
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
Reply With Quote
  #13  
Old 10-13-2004, 11:16 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

What position do you initialize the vertices to? Are the vertices attached to the screen?
Reply With Quote
  #14  
Old 10-13-2004, 11:32 AM
vsully vsully is offline
Member
 
Join Date: Sep 2004
Posts: 24
Send a message via AIM to vsully
They're initialized to viz.WORLD
Reply With Quote
  #15  
Old 10-13-2004, 11:37 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
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?
Reply With Quote
  #16  
Old 10-14-2004, 07:54 PM
vsully vsully is offline
Member
 
Join Date: Sep 2004
Posts: 24
Send a message via AIM to vsully
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
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 04:19 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC