WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 02-02-2009, 07:50 AM
Sandro Holzer Sandro Holzer is offline
Member
 
Join Date: Jul 2008
Posts: 19
node3d.visible(viz.OFF) Problem

Hello

I have a small problems with the node3d.visible command.

if I have 2 bodies like in the following code, when I swith off the visibility of the first body, then the second body also disapears.
Is there a workaround?

Thank you

Sandro


Code:
body1 = viz.add('body1.obj')
body2 = body1.add('body2.obj')

body1.visible(viz.OFF)
Reply With Quote
  #2  
Old 02-02-2009, 10:56 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,457
You can link an empty group node to your original parent object and then set the group node to be the parent of your child object. Then when you change the visibility of the original parent it won't affect the child. Here's an example.

Code:
import viz
viz.go()

box = viz.add('box.wrl',pos=[0,0,5])

#add empty group node and link it to the box
group = viz.addGroup()
link = viz.link(box,group)

#add the ball with the group node as parent
ball = viz.add('ball.wrl',parent=group,pos=[0,1,0])

#toggle box visibility
vizact.onkeydown(' ',box.visible,viz.TOGGLE)

#move box back and forth
moveback = vizact.goto(0,0,10,3)
moveforward = vizact.goto(0,0,5,3)
move = vizact.sequence([moveback,moveforward],viz.FOREVER) 
box.addAction(move)
Reply With Quote
  #3  
Old 02-03-2009, 02:22 AM
Sandro Holzer Sandro Holzer is offline
Member
 
Join Date: Jul 2008
Posts: 19
Thank You Jeff

I just have one more problem with this code.
In the line:

Code:
ball = viz.add('ball.wrl',parent=group,pos=[0,1,0])
the position of the ball is in world coordinates,
I would need to give this position in relation to the box.
In my real code, there are a lot of bodies, all connected in something like a chain.
So if I have to calculate all the initial positions in world coordinates it would be a lot of work.
With the line
Code:
body2 = body1.add('body2.obj')
in my original code all this work is done by Vizard. (but visibility does not work the way I want)

Do you have an idea how to do this?
Sandro
Reply With Quote
  #4  
Old 02-03-2009, 10:34 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,457
the position of the ball is set in its parent coordinate system, the default is viz.ABS_PARENT. So the ball is always [0,1,0] in the group node's coordinate system which is the same as the box. If you try
Code:
print ball.getPosition(viz.ABS_GLOBAL)
you'll see its position is not [0,1,0] in the global coordinate system
Reply With Quote
  #5  
Old 02-04-2009, 08:17 AM
Sandro Holzer Sandro Holzer is offline
Member
 
Join Date: Jul 2008
Posts: 19
Hi

Sorry, I am not able to work it ou by myself.
I added a small sample, and it should work like this:
there are 3 bars in a chain. The bar-body is attached
bar1 should rotate araund the vertikal axis (keys "t" and "b")
on the end of bar1, bar2 is connected and should rotate like a arm.
and on the end of bar2, bar3 is connected and should also rotate like a arm.

and then I want to switch the visibility of bar2

The first code is like I want it:

Code:
import viz
viz.go()
 
viz.clearcolor(0.1,0.1,1)
#ground = viz.add('tut_ground.wrl')
ANCHOR_POS= (0.6,1.8005,6)
bar1 = viz.add('bar2.obj',pos=ANCHOR_POS)
bar2 = bar1.add('bar2.obj')
bar2.translate([0.0,0.0,-1])


bar3 = bar2.add('bar2.obj')
bar3.translate([0.0,0.0,-1])

a = 0
b = 0
c = 0

def mytimer(num):
	global a,b,c
	if viz.iskeydown('t'):
		a = a + 1
		if a > 89:
			a = 89
		
		move()
	if viz.iskeydown('b'):
		a = a - 1
		if a < -89:
			a = -89
		move()
		
	if viz.iskeydown('f'):
		b = b + 1
		if b > 89:
			b = 89
		move()
	if viz.iskeydown('h'):
		b = b - 1
		if b < -89:
			b = -89
		move()
		
	if viz.iskeydown('z'):
		c = c + 1
		if c > 89:
			c = 89
		move()
	if viz.iskeydown('n'):
		c = c - 1
		if c < -89:
			c = -89
		move()

