#include <vector>
#include <set>
-SG_USING_STD(vector);
-SG_USING_STD(set);
-
-#include <plib/sg.h>
-#include <plib/ssg.h>
+#include <osg/Node>
+#include <osg/Texture2D>
+#include <osgDB/ReaderWriter>
#include <simgear/misc/sg_path.hxx>
#include <simgear/props/props.hxx>
-
-
-// Has anyone done anything *really* stupid, like making min and max macros?
-#ifdef min
-#undef min
-#endif
-#ifdef max
-#undef max
-#endif
-
-
-/**
- * Abstract class for adding data to the scene graph. modelLoaded() is
- * called by sgLoad3DModel() after the model was loaded, and the destructor
- * when the branch is removed from the graph.
- */
-class SGModelData : public ssgBase {
+#include <simgear/scene/util/NodeAndDrawableVisitor.hxx>
+
+namespace simgear
+{
+class SGReaderWriterXMLOptions;
+}
+
+osg::Texture2D*
+SGLoadTexture2D(bool staticTexture, const std::string& path,
+ const osgDB::ReaderWriter::Options* options = 0,
+ bool wrapu = true, bool wrapv = true, int mipmaplevels = -1);
+
+inline osg::Texture2D*
+SGLoadTexture2D(const std::string& path,
+ const osgDB::ReaderWriter::Options* options = 0,
+ bool wrapu = true, bool wrapv = true, int mipmaplevels = -1)
+{
+ return SGLoadTexture2D(true, path, options, wrapu, wrapv, mipmaplevels);
+}
+
+inline osg::Texture2D*
+SGLoadTexture2D(const SGPath& path,
+ const osgDB::ReaderWriter::Options* options = 0,
+ bool wrapu = true, bool wrapv = true,
+ int mipmaplevels = -1)
+{
+ return SGLoadTexture2D(true, path.str(), options, wrapu, wrapv,
+ mipmaplevels);
+}
+
+inline osg::Texture2D*
+SGLoadTexture2D(bool staticTexture, const SGPath& path,
+ const osgDB::ReaderWriter::Options* options = 0,
+ bool wrapu = true, bool wrapv = true,
+ int mipmaplevels = -1)
+{
+ return SGLoadTexture2D(staticTexture, path.str(), options, wrapu, wrapv,
+ mipmaplevels);
+}
+
+namespace simgear
+{
+osg::Node* copyModel(osg::Node* model);
+
+// Change the StateSets of a model to hold different textures based on
+// a livery path.
+
+class TextureUpdateVisitor : public NodeAndDrawableVisitor
+{
public:
- virtual ~SGModelData() {}
- virtual void modelLoaded( const string& path, SGPropertyNode *prop,
- ssgBranch *branch) {}
+ TextureUpdateVisitor(const osgDB::FilePathList& pathList);
+ virtual void apply(osg::Node& node);
+ virtual void apply(osg::Drawable& drawable);
+ // Copied from Mathias' earlier SGTextureUpdateVisitor
+protected:
+ osg::Texture2D* textureReplace(int unit, const osg::StateAttribute* attr);
+ osg::StateSet* cloneStateSet(const osg::StateSet* stateSet);
+private:
+ osgDB::FilePathList _pathList;
};
+// Create new userdata structs in a copied model.
+// The BVH trees are shared with the original model, but the velocity fields
+// should usually be distinct fields for distinct models.
+class UserDataCopyVisitor : public osg::NodeVisitor
+{
+public:
+ UserDataCopyVisitor();
+ virtual void apply(osg::Node& node);
+};
/**
- * Load a 3D model with or without XML wrapper. Note, this version
- * Does not know about or load the panel/cockpit information. Use the
- * "model_panel.hxx" version if you want to load an aircraft
- * (i.e. ownship) with a panel.
- *
- * If the path ends in ".xml", then it will be used as a property-
- * list wrapper to add animations to the model.
+ * Transform an OSG subgraph by substituting Effects and EffectGeodes
+ * for osg::Geodes with osg::StateSets. This is only guaranteed to
+ * work for models prouced by the .ac loader.
*
- * Subsystems should not normally invoke this function directly;
- * instead, they should use the FGModelLoader declared in loader.hxx.
- */
-ssgBranch *
-sgLoad3DModel( const string& fg_root, const string &path,
- SGPropertyNode *prop_root, double sim_time_sec,
- ssgEntity *(*load_panel)(SGPropertyNode *) = 0,
- SGModelData *data = 0 );
-
-
-/**
- * Make an offset matrix from rotations and position offset.
+ * returns a copy if any nodes are changed
*/
-void
-sgMakeOffsetsMatrix( sgMat4 * result, double h_rot, double p_rot, double r_rot,
- double x_off, double y_off, double z_off );
+osg::ref_ptr<osg::Node>
+instantiateEffects(osg::Node* model,
+ PropertyList& effectProps,
+ const SGReaderWriterXMLOptions* options);
/**
- * Make the animation
- */
-void
-sgMakeAnimation( ssgBranch * model,
- const char * name,
- vector<SGPropertyNode_ptr> &name_nodes,
- SGPropertyNode *prop_root,
- SGPropertyNode_ptr node,
- double sim_time_sec,
- SGPath &texture_path,
- set<ssgBranch *> &ignore_branches );
-
-/**
- * Set the filter state on models
- */
-bool
-sgSetModelFilter( bool filter );
-
-/**
- * Check if the ssg node contains an animation
- */
-bool
-sgCheckAnimationBranch (ssgEntity * entity);
-
-/**
- * Enable or disable Display list usage
+ * Transform an OSG subgraph by substituting the Effects and
+ * EffectGeodes for osg::Geodes with osg::StateSets, inheriting from
+ * the default model effect. This is only guaranteed to work for
+ * models prouced by the .ac loader.
+ *
+ * returns a copy if any nodes are changed
*/
-extern bool sgUseDisplayList;
+inline osg::ref_ptr<osg::Node>
+instantiateEffects(osg::Node* model,
+ const SGReaderWriterXMLOptions* options)
+{
+ PropertyList effectProps;
+ return instantiateEffects(model, effectProps, options);
+}
+}
#endif // __MODEL_HXX