arsa  2.7
IMeshManipulator.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 __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 
51  {
53  }
54 
56 
59  {
61  }
62 
64 
67  {
69  }
70 
72 
75  virtual void recalculateNormals(IMesh* mesh, bool smooth = false,
76  bool angleWeighted = false) const=0;
77 
79 
83  bool smooth = false, bool angleWeighted = false) const=0;
84 
86 
91  virtual void recalculateTangents(IMesh* mesh,
92  bool recalculateNormals=false, bool smooth=false,
93  bool angleWeighted=false) const=0;
94 
96 
101  virtual void recalculateTangents(IMeshBuffer* buffer,
102  bool recalculateNormals=false, bool smooth=false,
103  bool angleWeighted=false) const=0;
104 
106 
108  void scale(IMesh* mesh, const core::vector3df& factor) const
109  {
110  apply(SVertexPositionScaleManipulator(factor), mesh, true);
111  }
112 
114 
116  void scale(IMeshBuffer* buffer, const core::vector3df& factor) const
117  {
119  }
120 
122 
125  _IRR_DEPRECATED_ void scaleMesh(IMesh* mesh, const core::vector3df& factor) const {return scale(mesh,factor);}
126 
128 
131  void scaleTCoords(scene::IMesh* mesh, const core::vector2df& factor, u32 level=1) const
132  {
134  }
135 
137 
141  {
143  }
144 
146 
151  void transform(IMesh* mesh, const core::matrix4& m, u32 normalsUpdate = 0) const
152  {
154 
155  if ( normalsUpdate == 1 )
156  {
157  core::matrix4 invT;
158  if ( m.getInverse(invT) )
159  {
160  invT = invT.getTransposed();
161  apply(SVertexNormalTransformManipulator(invT), mesh, false);
162  }
163  }
164  }
165 
167 
172  void transform(IMeshBuffer* buffer, const core::matrix4& m, u32 normalsUpdate = 0) const
173  {
175 
176  if ( normalsUpdate == 1 )
177  {
178  core::matrix4 invT;
179  if ( m.getInverse(invT) )
180  {
181  invT = invT.getTransposed();
183  }
184  }
185  }
186 
188 
191  _IRR_DEPRECATED_ virtual void transformMesh(IMesh* mesh, const core::matrix4& m) const {return transform(mesh,m);}
192 
194 
198  virtual void makePlanarTextureMapping(IMesh* mesh, f32 resolution=0.001f) const=0;
199 
201 
205  virtual void makePlanarTextureMapping(scene::IMeshBuffer* meshbuffer, f32 resolution=0.001f) const=0;
206 
208 
215  virtual void makePlanarTextureMapping(scene::IMesh* mesh,
216  f32 resolutionS, f32 resolutionT,
217  u8 axis, const core::vector3df& offset) const=0;
218 
220 
228  f32 resolutionS, f32 resolutionT,
229  u8 axis, const core::vector3df& offset) const=0;
230 
232 
238  virtual SMesh* createMeshCopy(IMesh* mesh) const = 0;
239 
241 
257  virtual IMesh* createMeshWithTangents(IMesh* mesh,
258  bool recalculateNormals=false, bool smooth=false,
259  bool angleWeighted=false, bool recalculateTangents=true) const=0;
260 
262 
267  virtual IMesh* createMeshWith2TCoords(IMesh* mesh) const = 0;
268 
270 
275  virtual IMesh* createMeshWith1TCoords(IMesh* mesh) const = 0;
276 
278 
283  virtual IMesh* createMeshUniquePrimitives(IMesh* mesh) const = 0;
284 
286 
291  virtual IMesh* createMeshWelded(IMesh* mesh, f32 tolerance=core::ROUNDING_ERROR_f32) const = 0;
292 
294 
296  virtual s32 getPolyCount(IMesh* mesh) const = 0;
297 
299 
301  virtual s32 getPolyCount(IAnimatedMesh* mesh) const = 0;
302 
304 
310  virtual IAnimatedMesh * createAnimatedMesh(IMesh* mesh,
312 
314 
322  virtual IMesh* createForsythOptimizedMesh(const IMesh *mesh) const = 0;
323 
325 
335  virtual void heightmapOptimizeMesh(IMesh * const mesh, const f32 tolerance = core::ROUNDING_ERROR_f32) const = 0;
336 
338 
348  virtual void heightmapOptimizeMesh(IMeshBuffer * const mb, const f32 tolerance = core::ROUNDING_ERROR_f32) const = 0;
349 
351 
355  template <typename Functor>
356  bool apply(const Functor& func, IMeshBuffer* buffer, bool boundingBoxUpdate=false) const
357  {
358  return apply_(func, buffer, boundingBoxUpdate, func);
359  }
360 
361 
363 
367  template <typename Functor>
368  bool apply(const Functor& func, IMesh* mesh, bool boundingBoxUpdate=false) const
369  {
370  if (!mesh)
371  return true;
372  bool result = true;
373  core::aabbox3df bufferbox;
374  for (u32 i=0; i<mesh->getMeshBufferCount(); ++i)
375  {
376  result &= apply(func, mesh->getMeshBuffer(i), boundingBoxUpdate);
377  if (boundingBoxUpdate)
378  {
379  if (0==i)
380  bufferbox.reset(mesh->getMeshBuffer(i)->getBoundingBox());
381  else
382  bufferbox.addInternalBox(mesh->getMeshBuffer(i)->getBoundingBox());
383  }
384  }
385  if (boundingBoxUpdate)
386  mesh->setBoundingBox(bufferbox);
387  return result;
388  }
389 
390 protected:
392 
397  template <typename Functor>
398  bool apply_(const Functor& func, IMeshBuffer* buffer, bool boundingBoxUpdate, const IVertexManipulator& typeTest) const
399  {
400  if (!buffer)
401  return true;
402 
403  core::aabbox3df bufferbox;
404  for (u32 i=0; i<buffer->getVertexCount(); ++i)
405  {
406  switch (buffer->getVertexType())
407  {
408  case video::EVT_STANDARD:
409  {
410  video::S3DVertex* verts = (video::S3DVertex*)buffer->getVertices();
411  func(verts[i]);
412  }
413  break;
414  case video::EVT_2TCOORDS:
415  {
416  video::S3DVertex2TCoords* verts = (video::S3DVertex2TCoords*)buffer->getVertices();
417  func(verts[i]);
418  }
419  break;
420  case video::EVT_TANGENTS:
421  {
422  video::S3DVertexTangents* verts = (video::S3DVertexTangents*)buffer->getVertices();
423  func(verts[i]);
424  }
425  break;
426  }
427  if (boundingBoxUpdate)
428  {
429  if (0==i)
430  bufferbox.reset(buffer->getPosition(0));
431  else
432  bufferbox.addInternalPoint(buffer->getPosition(i));
433  }
434  }
435  if (boundingBoxUpdate)
436  buffer->setBoundingBox(bufferbox);
437  return true;
438  }
439 };
440 
441 } // end namespace scene
442 } // end namespace irr
443 
444 
445 #endif
virtual IMesh * createMeshWith2TCoords(IMesh *mesh) const =0
Creates a copy of the mesh, which will only consist of S3DVertex2TCoord vertices.
#define _IRR_DEPRECATED_
Defines a deprecated macro which generates a warning at compile time.
Definition: irrTypes.h:202
GLuint64EXT * result
virtual void flipSurfaces(IMesh *mesh) const =0
Flips the direction of surfaces.
virtual const core::aabbox3df & getBoundingBox() const =0
Get the axis aligned bounding box of this meshbuffer.
CMatrix4< T > getTransposed() const
Gets transposed matrix.
Definition: matrix4.h:2004
float f32
32 bit floating point variable.
Definition: irrTypes.h:108
GLint level
Definition: SDL_opengl.h:1572
const GLfloat * m
E_ANIMATED_MESH_TYPE
Possible types of meshes.
Definition: IMesh.h:19
Unknown animated mesh type.
Definition: IMesh.h:22
void transform(IMeshBuffer *buffer, const core::matrix4 &m, u32 normalsUpdate=0) const
Applies a transformation to a meshbuffer.
virtual s32 getPolyCount(IMesh *mesh) const =0
Get amount of polygons in mesh.
Everything in the Irrlicht Engine can be found in this namespace.
Definition: CARSADPad.h:6
Simple implementation of the IMesh interface.
Definition: SMesh.h:18
virtual void recalculateTangents(IMesh *mesh, bool recalculateNormals=false, bool smooth=false, bool angleWeighted=false) const =0
Recalculates tangents, requires a tangent mesh.
Vertex manipulator which scales the position of the vertex.
Vertex with two texture coordinates, video::S3DVertex2TCoords.
Definition: S3DVertex.h:25
GLfloat GLfloat GLfloat alpha
void reset(T x, T y, T z)
Resets the bounding box to a one-point box.
Definition: aabbox3d.h:50
void scale(IMeshBuffer *buffer, const core::vector3df &factor) const
Scales the actual meshbuffer, not a scene node.
virtual IMeshBuffer * getMeshBuffer(u32 nr) const =0
Get pointer to a mesh buffer.
Class which holds the geometry of an object.
Definition: IMesh.h:71
unsigned char u8
8 bit unsigned variable.
Definition: irrTypes.h:22
virtual void makePlanarTextureMapping(IMesh *mesh, f32 resolution=0.001f) const =0
Creates a planar texture mapping on the mesh.
const f32 ROUNDING_ERROR_f32
Definition: irrMath.h:50
Vertex with two texture coordinates.
Definition: S3DVertex.h:112
virtual u32 getMeshBufferCount() const =0
Get the amount of mesh buffers.
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
Vertex with a tangent and binormal vector, video::S3DVertexTangents.
Definition: S3DVertex.h:31
bool apply(const Functor &func, IMeshBuffer *buffer, bool boundingBoxUpdate=false) const
Apply a manipulator on the Meshbuffer.
void setVertexColorAlpha(IMeshBuffer *buffer, s32 alpha) const
Sets the alpha vertex color value of the whole mesh to a new value.
virtual IMesh * createMeshWith1TCoords(IMesh *mesh) const =0
Creates a copy of the mesh, which will only consist of S3DVertex vertices.
Vertex manipulator which transforms the position of the vertex.
GLfloat f
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
Standard vertex type used by the Irrlicht engine, video::S3DVertex.
Definition: S3DVertex.h:21
Interface for vertex manipulators.
virtual _IRR_DEPRECATED_ void transformMesh(IMesh *mesh, const core::matrix4 &m) const
Applies a transformation to a mesh.
bool apply_(const Functor &func, IMeshBuffer *buffer, bool boundingBoxUpdate, const IVertexManipulator &typeTest) const
Apply a manipulator based on the type of the functor.
Vertex manipulator to set the alpha value of the vertex color to a fixed value.
virtual void recalculateNormals(IMesh *mesh, bool smooth=false, bool angleWeighted=false) const =0
Recalculates all normals of the mesh.
virtual IMesh * createMeshWelded(IMesh *mesh, f32 tolerance=core::ROUNDING_ERROR_f32) const =0
Creates a copy of a mesh with vertices welded.
standard vertex used by the Irrlicht engine.
Definition: S3DVertex.h:44
virtual void setBoundingBox(const core::aabbox3df &box)=0
Set user-defined axis aligned bounding box.
bool apply(const Functor &func, IMesh *mesh, bool boundingBoxUpdate=false) const
Apply a manipulator on the Mesh.
void transform(IMesh *mesh, const core::matrix4 &m, u32 normalsUpdate=0) const
Applies a transformation to a mesh.
virtual IAnimatedMesh * createAnimatedMesh(IMesh *mesh, scene::E_ANIMATED_MESH_TYPE type=scene::EAMT_UNKNOWN) const =0
Create a new AnimatedMesh and adds the mesh to it.
void setVertexColorAlpha(IMesh *mesh, s32 alpha) const
Sets the alpha vertex color value of the whole mesh to a new value.
virtual IMesh * createMeshUniquePrimitives(IMesh *mesh) const =0
Creates a copy of a mesh with all vertices unwelded.
Vertex manipulator which scales the TCoords of the vertex.
Class representing a 32 bit ARGB color.
Definition: SColor.h:316
4x4 matrix. Mostly used as transformation matrix for 3d calculations.
Definition: matrix4.h:45
GLintptr offset
void setVertexColors(IMeshBuffer *buffer, video::SColor color) const
Sets the colors of all vertices to one color.
void addInternalPoint(const vector3d< T > &p)
Adds a point to the bounding box.
Definition: aabbox3d.h:74
GLenum func
void scale(IMesh *mesh, const core::vector3df &factor) const
Scales the actual mesh, not a scene node.
_IRR_DEPRECATED_ void scaleMesh(IMesh *mesh, const core::vector3df &factor) const
Scales the actual mesh, not a scene node.
void scaleTCoords(scene::IMeshBuffer *buffer, const core::vector2df &factor, u32 level=1) const
Scale the texture coords of a meshbuffer.
GLuint color
void setVertexColors(IMesh *mesh, video::SColor color) const
Sets the colors of all vertices to one color.
GLuint buffer
Base class of most objects of the Irrlicht Engine.
GLuint GLuint GLsizei GLenum type
Definition: SDL_opengl.h:1571
Vertex manipulator to set color to a fixed color for all vertices.
Interface for an animated mesh.
Definition: IAnimatedMesh.h:20
virtual IMesh * createMeshWithTangents(IMesh *mesh, bool recalculateNormals=false, bool smooth=false, bool angleWeighted=false, bool recalculateTangents=true) const =0
Creates a copy of the mesh, which will only consist of S3DVertexTangents vertices.
An interface for easy manipulation of meshes.
void scaleTCoords(scene::IMesh *mesh, const core::vector2df &factor, u32 level=1) const
Scale the texture coords of a mesh.
virtual void heightmapOptimizeMesh(IMesh *const mesh, const f32 tolerance=core::ROUNDING_ERROR_f32) const =0
Optimize the mesh with an algorithm tuned for heightmaps.
Vertex with a tangent and binormal vector.
Definition: S3DVertex.h:192
virtual SMesh * createMeshCopy(IMesh *mesh) const =0
Clones a static IMesh into a modifiable SMesh.
virtual IMesh * createForsythOptimizedMesh(const IMesh *mesh) const =0
Vertex cache optimization according to the Forsyth paper.
Vertex manipulator which transforms the normal of the vertex.