00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
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
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
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
00078
00080
00082
00084
00086
00088
00090
00092
00094
00096
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
00136
00137
00138
00139
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
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
00188 m_searchPaths = searchPaths;
00189
00190
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 }