Fix createMeshCopy to apply the original materials to new copy as well, as pointed out by tonic.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3631 dfc29bdd-3216-0410-991c-e03cc46cb475
master
hybrid 2011-04-12 11:49:32 +00:00
parent b314794eb5
commit 3d14880c0d
1 changed files with 55 additions and 49 deletions

View File

@ -299,19 +299,21 @@ SMesh* CMeshManipulator::createMeshCopy(scene::IMesh* mesh) const
for ( u32 b=0; b<meshBufferCount; ++b) for ( u32 b=0; b<meshBufferCount; ++b)
{ {
switch(mesh->getMeshBuffer(b)->getVertexType()) const IMeshBuffer* const mb = mesh->getMeshBuffer(b);
switch(mb->getVertexType())
{ {
case video::EVT_STANDARD: case video::EVT_STANDARD:
{ {
SMeshBuffer* buffer = new SMeshBuffer(); SMeshBuffer* buffer = new SMeshBuffer();
const u32 vcount = mesh->getMeshBuffer(b)->getVertexCount(); buffer->Material = mb->getMaterial();
const u32 vcount = mb->getVertexCount();
buffer->Vertices.reallocate(vcount); buffer->Vertices.reallocate(vcount);
video::S3DVertex* vertices = (video::S3DVertex*)mesh->getMeshBuffer(b)->getVertices(); video::S3DVertex* vertices = (video::S3DVertex*)mb->getVertices();
for (u32 i=0; i < vcount; ++i) for (u32 i=0; i < vcount; ++i)
buffer->Vertices.push_back(vertices[i]); buffer->Vertices.push_back(vertices[i]);
const u32 icount = mesh->getMeshBuffer(b)->getIndexCount(); const u32 icount = mb->getIndexCount();
buffer->Indices.reallocate(icount); buffer->Indices.reallocate(icount);
u16* indices = mesh->getMeshBuffer(b)->getIndices(); const u16* indices = mb->getIndices();
for (u32 i=0; i < icount; ++i) for (u32 i=0; i < icount; ++i)
buffer->Indices.push_back(indices[i]); buffer->Indices.push_back(indices[i]);
clone->addMeshBuffer(buffer); clone->addMeshBuffer(buffer);
@ -321,14 +323,15 @@ SMesh* CMeshManipulator::createMeshCopy(scene::IMesh* mesh) const
case video::EVT_2TCOORDS: case video::EVT_2TCOORDS:
{ {
SMeshBufferLightMap* buffer = new SMeshBufferLightMap(); SMeshBufferLightMap* buffer = new SMeshBufferLightMap();
const u32 vcount = mesh->getMeshBuffer(b)->getVertexCount(); buffer->Material = mb->getMaterial();
const u32 vcount = mb->getVertexCount();
buffer->Vertices.reallocate(vcount); buffer->Vertices.reallocate(vcount);
video::S3DVertex2TCoords* vertices = (video::S3DVertex2TCoords*)mesh->getMeshBuffer(b)->getVertices(); video::S3DVertex2TCoords* vertices = (video::S3DVertex2TCoords*)mb->getVertices();
for (u32 i=0; i < vcount; ++i) for (u32 i=0; i < vcount; ++i)
buffer->Vertices.push_back(vertices[i]); buffer->Vertices.push_back(vertices[i]);
const u32 icount = mesh->getMeshBuffer(b)->getIndexCount(); const u32 icount = mb->getIndexCount();
buffer->Indices.reallocate(icount); buffer->Indices.reallocate(icount);
u16* indices = mesh->getMeshBuffer(b)->getIndices(); const u16* indices = mb->getIndices();
for (u32 i=0; i < icount; ++i) for (u32 i=0; i < icount; ++i)
buffer->Indices.push_back(indices[i]); buffer->Indices.push_back(indices[i]);
clone->addMeshBuffer(buffer); clone->addMeshBuffer(buffer);
@ -338,14 +341,15 @@ SMesh* CMeshManipulator::createMeshCopy(scene::IMesh* mesh) const
case video::EVT_TANGENTS: case video::EVT_TANGENTS:
{ {
SMeshBufferTangents* buffer = new SMeshBufferTangents(); SMeshBufferTangents* buffer = new SMeshBufferTangents();
const u32 vcount = mesh->getMeshBuffer(b)->getVertexCount(); buffer->Material = mb->getMaterial();
const u32 vcount = mb->getVertexCount();
buffer->Vertices.reallocate(vcount); buffer->Vertices.reallocate(vcount);
video::S3DVertexTangents* vertices = (video::S3DVertexTangents*)mesh->getMeshBuffer(b)->getVertices(); video::S3DVertexTangents* vertices = (video::S3DVertexTangents*)mb->getVertices();
for (u32 i=0; i < vcount; ++i) for (u32 i=0; i < vcount; ++i)
buffer->Vertices.push_back(vertices[i]); buffer->Vertices.push_back(vertices[i]);
const u32 icount = mesh->getMeshBuffer(b)->getIndexCount(); const u32 icount = mb->getIndexCount();
buffer->Indices.reallocate(icount); buffer->Indices.reallocate(icount);
u16* indices = mesh->getMeshBuffer(b)->getIndices(); const u16* indices = mb->getIndices();
for (u32 i=0; i < icount; ++i) for (u32 i=0; i < icount; ++i)
buffer->Indices.push_back(indices[i]); buffer->Indices.push_back(indices[i]);
clone->addMeshBuffer(buffer); clone->addMeshBuffer(buffer);
@ -467,18 +471,19 @@ IMesh* CMeshManipulator::createMeshUniquePrimitives(IMesh* mesh) const
for ( u32 b=0; b<meshBufferCount; ++b) for ( u32 b=0; b<meshBufferCount; ++b)
{ {
const s32 idxCnt = mesh->getMeshBuffer(b)->getIndexCount(); const IMeshBuffer* const mb = mesh->getMeshBuffer(b);
const u16* idx = mesh->getMeshBuffer(b)->getIndices(); const s32 idxCnt = mb->getIndexCount();
const u16* idx = mb->getIndices();
switch(mesh->getMeshBuffer(b)->getVertexType()) switch(mb->getVertexType())
{ {
case video::EVT_STANDARD: case video::EVT_STANDARD:
{ {
SMeshBuffer* buffer = new SMeshBuffer(); SMeshBuffer* buffer = new SMeshBuffer();
buffer->Material = mesh->getMeshBuffer(b)->getMaterial(); buffer->Material = mb->getMaterial();
video::S3DVertex* v = video::S3DVertex* v =
(video::S3DVertex*)mesh->getMeshBuffer(b)->getVertices(); (video::S3DVertex*)mb->getVertices();
buffer->Vertices.reallocate(idxCnt); buffer->Vertices.reallocate(idxCnt);
buffer->Indices.reallocate(idxCnt); buffer->Indices.reallocate(idxCnt);
@ -493,7 +498,7 @@ IMesh* CMeshManipulator::createMeshUniquePrimitives(IMesh* mesh) const
buffer->Indices.push_back( i + 2 ); buffer->Indices.push_back( i + 2 );
} }
buffer->setBoundingBox(mesh->getMeshBuffer(b)->getBoundingBox()); buffer->setBoundingBox(mb->getBoundingBox());
clone->addMeshBuffer(buffer); clone->addMeshBuffer(buffer);
buffer->drop(); buffer->drop();
} }
@ -501,10 +506,10 @@ IMesh* CMeshManipulator::createMeshUniquePrimitives(IMesh* mesh) const
case video::EVT_2TCOORDS: case video::EVT_2TCOORDS:
{ {
SMeshBufferLightMap* buffer = new SMeshBufferLightMap(); SMeshBufferLightMap* buffer = new SMeshBufferLightMap();
buffer->Material = mesh->getMeshBuffer(b)->getMaterial(); buffer->Material = mb->getMaterial();
video::S3DVertex2TCoords* v = video::S3DVertex2TCoords* v =
(video::S3DVertex2TCoords*)mesh->getMeshBuffer(b)->getVertices(); (video::S3DVertex2TCoords*)mb->getVertices();
buffer->Vertices.reallocate(idxCnt); buffer->Vertices.reallocate(idxCnt);
buffer->Indices.reallocate(idxCnt); buffer->Indices.reallocate(idxCnt);
@ -518,7 +523,7 @@ IMesh* CMeshManipulator::createMeshUniquePrimitives(IMesh* mesh) const
buffer->Indices.push_back( i + 1 ); buffer->Indices.push_back( i + 1 );
buffer->Indices.push_back( i + 2 ); buffer->Indices.push_back( i + 2 );
} }
buffer->setBoundingBox(mesh->getMeshBuffer(b)->getBoundingBox()); buffer->setBoundingBox(mb->getBoundingBox());
clone->addMeshBuffer(buffer); clone->addMeshBuffer(buffer);
buffer->drop(); buffer->drop();
} }
@ -526,10 +531,10 @@ IMesh* CMeshManipulator::createMeshUniquePrimitives(IMesh* mesh) const
case video::EVT_TANGENTS: case video::EVT_TANGENTS:
{ {
SMeshBufferTangents* buffer = new SMeshBufferTangents(); SMeshBufferTangents* buffer = new SMeshBufferTangents();
buffer->Material = mesh->getMeshBuffer(b)->getMaterial(); buffer->Material = mb->getMaterial();
video::S3DVertexTangents* v = video::S3DVertexTangents* v =
(video::S3DVertexTangents*)mesh->getMeshBuffer(b)->getVertices(); (video::S3DVertexTangents*)mb->getVertices();
buffer->Vertices.reallocate(idxCnt); buffer->Vertices.reallocate(idxCnt);
buffer->Indices.reallocate(idxCnt); buffer->Indices.reallocate(idxCnt);
@ -544,7 +549,7 @@ IMesh* CMeshManipulator::createMeshUniquePrimitives(IMesh* mesh) const
buffer->Indices.push_back( i + 2 ); buffer->Indices.push_back( i + 2 );
} }
buffer->setBoundingBox(mesh->getMeshBuffer(b)->getBoundingBox()); buffer->setBoundingBox(mb->getBoundingBox());
clone->addMeshBuffer(buffer); clone->addMeshBuffer(buffer);
buffer->drop(); buffer->drop();
} }
@ -567,30 +572,31 @@ IMesh* CMeshManipulator::createMeshWelded(IMesh *mesh, f32 tolerance) const
for (u32 b=0; b<mesh->getMeshBufferCount(); ++b) for (u32 b=0; b<mesh->getMeshBufferCount(); ++b)
{ {
const IMeshBuffer* const mb = mesh->getMeshBuffer(b);
// reset redirect list // reset redirect list
redirects.set_used(mesh->getMeshBuffer(b)->getVertexCount()); redirects.set_used(mb->getVertexCount());
u16* indices = 0; const u16* indices = 0;
u32 indexCount = 0; u32 indexCount = 0;
core::array<u16>* outIdx = 0; core::array<u16>* outIdx = 0;
switch(mesh->getMeshBuffer(b)->getVertexType()) switch(mb->getVertexType())
{ {
case video::EVT_STANDARD: case video::EVT_STANDARD:
{ {
SMeshBuffer* buffer = new SMeshBuffer(); SMeshBuffer* buffer = new SMeshBuffer();
buffer->BoundingBox = mesh->getMeshBuffer(b)->getBoundingBox(); buffer->BoundingBox = mb->getBoundingBox();
buffer->Material = mesh->getMeshBuffer(b)->getMaterial(); buffer->Material = mb->getMaterial();
clone->addMeshBuffer(buffer); clone->addMeshBuffer(buffer);
buffer->drop(); buffer->drop();
video::S3DVertex* v = video::S3DVertex* v =
(video::S3DVertex*)mesh->getMeshBuffer(b)->getVertices(); (video::S3DVertex*)mb->getVertices();
u32 vertexCount = mesh->getMeshBuffer(b)->getVertexCount(); u32 vertexCount = mb->getVertexCount();
indices = mesh->getMeshBuffer(b)->getIndices(); indices = mb->getIndices();
indexCount = mesh->getMeshBuffer(b)->getIndexCount(); indexCount = mb->getIndexCount();
outIdx = &buffer->Indices; outIdx = &buffer->Indices;
buffer->Vertices.reallocate(vertexCount); buffer->Vertices.reallocate(vertexCount);
@ -622,18 +628,18 @@ IMesh* CMeshManipulator::createMeshWelded(IMesh *mesh, f32 tolerance) const
case video::EVT_2TCOORDS: case video::EVT_2TCOORDS:
{ {
SMeshBufferLightMap* buffer = new SMeshBufferLightMap(); SMeshBufferLightMap* buffer = new SMeshBufferLightMap();
buffer->BoundingBox = mesh->getMeshBuffer(b)->getBoundingBox(); buffer->BoundingBox = mb->getBoundingBox();
buffer->Material = mesh->getMeshBuffer(b)->getMaterial(); buffer->Material = mb->getMaterial();
clone->addMeshBuffer(buffer); clone->addMeshBuffer(buffer);
buffer->drop(); buffer->drop();
video::S3DVertex2TCoords* v = video::S3DVertex2TCoords* v =
(video::S3DVertex2TCoords*)mesh->getMeshBuffer(b)->getVertices(); (video::S3DVertex2TCoords*)mb->getVertices();
u32 vertexCount = mesh->getMeshBuffer(b)->getVertexCount(); u32 vertexCount = mb->getVertexCount();
indices = mesh->getMeshBuffer(b)->getIndices(); indices = mb->getIndices();
indexCount = mesh->getMeshBuffer(b)->getIndexCount(); indexCount = mb->getIndexCount();
outIdx = &buffer->Indices; outIdx = &buffer->Indices;
buffer->Vertices.reallocate(vertexCount); buffer->Vertices.reallocate(vertexCount);
@ -665,18 +671,18 @@ IMesh* CMeshManipulator::createMeshWelded(IMesh *mesh, f32 tolerance) const
case video::EVT_TANGENTS: case video::EVT_TANGENTS:
{ {
SMeshBufferTangents* buffer = new SMeshBufferTangents(); SMeshBufferTangents* buffer = new SMeshBufferTangents();
buffer->BoundingBox = mesh->getMeshBuffer(b)->getBoundingBox(); buffer->BoundingBox = mb->getBoundingBox();
buffer->Material = mesh->getMeshBuffer(b)->getMaterial(); buffer->Material = mb->getMaterial();
clone->addMeshBuffer(buffer); clone->addMeshBuffer(buffer);
buffer->drop(); buffer->drop();
video::S3DVertexTangents* v = video::S3DVertexTangents* v =
(video::S3DVertexTangents*)mesh->getMeshBuffer(b)->getVertices(); (video::S3DVertexTangents*)mb->getVertices();
u32 vertexCount = mesh->getMeshBuffer(b)->getVertexCount(); u32 vertexCount = mb->getVertexCount();
indices = mesh->getMeshBuffer(b)->getIndices(); indices = mb->getIndices();
indexCount = mesh->getMeshBuffer(b)->getIndexCount(); indexCount = mb->getIndexCount();
outIdx = &buffer->Indices; outIdx = &buffer->Indices;
buffer->Vertices.reallocate(vertexCount); buffer->Vertices.reallocate(vertexCount);
@ -737,7 +743,7 @@ IMesh* CMeshManipulator::createMeshWithTangents(IMesh* mesh, bool recalculateNor
for (u32 b=0; b<meshBufferCount; ++b) for (u32 b=0; b<meshBufferCount; ++b)
{ {
const IMeshBuffer* original = mesh->getMeshBuffer(b); const IMeshBuffer* const original = mesh->getMeshBuffer(b);
const u32 idxCnt = original->getIndexCount(); const u32 idxCnt = original->getIndexCount();
const u16* idx = original->getIndices(); const u16* idx = original->getIndices();
@ -825,7 +831,7 @@ IMesh* CMeshManipulator::createMeshWith2TCoords(IMesh* mesh) const
for (u32 b=0; b<meshBufferCount; ++b) for (u32 b=0; b<meshBufferCount; ++b)
{ {
const IMeshBuffer* original = mesh->getMeshBuffer(b); const IMeshBuffer* const original = mesh->getMeshBuffer(b);
const u32 idxCnt = original->getIndexCount(); const u32 idxCnt = original->getIndexCount();
const u16* idx = original->getIndices(); const u16* idx = original->getIndices();
@ -907,7 +913,7 @@ IMesh* CMeshManipulator::createMeshWith1TCoords(IMesh* mesh) const
for (u32 b=0; b<meshBufferCount; ++b) for (u32 b=0; b<meshBufferCount; ++b)
{ {
const IMeshBuffer* original = mesh->getMeshBuffer(b); const IMeshBuffer* const original = mesh->getMeshBuffer(b);
const u32 idxCnt = original->getIndexCount(); const u32 idxCnt = original->getIndexCount();
const u16* idx = original->getIndices(); const u16* idx = original->getIndices();