123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- #pragma once
- #include "IReferenceCounted.h"
- #include "vector3d.h"
- #include "aabbox3d.h"
- #include "IAnimatedMesh.h"
- #include "IMeshBuffer.h"
- #include "SVertexManipulator.h"
- namespace irr
- {
- namespace scene
- {
- struct SMesh;
- class IMeshManipulator : public virtual IReferenceCounted
- {
- public:
-
-
- virtual void recalculateNormals(IMesh *mesh, bool smooth = false,
- bool angleWeighted = false) const = 0;
-
-
- virtual void recalculateNormals(IMeshBuffer *buffer,
- bool smooth = false, bool angleWeighted = false) const = 0;
-
-
- void scale(IMesh *mesh, const core::vector3df &factor) const
- {
- apply(SVertexPositionScaleManipulator(factor), mesh, true);
- }
-
-
- void scale(IMeshBuffer *buffer, const core::vector3df &factor) const
- {
- apply(SVertexPositionScaleManipulator(factor), buffer, true);
- }
-
-
- virtual SMesh *createMeshCopy(IMesh *mesh) const = 0;
-
-
- virtual s32 getPolyCount(IMesh *mesh) const = 0;
-
-
- virtual s32 getPolyCount(IAnimatedMesh *mesh) const = 0;
-
-
- virtual IAnimatedMesh *createAnimatedMesh(IMesh *mesh,
- scene::E_ANIMATED_MESH_TYPE type = scene::EAMT_UNKNOWN) const = 0;
-
-
- template <typename Functor>
- bool apply(const Functor &func, IMeshBuffer *buffer, bool boundingBoxUpdate = false) const
- {
- return apply_(func, buffer, boundingBoxUpdate, func);
- }
-
-
- template <typename Functor>
- bool apply(const Functor &func, IMesh *mesh, bool boundingBoxUpdate = false) const
- {
- if (!mesh)
- return true;
- bool result = true;
- core::aabbox3df bufferbox;
- for (u32 i = 0; i < mesh->getMeshBufferCount(); ++i) {
- result &= apply(func, mesh->getMeshBuffer(i), boundingBoxUpdate);
- if (boundingBoxUpdate) {
- if (0 == i)
- bufferbox.reset(mesh->getMeshBuffer(i)->getBoundingBox());
- else
- bufferbox.addInternalBox(mesh->getMeshBuffer(i)->getBoundingBox());
- }
- }
- if (boundingBoxUpdate)
- mesh->setBoundingBox(bufferbox);
- return result;
- }
- protected:
-
-
- template <typename Functor>
- bool apply_(const Functor &func, IMeshBuffer *buffer, bool boundingBoxUpdate, const IVertexManipulator &typeTest) const
- {
- if (!buffer)
- return true;
- core::aabbox3df bufferbox;
- for (u32 i = 0; i < buffer->getVertexCount(); ++i) {
- switch (buffer->getVertexType()) {
- case video::EVT_STANDARD: {
- video::S3DVertex *verts = (video::S3DVertex *)buffer->getVertices();
- func(verts[i]);
- } break;
- case video::EVT_2TCOORDS: {
- video::S3DVertex2TCoords *verts = (video::S3DVertex2TCoords *)buffer->getVertices();
- func(verts[i]);
- } break;
- case video::EVT_TANGENTS: {
- video::S3DVertexTangents *verts = (video::S3DVertexTangents *)buffer->getVertices();
- func(verts[i]);
- } break;
- }
- if (boundingBoxUpdate) {
- if (0 == i)
- bufferbox.reset(buffer->getPosition(0));
- else
- bufferbox.addInternalPoint(buffer->getPosition(i));
- }
- }
- if (boundingBoxUpdate)
- buffer->setBoundingBox(bufferbox);
- return true;
- }
- };
- }
- }
|