Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __SP_SCENE_MESH_H__
00009 #define __SP_SCENE_MESH_H__
00010
00011
00012 #include "Base/spStandard.hpp"
00013 #include "Base/spInputOutputString.hpp"
00014 #include "Base/spMaterialStates.hpp"
00015 #include "Base/spMeshBuffer.hpp"
00016 #include "Base/spViewFrustum.hpp"
00017 #include "Base/spTreeNodeQuad.hpp"
00018 #include "Base/spTreeNodeOct.hpp"
00019 #include "Base/spTreeNodeBSP.hpp"
00020 #include "SceneGraph/spMaterialNode.hpp"
00021 #include "RenderSystem/spTextureBase.hpp"
00022
00023 #include <limits.h>
00024 #include <vector>
00025 #include <list>
00026 #include <map>
00027
00028
00029 namespace sp
00030 {
00031 namespace scene
00032 {
00033
00034
00035
00036
00037
00038
00039 static const u32 MESHBUFFER_IGNORE = UINT_MAX;
00040
00041
00042
00043
00044
00045
00046 class Mesh;
00047 class Camera;
00048 class SceneGraph;
00049
00050 struct SPickingObject;
00051 struct SCollisionObject;
00052
00053
00088 class SP_EXPORT Mesh : public MaterialNode
00089 {
00090
00091 public:
00092
00093 Mesh();
00094 virtual ~Mesh();
00095
00096
00097
00104 virtual bool compareMeshBuffers(const Mesh* Other) const;
00105
00106
00107
00109 void addTexture(
00110 video::Texture* Tex, const u8 Layer = video::TEXLAYER_LAST,
00111 const video::ETextureLayerTypes LayerType = video::TEXLAYER_DEFAULT
00112 );
00113
00124 void textureAutoMap(
00125 const u8 Layer, const f32 Density = 1.0, const u32 MeshBufferIndex = MESHBUFFER_IGNORE,
00126 bool GlobalProjection = true, bool AllowNegativeTexCoords = false
00127 );
00128
00130 std::vector<video::Texture*> getTextureList() const;
00132 u32 getTextureCount() const;
00133
00134
00135
00140 virtual void updateNormals();
00141
00146 void updateTangentSpace(
00147 const u8 TangentLayer = video::TEXTURE_IGNORE, const u8 BinormalLayer = video::TEXTURE_IGNORE, bool UpdateNormals = true
00148 );
00149
00151 void updateVertexBuffer();
00153 void updateIndexBuffer();
00155 void updateMeshBuffer();
00156
00162 void meshTranslate(const dim::vector3df &Direction);
00163 void meshTransform(const dim::vector3df &Size);
00164 void meshTransform(const dim::matrix4f &Matrix);
00165 void meshTurn(const dim::vector3df &Rotation);
00166
00168 void meshFlip();
00169 void meshFlip(bool isXAxis, bool isYAxis, bool isZAxis);
00170
00172 void meshFit(const dim::vector3df &Position, const dim::vector3df &Size);
00174 void meshSpherify(f32 Factor);
00176 void meshTwist(f32 Rotation);
00177
00183 void mergeFamily(bool isDeleteChildren = true);
00184
00189 dim::vector3df centerOrigin();
00190
00192 void seperateTriangles();
00193
00198 void flipTriangles();
00199
00208 bool getMeshBoundingBox(dim::vector3df &Min, dim::vector3df &Max, bool isGlobal = false) const;
00210 dim::aabbox3df getMeshBoundingBox(bool isGlobal = false) const;
00212 f32 getMeshBoundingSphere(bool isGlobal = false) const;
00213
00214
00215
00222 void addLODSubMesh(Mesh* LODSubMesh, bool isCopyMaterials = false);
00224 void clearLODSubMeshes();
00225
00227 void setLODSubMeshList(const std::vector<Mesh*> &LODSubMeshList);
00228
00233 void setLODDistance(f32 Distance);
00234
00236 void setLOD(bool Enable);
00237
00238
00239
00246 video::MeshBuffer* createMeshBuffer(
00247 const video::VertexFormat* VertexFormat = 0,
00248 const video::ERendererDataTypes IndexFormat = video::DATATYPE_UNSIGNED_SHORT
00249 );
00250
00252 void deleteMeshBuffer(const u32 Index);
00253
00255 void deleteMeshBuffers();
00256
00262 void mergeMeshBuffers();
00263
00269 void optimizeTransparency();
00270
00271
00272
00274 u32 getVertexCount() const;
00276 u32 getTriangleCount() const;
00277
00279 u32 getOrigVertexCount() const;
00281 u32 getOrigTriangleCount() const;
00282
00292 void setReference(Mesh* ReferenceMesh, bool CopyLocation = false, bool CopyMaterial = false);
00293
00294 Mesh* getReference();
00295 const Mesh* getReference() const;
00296
00302 void paint(const video::color &Color, bool CombineColors = false);
00303
00310 void setShading(const video::EShadingTypes Type, bool UpdateImmediate = false);
00311
00312
00313
00318 void copy(const Mesh* Other);
00319
00321 Mesh* copy() const;
00322
00327 virtual void render();
00328
00329
00330
00332 inline video::MeshBuffer* getMeshBuffer(const u32 Index)
00333 {
00334 return Index < SurfaceList_->size() ? (*SurfaceList_)[Index] : 0;
00335 }
00337 inline const video::MeshBuffer* getMeshBuffer(const u32 Index) const
00338 {
00339 return Index < SurfaceList_->size() ? (*SurfaceList_)[Index] : 0;
00340 }
00341
00343 inline video::MeshBuffer* getOrigMeshBuffer(const u32 Index)
00344 {
00345 return Index < OrigSurfaceList_.size() ? OrigSurfaceList_[Index] : 0;
00346 }
00348 inline const video::MeshBuffer* getOrigMeshBuffer(const u32 Index) const
00349 {
00350 return Index < OrigSurfaceList_.size() ? OrigSurfaceList_[Index] : 0;
00351 }
00352
00354 inline video::MeshBuffer* getLastMeshBuffer()
00355 {
00356 return !OrigSurfaceList_.empty() ? OrigSurfaceList_[OrigSurfaceList_.size() - 1] : 0;
00357 }
00359 inline const video::MeshBuffer* getLastMeshBuffer() const
00360 {
00361 return !OrigSurfaceList_.empty() ? OrigSurfaceList_[OrigSurfaceList_.size() - 1] : 0;
00362 }
00363
00365 inline u32 getMeshBufferCount() const
00366 {
00367 return SurfaceList_->size();
00368 }
00370 inline u32 getOrigMeshBufferCount() const
00371 {
00372 return OrigSurfaceList_.size();
00373 }
00374
00376 inline const std::vector<video::MeshBuffer*>& getMeshBufferList() const
00377 {
00378 return *SurfaceList_;
00379 }
00380
00382 inline void setRenderCallback(const video::UserRenderCallback &RenderCallback)
00383 {
00384 UserRenderProc_ = RenderCallback;
00385 }
00386
00388 inline const std::vector<Mesh*>& getLODSubMeshList() const
00389 {
00390 return LODSubMeshList_;
00391 }
00393 inline f32 getLODDistance() const
00394 {
00395 return LODSubMeshDistance_;
00396 }
00398 inline bool getLOD() const
00399 {
00400 return UseLODSubMeshes_;
00401 }
00402
00407 inline bool isInstanced() const
00408 {
00409 return Reference_ != 0;
00410 }
00411
00412 protected:
00413
00414 friend class SceneGraph;
00415 friend class SimpleSceneManager;
00416 friend struct SCollisionSystemObject;
00417 friend struct SPickingObject;
00418 friend struct SCollisionObject;
00419
00420 friend bool cmpObjectMeshes(Mesh* &obj1, Mesh* &obj2);
00421
00422
00423
00424 u32 updateLevelOfDetail();
00425
00426 void copyMesh(Mesh* NewMesh) const;
00427
00428
00429
00430 std::vector<video::MeshBuffer*> OrigSurfaceList_;
00431 std::vector<video::MeshBuffer*> * SurfaceList_, * LODSurfaceList_;
00432
00433 bool UseLODSubMeshes_;
00434 f32 LODSubMeshDistance_;
00435 std::vector<Mesh*> LODSubMeshList_;
00436
00437 Mesh* Reference_;
00438
00439 video::UserRenderCallback UserRenderProc_;
00440
00441 };
00442
00443
00444 }
00445
00446 }
00447
00448
00449 #endif
00450
00451
00452
00453