Skylicht Engine
Loading...
Searching...
No Matches
IMeshManipulator.h
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 "CMeshBuffer.h"
13#include "SMesh.h"
14
15namespace irr
16{
17namespace scene
18{
20
25 class IMeshManipulator : public virtual IReferenceCounted
26 {
27 public:
28
30
33 virtual void flipSurfaces(IMesh* mesh) const = 0;
34
36
38 virtual void setVertexColorAlpha(IMeshBuffer* meshBuffer, s32 alpha) const = 0;
39
41
43 void setVertexColorAlpha(IMesh* mesh, s32 alpha) const
44 {
45 for(u32 i = 0; i < mesh->getMeshBufferCount(); ++i)
46 setVertexColorAlpha(mesh->getMeshBuffer(i), alpha);
47 }
48
50
52 virtual void setVertexColors(IMeshBuffer* meshBuffer, video::SColor color) const = 0;
53
55
57 void setVertexColors(IMesh* mesh, video::SColor color) const
58 {
59 for(u32 i = 0; i < mesh->getMeshBufferCount(); ++i)
60 setVertexColors(mesh->getMeshBuffer(i), color);
61 }
62
64
66 virtual void scale(IMeshBuffer* meshBuffer, const core::vector3df& factor) const = 0;
67
69
71 void scale(IMesh* mesh, const core::vector3df& factor) const
72 {
73 core::aabbox3df BufferBox;
74
75 for(u32 i = 0; i < mesh->getMeshBufferCount(); ++i)
76 {
77 scale(mesh->getMeshBuffer(i), factor);
78
79 if (0 == i)
80 BufferBox.reset(mesh->getMeshBuffer(i)->getBoundingBox());
81 else
82 BufferBox.addInternalBox(mesh->getMeshBuffer(i)->getBoundingBox());
83 }
84
85 mesh->setBoundingBox(BufferBox);
86 }
87
89
92 _IRR_DEPRECATED_ void scaleMesh(IMesh* mesh, const core::vector3df& factor) const {return scale(mesh,factor);}
93
95
98 virtual void scaleTCoords(IMeshBuffer* meshBuffer, const core::vector2df& factor, u32 level = 0) const = 0;
99
101
104 void scaleTCoords(scene::IMesh* mesh, const core::vector2df& factor, u32 level=0) const
105 {
106 for(u32 i = 0; i < mesh->getMeshBufferCount(); ++i)
107 scaleTCoords(mesh->getMeshBuffer(i), factor, level);
108 }
109
111
113 virtual void transform(IMeshBuffer* meshBuffer, const core::matrix4& mat) const = 0;
114
116
118 void transform(IMesh* mesh, const core::matrix4& m) const
119 {
120 core::aabbox3df BufferBox;
121
122 for(u32 i = 0; i < mesh->getMeshBufferCount(); ++i)
123 {
124 transform(mesh->getMeshBuffer(i), m);
125
126 if (0 == i)
127 BufferBox.reset(mesh->getMeshBuffer(i)->getBoundingBox());
128 else
129 BufferBox.addInternalBox(mesh->getMeshBuffer(i)->getBoundingBox());
130 }
131
132 mesh->setBoundingBox(BufferBox);
133 }
134
136
139 _IRR_DEPRECATED_ virtual void transformMesh(IMesh* mesh, const core::matrix4& m) const {return transform(mesh,m);}
140
142
145 virtual void recalculateNormals(IMeshBuffer* meshBuffer, bool smooth = false, bool angleWeighted = false) const = 0;
146
148
151 void recalculateNormals(IMesh* mesh, bool smooth = false, bool angleWeighted = false) const
152 {
153 for(u32 i = 0; i < mesh->getMeshBufferCount(); ++i)
154 recalculateNormals(mesh->getMeshBuffer(i), smooth, angleWeighted);
155 }
156
157 virtual void recalculateTangents(IMeshBuffer* meshBuffer, bool recalculateNormals = false, bool smooth = false, bool angleWeighted = false) const = 0;
158
159 void recalculateTangents(IMesh* mesh, bool recNormals = false, bool smooth = false, bool angleWeighted = false) const
160 {
161 for(u32 i = 0; i < mesh->getMeshBufferCount(); ++i)
162 recalculateTangents(mesh->getMeshBuffer(i), recNormals, smooth, angleWeighted);
163 }
164
166
170 virtual void makePlanarTextureMapping(IMeshBuffer* meshBuffer, f32 resolution = 0.001f) const = 0;
171
173
177 void makePlanarTextureMapping(IMesh* mesh, f32 resolution=0.001f) const
178 {
179 for(u32 i = 0; i < mesh->getMeshBufferCount(); ++i)
180 makePlanarTextureMapping(mesh->getMeshBuffer(i), resolution);
181 }
182
184
191 virtual void makePlanarTextureMapping(IMeshBuffer* meshBuffer, f32 resolutionS, f32 resolutionT, u8 axis, const core::vector3df& offset) const = 0;
192
194
202 f32 resolutionS, f32 resolutionT,
203 u8 axis, const core::vector3df& offset) const
204 {
205 for(u32 i = 0; i < mesh->getMeshBufferCount(); ++i)
206 makePlanarTextureMapping(mesh->getMeshBuffer(i), resolutionS, resolutionT, axis, offset);
207 }
208
209 virtual bool copyIndices(IIndexBuffer* srcBuffer, IIndexBuffer* dstBuffer) const = 0;
210
211 virtual bool copyVertices(IVertexBuffer* srcBuffer, u32 srcDescriptionBufferID, video::IVertexDescriptor* srcDescriptor,
212 IVertexBuffer* dstBuffer, u32 dstDescriptionBufferID, video::IVertexDescriptor* dstDescriptor, bool copyCustomAttribute) const = 0;
213
214 virtual bool createTangents(IMeshBuffer* srcBuffer, IMeshBuffer* dstBuffer, bool copyCustomAttribute,
215 bool recalculateNormals = false, bool smooth = false, bool angleWeighted= false) = 0;
216
217 virtual bool createUniquePrimitives(IMeshBuffer* srcBuffer, IMeshBuffer* dstBuffer) const = 0;
218
219 virtual bool createWelded(IMeshBuffer* srcBuffer, IMeshBuffer* dstBuffer, f32 tolerance = core::ROUNDING_ERROR_f32,
220 bool check4Component = true, bool check3Component = true, bool check2Component = true, bool check1Component = true) const = 0;
221
222 // Support mesh buffers with only one vertex buffer per mesh buffer.
223 template <class T>
224 bool convertVertices(IMeshBuffer* buffer, video::IVertexDescriptor* descriptor, bool copyCustomAttribute = false)
225 {
226 if (!buffer || !buffer->isVertexBufferCompatible() || buffer->getVertexBufferCount() > 1 ||
227 !descriptor || descriptor->getVertexSize(0) != sizeof(T))
228 return false;
229
231
232 bool status = false;
233
234 if (copyVertices(buffer->getVertexBuffer(0), 0, buffer->getVertexDescriptor(), vb, 0, descriptor, false))
235 {
236 buffer->setVertexDescriptor(descriptor);
237 buffer->setVertexBuffer(vb, 0);
238 status = true;
239 }
240
241 vb->drop();
242
243 return status;
244 }
245
246 // Support mesh buffers with only one vertex buffer per mesh buffer.
247 template <class T>
248 bool createTangents(IMeshBuffer* buffer, video::IVertexDescriptor* descriptor, bool copyCustomAttribute = false)
249 {
250 if (!convertVertices<T>(buffer, descriptor, copyCustomAttribute))
251 return false;
252
253 recalculateTangents(buffer, false, false, false);
254
255 return true;
256 }
257
258 // Support mesh buffers with only one vertex buffer per mesh buffer.
259 template <class T>
260 SMesh* createMeshCopy(IMesh* mesh, video::IVertexDescriptor* descriptor, bool copyCustomAttribute = false)
261 {
262 if (!mesh || mesh->getMeshBufferCount() == 0 || !descriptor || descriptor->getVertexSize(0) != sizeof(T))
263 return NULL;
264
265 const u32 mbCount = mesh->getMeshBufferCount();
266
267 for (u32 i = 0; i < mbCount; ++i)
268 {
269 const IMeshBuffer* const mb = mesh->getMeshBuffer(i);
270
271 if (!mb->isVertexBufferCompatible() || mb->getVertexBufferCount() > 1)
272 return NULL;
273 }
274
275 SMesh* dstMesh = new SMesh();
276
277 for (u32 i = 0; i < mbCount; ++i)
278 {
279 IMeshBuffer* srcBuffer = mesh->getMeshBuffer(i);
280 IIndexBuffer* srcIndexBuffer = srcBuffer->getIndexBuffer();
281 CMeshBuffer<T>* dstBuffer = new CMeshBuffer<T>(descriptor, srcIndexBuffer->getType());
282
283 dstBuffer->getMaterial() = srcBuffer->getMaterial();
284
285 copyIndices(srcIndexBuffer, dstBuffer->getIndexBuffer());
286 copyVertices(srcBuffer->getVertexBuffer(0), 0, srcBuffer->getVertexDescriptor(), dstBuffer->getVertexBuffer(0), 0, dstBuffer->getVertexDescriptor(), copyCustomAttribute);
287
288 dstMesh->addMeshBuffer(dstBuffer);
289 dstBuffer->drop();
290 }
291
292 dstMesh->BoundingBox = mesh->getBoundingBox();
293
294 return dstMesh;
295 }
296
298
300 virtual s32 getPolyCount(IMesh* mesh) const = 0;
301
303
311 virtual IMesh* createForsythOptimizedMesh(const IMesh *mesh) const = 0;
312};
313
314} // end namespace scene
315} // end namespace irr
316
317
318#endif
bool drop() const
Drops the object. Decrements the reference counter by one.
Definition IReferenceCounted.h:126
IReferenceCounted()
Constructor.
Definition IReferenceCounted.h:50
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
Definition CVertexBuffer.h:17
Definition IIndexBuffer.h:25
Struct for holding a mesh with a single material.
Definition IMeshBuffer.h:42
bool isVertexBufferCompatible() const
Inform if stored vertex buffers have the same vertex descriptors.
Definition IMeshBuffer.h:66
virtual const core::aabbox3df & getBoundingBox() const =0
Get the axis aligned bounding box of this meshbuffer.
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.
Definition IMeshManipulator.h:26
_IRR_DEPRECATED_ void scaleMesh(IMesh *mesh, const core::vector3df &factor) const
Scales the actual mesh, not a scene node.
Definition IMeshManipulator.h:92
virtual void scaleTCoords(IMeshBuffer *meshBuffer, const core::vector2df &factor, u32 level=0) const =0
Scale the texture coords of a meshbuffer.
virtual _IRR_DEPRECATED_ void transformMesh(IMesh *mesh, const core::matrix4 &m) const
Applies a transformation to a mesh.
Definition IMeshManipulator.h:139
virtual void makePlanarTextureMapping(IMeshBuffer *meshBuffer, f32 resolutionS, f32 resolutionT, u8 axis, const core::vector3df &offset) const =0
Creates a planar texture mapping on the meshbuffer.
void recalculateNormals(IMesh *mesh, bool smooth=false, bool angleWeighted=false) const
Recalculates all normals of the mesh.
Definition IMeshManipulator.h:151
virtual void makePlanarTextureMapping(IMeshBuffer *meshBuffer, f32 resolution=0.001f) const =0
Creates a planar texture mapping 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.
Definition IMeshManipulator.h:57
void makePlanarTextureMapping(IMesh *mesh, f32 resolution=0.001f) const
Creates a planar texture mapping on the mesh.
Definition IMeshManipulator.h:177
virtual void transform(IMeshBuffer *meshBuffer, const core::matrix4 &mat) const =0
Applies a transformation to a meshbuffer.
virtual s32 getPolyCount(IMesh *mesh) const =0
Get amount of polygons in mesh.
void scaleTCoords(scene::IMesh *mesh, const core::vector2df &factor, u32 level=0) const
Scale the texture coords of a mesh.
Definition IMeshManipulator.h:104
void setVertexColorAlpha(IMesh *mesh, s32 alpha) const
Sets the alpha vertex color value of the whole mesh to a new value.
Definition IMeshManipulator.h:43
void transform(IMesh *mesh, const core::matrix4 &m) const
Applies a transformation to a mesh.
Definition IMeshManipulator.h:118
virtual void recalculateNormals(IMeshBuffer *meshBuffer, bool smooth=false, bool angleWeighted=false) const =0
Recalculates all normals of the mesh buffer.
void scale(IMesh *mesh, const core::vector3df &factor) const
Scales the actual mesh, not a scene node.
Definition IMeshManipulator.h:71
virtual void setVertexColorAlpha(IMeshBuffer *meshBuffer, s32 alpha) const =0
Sets the alpha vertex color value of the whole mesh to a new value.
virtual IMesh * createForsythOptimizedMesh(const IMesh *mesh) const =0
Vertex cache optimization according to the Forsyth paper.
virtual void setVertexColors(IMeshBuffer *meshBuffer, video::SColor color) const =0
Sets the colors of all vertices to one color.
void makePlanarTextureMapping(scene::IMesh *mesh, f32 resolutionS, f32 resolutionT, u8 axis, const core::vector3df &offset) const
Creates a planar texture mapping on the buffer.
Definition IMeshManipulator.h:201
virtual void scale(IMeshBuffer *meshBuffer, const core::vector3df &factor) const =0
Scales the actual meshbuffer, not a scene node.
Definition IVertexBuffer.h:17
Definition IVertexDescriptor.h:154
Class representing a 32 bit ARGB color.
Definition SColor.h:285
vector3d< f32 > vector3df
Typedef for a f32 3d vector.
Definition vector3d.h:445
vector2d< f32 > vector2df
Typedef for f32 2d vector.
Definition vector2d.h:323
CMatrix4< f32 > matrix4
Typedef for f32 matrix.
Definition matrix4.h:2241
aabbox3d< f32 > aabbox3df
Typedef for a f32 3d bounding box.
Definition aabbox3d.h:351
All scene management can be found in this namespace: Mesh loading, special scene nodes like octrees a...
Definition CIndexBuffer.h:13
Everything in the Irrlicht Engine can be found in this namespace.
Definition Skylicht.h:33
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