Commit 960be376 authored by cutealien's avatar cutealien

CTriangleSelector now supports 32-bit meshbuffers. Thanks @Wol101 for reporting and patch-proposal.

I used another patch which complicates the code somewhat, but old solution was too slow for my taste.
This should now speedup CTriangleSelector for animated meshes which call updateFromMesh regularly.
Also a fix: CTriangleSelector no longer resets it's boundingbox to 0,0,0 (that caused too large meshbuffers when a meshbuffer was not around 0), so basically also just a speedup.


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@5304 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 2c641594
--------------------------
Changes in 1.9 (not yet released)
- Speedup CTriangleSelector (mainly for animated meshes)
- CTriangleSelector now supports 32-bit meshbuffers. Thanks @Wol101 for reporting and patch-proposal.
- Fix: CTriangleSelector no longer resets it's boundingbox to 0,0,0 (was wrong when a meshbuffer was not around 0)
- Fix: Collada writer now uses wrap_p for third texture wrap value instead of invalid wrap_w (thx @Yoran for bugreport)
- Several getter functions in IAttributes made const (thx @Erik Schultheis for the patch)
- Fix: CTriangleSelector no longer ignores meshbuffer transformations from skinned meshes (thx @AlexAzazel for report and test-model).
......
......@@ -84,6 +84,30 @@ void CTriangleSelector::createFromMesh(const IMesh* mesh)
updateFromMesh(mesh);
}
template <typename TIndex>
static void updateTriangles(u32& triangleCount, core::array<core::triangle3df>& triangles, u32 idxCnt, const TIndex* indices, const u8* vertices, u32 vertexPitch, const core::matrix4* bufferTransform)
{
if ( bufferTransform )
{
for (u32 index = 0; index < idxCnt; index += 3)
{
core::triangle3df& tri = triangles[triangleCount++];
bufferTransform->transformVect( tri.pointA, (*reinterpret_cast<const video::S3DVertex*>(&vertices[indices[index + 0]*vertexPitch])).Pos );
bufferTransform->transformVect( tri.pointB, (*reinterpret_cast<const video::S3DVertex*>(&vertices[indices[index + 1]*vertexPitch])).Pos );
bufferTransform->transformVect( tri.pointC, (*reinterpret_cast<const video::S3DVertex*>(&vertices[indices[index + 2]*vertexPitch])).Pos );
}
}
else
{
for (u32 index = 0; index < idxCnt; index += 3)
{
core::triangle3df& tri = triangles[triangleCount++];
tri.pointA = (*reinterpret_cast<const video::S3DVertex*>(&vertices[indices[index + 0]*vertexPitch])).Pos;
tri.pointB = (*reinterpret_cast<const video::S3DVertex*>(&vertices[indices[index + 1]*vertexPitch])).Pos;
tri.pointC = (*reinterpret_cast<const video::S3DVertex*>(&vertices[indices[index + 2]*vertexPitch])).Pos;
}
}
}
void CTriangleSelector::updateFromMesh(const IMesh* mesh) const
{
......@@ -94,40 +118,53 @@ void CTriangleSelector::updateFromMesh(const IMesh* mesh) const
u32 meshBuffers = mesh->getMeshBufferCount();
u32 triangleCount = 0;
BoundingBox.reset(0.f, 0.f, 0.f);
for (u32 i = 0; i < meshBuffers; ++i)
{
IMeshBuffer* buf = mesh->getMeshBuffer(i);
u32 idxCnt = buf->getIndexCount();
const u16* indices = buf->getIndices();
u32 vertexPitch = getVertexPitchFromType(buf->getVertexType());
u8* vertices = (u8*)buf->getVertices();
const core::matrix4* bufferTransform = 0;
if ( skinnnedMesh )
{
const core::matrix4& bufferTransform = ((scene::SSkinMeshBuffer*)buf)->Transformation;
for (u32 index = 0; index < idxCnt; index += 3)
bufferTransform = &(((scene::SSkinMeshBuffer*)buf)->Transformation);
if ( bufferTransform->isIdentity() )
bufferTransform = 0;
}
switch ( buf->getIndexType() )
{
core::triangle3df& tri = Triangles[triangleCount++];
bufferTransform.transformVect(tri.pointA, buf->getPosition(indices[index + 0]));
bufferTransform.transformVect(tri.pointB, buf->getPosition(indices[index + 1]));
bufferTransform.transformVect(tri.pointC, buf->getPosition(indices[index + 2]));
BoundingBox.addInternalPoint(tri.pointA);
BoundingBox.addInternalPoint(tri.pointB);
BoundingBox.addInternalPoint(tri.pointC);
case video::EIT_16BIT:
{
const u16* indices = buf->getIndices();
updateTriangles(triangleCount, Triangles, idxCnt, indices, vertices, vertexPitch, bufferTransform);
}
break;
case video::EIT_32BIT:
{
const u32* indices = (u32*)buf->getIndices();
updateTriangles(triangleCount, Triangles, idxCnt, indices, vertices, vertexPitch, bufferTransform);
}
else
break;
}
}
// Update bounding box
if ( triangleCount )
{
for (u32 index = 0; index < idxCnt; index += 3)
BoundingBox.reset( Triangles[0].pointA );
for (u32 i=0; i < triangleCount; ++i)
{
core::triangle3df& tri = Triangles[triangleCount++];
tri.pointA = buf->getPosition(indices[index + 0]);
tri.pointB = buf->getPosition(indices[index + 1]);
tri.pointC = buf->getPosition(indices[index + 2]);
const core::triangle3df& tri = Triangles[i];
BoundingBox.addInternalPoint(tri.pointA);
BoundingBox.addInternalPoint(tri.pointB);
BoundingBox.addInternalPoint(tri.pointC);
}
}
else
{
BoundingBox.reset(0.f, 0.f, 0.f);
}
}
......
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