From 935df3a239bc39ca9ab2dfc80ad3737ad4be633c Mon Sep 17 00:00:00 2001 From: Cody Glassman Date: Fri, 7 Mar 2025 18:53:32 -0800 Subject: [PATCH] move rendering related code to mwrender --- apps/openmw/mwclass/tree4.cpp | 32 ------------------------------ apps/openmw/mwrender/animation.cpp | 31 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 32 deletions(-) diff --git a/apps/openmw/mwclass/tree4.cpp b/apps/openmw/mwclass/tree4.cpp index d38f570e0c..e4713b0385 100644 --- a/apps/openmw/mwclass/tree4.cpp +++ b/apps/openmw/mwclass/tree4.cpp @@ -8,34 +8,6 @@ #include "../mwrender/vismask.hpp" #include "../mwworld/ptr.hpp" -namespace -{ - class LeafParamsAssigner : public osg::NodeVisitor - { - public: - LeafParamsAssigner(const MWWorld::LiveCellRef* treeRef) - : osg::NodeVisitor(TRAVERSE_ALL_CHILDREN) - , mTreeRef(treeRef) - , mVertexAttrib(new osg::Vec3Array(1)) - , mTimeOffset(Misc::Rng::roll0to99()) - { - mVertexAttrib->at(0) = osg::Vec3f( - mTreeRef->mBase->mParams.mLeafAmplitude, mTreeRef->mBase->mParams.mLeafFrequency, mTimeOffset); - } - - void apply(osg::Geometry& geometry) override - { - geometry.setVertexAttribArray(7, mVertexAttrib, osg::Array::BIND_OVERALL); - - traverse(geometry); - } - - const MWWorld::LiveCellRef* mTreeRef = nullptr; - osg::ref_ptr mVertexAttrib = nullptr; - float mTimeOffset = 0.f; - }; -} - namespace MWClass { ESM4Tree::ESM4Tree() @@ -49,10 +21,6 @@ namespace MWClass if (!model.empty()) { renderingInterface.getObjects().insertModel(ptr, model); - - LeafParamsAssigner nv{ ptr.get() }; - ptr.getRefData().getBaseNode()->accept(nv); - ptr.getRefData().getBaseNode()->setNodeMask(MWRender::Mask_Static); } } diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 0a2ef7bef8..cc0c7c2cac 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -67,6 +68,31 @@ namespace { + class LeafParamsAssigner : public osg::NodeVisitor + { + public: + LeafParamsAssigner(const MWWorld::LiveCellRef* treeRef) + : osg::NodeVisitor(TRAVERSE_ALL_CHILDREN) + , mTreeRef(treeRef) + , mVertexAttrib(new osg::Vec3Array(1)) + , mTimeOffset(Misc::Rng::roll0to99()) + { + mVertexAttrib->at(0) = osg::Vec3f( + mTreeRef->mBase->mParams.mLeafAmplitude, mTreeRef->mBase->mParams.mLeafFrequency, mTimeOffset); + } + + void apply(osg::Geometry& geometry) override + { + geometry.setVertexAttribArray(7, mVertexAttrib, osg::Array::BIND_OVERALL); + + traverse(geometry); + } + + const MWWorld::LiveCellRef* mTreeRef = nullptr; + osg::ref_ptr mVertexAttrib = nullptr; + float mTimeOffset = 0.f; + }; + class MarkDrawablesVisitor : public osg::NodeVisitor { public: @@ -2079,6 +2105,11 @@ namespace MWRender addExtraLight(getOrCreateObjectRoot(), SceneUtil::LightCommon(*ptr.get()->mBase)); if (ptr.getType() == ESM4::Light::sRecordId && allowLight) addExtraLight(getOrCreateObjectRoot(), SceneUtil::LightCommon(*ptr.get()->mBase)); + if (ptr.getType() == ESM4::Tree::sRecordId) + { + LeafParamsAssigner nv{ ptr.get() }; + ptr.getRefData().getBaseNode()->accept(nv); + } if (!allowLight && mObjectRoot) {