00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #pragma once
00013
00014 #include "nvsg/PlugInterface.h"
00015 #include "nvsg/NBF.h"
00016
00017 #include <map>
00018 #include <vector>
00019 #include <string>
00020
00021
00022 #if defined(_WIN32)
00023 # ifdef NBFLOADER_EXPORTS
00024 # define NBFLOADER_API __declspec(dllexport)
00025 # else
00026 # define NBFLOADER_API __declspec(dllimport)
00027 # endif
00028 #else
00029 # define NBFLOADER_API
00030 #endif
00031
00032 #if defined(LINUX)
00033 void lib_init() __attribute__ ((constructor));
00034 #endif
00035
00036
00037 #if defined(LINUX)
00038 extern "C"
00039 {
00040 #endif
00041 NBFLOADER_API bool getPlugInterface(const nvutil::UPIID& piid, nvutil::PlugIn *& pi);
00042 NBFLOADER_API bool queryPlugInterfaceType(const nvutil::UPITID& pitid, std::vector<nvutil::UPIID>& piids);
00043 #if defined(LINUX)
00044 }
00045 #endif
00046
00047
00048 #ifdef _DEBUG
00049 # ifndef new
00050 # define new new(__FILE__, __LINE__)
00051 # define _DEFINED_DBGNEW // restrict the 'new' macro to this header file only
00052 # endif
00053 #endif
00054
00055
00056 namespace nvsg
00057 {
00058 class AnimatedQuads;
00059 class AnimatedTransform;
00060 class AnimatedTriangles;
00061 class Camera;
00062 class CgFx;
00063 class DirectedLight;
00064 class Drawable;
00065 class FaceAttribute;
00066 class GeoNode;
00067 class GeoSet;
00068 class Group;
00069 class LightSource;
00070 class LOD;
00071 class Material;
00072 class Node;
00073 class ParallelCamera;
00074 class PerspectiveCamera;
00075 class PointLight;
00076 class Quads;
00077 class QuadStrips;
00078 class SimpleCamera;
00079 class SkinnedTriangles;
00080 class SpotLight;
00081 class StateAttribute;
00082 class StateSet;
00083 class TextureAttribute;
00084 class TextureAttributeItem;
00085 class Transform;
00086 class Triangles;
00087 class TriStrips;
00088 class Switch;
00089 class Scene;
00090 class ViewState;
00091 template<typename T> class FramedAnimation;
00092 template<typename T> class InterpolatedAnimation;
00093 }
00094
00096 class NBFLoader : public nvsg::SceneLoader
00097 {
00098 public:
00099 NBFLoader();
00100
00102
00103 void deleteThis( void );
00104
00106
00110 const nvsg::Scene * load(
00111 const std::string& filename
00112 , const std::vector<std::string> &searchPaths
00113 , const nvsg::ViewState *& viewState
00115 );
00116
00117 protected:
00119 virtual ~NBFLoader(void);
00120
00122
00133 virtual const nvsg::Object * loadCustomObject(
00134 uint_t objectCode
00135 , uint_t offset
00136 );
00137
00139
00141 ubyte_t * mapOffset(
00142 uint_t offset
00143 , size_t numBytes
00144 );
00145
00146 private:
00147
00148 bool mapViewOfFile(const std::string& file);
00149 void unmapViewOfFile();
00150
00151
00152 void mapObject(uint_t offset, const nvsg::Object * object);
00153
00154
00155 const nvsg::Animation<nvmath::Trafo> * loadTrafoAnimation(uint_t offset);
00156 const nvsg::Animation<nvsg::VNVector> * loadVNVectorAnimation(uint_t offset);
00157
00158 const nvsg::FramedAnimation<nvmath::Trafo> * loadFramedTrafoAnimation(uint_t offset);
00159 const nvsg::FramedAnimation<nvsg::VNVector> * loadFramedVNVectorAnimation(uint_t offset);
00160
00161 const nvsg::InterpolatedAnimation<nvmath::Trafo> * loadInterpolatedTrafoAnimation(uint_t offset);
00162 const nvsg::InterpolatedAnimation<nvsg::VNVector> * loadInterpolatedVNVectorAnimation(uint_t offset);
00163
00164 const nvsg::Camera * loadCamera(uint_t offset);
00165 const nvsg::ParallelCamera * loadParallelCamera(uint_t offset);
00166 const nvsg::PerspectiveCamera * loadPerspectiveCamera(uint_t offset);
00167
00168 const nvsg::Drawable * loadDrawable(uint_t offset);
00169 const nvsg::Triangles * loadTriangles(uint_t offset);
00170 const nvsg::AnimatedTriangles * loadAnimatedTriangles(uint_t offset);
00171 const nvsg::SkinnedTriangles * loadSkinnedTriangles(uint_t offset);
00172 const nvsg::Quads * loadQuads(uint_t offset);
00173 const nvsg::AnimatedQuads * loadAnimatedQuads(uint_t offset);
00174 template<typename StripType> const StripType * loadStrips(uint_t offset);
00175
00176 const nvsg::Scene * loadScene(uint_t offset);
00177
00178 const nvsg::Node * loadNode(uint_t offset);
00179 const nvsg::GeoNode * loadGeoNode(uint_t offset);
00180 const nvsg::Group * loadGroup(uint_t offset);
00181 const nvsg::Transform * loadTransform(uint_t offset);
00182 const nvsg::AnimatedTransform * loadAnimatedTransform(uint_t offset);
00183 const nvsg::LOD * loadLOD(uint_t offset);
00184 const nvsg::Switch * loadSwitch(uint_t offset);
00185 const nvsg::LightSource * loadLightSource(uint_t offset);
00186 const nvsg::DirectedLight * loadDirectedLight(uint_t offset);
00187 const nvsg::PointLight * loadPointLight(uint_t offset);
00188 const nvsg::SpotLight * loadSpotLight(uint_t offset);
00189
00190 const nvsg::StateAttribute * loadStateAttribute(uint_t offset);
00191 const nvsg::CgFx * loadCgFx(uint_t offset);
00192 const nvsg::FaceAttribute * loadFaceAttribute(uint_t offset);
00193 const nvsg::Material * loadMaterial(uint_t offset);
00194 const nvsg::TextureAttribute * loadTextureAttribute(uint_t offset);
00195 const nvsg::TextureAttributeItem * loadTextureAttributeItem(uint_t offset);
00196
00197 const nvsg::StateSet * loadStateSet(uint_t offset);
00198
00199 const nvsg::ViewState * loadViewState(uint_t offset);
00200
00201 template <typename ObjectType, typename NBFObjectType>
00202 bool loadSharedObject(nvutil::RCObject_AutoPtr<ObjectType>& obj, NBFObjectType *& objPtr);
00203
00204
00205 void readObject(nvsg::Object * dst, const NBFObject * src);
00206 void readGroup(nvsg::Group * dst, const NBFGroup * src);
00207 void readGeoSet(nvsg::GeoSet * dst, const NBFGeoSet * src);
00208 void readLightSource(nvsg::LightSource * dst, NBFLightSource * src);
00209 void readNode(nvsg::Node * dst, NBFNode * src);
00210 void readSimpleCamera(nvsg::SimpleCamera * dst, const NBFSimpleCamera * src);
00211
00212 private:
00213
00214 enum
00215 {
00216 VIEWSIZE = 0x04000000
00217 };
00218
00219 struct ViewHeader
00220 {
00221 ubyte_t * basePtr;
00222 size_t startOffs;
00223 size_t endOffs;
00224 };
00225 std::vector<ViewHeader> m_mappedViews;
00226 #if defined(_WIN32)
00227 HANDLE m_file;
00228 HANDLE m_fileMapping;
00229 #elif defined(LINUX)
00230 int m_file;
00231 #endif
00232 size_t m_mappingSize;
00233 size_t m_allocationGranularity;
00234 std::vector<std::string> m_searchPaths;
00235 std::map<uint_t, const nvsg::Object *> m_offsetObjectMap;
00236 std::map<nvsg::DataID, const nvsg::Object *> m_sharedObjectsMap;
00237
00238 ubyte_t m_nbfMajor;
00239 ubyte_t m_nbfMinor;
00240 ubyte_t m_nbfBugfix;
00241 };
00242
00243 inline void NBFLoader::deleteThis()
00244 {
00245 delete this;
00246 }
00247
00248 #ifdef _DEFINED_DBGNEW
00249 # undef new
00250 #endif