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

NVNVB.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  <set>
00015 #include  "nvsg/nvsgapi.h"
00016 #include  "nvmath/Vec2f.h"
00017 #include  "nvsg/Face.h"
00018 #include  "nvsg/Scene.h"
00019 #include  "nvsg/SkinnedTriangles.h"
00020 #include  "nvsg/TextureAttribute.h"
00021 #include  "NVBBreaker/inc/NVBLoader.h"
00022 
00023 // forward declarations
00024 namespace nvsg
00025 {
00026   class AnimatedTransform;
00027   class Camera;
00028   class FaceAttribute;
00029   class LightSource;
00030   class Material;
00031   class Scene;
00032   class Transform;
00033 }
00034 
00035 //  it's not neccessary to document this helper class !
00036 #if ! defined( DOXYGEN_IGNORE )
00037 class MeshData
00038 {
00039   public:
00040     MeshData();
00041 
00042   public:
00043     std::vector<std::vector<sdword> > m_animationIDs;
00044     std::vector<std::vector<nvmath::Vec3f> >  m_boneOffsets;
00045     unsigned int            m_faceCount;
00046     std::vector<nvsg::Face3>           m_faces;
00047     std::vector<size_t>          m_normalIndices;
00048     std::vector<nvmath::Vec3f>           m_normals;
00049     unsigned int            m_matId;
00050     std::vector<nvsg::Skin>            m_skins;
00051     std::vector<nvmath::Vec3f>           m_vertices;
00052     std::vector<std::vector<nvmath::Vec2f> >  m_texCoords;
00053     unsigned int            m_vertexCount;
00054 };
00055 
00056 inline MeshData::MeshData()
00057 : m_faceCount( 0 )
00058 {
00059 }
00060 #endif  //  DOXYGEN_IGNORE
00061 
00063 class NVNVB : public NVBRenderManager::NVBBreaker
00064 {
00065   public:
00066     NVNVB(void);
00067     ~NVNVB(void);
00068 
00069   public:
00071 
00072     const nvsg::Scene * load( const std::string& filename            
00073                        , const std::vector<std::string> &searchPaths 
00074                        );
00075 
00076     // Application-dependent import methods, called by the importer
00078     virtual bool  NewScene      ( const NVBRenderManager::NVBSceneInfo& scene );
00080     virtual bool  NewCamera     ( const NVBRenderManager::NVBCameraInfo& camera );
00082     virtual bool  NewLight      ( const NVBRenderManager::NVBLightInfo& light );
00084     virtual bool  NewMaterial   ( const NVBRenderManager::NVBMaterialInfo& material );
00086     virtual bool  NewTexture    ( const NVBRenderManager::NVBTextureInfo& texture );
00088     virtual bool  NewMesh       ( const NVBRenderManager::NVBMeshInfo& mesh );
00090     virtual bool  NewShape      ( const NVBRenderManager::NVBShapeInfo& shape );
00092     virtual bool  NewHelper     ( const NVBRenderManager::NVBHelperInfo& helper );
00094     virtual bool  NewController ( const NVBRenderManager::NVBControllerInfo& controller );
00096     virtual bool  NewMotion     ( const NVBRenderManager::NVBMotionInfo& motion );
00097 
00099     virtual bool  EndImport     ( void );
00100 
00102     virtual bool  NVBImportError  ( const char* errortext, udword errorcode );
00103 
00105     virtual void  NVBLog          ( NVBRenderManager::TLogLevel level, LPSTR fmt, ... );
00107     virtual void  SetLogCallback  ( NVBRenderManager::TloggingCB cbfn, unsigned long userparam = 0 );
00108 
00109   private:
00110     void        addMap( sdword mapID, float coeff, nvsg::TextureType tt, const nvsg::TextureAttribute * texAttrib, size_t& unit );
00111     void        addMaps( const NVBRenderManager::NVBMaterialInfo& material, nvsg::Material *pMaterial );
00112     const nvsg::Transform * newTransform( sdword ID, const Point &pos, const Quat &rot, size_t position = 0xFFFFFFFF );
00113 
00114   private:
00115     std::map<const nvsg::Camera *, sdword>                m_cameraToTransformID;
00116     std::vector<const nvsg::Material *>                   m_faceMappedMaterial;
00117     const nvsg::FaceAttribute                           * m_globalFaceAttribute;
00118     std::set<sdword>                                      m_invalidTextureIDs;
00119     std::map<sdword, const nvsg::AnimatedTransform *>     m_IDToAnimatedTransform;
00120     std::map<sdword, const nvsg::Material *>              m_IDToMaterial;
00121     std::map<sdword, std::string>                         m_IDToTextureFileName;
00122     std::map<sdword, float>                               m_IDToTextureRotation;
00123     std::map<sdword, nvmath::Vec3f>                       m_IDToTextureScaling;
00124     std::map<sdword, nvmath::Vec3f>                       m_IDToTextureTranslation;
00125     std::map<sdword, nvsg::Transform *>                   m_IDToTransform;
00126     std::map<const nvsg::LightSource *, sdword>           m_lightToTransformID;
00127     std::set<std::string>                                 m_materialNames;
00128     std::map<const nvsg::Material *, const nvsg::StateSet *>    m_materialToStateSet;
00129     std::vector<MeshData>                                 m_meshData;
00130     int                                                   m_numCgFxAttribs; 
00131     const nvsg::Group                                   * m_rootNode;
00132     const nvsg::Scene                                   * m_scene;
00133     std::vector<std::string>                              m_searchPaths;
00134 
00135     //  On each meshID (sdword) with SkinnedTriangles store some SkinnedTriangles information and the mesh size
00136     //    (number of vertices)
00137     //  The SkinnedTriangles information contains a pair of a pointer to a SkinnedTriangles and pair of a vector of indices
00138     //    into a (mesh-)common normal array and a vector of ids of (Animated)Transforms.
00139     //  For each material in this mesh, there is one such pair (of a pointer and a pair).
00140     typedef struct
00141     {
00142       std::vector<std::vector<sdword> >         m_animationIDs;
00143       std::vector<std::vector<nvmath::Vec3f> >  m_boneOffsets;
00144       std::vector<size_t>                       m_normalIndices;
00145     } SkinnedTrianglesInfo;
00146     std::map<sdword,std::pair<std::vector<std::pair<nvsg::SkinnedTriangles*,SkinnedTrianglesInfo> >,size_t> > m_IDToSkinnedTriangles;
00147 
00148 #if defined( _DEBUG )
00149     std::set<udword> m_meshIds;
00150 #endif
00151 };
00152 
00153 inline const nvsg::Scene * NVNVB::load( const std::string& filename, const std::vector<std::string> &searchPaths )
00154 {
00155   __TRACE();
00156 
00157   if ( m_scene )
00158   {
00159     m_scene->removeRef();
00160   }
00161   m_scene = NULL;
00162       
00163   // We need to clean up everything, so we can use loader instance more than once.
00164   m_cameraToTransformID.clear();
00165   m_faceMappedMaterial.clear();
00166   m_globalFaceAttribute=NULL;
00167   m_invalidTextureIDs.clear();
00168   m_IDToAnimatedTransform.clear();
00169   m_IDToMaterial.clear();
00170   m_IDToTextureFileName.clear();
00171   m_IDToTextureRotation.clear();
00172   m_IDToTextureScaling.clear();
00173   m_IDToTextureTranslation.clear();
00174   m_IDToTransform.clear();
00175   m_lightToTransformID.clear();
00176   m_materialNames.clear();
00177   m_materialToStateSet.clear();
00178   m_meshData.clear();
00179   m_numCgFxAttribs=0;
00180   m_rootNode=NULL;    
00181   m_IDToSkinnedTriangles.clear();
00182 
00183 #if defined( _DEBUG )
00184   m_meshIds.clear();
00185 #endif
00186 
00187   // private copy of the search paths
00188   m_searchPaths = searchPaths;
00189 
00190   // run the importer
00191   if ( !Import( filename.c_str() ) )
00192   {
00193     __TRACE_OUT_F(("Failed to import %s!\n", filename.c_str()))
00194   }
00195   __ASSERT(m_scene);
00196   return( m_scene );
00197 }

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