Traversing the SceneObjects
by Fabio Zambetta · in Technical Issues · 10/09/2007 (10:29 pm) · 11 replies
Hi everyone,
I need to traverse all the sceneobjects in the level. How do I get them one by one?
Thanks!
GTW
I need to traverse all the sceneobjects in the level. How do I get them one by one?
Thanks!
GTW
About the author
#2
GTW
10/15/2007 (12:39 am)
Thanks Aun... just wondering, why is that class called MissionCleanup? I want to make sure that I'm getting the objects that are currently in the world.GTW
#3
but you should never need to traverse through all the sceneobjects in the world.
10/15/2007 (7:34 am)
You could also use a radius container search where the radius is the mission size.but you should never need to traverse through all the sceneobjects in the world.
#4
The MissionCleanup is just a simGroup to ensure that when the mission is over all the world object would be cleaned.
Aun.
Mayan Software
10/15/2007 (8:27 am)
@ Fabio ,The MissionCleanup is just a simGroup to ensure that when the mission is over all the world object would be cleaned.
Aun.
Mayan Software
#5
I tried it but I don't think it does what I want to do. My scene is a slightly modified version of the Torque Logo collecting tutorial. I've added at least 5 visible objects (excluding the player, the sky and the terrain) but MissionCleanup.getCount() gives only 2. When I iterate through them, I'm not getting the objects I want.
Can you help?
Thanks!
GTW
10/17/2007 (5:42 am)
Aun,I tried it but I don't think it does what I want to do. My scene is a slightly modified version of the Torque Logo collecting tutorial. I've added at least 5 visible objects (excluding the player, the sky and the terrain) but MissionCleanup.getCount() gives only 2. When I iterate through them, I'm not getting the objects I want.
Can you help?
Thanks!
GTW
#6
My guess is that you have added some of your objects to another simgroup. You could try something like this
Call the function by ...
Or you have another option if you already know which simGroup that contain the object you are interested you could name that simGroup and just traverse it normally.
Aun.
10/17/2007 (10:01 am)
@ Fabio,My guess is that you have added some of your objects to another simgroup. You could try something like this
function walkSimGroup ( %simGroup )
{
if ( %simGroup.getCount() <= 0 )
{
// do something with the simGroup
return ;
}
while( isObject ( %simGroup .getObject(0) ) )
{
%childSim = %simGroup .getObject(0) ;
if( %childSim.getCount() > 0 )
walkSimGroup ( %childSim ) ;
else
// do something with the simGroup
}
}Call the function by ...
walkSimGroup ( MissionCleanup ) ;
Or you have another option if you already know which simGroup that contain the object you are interested you could name that simGroup and just traverse it normally.
Aun.
#7
maybe you meant something like
10/17/2007 (10:16 am)
Aun - i don't understand how this line will ever evaluate as false:while( isObject ( %simGroup .getObject(0) ) )
maybe you meant something like
for (%n = 0; isObject(%simGroup.getObject(%n); %n++)?
#8
Yeap you right, my bad. I took it from some of my old code without looking carefully. Thanks for the correction :)
Aun.
Edit** gramma
10/17/2007 (10:21 am)
@Orion , Yeap you right, my bad. I took it from some of my old code without looking carefully. Thanks for the correction :)
Aun.
Edit** gramma
#9
What I exactly want to do is go through all the visible objects in a scene and check if they're in the player's view. So my idea was to use the code above to call the sceneState::isObjectRendered function on each object.
I also need to do this through C++ for speed. I'm not sure how to get access to the MissionCleanup in C++.
Would it be possible to go through the SceneGraph to get the SceneObjects? If so, what the fastest way to do this?
Thanks again!
GTW
10/17/2007 (7:15 pm)
Thanks guys... I tried it and it works.What I exactly want to do is go through all the visible objects in a scene and check if they're in the player's view. So my idea was to use the code above to call the sceneState::isObjectRendered function on each object.
I also need to do this through C++ for speed. I'm not sure how to get access to the MissionCleanup in C++.
Would it be possible to go through the SceneGraph to get the SceneObjects? If so, what the fastest way to do this?
Thanks again!
GTW
#10
1. Create a list of interested objects within the scene
2. When you need to get the object in the player's view take the player's position as a Vector and create a view angle calculate it with the player's position vector and you'll be able to test which object is in the player's view.
The reason with my approach is all of the code could be in script :)
Aun.
10/17/2007 (7:26 pm)
This is just my idea, I'm sure you could come up with something better.1. Create a list of interested objects within the scene
2. When you need to get the object in the player's view take the player's position as a Vector and create a view angle calculate it with the player's position vector and you'll be able to test which object is in the player's view.
The reason with my approach is all of the code could be in script :)
Aun.
#11
For step 2, I'm inclined to use SceneState's isObjectRendered() function because it's already there and does the same thing. How can I call it from script?
Thanks!
GTW
10/17/2007 (7:41 pm)
Thanks, Aun.For step 2, I'm inclined to use SceneState's isObjectRendered() function because it's already there and does the same thing. How can I call it from script?
Thanks!
GTW
Torque 3D Owner Aun Taraseina
%count = MissionCleanup.getCount () ; for (%i = 0 ; %i < %count ; %i++ ) { %obj = MissionCleanup.getObject (%i) ; // do something with %obj }Aun.
Mayan Software