sceneManager.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  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. if(GFX->getCurrentRenderStyle() == GFXDevice::RS_StereoSideBySide)
  182. {
  183. // Store previous values
  184. RectI originalVP = GFX->getViewport();
  185. MatrixF originalWorld = GFX->getWorldMatrix();
  186. Point2F projOffset = GFX->getCurrentProjectionOffset();
  187. Point3F eyeOffset = GFX->getStereoEyeOffset();
  188. // Render left half of display
  189. RectI leftVP = originalVP;
  190. leftVP.extent.x *= 0.5;
  191. GFX->setViewport(leftVP);
  192. MatrixF leftWorldTrans(true);
  193. leftWorldTrans.setPosition(Point3F(eyeOffset.x, eyeOffset.y, eyeOffset.z));
  194. MatrixF leftWorld(originalWorld);
  195. leftWorld.mulL(leftWorldTrans);
  196. GFX->setWorldMatrix(leftWorld);
  197. Frustum gfxFrustum = GFX->getFrustum();
  198. gfxFrustum.setProjectionOffset(Point2F(projOffset.x, projOffset.y));
  199. GFX->setFrustum(gfxFrustum);
  200. SceneCameraState cameraStateLeft = SceneCameraState::fromGFX();
  201. SceneRenderState renderStateLeft( this, renderState->getScenePassType(), cameraStateLeft );
  202. renderStateLeft.setSceneRenderStyle(SRS_SideBySide);
  203. renderStateLeft.setSceneRenderField(0);
  204. renderSceneNoLights( &renderStateLeft, objectMask, baseObject, baseZone );
  205. // Render right half of display
  206. RectI rightVP = originalVP;
  207. rightVP.extent.x *= 0.5;
  208. rightVP.point.x += rightVP.extent.x;
  209. GFX->setViewport(rightVP);
  210. MatrixF rightWorldTrans(true);
  211. rightWorldTrans.setPosition(Point3F(-eyeOffset.x, eyeOffset.y, eyeOffset.z));
  212. MatrixF rightWorld(originalWorld);
  213. rightWorld.mulL(rightWorldTrans);
  214. GFX->setWorldMatrix(rightWorld);
  215. gfxFrustum = GFX->getFrustum();
  216. gfxFrustum.setProjectionOffset(Point2F(-projOffset.x, projOffset.y));
  217. GFX->setFrustum(gfxFrustum);
  218. SceneCameraState cameraStateRight = SceneCameraState::fromGFX();
  219. SceneRenderState renderStateRight( this, renderState->getScenePassType(), cameraStateRight );
  220. renderStateRight.setSceneRenderStyle(SRS_SideBySide);
  221. renderStateRight.setSceneRenderField(1);
  222. renderSceneNoLights( &renderStateRight, objectMask, baseObject, baseZone );
  223. // Restore previous values
  224. GFX->setWorldMatrix(originalWorld);
  225. gfxFrustum.clearProjectionOffset();
  226. GFX->setFrustum(gfxFrustum);
  227. GFX->setViewport(originalVP);
  228. }
  229. else
  230. {
  231. renderSceneNoLights( renderState, objectMask, baseObject, baseZone );
  232. }
  233. // Trigger the post-render signal.
  234. PROFILE_START( SceneGraphRender_postRenderSignal );
  235. mCurrentRenderState = renderState;
  236. getPostRenderSignal().trigger( this, renderState );
  237. mCurrentRenderState = NULL;
  238. PROFILE_END();
  239. // Remove the previously registered lights.
  240. PROFILE_START( SceneGraph_unregisterLights);
  241. LIGHTMGR->unregisterAllLights();
  242. PROFILE_END();
  243. }
  244. //-----------------------------------------------------------------------------
  245. void SceneManager::renderSceneNoLights( SceneRenderState* renderState, U32 objectMask, SceneZoneSpace* baseObject, U32 baseZone )
  246. {
  247. // Set the current state.
  248. mCurrentRenderState = renderState;
  249. // Render.
  250. _renderScene( mCurrentRenderState, objectMask, baseObject, baseZone );
  251. #ifdef TORQUE_DEBUG
  252. // If frustum is locked and this is a diffuse pass, render the culling volumes of
  253. // zones that are selected (or the volumes of the outdoor zone if no zone is
  254. // selected).
  255. if( gEditingMission && renderState->isDiffusePass() && smLockDiffuseFrustum )
  256. renderState->getCullingState().debugRenderCullingVolumes();
  257. #endif
  258. mCurrentRenderState = NULL;
  259. }
  260. //-----------------------------------------------------------------------------
  261. void SceneManager::_renderScene( SceneRenderState* state, U32 objectMask, SceneZoneSpace* baseObject, U32 baseZone )
  262. {
  263. AssertFatal( this == gClientSceneGraph, "SceneManager::_buildSceneGraph - Only the client scenegraph can support this call!" );
  264. PROFILE_SCOPE( SceneGraph_batchRenderImages );
  265. // In the editor, override the type mask for diffuse passes.
  266. if( gEditingMission && state->isDiffusePass() )
  267. objectMask = EDITOR_RENDER_TYPEMASK;
  268. // Update the zoning state and traverse zones.
  269. if( getZoneManager() )
  270. {
  271. // Update.
  272. getZoneManager()->updateZoningState();
  273. // If zone culling isn't disabled, traverse the
  274. // zones now.
  275. if( !state->getCullingState().disableZoneCulling() )
  276. {
  277. // Find the start zone if we haven't already.
  278. if( !baseObject )
  279. {
  280. getZoneManager()->findZone( state->getCameraPosition(), baseObject, baseZone );
  281. AssertFatal( baseObject != NULL, "SceneManager::_renderScene - findZone() did not return an object" );
  282. }
  283. // Traverse zones starting in base object.
  284. SceneTraversalState traversalState( &state->getCullingState() );
  285. PROFILE_START( Scene_traverseZones );
  286. baseObject->traverseZones( &traversalState, baseZone );
  287. PROFILE_END();
  288. // Set the scene render box to the area we have traversed.
  289. state->setRenderArea( traversalState.getTraversedArea() );
  290. }
  291. }
  292. // Set the query box for the container query. Never
  293. // make it larger than the frustum's AABB. In the editor,
  294. // always query the full frustum as that gives objects
  295. // the opportunity to render editor visualizations even if
  296. // they are otherwise not in view.
  297. if( !state->getFrustum().getBounds().isOverlapped( state->getRenderArea() ) )
  298. {
  299. // This handles fringe cases like flying backwards into a zone where you
  300. // end up pretty much standing on a zone border and looking directly into
  301. // its "walls". In that case the traversal area will be behind the frustum
  302. // (remember that the camera isn't where visibility starts, it's the near
  303. // distance).
  304. return;
  305. }
  306. Box3F queryBox = state->getFrustum().getBounds();
  307. if( !gEditingMission )
  308. {
  309. queryBox.minExtents.setMax( state->getRenderArea().minExtents );
  310. queryBox.maxExtents.setMin( state->getRenderArea().maxExtents );
  311. }
  312. PROFILE_START( Scene_cullObjects );
  313. //TODO: We should split the codepaths here based on whether the outdoor zone has visible space.
  314. // If it has, we should use the container query-based path.
  315. // If it hasn't, we should fill the object list directly from the zone lists which will usually
  316. // include way fewer objects.
  317. // Gather all objects that intersect the scene render box.
  318. mBatchQueryList.clear();
  319. getContainer()->findObjectList( queryBox, objectMask, &mBatchQueryList );
  320. // Cull the list.
  321. U32 numRenderObjects = state->getCullingState().cullObjects(
  322. mBatchQueryList.address(),
  323. mBatchQueryList.size(),
  324. !state->isDiffusePass() ? SceneCullingState::CullEditorOverrides : 0 // Keep forced editor stuff out of non-diffuse passes.
  325. );
  326. //HACK: If the control object is a Player and it is not in the render list, force
  327. // it into it. This really should be solved by collision bounds being separate from
  328. // object bounds; only because the Player class is using bounds not encompassing
  329. // the actual player object is it that we have this problem in the first place.
  330. // Note that we are forcing the player object into ALL passes here but such
  331. // is the power of proliferation of things done wrong.
  332. GameConnection* connection = GameConnection::getConnectionToServer();
  333. if( connection )
  334. {
  335. Player* player = dynamic_cast< Player* >( connection->getControlObject() );
  336. if( player )
  337. {
  338. mBatchQueryList.setSize( numRenderObjects );
  339. if( !mBatchQueryList.contains( player ) )
  340. {
  341. mBatchQueryList.push_back( player );
  342. numRenderObjects ++;
  343. }
  344. }
  345. }
  346. PROFILE_END();
  347. // Render the remaining objects.
  348. PROFILE_START( Scene_renderObjects );
  349. state->renderObjects( mBatchQueryList.address(), numRenderObjects );
  350. PROFILE_END();
  351. // Render bounding boxes, if enabled.
  352. if( smRenderBoundingBoxes && state->isDiffusePass() )
  353. {
  354. GFXDEBUGEVENT_SCOPE( Scene_renderBoundingBoxes, ColorI::WHITE );
  355. GameBase* cameraObject = 0;
  356. if( connection )
  357. cameraObject = connection->getCameraObject();
  358. GFXStateBlockDesc desc;
  359. desc.setFillModeWireframe();
  360. desc.setZReadWrite( true, false );
  361. for( U32 i = 0; i < numRenderObjects; ++ i )
  362. {
  363. SceneObject* object = mBatchQueryList[ i ];
  364. // Skip global bounds object.
  365. if( object->isGlobalBounds() )
  366. continue;
  367. // Skip camera object as we're viewing the scene from it.
  368. if( object == cameraObject )
  369. continue;
  370. const Box3F& worldBox = object->getWorldBox();
  371. GFX->getDrawUtil()->drawObjectBox(
  372. desc,
  373. Point3F( worldBox.len_x(), worldBox.len_y(), worldBox.len_z() ),
  374. worldBox.getCenter(),
  375. MatrixF::Identity,
  376. ColorI::WHITE
  377. );
  378. }
  379. }
  380. }
  381. //-----------------------------------------------------------------------------
  382. struct ScopingInfo
  383. {
  384. Point3F scopePoint;
  385. F32 scopeDist;
  386. F32 scopeDistSquared;
  387. NetConnection* connection;
  388. };
  389. static void _scopeCallback( SceneObject* object, void* data )
  390. {
  391. if( !object->isScopeable() )
  392. return;
  393. ScopingInfo* info = reinterpret_cast< ScopingInfo* >( data );
  394. NetConnection* connection = info->connection;
  395. F32 difSq = ( object->getWorldSphere().center - info->scopePoint ).lenSquared();
  396. if( difSq < info->scopeDistSquared )
  397. {
  398. // Not even close, it's in...
  399. connection->objectInScope( object );
  400. }
  401. else
  402. {
  403. // Check a little more closely...
  404. F32 realDif = mSqrt( difSq );
  405. if( realDif - object->getWorldSphere().radius < info->scopeDist)
  406. connection->objectInScope( object );
  407. }
  408. }
  409. void SceneManager::scopeScene( CameraScopeQuery* query, NetConnection* netConnection )
  410. {
  411. PROFILE_SCOPE( SceneGraph_scopeScene );
  412. // Note that this method does not use the zoning information in the scene
  413. // to scope objects. The reason is that with the way that scoping is implemented
  414. // in the networking layer--i.e. by killing off ghosts of objects that are out
  415. // of scope--, it doesn't make sense to let, for example, all objects in the outdoor
  416. // zone go out of scope, just because there is no exterior portal that is visible from
  417. // the current camera viewpoint (in any direction).
  418. //
  419. // So, we perform a simple box query on the area covered by the camera query
  420. // and then scope in everything that is in range.
  421. // Set up scoping info.
  422. ScopingInfo info;
  423. info.scopePoint = query->pos;
  424. info.scopeDist = query->visibleDistance;
  425. info.scopeDistSquared = info.scopeDist * info.scopeDist;
  426. info.connection = netConnection;
  427. // Scope all objects in the query area.
  428. Box3F area( query->visibleDistance );
  429. area.setCenter( query->pos );
  430. getContainer()->findObjects( area, 0xFFFFFFFF, _scopeCallback, &info );
  431. }
  432. //-----------------------------------------------------------------------------
  433. bool SceneManager::addObjectToScene( SceneObject* object )
  434. {
  435. AssertFatal( !object->mSceneManager, "SceneManager::addObjectToScene - Object already part of a scene" );
  436. // Mark the object as belonging to us.
  437. object->mSceneManager = this;
  438. // Register with managers except its the root zone.
  439. if( !dynamic_cast< SceneRootZone* >( object ) )
  440. {
  441. // Add to container.
  442. getContainer()->addObject( object );
  443. // Register the object with the zone manager.
  444. if( getZoneManager() )
  445. getZoneManager()->registerObject( object );
  446. }
  447. // Notify the object.
  448. return object->onSceneAdd();
  449. }
  450. //-----------------------------------------------------------------------------
  451. void SceneManager::removeObjectFromScene( SceneObject* obj )
  452. {
  453. AssertFatal( obj->getSceneManager() == this, "SceneManager::removeObjectFromScene - Object not part of SceneManager" );
  454. // Notify the object.
  455. obj->onSceneRemove();
  456. // Remove the object from the container.
  457. getContainer()->removeObject( obj );
  458. // Remove the object from the zoning system.
  459. if( getZoneManager() )
  460. getZoneManager()->unregisterObject( obj );
  461. // Clear out the reference to us.
  462. obj->mSceneManager = NULL;
  463. }
  464. //-----------------------------------------------------------------------------
  465. void SceneManager::notifyObjectDirty( SceneObject* object )
  466. {
  467. // Update container state.
  468. if( object->mContainer )
  469. object->mContainer->checkBins( object );
  470. // Mark zoning state as dirty.
  471. if( getZoneManager() )
  472. getZoneManager()->notifyObjectChanged( object );
  473. }
  474. //-----------------------------------------------------------------------------
  475. void SceneManager::setDisplayTargetResolution( const Point2I &size )
  476. {
  477. mDisplayTargetResolution = size;
  478. }
  479. //-----------------------------------------------------------------------------
  480. const Point2I & SceneManager::getDisplayTargetResolution() const
  481. {
  482. return mDisplayTargetResolution;
  483. }
  484. //-----------------------------------------------------------------------------
  485. bool SceneManager::setLightManager( const char* lmName )
  486. {
  487. LightManager *lm = LightManager::findByName( lmName );
  488. if ( !lm )
  489. return false;
  490. return _setLightManager( lm );
  491. }
  492. //-----------------------------------------------------------------------------
  493. bool SceneManager::_setLightManager( LightManager* lm )
  494. {
  495. // Avoid unnecessary work reinitializing materials.
  496. if ( lm == mLightManager )
  497. return true;
  498. // Make sure its valid... else fail!
  499. if ( !lm->isCompatible() )
  500. return false;
  501. // We only deactivate it... all light managers are singletons
  502. // and will manager their own lifetime.
  503. if ( mLightManager )
  504. mLightManager->deactivate();
  505. mLightManager = lm;
  506. if ( mLightManager )
  507. mLightManager->activate( this );
  508. return true;
  509. }
  510. //-----------------------------------------------------------------------------
  511. RenderPassManager* SceneManager::getDefaultRenderPass() const
  512. {
  513. if( !mDefaultRenderPass )
  514. {
  515. Sim::findObject( "DiffuseRenderPassManager", mDefaultRenderPass );
  516. AssertISV( mDefaultRenderPass, "SceneManager::_setDefaultRenderPass - No DiffuseRenderPassManager defined! Must be set up in script!" );
  517. }
  518. return mDefaultRenderPass;
  519. }
  520. //=============================================================================
  521. // Console API.
  522. //=============================================================================
  523. // MARK: ---- Console API ----
  524. //-----------------------------------------------------------------------------
  525. DefineConsoleFunction( sceneDumpZoneStates, void, ( bool updateFirst ), ( true ),
  526. "Dump the current zoning states of all zone spaces in the scene to the console.\n\n"
  527. "@param updateFirst If true, zoning states are brought up to date first; if false, the zoning states "
  528. "are dumped as is.\n\n"
  529. "@note Only valid on the client.\n"
  530. "@ingroup Game" )
  531. {
  532. if( !gClientSceneGraph )
  533. {
  534. Con::errorf( "sceneDumpZoneStates - Only valid on client!" );
  535. return;
  536. }
  537. SceneZoneSpaceManager* manager = gClientSceneGraph->getZoneManager();
  538. if( !manager )
  539. {
  540. Con::errorf( "sceneDumpZoneStates - Scene is not using zones!" );
  541. return;
  542. }
  543. manager->dumpZoneStates( updateFirst );
  544. }
  545. //-----------------------------------------------------------------------------
  546. DefineConsoleFunction( sceneGetZoneOwner, SceneObject*, ( U32 zoneId ), ( true ),
  547. "Return the SceneObject that contains the given zone.\n\n"
  548. "@param zoneId ID of zone.\n"
  549. "@return A SceneObject or NULL if the given @a zoneId is invalid.\n\n"
  550. "@note Only valid on the client.\n"
  551. "@ingroup Game" )
  552. {
  553. if( !gClientSceneGraph )
  554. {
  555. Con::errorf( "sceneGetZoneOwner - Only valid on client!" );
  556. return NULL;
  557. }
  558. SceneZoneSpaceManager* manager = gClientSceneGraph->getZoneManager();
  559. if( !manager )
  560. {
  561. Con::errorf( "sceneGetZoneOwner - Scene is not using zones!" );
  562. return NULL;
  563. }
  564. if( !manager->isValidZoneId( zoneId ) )
  565. {
  566. Con::errorf( "sceneGetZoneOwner - Invalid zone ID: %i", zoneId );
  567. return NULL;
  568. }
  569. return manager->getZoneOwner( zoneId );
  570. }