Nirtcpp 2.1.0
Nirtcpp is a high-performance c++ graphics engine.
Loading...
Searching...
No Matches
IMeshManipulator.hpp
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 nirtcpp/nirtcpp.hpp
4
5#ifndef NIRT_I_MESH_MANIPULATOR_HPP_INCLUDED
6#define NIRT_I_MESH_MANIPULATOR_HPP_INCLUDED
7
8#include <nirtcpp/core/engine/IReferenceCounted.hpp>
9#include <nirtcpp/core/engine/vector3d.hpp>
10#include <nirtcpp/core/engine/aabbox3d.hpp>
11#include <nirtcpp/core/engine/matrix4.hpp>
12#include <nirtcpp/core/engine/IAnimatedMesh.hpp>
13#include <nirtcpp/core/engine/IMeshBuffer.hpp>
14#include <nirtcpp/core/engine/SVertexManipulator.hpp>
15
16namespace nirt
17{
18namespace scene
19{
20
21 class 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
110 void scale(IMesh* mesh, const core::vector3df& factor) const
111 {
112 apply(SVertexPositionScaleManipulator(factor), mesh, true);
113 }
114
116
120 void scale(IMeshBuffer* buffer, const core::vector3df& factor) const
121 {
122 apply(SVertexPositionScaleManipulator(factor), buffer, true);
123 }
124
126
129 NIRT_DEPRECATED void scaleMesh(IMesh* mesh, const core::vector3df& factor) const {return scale(mesh,factor);}
130
132
135 void scaleTCoords(scene::IMesh* mesh, const core::vector2df& factor, u32 level=1) const
136 {
137 apply(SVertexTCoordsScaleManipulator(factor, level), mesh);
138 }
139
141
144 void scaleTCoords(scene::IMeshBuffer* buffer, const core::vector2df& factor, u32 level=1) const
145 {
146 apply(SVertexTCoordsScaleManipulator(factor, level), buffer);
147 }
148
150
158 void transform(IMesh* mesh, const core::matrix4& m, u32 normalsUpdate = 0, bool normalizeNormals=false) const
159 {
161
162 if ( normalsUpdate == 1 )
163 {
164 core::matrix4 invT;
165 if ( m.getInverse(invT) )
166 {
167 invT = invT.getTransposed();
168 apply(SVertexNormalRotateScaleManipulator(invT), mesh, false);
169 }
170 }
171 if ( normalizeNormals )
172 {
174 }
175 }
176
178
186 void transform(IMeshBuffer* buffer, const core::matrix4& m, u32 normalsUpdate = 0, bool normalizeNormals=false) const
187 {
189
190 if ( normalsUpdate == 1 )
191 {
192 core::matrix4 invT;
193 if ( m.getInverse(invT) )
194 {
195 invT = invT.getTransposed();
196 apply(SVertexNormalRotateScaleManipulator(invT), buffer, false);
197 }
198 }
199 if ( normalizeNormals )
200 {
202 }
203 }
204
206
209 NIRT_DEPRECATED virtual void transformMesh(IMesh* mesh, const core::matrix4& m) const {return transform(mesh,m);}
210
212
216 virtual void makePlanarTextureMapping(IMesh* mesh, f32 resolution=0.001f) const=0;
217
219
223 virtual void makePlanarTextureMapping(scene::IMeshBuffer* meshbuffer, f32 resolution=0.001f) const=0;
224
226
234 f32 resolutionS, f32 resolutionT,
235 u8 axis, const core::vector3df& offset) const=0;
236
238
246 f32 resolutionS, f32 resolutionT,
247 u8 axis, const core::vector3df& offset) const=0;
248
250
254 virtual SMesh* createMeshCopy(IMesh* mesh) const = 0;
255
257
275 bool recalculateNormals=false, bool smooth=false,
276 bool angleWeighted=false, bool recalculateTangents=true) const=0;
277
279
285 virtual IMesh* createMeshWith2TCoords(IMesh* mesh) const = 0;
286
288
294 virtual IMesh* createMeshWith1TCoords(IMesh* mesh) const = 0;
295
297
303 virtual IMesh* createMeshUniquePrimitives(IMesh* mesh) const = 0;
304
306
312 virtual IMesh* createMeshWelded(IMesh* mesh, f32 tolerance=core::ROUNDING_ERROR_f32) const = 0;
313
315
317 virtual s32 getPolyCount(IMesh* mesh) const = 0;
318
320
322 virtual s32 getPolyCount(IAnimatedMesh* mesh) const = 0;
323
325
333
335
343 virtual IMesh* createForsythOptimizedMesh(const IMesh *mesh) const = 0;
344
346
356 virtual void heightmapOptimizeMesh(IMesh * const mesh, const f32 tolerance = core::ROUNDING_ERROR_f32) const = 0;
357
359
369 virtual void heightmapOptimizeMesh(IMeshBuffer * const mb, const f32 tolerance = core::ROUNDING_ERROR_f32) const = 0;
370
372
376 template <typename Functor>
377 bool apply(const Functor& func, IMeshBuffer* buffer, bool boundingBoxUpdate=false) const
378 {
379 return apply_(func, buffer, boundingBoxUpdate, func);
380 }
381
382
384
388 template <typename Functor>
389 bool apply(const Functor& func, IMesh* mesh, bool boundingBoxUpdate=false) const
390 {
391 if (!mesh)
392 return true;
393 bool result = true;
394 core::aabbox3df bufferbox;
395 for (u32 i=0; i<mesh->getMeshBufferCount(); ++i)
396 {
397 result &= apply(func, mesh->getMeshBuffer(i), boundingBoxUpdate);
398 if (boundingBoxUpdate)
399 {
400 if (0==i)
401 bufferbox.reset(mesh->getMeshBuffer(i)->getBoundingBox());
402 else
403 bufferbox.addInternalBox(mesh->getMeshBuffer(i)->getBoundingBox());
404 }
405 }
406 if (boundingBoxUpdate)
407 mesh->setBoundingBox(bufferbox);
408 return result;
409 }
410
411protected:
413
418 template <typename Functor>
419 bool apply_(const Functor& func, IMeshBuffer* buffer, bool boundingBoxUpdate, const IVertexManipulator& typeTest) const
420 {
421 if (!buffer)
422 return true;
423
424 core::aabbox3df bufferbox;
425 for (u32 i=0; i<buffer->getVertexCount(); ++i)
426 {
427 switch (buffer->getVertexType())
428 {
430 {
431 video::S3DVertex* verts = (video::S3DVertex*)buffer->getVertices();
432 func(verts[i]);
433 }
434 break;
436 {
438 func(verts[i]);
439 }
440 break;
442 {
444 func(verts[i]);
445 }
446 break;
447 }
448 if (boundingBoxUpdate)
449 {
450 if (0==i)
451 bufferbox.reset(buffer->getPosition(0));
452 else
453 bufferbox.addInternalPoint(buffer->getPosition(i));
454 }
455 }
456 if (boundingBoxUpdate)
457 buffer->setBoundingBox(bufferbox);
458 return true;
459 }
460};
461
462} // end namespace scene
463} // end namespace nirt
464
465#endif
Base class of most objects of the Nirtcpp Engine.
Definition IReferenceCounted.hpp:46
4x4 matrix. Mostly used as transformation matrix for 3d calculations.
Definition matrix4.hpp:49
CMatrix4< T > getTransposed() const
Gets transposed matrix.
Definition matrix4.hpp:2036
bool getInverse(CMatrix4< T > &out) const
Gets the inverse matrix of this one.
Definition matrix4.hpp:1404
void addInternalPoint(const vector3d< T > &p)
Adds a point to the bounding box.
Definition aabbox3d.hpp:74
void addInternalBox(const aabbox3d< T > &b)
Adds another bounding box.
Definition aabbox3d.hpp:82
void reset(T x, T y, T z)
Resets the bounding box to a one-point box.
Definition aabbox3d.hpp:50
Interface for an animated mesh.
Definition IAnimatedMesh.hpp:21
Class for holding a mesh with a single material.
Definition IMeshBuffer.hpp:41
virtual u32 getVertexCount() const =0
Get amount of vertices in meshbuffer.
virtual void setBoundingBox(const core::aabbox3df &box)=0
Set axis aligned bounding box.
virtual const core::vector3df & getPosition(u32 i) const =0
returns position of vertex i
virtual const core::aabbox3df & getBoundingBox() const =0
Get the axis aligned bounding box of this meshbuffer.
virtual video::E_VERTEX_TYPE getVertexType() const =0
Get type of vertex data which is stored in this meshbuffer.
virtual const void * getVertices() const =0
Get access to vertex data. The data is an array of vertices.
An interface for easy manipulation of meshes.
Definition IMeshManipulator.hpp:30
void setVertexColorAlpha(IMeshBuffer *buffer, s32 alpha) const
Sets the alpha vertex color value of the whole mesh to a new value.
Definition IMeshManipulator.hpp:50
bool apply_(const Functor &func, IMeshBuffer *buffer, bool boundingBoxUpdate, const IVertexManipulator &typeTest) const
Apply a manipulator based on the type of the functor.
Definition IMeshManipulator.hpp:419
virtual s32 getPolyCount(IAnimatedMesh *mesh) const =0
Get amount of polygons in mesh.
void scale(IMeshBuffer *buffer, const core::vector3df &factor) const
Scales the actual meshbuffer, not a scene node.
Definition IMeshManipulator.hpp:120
virtual IMesh * createMeshWith2TCoords(IMesh *mesh) const =0
Creates a copy of the mesh, which will only consist of S3DVertex2TCoord vertices.
virtual IMesh * createMeshUniquePrimitives(IMesh *mesh) const =0
Creates a copy of a mesh with all vertices unwelded.
void transform(IMesh *mesh, const core::matrix4 &m, u32 normalsUpdate=0, bool normalizeNormals=false) const
Applies a transformation to a mesh.
Definition IMeshManipulator.hpp:158
bool apply(const Functor &func, IMeshBuffer *buffer, bool boundingBoxUpdate=false) const
Apply a manipulator on the Meshbuffer.
Definition IMeshManipulator.hpp:377
virtual void recalculateTangents(IMesh *mesh, bool recalculateNormals=false, bool smooth=false, bool angleWeighted=false) const =0
Recalculates tangents, requires a tangent mesh.
NIRT_DEPRECATED void scaleMesh(IMesh *mesh, const core::vector3df &factor) const
Scales the actual mesh, not a scene node.
Definition IMeshManipulator.hpp:129
void setVertexColors(IMesh *mesh, video::SColor color) const
Sets the colors of all vertices to one color.
Definition IMeshManipulator.hpp:58
virtual void heightmapOptimizeMesh(IMesh *const mesh, const f32 tolerance=core::ROUNDING_ERROR_f32) const =0
Optimize the mesh with an algorithm tuned for heightmaps.
void scaleTCoords(scene::IMesh *mesh, const core::vector2df &factor, u32 level=1) const
Scale the texture coords of a mesh.
Definition IMeshManipulator.hpp:135
virtual IMesh * createMeshWelded(IMesh *mesh, f32 tolerance=core::ROUNDING_ERROR_f32) const =0
Creates a copy of a mesh with vertices welded.
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.
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.
virtual void recalculateTangents(IMeshBuffer *buffer, bool recalculateNormals=false, bool smooth=false, bool angleWeighted=false) const =0
Recalculates tangents, requires a tangent mesh buffer.
void setVertexColorAlpha(IMesh *mesh, s32 alpha) const
Sets the alpha vertex color value of the whole mesh to a new value.
Definition IMeshManipulator.hpp:42
virtual void makePlanarTextureMapping(scene::IMeshBuffer *meshbuffer, f32 resolution=0.001f) const =0
Creates a planar texture mapping on the meshbuffer.
void scaleTCoords(scene::IMeshBuffer *buffer, const core::vector2df &factor, u32 level=1) const
Scale the texture coords of a meshbuffer.
Definition IMeshManipulator.hpp:144
virtual NIRT_DEPRECATED void transformMesh(IMesh *mesh, const core::matrix4 &m) const
Applies a transformation to a mesh.
Definition IMeshManipulator.hpp:209
void setVertexColors(IMeshBuffer *buffer, video::SColor color) const
Sets the colors of all vertices to one color.
Definition IMeshManipulator.hpp:66
virtual void recalculateNormals(IMesh *mesh, bool smooth=false, bool angleWeighted=false) const =0
Recalculates all normals of the mesh.
virtual void flipSurfaces(IMesh *mesh) const =0
Flips the direction of surfaces.
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.
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.
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.
bool apply(const Functor &func, IMesh *mesh, bool boundingBoxUpdate=false) const
Apply a manipulator on the Mesh.
Definition IMeshManipulator.hpp:389
void transform(IMeshBuffer *buffer, const core::matrix4 &m, u32 normalsUpdate=0, bool normalizeNormals=false) const
Applies a transformation to a meshbuffer.
Definition IMeshManipulator.hpp:186
void scale(IMesh *mesh, const core::vector3df &factor) const
Scales the actual mesh, not a scene node.
Definition IMeshManipulator.hpp:110
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.
virtual void heightmapOptimizeMesh(IMeshBuffer *const mb, const f32 tolerance=core::ROUNDING_ERROR_f32) const =0
Optimize the meshbuffer with an algorithm tuned for heightmaps.
virtual void makePlanarTextureMapping(IMesh *mesh, f32 resolution=0.001f) const =0
Creates a planar texture mapping on the mesh.
virtual IMesh * createMeshWith1TCoords(IMesh *mesh) const =0
Creates a copy of the mesh, which will only consist of S3DVertex vertices.
Class which holds the geometry of an object.
Definition IMesh.hpp:72
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.
Interface for vertex manipulators.
Definition SVertexManipulator.hpp:25
Simple implementation of the IMesh interface.
Definition SMesh.hpp:19
Vertex manipulator to set the alpha value of the vertex color to a fixed value.
Definition SVertexManipulator.hpp:41
Vertex manipulator to set color to a fixed color for all vertices.
Definition SVertexManipulator.hpp:29
Vertex manipulator which transforms the normal of the vertex with the rotate/scale part of the given ...
Definition SVertexManipulator.hpp:282
Vertex manipulator which normalizes the normal of the vertex.
Definition SVertexManipulator.hpp:296
Vertex manipulator which scales the position of the vertex.
Definition SVertexManipulator.hpp:223
Vertex manipulator which transforms the position of the vertex.
Definition SVertexManipulator.hpp:254
Vertex manipulator which scales the TCoords of the vertex.
Definition SVertexManipulator.hpp:308
Vertex with two texture coordinates.
Definition S3DVertex.hpp:116
Vertex with a tangent and binormal vector.
Definition S3DVertex.hpp:199
standard vertex used by the Nirtcpp engine.
Definition S3DVertex.hpp:45
Class representing a 32 bit ARGB color.
Definition SColor.hpp:317
E_ANIMATED_MESH_TYPE
Possible types of meshes.
Definition IMesh.hpp:20
@ EAMT_UNKNOWN
Unknown animated mesh type.
Definition IMesh.hpp:22
@ EVT_2TCOORDS
Vertex with two texture coordinates, video::S3DVertex2TCoords.
Definition S3DVertex.hpp:25
@ EVT_STANDARD
Standard vertex type used by the Nirtcpp engine, video::S3DVertex.
Definition S3DVertex.hpp:21
@ EVT_TANGENTS
Vertex with a tangent and binormal vector, video::S3DVertexTangents.
Definition S3DVertex.hpp:31
As of Nirtcpp 1.6, position2d is a synonym for vector2d.
Definition vector3d.hpp:11
signed int s32
32 bit signed variable.
Definition irrTypes.hpp:72
unsigned char u8
8 bit unsigned variable.
Definition irrTypes.hpp:24
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.hpp:64
float f32
32 bit floating point variable.
Definition irrTypes.hpp:110

Nirtcpp    @cppfx.xyz

Esvcpp    esv::print