Irrlicht 3D Engine
SMesh.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
2 // This file is part of the "Irrlicht Engine".
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
4 
5 #ifndef __S_MESH_H_INCLUDED__
6 #define __S_MESH_H_INCLUDED__
7 
8 #include "IMesh.h"
9 #include "IMeshBuffer.h"
10 #include "aabbox3d.h"
11 #include "irrArray.h"
12 
13 namespace irr
14 {
15 namespace scene
16 {
18  struct SMesh : public IMesh
19  {
22  {
23  #ifdef _DEBUG
24  setDebugName("SMesh");
25  #endif
26  }
27 
29  virtual ~SMesh()
30  {
31  // drop buffers
32  for (u32 i=0; i<MeshBuffers.size(); ++i)
33  MeshBuffers[i]->drop();
34  }
35 
37  virtual void clear()
38  {
39  for (u32 i=0; i<MeshBuffers.size(); ++i)
40  MeshBuffers[i]->drop();
41  MeshBuffers.clear();
42  BoundingBox.reset ( 0.f, 0.f, 0.f );
43  }
44 
45 
47  virtual u32 getMeshBufferCount() const
48  {
49  return MeshBuffers.size();
50  }
51 
53  virtual IMeshBuffer* getMeshBuffer(u32 nr) const
54  {
55  return MeshBuffers[nr];
56  }
57 
59 
60  virtual IMeshBuffer* getMeshBuffer( const video::SMaterial & material) const
61  {
62  for (s32 i = (s32)MeshBuffers.size()-1; i >= 0; --i)
63  {
64  if ( material == MeshBuffers[i]->getMaterial())
65  return MeshBuffers[i];
66  }
67 
68  return 0;
69  }
70 
72  virtual const core::aabbox3d<f32>& getBoundingBox() const
73  {
74  return BoundingBox;
75  }
76 
78  virtual void setBoundingBox( const core::aabbox3df& box)
79  {
80  BoundingBox = box;
81  }
82 
85  {
86  bool hasMeshBufferBBox = false;
87  for (u32 i=0; i<MeshBuffers.size(); ++i)
88  {
89  const core::aabbox3df& bb = MeshBuffers[i]->getBoundingBox();
90  if ( !bb.isEmpty() )
91  {
92  if ( !hasMeshBufferBBox )
93  {
94  hasMeshBufferBBox = true;
95  BoundingBox = bb;
96  }
97  else
98  {
100  }
101 
102  }
103  }
104 
105  if ( !hasMeshBufferBBox )
106  BoundingBox.reset(0.0f, 0.0f, 0.0f);
107  }
108 
110 
112  {
113  if (buf)
114  {
115  buf->grab();
116  MeshBuffers.push_back(buf);
117  }
118  }
119 
121  virtual void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue)
122  {
123  for (u32 i=0; i<MeshBuffers.size(); ++i)
124  MeshBuffers[i]->getMaterial().setFlag(flag, newvalue);
125  }
126 
129  {
130  for (u32 i=0; i<MeshBuffers.size(); ++i)
131  MeshBuffers[i]->setHardwareMappingHint(newMappingHint, buffer);
132  }
133 
136  {
137  for (u32 i=0; i<MeshBuffers.size(); ++i)
138  MeshBuffers[i]->setDirty(buffer);
139  }
140 
143 
146  };
147 
148 
149 } // end namespace scene
150 } // end namespace irr
151 
152 #endif
153 
virtual u32 getMeshBufferCount() const
returns amount of mesh buffers.
Definition: SMesh.h:47
bool drop() const
Drops the object. Decrements the reference counter by one.
virtual void clear()
clean mesh
Definition: SMesh.h:37
core::aabbox3d< f32 > BoundingBox
The bounding box of this mesh.
Definition: SMesh.h:145
void recalculateBoundingBox()
recalculates the bounding box
Definition: SMesh.h:84
Everything in the Irrlicht Engine can be found in this namespace.
Definition: aabbox3d.h:12
Simple implementation of the IMesh interface.
Definition: SMesh.h:18
core::array< IMeshBuffer * > MeshBuffers
The meshbuffers of this mesh.
Definition: SMesh.h:142
virtual void setHardwareMappingHint(E_HARDWARE_MAPPING newMappingHint, E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX)
set the hardware mapping hint, for driver
Definition: SMesh.h:128
void reset(T x, T y, T z)
Resets the bounding box to a one-point box.
Definition: aabbox3d.h:50
Class which holds the geometry of an object.
Definition: IMesh.h:71
virtual void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue)
sets a flag of all contained materials to a new value
Definition: SMesh.h:121
signed int s32
32 bit signed variable.
Definition: irrTypes.h:70
Struct for holding a mesh with a single material.
Definition: IMeshBuffer.h:39
void addInternalBox(const aabbox3d< T > &b)
Adds another bounding box.
Definition: aabbox3d.h:82
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
Change both vertex and index mapping to the same value.
virtual void setDirty(E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX)
flags the meshbuffer as changed, reloads hardware buffers
Definition: SMesh.h:135
virtual ~SMesh()
destructor
Definition: SMesh.h:29
virtual IMeshBuffer * getMeshBuffer(const video::SMaterial &material) const
returns a meshbuffer which fits a material
Definition: SMesh.h:60
void addMeshBuffer(IMeshBuffer *buf)
adds a MeshBuffer
Definition: SMesh.h:111
virtual void setBoundingBox(const core::aabbox3df &box)
set user axis aligned bounding box
Definition: SMesh.h:78
SMesh()
constructor
Definition: SMesh.h:21
Self reallocating template array (like stl vector) with additional features.
Definition: irrArray.h:22
void grab() const
Grabs the object. Increments the reference counter by one.
bool isEmpty() const
Check if the box is empty.
Definition: aabbox3d.h:129
E_MATERIAL_FLAG
Material flags.
void setDebugName(const c8 *newName)
Sets the debug name of the object.
virtual const core::aabbox3d< f32 > & getBoundingBox() const
returns an axis aligned bounding box
Definition: SMesh.h:72
Struct for holding parameters for a material renderer.
Definition: SMaterial.h:286
virtual IMeshBuffer * getMeshBuffer(u32 nr) const
returns pointer to a mesh buffer
Definition: SMesh.h:53