From de479e35c8e39f6097148d17b5631630333cd1b4 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 30 Jul 2015 23:51:37 +0200 Subject: [PATCH] Fix AlphaController affecting all instances of the StateSet --- components/nifosg/controller.cpp | 7 +++++++ components/nifosg/controller.hpp | 2 ++ 2 files changed, 9 insertions(+) diff --git a/components/nifosg/controller.cpp b/components/nifosg/controller.cpp index 83ecc0fa9..e66713c17 100644 --- a/components/nifosg/controller.cpp +++ b/components/nifosg/controller.cpp @@ -353,6 +353,13 @@ AlphaController::AlphaController(const AlphaController ©, const osg::CopyOp { } +void AlphaController::setDefaults(osg::StateSet *stateset) +{ + // need to create a deep copy of StateAttributes we will modify + osg::Material* mat = static_cast(stateset->getAttribute(osg::StateAttribute::MATERIAL)); + stateset->setAttribute(osg::clone(mat, osg::CopyOp::DEEP_COPY_ALL), osg::StateAttribute::ON); +} + void AlphaController::apply(osg::StateSet *stateset, osg::NodeVisitor *nv) { if (hasInput()) diff --git a/components/nifosg/controller.hpp b/components/nifosg/controller.hpp index 4877c83db..500a5cc17 100644 --- a/components/nifosg/controller.hpp +++ b/components/nifosg/controller.hpp @@ -189,6 +189,8 @@ namespace NifOsg AlphaController(); AlphaController(const AlphaController& copy, const osg::CopyOp& copyop); + virtual void setDefaults(osg::StateSet* stateset); + virtual void apply(osg::StateSet* stateset, osg::NodeVisitor* nv); META_Object(NifOsg, AlphaController)