Access Objects in a Scene
by Eric Armstrong · in Torque Game Builder · 01/04/2006 (12:45 pm) · 6 replies
Is there a way for me to get access to the objects in a scene after I have loaded it from disk? Specifically, I have a TileMap that was saved with the scene that I would like to have access to after I load it. I looked through the docs, but couldn't find anything that looked to give me access. Is there such a method?
Apologies if it's something obvious and I just missed it.
Thanks...
Apologies if it's something obvious and I just missed it.
Thanks...
#2
If you want this call now then you can add the following code and recompile:
To the "t2dSceneGraph.h" file (next to the "getSceneObjectList()" call):
To the "t2dSceneGraph.cc" file:
Hope this helps,
- Melv.
01/04/2006 (1:38 pm)
Eric,If you want this call now then you can add the following code and recompile:
To the "t2dSceneGraph.h" file (next to the "getSceneObjectList()" call):
inline t2dSceneObject* getSceneObject( const U32 objectIndex );
To the "t2dSceneGraph.cc" file:
//-----------------------------------------------------------------------------
// Get Scene Object.
//-----------------------------------------------------------------------------
ConsoleMethod(t2dSceneGraph, getSceneObject, S32, 2, 2, "Gets the selected Scene Object.")
{
// Fetch Object Index.
const U32 objectIndex = dAtoi(argv[2]);
// Fetch Scene Object.
const t2dSceneObject* pSceneObject = object->getSceneObject( objectIndex );
// Check Object.
if ( pSceneObject != NULL )
{
// No error so return object id.
return pSceneObject->getId();
}
else
{
// Error so warn.
Con::warnf("t2dSceneGraph::getSceneObject() - Cannot retrieve specified object index (%d)!", objectIndex);
// Return no object.
return 0;
}
}
// Get Scene Object.
t2dSceneObject* t2dSceneGraph::getSceneObject( const U32 objectIndex )
{
// No objects if scene is empty!
if ( getSceneObjectCount() == 0 )
return NULL;
// Reset object index.
U32 objectCount = 0;
// Fetch First Object.
t2dSceneObject* pSceneObject2D = getProcessHead()->getProcessNext();
// Process Objects until all actioned.
while ( pSceneObject2D != getProcessHead() )
{
// Is this our object?
if ( objectIndex == objectCount )
{
// Yes, so return object.
return pSceneObject2D;
}
// Fetch Next Object.
pSceneObject2D = pSceneObject2D->getProcessNext();
// Increase Object Count.
objectCount++;
};
// Return Error.
return NULL;
}Hope this helps,
- Melv.
#3
Thanks again...
01/04/2006 (1:43 pm)
Excellent! Exactly what I needed... I'll throw that new code in there now so I'll be set for the next update.Thanks again...
#4
To the "t2dSceneGraph.h" file (next to the "getSceneTime()" call):
To the "t2dSceneObject.h" file (next to the "getProcessMount()" call):
Or you can simply refer directly to "mpProcessHead" and "mpNextProcess" if you wish.
Sorry for the confusion,
- Melv.
01/04/2006 (11:17 pm)
@Eric: I got a notification of your post but it's not here so I assume you deleted it? I'll reply anyway.Quote:Looks like I need the getProcessHead() method also...Yeah, sorry about that. Here are some of the missing commands:-
To the "t2dSceneGraph.h" file (next to the "getSceneTime()" call):
inline t2dSceneObject* getProcessHead( void ) const { return mpProcessHead; };To the "t2dSceneObject.h" file (next to the "getProcessMount()" call):
t2dSceneObject* getProcessNext( void ) const { return mpNextProcess; };
t2dSceneObject* getProcessPrevious( void ) const { return mpPreviousProcess; };Or you can simply refer directly to "mpProcessHead" and "mpNextProcess" if you wish.
Sorry for the confusion,
- Melv.
#5
This:
Should be:
Other than those changes, it worked perfectly. Thanks again...
01/05/2006 (5:16 am)
Yea, I found the mpProcessHead and mpNextProcess stuff from the other methods, so I was able to get it working. One other change to make though also.This:
ConsoleMethod(t2dSceneGraph, getSceneObject, S32, 2, 2, "Gets the selected Scene Object.")
Should be:
ConsoleMethod(t2dSceneGraph, getSceneObject, S32, 3, 3, "Gets the selected Scene Object.")
Other than those changes, it worked perfectly. Thanks again...
Associate Melv May
- "t2dSceneGraph::getSceneObjectCount()"
- "t2dSceneGraph::getSceneObjectList()"
The first command gives you an object count and the second one simply retrieves a complete list of objects. You can access this list using the standard "getWord()" call.
There is an additional (and more useful) command in the next release:
- "t2dSceneGraph::getSceneObject(index)"
This new command lets you access objects in the scene by their logical scene-index one at a time.
Hope this helps,
- Melv.