From: frohlich <frohlich>
Date: Fri, 13 Mar 2009 05:45:11 +0000 (+0000)
Subject: Make sure each carrier gets its own valocity.
X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=42e76477cfa6b5c5bca8df8da8f24497dc723dea;p=simgear.git

Make sure each carrier gets its own valocity.

Modified Files:
	simgear/scene/model/ModelRegistry.cxx
---

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<SGSceneUserData> 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;
 }