Commit fbb1d585 authored by hybrid's avatar hybrid

Make even more use of meshbuffer vertex access methods.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1091 dfc29bdd-3216-0410-991c-e03cc46cb475
parent f02c10a0
...@@ -17,48 +17,6 @@ namespace irr ...@@ -17,48 +17,6 @@ namespace irr
namespace scene namespace scene
{ {
//! Recalculates the normals in vertex array.
//! This template function was a member of the CMeshManipulator class, but
//! visual studio 6.0 didn't like it.
template<class VTXTYPE>
inline void recalculateNormalsT_Flat(VTXTYPE* v, int vtxcnt,
u16* idx, int idxcnt)
{
for (int i=0; i<idxcnt; i+=3)
{
const core::plane3d<f32> p(v[idx[i+0]].Pos, v[idx[i+1]].Pos, v[idx[i+2]].Pos);
v[idx[i+0]].Normal = p.Normal;
v[idx[i+1]].Normal = p.Normal;
v[idx[i+2]].Normal = p.Normal;
}
}
template<class VTXTYPE>
inline void recalculateNormalsT_Smooth(VTXTYPE* v, int vtxcnt,
u16* idx, int idxcnt)
{
s32 i;
for ( i = 0; i!= vtxcnt; ++i )
{
v[i].Normal.set ( 0.f, 0.f, 0.f );
}
for ( i=0; i<idxcnt; i+=3)
{
const core::plane3d<f32> p(v[idx[i+0]].Pos, v[idx[i+1]].Pos, v[idx[i+2]].Pos);
v[idx[i+0]].Normal += p.Normal;
v[idx[i+1]].Normal += p.Normal;
v[idx[i+2]].Normal += p.Normal;
}
for ( i = 0; i!= vtxcnt; ++i )
{
v[i].Normal.normalize ();
}
}
//! Recalculates normals in a vertex array.
//! This template function was a member of the CMeshManipulator class, but //! This template function was a member of the CMeshManipulator class, but
//! visual studio 6.0 didn't like it. //! visual studio 6.0 didn't like it.
template<class VERTEXTYPE> template<class VERTEXTYPE>
...@@ -219,41 +177,41 @@ void CMeshManipulator::recalculateNormals(IMeshBuffer* buffer, bool smooth) cons ...@@ -219,41 +177,41 @@ void CMeshManipulator::recalculateNormals(IMeshBuffer* buffer, bool smooth) cons
if (!buffer) if (!buffer)
return; return;
u32 vtxcnt = buffer->getVertexCount(); const u32 vtxcnt = buffer->getVertexCount();
u32 idxcnt = buffer->getIndexCount(); const u32 idxcnt = buffer->getIndexCount();
u16* idx = buffer->getIndices(); const u16* idx = buffer->getIndices();
switch(buffer->getVertexType()) if (!smooth)
{ for (u32 i=0; i<idxcnt; i+=3)
case video::EVT_STANDARD:
{ {
video::S3DVertex* v = (video::S3DVertex*)buffer->getVertices(); const core::vector3df& v1 = buffer->getPosition(idx[i+0]);
const core::vector3df& v2 = buffer->getPosition(idx[i+1]);
if (!smooth) const core::vector3df& v3 = buffer->getPosition(idx[i+2]);
recalculateNormalsT_Flat(v, vtxcnt, idx, idxcnt); const core::vector3df normal = core::plane3d<f32>(v1, v2, v3).Normal;
else buffer->getNormal(idx[i+0]) = normal;
recalculateNormalsT_Smooth(v, vtxcnt, idx, idxcnt); buffer->getNormal(idx[i+1]) = normal;
buffer->getNormal(idx[i+2]) = normal;
} }
break; else
case video::EVT_2TCOORDS: {
{ u32 i;
video::S3DVertex2TCoords* v = (video::S3DVertex2TCoords*)buffer->getVertices();
if (!smooth) for ( i = 0; i!= vtxcnt; ++i )
recalculateNormalsT_Flat(v, vtxcnt, idx, idxcnt); buffer->getNormal(i).set( 0.f, 0.f, 0.f );
else
recalculateNormalsT_Smooth(v, vtxcnt, idx, idxcnt); for ( i=0; i<idxcnt; i+=3)
}
break;
case video::EVT_TANGENTS:
{ {
// TODO: recalculate tangent and binormal const core::vector3df& v1 = buffer->getPosition(idx[i+0]);
video::S3DVertexTangents* v = (video::S3DVertexTangents*)buffer->getVertices(); const core::vector3df& v2 = buffer->getPosition(idx[i+1]);
if (!smooth) const core::vector3df& v3 = buffer->getPosition(idx[i+2]);
recalculateNormalsT_Flat(v, vtxcnt, idx, idxcnt); const core::vector3df normal = core::plane3d<f32>(v1, v2, v3).Normal;
else buffer->getNormal(idx[i+0]) += normal;
recalculateNormalsT_Smooth(v, vtxcnt, idx, idxcnt); buffer->getNormal(idx[i+1]) += normal;
buffer->getNormal(idx[i+2]) += normal;
} }
for ( i = 0; i!= vtxcnt; ++i )
buffer->getNormal(i).normalize();
} }
} }
...@@ -339,51 +297,17 @@ void CMeshManipulator::scaleMesh(scene::IMesh* mesh, const core::vector3df& scal ...@@ -339,51 +297,17 @@ void CMeshManipulator::scaleMesh(scene::IMesh* mesh, const core::vector3df& scal
for ( u32 b=0; b<bcount; ++b) for ( u32 b=0; b<bcount; ++b)
{ {
IMeshBuffer* buffer = mesh->getMeshBuffer(b); IMeshBuffer* buffer = mesh->getMeshBuffer(b);
void* v = buffer->getVertices();
const u32 vtxcnt = buffer->getVertexCount(); const u32 vtxcnt = buffer->getVertexCount();
core::aabbox3df bufferbox; core::aabbox3df bufferbox;
u32 i; u32 i;
switch(buffer->getVertexType()) if (vtxcnt != 0)
{ bufferbox.reset(buffer->getPosition(0) * scale);
case video::EVT_STANDARD:
{
if (vtxcnt != 0)
bufferbox.reset(((video::S3DVertex*)v)[0].Pos * scale);
for ( i=0; i<vtxcnt; ++i) for ( i=0; i<vtxcnt; ++i)
{ {
((video::S3DVertex*)v)[i].Pos *= scale; buffer->getPosition(i) *= scale;
bufferbox.addInternalPoint(((video::S3DVertex*)v)[i].Pos); bufferbox.addInternalPoint(buffer->getPosition(i));
}
}
break;
case video::EVT_2TCOORDS:
{
if (vtxcnt != 0)
bufferbox.reset(((video::S3DVertex2TCoords*)v)[0].Pos * scale);
for ( i=0; i<vtxcnt; ++i)
{
((video::S3DVertex2TCoords*)v)[i].Pos *= scale;
bufferbox.addInternalPoint(((video::S3DVertex2TCoords*)v)[i].Pos);
}
}
break;
case video::EVT_TANGENTS:
{
if (vtxcnt != 0)
bufferbox.reset(((video::S3DVertexTangents*)v)[0].Pos * scale);
for ( i=0; i<vtxcnt; ++i)
{
((video::S3DVertexTangents*)v)[i].Pos *= scale;
bufferbox.addInternalPoint(((video::S3DVertexTangents*)v)[i].Pos);
}
}
break;
} }
buffer->setBoundingBox( bufferbox ); buffer->setBoundingBox( bufferbox );
......
...@@ -269,13 +269,12 @@ void CShadowVolumeSceneNode::setMeshToRenderFrom(const IMesh* mesh) ...@@ -269,13 +269,12 @@ void CShadowVolumeSceneNode::setMeshToRenderFrom(const IMesh* mesh)
s32 totalVertices = 0; s32 totalVertices = 0;
s32 totalIndices = 0; s32 totalIndices = 0;
u32 bufcnt = mesh->getMeshBufferCount(); u32 bufcnt = mesh->getMeshBufferCount();
const IMeshBuffer* b;
for (i=0; i<bufcnt; ++i) for (i=0; i<bufcnt; ++i)
{ {
b = mesh->getMeshBuffer(i); const IMeshBuffer* buf = mesh->getMeshBuffer(i);
totalIndices += b->getIndexCount(); totalIndices += buf->getIndexCount();
totalVertices += b->getVertexCount(); totalVertices += buf->getVertexCount();
} }
// allocate memory if necessary // allocate memory if necessary
...@@ -304,49 +303,16 @@ void CShadowVolumeSceneNode::setMeshToRenderFrom(const IMesh* mesh) ...@@ -304,49 +303,16 @@ void CShadowVolumeSceneNode::setMeshToRenderFrom(const IMesh* mesh)
for (i=0; i<bufcnt; ++i) for (i=0; i<bufcnt; ++i)
{ {
b = mesh->getMeshBuffer(i); const IMeshBuffer* buf = mesh->getMeshBuffer(i);
s32 idxcnt = b->getIndexCount();
s32 vtxnow = VertexCount;
const u16* idxp = b->getIndices();
const u16* idxpend = idxp + idxcnt;
const u16* idxp = buf->getIndices();
const u16* idxpend = idxp + buf->getIndexCount();
for (; idxp!=idxpend; ++idxp) for (; idxp!=idxpend; ++idxp)
Indices[IndexCount++] = *idxp + vtxnow; Indices[IndexCount++] = *idxp + VertexCount;
s32 vtxcnt = b->getVertexCount();
switch(b->getVertexType())
{
case video::EVT_STANDARD:
{
const video::S3DVertex* vp = (video::S3DVertex*)b->getVertices();
const video::S3DVertex* const vpend = vp + vtxcnt;
for (; vp!=vpend; ++vp)
Vertices[VertexCount++] = (*vp).Pos;
}
break;
case video::EVT_2TCOORDS:
{
const video::S3DVertex2TCoords* vp = (video::S3DVertex2TCoords*)b->getVertices();
const video::S3DVertex2TCoords* const vpend = vp + vtxcnt;
for (; vp!=vpend; ++vp) const u32 vtxcnt = buf->getVertexCount();
Vertices[VertexCount++] = (*vp).Pos; for (u32 j=0; j<vtxcnt; ++j)
} Vertices[VertexCount++] = buf->getPosition(j);
break;
case video::EVT_TANGENTS:
{
const video::S3DVertexTangents* vp = (video::S3DVertexTangents*)b->getVertices();
const video::S3DVertexTangents* const vpend = vp + vtxcnt;
for (; vp!=vpend; ++vp)
Vertices[VertexCount++] = (*vp).Pos;
}
break;
}
} }
// recalculate adjacency if necessary // recalculate adjacency if necessary
......
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