Added a Mesh to 2TCoords converter.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1010 dfc29bdd-3216-0410-991c-e03cc46cb475
master
hybrid 2007-09-28 21:11:30 +00:00
parent aa9b94b3ca
commit e7393eddc7
5 changed files with 99 additions and 9 deletions

View File

@ -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;

View File

@ -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
*

View File

@ -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; i<vtxCnt; ++i)
buffer->Vertices.push_back(v[i]);
buffer->Indices.reallocate(idxCnt);
for (i=0; i<idxCnt; ++i)
buffer->Indices.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; i<vtxCnt; ++i)
buffer->Vertices.push_back(v[i]);
buffer->Indices.reallocate(idxCnt);
for (i=0; i<idxCnt; ++i)
buffer->Indices.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; i<vtxCnt; ++i)
buffer->Vertices.push_back(v[i]);
buffer->Indices.reallocate(idxCnt);
for (i=0; i<idxCnt; ++i)
buffer->Indices.push_back(idx[i]);
@ -538,7 +544,7 @@ IMesh* CMeshManipulator::createMeshUniquePrimitives(IMesh* mesh) const
for ( u32 b=0; b<meshBufferCount; ++b)
{
s32 idxCnt = mesh->getMeshBuffer(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; i<idxCnt; i += 3)
{
buffer->Vertices.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; i<idxCnt; i += 3)
{
buffer->Vertices.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; i<idxCnt; i += 3)
{
buffer->Vertices.push_back( v[idx[i + 0 ]] );
@ -800,7 +812,7 @@ IMesh* CMeshManipulator::createMeshWithTangents(IMesh* mesh) const
for (b=0; b<meshBufferCount; ++b)
{
s32 idxCnt = mesh->getMeshBuffer(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; b<meshBufferCount; ++b)
{
s32 idxCnt = clone->getMeshBuffer(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; b<meshBufferCount; ++b)
{
const s32 idxCnt = mesh->getMeshBuffer(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; i<idxCnt; ++i)
buffer->Vertices.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; i<idxCnt; ++i)
buffer->Vertices.push_back(v[idx[i]]);
}
break;
case video::EVT_TANGENTS:
{
video::S3DVertexTangents* v =
(video::S3DVertexTangents*)mesh->getMeshBuffer(b)->getVertices();
for (s32 i=0; i<idxCnt; ++i)
buffer->Vertices.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; i<idxCnt; ++i)
buffer->Indices[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,

View File

@ -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;

View File

@ -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_