1
0
Fork 0

Streamline to create fewer branch nodes. This involves moving some

objects around when an animation specifies more than one object.
This commit is contained in:
david 2002-11-03 15:42:11 +00:00
parent 2bc7a538cf
commit 351a4d5c09
2 changed files with 32 additions and 19 deletions

View file

@ -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<SGPropertyNode_ptr> 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<SGPropertyNode_ptr> &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<SGPropertyNode_ptr> 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);
}

View file

@ -17,6 +17,8 @@ SG_USING_STD(vector);
#include <plib/sg.h>
#include <plib/ssg.h>
#include <simgear/misc/props.hxx>
// 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;