Add setNormal and setTCoords for IMeshBuffer

This commit is contained in:
Benau 2022-11-27 09:07:07 +08:00
parent 641dbcf9c0
commit fd579111e1
4 changed files with 31 additions and 6 deletions

View File

@ -107,6 +107,8 @@ public:
return unused;
}
// ------------------------------------------------------------------------
virtual void setNormal(irr::u32 i, const irr::core::vector3df& normal);
// ------------------------------------------------------------------------
virtual const irr::core::vector2df& getTCoords(irr::u32 i) const
{
static irr::core::vector2df unused;
@ -119,6 +121,8 @@ public:
return unused;
}
// ------------------------------------------------------------------------
virtual void setTCoords(irr::u32 i, const irr::core::vector2df& tcoords);
// ------------------------------------------------------------------------
virtual irr::scene::E_PRIMITIVE_TYPE getPrimitiveType() const
{ return irr::scene::EPT_TRIANGLES; }
// ------------------------------------------------------------------------

View File

@ -6,6 +6,8 @@
#include <algorithm>
#include "mini_glm.hpp"
namespace GE
{
// ----------------------------------------------------------------------------
@ -100,4 +102,17 @@ void GESPMBuffer::destroyVertexIndexBuffer()
m_memory = VK_NULL_HANDLE;
} // destroyVertexIndexBuffer
// ----------------------------------------------------------------------------
void GESPMBuffer::setNormal(u32 i, const core::vector3df& normal)
{
m_vertices[i].m_normal = MiniGLM::compressVector3(normal);
} // setNormal
// ----------------------------------------------------------------------------
void GESPMBuffer::setTCoords(u32 i, const core::vector2df& tcoords)
{
m_vertices[i].m_all_uvs[0] = MiniGLM::toFloat16(tcoords.X);
m_vertices[i].m_all_uvs[1] = MiniGLM::toFloat16(tcoords.Y);
} // setTCoords
}

View File

@ -106,12 +106,18 @@ namespace scene
//! returns normal of vertex i
virtual core::vector3df& getNormal(u32 i) = 0;
//! set normal of vertex i
virtual void setNormal(u32 i, const core::vector3df& normal) { getNormal(i) = normal; }
//! returns texture coord of vertex i
virtual const core::vector2df& getTCoords(u32 i) const = 0;
//! returns texture coord of vertex i
virtual core::vector2df& getTCoords(u32 i) = 0;
//! set texture coord of vertex i
virtual void setTCoords(u32 i, const core::vector2df& tcoords) { getTCoords(i) = tcoords; }
//! Returns the primitive type of this buffer
virtual scene::E_PRIMITIVE_TYPE getPrimitiveType() const = 0;

View File

@ -67,10 +67,10 @@ Shadow::Shadow(Material* shadow_mat, const AbstractKart& kart)
scene::SMeshBuffer* buffer = new scene::SMeshBuffer();
buffer->append(vertices.data(), vertices.size(), indices.data(),
indices.size());
buffer->getTCoords(0) = core::vector2df(0.0f, 0.0f);
buffer->getTCoords(1) = core::vector2df(1.0f, 0.0f);
buffer->getTCoords(2) = core::vector2df(1.0f, 1.0f);
buffer->getTCoords(3) = core::vector2df(0.0f, 1.0f);
buffer->setTCoords(0, core::vector2df(0.0f, 0.0f));
buffer->setTCoords(1, core::vector2df(1.0f, 0.0f));
buffer->setTCoords(2, core::vector2df(1.0f, 1.0f));
buffer->setTCoords(3, core::vector2df(0.0f, 1.0f));
shadow_mat->setMaterialProperties(&buffer->getMaterial(), buffer);
buffer->getMaterial().setTexture(0, shadow_mat->getTexture());
buffer->setHardwareMappingHint(scene::EHM_STREAM);
@ -168,8 +168,8 @@ void Shadow::update(bool enabled)
up_vector = up_vector * (wi.m_raycastInfo.m_suspensionLength - 0.02f);
Vec3 pos = kart_trans(position[i]) - up_vector;
buffer->getPosition(i) = pos.toIrrVector();
buffer->getNormal(i) = Vec3(wi.m_raycastInfo.m_contactNormalWS)
.toIrrVector();
buffer->setNormal(i, Vec3(wi.m_raycastInfo.m_contactNormalWS)
.toIrrVector());
}
buffer->recalculateBoundingBox();
mesh->setBoundingBox(buffer->getBoundingBox());