Irrlicht 3D Engine
 
Loading...
Searching...
No Matches
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
16namespace irr
17{
18namespace 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 setVertexColorAlpha(IMeshBuffer* buffer, s32 alpha) const
51 {
53 }
54
56
58 void setVertexColors(IMesh* mesh, video::SColor color) const
59 {
61 }
62
64
66 void setVertexColors(IMeshBuffer* buffer, video::SColor color) const
67 {
69 }
70
72
75 virtual void recalculateNormals(IMesh* mesh, bool smooth = false,
76 bool angleWeighted = false) const=0;
77
79
82 virtual void recalculateNormals(IMeshBuffer* buffer,
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 {
118 apply(SVertexPositionScaleManipulator(factor), buffer, true);
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 {
133 apply(SVertexTCoordsScaleManipulator(factor, level), mesh);
134 }
135
137
140 void scaleTCoords(scene::IMeshBuffer* buffer, const core::vector2df& factor, u32 level=1) const
141 {
142 apply(SVertexTCoordsScaleManipulator(factor, level), buffer);
143 }
144
146
148 void transform(IMesh* mesh, const core::matrix4& m) const
149 {
151 }
152
154
156 void transform(IMeshBuffer* buffer, const core::matrix4& m) const
157 {
159 }
160
162
165 _IRR_DEPRECATED_ virtual void transformMesh(IMesh* mesh, const core::matrix4& m) const {return transform(mesh,m);}
166
168
172 virtual void makePlanarTextureMapping(IMesh* mesh, f32 resolution=0.001f) const=0;
173
175
179 virtual void makePlanarTextureMapping(scene::IMeshBuffer* meshbuffer, f32 resolution=0.001f) const=0;
180
182
190 f32 resolutionS, f32 resolutionT,
191 u8 axis, const core::vector3df& offset) const=0;
192
194
202 f32 resolutionS, f32 resolutionT,
203 u8 axis, const core::vector3df& offset) const=0;
204
206
212 virtual SMesh* createMeshCopy(IMesh* mesh) const = 0;
213
215
232 bool recalculateNormals=false, bool smooth=false,
233 bool angleWeighted=false, bool recalculateTangents=true) const=0;
234
236
241 virtual IMesh* createMeshWith2TCoords(IMesh* mesh) const = 0;
242
244
249 virtual IMesh* createMeshWith1TCoords(IMesh* mesh) const = 0;
250
252
257 virtual IMesh* createMeshUniquePrimitives(IMesh* mesh) const = 0;
258
260
265 virtual IMesh* createMeshWelded(IMesh* mesh, f32 tolerance=core::ROUNDING_ERROR_f32) const = 0;
266
268
270 virtual s32 getPolyCount(IMesh* mesh) const = 0;
271
273
275 virtual s32 getPolyCount(IAnimatedMesh* mesh) const = 0;
276
278
286
288
296 virtual IMesh* createForsythOptimizedMesh(const IMesh *mesh) const = 0;
297
299
303 template <typename Functor>
304 bool apply(const Functor& func, IMeshBuffer* buffer, bool boundingBoxUpdate=false) const
305 {
306 return apply_(func, buffer, boundingBoxUpdate, func);
307 }
308
309
311
315 template <typename Functor>
316 bool apply(const Functor& func, IMesh* mesh, bool boundingBoxUpdate=false) const
317 {
318 if (!mesh)
319 return true;
320 bool result = true;
321 core::aabbox3df bufferbox;
322 for (u32 i=0; i<mesh->getMeshBufferCount(); ++i)
323 {
324 result &= apply(func, mesh->getMeshBuffer(i), boundingBoxUpdate);
325 if (boundingBoxUpdate)
326 {
327 if (0==i)
328 bufferbox.reset(mesh->getMeshBuffer(i)->getBoundingBox());
329 else
330 bufferbox.addInternalBox(mesh->getMeshBuffer(i)->getBoundingBox());
331 }
332 }
333 if (boundingBoxUpdate)
334 mesh->setBoundingBox(bufferbox);
335 return result;
336 }
337
338protected:
340
345 template <typename Functor>
346 bool apply_(const Functor& func, IMeshBuffer* buffer, bool boundingBoxUpdate, const IVertexManipulator& typeTest) const
347 {
348 if (!buffer)
349 return true;
350
351 core::aabbox3df bufferbox;
352 for (u32 i=0; i<buffer->getVertexCount(); ++i)
353 {
354 switch (buffer->getVertexType())
355 {
357 {
358 video::S3DVertex* verts = (video::S3DVertex*)buffer->getVertices();
359 func(verts[i]);
360 }
361 break;
363 {
365 func(verts[i]);
366 }
367 break;
369 {
371 func(verts[i]);
372 }
373 break;
374 }
375 if (boundingBoxUpdate)
376 {
377 if (0==i)
378 bufferbox.reset(buffer->getPosition(0));
379 else
380 bufferbox.addInternalPoint(buffer->getPosition(i));
381 }
382 }
383 if (boundingBoxUpdate)
384 buffer->setBoundingBox(bufferbox);
385 return true;
386 }
387};
388
389} // end namespace scene
390} // end namespace irr
391
392
393#endif
Base class of most objects of the Irrlicht Engine.
4x4 matrix. Mostly used as transformation matrix for 3d calculations.
Definition matrix4.h:46
void addInternalPoint(const vector3d< T > &p)
Adds a point to the bounding box.
Definition aabbox3d.h:74
void addInternalBox(const aabbox3d< T > &b)
Adds another bounding box.
Definition aabbox3d.h:82
void reset(T x, T y, T z)
Resets the bounding box to a one-point box.
Definition aabbox3d.h:50
Interface for an animated mesh.
Struct for holding a mesh with a single material.
Definition IMeshBuffer.h:40
virtual const core::vector3df & getPosition(u32 i) const =0
returns position of vertex i
virtual video::E_VERTEX_TYPE getVertexType() const =0
Get type of vertex data which is stored in this meshbuffer.
virtual u32 getVertexCount() const =0
Get amount of vertices in meshbuffer.
virtual const void * getVertices() const =0
Get access to vertex data. The data is an array of vertices.
virtual const core::aabbox3df & getBoundingBox() const =0
Get the axis aligned bounding box of this meshbuffer.
virtual void setBoundingBox(const core::aabbox3df &box)=0
Set axis aligned bounding box.
Class which holds the geometry of an object.
Definition IMesh.h:24
virtual void setBoundingBox(const core::aabbox3df &box)=0
Set user-defined axis aligned bounding box.
virtual u32 getMeshBufferCount() const =0
Get the amount of mesh buffers.
virtual IMeshBuffer * getMeshBuffer(u32 nr) const =0
Get pointer to a mesh buffer.
An interface for easy manipulation of meshes.
_IRR_DEPRECATED_ void scaleMesh(IMesh *mesh, const core::vector3df &factor) const
Scales the actual mesh, not a scene node.
virtual IMesh * createMeshWelded(IMesh *mesh, f32 tolerance=core::ROUNDING_ERROR_f32) const =0
Creates a copy of a mesh with vertices welded.
virtual void recalculateTangents(IMesh *mesh, bool recalculateNormals=false, bool smooth=false, bool angleWeighted=false) const =0
Recalculates tangents, requires a tangent mesh.
virtual _IRR_DEPRECATED_ void transformMesh(IMesh *mesh, const core::matrix4 &m) const
Applies a transformation to a mesh.
void transform(IMeshBuffer *buffer, const core::matrix4 &m) const
Applies a transformation to a meshbuffer.
virtual IMesh * createMeshUniquePrimitives(IMesh *mesh) const =0
Creates a copy of a mesh with all vertices unwelded.
virtual void makePlanarTextureMapping(scene::IMeshBuffer *buffer, f32 resolutionS, f32 resolutionT, u8 axis, const core::vector3df &offset) const =0
Creates a planar texture mapping on the meshbuffer.
void scaleTCoords(scene::IMesh *mesh, const core::vector2df &factor, u32 level=1) const
Scale the texture coords of a mesh.
bool apply(const Functor &func, IMesh *mesh, bool boundingBoxUpdate=false) const
Apply a manipulator on the Mesh.
void scale(IMeshBuffer *buffer, const core::vector3df &factor) const
Scales the actual meshbuffer, not a scene node.
virtual void recalculateTangents(IMeshBuffer *buffer, bool recalculateNormals=false, bool smooth=false, bool angleWeighted=false) const =0
Recalculates tangents, requires a tangent mesh buffer.
bool apply(const Functor &func, IMeshBuffer *buffer, bool boundingBoxUpdate=false) const
Apply a manipulator on the Meshbuffer.
virtual void flipSurfaces(IMesh *mesh) const =0
Flips the direction of surfaces.
void setVertexColors(IMesh *mesh, video::SColor color) const
Sets the colors of all vertices to one color.
virtual void makePlanarTextureMapping(scene::IMeshBuffer *meshbuffer, f32 resolution=0.001f) const =0
Creates a planar texture mapping on the meshbuffer.
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.
bool apply_(const Functor &func, IMeshBuffer *buffer, bool boundingBoxUpdate, const IVertexManipulator &typeTest) const
Apply a manipulator based on the type of the functor.
virtual void makePlanarTextureMapping(IMesh *mesh, f32 resolution=0.001f) const =0
Creates a planar texture mapping on the mesh.
virtual void recalculateNormals(IMesh *mesh, bool smooth=false, bool angleWeighted=false) const =0
Recalculates all normals of the mesh.
virtual SMesh * createMeshCopy(IMesh *mesh) const =0
Clones a static IMesh into a modifiable SMesh.
virtual s32 getPolyCount(IMesh *mesh) const =0
Get amount of polygons in mesh.
virtual void recalculateNormals(IMeshBuffer *buffer, bool smooth=false, bool angleWeighted=false) const =0
Recalculates all normals of the mesh buffer.
void setVertexColorAlpha(IMesh *mesh, s32 alpha) const
Sets the alpha vertex color value of the whole mesh to a new value.
void transform(IMesh *mesh, const core::matrix4 &m) const
Applies a transformation to a mesh.
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.
void setVertexColors(IMeshBuffer *buffer, video::SColor color) const
Sets the colors of all vertices to one color.
virtual void makePlanarTextureMapping(scene::IMesh *mesh, f32 resolutionS, f32 resolutionT, u8 axis, const core::vector3df &offset) const =0
Creates a planar texture mapping on the buffer.
void scale(IMesh *mesh, const core::vector3df &factor) const
Scales the actual mesh, not a scene node.
virtual IMesh * createMeshWith2TCoords(IMesh *mesh) const =0
Creates a copy of the mesh, which will only consist of S3DVertex2TCoord vertices.
void scaleTCoords(scene::IMeshBuffer *buffer, const core::vector2df &factor, u32 level=1) const
Scale the texture coords of a meshbuffer.
virtual IMesh * createForsythOptimizedMesh(const IMesh *mesh) const =0
Vertex cache optimization according to the Forsyth paper.
virtual s32 getPolyCount(IAnimatedMesh *mesh) const =0
Get amount of polygons in mesh.
virtual IMesh * createMeshWith1TCoords(IMesh *mesh) const =0
Creates a copy of the mesh, which will only consist of S3DVertex vertices.
void setVertexColorAlpha(IMeshBuffer *buffer, s32 alpha) const
Sets the alpha vertex color value of the whole mesh to a new value.
Vertex manipulator to set the alpha value of the vertex color to a fixed value.
Vertex manipulator to set color to a fixed color for all vertices.
Vertex manipulator which scales the position of the vertex.
Vertex manipulator which transforms the position of the vertex.
Vertex manipulator which scales the TCoords of the vertex.
Class representing a 32 bit ARGB color.
Definition SColor.h:202
#define _IRR_DEPRECATED_
Defines a deprecated macro which generates a warning at compile time.
Definition irrTypes.h:195
const f32 ROUNDING_ERROR_f32
Definition irrMath.h:49
E_ANIMATED_MESH_TYPE
Possible types of (animated) meshes.
@ EAMT_UNKNOWN
Unknown animated mesh type.
@ EVT_2TCOORDS
Vertex with two texture coordinates, video::S3DVertex2TCoords.
Definition S3DVertex.h:25
@ EVT_TANGENTS
Vertex with a tangent and binormal vector, video::S3DVertexTangents.
Definition S3DVertex.h:29
@ EVT_STANDARD
Standard vertex type used by the Irrlicht engine, video::S3DVertex.
Definition S3DVertex.h:21
Everything in the Irrlicht Engine can be found in this namespace.
Definition aabbox3d.h:13
float f32
32 bit floating point variable.
Definition irrTypes.h:104
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.h:58
unsigned char u8
8 bit unsigned variable.
Definition irrTypes.h:18
signed int s32
32 bit signed variable.
Definition irrTypes.h:66
Interface for vertex manipulators.
Simple implementation of the IMesh interface.
Definition SMesh.h:19
Vertex with two texture coordinates.
Definition S3DVertex.h:110
standard vertex used by the Irrlicht engine.
Definition S3DVertex.h:43
Vertex with a tangent and binormal vector.
Definition S3DVertex.h:188