X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fscene%2Fmodel%2Fmodel.cxx;h=3d7cf5f3f8493ee3244905fde46a991cc959a19f;hb=bda112297f2d81bd752b758bbb42485ccbf6a89e;hp=b3678efb25571752e0987bb85e3066371b857c2b;hpb=16dd841ce5cbdcd7b7a8bd1cfa4f99ab7d17c44e;p=simgear.git diff --git a/simgear/scene/model/model.cxx b/simgear/scene/model/model.cxx index b3678efb..3d7cf5f3 100644 --- a/simgear/scene/model/model.cxx +++ b/simgear/scene/model/model.cxx @@ -3,6 +3,10 @@ // // This file is in the Public Domain, and comes with no warranty. +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include // for strcmp() @@ -13,30 +17,52 @@ #include #include -#include +#include #include #include #include -#include +#include "animation.hxx" #include "model.hxx" SG_USING_STD(vector); + +//////////////////////////////////////////////////////////////////////// +// Global state +//////////////////////////////////////////////////////////////////////// +static bool +model_filter = true; + //////////////////////////////////////////////////////////////////////// // 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) { - ((Animation *)entity->getUserData())->update(); - return true; + 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; } @@ -79,7 +105,7 @@ splice_branch (ssgBranch * branch, ssgEntity * child) * Make an offset matrix from rotations and position offset. */ void -fgMakeOffsetsMatrix( sgMat4 * result, double h_rot, double p_rot, double r_rot, +sgMakeOffsetsMatrix( sgMat4 * result, double h_rot, double p_rot, double r_rot, double x_off, double y_off, double z_off ) { sgMat4 rot_matrix; @@ -91,33 +117,49 @@ fgMakeOffsetsMatrix( sgMat4 * result, double h_rot, double p_rot, double r_rot, void -fgMakeAnimation( ssgBranch * model, +sgMakeAnimation( ssgBranch * model, const char * name, vector &name_nodes, SGPropertyNode *prop_root, SGPropertyNode_ptr node, double sim_time_sec ) { - Animation * animation = 0; + SGAnimation * animation = 0; const char * type = node->getStringValue("type", "none"); if (!strcmp("none", type)) { - animation = new NullAnimation(node); + animation = new SGNullAnimation(node); } else if (!strcmp("range", type)) { - animation = new RangeAnimation(node); + animation = new SGRangeAnimation(prop_root, node); } else if (!strcmp("billboard", type)) { - animation = new BillboardAnimation(node); + animation = new SGBillboardAnimation(node); } else if (!strcmp("select", type)) { - animation = new SelectAnimation(prop_root, node); + animation = new SGSelectAnimation(prop_root, node); } else if (!strcmp("spin", type)) { - animation = new SpinAnimation(prop_root, node, sim_time_sec ); + animation = new SGSpinAnimation(prop_root, node, sim_time_sec ); } else if (!strcmp("timed", type)) { - animation = new TimedAnimation(node); + animation = new SGTimedAnimation(node); } else if (!strcmp("rotate", type)) { - animation = new RotateAnimation(prop_root, node); + animation = new SGRotateAnimation(prop_root, node); } else if (!strcmp("translate", type)) { - animation = new TranslateAnimation(prop_root, node); + 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 NullAnimation(node); + animation = new SGNullAnimation(node); SG_LOG(SG_INPUT, SG_WARN, "Unknown animation type " << type); } @@ -136,6 +178,9 @@ fgMakeAnimation( ssgBranch * model, } else { object = model; } + + if ( animation == 0 ) + return; ssgBranch * branch = animation->getBranch(); splice_branch(branch, object); @@ -156,6 +201,7 @@ fgMakeAnimation( ssgBranch * model, animation->init(); branch->setUserData(animation); branch->setTravCallback(SSG_CALLBACK_PRETRAV, animation_callback); + branch->setTravCallback(SSG_CALLBACK_POSTTRAV, restore_callback); } @@ -166,27 +212,24 @@ fgMakeAnimation( ssgBranch * model, //////////////////////////////////////////////////////////////////////// ssgBranch * -fgLoad3DModel( const string &fg_root, const string &path, +sgLoad3DModel( const string &fg_root, const string &path, SGPropertyNode *prop_root, - double sim_time_sec ) + double sim_time_sec, ssgEntity *(*load_panel)(SGPropertyNode *) ) { ssgBranch * model = 0; SGPropertyNode props; // Load the 3D aircraft object itself - SGPath xmlpath; SGPath modelpath = path; - if ( ulIsAbsolutePathName( path.c_str() ) ) { - xmlpath = modelpath; - } - else { - xmlpath = fg_root; - xmlpath.append(modelpath.str()); + if ( !ulIsAbsolutePathName( path.c_str() ) ) { + SGPath tmp = fg_root; + tmp.append(modelpath.str()); + modelpath = tmp; } // Check for an XML wrapper - if (xmlpath.str().substr(xmlpath.str().size() - 4, 4) == ".xml") { - readProperties(xmlpath.str(), &props); + if (modelpath.str().substr(modelpath.str().size() - 4, 4) == ".xml") { + readProperties(modelpath.str(), &props); if (props.hasValue("/path")) { modelpath = modelpath.dir(); modelpath.append(props.getStringValue("/path")); @@ -199,7 +242,7 @@ fgLoad3DModel( const string &fg_root, const string &path, // Assume that textures are in // the same location as the XML file. if (model == 0) { - ssgTexturePath((char *)xmlpath.dir().c_str()); + ssgTexturePath((char *)modelpath.dir().c_str()); model = (ssgBranch *)ssgLoad((char *)modelpath.c_str()); if (model == 0) throw sg_exception("Failed to load 3D model"); @@ -207,9 +250,11 @@ fgLoad3DModel( const string &fg_root, const string &path, // Set up the alignment node ssgTransform * alignmainmodel = new ssgTransform; + if ( load_panel == 0 ) + alignmainmodel->setTravCallback( SSG_CALLBACK_PRETRAV, model_filter_callback ); alignmainmodel->addKid(model); sgMat4 res_matrix; - fgMakeOffsetsMatrix(&res_matrix, + sgMakeOffsetsMatrix(&res_matrix, props.getFloatValue("/offsets/heading-deg", 0.0), props.getFloatValue("/offsets/roll-deg", 0.0), props.getFloatValue("/offsets/pitch-deg", 0.0), @@ -220,14 +265,16 @@ fgLoad3DModel( const string &fg_root, const string &path, unsigned int i; - // Load animations - vector animation_nodes = props.getChildren("animation"); - for (i = 0; i < animation_nodes.size(); i++) { - const char * name = animation_nodes[i]->getStringValue("name", 0); - vector name_nodes = - animation_nodes[i]->getChildren("object-name"); - fgMakeAnimation( model, name, name_nodes, prop_root, animation_nodes[i], - sim_time_sec); + if ( load_panel ) { + // Load panels + vector panel_nodes = props.getChildren("panel"); + for (i = 0; i < panel_nodes.size(); i++) { + SG_LOG(SG_INPUT, SG_DEBUG, "Loading a panel"); + ssgEntity * panel = load_panel(panel_nodes[i]); + if (panel_nodes[i]->hasValue("name")) + panel->setName((char *)panel_nodes[i]->getStringValue("name")); + model->addKid(panel); + } } // Load sub-models @@ -236,7 +283,7 @@ fgLoad3DModel( const string &fg_root, const string &path, SGPropertyNode_ptr node = model_nodes[i]; ssgTransform * align = new ssgTransform; sgMat4 res_matrix; - fgMakeOffsetsMatrix(&res_matrix, + sgMakeOffsetsMatrix(&res_matrix, node->getFloatValue("offsets/heading-deg", 0.0), node->getFloatValue("offsets/roll-deg", 0.0), node->getFloatValue("offsets/pitch-deg", 0.0), @@ -245,14 +292,33 @@ fgLoad3DModel( const string &fg_root, const string &path, node->getFloatValue("offsets/z-m", 0.0)); align->setTransform(res_matrix); - ssgBranch * kid = fgLoad3DModel( fg_root, node->getStringValue("path"), - prop_root, sim_time_sec ); + ssgBranch * kid = sgLoad3DModel( fg_root, node->getStringValue("path"), + prop_root, sim_time_sec, load_panel ); align->addKid(kid); + align->setName(node->getStringValue("name", "")); model->addKid(align); } + // Load animations + vector animation_nodes = props.getChildren("animation"); + for (i = 0; i < animation_nodes.size(); i++) { + const char * name = animation_nodes[i]->getStringValue("name", 0); + vector name_nodes = + animation_nodes[i]->getChildren("object-name"); + sgMakeAnimation( model, name, name_nodes, prop_root, animation_nodes[i], + sim_time_sec); + } + return alignmainmodel; } +bool +sgSetModelFilter( bool filter ) +{ + bool old = model_filter; + model_filter = filter; + return old; +} + // end of model.cxx