diff -Nauwr source/Irrlicht/CMeshManipulator.cpp source/Irrlicht/CMeshManipulator.cpp --- source/Irrlicht/CMeshManipulator.cpp 2005-08-20 22:17:50.000000000 +0200 +++ source/Irrlicht/CMeshManipulator.cpp 2005-09-16 15:31:22.000000000 +0200 @@ -82,6 +82,54 @@ } +//! Recalculates normals in a vertex array. +//! This template function was a member of the CMeshManipulator class, but +//! visual studio 6.0 didn't like it. +template +inline void makePlanarMappingT2(VERTEXTYPE *v, + int vtxcnt, + u16* idx, int idxcnt, f32 resolution ) +{ + for (int i=0; i p(v[idx[i+0]].Pos, v[idx[i+1]].Pos, v[idx[i+2]].Pos); + p.Normal.normalize(); + + p.Normal.X = (f32)(fabs(p.Normal.X)); + p.Normal.Y = (f32)(fabs(p.Normal.Y)); + p.Normal.Z = (f32)(fabs(p.Normal.Z)); + + // calculate planar mapping worldspace coordinates + + if (p.Normal.X > p.Normal.Y && p.Normal.X > p.Normal.Z) + { + for (s32 o=0; o<3; ++o) + { + v[idx[i+o]].TCoords2.X = v[idx[i+o]].Pos.Y * resolution; + v[idx[i+o]].TCoords2.Y = v[idx[i+o]].Pos.Z * resolution; + } + } + else + if (p.Normal.Y > p.Normal.X && p.Normal.Y > p.Normal.Z) + { + for (s32 o=0; o<3; ++o) + { + v[idx[i+o]].TCoords2.X = v[idx[i+o]].Pos.X * resolution; + v[idx[i+o]].TCoords2.Y = v[idx[i+o]].Pos.Z * resolution; + } + } + else + { + for (s32 o=0; o<3; ++o) + { + v[idx[i+o]].TCoords2.X = v[idx[i+o]].Pos.X * resolution; + v[idx[i+o]].TCoords2.Y = v[idx[i+o]].Pos.Y * resolution; + } + } + } +} + + //! Constructor CMeshManipulator::CMeshManipulator() { @@ -426,7 +474,7 @@ //! \param resolution: resolution of the planar mapping. This is the value //! specifying which is the releation between world space and //! texture coordinate space. -void CMeshManipulator::makePlanarTextureMapping(scene::IMesh* mesh, f32 resolution=0.01f) const +void CMeshManipulator::makePlanarTextureMapping(scene::IMesh* mesh, f32 resolution, bool firstTCoord) const { if (!mesh) return; @@ -450,8 +498,16 @@ case video::EVT_2TCOORDS: { video::S3DVertex2TCoords* v = (video::S3DVertex2TCoords*)buffer->getVertices(); + + if( firstTCoord ) + { makePlanarMappingT(v, vtxcnt, idx, idxcnt, resolution); } + else + { + makePlanarMappingT2(v, vtxcnt, idx, idxcnt, resolution); + } + } break; case video::EVT_TANGENTS: { diff -Nauwr source/Irrlicht/CMeshManipulator.h source/Irrlicht/CMeshManipulator.h --- source/Irrlicht/CMeshManipulator.h 2005-08-20 22:17:50.000000000 +0200 +++ source/Irrlicht/CMeshManipulator.h 2005-09-22 19:04:22.000000000 +0200 @@ -59,7 +59,7 @@ //! \param resolution: resolution of the planar mapping. This is the value //! specifying which is the releation between world space and //! texture coordinate space. - virtual void makePlanarTextureMapping(scene::IMesh* mesh, f32 resolution) const; + virtual void makePlanarTextureMapping(scene::IMesh* mesh, f32 resolution = 0.001f, bool firstTCoord = true) const; //! Creates a copy of the mesh, which will only consist of S3DVertexTangents vertices. //! This is useful if you want to draw tangent space normal mapped geometry because diff -Nauwr include/IMeshManipulator.h include/IMeshManipulator.h --- include/IMeshManipulator.h 2005-08-20 22:17:44.000000000 +0200 +++ include/IMeshManipulator.h 2005-08-29 20:00:14.000000000 +0200 @@ -73,7 +73,7 @@ \param resolution: resolution of the planar mapping. This is the value specifying which is the relation between world space and texture coordinate space. */ - virtual void makePlanarTextureMapping(IMesh* mesh, f32 resolution=0.001f) const = 0; + virtual void makePlanarTextureMapping(IMesh* mesh, f32 resolution=0.001f, bool firstTCoord=true) const = 0; //! Creates a copy of the mesh, which will only consist of S3DVertexTangents vertices. /** This is useful if you want to draw tangent space normal mapped geometry because