Home | Namespaces | Hierarchy | Alphabetical List | Class list | Files | Namespace Members | Class members | File members | Tutorials
IMeshManipulator.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2010 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 __I_MESH_MANIPULATOR_H_INCLUDED__
6 #define __I_MESH_MANIPULATOR_H_INCLUDED__
7 
8 #include "IReferenceCounted.h"
9 #include "vector3d.h"
10 #include "aabbox3d.h"
11 #include "matrix4.h"
12 #include "IAnimatedMesh.h"
13 #include "IMeshBuffer.h"
14 #include "SVertexManipulator.h"
15 
16 namespace irr
17 {
18 namespace scene
19 {
20 
21  struct SMesh;
22 
24 
29  class IMeshManipulator : public virtual IReferenceCounted
30  {
31  public:
32 
34 
37  virtual void flipSurfaces(IMesh* mesh) const = 0;
38 
40 
42  void setVertexColorAlpha(IMesh* mesh, s32 alpha) const
43  {
45  }
46 
48 
50  void setVertexColors(IMesh* mesh, video::SColor color) const
51  {
53  }
54 
56 
59  virtual void recalculateNormals(IMesh* mesh, bool smooth = false, bool angleWeighted = false) const = 0;
60 
62 
65  virtual void recalculateNormals(IMeshBuffer* buffer, bool smooth = false, bool angleWeighted = false) const = 0;
66 
68 
73  virtual void recalculateTangents(IMesh* mesh,
74  bool recalculateNormals=false, bool smooth=false,
75  bool angleWeighted=false) const=0;
76 
78 
80  void scale(IMesh* mesh, const core::vector3df& factor) const
81  {
82  apply(SVertexPositionScaleManipulator(factor), mesh, true);
83  }
84 
86 
88  void scale(IMeshBuffer* buffer, const core::vector3df& factor) const
89  {
90  apply(SVertexPositionScaleManipulator(factor), buffer, true);
91  }
92 
94 
97  void scaleMesh(IMesh* mesh, const core::vector3df& factor) const {return scale(mesh,factor);}
98 
100 
103  void scaleTCoords(scene::IMesh* mesh, const core::vector2df& factor, u32 level=1) const
104  {
105  apply(SVertexTCoordsScaleManipulator(factor, level), mesh);
106  }
107 
109 
112  void scaleTCoords(scene::IMeshBuffer* buffer, const core::vector2df& factor, u32 level=1) const
113  {
114  apply(SVertexTCoordsScaleManipulator(factor, level), buffer);
115  }
116 
118 
120  void transform(IMesh* mesh, const core::matrix4& m) const
121  {
123  }
124 
126 
128  void transform(IMeshBuffer* buffer, const core::matrix4& m) const
129  {
130  apply(SVertexPositionTransformManipulator(m), buffer, true);
131  }
132 
134 
137  virtual void transformMesh(IMesh* mesh, const core::matrix4& m) const {return transform(mesh,m);}
138 
140 
146  virtual SMesh* createMeshCopy(IMesh* mesh) const = 0;
147 
149 
153  virtual void makePlanarTextureMapping(IMesh* mesh, f32 resolution=0.001f) const =0;
154 
156 
160  virtual void makePlanarTextureMapping(scene::IMeshBuffer* meshbuffer, f32 resolution=0.001f) const =0;
161 
163 
170  virtual void makePlanarTextureMapping(scene::IMeshBuffer* buffer, f32 resolutionS, f32 resolutionT, u8 axis, const core::vector3df& offset) const =0;
171 
173 
189  virtual IMesh* createMeshWithTangents(IMesh* mesh, bool recalculateNormals=false, bool smooth=false, bool angleWeighted=false, bool recalculateTangents=true) const = 0;
190 
192 
197  virtual IMesh* createMeshWith2TCoords(IMesh* mesh) const = 0;
198 
200 
205  virtual IMesh* createMeshWith1TCoords(IMesh* mesh) const = 0;
206 
208 
213  virtual IMesh* createMeshUniquePrimitives(IMesh* mesh) const = 0;
214 
216 
221  virtual IMesh* createMeshWelded(IMesh* mesh, f32 tolerance=core::ROUNDING_ERROR_f32) const = 0;
222 
224 
226  virtual s32 getPolyCount(IMesh* mesh) const = 0;
227 
229 
231  virtual s32 getPolyCount(IAnimatedMesh* mesh) const = 0;
232 
234 
240  virtual IAnimatedMesh * createAnimatedMesh(IMesh* mesh,
242 
244 
248  template <typename Functor>
249  bool apply(const Functor& func, IMeshBuffer* buffer, bool boundingBoxUpdate=false) const
250  {
251  return apply_(func, buffer, boundingBoxUpdate, func);
252  }
253 
254 
256 
260  template <typename Functor>
261  bool apply(const Functor& func, IMesh* mesh, bool boundingBoxUpdate=false) const
262  {
263  if (!mesh)
264  return true;
265  bool result = true;
266  core::aabbox3df bufferbox;
267  for (u32 i=0; i<mesh->getMeshBufferCount(); ++i)
268  {
269  result &= apply(func, mesh->getMeshBuffer(i), boundingBoxUpdate);
270  if (boundingBoxUpdate)
271  {
272  if (0==i)
273  bufferbox.reset(mesh->getMeshBuffer(i)->getBoundingBox());
274  else
275  bufferbox.addInternalBox(mesh->getMeshBuffer(i)->getBoundingBox());
276  }
277  }
278  if (boundingBoxUpdate)
279  mesh->setBoundingBox(bufferbox);
280  return result;
281  }
282 
283 protected:
285 
290  template <typename Functor>
291  bool apply_(const Functor& func, IMeshBuffer* buffer, bool boundingBoxUpdate, const IVertexManipulator& typeTest) const
292  {
293  if (!buffer)
294  return true;
295 
296  core::aabbox3df bufferbox;
297  for (u32 i=0; i<buffer->getVertexCount(); ++i)
298  {
299  switch (buffer->getVertexType())
300  {
301  case video::EVT_STANDARD:
302  {
303  video::S3DVertex* verts = (video::S3DVertex*)buffer->getVertices();
304  func(verts[i]);
305  }
306  break;
307  case video::EVT_2TCOORDS:
308  {
310  func(verts[i]);
311  }
312  break;
313  case video::EVT_TANGENTS:
314  {
316  func(verts[i]);
317  }
318  break;
319  }
320  if (boundingBoxUpdate)
321  {
322  if (0==i)
323  bufferbox.reset(buffer->getPosition(0));
324  else
325  bufferbox.addInternalPoint(buffer->getPosition(i));
326  }
327  }
328  if (boundingBoxUpdate)
329  buffer->setBoundingBox(bufferbox);
330  return true;
331  }
332 };
333 
334 } // end namespace scene
335 } // end namespace irr
336 
337 
338 #endif

The Irrlicht Engine
The Irrlicht Engine Documentation © 2003-2010 by Nikolaus Gebhardt. Generated on Tue Jun 5 2012 17:57:12 by Doxygen (1.8.1)