def move():
	
	euler = bar1.getEuler(viz.ABS_GLOBAL)
	euler[0] = a
	bar1.setEuler(euler,viz.ABS_GLOBAL)
	
	euler = bar2.getEuler(viz.ABS_GLOBAL)
	euler[1] = b
	bar2.setEuler(euler,viz.ABS_GLOBAL)
	
	euler = bar3.getEuler(viz.ABS_GLOBAL)
	euler[1] = c
	bar3.setEuler(euler,viz.ABS_GLOBAL)


	
	
vizact.onkeydown(' ',bar2.visible,viz.TOGGLE)

viz.callback(viz.TIMER_EVENT,mytimer)
viz.starttimer(0,0.02,viz.FOREVER)
The following code is with the linked group:

First problem, the bar3 is not at the end of bar2 (you have to navigate back to look for it) this has something to do with the ANCHOR_POS of the first bar.
Second problem, bar3 follows bar2, but not the bar1.

Code:
import viz
viz.go()
 
viz.clearcolor(0.1,0.1,1)
#ground = viz.add('tut_ground.wrl')
ANCHOR_POS= (0.6,1.8005,6)
bar1 = viz.add('bar2.obj',pos=ANCHOR_POS)
bar2 = bar1.add('bar2.obj')
bar2.translate([0.0,0.0,-1])
group = viz.addGroup()
link = viz.link(bar2,group)


bar3 = viz.add('bar2.obj',parent=group,pos=[0.0,0.0,-1.0])



a = 0
b = 0
c = 0

def mytimer(num):
	global a,b,c
	if viz.iskeydown('t'):
		a = a + 1
		if a > 89:
			a = 89
		
		move()
	if viz.iskeydown('b'):
		a = a - 1
		if a < -89:
			a = -89
		move()
		
	if viz.iskeydown('f'):
		b = b + 1
		if b > 89:
			b = 89
		move()
	if viz.iskeydown('h'):
		b = b - 1
		if b < -89:
			b = -89
		move()
		
	if viz.iskeydown('z'):
		c = c + 1
		if c > 89:
			c = 89
		move()
	if viz.iskeydown('n'):
		c = c - 1
		if c < -89:
			c = -89
		move()

def move():
	
	euler = bar1.getEuler(viz.ABS_GLOBAL)
	euler[0] = a
	bar1.setEuler(euler,viz.ABS_GLOBAL)
	
	euler = bar2.getEuler(viz.ABS_GLOBAL)
	euler[1] = b
	bar2.setEuler(euler,viz.ABS_GLOBAL)
	
	euler = bar3.getEuler(viz.ABS_GLOBAL)
	euler[1] = c
	bar3.setEuler(euler,viz.ABS_GLOBAL)


	
	
vizact.onkeydown(' ',bar2.visible,viz.TOGGLE)

viz.callback(viz.TIMER_EVENT,mytimer)
viz.starttimer(0,0.02,viz.FOREVER)
Attached Files
File Type: zip bar2.zip (1.1 KB, 379 views)
Reply With Quote
  #6  
Old 02-05-2009, 01:11 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,457
Here are two options. For your code without the group node you could replace
Code:
vizact.onkeydown(' ',bar2.visible,viz.TOGGLE)
with something like
Code:
vizact.onkeydown('1',bar2.disable,viz.RENDERING)
vizact.onkeydown('2',bar2.enable,viz.RENDERING)
the third bar will continue to be rendered whether or not the second one is

in the code with group node and the link you could add
Code:
link.setSrcFlag(viz.ABS_GLOBAL)
after creating the link. The third bar will be in the correct position and you can toggle the visibility of the second bar.
Reply With Quote
  #7  
Old 02-10-2009, 06:20 AM
Sandro Holzer Sandro Holzer is offline
Member
 
Join Date: Jul 2008
Posts: 19
Thank you Jeff

The version with "bar.disable,viz.RENDERING" works best for me, and I think this is the easiest way to do it.
And with this version I can still use the "box.visible,viz.TOGGLE" command when I want all linked nodes to disappear.

Sandro
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Vertex shader performance problem Joran Vizard 2 11-17-2008 01:29 AM
export problem bazelaisr Vizard 2 05-28-2008 10:19 AM
5DT Data Glove 5 Ultra Problem bjgold Vizard 1 08-08-2006 04:08 PM
problem with female animations vmonkey Vizard 1 10-07-2005 10:36 AM
PROBLEM: Picture-in-Picture breaks textures?!? vcarlson Vizard 4 10-05-2004 04:22 PM


All times are GMT -7. The time now is 08:11 PM.


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