Make an animation with no object name apply to the model as a whole.
This replaces the old "range" subtree with something more general.
This commit is contained in:
parent
586d767ab6
commit
a8576b9e95
2 changed files with 34 additions and 43 deletions
|
@ -162,12 +162,9 @@ FG3DModel::~FG3DModel ()
|
||||||
// since the nodes are attached to the scene graph, they'll be
|
// since the nodes are attached to the scene graph, they'll be
|
||||||
// deleted automatically
|
// deleted automatically
|
||||||
|
|
||||||
for (int i = 0; i < _animations.size(); i++) {
|
int i;
|
||||||
Animation * tmp = _animations[i];
|
for (i = 0; i < _animations.size(); i++)
|
||||||
_animations[i] = 0;
|
delete _animations[i];
|
||||||
delete tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -194,39 +191,13 @@ FG3DModel::init (const string &path)
|
||||||
// Assume that textures are in
|
// Assume that textures are in
|
||||||
// the same location as the XML file.
|
// the same location as the XML file.
|
||||||
ssgTexturePath((char *)xmlpath.dir().c_str());
|
ssgTexturePath((char *)xmlpath.dir().c_str());
|
||||||
_model = ssgLoad((char *)modelpath.c_str());
|
_model = (ssgBranch *)ssgLoad((char *)modelpath.c_str());
|
||||||
if (_model == 0)
|
if (_model == 0)
|
||||||
throw sg_exception("Failed to load 3D model");
|
throw sg_exception("Failed to load 3D model");
|
||||||
|
|
||||||
// Load animations
|
|
||||||
vector<SGPropertyNode *> animation_nodes = props.getChildren("animation");
|
|
||||||
for (unsigned int i = 0; i < animation_nodes.size(); i++) {
|
|
||||||
vector<SGPropertyNode *> name_nodes =
|
|
||||||
animation_nodes[i]->getChildren("object-name");
|
|
||||||
if (name_nodes.size() < 1) {
|
|
||||||
SG_LOG(SG_INPUT, SG_ALERT, "No object-name given for transformation");
|
|
||||||
} else {
|
|
||||||
for (unsigned int j = 0; j < name_nodes.size(); j++) {
|
|
||||||
Animation * animation =
|
|
||||||
make_animation(name_nodes[j]->getStringValue(), animation_nodes[i]);
|
|
||||||
if (animation != 0)
|
|
||||||
_animations.push_back(animation);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set up the range selector node
|
|
||||||
float ranges[2];
|
|
||||||
ssgRangeSelector * lod = new ssgRangeSelector;
|
|
||||||
lod->addKid(_model);
|
|
||||||
ranges[0] = props.getFloatValue("range/min-m", 0);
|
|
||||||
ranges[1] = props.getFloatValue("range/max-m", 5000);
|
|
||||||
lod->setRanges(ranges, 2);
|
|
||||||
|
|
||||||
|
|
||||||
// Set up the alignment node
|
// Set up the alignment node
|
||||||
ssgTransform * align = new ssgTransform;
|
ssgTransform * align = new ssgTransform;
|
||||||
align->addKid(lod);
|
align->addKid(_model);
|
||||||
sgMat4 rot_matrix;
|
sgMat4 rot_matrix;
|
||||||
sgMat4 off_matrix;
|
sgMat4 off_matrix;
|
||||||
sgMat4 res_matrix;
|
sgMat4 res_matrix;
|
||||||
|
@ -251,6 +222,23 @@ FG3DModel::init (const string &path)
|
||||||
// Set up a location class
|
// Set up a location class
|
||||||
_location = (FGLocation *) new FGLocation;
|
_location = (FGLocation *) new FGLocation;
|
||||||
|
|
||||||
|
// Load animations
|
||||||
|
vector<SGPropertyNode *> animation_nodes = props.getChildren("animation");
|
||||||
|
unsigned int i;
|
||||||
|
for (i = 0; i < animation_nodes.size(); i++) {
|
||||||
|
vector<SGPropertyNode *> name_nodes =
|
||||||
|
animation_nodes[i]->getChildren("object-name");
|
||||||
|
if (name_nodes.size() < 1) {
|
||||||
|
Animation * animation = make_animation(0, animation_nodes[i]);
|
||||||
|
} else {
|
||||||
|
for (unsigned int j = 0; j < name_nodes.size(); j++) {
|
||||||
|
Animation * animation =
|
||||||
|
make_animation(name_nodes[j]->getStringValue(), animation_nodes[i]);
|
||||||
|
if (animation != 0)
|
||||||
|
_animations.push_back(animation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -367,15 +355,19 @@ FG3DModel::make_animation (const char * object_name,
|
||||||
SG_LOG(SG_INPUT, SG_WARN, "Unknown animation type " << type);
|
SG_LOG(SG_INPUT, SG_WARN, "Unknown animation type " << type);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssgEntity * object = find_named_node(_model, object_name);
|
ssgEntity * object;
|
||||||
if (object == 0) {
|
if (object_name != 0) {
|
||||||
SG_LOG(SG_INPUT, SG_WARN, "Object " << object_name << " not found");
|
object = find_named_node(_model, object_name);
|
||||||
delete animation;
|
if (object == 0) {
|
||||||
animation = 0;
|
SG_LOG(SG_INPUT, SG_WARN, "Object " << object_name << " not found");
|
||||||
|
delete animation;
|
||||||
|
animation = 0;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
animation->init(object, node);
|
object = _model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
animation->init(object, node);
|
||||||
return animation;
|
return animation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ SG_USING_STD(vector);
|
||||||
|
|
||||||
|
|
||||||
// Don't pull in the headers, since we don't need them here.
|
// Don't pull in the headers, since we don't need them here.
|
||||||
|
class ssgBranch;
|
||||||
class ssgEntity;
|
class ssgEntity;
|
||||||
class ssgRangeSelector;
|
class ssgRangeSelector;
|
||||||
class ssgSelector;
|
class ssgSelector;
|
||||||
|
@ -89,12 +90,10 @@ private:
|
||||||
double _heading_deg;
|
double _heading_deg;
|
||||||
|
|
||||||
// Animations
|
// Animations
|
||||||
|
|
||||||
vector <Animation *> _animations;
|
vector <Animation *> _animations;
|
||||||
|
|
||||||
|
|
||||||
// Scene graph
|
// Scene graph
|
||||||
ssgEntity * _model;
|
ssgBranch * _model;
|
||||||
ssgSelector * _selector;
|
ssgSelector * _selector;
|
||||||
ssgTransform * _position;
|
ssgTransform * _position;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue