From 351a4d5c090ecf7f5a2038c0d4b6611e39e5d5fb Mon Sep 17 00:00:00 2001 From: david Date: Sun, 3 Nov 2002 15:42:11 +0000 Subject: [PATCH] Streamline to create fewer branch nodes. This involves moving some objects around when an animation specifies more than one object. --- src/Model/model.cxx | 42 +++++++++++++++++++++++++++--------------- src/Model/model.hxx | 9 +++++---- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/Model/model.cxx b/src/Model/model.cxx index a71d6886d..88490eec3 100644 --- a/src/Model/model.cxx +++ b/src/Model/model.cxx @@ -156,9 +156,9 @@ make_offsets_matrix (sgMat4 * result, double h_rot, double p_rot, double r_rot, * Read an interpolation table from properties. */ static SGInterpTable * -read_interpolation_table (const SGPropertyNode * props) +read_interpolation_table (SGPropertyNode_ptr props) { - const SGPropertyNode * table_node = props->getNode("interpolation"); + SGPropertyNode_ptr table_node = props->getNode("interpolation"); if (table_node != 0) { SGInterpTable * table = new SGInterpTable(); vector entries = table_node->getChildren("entry"); @@ -174,8 +174,8 @@ read_interpolation_table (const SGPropertyNode * props) static void make_animation (ssgBranch * model, - const char * object_name, - SGPropertyNode * node) + vector &name_nodes, + SGPropertyNode_ptr node) { Animation * animation = 0; const char * type = node->getStringValue("type"); @@ -199,10 +199,11 @@ make_animation (ssgBranch * model, } ssgEntity * object; - if (object_name != 0) { - object = find_named_node(model, object_name); + if (name_nodes.size() > 0) { + object = find_named_node(model, name_nodes[0]->getStringValue()); if (object == 0) { - SG_LOG(SG_INPUT, SG_WARN, "Object " << object_name << " not found"); + SG_LOG(SG_INPUT, SG_WARN, "Object " << name_nodes[0]->getStringValue() + << " not found"); delete animation; animation = 0; } @@ -212,6 +213,23 @@ make_animation (ssgBranch * model, ssgBranch * branch = animation->getBranch(); splice_branch(branch, object); + + for (int i = 1; i < name_nodes.size(); i++) { + const char * name = name_nodes[i]->getStringValue(); + object = find_named_node(model, name); + if (object == 0) { + SG_LOG(SG_INPUT, SG_WARN, "Object " << name << " not found"); + delete animation; + animation = 0; + } + ssgBranch * oldParent = object->getParent(0); + std::cerr << "Moving " << name << " to new parent\n"; + branch->addKid(object); + oldParent->removeKid(object); + std::cerr << " leaf has " << object->getNumParents() << " parents\n"; + std::cerr << " branch has " << branch->getNumKids() << " kids\n"; + } + branch->setUserData(animation); branch->setTravCallback(SSG_CALLBACK_PRETRAV, animation_callback); } @@ -279,13 +297,7 @@ fgLoad3DModel (const string &path) for (i = 0; i < animation_nodes.size(); i++) { vector name_nodes = animation_nodes[i]->getChildren("object-name"); - if (name_nodes.size() < 1) { - make_animation(model, 0, animation_nodes[i]); - } else { - for (unsigned int j = 0; j < name_nodes.size(); j++) { - make_animation(model, name_nodes[j]->getStringValue(), animation_nodes[i]); - } - } + make_animation(model, name_nodes, animation_nodes[i]); } // Load panels @@ -409,7 +421,7 @@ SelectAnimation::SelectAnimation (SGPropertyNode_ptr props) : Animation(props, new ssgSelector), _condition(0) { - SGPropertyNode * node = props->getChild("condition"); + SGPropertyNode_ptr node = props->getChild("condition"); if (node != 0) _condition = fgReadCondition(node); } diff --git a/src/Model/model.hxx b/src/Model/model.hxx index edfbfdae0..18e320e1e 100644 --- a/src/Model/model.hxx +++ b/src/Model/model.hxx @@ -17,6 +17,8 @@ SG_USING_STD(vector); #include #include +#include + // Don't pull in the headers, since we don't need them here. class ssgBranch; @@ -26,7 +28,6 @@ class ssgRangeSelector; class ssgSelector; class ssgTransform; -class SGPropertyNode; class SGInterpTable; class FGCondition; class FGLocation; @@ -148,7 +149,7 @@ public: virtual ~SpinAnimation (); virtual void update (); private: - SGPropertyNode * _prop; + SGPropertyNode_ptr _prop; double _factor; double _position_deg; double _last_time_sec; @@ -170,7 +171,7 @@ public: virtual ~RotateAnimation (); virtual void update (); private: - SGPropertyNode * _prop; + SGPropertyNode_ptr _prop; double _offset_deg; double _factor; SGInterpTable * _table; @@ -195,7 +196,7 @@ public: virtual ~TranslateAnimation (); virtual void update (); private: - SGPropertyNode * _prop; + SGPropertyNode_ptr _prop; double _offset_m; double _factor; SGInterpTable * _table; -- 2.39.5