00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __SP_SCENELOADER_SPSB_H__
00009 #define __SP_SCENELOADER_SPSB_H__
00010
00011
00012 #include "Base/spStandard.hpp"
00013
00014 #ifdef SP_COMPILE_WITH_SCENELOADER_SPSB
00015
00016
00017 #include "Base/spInputOutputLog.hpp"
00018 #include "Base/spInputOutputFileSystem.hpp"
00019 #include "Base/spDimension.hpp"
00020 #include "Base/spBasicMeshGenerator.hpp"
00021 #include "RenderSystem/spTextureBase.hpp"
00022 #include "FileFormats/Mesh/spMeshLoader.hpp"
00023 #include "SoundSystem/spSoundDevice.hpp"
00024 #include "SceneGraph/Collision/spCollisionConfigTypes.hpp"
00025 #include "Framework/Tools/spStoryboardTrigger.hpp"
00026
00027 #include "Plugins/SpSbImportExport/spsImporter.h"
00028
00029 #include <list>
00030
00031
00032 namespace sp
00033 {
00034 namespace scene
00035 {
00036
00037
00038 class Mesh;
00039 class Light;
00040 class Camera;
00041 class Billboard;
00042
00043
00044 enum ESceneLoaderFlags
00045 {
00046 SCENEFLAG_ABSOLUTEPATH = 0x00000001,
00047
00048 SCENEFLAG_CONFIG = 0x00000002,
00049
00050 SCENEFLAG_MESHES = 0x00000004,
00051 SCENEFLAG_LIGHTS = 0x00000008,
00052 SCENEFLAG_CAMERAS = 0x00000010,
00053 SCENEFLAG_WAYPOINTS = 0x00000020,
00054 SCENEFLAG_BOUNDVOLUMES = 0x00000040,
00055 SCENEFLAG_SOUNDS = 0x00000080,
00056 SCENEFLAG_SPRITES = 0x00000100,
00057 SCENEFLAG_ANIMNODES = 0x00000200,
00058
00059 SCENEFLAG_TEXTURES = 0x00010000,
00060 SCENEFLAG_LIGHTMAPS = 0x00020000,
00061 SCENEFLAG_SHADERS = 0x00040000,
00062
00063 SCENEFLAG_STORYBOARDITEMS = 0x00080000,
00064
00066 SCENEFLAG_OBJECTS =
00067 SCENEFLAG_MESHES |
00068 SCENEFLAG_LIGHTS |
00069 SCENEFLAG_CAMERAS |
00070 SCENEFLAG_WAYPOINTS |
00071 SCENEFLAG_BOUNDVOLUMES |
00072 SCENEFLAG_SOUNDS |
00073 SCENEFLAG_SPRITES |
00074 SCENEFLAG_ANIMNODES,
00075
00077 SCENEFLAG_ALL = ~0,
00078 };
00079
00080
00087 class SP_EXPORT SceneLoaderSPSB : public SceneLoader, public sps::SpSceneImporter
00088 {
00089
00090 public:
00091
00092 SceneLoaderSPSB();
00093 virtual ~SceneLoaderSPSB();
00094
00095
00096
00097 virtual Mesh* loadScene(const io::stringc &Filename, const io::stringc &TexturePath, const s32 Flags);
00098
00099 protected:
00100
00101
00102
00103 enum ETextureClassLayerTypes
00104 {
00105 TEXCLASSLAYER_CUSTOM = 0,
00106 TEXCLASSLAYER_LIGHTMAP,
00107 TEXCLASSLAYER_SHADER,
00108 };
00109
00110
00111
00112 struct SParentQueue
00113 {
00114 SParentQueue() :
00115 Object (0),
00116 ParentId(0)
00117 {
00118 }
00119 ~SParentQueue()
00120 {
00121 }
00122
00123
00124 SceneNode* Object;
00125 u32 ParentId;
00126 };
00127
00128
00129
00130 virtual void Error(const std::string &Message, const EErrorTypes Type = ERROR_DEFAULT);
00131 virtual void Warning(const std::string &Message, const EWarningType Type = WARNING_DEFAULT);
00132
00133 virtual bool CatchHeader (const SpHeader &Header);
00134
00135 virtual bool CatchSceneConfig (const SpSceneConfig &Object);
00136 virtual bool CatchMesh (const SpMesh &Object);
00137 virtual bool CatchCamera (const SpCamera &Object);
00138 virtual bool CatchWayPoint (const SpWayPoint &Object);
00139 virtual bool CatchLight (const SpLight &Object);
00140 virtual bool CatchBoundVolume (const SpBoundVolume &Object);
00141 virtual bool CatchSound (const SpSound &Object);
00142 virtual bool CatchSprite (const SpSprite &Object);
00143 virtual bool CatchAnimNode (const SpAnimNode &Object);
00144 virtual bool CatchTexture (const SpTexture &Object);
00145 virtual bool CatchTextureClass (const SpTextureClass &Object);
00146 virtual bool CatchLightmap (const SpLightmap &Object);
00147 virtual bool CatchLightmapScene (const SpLightmapScene &Object);
00148 virtual bool CatchShaderClass (const SpShaderClass &Object);
00149 virtual bool CatchStoryboardItem(const SpStoryboardItem &Object);
00150
00152 virtual io::stringc getFinalPath(const io::stringc &Path) const;
00154 virtual void applyQueues();
00155 virtual void addObjectToParentQueue(SceneNode* Node, u32 ParentId);
00156
00157 virtual SpTextureClass* findTextureClass(u32 Id);
00158 virtual video::Texture* findTexture(u32 Id);
00159 virtual video::ShaderClass* findShaderClass(u32 Id);
00160 virtual Transformation findAnimNodeTransformation(u32 Id);
00161
00163 virtual bool setupBaseObject (SceneNode* Node, const SpBaseObject &Object);
00164 virtual bool setupViewCulling (SceneNode* Node, const SpViewCulling &Object);
00165 virtual bool setupAnimation (SceneNode* Node, const SpAnimationObject &Object);
00166 virtual bool setupMaterial (video::MaterialStates* Material, const SpMaterial &Object);
00167 virtual bool setupSurface (Mesh* MeshObj, video::MeshBuffer* Surface, const SpSurface &Object, u32 Index);
00168 virtual bool setupSurfaceTexture (video::MeshBuffer* Surface, video::Texture* Tex, u32 TexId, u8 Layer);
00169 virtual bool setupSurfaceTextureClass (video::MeshBuffer* Surface, const SpTextureClassLayer &TexClassLayer, bool NeedDefaultTex, u8 Layer);
00170 virtual bool setupMeshBufferFormat (video::MeshBuffer* Surface, const video::VertexFormat* VxFormat, const video::ERendererDataTypes IxFormat);
00171 virtual bool setupMeshCollision (Mesh* MeshObj, const ECollisionModels CollModel, s32 Flags);
00172 virtual bool setupMeshShader (Mesh* MeshObj, u32 ShaderClassId);
00173 virtual bool setupScriptTemplates (SceneNode* Node, const SpBaseObject &Object, const SpScriptData &Script);
00174 virtual bool setupTexture (video::Texture* Tex, const SpTexture &Object);
00175 virtual bool setupLightmapSceneSurface (video::MeshBuffer* Surface, const SpLightmapSceneSurface &Object);
00176 virtual bool setupShaderConstants (video::Shader* ShaderObj, const SpShader &Object);
00177
00178 virtual bool completeMeshConstruct (Mesh* MeshObj, const SpMesh &Object);
00179 virtual bool completeCameraConstruct(Camera* CameraObj, const SpCamera &Object);
00180 virtual bool completeLightConstruct (Light* LightObj, const SpLight &Object);
00181 virtual bool completeSpriteConstruct(Billboard* SpriteObj, const SpSprite &Object);
00182
00183 virtual Mesh* createSkyBox (const std::string (&SkyBoxTexFilenames)[6]);
00184 virtual Mesh* createMeshBasic (const SpMeshConstructionBasic &Construct);
00185 virtual Mesh* createMeshResource (const SpMeshConstructionResource &Construct);
00186 virtual video::Shader* createShader (const SpShader &Object, video::ShaderClass* ShaderClassObj, const video::EShaderTypes Type);
00187
00188 #ifdef SP_COMPILE_WITH_STORYBOARD
00189 virtual tool::Trigger* createStoryboardItem(const SpStoryboardItem &Object);
00190 #endif
00191
00192 virtual video::VertexFormat* getVertexFormat(s8 VertexFormat);
00193
00194
00195
00196 template <typename T> T* findObjectById(u32 Id, std::map<u32, T*> &Map, const io::stringc &Name)
00197 {
00198 if (Id > 0)
00199 {
00200 typename std::map<u32, T*>::iterator it = Map.find(Id);
00201 if (it != Map.end())
00202 return it->second;
00203 else
00204 Error(("Wrong ID number for " + Name + " (" + io::stringc(Id) + ")").str());
00205 }
00206 return 0;
00207 }
00208
00209
00210
00211 inline dim::point2df convert(const SpVector2 &Vec) const
00212 {
00213 return *(const dim::point2df*)(&Vec.x);
00214 }
00215 inline dim::vector3df convert(const SpVector3 &Vec) const
00216 {
00217 return *(const dim::vector3df*)(&Vec.x);
00218 }
00219 inline dim::vector4df convert(const SpVector4 &Vec) const
00220 {
00221 return *(const dim::vector4df*)(&Vec.x);
00222 }
00223 inline dim::matrix4f convert(const SpMatrix4 &Mat) const
00224 {
00225 return *(const dim::matrix4f*)(&Mat.m[0]);
00226 }
00227 inline video::color convert(const SpColor &Color) const
00228 {
00229 return *(const video::color*)(&Color.r);
00230 }
00231
00232 inline Transformation convertTransformation(const SpBaseObject &Object) const
00233 {
00234 return Transformation(
00235 convert(Object.Position ),
00236 convert(Object.Rotation ),
00237 convert(Object.Scaling )
00238 );
00239 }
00240
00241 private:
00242
00243
00244
00245 #ifdef SP_COMPILE_WITH_STORYBOARD
00246
00247 struct SStoryQueueItem
00248 {
00249 tool::Trigger* Object;
00250 std::vector<u32> LinkIDs;
00251 };
00252
00253 #endif
00254
00255
00256
00257 ECollisionModels convertCollisionModel(const s8 Model) const;
00258 s32 getCollisionFlags(const s8 CollModel, const s8 PickModel) const;
00259
00260
00261
00262 std::map<u32, SceneNode*> ObjectIdMap_;
00263 std::map<u32, video::Texture*> Textures_;
00264 std::map<u32, video::ShaderClass*> ShaderClasses_;
00265 std::map<u32, SpTextureClass> TextureClasses_;
00266 std::map<u32, Transformation> AnimNodeTransMap_;
00267
00268 std::vector<video::Texture*> LightmapTextures_;
00269
00270
00271 std::list<SParentQueue> QueueParents_;
00272
00273 #ifdef SP_COMPILE_WITH_STORYBOARD
00274 std::map<u32, SStoryQueueItem> QueueStoryItems_;
00275 #endif
00276
00277 io::stringc RootPath_;
00278
00279 io::stringc ResourcePath_;
00280 io::stringc ScriptTemplateFilename_;
00281
00282 bool HasLightmaps_;
00283
00284 };
00285
00286
00287 }
00288
00289 }
00290
00291
00292 #endif
00293
00294 #endif
00295
00296
00297
00298