![]() |
VR-Forces 4.0.4 Class Documentation
|
00001 /****************************************************************************** 00002 ** Copyright (c) 2007 MAK Technologies, Inc. 00003 ** All rights reserved. 00004 ******************************************************************************/ 00005 /****************************************************************************** 00006 ** $RCSfile: DtOsgModelInstance.h,v $ $Revision: 1.16 $ $State: Exp $ 00007 ******************************************************************************/ 00008 00012 00013 #pragma once 00014 00015 #include <vrvOsg/vrvOsg.h> 00016 #include <vrvCore/DtModelInstance.h> 00017 #include <vrvUtil/DtVirtualBaseClass.h> 00018 #include <vrvUtil/signalslib.h> 00019 00020 #include <osg/Node> 00021 #include <osg/Texture> 00022 #include <osg/ref_ptr> 00023 00024 namespace makVrv 00025 { 00026 class DtOsgSceneConnector; 00027 00030 class DT_DLL_VRVOSG DtCachedNodeHolder : public DtInstanceHolder<osg::ref_ptr<osg::Node> > 00031 { 00032 public: 00033 DtCachedNodeHolder(DtDe& de,osg::Node* node); 00034 00035 virtual ~DtCachedNodeHolder(); 00036 00037 protected: 00038 00039 void releaseGLObjects(); 00040 00041 DtDe& myDe; 00042 }; 00043 00046 class DT_DLL_VRVOSG DtCachedTextureHolder : public DtInstanceHolder<osg::ref_ptr<osg::Texture> > 00047 { 00048 public: 00049 DtCachedTextureHolder(DtDe&,osg::Texture* node); 00050 00051 virtual ~DtCachedTextureHolder(); 00052 00053 protected: 00054 00055 void releaseGLObjects(); 00056 00057 DtDe& myDe; 00058 }; 00059 00060 00061 00065 class DT_DLL_VRVOSG DtOsgModelInstance : public DtModelInstance 00066 { 00067 public: 00068 00070 virtual ~DtOsgModelInstance(); 00071 00073 virtual void addToConnector( DtOsgSceneConnector* connector ); 00074 00077 virtual bool removeFromConnector( DtOsgSceneConnector* connector ); 00078 00080 00081 virtual osg::Node* rootNode(); 00082 virtual const osg::Node* rootNode() const; 00084 00086 virtual bool saveModelToFile(const std::string& filename) const; 00087 00088 virtual void enableColorBlending( bool b ); 00089 00090 virtual void setBlendColor(float r, float g, float b, float a); 00091 00092 virtual void enableTexture( bool onOff ); 00093 00094 //Utility function for reading a Vec4 from a definition. 00095 static osg::Vec4 readVec4(const std::string& paramName, const DtModelDefinition& definition); 00096 00097 //Utility function for reading a Vec3 from a definition. 00098 static osg::Vec3 readVec3(const std::string& paramName, const DtModelDefinition& definition); 00099 00101 virtual void setVisibleViaSwitch(bool useSwitch); 00102 00103 protected: 00104 00107 virtual void updateColorBlending(); 00108 00109 virtual void updateColorBlending( osg::Node* node ); 00110 virtual void enableTexture( osg::Node* root, bool onOff ); 00111 00112 virtual void updateBoundingBoxViaContents(); 00113 00115 DtOsgModelInstance(DtDe& de); 00116 00118 virtual void setRootNode(osg::Node* node); 00119 00120 protected: 00121 00122 osg::ref_ptr<osg::Node> myModelRoot; 00123 osg::ref_ptr<osg::StateSet> myCachedState; 00124 }; 00125 00127 class DT_DLL_VRVOSG DtOsgModelInstanceSignaler : public DtVirtualBaseClass 00128 { 00129 public: 00131 static DtOsgModelInstanceSignaler& instance(DtDe&); 00132 00134 ~DtOsgModelInstanceSignaler(); 00135 00137 boost::signal<void (DtModelInstance&)> signal_modelCreated; 00138 00140 boost::signal<void (DtModelInstance&)> signal_modelChanged; 00141 00144 boost::signal<void (DtModelInstance&)> signal_modelToBeDestroyed; 00145 00146 protected: 00147 00149 DtOsgModelInstanceSignaler(); 00150 00151 private: 00152 DtOsgModelInstanceSignaler(const DtOsgModelInstanceSignaler&); 00153 DtOsgModelInstanceSignaler& operator=(const DtOsgModelInstanceSignaler&); 00154 }; 00155 } 00156 00157