mirror of
				https://github.com/TES3MP/openmw-tes3mp.git
				synced 2025-10-31 20:26:48 +00:00 
			
		
		
		
	create static functions to set/get hidden node mask; compromise on magic numbers to make things easier to understand
This commit is contained in:
		
							parent
							
								
									e1a5435531
								
							
						
					
					
						commit
						68549828b4
					
				
					 7 changed files with 30 additions and 15 deletions
				
			
		|  | @ -10,9 +10,6 @@ namespace CSVRender | |||
|     /// @copydoc MWRender::VisMask
 | ||||
|     enum Mask | ||||
|     { | ||||
|         // internal use within NifLoader, do not change
 | ||||
|         Mask_UpdateVisitor = 0x1, | ||||
| 
 | ||||
|         // elements that are part of the actual scene
 | ||||
|         Mask_Reference = 0x2, | ||||
|         Mask_Pathgrid = 0x4, | ||||
|  |  | |||
|  | @ -88,8 +88,6 @@ RenderWidget::RenderWidget(QWidget *parent, Qt::WindowFlags f) | |||
|     // Add ability to signal osg to show its statistics for debugging purposes
 | ||||
|     mView->addEventHandler(new osgViewer::StatsHandler); | ||||
| 
 | ||||
|     mView->getCamera()->setCullMask(~(Mask_UpdateVisitor)); | ||||
| 
 | ||||
|     viewer.addView(mView); | ||||
|     viewer.setDone(false); | ||||
|     viewer.realize(); | ||||
|  |  | |||
|  | @ -20,6 +20,8 @@ | |||
| 
 | ||||
| #include <osgViewer/Viewer> | ||||
| 
 | ||||
| #include <components/nifosg/nifloader.cpp> | ||||
| 
 | ||||
| #include <components/debug/debuglog.hpp> | ||||
| 
 | ||||
| #include <components/misc/stringops.hpp> | ||||
|  | @ -373,6 +375,7 @@ namespace MWRender | |||
|         mViewer->getCamera()->setCullingMode(cullingMode); | ||||
| 
 | ||||
|         mViewer->getCamera()->setCullMask(~(Mask_UpdateVisitor|Mask_SimpleWater)); | ||||
|         NifOsg::Loader::setHiddenNodeMask(Mask_UpdateVisitor); | ||||
| 
 | ||||
|         mNearClip = Settings::Manager::getFloat("near clip", "Camera"); | ||||
|         mViewDistance = Settings::Manager::getFloat("viewing distance", "Camera"); | ||||
|  |  | |||
|  | @ -269,12 +269,14 @@ void UVController::apply(osg::StateSet* stateset, osg::NodeVisitor* nv) | |||
|     } | ||||
| } | ||||
| 
 | ||||
| VisController::VisController(const Nif::NiVisData *data) | ||||
| VisController::VisController(const Nif::NiVisData *data, unsigned int mask) | ||||
|     : mData(data->mVis) | ||||
|     , mMask(mask) | ||||
| { | ||||
| } | ||||
| 
 | ||||
| VisController::VisController() | ||||
|     : mMask(0) | ||||
| { | ||||
| } | ||||
| 
 | ||||
