WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 01-18-2011, 09:14 AM
miles miles is offline
Member
 
Join Date: Jan 2011
Posts: 21
Clearing the MainScene

Hello all,

I have recently joined an experimental research group using Vizard for submersing test subjects in a virtual environment. After becoming acquainted with Vizard and the existing code base, I am now working on improving features and fixing bugs.

One issue I can't quite seem to figure out is how to clear all objects from the scene. As it stands now, before each trial of the experiment is run, the environment is uniquely regenerated. However, the objects from previous trials persist trial to trial.

I need to find a way to clear the scene before it is regenerated. I have looked for a Vizard function that will do this with no avail. Any thoughts?

Thanks in advance
Reply With Quote
  #2  
Old 01-18-2011, 11:33 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
You could save each object you create in a global list. Then when you're ready to clear the scene use the <node3D>.remove command for each element in the list.
Reply With Quote
  #3  
Old 01-18-2011, 12:23 PM
miles miles is offline
Member
 
Join Date: Jan 2011
Posts: 21
I see, but there's no built in function for either clearing the whole scene, or getting a list of objects in the scene? I've tried for node in viz.getNodeList(): node.remove(), but this seems to give unexpected results.
Reply With Quote
  #4  
Old 01-18-2011, 12:30 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Try using viz.MainScene.getChildren() to get all the nodes in the scene.
Reply With Quote
  #5  
Old 01-18-2011, 12:58 PM
miles miles is offline
Member
 
Join Date: Jan 2011
Posts: 21
Thanks for the replies.

I've tried that too. I have the same unexpected results. For instance, running

viz.MainScene.getChildren()[0].remove()

in the console while it's running seems to mess up navigation.
Reply With Quote
  #6  
Old 01-18-2011, 01:22 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
Can you post some example code that shows the problem you're having?
Reply With Quote
  #7  
Old 01-18-2011, 01:37 PM
miles miles is offline
Member
 
Join Date: Jan 2011
Posts: 21
Unfortunately, the project is many large files, so I can't post the whole thing. I can try posting relevant sections, but it would be difficult to get it working isolated.

#loads all environmental objects
class Environment:
def __init__(self, config, link):
self.link = link

#clear the scene
### THIS IS NOT WORKING
#for child in viz.MainScene.getChildren():
# child.remove()

backgroundcolor = config.GetVector('vDisplayBackgroundColor')
viz.clearcolor(backgroundcolor)

self.court = viz.addTexQuad(viz.WORLD, viz.MainScene, 100)
self.court.setEuler(0,90,0)

#grass field
if config.GetBool('bEnvGroundTexture'):
grass = viz.addTexture('res/grass.jpg')
grass.wrap(viz.WRAP_T, viz.REPEAT)
grass.wrap(viz.WRAP_S, viz.REPEAT)
scale = viz.Transform()
scale.setScale(10,10,1)
self.court.texmat(scale)
self.court.texture(grass)
#green plane
else:
self.court.color(0,.3,0)
self.court.disable(viz.LIGHTING)
Reply With Quote
  #8  
Old 01-18-2011, 02:51 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
That's the problem with wanting to clear the entire scene, other modules might add their own hidden nodes to the scene which can cause problems when you delete them.

You can keep track of all the nodes you create and delete them individually, as Jeff already suggested.

The approach I would recommend is to create a root group node and add all your objects as children of it. Then you just need to delete the root node and all your objects will be cleared. Here is an example:
Code:
# Root node for all objects
root = viz.addGroup()

# Add object underneath root
court = viz.addTexQuad(parent=root)

.
.
.
# This will delete all the objects added to root
root.remove()
Reply With Quote
  #9  
Old 01-19-2011, 07:57 AM
miles miles is offline
Member
 
Join Date: Jan 2011
Posts: 21
Thanks, I will try making a group node. How would I define a shape with the root node as parent? I have this:

self.cylinder = vizshape.addCylinder(height, .02)
Reply With Quote
  #10  
Old 01-19-2011, 11:02 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
The vizshape commands accept the same optional arguments that you can use when creating other node3D objects. You can also use any node3D methods on the shape, such as <node3D>.parent().
Reply With Quote
  #11  
Old 01-19-2011, 11:45 AM
miles miles is offline
Member
 
Join Date: Jan 2011
Posts: 21
In the documentation, I see only

<vizshape>.addCylinder(
height = 1.0
radius = 0.5
topRadius = None
bottomRadius = None
axis = vizshape.AXIS_Y
slices = 20
bottom = True
top = True
)

How can I specify a parent? Thanks again for all the help.
Reply With Quote
  #12  
Old 01-19-2011, 02:38 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
You can either do:
Code:
cylinder = vizshape.addCylinder(parent=root)
or
Code:
cylinder = vizshape.addCylinder()
cylinder.parent(root)
Reply With Quote
  #13  
Old 01-19-2011, 04:09 PM
miles miles is offline
Member
 
Join Date: Jan 2011
Posts: 21
It's working fine now. Thanks Jeff and farshizzo!
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 03:46 PM.


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