Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

NVSGSaver.h

Go to the documentation of this file.
00001 // Copyright NVIDIA Corporation 2002-2004
00002 // TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED
00003 // *AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS
00004 // OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
00005 // AND FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS
00006 // BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES
00007 // WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS,
00008 // BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS)
00009 // ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS
00010 // BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES 
00011 
00012 #pragma once
00013 
00014 #include  "nvsg/nvsgapi.h"
00015 #include  "nvtraverser/Traverser.h"
00016 #include  "nvsg/AnimatedQuads.h"
00017 #include  "nvsg/PlugInterface.h"
00018 #include  "nvsg/StateAttribute.h"
00019 #include  <set>
00020 
00021 
00022 //  Don't need to document the API specifier
00023 #if ! defined( DOXYGEN_IGNORE )
00024 #ifdef NVSGSAVER_EXPORTS
00025 #define NVSGSAVER_API __declspec(dllexport)
00026 #else
00027 #define NVSGSAVER_API __declspec(dllimport)
00028 #endif
00029 #endif  //  DOXYGEN_IGNORE
00030 
00032 
00037 NVSGSAVER_API bool getPlugInterface(const nvutil::UPIID& piid, nvutil::PlugIn *& pi);
00038 
00040 
00046 NVSGSAVER_API bool queryPlugInterfaceType(const nvutil::UPITID& pitid, std::vector<nvutil::UPIID>& piids);
00047 
00049 class NVSGSaveTraverser : public nvtraverser::Traverser
00050 {
00051   public:
00053     NVSGSaveTraverser();
00054 
00056     void  setFILE( 
00057       FILE *fh                       
00058     );
00059 
00060   protected:
00062 
00063     void doApply( 
00064       const nvsg::ViewState *pViewState     
00065     , const nvsg::Scene *pScene             
00066     );
00067 
00068     // overloads to process concrete types for saving
00069     // ...Cameras
00071     /** If the \c JitterCamera \a p is encountered on saving the first time, it's base camera is traversed with \a root
00072       * and it's name is registered.
00073       * \note The NVSG file format does not support a \c JitterCamera, so it isn't saved as such. */
00074     virtual void handleJitterCamera(const nvsg::JitterCamera *p, const nvsg::Node *root);
00075 
00077 
00079     virtual void handleParallelCamera(const nvsg::ParallelCamera *p, const nvsg::Node *root);
00080 
00082 
00084     virtual void handlePerspectiveCamera(const nvsg::PerspectiveCamera *p, const nvsg::Node *root);
00085 
00087 
00090     virtual void handleStereoCamera(const nvsg::StereoCamera *p, const nvsg::Node *root);
00091 
00092     // ...Nodes
00094     /** If the \c GeoNode \a p is encountered on saving the first time, it is traversed and then saved. */
00095     virtual void handleGeoNode(const nvsg::GeoNode *p);
00096 
00098 
00099     virtual void handleGroup( const nvsg::Group *p );
00100 
00102 
00103     virtual void handleTransform(const nvsg::Transform *p);
00104 
00106 
00108     virtual void handleAnimatedTransform(const nvsg::AnimatedTransform *p);
00109 
00111 
00113     virtual void handleLOD(const nvsg::LOD *p);
00114 
00116 
00118     virtual void handleSwitch(const nvsg::Switch *p);
00119 
00121 
00123     virtual void handleDirectedLight(const nvsg::DirectedLight *p);
00124 
00126 
00128     virtual void handlePointLight(const nvsg::PointLight *p);
00129 
00131 
00133     virtual void handleSpotLight(const nvsg::SpotLight *p);
00134 
00135     // ...StateSet
00137     /** If the \c StateSet \a p is encountered on saving, it is stored as the current one. Then, if it's the first time,
00138       * it is traversed and then saved. */
00139     virtual void handleStateSet(const nvsg::StateSet *p);
00140 
00141     // ...StateAttribs
00143     /** If the \c CgFx \a p is encountered on saving the first time, it is saved. */
00144     virtual void handleCgFx(const nvsg::CgFx *p);
00145 
00147 
00148     virtual void handleFaceAttribute(const nvsg::FaceAttribute *p);
00149 
00151 
00152     virtual void handleMaterial(const nvsg::Material *p);
00153 
00155 
00156     virtual void handleTextureAttribute(const nvsg::TextureAttribute *p);
00157 
00159 
00160     virtual void handleTextureAttributeItem(const nvsg::TextureAttributeItem * p, size_t tu);
00161 
00162     // ...GeoSets
00164     /** If the \c Triangles \a p is encountered on saving the first time, it is saved. */
00165     virtual void handleTriangles(const nvsg::Triangles *p);
00166 
00168 
00170     virtual void handleAnimatedTriangles(const nvsg::AnimatedTriangles *p);
00171 
00173 
00175     virtual void handleSkinnedTriangles(const nvsg::SkinnedTriangles *p);
00176 
00178 
00179     virtual void handleTriStrips(const nvsg::TriStrips *p);
00180 
00182 
00183     virtual void handleQuads(const nvsg::Quads *p);
00184 
00186 
00188     virtual void handleAnimatedQuads(const nvsg::AnimatedQuads *p);
00189 
00191 
00192     virtual void handleQuadStrips(const nvsg::QuadStrips *p);
00193 
00194     // ... Animations 
00196     /** If the \c FramedTrafoAnimation \a p is encountered on saving the first time, it is saved. */
00197     virtual void handleFramedTrafoAnimation(const nvsg::FramedAnimation<nvmath::Trafo> *p);
00198 
00200 
00201     virtual void handleFramedVNVectorAnimation(const nvsg::FramedAnimation<nvsg::VNVector> *p);
00202 
00204 
00205     virtual void handleLinearInterpolatedTrafoAnimation(const nvsg::LinearInterpolatedAnimation<nvmath::Trafo> *p);
00206 
00208 
00209     virtual void handleLinearInterpolatedVNVectorAnimation(const nvsg::LinearInterpolatedAnimation<nvsg::VNVector> *p);
00210 
00211 private:
00212     const   std::string  getName( const std::string &name );
00213     void    geoset( const nvsg::GeoSet *p, bool doVerticesAndNormals );
00214     std::string  getObjectName( const nvsg::Object *p, std::string namePrefix, int &counter );
00215     void    groupData( const nvsg::Group *p );
00216     void    initUnnamedCounters( void );
00217     bool    isFirstTime( const nvutil::RCObject *p );
00218     void    lightSourceData( const nvsg::LightSource *p );
00219     void    nodeData( const nvsg::Node *p );
00220     void    quads( const nvsg::Quads *p, bool doVerticesAndNormals );
00221     void    simpleCameraData( const nvsg::SimpleCamera *p );
00222     void    triangles( const nvsg::Triangles *p, bool doVerticesAndNormals );
00223 
00224   private:
00225     FILE * m_fh;
00226 
00227     std::set<const nvutil::RCObject *>             m_sharedRCObjects;
00228     std::map<nvsg::DataID, std::string>               m_sharedData;
00229     std::vector<std::pair<std::string,std::string> >      m_geometryNames;
00230     std::vector<const nvsg::StateAttribute *>    m_attributes;
00231     std::vector<const nvsg::TextureAttributeItem*> m_texAttribItems;
00232     const nvsg::StateSet *                  m_currentStateSet;
00233     int                               m_unnamedAnimatedQuadsCounter;
00234     int                               m_unnamedAnimatedTransformCounter;
00235     int                               m_unnamedAnimatedTrianglesCounter;
00236     int                               m_unnamedCgFxCounter;
00237     int                               m_unnamedDirectedLightCounter;
00238     int                               m_unnamedFaceAttributeCounter;
00239     int                               m_unnamedFramedTrafoAnimationCounter;
00240     int                               m_unnamedFramedVNVectorAnimationCounter;
00241     int                               m_unnamedGeoNodeCounter;
00242     int                               m_unnamedGroupCounter;
00243     int                               m_unnamedJitterCameraCounter;
00244     int                               m_unnamedLinearInterpolatedTrafoAnimation;
00245     int                               m_unnamedLinearInterpolatedVNVectorAnimationCounter;
00246     int                               m_unnamedLODCounter;
00247     int                               m_unnamedMaterialCounter;
00248     int                               m_unnamedParallelCameraCounter;
00249     int                               m_unnamedPerspectiveCameraCounter;
00250     int                               m_unnamedPointLightCounter;
00251     int                               m_unnamedQuadsCounter;
00252     int                               m_unnamedQuadStripsCounter;
00253     int                               m_unnamedSkinnedTrianglesCounter;
00254     int                               m_unnamedSpotLightCounter;
00255     int                               m_unnamedStateSetCounter;
00256     int                               m_unnamedStereoCameraCounter;
00257     int                               m_unnamedSwitchCounter;
00258     int                               m_unnamedTextureAttributeCounter;
00259     int                               m_unnamedTextureAttributeItemCounter;
00260     int                               m_unnamedTransformCounter;
00261     int                               m_unnamedTrianglesCounter;
00262     int                               m_unnamedTriStripsCounter;
00263     std::map<const nvsg::Object *, std::string>       m_objectNames;
00264 };
00265 
00267 
00269 class NVSGSaver : public nvsg::SceneSaver
00270 {
00271   public :
00273 
00274     void  deleteThis( void ); 
00275 
00277 
00278     bool  save( const nvsg::Scene &scene          
00279               , const nvsg::ViewState *viewState  
00280               , const std::string& filename      
00281               );
00282 
00283   private :
00284     NVSGSaveTraverser m_traverser;
00285 };
00286 
00287 inline void NVSGSaver::deleteThis( void )
00288 {
00289   delete this;
00290 }

Generated on Tue Mar 1 13:19:18 2005 for NVSGSDK by NVIDIA