Commit f3bf8b1f authored by hybrid's avatar hybrid

Fix createMeshWith1TCoords to avoid vertex duplication.

Add a new VertexManipulator interface, which allows to easily add manipulators. Several existing methods have been replaced by this interface. 
Further manipulation schemes will be added later.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2856 dfc29bdd-3216-0410-991c-e03cc46cb475
parent a8e7d5eb
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "aabbox3d.h" #include "aabbox3d.h"
#include "matrix4.h" #include "matrix4.h"
#include "IAnimatedMesh.h" #include "IAnimatedMesh.h"
#include "SColor.h" #include "SVertexManipulator.h"
namespace irr namespace irr
{ {
...@@ -40,12 +40,18 @@ namespace scene ...@@ -40,12 +40,18 @@ namespace scene
//! Sets the alpha vertex color value of the whole mesh to a new value. //! Sets the alpha vertex color value of the whole mesh to a new value.
/** \param mesh Mesh on which the operation is performed. /** \param mesh Mesh on which the operation is performed.
\param alpha New alpha value. Must be a value between 0 and 255. */ \param alpha New alpha value. Must be a value between 0 and 255. */
virtual void setVertexColorAlpha(IMesh* mesh, s32 alpha) const = 0; void setVertexColorAlpha(IMesh* mesh, s32 alpha) const
{
apply(scene::SVertexColorSetAlphaManipulator(alpha), mesh);
}
//! Sets the colors of all vertices to one color //! Sets the colors of all vertices to one color
/** \param mesh Mesh on which the operation is performed. /** \param mesh Mesh on which the operation is performed.
\param color New color. */ \param color New color. */
virtual void setVertexColors(IMesh* mesh, video::SColor color) const = 0; void setVertexColors(IMesh* mesh, video::SColor color) const
{
apply(scene::SVertexColorSetManipulator(color), mesh);
}
//! Recalculates all normals of the mesh. //! Recalculates all normals of the mesh.
/** \param mesh: Mesh on which the operation is performed. /** \param mesh: Mesh on which the operation is performed.
...@@ -62,40 +68,58 @@ namespace scene ...@@ -62,40 +68,58 @@ namespace scene
//! Scales the actual mesh, not a scene node. //! Scales the actual mesh, not a scene node.
/** \param mesh Mesh on which the operation is performed. /** \param mesh Mesh on which the operation is performed.
\param factor Scale factor for each axis. */ \param factor Scale factor for each axis. */
virtual void scale(IMesh* mesh, const core::vector3df& factor) const = 0; void scale(IMesh* mesh, const core::vector3df& factor) const
{
apply(SVertexPositionScaleManipulator(factor), mesh, true);
}
//! Scales the actual meshbuffer, not a scene node. //! Scales the actual meshbuffer, not a scene node.
/** \param buffer Meshbuffer on which the operation is performed. /** \param buffer Meshbuffer on which the operation is performed.
\param factor Scale factor for each axis. */ \param factor Scale factor for each axis. */
virtual void scale(IMeshBuffer* buffer, const core::vector3df& factor) const = 0; void scale(IMeshBuffer* buffer, const core::vector3df& factor) const
{
apply(SVertexPositionScaleManipulator(factor), buffer, true);
}
//! Scales the actual mesh, not a scene node. //! Scales the actual mesh, not a scene node.
/** \deprecated Use scale() instead /** \deprecated Use scale() instead
\param mesh Mesh on which the operation is performed. \param mesh Mesh on which the operation is performed.
\param factor Scale factor for each axis. */ \param factor Scale factor for each axis. */
virtual void scaleMesh(IMesh* mesh, const core::vector3df& factor) const {return scale(mesh,factor);} void scaleMesh(IMesh* mesh, const core::vector3df& factor) const {return scale(mesh,factor);}
//! Scale the texture coords of a mesh. //! Scale the texture coords of a mesh.
/** \param mesh Mesh on which the operation is performed. /** \param mesh Mesh on which the operation is performed.
\param factor Vector which defines the scale for each axis. \param factor Vector which defines the scale for each axis.
\param level Number of texture coord, starting from 1. Support for level 2 exists for LightMap buffers. */ \param level Number of texture coord, starting from 1. Support for level 2 exists for LightMap buffers. */
virtual void scaleTCoords(scene::IMesh* mesh, const core::vector2df& factor, u32 level=1) const =0; void scaleTCoords(scene::IMesh* mesh, const core::vector2df& factor, u32 level=1) const
{
apply(SVertexTCoordsScaleManipulator(factor, level), mesh);
}
//! Scale the texture coords of a meshbuffer. //! Scale the texture coords of a meshbuffer.
/** \param buffer Meshbuffer on which the operation is performed. /** \param buffer Meshbuffer on which the operation is performed.
\param factor Vector which defines the scale for each axis. \param factor Vector which defines the scale for each axis.
\param level Number of texture coord, starting from 1. Support for level 2 exists for LightMap buffers. */ \param level Number of texture coord, starting from 1. Support for level 2 exists for LightMap buffers. */
virtual void scaleTCoords(scene::IMeshBuffer* buffer, const core::vector2df& factor, u32 level=1) const =0; void scaleTCoords(scene::IMeshBuffer* buffer, const core::vector2df& factor, u32 level=1) const
{
apply(SVertexTCoordsScaleManipulator(factor, level), buffer);
}
//! Applies a transformation to a mesh //! Applies a transformation to a mesh
/** \param mesh Mesh on which the operation is performed. /** \param mesh Mesh on which the operation is performed.
\param m transformation matrix. */ \param m transformation matrix. */
virtual void transform(IMesh* mesh, const core::matrix4& m) const = 0; void transform(IMesh* mesh, const core::matrix4& m) const
{
apply(SVertexPositionTransformManipulator(m), mesh, true);
}
//! Applies a transformation to a meshbuffer //! Applies a transformation to a meshbuffer
/** \param buffer Meshbuffer on which the operation is performed. /** \param buffer Meshbuffer on which the operation is performed.
\param m transformation matrix. */ \param m transformation matrix. */
virtual void transform(IMeshBuffer* buffer, const core::matrix4& m) const = 0; void transform(IMeshBuffer* buffer, const core::matrix4& m) const
{
apply(SVertexPositionTransformManipulator(m), buffer, true);
}
//! Applies a transformation to a mesh //! Applies a transformation to a mesh
/** \deprecated Use transform() instead /** \deprecated Use transform() instead
...@@ -205,11 +229,100 @@ namespace scene ...@@ -205,11 +229,100 @@ namespace scene
IReferenceCounted::drop() for more information. */ IReferenceCounted::drop() for more information. */
virtual IAnimatedMesh * createAnimatedMesh(IMesh* mesh, virtual IAnimatedMesh * createAnimatedMesh(IMesh* mesh,
scene::E_ANIMATED_MESH_TYPE type = scene::EAMT_UNKNOWN) const = 0; scene::E_ANIMATED_MESH_TYPE type = scene::EAMT_UNKNOWN) const = 0;
};
//! Apply a manipulator on the Meshbuffer
/** \param func A functor defining the mesh manipulation.
\param buffer The Meshbuffer to apply the manipulator to.
\param boundingBoxUpdate Specifies if the bounding box should be updated during manipulation.
\return True if the functor was successfully applied, else false. */
template <typename Functor>
bool apply(const Functor& func, IMeshBuffer* buffer, bool boundingBoxUpdate=false) const
{
return apply_(func, buffer, boundingBoxUpdate, func);
}
//! Apply a manipulator on the Mesh
/** \param func A functor defining the mesh manipulation.
\param mesh The Mesh to apply the manipulator to.
\param boundingBoxUpdate Specifies if the bounding box should be updated during manipulation.
\return True if the functor was successfully applied, else false. */
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->getBoundingBox());
else
bufferbox.addInternalBox(mesh->getBoundingBox());
}
}
if (boundingBoxUpdate)
mesh->setBoundingBox(bufferbox);
return result;
}
protected:
//! Apply a manipulator based on the type of the functor
/** \param func A functor defining the mesh manipulation.
\param buffer The Meshbuffer to apply the manipulator to.
\param boundingBoxUpdate Specifies if the bounding box should be updated during manipulation.
\param typeTest Unused parameter, which handles the proper call selection based on the type of the Functor which is passed in two times.
\return True if the functor was successfully applied, else false. */
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;
}
};
} // end namespace scene } // end namespace scene
} // end namespace irr } // end namespace irr
#endif #endif
// Copyright (C) 2009 Christian Stehno
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __S_VERTEX_MANIPULATOR_H_INCLUDED__
#define __S_VERTEX_MANIPULATOR_H_INCLUDED__
#include "S3DVertex.h"
#include "SColor.h"
namespace irr
{
namespace scene
{
class IMesh;
class IMeshBuffer;
struct SMesh;
//! Interface for vertex manipulators.
/** You should derive your manipulator from this class if it shall be called for every vertex, getting as parameter just the vertex.
*/
struct IVertexManipulator
{
};
//! Vertex manipulator to set color to a fixed color for all vertices
class SVertexColorSetManipulator : public IVertexManipulator
{
public:
SVertexColorSetManipulator(video::SColor color) : Color(color) {}
void operator()(video::S3DVertex& vertex) const
{
vertex.Color=Color;
}
private:
video::SColor Color;
};
//! Vertex manipulator to set the alpha value of the vertex color to a fixed value
class SVertexColorSetAlphaManipulator : public IVertexManipulator
{
public:
SVertexColorSetAlphaManipulator(u32 alpha) : Alpha(alpha) {}
void operator()(video::S3DVertex& vertex) const
{
vertex.Color.setAlpha(Alpha);
}
private:
u32 Alpha;
};
//! Vertex manipulator which invertes the RGB values
class SVertexColorInvertManipulator : public IVertexManipulator
{
public:
void operator()(video::S3DVertex& vertex) const
{
vertex.Color.setRed(255-vertex.Color.getRed());
vertex.Color.setGreen(255-vertex.Color.getGreen());
vertex.Color.setBlue(255-vertex.Color.getBlue());
}
};
//! Vertex manipulator to set vertex color to one of two values depending on a given threshold
/** If average of the color value is >Threshold the High color is chosen, else Low. */
class SVertexColorThresholdManipulator : public IVertexManipulator
{
public:
SVertexColorThresholdManipulator(u8 threshold, video::SColor low,
video::SColor high) : Threshold(threshold), Low(low), High(high) {}
void operator()(video::S3DVertex& vertex) const
{
vertex.Color = (vertex.Color.getAverage()>Threshold)?High:Low;
}
private:
u8 Threshold;
video::SColor Low;
video::SColor High;
};
//! Vertex manipulator which adjusts the brightness by the given amount
/** A positive value increases brightness, a negative value darkens the colors. */
class SVertexColorBrightnessManipulator : public IVertexManipulator
{
public:
SVertexColorBrightnessManipulator(s32 amount) : Amount(amount) {}
void operator()(video::S3DVertex& vertex) const
{
vertex.Color.setRed(core::clamp(vertex.Color.getRed()+Amount, 0u, 255u));
vertex.Color.setGreen(core::clamp(vertex.Color.getGreen()+Amount, 0u, 255u));
vertex.Color.setBlue(core::clamp(vertex.Color.getBlue()+Amount, 0u, 255u));
}
private:
s32 Amount;
};
//! Vertex manipulator which adjusts the contrast by the given factor
/** Factors over 1 increase contrast, below 1 reduce it. */
class SVertexColorContrastManipulator : public IVertexManipulator
{
public:
SVertexColorContrastManipulator(f32 factor) : Factor(factor) {}
void operator()(video::S3DVertex& vertex) const
{
vertex.Color.setRed(core::clamp(core::round32((vertex.Color.getRed()-128)*Factor)+128, 0, 255));
vertex.Color.setGreen(core::clamp(core::round32((vertex.Color.getGreen()-128)*Factor)+128, 0, 255));
vertex.Color.setBlue(core::clamp(core::round32((vertex.Color.getBlue()-128)*Factor)+128, 0, 255));
}
private:
f32 Factor;
};
//! Vertex manipulator which adjusts the contrast by the given factor and brightness by a signed amount.
/** Factors over 1 increase contrast, below 1 reduce it.
A positive amount increases brightness, a negative one darkens the colors. */
class SVertexColorContrastBrightnessManipulator : public IVertexManipulator
{
public:
SVertexColorContrastBrightnessManipulator(f32 factor, s32 amount) : Factor(factor), Amount(amount+128) {}
void operator()(video::S3DVertex& vertex) const
{
vertex.Color.setRed(core::clamp(core::round32((vertex.Color.getRed()-128)*Factor)+Amount, 0, 255));
vertex.Color.setGreen(core::clamp(core::round32((vertex.Color.getGreen()-128)*Factor)+Amount, 0, 255));
vertex.Color.setBlue(core::clamp(core::round32((vertex.Color.getBlue()-128)*Factor)+Amount, 0, 255));
}
private:
f32 Factor;
s32 Amount;
};
//! Vertex manipulator which adjusts the brightness by a gamma operation
/** A value over one increases brightness, one below darkens the colors. */
class SVertexColorGammaManipulator : public IVertexManipulator
{
public:
SVertexColorGammaManipulator(f32 gamma) : Gamma(1.f)
{
if (gamma != 0.f)
Gamma = 1.f/gamma;
}
void operator()(video::S3DVertex& vertex) const
{
vertex.Color.setRed(core::clamp(core::round32(powf((f32)(vertex.Color.getRed()),Gamma)), 0, 255));
vertex.Color.setGreen(core::clamp(core::round32(powf((f32)(vertex.Color.getGreen()),Gamma)), 0, 255));
vertex.Color.setBlue(core::clamp(core::round32(powf((f32)(vertex.Color.getBlue()),Gamma)), 0, 255));
}
private:
f32 Gamma;
};
//! Vertex manipulator which scales the color values
/** Can e.g be used for white balance, factor would be 255.f/brightest color. */
class SVertexColorScaleManipulator : public IVertexManipulator
{
public:
SVertexColorScaleManipulator(f32 factor) : Factor(factor) {}
void operator()(video::S3DVertex& vertex) const
{
vertex.Color.setRed(core::clamp(core::round32(vertex.Color.getRed()*Factor), 0, 255));
vertex.Color.setGreen(core::clamp(core::round32(vertex.Color.getGreen()*Factor), 0, 255));
vertex.Color.setBlue(core::clamp(core::round32(vertex.Color.getBlue()*Factor), 0, 255));
}
private:
f32 Factor;
};
//! Vertex manipulator which desaturates the color values
/** Uses the lightness value of the color. */
class SVertexColorDesaturateToLightnessManipulator : public IVertexManipulator
{
public:
void operator()(video::S3DVertex& vertex) const
{
vertex.Color=core::round32(vertex.Color.getLightness());
}
};
//! Vertex manipulator which desaturates the color values
/** Uses the average value of the color. */
class SVertexColorDesaturateToAverageManipulator : public IVertexManipulator
{
public:
void operator()(video::S3DVertex& vertex) const
{
vertex.Color=vertex.Color.getAverage();
}
};
//! Vertex manipulator which desaturates the color values
/** Uses the luminance value of the color. */
class SVertexColorDesaturateToLuminanceManipulator : public IVertexManipulator
{
public:
void operator()(video::S3DVertex& vertex) const
{
vertex.Color=core::round32(vertex.Color.getLuminance());
}
};
//! Vertex manipulator which interpolates the color values
/** Uses linear interpolation. */
class SVertexColorInterpolateLinearManipulator : public IVertexManipulator
{
public:
SVertexColorInterpolateLinearManipulator(video::SColor color, f32 factor) :
Color(color), Factor(factor) {}
void operator()(video::S3DVertex& vertex) const
{
vertex.Color=vertex.Color.getInterpolated(Color, Factor);
}
private:
video::SColor Color;
f32 Factor;
};
//! Vertex manipulator which interpolates the color values
/** Uses linear interpolation. */
class SVertexColorInterpolateQuadraticManipulator : public IVertexManipulator
{
public:
SVertexColorInterpolateQuadraticManipulator(video::SColor color1, video::SColor color2, f32 factor) :
Color1(color1), Color2(color2), Factor(factor) {}
void operator()(video::S3DVertex& vertex) const
{
vertex.Color=vertex.Color.getInterpolated_quadratic(Color1, Color2, Factor);
}
private:
video::SColor Color1;
video::SColor Color2;
f32 Factor;
};
//! Vertex manipulator which scales the position of the vertex
class SVertexPositionScaleManipulator : public IVertexManipulator
{
public:
SVertexPositionScaleManipulator(const core::vector3df& factor) : Factor(factor) {}
template <typename VType>
void operator()(VType& vertex) const
{
vertex.Pos *= Factor;
}
private:
core::vector3df Factor;
};
//! Vertex manipulator which transforms the position of the vertex
class SVertexPositionTransformManipulator : public IVertexManipulator
{
public:
SVertexPositionTransformManipulator(const core::matrix4& m) : Transformation(m) {}
template <typename VType>
void operator()(VType& vertex) const
{
Transformation.transformVect(vertex.Pos);
}
private:
core::matrix4 Transformation;
};
//! Vertex manipulator which scales the TCoords of the vertex
class SVertexTCoordsScaleManipulator : public IVertexManipulator
{
public:
SVertexTCoordsScaleManipulator(const core::vector2df& factor, u32 uvSet=1) : Factor(factor), UVSet(uvSet) {}
void operator()(video::S3DVertex2TCoords& vertex) const
{
if (1==UVSet)
vertex.TCoords *= Factor;
else if (2==UVSet)
vertex.TCoords2 *= Factor;
}
template <typename VType>
void operator()(VType& vertex) const
{
if (1==UVSet)
vertex.TCoords *= Factor;
}
private:
core::vector2df Factor;
u32 UVSet;
};
} // end namespace scene
} // end namespace irr
#endif
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "CMeshBuffer.h" #include "CMeshBuffer.h"
#include "SAnimatedMesh.h" #include "SAnimatedMesh.h"
#include "os.h" #include "os.h"
#include "irrMap.h"
namespace irr namespace irr
{ {
...@@ -60,86 +61,6 @@ void CMeshManipulator::flipSurfaces(scene::IMesh* mesh) const ...@@ -60,86 +61,6 @@ void CMeshManipulator::flipSurfaces(scene::IMesh* mesh) const
} }
//! Sets the alpha vertex color value of the whole mesh to a new value
//! \param mesh: Mesh on which the operation is performed.
void CMeshManipulator::setVertexColorAlpha(scene::IMesh* mesh, s32 alpha) const
{
if (!mesh)
return;
u32 i;
const u32 bcount = mesh->getMeshBufferCount();
for ( u32 b=0; b<bcount; ++b)
{
IMeshBuffer* buffer = mesh->getMeshBuffer(b);
void* v = buffer->getVertices();
u32 vtxcnt = buffer->getVertexCount();
switch(buffer->getVertexType())
{
case video::EVT_STANDARD:
{
for ( i=0; i<vtxcnt; ++i)
((video::S3DVertex*)v)[i].Color.setAlpha(alpha);
}
break;
case video::EVT_2TCOORDS:
{
for ( i=0; i<vtxcnt; ++i)
((video::S3DVertex2TCoords*)v)[i].Color.setAlpha(alpha);
}
break;
case video::EVT_TANGENTS:
{
for ( i=0; i<vtxcnt; ++i)
((video::S3DVertexTangents*)v)[i].Color.setAlpha(alpha);
}
break;
}
}
}
//! Sets the colors of all vertices to one color
void CMeshManipulator::setVertexColors(IMesh* mesh, video::SColor color) const
{
if (!mesh)
return;
const u32 bcount = mesh->getMeshBufferCount();
for (u32 b=0; b<bcount; ++b)
{
IMeshBuffer* buffer = mesh->getMeshBuffer(b);
void* v = buffer->getVertices();
const u32 vtxcnt = buffer->getVertexCount();
u32 i;
switch(buffer->getVertexType())
{
case video::EVT_STANDARD:
{
for ( i=0; i<vtxcnt; ++i)
((video::S3DVertex*)v)[i].Color = color;
}
break;
case video::EVT_2TCOORDS:
{
for ( i=0; i<vtxcnt; ++i)
((video::S3DVertex2TCoords*)v)[i].Color = color;
}
break;
case video::EVT_TANGENTS:
{
for ( i=0; i<vtxcnt; ++i)
((video::S3DVertexTangents*)v)[i].Color = color;
}
break;
}
}
}
//! Recalculates all normals of the mesh buffer. //! Recalculates all normals of the mesh buffer.
/** \param buffer: Mesh buffer on which the operation is performed. */ /** \param buffer: Mesh buffer on which the operation is performed. */
void CMeshManipulator::recalculateNormals(IMeshBuffer* buffer, bool smooth, bool angleWeighted) const void CMeshManipulator::recalculateNormals(IMeshBuffer* buffer, bool smooth, bool angleWeighted) const
...@@ -205,143 +126,6 @@ void CMeshManipulator::recalculateNormals(scene::IMesh* mesh, bool smooth, bool ...@@ -205,143 +126,6 @@ void CMeshManipulator::recalculateNormals(scene::IMesh* mesh, bool smooth, bool
} }
//! Applies a transformation
/** \param buffer: Meshbuffer on which the operation is performed.
\param m: matrix. */
void CMeshManipulator::transform(scene::IMeshBuffer* buffer, const core::matrix4& m) const
{
const u32 vtxcnt = buffer->getVertexCount();
if (!vtxcnt)
return;
core::aabbox3df bufferbox;
// first transform
{
m.transformVect(buffer->getPosition(0));
m.rotateVect(buffer->getNormal(0));
buffer->getNormal(0).normalize();
bufferbox.reset(buffer->getPosition(0));
}
for ( u32 i=1 ;i < vtxcnt; ++i)
{
m.transformVect(buffer->getPosition(i));
m.rotateVect(buffer->getNormal(i));
buffer->getNormal(i).normalize();
bufferbox.addInternalPoint(buffer->getPosition(i));
}
buffer->setBoundingBox(bufferbox);
}
//! Applies a transformation
/** \param mesh: Mesh on which the operation is performed.
\param m: matrix. */
void CMeshManipulator::transform(scene::IMesh* mesh, const core::matrix4& m) const
{
if (!mesh)
return;
core::aabbox3df meshbox;
const u32 bcount = mesh->getMeshBufferCount();
for ( u32 b=0; b<bcount; ++b)
{
IMeshBuffer* buffer = mesh->getMeshBuffer(b);
transform(buffer, m);
if (b == 0)
meshbox.reset(buffer->getBoundingBox());
else
meshbox.addInternalBox(buffer->getBoundingBox());
}
mesh->setBoundingBox( meshbox );
}
//! Scales the actual mesh, not a scene node.
void CMeshManipulator::scale(scene::IMesh* mesh, const core::vector3df& factor) const
{
if (!mesh)
return;
core::aabbox3df meshbox;
const u32 bcount = mesh->getMeshBufferCount();
for ( u32 b=0; b<bcount; ++b)
{
IMeshBuffer* buffer = mesh->getMeshBuffer(b);
scale(buffer, factor);
if (b == 0)
meshbox.reset(buffer->getBoundingBox());
else
meshbox.addInternalBox(buffer->getBoundingBox());
}
mesh->setBoundingBox( meshbox );
}
//! Scales the actual meshbuffer, not a scene node.
void CMeshManipulator::scale(scene::IMeshBuffer* buffer, const core::vector3df& factor) const
{
if (!buffer)
return;
const u32 vtxcnt = buffer->getVertexCount();
core::aabbox3df bufferbox;
if (vtxcnt != 0)
bufferbox.reset(buffer->getPosition(0) * factor);
for (u32 i=0; i<vtxcnt; ++i)
{
buffer->getPosition(i) *= factor;
bufferbox.addInternalPoint(buffer->getPosition(i));
}
buffer->setBoundingBox(bufferbox);
}
//! Scale the texture coords of a mesh.
void CMeshManipulator::scaleTCoords(scene::IMesh* mesh, const core::vector2df& factor, u32 layer) const
{
if (!mesh)
return;
const u32 bcount = mesh->getMeshBufferCount();
for (u32 b=0; b<bcount; ++b)
scaleTCoords(mesh->getMeshBuffer(b), factor, layer);
}
//! Scale the level-th texture coords of a meshbuffer.
void CMeshManipulator::scaleTCoords(scene::IMeshBuffer* buffer, const core::vector2df& factor, u32 level) const
{
if (!buffer || ((level>1) && (buffer->getVertexType() != video::EVT_2TCOORDS)))
return;
const u32 vtxcnt = buffer->getVertexCount();
if (level==1)
{
for (u32 i=0; i<vtxcnt; ++i)
buffer->getTCoords(i) *= factor;
}
else
{
for (u32 i=0; i<vtxcnt; ++i)
((SMeshBufferLightMap*)buffer)->Vertices[i].TCoords2 *= factor;
}
}
//! Clones a static IMesh into a modifyable SMesh. //! Clones a static IMesh into a modifyable SMesh.
SMesh* CMeshManipulator::createMeshCopy(scene::IMesh* mesh) const SMesh* CMeshManipulator::createMeshCopy(scene::IMesh* mesh) const
{ {
...@@ -1099,57 +883,64 @@ IMesh* CMeshManipulator::createMeshWith1TCoords(IMesh* mesh) const ...@@ -1099,57 +883,64 @@ IMesh* CMeshManipulator::createMeshWith1TCoords(IMesh* mesh) const
for (b=0; b<meshBufferCount; ++b) for (b=0; b<meshBufferCount; ++b)
{ {
const u32 idxCnt = mesh->getMeshBuffer(b)->getIndexCount(); const IMeshBuffer* original = mesh->getMeshBuffer(b);
const u16* idx = mesh->getMeshBuffer(b)->getIndices(); const u32 idxCnt = original->getIndexCount();
const u16* idx = original->getIndices();
SMeshBuffer* buffer = new SMeshBuffer(); SMeshBuffer* buffer = new SMeshBuffer();
buffer->Material = mesh->getMeshBuffer(b)->getMaterial(); buffer->Material = original->getMaterial();
buffer->Vertices.reallocate(idxCnt);
buffer->Indices.set_used(idxCnt);
// copy vertices core::map<video::S3DVertex, int> vertMap;
int vertLocation;
buffer->Vertices.reallocate(idxCnt); // copy vertices
switch(mesh->getMeshBuffer(b)->getVertexType()) const video::E_VERTEX_TYPE vType = original->getVertexType();
video::S3DVertex vNew;
for (u32 i=0; i<idxCnt; ++i)
{ {
case video::EVT_STANDARD: switch(vType)
{ {
video::S3DVertex* v = case video::EVT_STANDARD:
(video::S3DVertex*)mesh->getMeshBuffer(b)->getVertices(); {
video::S3DVertex* v =
for (u32 i=0; i<idxCnt; ++i) (video::S3DVertex*)original->getVertices();
buffer->Vertices.push_back(v[idx[i]]); vNew = v[idx[i]];
}
break;
case video::EVT_2TCOORDS:
{
video::S3DVertex2TCoords* v =
(video::S3DVertex2TCoords*)original->getVertices();
vNew = video::S3DVertex(
v[idx[i]].Pos, v[idx[i]].Normal, v[idx[i]].Color, v[idx[i]].TCoords);
}
break;
case video::EVT_TANGENTS:
{
video::S3DVertexTangents* v =
(video::S3DVertexTangents*)original->getVertices();
vNew = video::S3DVertex(
v[idx[i]].Pos, v[idx[i]].Normal, v[idx[i]].Color, v[idx[i]].TCoords);
}
break;
} }
break; core::map<video::S3DVertex, int>::Node* n = vertMap.find(vNew);
case video::EVT_2TCOORDS: if (n)
{ {
video::S3DVertex2TCoords* v = vertLocation = n->getValue();
(video::S3DVertex2TCoords*)mesh->getMeshBuffer(b)->getVertices();
for (u32 i=0; i<idxCnt; ++i)
buffer->Vertices.push_back(
video::S3DVertex(
v[idx[i]].Pos, v[idx[i]].Normal, v[idx[i]].Color, v[idx[i]].TCoords));
} }
break; else
case video::EVT_TANGENTS:
{ {
video::S3DVertexTangents* v = vertLocation = buffer->Vertices.size();
(video::S3DVertexTangents*)mesh->getMeshBuffer(b)->getVertices(); buffer->Vertices.push_back(vNew);
vertMap.insert(vNew, vertLocation);
for (u32 i=0; i<idxCnt; ++i)
buffer->Vertices.push_back(
video::S3DVertex(
v[idx[i]].Pos, v[idx[i]].Normal, v[idx[i]].Color, v[idx[i]].TCoords));
} }
break;
}
// create new indices
buffer->Indices.set_used(idxCnt); // create new indices
for (u32 i=0; i<idxCnt; ++i) buffer->Indices[i] = vertLocation;
buffer->Indices[i] = i; }
//buffer->setBoundingBox(mesh->getMeshBuffer(b)->getBoundingBox()); //buffer->setBoundingBox(mesh->getMeshBuffer(b)->getBoundingBox());
buffer->recalculateBoundingBox (); buffer->recalculateBoundingBox ();
...@@ -1159,9 +950,7 @@ IMesh* CMeshManipulator::createMeshWith1TCoords(IMesh* mesh) const ...@@ -1159,9 +950,7 @@ IMesh* CMeshManipulator::createMeshWith1TCoords(IMesh* mesh) const
buffer->drop(); buffer->drop();
} }
clone->recalculateBoundingBox (); clone->recalculateBoundingBox();
//clone->BoundingBox = mesh->getBoundingBox();
return clone; return clone;
} }
......
...@@ -25,14 +25,6 @@ public: ...@@ -25,14 +25,6 @@ public:
\param mesh: Mesh on which the operation is performed. */ \param mesh: Mesh on which the operation is performed. */
virtual void flipSurfaces(scene::IMesh* mesh) const; virtual void flipSurfaces(scene::IMesh* mesh) const;
//! Sets the alpha vertex color value of the whole mesh to a new value
/** \param mesh: Mesh on which the operation is performed.
\param alpha: New alpha for the vertex color. */
virtual void setVertexColorAlpha(scene::IMesh* mesh, s32 alpha) const;
//! Sets the colors of all vertices to one color
virtual void setVertexColors(IMesh* mesh, video::SColor color) const;
//! Recalculates all normals of the mesh. //! Recalculates all normals of the mesh.
/** \param mesh: Mesh on which the operation is performed. /** \param mesh: Mesh on which the operation is performed.
\param smooth: Whether to use smoothed normals. */ \param smooth: Whether to use smoothed normals. */
...@@ -43,38 +35,6 @@ public: ...@@ -43,38 +35,6 @@ public:
\param smooth: Whether to use smoothed normals. */ \param smooth: Whether to use smoothed normals. */
virtual void recalculateNormals(IMeshBuffer* buffer, bool smooth = false, bool angleWeighted = false) const; virtual void recalculateNormals(IMeshBuffer* buffer, bool smooth = false, bool angleWeighted = false) const;
//! Scales the actual mesh, not the scene node.
/** \param mesh Mesh on which the operation is performed.
\param factor Vector which defines the scale for each axis. */
virtual void scale(scene::IMesh* mesh, const core::vector3df& factor) const;
//! Scales the actual meshbuffer, not the scene node.
/** \param buffer MeshBuffer on which the operation is performed.
\param factor Vector which defines the scale for each axis. */
virtual void scale(scene::IMeshBuffer* buffer, const core::vector3df& factor) const;
//! Scale the texture coords of a mesh.
/** \param mesh Mesh on which the operation is performed.
\param factor Vector which defines the scale for each axis.
\param level Number of texture coord, starting from 1. Support for level 2 exists for LightMap buffers. */
virtual void scaleTCoords(scene::IMesh* mesh, const core::vector2df& factor, u32 layer=1) const;
//! Scale the texture coords of a meshbuffer.
/** \param mesh Mesh on which the operation is performed.
\param factor Vector which defines the scale for each axis.
\param level Number of texture coord, starting from 1. Support for level 2 exists for LightMap buffers. */
virtual void scaleTCoords(scene::IMeshBuffer* buffer, const core::vector2df& factor, u32 level=1) const;
//! Applies a transformation to a meshbuffer
/** \param buffer: Meshbuffer on which the operation is performed.
\param m: matrix. */
void transform(scene::IMeshBuffer* buffer, const core::matrix4& m) const;
//! Applies a transformation to a mesh
/** \param mesh: Mesh on which the operation is performed.
\param m: transformation matrix. */
virtual void transform(scene::IMesh* mesh, const core::matrix4& m) const;
//! Clones a static IMesh into a modifiable SMesh. //! Clones a static IMesh into a modifiable SMesh.
virtual SMesh* createMeshCopy(scene::IMesh* mesh) const; virtual SMesh* createMeshCopy(scene::IMesh* mesh) const;
...@@ -129,4 +89,3 @@ private: ...@@ -129,4 +89,3 @@ private:
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment