00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #pragma once
00013
00015 #include "nvsg/PlugInterface.h"
00016 #include "nvutil/Tools.h"
00017 #include "inc/NVNVB.h"
00018 #include "inc/NVNVB2.h"
00019
00020
00021 #if ! defined( DOXYGEN_IGNORE )
00022 #ifdef NVBLOADER_EXPORTS
00023 # define NVNVB_API __declspec(dllexport)
00024 #else
00025 # define NVNVB_API __declspec(dllimport)
00026 #endif
00027 #endif // DOXYGEN_IGNORE
00028
00030
00034 NVNVB_API bool getPlugInterface( const nvutil::UPIID& piid
00035 , nvutil::PlugIn *& pi
00036 );
00037
00039
00044 NVNVB_API bool queryPlugInterfaceType( const nvutil::UPITID& pitid
00045 , std::vector<nvutil::UPIID>& piids
00046 );
00047
00049
00053 class NVBLoader : public nvsg::SceneLoader
00054 {
00055 public:
00056 NVBLoader();
00057
00059
00060 void deleteThis( void );
00061
00063
00068 const nvsg::Scene * load( const std::string& filename
00069 , const std::vector<std::string> &searchPaths
00070 , const nvsg::ViewState *& viewState
00072 );
00073
00074 protected:
00076 virtual ~NVBLoader(void);
00077
00078 private:
00079 NVNVB * m_nvnvb;
00080 NVNVB2 * m_nvnvb2;
00081 };
00082
00083 inline NVBLoader::NVBLoader()
00084 : m_nvnvb(NULL)
00085 , m_nvnvb2(NULL)
00086 {
00087 }
00088
00089 inline NVBLoader::~NVBLoader()
00090 {
00091 if ( m_nvnvb )
00092 {
00093 delete m_nvnvb;
00094 }
00095 if ( m_nvnvb2 )
00096 {
00097 delete m_nvnvb2;
00098 }
00099 }
00100
00101 inline void NVBLoader::deleteThis( void )
00102 {
00103 delete this;
00104 }
00105
00106 inline const nvsg::Scene * NVBLoader::load( const std::string& filename, const std::vector<std::string> &searchPaths, const nvsg::ViewState *& viewState )
00107 {
00108 __TRACE();
00109 viewState = NULL;
00110 const nvsg::Scene * scene = NULL;
00111 std::string theFile = filename;
00112 if ( nvutil::FindFileFirst(filename, searchPaths, theFile) )
00113 {
00114 FILE * fh = fopen( theFile.c_str(), "rb" );
00115 char header[5];
00116 fread( header, 1, 4, fh );
00117 header[4] = '\0';
00118 fclose( fh );
00119
00120 if ( !strcmp( header, "NVBP" ) || !strcmp( header, "NVB!" ) )
00121 {
00122 if ( ! m_nvnvb )
00123 {
00124 m_nvnvb = new NVNVB;
00125 __ASSERT( m_nvnvb );
00126 }
00127 scene = m_nvnvb->load( theFile, searchPaths );
00128 }
00129 else if ( !strcmp( header, "NVB2" ) )
00130 {
00131 if ( ! m_nvnvb2 )
00132 {
00133 m_nvnvb2 = new NVNVB2;
00134 __ASSERT( m_nvnvb2 );
00135 }
00136 scene = m_nvnvb2->load( theFile, searchPaths );
00137 }
00138 else
00139 {
00140 __TRACE_OUT_F(("Invalid file format: %s !\n", header ));
00141 scene = NULL;
00142 }
00143 }
00144 else
00145 {
00146 __TRACE_OUT_F(("File %s not found!\n", filename.c_str()))
00147 }
00148 return( scene );
00149 }