View Single Post
  #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