-
-\f
-////////////////////////////////////////////////////////////////////////
-// Global state
-////////////////////////////////////////////////////////////////////////
-static bool
-model_filter = true;
-
-\f
-////////////////////////////////////////////////////////////////////////
-// Static utility functions.
-////////////////////////////////////////////////////////////////////////
-
-static int
-model_filter_callback (ssgEntity * entity, int mask)
-{
- return model_filter ? 1 : 0;
-}
-
-/**
- * Callback to update an animation.
- */
-static int
-animation_callback (ssgEntity * entity, int mask)
-{
- return ((SGAnimation *)entity->getUserData())->update();
-}
-
-/**
- * Callback to restore the state after an animation.
- */
-static int
-restore_callback (ssgEntity * entity, int mask)
-{
- ((SGAnimation *)entity->getUserData())->restore();
- return 1;
-}
-
-
-/**
- * Locate a named SSG node in a branch.
- */
-static ssgEntity *
-find_named_node (ssgEntity * node, const char * name)
-{
- char * node_name = node->getName();
- if (node_name != 0 && !strcmp(name, node_name))
- return node;
- else if (node->isAKindOf(ssgTypeBranch())) {
- int nKids = node->getNumKids();
- for (int i = 0; i < nKids; i++) {
- ssgEntity * result =
- find_named_node(((ssgBranch*)node)->getKid(i), name);
- if (result != 0)
- return result;
- }
- }
- return 0;
-}
-
-/**
- * Splice a branch in between all child nodes and their parents.
- */
-static void
-splice_branch (ssgBranch * branch, ssgEntity * child)
-{
- int nParents = child->getNumParents();
- branch->addKid(child);
- for (int i = 0; i < nParents; i++) {
- ssgBranch * parent = child->getParent(i);
- parent->replaceKid(child, branch);
- }
-}
-
-/**
- * Make an offset matrix from rotations and position offset.
- */
-void
-sgMakeOffsetsMatrix( sgMat4 * result, double h_rot, double p_rot, double r_rot,
- double x_off, double y_off, double z_off )
-{
- sgMat4 rot_matrix;
- sgMat4 pos_matrix;
- sgMakeRotMat4(rot_matrix, h_rot, p_rot, r_rot);
- sgMakeTransMat4(pos_matrix, x_off, y_off, z_off);
- sgMultMat4(*result, pos_matrix, rot_matrix);
-}
-
-
-void
-sgMakeAnimation( ssgBranch * model,
- const char * name,
- vector<SGPropertyNode_ptr> &name_nodes,
- SGPropertyNode *prop_root,
- SGPropertyNode_ptr node,
- double sim_time_sec )
-{
- SGAnimation * animation = 0;
- const char * type = node->getStringValue("type", "none");
- if (!strcmp("none", type)) {
- animation = new SGNullAnimation(node);
- } else if (!strcmp("range", type)) {
- animation = new SGRangeAnimation(prop_root, node);
- } else if (!strcmp("billboard", type)) {
- animation = new SGBillboardAnimation(node);
- } else if (!strcmp("select", type)) {
- animation = new SGSelectAnimation(prop_root, node);
- } else if (!strcmp("spin", type)) {
- animation = new SGSpinAnimation(prop_root, node, sim_time_sec );
- } else if (!strcmp("timed", type)) {
- animation = new SGTimedAnimation(node);
- } else if (!strcmp("rotate", type)) {
- animation = new SGRotateAnimation(prop_root, node);
- } else if (!strcmp("translate", type)) {
- animation = new SGTranslateAnimation(prop_root, node);
- } else if (!strcmp("scale", type)) {
- animation = new SGScaleAnimation(prop_root, node);
- } else if (!strcmp("texrotate", type)) {
- animation = new SGTexRotateAnimation(prop_root, node);
- } else if (!strcmp("textranslate", type)) {
- animation = new SGTexTranslateAnimation(prop_root, node);
- } else if (!strcmp("texmultiple", type)) {
- animation = new SGTexMultipleAnimation(prop_root, node);
- } else if (!strcmp("blend", type)) {
- animation = new SGBlendAnimation(prop_root, node);
- } else if (!strcmp("alpha-test", type)) {
- animation = new SGAlphaTestAnimation(node);
- } else if (!strcmp("flash", type)) {
- animation = new SGFlashAnimation(node);
- } else if (!strcmp("dist-scale", type)) {
- animation = new SGDistScaleAnimation(node);
- } else {
- animation = new SGNullAnimation(node);
- SG_LOG(SG_INPUT, SG_WARN, "Unknown animation type " << type);
- }
-
- if (name != 0)
- animation->setName((char *)name);
-
- ssgEntity * object;
- if (name_nodes.size() > 0) {
- object = find_named_node(model, name_nodes[0]->getStringValue());
- if (object == 0) {
- SG_LOG(SG_INPUT, SG_ALERT, "Object " << name_nodes[0]->getStringValue()
- << " not found");
- delete animation;
- animation = 0;
- }
- } else {
- object = model;
- }
-
- if ( animation == 0 )
- return;
-
- ssgBranch * branch = animation->getBranch();
- splice_branch(branch, object);
-
- for (unsigned 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_ALERT, "Object " << name << " not found");
- delete animation;
- animation = 0;
- } else {
- ssgBranch * oldParent = object->getParent(0);
- branch->addKid(object);
- oldParent->removeKid(object);
- }
- }
-
- if ( animation != 0 ) {
- animation->init();
- branch->setUserData(animation);
- branch->setTravCallback(SSG_CALLBACK_PRETRAV, animation_callback);
- branch->setTravCallback(SSG_CALLBACK_POSTTRAV, restore_callback);
- }
-}
-
-
-static void makeDList( ssgBranch *b )