From 42e76477cfa6b5c5bca8df8da8f24497dc723dea Mon Sep 17 00:00:00 2001 From: frohlich Date: Fri, 13 Mar 2009 05:45:11 +0000 Subject: [PATCH] Make sure each carrier gets its own valocity. Modified Files: simgear/scene/model/ModelRegistry.cxx --- simgear/scene/model/ModelRegistry.cxx | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/simgear/scene/model/ModelRegistry.cxx b/simgear/scene/model/ModelRegistry.cxx index 1d587c2b..55af268c 100644 --- a/simgear/scene/model/ModelRegistry.cxx +++ b/simgear/scene/model/ModelRegistry.cxx @@ -226,6 +226,28 @@ private: FilePathList _pathList; }; +// Create new userdata structs in a copied model. +// The BVH trees are shared with the original model, but the velocity fields +// should usually be distinct fields for distinct models. +class UserDataCopyVisitor : public osg::NodeVisitor { +public: + UserDataCopyVisitor() : + osg::NodeVisitor(osg::NodeVisitor::NODE_VISITOR, + osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) + { + } + virtual void apply(osg::Node& node) + { + osg::ref_ptr userData; + userData = SGSceneUserData::getSceneUserData(&node); + if (userData.valid()) { + SGSceneUserData* newUserData = new SGSceneUserData(*userData); + newUserData->setVelocity(0); + node.setUserData(newUserData); + } + node.traverse(*this); + } +}; class SGTexCompressionVisitor : public SGTextureStateAttributeVisitor { public: @@ -427,6 +449,11 @@ osg::Node* DefaultCopyPolicy::copy(osg::Node* model, const string& fileName, TextureUpdateVisitor liveryUpdate(opt->getDatabasePathList()); res->accept(liveryUpdate); + // Copy the userdata fields, still sharing the boundingvolumes, + // but introducing new data for velocities. + UserDataCopyVisitor userDataCopyVisitor; + res->accept(userDataCopyVisitor); + return res; } -- 2.39.5