From 57c16f70d8c9ff27766cb1aa74e3a0b17872d0e6 Mon Sep 17 00:00:00 2001 From: hybrid Date: Sun, 1 Feb 2009 23:43:44 +0000 Subject: [PATCH] Added new makePlanarMapping method with one major axis for the whole mesh buffer, and different resolutions in S and T. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2181 dfc29bdd-3216-0410-991c-e03cc46cb475 --- include/IMeshManipulator.h | 13 ++++++++-- source/Irrlicht/CMeshManipulator.cpp | 37 ++++++++++++++++++++++++++++ source/Irrlicht/CMeshManipulator.h | 3 +++ 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/include/IMeshManipulator.h b/include/IMeshManipulator.h index 9c9659e8..1e499631 100644 --- a/include/IMeshManipulator.h +++ b/include/IMeshManipulator.h @@ -117,14 +117,23 @@ namespace scene \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) const =0; //! Creates a planar texture mapping on the meshbuffer /** \param meshbuffer: Buffer on which the operation is performed. \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(scene::IMeshBuffer* meshbuffer, f32 resolution=0.001f) const = 0; + virtual void makePlanarTextureMapping(scene::IMeshBuffer* meshbuffer, f32 resolution=0.001f) const =0; + + //! Creates a planar texture mapping on the meshbuffer + /** This method is currently implemented towards the LWO planar mapping. A more general biasing might be required. + \param meshbuffer Buffer on which the operation is performed. + \param resolutionS Resolution of the planar mapping in horizontal direction. This is the ratio between object space and texture space. + \param resolutionT Resolution of the planar mapping in vertical direction. This is the ratio between object space and texture space. + \param axis The axis along which the texture is projected. The allowed values are 0 (X), 1(Y), and 2(Z). + */ + virtual void makePlanarTextureMapping(scene::IMeshBuffer* buffer, f32 resolutionS, f32 resolutionT, u8 axis) 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 diff --git a/source/Irrlicht/CMeshManipulator.cpp b/source/Irrlicht/CMeshManipulator.cpp index 4dc4ee3c..e63c0ea0 100644 --- a/source/Irrlicht/CMeshManipulator.cpp +++ b/source/Irrlicht/CMeshManipulator.cpp @@ -443,6 +443,43 @@ void CMeshManipulator::makePlanarTextureMapping(scene::IMeshBuffer* buffer, f32 } +//! Creates a planar texture mapping on the meshbuffer +void CMeshManipulator::makePlanarTextureMapping(scene::IMeshBuffer* buffer, f32 resolutionS, f32 resolutionT, u8 axis) const +{ + u32 idxcnt = buffer->getIndexCount(); + u16* idx = buffer->getIndices(); + + for (u32 i=0; igetTCoords(idx[i+o]).X = buffer->getPosition(idx[i+o]).Z * resolutionS; + buffer->getTCoords(idx[i+o]).Y = 0.5f+buffer->getPosition(idx[i+o]).Y * resolutionT; + } + } + else if (axis==1) + { + for (u32 o=0; o!=3; ++o) + { + buffer->getTCoords(idx[i+o]).X = 0.5f+buffer->getPosition(idx[i+o]).X * resolutionS; + buffer->getTCoords(idx[i+o]).Y = 0.5f+buffer->getPosition(idx[i+o]).Z * resolutionT; + } + } + else if (axis==2) + { + for (u32 o=0; o!=3; ++o) + { + buffer->getTCoords(idx[i+o]).X = 0.5f+buffer->getPosition(idx[i+o]).X * resolutionS; + buffer->getTCoords(idx[i+o]).Y = buffer->getPosition(idx[i+o]).Y * resolutionT; + } + } + } +} + + //! Creates a copy of the mesh, which will only consist of unique primitives IMesh* CMeshManipulator::createMeshUniquePrimitives(IMesh* mesh) const { diff --git a/source/Irrlicht/CMeshManipulator.h b/source/Irrlicht/CMeshManipulator.h index 12fe2877..95b5fd8b 100644 --- a/source/Irrlicht/CMeshManipulator.h +++ b/source/Irrlicht/CMeshManipulator.h @@ -88,6 +88,9 @@ public: //! Creates a planar texture mapping on the meshbuffer virtual void makePlanarTextureMapping(scene::IMeshBuffer* meshbuffer, f32 resolution=0.001f) const; + //! Creates a planar texture mapping on the meshbuffer + void makePlanarTextureMapping(scene::IMeshBuffer* buffer, f32 resolutionS, f32 resolutionT, u8 axis) const; + //! Creates a copy of the mesh, which will only consist of S3DVertexTangents vertices. virtual IMesh* createMeshWithTangents(IMesh* mesh, bool recalculateNormals=false, bool smooth=false, bool angleWeighted=false) const;