WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 12-18-2008, 08:58 AM
moooh moooh is offline
Member
 
Join Date: Dec 2008
Posts: 19
Problem with unparent

I'm running into some trouble with the <node3d>.unparent() function. It seems that the detaching of the node is not complete.
Normally, changing visibility state of a parent will also affect all its children.
I want to have a child visible whilst the parent is invisible and in order to do that I have to detach the child from the parent prior to changing their visibility states.


Initially I have a cube created onthefly and a sphere obtained through viz.add both contained in a class
(omitted cube creation)
self.cube = viz.endlayer()
self.cube.parent(self.sphere)

Code:
objectList = [] #a list of objects
flag = 0
def toggleVisibility():
    global objectList, flag
	
    flag = 1 - flag #toggle flag value
	
    for obj in objectList:
        if flag:
	    obj.cube.unparent(obj.sphere) #detach the cube from the sphere
	else:
	    obj.cube.parent(obj.sphere) #put the cube back as child
		
	obj.cube.visible(flag)	#makes the cube visible when the sphere is not visible
	obj.sphere.visible(1 - flag)	#makes the sphere visible when the cube is not visible
		
	print "cube visibility: " + str(obj.cube.getVisible())
	print "sphere visibility: " + str(obj.sphere.getVisible())
The two print at the bottom gives:
false
true
when the flag is 0, which is the expected result.

The print gives:
true
false
when the flag is 1, which is also expected.
However, even though the cube.getVisible() gives me true, the cube is not rendered when the former parent (the sphere) is invisible.

If I modify the code to keep the cube visibility at 1 at all times, the cube shows up when the sphere is visible, and disappears when the spear is invisible, which makes me think that the cube is still a child of the sphere even though the call to unparent has been made.
Reply With Quote
  #2  
Old 12-18-2008, 02:56 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
When you unparent the cube from the sphere, it will no longer exist in the scene graph, so it won't be rendered. I would recommend creating a group node that serves as the parent of the cube and sphere. This way you can toggle the visibility of the cube and sphere independently.
Reply With Quote
  #3  
Old 12-19-2008, 01:37 AM
moooh moooh is offline
Member
 
Join Date: Dec 2008
Posts: 19
I see. Is there any way to re-attach the cube to the scene graph after the unparenting? The reason I wonder is that I still need to have the cube as child of the sphere because alot of transformations are done on the sphere node. Adding another level of hierarchy above the sphere will force me to rewrite quite many parts so I was kind of hoping to avoid that.


Perhaps I could give it a new parent instead of unparenting, maybe assign it to a group node at the times the sphere is invisible and re-assign it back to the sphere when the cube is invisible. I'm going to try this out.

edit:no of course that wouldn't work, the cubes would just move to the group nodes position when they are assigned as childs.

Guess I'm stuck with having to do some rewriting then.

Last edited by moooh; 12-19-2008 at 01:42 AM.
Reply With Quote
  #4  
Old 12-19-2008, 10:14 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
You can reparent the cube to any part of the scene graph. For example, if you wanted to reparent the cube to root of the scene, then instead of calling cube.unparent() you would call the following:
Code:
cube.parent(viz.WORLD)
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
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
sound problem alaa Vizard 7 09-02-2005 01:13 PM
PROBLEM: Picture-in-Picture breaks textures?!? vcarlson Vizard 4 10-05-2004 04:22 PM


All times are GMT -7. The time now is 02:10 AM.


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