|  | @ -282,6 +284,7 @@ VisController::VisController(const VisController ©, const osg::CopyOp ©o | |||
|     : osg::NodeCallback(copy, copyop) | ||||
|     , Controller(copy) | ||||
|     , mData(copy.mData) | ||||
|     , mMask(copy.mMask) | ||||
| { | ||||
| } | ||||
| 
 | ||||
|  | @ -303,8 +306,7 @@ void VisController::operator() (osg::Node* node, osg::NodeVisitor* nv) | |||
|     if (hasInput()) | ||||
|     { | ||||
|         bool vis = calculate(getInputValue(nv)); | ||||
|         // Leave 0x1 enabled for UpdateVisitor, so we can make ourselves visible again in the future from this update callback
 | ||||
|         node->setNodeMask(vis ? ~0 : 0x1); | ||||
|         node->setNodeMask(vis ? ~0 : mMask); | ||||
|     } | ||||
|     traverse(node, nv); | ||||
| } | ||||
|  |  | |||
|  | @ -234,11 +234,12 @@ namespace NifOsg | |||
|     { | ||||
|     private: | ||||
|         std::vector<Nif::NiVisData::VisData> mData; | ||||
|         unsigned int mMask; | ||||
| 
 | ||||
|         bool calculate(float time) const; | ||||
| 
 | ||||
|     public: | ||||
|         VisController(const Nif::NiVisData *data); | ||||
|         VisController(const Nif::NiVisData *data, unsigned int mask); | ||||
|         VisController(); | ||||
|         VisController(const VisController& copy, const osg::CopyOp& copyop); | ||||
| 
 | ||||
|  |  | |||
|  | @ -193,6 +193,17 @@ namespace NifOsg | |||
|         return sShowMarkers; | ||||
|     } | ||||
| 
 | ||||
|     unsigned int Loader::sHiddenNodeMask = 0; | ||||
| 
 | ||||
|     void Loader::setHiddenNodeMask(unsigned int mask) | ||||
|     { | ||||
|         sHiddenNodeMask = mask; | ||||
|     } | ||||
|     unsigned int Loader::getHiddenNodeMask() | ||||
|     { | ||||
|         return sHiddenNodeMask; | ||||
|     } | ||||
| 
 | ||||
|     class LoaderImpl | ||||
|     { | ||||
|     public: | ||||
|  | @ -571,8 +582,7 @@ namespace NifOsg | |||
|             if (nifNode->recType == Nif::RC_RootCollisionNode) | ||||
|             { | ||||
|                 skipMeshes = true; | ||||
|                 // Leave mask for UpdateVisitor enabled
 | ||||
|                 node->setNodeMask(0x1); | ||||
|                 node->setNodeMask(Loader::getHiddenNodeMask()); | ||||
|             } | ||||
| 
 | ||||
|             // We can skip creating meshes for hidden nodes if they don't have a VisController that
 | ||||
|  | @ -586,8 +596,7 @@ namespace NifOsg | |||
|                 if (!hasVisController) | ||||
|                     skipMeshes = true; // skip child meshes, but still create the child node hierarchy for animating collision shapes
 | ||||
| 
 | ||||
|                 // now hide this node, but leave the mask for UpdateVisitor enabled so that KeyframeController works
 | ||||
|                 node->setNodeMask(0x1); | ||||
|                 node->setNodeMask(Loader::getHiddenNodeMask()); | ||||
|             } | ||||
| 
 | ||||
|             if ((skipMeshes || hasMarkers) && isAnimated) // make sure the empty node is not optimized away so the physicssystem can find it.
 | ||||
|  | @ -753,7 +762,7 @@ namespace NifOsg | |||
|         { | ||||
|             if (visctrl->data.empty()) | ||||
|                 return; | ||||
|             osg::ref_ptr<VisController> callback(new VisController(visctrl->data.getPtr())); | ||||
|             osg::ref_ptr<VisController> callback(new VisController(visctrl->data.getPtr(), Loader::getHiddenNodeMask())); | ||||
|             setupController(visctrl, callback, animflags); | ||||
|             node->addUpdateCallback(callback); | ||||
|         } | ||||
|  |  | |||
|  | @ -74,8 +74,13 @@ namespace NifOsg | |||
| 
 | ||||
|         static bool getShowMarkers(); | ||||
| 
 | ||||
|     private: | ||||
|         /// Set the mask to use for hidden nodes. The default is 0, i.e. updates to those nodes can no longer happen.
 | ||||
|         /// If you need to run animations or physics for hidden nodes, you may want to set this to a non-zero mask and remove exactly that mask from the camera's cull mask.
 | ||||
|         static void setHiddenNodeMask(unsigned int mask); | ||||
|         static unsigned int getHiddenNodeMask(); | ||||
| 
 | ||||
|     private: | ||||
|         static unsigned int sHiddenNodeMask; | ||||
|         static bool sShowMarkers; | ||||
|     }; | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue