sceneManager.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "platform/platform.h"
  23. #include "scene/sceneManager.h"
  24. #include "scene/sceneObject.h"
  25. #include "scene/zones/sceneTraversalState.h"
  26. #include "scene/sceneRenderState.h"
  27. #include "scene/zones/sceneRootZone.h"
  28. #include "scene/zones/sceneZoneSpace.h"
  29. #include "lighting/lightManager.h"
  30. #include "renderInstance/renderPassManager.h"
  31. #include "gfx/gfxDevice.h"
  32. #include "gfx/gfxDrawUtil.h"
  33. #include "gfx/gfxDebugEvent.h"
  34. #include "console/engineAPI.h"
  35. #include "sim/netConnection.h"
  36. #include "T3D/gameBase/gameConnection.h"
  37. // For player object bounds workaround.
  38. #include "T3D/player.h"
  39. extern bool gEditingMission;
  40. MODULE_BEGIN( Scene )
  41. MODULE_INIT_AFTER( Sim )
  42. MODULE_SHUTDOWN_BEFORE( Sim )
  43. MODULE_INIT
  44. {
  45. // Client scene.
  46. gClientSceneGraph = new SceneManager( true );
  47. // Server scene.
  48. gServerSceneGraph = new SceneManager( false );
  49. Con::addVariable( "$Scene::lockCull", TypeBool, &SceneManager::smLockDiffuseFrustum,
  50. "Debug tool which locks the frustum culling to the current camera location.\n"
  51. "@ingroup Rendering\n" );
  52. Con::addVariable( "$Scene::disableTerrainOcclusion", TypeBool, &SceneCullingState::smDisableTerrainOcclusion,
  53. "Used to disable the somewhat expensive terrain occlusion testing.\n"
  54. "@ingroup Rendering\n" );
  55. Con::addVariable( "$Scene::disableZoneCulling", TypeBool, &SceneCullingState::smDisableZoneCulling,
  56. "If true, zone culling will be disabled and the scene contents will only be culled against the root frustum.\n\n"
  57. "@ingroup Rendering\n" );
  58. Con::addVariable( "$Scene::renderBoundingBoxes", TypeBool, &SceneManager::smRenderBoundingBoxes,
  59. "If true, the bounding boxes of objects will be displayed.\n\n"
  60. "@ingroup Rendering" );
  61. Con::addVariable( "$Scene::maxOccludersPerZone", TypeS32, &SceneCullingState::smMaxOccludersPerZone,
  62. "Maximum number of occluders that will be concurrently allowed into the scene culling state of any given zone.\n\n"
  63. "@ingroup Rendering" );
  64. Con::addVariable( "$Scene::occluderMinWidthPercentage", TypeF32, &SceneCullingState::smOccluderMinWidthPercentage,
  65. "TODO\n\n"
  66. "@ingroup Rendering" );
  67. Con::addVariable( "$Scene::occluderMinHeightPercentage", TypeF32, &SceneCullingState::smOccluderMinHeightPercentage,
  68. "TODO\n\n"
  69. "@ingroup Rendering" );
  70. }
  71. MODULE_SHUTDOWN
  72. {
  73. SAFE_DELETE( gClientSceneGraph );
  74. SAFE_DELETE( gServerSceneGraph );
  75. }
  76. MODULE_END;
  77. bool SceneManager::smRenderBoundingBoxes;
  78. bool SceneManager::smLockDiffuseFrustum = false;
  79. SceneCameraState SceneManager::smLockedDiffuseCamera = SceneCameraState( RectI(), Frustum(), MatrixF(), MatrixF() );
  80. SceneManager* gClientSceneGraph = NULL;
  81. SceneManager* gServerSceneGraph = NULL;
  82. //-----------------------------------------------------------------------------
  83. SceneManager::SceneManager( bool isClient )
  84. : mLightManager( NULL ),
  85. mCurrentRenderState( NULL ),
  86. mIsClient( isClient ),
  87. mUsePostEffectFog( true ),
  88. mDisplayTargetResolution( 0, 0 ),
  89. mDefaultRenderPass( NULL ),
  90. mVisibleDistance( 500.f ),
  91. mNearClip( 0.1f ),
  92. mAmbientLightColor( ColorF( 0.1f, 0.1f, 0.1f, 1.0f ) ),
  93. mZoneManager( NULL )
  94. {
  95. VECTOR_SET_ASSOCIATION( mBatchQueryList );
  96. // For the client, create a zone manager.
  97. if( isClient )
  98. {
  99. mZoneManager = new SceneZoneSpaceManager( getContainer() );
  100. // Add the root zone to the scene.
  101. addObjectToScene( mZoneManager->getRootZone() );
  102. }
  103. }
  104. //-----------------------------------------------------------------------------
  105. SceneManager::~SceneManager()
  106. {
  107. SAFE_DELETE( mZoneManager );
  108. if( mLightManager )
  109. mLightManager->deactivate();
  110. }
  111. //-----------------------------------------------------------------------------
  112. void SceneManager::renderScene( ScenePassType passType, U32 objectMask )
  113. {
  114. SceneCameraState cameraState = SceneCameraState::fromGFX();
  115. // Handle frustum locking.
  116. const bool lockedFrustum = ( smLockDiffuseFrustum && passType == SPT_Diffuse );
  117. if( lockedFrustum )
  118. cameraState = smLockedDiffuseCamera;
  119. else if( passType == SPT_Diffuse )
  120. {
  121. // Store the camera state so if we lock, this will become the
  122. // locked state.
  123. if( passType == SPT_Diffuse )
  124. smLockedDiffuseCamera = cameraState;
  125. }
  126. // Create the render state.
  127. SceneRenderState renderState( this, passType, cameraState );
  128. // If we have locked the frustum, reset the view transform
  129. // on the render pass which the render state has just set
  130. // to the view matrix corresponding to the locked frustum. For
  131. // rendering, however, we need the true view matrix from the
  132. // GFX state.
  133. if( lockedFrustum )
  134. {
  135. RenderPassManager* rpm = renderState.getRenderPass();
  136. rpm->assignSharedXform( RenderPassManager::View, GFX->getWorldMatrix() );
  137. }
  138. // Render.
  139. renderScene( &renderState, objectMask );
  140. }
  141. //-----------------------------------------------------------------------------
  142. void SceneManager::renderScene( SceneRenderState* renderState, U32 objectMask, SceneZoneSpace* baseObject, U32 baseZone )
  143. {
  144. PROFILE_SCOPE( SceneGraph_renderScene );
  145. // Get the lights for rendering the scene.
  146. PROFILE_START( SceneGraph_registerLights );
  147. LIGHTMGR->registerGlobalLights( &renderState->getFrustum(), false );
  148. PROFILE_END();
  149. // If its a diffuse pass, update the current ambient light level.
  150. // To do that find the starting zone and determine whether it has a custom
  151. // ambient light color. If so, pass it on to the ambient light manager.
  152. // If not, use the ambient light color of the sunlight.
  153. //
  154. // Note that we retain the starting zone information here and pass it
  155. // on to renderSceneNoLights so that we don't need to look it up twice.
  156. if( renderState->isDiffusePass() )
  157. {
  158. if( !baseObject && getZoneManager() )
  159. {
  160. getZoneManager()->findZone( renderState->getCameraPosition(), baseObject, baseZone );
  161. AssertFatal( baseObject != NULL, "SceneManager::renderScene - findZone() did not return an object" );
  162. }
  163. ColorF zoneAmbient;
  164. if( baseObject && baseObject->getZoneAmbientLightColor( baseZone, zoneAmbient ) )
  165. mAmbientLightColor.setTargetValue( zoneAmbient );
  166. else
  167. {
  168. const LightInfo* sunlight = LIGHTMGR->getSpecialLight( LightManager::slSunLightType );
  169. if( sunlight )
  170. mAmbientLightColor.setTargetValue( sunlight->getAmbient() );
  171. }
  172. renderState->setAmbientLightColor( mAmbientLightColor.getCurrentValue() );
  173. }
  174. // Trigger the pre-render signal.
  175. PROFILE_START( SceneGraph_preRenderSignal);
  176. mCurrentRenderState = renderState;
  177. getPreRenderSignal().trigger( this, renderState );
  178. mCurrentRenderState = NULL;
  179. PROFILE_END();
  180. // Render the scene.
  181. renderSceneNoLights( renderState, objectMask, baseObject, baseZone );
  182. // Trigger the post-render signal.
  183. PROFILE_START( SceneGraphRender_postRenderSignal );
  184. mCurrentRenderState = renderState;
  185. getPostRenderSignal().trigger( this, renderState );
  186. mCurrentRenderState = NULL;
  187. PROFILE_END();
  188. // Remove the previously registered lights.
  189. PROFILE_START( SceneGraph_unregisterLights);
  190. LIGHTMGR->unregisterAllLights();
  191. PROFILE_END();
  192. }
  193. //-----------------------------------------------------------------------------
  194. void SceneManager::renderSceneNoLights( SceneRenderState* renderState, U32 objectMask, SceneZoneSpace* baseObject, U32 baseZone )
  195. {
  196. // Set the current state.
  197. mCurrentRenderState = renderState;
  198. // Render.
  199. _renderScene( mCurrentRenderState, objectMask, baseObject, baseZone );
  200. #ifdef TORQUE_DEBUG
  201. // If frustum is locked and this is a diffuse pass, render the culling volumes of
  202. // zones that are selected (or the volumes of the outdoor zone if no zone is
  203. // selected).
  204. if( gEditingMission && renderState->isDiffusePass() && smLockDiffuseFrustum )
  205. renderState->getCullingState().debugRenderCullingVolumes();
  206. #endif
  207. mCurrentRenderState = NULL;
  208. }
  209. //-----------------------------------------------------------------------------
  210. void SceneManager::_renderScene( SceneRenderState* state, U32 objectMask, SceneZoneSpace* baseObject, U32 baseZone )
  211. {
  212. AssertFatal( this == gClientSceneGraph, "SceneManager::_buildSceneGraph - Only the client scenegraph can support this call!" );
  213. PROFILE_SCOPE( SceneGraph_batchRenderImages );
  214. // In the editor, override the type mask for diffuse passes.
  215. if( gEditingMission && state->isDiffusePass() )
  216. objectMask = EDITOR_RENDER_TYPEMASK;
  217. // Update the zoning state and traverse zones.
  218. if( getZoneManager() )
  219. {
  220. // Update.
  221. getZoneManager()->updateZoningState();
  222. // If zone culling isn't disabled, traverse the
  223. // zones now.
  224. if( !state->getCullingState().disableZoneCulling() )
  225. {
  226. // Find the start zone if we haven't already.
  227. if( !baseObject )
  228. {
  229. getZoneManager()->findZone( state->getCameraPosition(), baseObject, baseZone );
  230. AssertFatal( baseObject != NULL, "SceneManager::_renderScene - findZone() did not return an object" );
  231. }
  232. // Traverse zones starting in base object.
  233. SceneTraversalState traversalState( &state->getCullingState() );
  234. PROFILE_START( Scene_traverseZones );
  235. baseObject->traverseZones( &traversalState, baseZone );
  236. PROFILE_END();
  237. // Set the scene render box to the area we have traversed.
  238. state->setRenderArea( traversalState.getTraversedArea() );
  239. }
  240. }
  241. // Set the query box for the container query. Never
  242. // make it larger than the frustum's AABB. In the editor,
  243. // always query the full frustum as that gives objects
  244. // the opportunity to render editor visualizations even if
  245. // they are otherwise not in view.
  246. if( !state->getFrustum().getBounds().isOverlapped( state->getRenderArea() ) )
  247. {
  248. // This handles fringe cases like flying backwards into a zone where you
  249. // end up pretty much standing on a zone border and looking directly into
  250. // its "walls". In that case the traversal area will be behind the frustum
  251. // (remember that the camera isn't where visibility starts, it's the near
  252. // distance).
  253. return;
  254. }
  255. Box3F queryBox = state->getFrustum().getBounds();
  256. if( !gEditingMission )
  257. {
  258. queryBox.minExtents.setMax( state->getRenderArea().minExtents );
  259. queryBox.maxExtents.setMin( state->getRenderArea().maxExtents );
  260. }
  261. PROFILE_START( Scene_cullObjects );
  262. //TODO: We should split the codepaths here based on whether the outdoor zone has visible space.
  263. // If it has, we should use the container query-based path.
  264. // If it hasn't, we should fill the object list directly from the zone lists which will usually
  265. // include way fewer objects.
  266. // Gather all objects that intersect the scene render box.
  267. mBatchQueryList.clear();
  268. getContainer()->findObjectList( queryBox, objectMask, &mBatchQueryList );
  269. // Cull the list.
  270. U32 numRenderObjects = state->getCullingState().cullObjects(
  271. mBatchQueryList.address(),
  272. mBatchQueryList.size(),
  273. !state->isDiffusePass() ? SceneCullingState::CullEditorOverrides : 0 // Keep forced editor stuff out of non-diffuse passes.
  274. );
  275. //HACK: If the control object is a Player and it is not in the render list, force
  276. // it into it. This really should be solved by collision bounds being separate from
  277. // object bounds; only because the Player class is using bounds not encompassing
  278. // the actual player object is it that we have this problem in the first place.
  279. // Note that we are forcing the player object into ALL passes here but such
  280. // is the power of proliferation of things done wrong.
  281. GameConnection* connection = GameConnection::getConnectionToServer();
  282. if( connection )
  283. {
  284. Player* player = dynamic_cast< Player* >( connection->getControlObject() );
  285. if( player )
  286. {
  287. mBatchQueryList.setSize( numRenderObjects );
  288. if( !mBatchQueryList.contains( player ) )
  289. {
  290. mBatchQueryList.push_back( player );
  291. numRenderObjects ++;
  292. }
  293. }
  294. }
  295. PROFILE_END();
  296. // Render the remaining objects.
  297. PROFILE_START( Scene_renderObjects );
  298. state->renderObjects( mBatchQueryList.address(), numRenderObjects );
  299. PROFILE_END();
  300. // Render bounding boxes, if enabled.
  301. if( smRenderBoundingBoxes && state->isDiffusePass() )
  302. {
  303. GFXDEBUGEVENT_SCOPE( Scene_renderBoundingBoxes, ColorI::WHITE );
  304. GameBase* cameraObject = 0;
  305. if( connection )
  306. cameraObject = connection->getCameraObject();
  307. GFXStateBlockDesc desc;
  308. desc.setFillModeWireframe();
  309. desc.setZReadWrite( true, false );
  310. for( U32 i = 0; i < numRenderObjects; ++ i )
  311. {
  312. SceneObject* object = mBatchQueryList[ i ];
  313. // Skip global bounds object.
  314. if( object->isGlobalBounds() )
  315. continue;
  316. // Skip camera object as we're viewing the scene from it.
  317. if( object == cameraObject )
  318. continue;
  319. const Box3F& worldBox = object->getWorldBox();
  320. GFX->getDrawUtil()->drawObjectBox(
  321. desc,
  322. Point3F( worldBox.len_x(), worldBox.len_y(), worldBox.len_z() ),
  323. worldBox.getCenter(),
  324. MatrixF::Identity,
  325. ColorI::WHITE
  326. );
  327. }
  328. }
  329. }
  330. //-----------------------------------------------------------------------------
  331. struct ScopingInfo
  332. {
  333. Point3F scopePoint;
  334. F32 scopeDist;
  335. F32 scopeDistSquared;
  336. NetConnection* connection;
  337. };
  338. static void _scopeCallback( SceneObject* object, void* data )
  339. {
  340. if( !object->isScopeable() )
  341. return;
  342. ScopingInfo* info = reinterpret_cast< ScopingInfo* >( data );
  343. NetConnection* connection = info->connection;
  344. F32 difSq = ( object->getWorldSphere().center - info->scopePoint ).lenSquared();
  345. if( difSq < info->scopeDistSquared )
  346. {
  347. // Not even close, it's in...
  348. connection->objectInScope( object );
  349. }
  350. else
  351. {
  352. // Check a little more closely...
  353. F32 realDif = mSqrt( difSq );
  354. if( realDif - object->getWorldSphere().radius < info->scopeDist)
  355. connection->objectInScope( object );
  356. }
  357. }
  358. void SceneManager::scopeScene( CameraScopeQuery* query, NetConnection* netConnection )
  359. {
  360. PROFILE_SCOPE( SceneGraph_scopeScene );
  361. // Note that this method does not use the zoning information in the scene
  362. // to scope objects. The reason is that with the way that scoping is implemented
  363. // in the networking layer--i.e. by killing off ghosts of objects that are out
  364. // of scope--, it doesn't make sense to let, for example, all objects in the outdoor
  365. // zone go out of scope, just because there is no exterior portal that is visible from
  366. // the current camera viewpoint (in any direction).
  367. //
  368. // So, we perform a simple box query on the area covered by the camera query
  369. // and then scope in everything that is in range.
  370. // Set up scoping info.
  371. ScopingInfo info;
  372. info.scopePoint = query->pos;
  373. info.scopeDist = query->visibleDistance;
  374. info.scopeDistSquared = info.scopeDist * info.scopeDist;
  375. info.connection = netConnection;
  376. // Scope all objects in the query area.
  377. Box3F area( query->visibleDistance );
  378. area.setCenter( query->pos );
  379. getContainer()->findObjects( area, 0xFFFFFFFF, _scopeCallback, &info );
  380. }
  381. //-----------------------------------------------------------------------------
  382. bool SceneManager::addObjectToScene( SceneObject* object )
  383. {
  384. AssertFatal( !object->mSceneManager, "SceneManager::addObjectToScene - Object already part of a scene" );
  385. // Mark the object as belonging to us.
  386. object->mSceneManager = this;
  387. // Register with managers except its the root zone.
  388. if( !dynamic_cast< SceneRootZone* >( object ) )
  389. {
  390. // Add to container.
  391. getContainer()->addObject( object );
  392. // Register the object with the zone manager.
  393. if( getZoneManager() )
  394. getZoneManager()->registerObject( object );
  395. }
  396. // Notify the object.
  397. return object->onSceneAdd();
  398. }
  399. //-----------------------------------------------------------------------------
  400. void SceneManager::removeObjectFromScene( SceneObject* obj )
  401. {
  402. AssertFatal( obj->getSceneManager() == this, "SceneManager::removeObjectFromScene - Object not part of SceneManager" );
  403. // Notify the object.
  404. obj->onSceneRemove();
  405. // Remove the object from the container.
  406. getContainer()->removeObject( obj );
  407. // Remove the object from the zoning system.
  408. if( getZoneManager() )
  409. getZoneManager()->unregisterObject( obj );
  410. // Clear out the reference to us.
  411. obj->mSceneManager = NULL;
  412. }
  413. //-----------------------------------------------------------------------------
  414. void SceneManager::notifyObjectDirty( SceneObject* object )
  415. {
  416. // Update container state.
  417. if( object->mContainer )
  418. object->mContainer->checkBins( object );
  419. // Mark zoning state as dirty.
  420. if( getZoneManager() )
  421. getZoneManager()->notifyObjectChanged( object );
  422. }
  423. //-----------------------------------------------------------------------------
  424. void SceneManager::setDisplayTargetResolution( const Point2I &size )
  425. {
  426. mDisplayTargetResolution = size;
  427. }
  428. //-----------------------------------------------------------------------------
  429. const Point2I & SceneManager::getDisplayTargetResolution() const
  430. {
  431. return mDisplayTargetResolution;
  432. }
  433. //-----------------------------------------------------------------------------
  434. bool SceneManager::setLightManager( const char* lmName )
  435. {
  436. LightManager *lm = LightManager::findByName( lmName );
  437. if ( !lm )
  438. return false;
  439. return _setLightManager( lm );
  440. }
  441. //-----------------------------------------------------------------------------
  442. bool SceneManager::_setLightManager( LightManager* lm )
  443. {
  444. // Avoid unnecessary work reinitializing materials.
  445. if ( lm == mLightManager )
  446. return true;
  447. // Make sure its valid... else fail!
  448. if ( !lm->isCompatible() )
  449. return false;
  450. // We only deactivate it... all light managers are singletons
  451. // and will manager their own lifetime.
  452. if ( mLightManager )
  453. mLightManager->deactivate();
  454. mLightManager = lm;
  455. if ( mLightManager )
  456. mLightManager->activate( this );
  457. return true;
  458. }
  459. //-----------------------------------------------------------------------------
  460. RenderPassManager* SceneManager::getDefaultRenderPass() const
  461. {
  462. if( !mDefaultRenderPass )
  463. {
  464. Sim::findObject( "DiffuseRenderPassManager", mDefaultRenderPass );
  465. AssertISV( mDefaultRenderPass, "SceneManager::_setDefaultRenderPass - No DiffuseRenderPassManager defined! Must be set up in script!" );
  466. }
  467. return mDefaultRenderPass;
  468. }
  469. //=============================================================================
  470. // Console API.
  471. //=============================================================================
  472. // MARK: ---- Console API ----
  473. //-----------------------------------------------------------------------------
  474. DefineConsoleFunction( sceneDumpZoneStates, void, ( bool updateFirst ), ( true ),
  475. "Dump the current zoning states of all zone spaces in the scene to the console.\n\n"
  476. "@param updateFirst If true, zoning states are brought up to date first; if false, the zoning states "
  477. "are dumped as is.\n\n"
  478. "@note Only valid on the client.\n"
  479. "@ingroup Game" )
  480. {
  481. if( !gClientSceneGraph )
  482. {
  483. Con::errorf( "sceneDumpZoneStates - Only valid on client!" );
  484. return;
  485. }
  486. SceneZoneSpaceManager* manager = gClientSceneGraph->getZoneManager();
  487. if( !manager )
  488. {
  489. Con::errorf( "sceneDumpZoneStates - Scene is not using zones!" );
  490. return;
  491. }
  492. manager->dumpZoneStates( updateFirst );
  493. }
  494. //-----------------------------------------------------------------------------
  495. DefineConsoleFunction( sceneGetZoneOwner, SceneObject*, ( U32 zoneId ), ( true ),
  496. "Return the SceneObject that contains the given zone.\n\n"
  497. "@param zoneId ID of zone.\n"
  498. "@return A SceneObject or NULL if the given @a zoneId is invalid.\n\n"
  499. "@note Only valid on the client.\n"
  500. "@ingroup Game" )
  501. {
  502. if( !gClientSceneGraph )
  503. {
  504. Con::errorf( "sceneGetZoneOwner - Only valid on client!" );
  505. return NULL;
  506. }
  507. SceneZoneSpaceManager* manager = gClientSceneGraph->getZoneManager();
  508. if( !manager )
  509. {
  510. Con::errorf( "sceneGetZoneOwner - Scene is not using zones!" );
  511. return NULL;
  512. }
  513. if( !manager->isValidZoneId( zoneId ) )
  514. {
  515. Con::errorf( "sceneGetZoneOwner - Invalid zone ID: %i", zoneId );
  516. return NULL;
  517. }
  518. return manager->getZoneOwner( zoneId );
  519. }