diff --git a/include/IMeshManipulator.h b/include/IMeshManipulator.h index 22939866..45f4e410 100644 --- a/include/IMeshManipulator.h +++ b/include/IMeshManipulator.h @@ -93,6 +93,8 @@ namespace scene See IReferenceCounted::drop() for more information. */ virtual IMesh* createMeshWithTangents(IMesh* mesh) const = 0; + //! Creates a copy of the mesh, which will only consist of S3DVertex2TCoord vertices. + virtual IMesh* createMeshWith2TCoords(IMesh* mesh) const = 0; //! Creates a copy of a mesh with all vertices unwelded virtual IMesh* createMeshUniquePrimitives(IMesh* mesh) const = 0; diff --git a/include/irrlicht.h b/include/irrlicht.h index a8455a77..52bf3243 100644 --- a/include/irrlicht.h +++ b/include/irrlicht.h @@ -31,13 +31,16 @@ #include "IrrCompileConfig.h" #include "aabbox3d.h" +#include "coreutil.h" #include "irrArray.h" #include "irrMap.h" +#include "irrMath.h" +#include "irrString.h" +#include "irrTypes.h" #include "SColor.h" #include "SLight.h" #include "dimension2d.h" #include "EDriverTypes.h" -#include "heapsort.h" #include "IAttributes.h" #include "IAttributeExchangingObject.h" #include "IAnimatedMesh.h" @@ -91,8 +94,6 @@ #include "IMetaTriangleSelector.h" #include "IReadFile.h" #include "IrrlichtDevice.h" -#include "irrMath.h" -#include "irrString.h" #include "ISceneManager.h" #include "ISceneNode.h" #include "ISceneUserDataSerializer.h" @@ -136,8 +137,6 @@ #include "SMeshBufferLightMap.h" #include "SMeshBufferTangents.h" #include "SViewFrustum.h" -#include "irrTypes.h" -#include "coreutil.h" /*! \mainpage Irrlicht Engine 1.4 API documentation * diff --git a/source/Irrlicht/CMeshManipulator.cpp b/source/Irrlicht/CMeshManipulator.cpp index dbe15227..497b6694 100644 --- a/source/Irrlicht/CMeshManipulator.cpp +++ b/source/Irrlicht/CMeshManipulator.cpp @@ -426,9 +426,11 @@ SMesh* CMeshManipulator::createMeshCopy(scene::IMesh* mesh) const video::S3DVertex* v = (video::S3DVertex*)mesh->getMeshBuffer(b)->getVertices(); + buffer->Vertices.reallocate(vtxCnt); for (i=0; iVertices.push_back(v[i]); + buffer->Indices.reallocate(idxCnt); for (i=0; iIndices.push_back(idx[i]); @@ -444,9 +446,11 @@ SMesh* CMeshManipulator::createMeshCopy(scene::IMesh* mesh) const video::S3DVertex2TCoords* v = (video::S3DVertex2TCoords*)mesh->getMeshBuffer(b)->getVertices(); + buffer->Vertices.reallocate(vtxCnt); for (i=0; iVertices.push_back(v[i]); + buffer->Indices.reallocate(idxCnt); for (i=0; iIndices.push_back(idx[i]); @@ -462,9 +466,11 @@ SMesh* CMeshManipulator::createMeshCopy(scene::IMesh* mesh) const video::S3DVertexTangents* v = (video::S3DVertexTangents*)mesh->getMeshBuffer(b)->getVertices(); + buffer->Vertices.reallocate(vtxCnt); for (i=0; iVertices.push_back(v[i]); + buffer->Indices.reallocate(idxCnt); for (i=0; iIndices.push_back(idx[i]); @@ -538,7 +544,7 @@ IMesh* CMeshManipulator::createMeshUniquePrimitives(IMesh* mesh) const for ( u32 b=0; bgetMeshBuffer(b)->getIndexCount(); + const s32 idxCnt = mesh->getMeshBuffer(b)->getIndexCount(); const u16* idx = mesh->getMeshBuffer(b)->getIndices(); switch(mesh->getMeshBuffer(b)->getVertexType()) @@ -551,6 +557,8 @@ IMesh* CMeshManipulator::createMeshUniquePrimitives(IMesh* mesh) const video::S3DVertex* v = (video::S3DVertex*)mesh->getMeshBuffer(b)->getVertices(); + buffer->Vertices.reallocate(idxCnt); + buffer->Indices.reallocate(idxCnt); for (s32 i=0; iVertices.push_back( v[idx[i + 0 ]] ); @@ -574,6 +582,8 @@ IMesh* CMeshManipulator::createMeshUniquePrimitives(IMesh* mesh) const video::S3DVertex2TCoords* v = (video::S3DVertex2TCoords*)mesh->getMeshBuffer(b)->getVertices(); + buffer->Vertices.reallocate(idxCnt); + buffer->Indices.reallocate(idxCnt); for (s32 i=0; iVertices.push_back( v[idx[i + 0 ]] ); @@ -596,6 +606,8 @@ IMesh* CMeshManipulator::createMeshUniquePrimitives(IMesh* mesh) const video::S3DVertexTangents* v = (video::S3DVertexTangents*)mesh->getMeshBuffer(b)->getVertices(); + buffer->Vertices.reallocate(idxCnt); + buffer->Indices.reallocate(idxCnt); for (s32 i=0; iVertices.push_back( v[idx[i + 0 ]] ); @@ -800,7 +812,7 @@ IMesh* CMeshManipulator::createMeshWithTangents(IMesh* mesh) const for (b=0; bgetMeshBuffer(b)->getIndexCount(); + const s32 idxCnt = mesh->getMeshBuffer(b)->getIndexCount(); const u16* idx = mesh->getMeshBuffer(b)->getIndices(); SMeshBufferTangents* buffer = new SMeshBufferTangents(); @@ -808,6 +820,7 @@ IMesh* CMeshManipulator::createMeshWithTangents(IMesh* mesh) const // copy vertices + buffer->Vertices.reallocate(idxCnt); switch(mesh->getMeshBuffer(b)->getVertexType()) { case video::EVT_STANDARD: @@ -858,7 +871,7 @@ IMesh* CMeshManipulator::createMeshWithTangents(IMesh* mesh) const // now calculate tangents for (b=0; bgetMeshBuffer(b)->getIndexCount(); + const s32 idxCnt = clone->getMeshBuffer(b)->getIndexCount(); u16* idx = clone->getMeshBuffer(b)->getIndices(); video::S3DVertexTangents* v = @@ -906,6 +919,81 @@ IMesh* CMeshManipulator::createMeshWithTangents(IMesh* mesh) const +//! Creates a copy of the mesh, which will only consist of S3DVertex2TCoords vertices. +IMesh* CMeshManipulator::createMeshWith2TCoords(IMesh* mesh) const +{ + if (!mesh) + return 0; + + // copy mesh and fill data into SMeshBufferLightMap + + SMesh* clone = new SMesh(); + const u32 meshBufferCount = mesh->getMeshBufferCount(); + u32 b; + + for (b=0; bgetMeshBuffer(b)->getIndexCount(); + const u16* idx = mesh->getMeshBuffer(b)->getIndices(); + + SMeshBufferLightMap* buffer = new SMeshBufferLightMap(); + buffer->Material = mesh->getMeshBuffer(b)->getMaterial(); + + // copy vertices + + buffer->Vertices.reallocate(idxCnt); + switch(mesh->getMeshBuffer(b)->getVertexType()) + { + case video::EVT_STANDARD: + { + video::S3DVertex* v = + (video::S3DVertex*)mesh->getMeshBuffer(b)->getVertices(); + + for (s32 i=0; iVertices.push_back( + video::S3DVertex2TCoords( + v[idx[i]].Pos, v[idx[i]].Color, v[idx[i]].TCoords, v[idx[i]].TCoords)); + } + break; + case video::EVT_2TCOORDS: + { + video::S3DVertex2TCoords* v = + (video::S3DVertex2TCoords*)mesh->getMeshBuffer(b)->getVertices(); + + for (s32 i=0; iVertices.push_back(v[idx[i]]); + } + break; + case video::EVT_TANGENTS: + { + video::S3DVertexTangents* v = + (video::S3DVertexTangents*)mesh->getMeshBuffer(b)->getVertices(); + + for (s32 i=0; iVertices.push_back(video::S3DVertex2TCoords( + v[idx[i]].Pos, v[idx[i]].Color, v[idx[i]].TCoords, v[idx[i]].TCoords)); + } + break; + } + + // create new indices + + buffer->Indices.set_used(idxCnt); + for (s32 i=0; iIndices[i] = i; + + // add new buffer + clone->addMeshBuffer(buffer); + buffer->drop(); + } + + clone->BoundingBox = mesh->getBoundingBox(); + + return clone; +} + + + void CMeshManipulator::calculateTangents( core::vector3df& normal, core::vector3df& tangent, diff --git a/source/Irrlicht/CMeshManipulator.h b/source/Irrlicht/CMeshManipulator.h index 1dafefcb..352a90ff 100644 --- a/source/Irrlicht/CMeshManipulator.h +++ b/source/Irrlicht/CMeshManipulator.h @@ -75,6 +75,7 @@ public: //! If you no longer need the cloned mesh, you should call IMesh::drop(). //! See IReferenceCounted::drop() for more information. virtual IMesh* createMeshWithTangents(IMesh* mesh) const; + virtual IMesh* createMeshWith2TCoords(IMesh* mesh) const; virtual IMesh* createMeshUniquePrimitives(IMesh* mesh) const; diff --git a/source/Irrlicht/Makefile b/source/Irrlicht/Makefile index c7c51239..49fbab5a 100644 --- a/source/Irrlicht/Makefile +++ b/source/Irrlicht/Makefile @@ -73,7 +73,7 @@ staticlib sharedlib : CXXINCS += -I/usr/X11R6/include #Windows specific options sharedlib_win32 staticlib_win32: SYSTEM = Win32-gcc -sharedlib_win32: LDFLAGS = -lgdi32 -lwinspool -lcomdlg32 -lole32 -loleaut32 -luuid -lopengl32 -ld3dx9d -lSDL +sharedlib_win32: LDFLAGS = -lgdi32 -lopengl32 -ld3dx9d -lSDL sharedlib_win32 staticlib_win32: CPPFLAGS += -DIRR_COMPILE_WITH_DX9_DEV_PACK -D__GNUWIN32__ -D_WIN32 -DWIN32 -D_WINDOWS -D_MBCS -D_USRDLL staticlib_win32: CPPFLAGS += -D_IRR_STATIC_LIB_