| Irrlicht 3D Engine |

SMesh.h
Go to the documentation of this file.

    00001 // Copyright (C) 2002-2012 Nikolaus Gebhardt
    00002 // This file is part of the "Irrlicht Engine".
    00003 // For conditions of distribution and use, see copyright notice in irrlicht.h
    00004
    00005 #ifndef __S_MESH_H_INCLUDED__
    00006 #define __S_MESH_H_INCLUDED__
    00007
    00008 #include "IMesh.h"
    00009 #include "IMeshBuffer.h"
    00010 #include "aabbox3d.h"
    00011 #include "irrArray.h"
    00012
    00013 namespace irr
    00014 {
    00015 namespace scene
    00016 {
    00018     struct SMesh : public IMesh
    00019     {
    00021         SMesh()
    00022         {
    00023             #ifdef _DEBUG
    00024             setDebugName("SMesh");
    00025             #endif
    00026         }
    00027
    00029         virtual ~SMesh()
    00030         {
    00031             // drop buffers
    00032             for (u32 i=0; i<MeshBuffers.size(); ++i)
    00033                 MeshBuffers[i]->drop();
    00034         }
    00035
    00037         virtual void clear()
    00038         {
    00039             for (u32 i=0; i<MeshBuffers.size(); ++i)
    00040                 MeshBuffers[i]->drop();
    00041             MeshBuffers.clear();
    00042             BoundingBox.reset ( 0.f, 0.f, 0.f );
    00043         }
    00044
    00045
    00047         virtual u32 getMeshBufferCount() const
    00048         {
    00049             return MeshBuffers.size();
    00050         }
    00051
    00053         virtual IMeshBuffer* getMeshBuffer(u32 nr) const
    00054         {
    00055             return MeshBuffers[nr];
    00056         }
    00057
    00059
    00060         virtual IMeshBuffer* getMeshBuffer( const video::SMaterial & material) const
    00061         {
    00062             for (s32 i = (s32)MeshBuffers.size()-1; i >= 0; --i)
    00063             {
    00064                 if ( material == MeshBuffers[i]->getMaterial())
    00065                     return MeshBuffers[i];
    00066             }
    00067
    00068             return 0;
    00069         }
    00070
    00072         virtual const core::aabbox3d<f32>& getBoundingBox() const
    00073         {
    00074             return BoundingBox;
    00075         }
    00076
    00078         virtual void setBoundingBox( const core::aabbox3df& box)
    00079         {
    00080             BoundingBox = box;
    00081         }
    00082
    00084         void recalculateBoundingBox()
    00085         {
    00086             if (MeshBuffers.size())
    00087             {
    00088                 BoundingBox = MeshBuffers[0]->getBoundingBox();
    00089                 for (u32 i=1; i<MeshBuffers.size(); ++i)
    00090                     BoundingBox.addInternalBox(MeshBuffers[i]->getBoundingBox());
    00091             }
    00092             else
    00093                 BoundingBox.reset(0.0f, 0.0f, 0.0f);
    00094         }
    00095
    00097
    00098         void addMeshBuffer(IMeshBuffer* buf)
    00099         {
    00100             if (buf)
    00101             {
    00102                 buf->grab();
    00103                 MeshBuffers.push_back(buf);
    00104             }
    00105         }
    00106
    00108         virtual void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue)
    00109         {
    00110             for (u32 i=0; i<MeshBuffers.size(); ++i)
    00111                 MeshBuffers[i]->getMaterial().setFlag(flag, newvalue);
    00112         }
    00113
    00115         virtual void setHardwareMappingHint( E_HARDWARE_MAPPING newMappingHint, E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX )
    00116         {
    00117             for (u32 i=0; i<MeshBuffers.size(); ++i)
    00118                 MeshBuffers[i]->setHardwareMappingHint(newMappingHint, buffer);
    00119         }
    00120
    00122         virtual void setDirty(E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX)
    00123         {
    00124             for (u32 i=0; i<MeshBuffers.size(); ++i)
    00125                 MeshBuffers[i]->setDirty(buffer);
    00126         }
    00127
    00129         core::array<IMeshBuffer*> MeshBuffers;
    00130
    00132         core::aabbox3d<f32> BoundingBox;
    00133     };
    00134
    00135
    00136 } // end namespace scene
    00137 } // end namespace irr
    00138
    00139 #endif
    00140