Home | Namespaces | Hierarchy | Alphabetical List | Class list | Files | Namespace Members | Class members | File members | Tutorials

IMeshManipulator.h

Go to the documentation of this file.
00001 // Copyright (C) 2002-2010 Nikolaus Gebhardt
00002 // This file is part of the "Irrlicht Engine".
00003 // For conditions of distribution and use, see copyright notice in irrlicht.h
00004 
00005 #ifndef __I_MESH_MANIPULATOR_H_INCLUDED__
00006 #define __I_MESH_MANIPULATOR_H_INCLUDED__
00007 
00008 #include "IReferenceCounted.h"
00009 #include "vector3d.h"
00010 #include "aabbox3d.h"
00011 #include "matrix4.h"
00012 #include "IAnimatedMesh.h"
00013 #include "IMeshBuffer.h"
00014 #include "SVertexManipulator.h"
00015 
00016 namespace irr
00017 {
00018 namespace scene
00019 {
00020 
00021         struct SMesh;
00022 
00024 
00029         class IMeshManipulator : public virtual IReferenceCounted
00030         {
00031         public:
00032 
00034 
00037                 virtual void flipSurfaces(IMesh* mesh) const = 0;
00038 
00040 
00042                 void setVertexColorAlpha(IMesh* mesh, s32 alpha) const
00043                 {
00044                         apply(scene::SVertexColorSetAlphaManipulator(alpha), mesh);
00045                 }
00046 
00048 
00050                 void setVertexColors(IMesh* mesh, video::SColor color) const
00051                 {
00052                         apply(scene::SVertexColorSetManipulator(color), mesh);
00053                 }
00054 
00056 
00059                 virtual void recalculateNormals(IMesh* mesh, bool smooth = false, bool angleWeighted = false) const = 0;
00060 
00062 
00065                 virtual void recalculateNormals(IMeshBuffer* buffer, bool smooth = false, bool angleWeighted = false) const = 0;
00066 
00068 
00073                 virtual void recalculateTangents(IMesh* mesh,
00074                                 bool recalculateNormals=false, bool smooth=false,
00075                                 bool angleWeighted=false) const=0;
00076 
00078 
00080                 void scale(IMesh* mesh, const core::vector3df& factor) const
00081                 {
00082                         apply(SVertexPositionScaleManipulator(factor), mesh, true);
00083                 }
00084 
00086 
00088                 void scale(IMeshBuffer* buffer, const core::vector3df& factor) const
00089                 {
00090                         apply(SVertexPositionScaleManipulator(factor), buffer, true);
00091                 }
00092 
00094 
00097                 void scaleMesh(IMesh* mesh, const core::vector3df& factor) const {return scale(mesh,factor);}
00098 
00100 
00103                 void scaleTCoords(scene::IMesh* mesh, const core::vector2df& factor, u32 level=1) const
00104                 {
00105                         apply(SVertexTCoordsScaleManipulator(factor, level), mesh);
00106                 }
00107 
00109 
00112                 void scaleTCoords(scene::IMeshBuffer* buffer, const core::vector2df& factor, u32 level=1) const
00113                 {
00114                         apply(SVertexTCoordsScaleManipulator(factor, level), buffer);
00115                 }
00116 
00118 
00120                 void transform(IMesh* mesh, const core::matrix4& m) const
00121                 {
00122                         apply(SVertexPositionTransformManipulator(m), mesh, true);
00123                 }
00124 
00126 
00128                 void transform(IMeshBuffer* buffer, const core::matrix4& m) const
00129                 {
00130                         apply(SVertexPositionTransformManipulator(m), buffer, true);
00131                 }
00132 
00134 
00137                 virtual void transformMesh(IMesh* mesh, const core::matrix4& m) const {return transform(mesh,m);}
00138 
00140 
00146                 virtual SMesh* createMeshCopy(IMesh* mesh) const = 0;
00147 
00149 
00153                 virtual void makePlanarTextureMapping(IMesh* mesh, f32 resolution=0.001f) const =0;
00154 
00156 
00160                 virtual void makePlanarTextureMapping(scene::IMeshBuffer* meshbuffer, f32 resolution=0.001f) const =0;
00161 
00163 
00170                 virtual void makePlanarTextureMapping(scene::IMeshBuffer* buffer, f32 resolutionS, f32 resolutionT, u8 axis, const core::vector3df& offset) const =0;
00171 
00173 
00189                 virtual IMesh* createMeshWithTangents(IMesh* mesh, bool recalculateNormals=false, bool smooth=false, bool angleWeighted=false, bool recalculateTangents=true) const = 0;
00190 
00192 
00197                 virtual IMesh* createMeshWith2TCoords(IMesh* mesh) const = 0;
00198 
00200 
00205                 virtual IMesh* createMeshWith1TCoords(IMesh* mesh) const = 0;
00206 
00208 
00213                 virtual IMesh* createMeshUniquePrimitives(IMesh* mesh) const = 0;
00214 
00216 
00221                 virtual IMesh* createMeshWelded(IMesh* mesh, f32 tolerance=core::ROUNDING_ERROR_f32) const = 0;
00222 
00224 
00226                 virtual s32 getPolyCount(IMesh* mesh) const = 0;
00227 
00229 
00231                 virtual s32 getPolyCount(IAnimatedMesh* mesh) const = 0;
00232 
00234 
00240                 virtual IAnimatedMesh * createAnimatedMesh(IMesh* mesh,
00241                         scene::E_ANIMATED_MESH_TYPE type = scene::EAMT_UNKNOWN) const = 0;
00242 
00244 
00248                 template <typename Functor>
00249                 bool apply(const Functor& func, IMeshBuffer* buffer, bool boundingBoxUpdate=false) const
00250                 {
00251                         return apply_(func, buffer, boundingBoxUpdate, func);
00252                 }
00253 
00254 
00256 
00260                 template <typename Functor>
00261                 bool apply(const Functor& func, IMesh* mesh, bool boundingBoxUpdate=false) const
00262                 {
00263                         if (!mesh)
00264                                 return true;
00265                         bool result = true;
00266                         core::aabbox3df bufferbox;
00267                         for (u32 i=0; i<mesh->getMeshBufferCount(); ++i)
00268                         {
00269                                 result &= apply(func, mesh->getMeshBuffer(i), boundingBoxUpdate);
00270                                 if (boundingBoxUpdate)
00271                                 {
00272                                         if (0==i)
00273                                                 bufferbox.reset(mesh->getMeshBuffer(i)->getBoundingBox());
00274                                         else
00275                                                 bufferbox.addInternalBox(mesh->getMeshBuffer(i)->getBoundingBox());
00276                                 }
00277                         }
00278                         if (boundingBoxUpdate)
00279                                 mesh->setBoundingBox(bufferbox);
00280                         return result;
00281                 }
00282 
00283 protected:
00285 
00290                 template <typename Functor>
00291                 bool apply_(const Functor& func, IMeshBuffer* buffer, bool boundingBoxUpdate, const IVertexManipulator& typeTest) const
00292                 {
00293                         if (!buffer)
00294                                 return true;
00295 
00296                         core::aabbox3df bufferbox;
00297                         for (u32 i=0; i<buffer->getVertexCount(); ++i)
00298                         {
00299                                 switch (buffer->getVertexType())
00300                                 {
00301                                 case video::EVT_STANDARD:
00302                                         {
00303                                                 video::S3DVertex* verts = (video::S3DVertex*)buffer->getVertices();
00304                                                 func(verts[i]);
00305                                         }
00306                                         break;
00307                                 case video::EVT_2TCOORDS:
00308                                         {
00309                                                 video::S3DVertex2TCoords* verts = (video::S3DVertex2TCoords*)buffer->getVertices();
00310                                                 func(verts[i]);
00311                                         }
00312                                         break;
00313                                 case video::EVT_TANGENTS:
00314                                         {
00315                                                 video::S3DVertexTangents* verts = (video::S3DVertexTangents*)buffer->getVertices();
00316                                                 func(verts[i]);
00317                                         }
00318                                         break;
00319                                 }
00320                                 if (boundingBoxUpdate)
00321                                 {
00322                                         if (0==i)
00323                                                 bufferbox.reset(buffer->getPosition(0));
00324                                         else
00325                                                 bufferbox.addInternalPoint(buffer->getPosition(i));
00326                                 }
00327                         }
00328                         if (boundingBoxUpdate)
00329                                 buffer->setBoundingBox(bufferbox);
00330                         return true;
00331                 }
00332 };
00333 
00334 } // end namespace scene
00335 } // end namespace irr
00336 
00337 
00338 #endif

The Irrlicht Engine
The Irrlicht Engine Documentation © 2003-2010 by Nikolaus Gebhardt. Generated on Sun Oct 24 12:41:57 2010 by Doxygen (1.6.2)