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

View File

@ -6,6 +6,8 @@
#include <algorithm> #include <algorithm>
#include "mini_glm.hpp"
namespace GE namespace GE
{ {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -100,4 +102,17 @@ void GESPMBuffer::destroyVertexIndexBuffer()
m_memory = VK_NULL_HANDLE; m_memory = VK_NULL_HANDLE;
} // destroyVertexIndexBuffer } // 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 //! returns normal of vertex i
virtual core::vector3df& getNormal(u32 i) = 0; 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 //! returns texture coord of vertex i
virtual const core::vector2df& getTCoords(u32 i) const = 0; virtual const core::vector2df& getTCoords(u32 i) const = 0;
//! returns texture coord of vertex i //! returns texture coord of vertex i
virtual core::vector2df& getTCoords(u32 i) = 0; 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 //! Returns the primitive type of this buffer
virtual scene::E_PRIMITIVE_TYPE getPrimitiveType() const = 0; 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(); scene::SMeshBuffer* buffer = new scene::SMeshBuffer();
buffer->append(vertices.data(), vertices.size(), indices.data(), buffer->append(vertices.data(), vertices.size(), indices.data(),
indices.size()); indices.size());
buffer->getTCoords(0) = core::vector2df(0.0f, 0.0f); buffer->setTCoords(0, core::vector2df(0.0f, 0.0f));
buffer->getTCoords(1) = core::vector2df(1.0f, 0.0f); buffer->setTCoords(1, core::vector2df(1.0f, 0.0f));
buffer->getTCoords(2) = core::vector2df(1.0f, 1.0f); buffer->setTCoords(2, core::vector2df(1.0f, 1.0f));
buffer->getTCoords(3) = core::vector2df(0.0f, 1.0f); buffer->setTCoords(3, core::vector2df(0.0f, 1.0f));
shadow_mat->setMaterialProperties(&buffer->getMaterial(), buffer); shadow_mat->setMaterialProperties(&buffer->getMaterial(), buffer);
buffer->getMaterial().setTexture(0, shadow_mat->getTexture()); buffer->getMaterial().setTexture(0, shadow_mat->getTexture());
buffer->setHardwareMappingHint(scene::EHM_STREAM); 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); up_vector = up_vector * (wi.m_raycastInfo.m_suspensionLength - 0.02f);
Vec3 pos = kart_trans(position[i]) - up_vector; Vec3 pos = kart_trans(position[i]) - up_vector;
buffer->getPosition(i) = pos.toIrrVector(); buffer->getPosition(i) = pos.toIrrVector();
buffer->getNormal(i) = Vec3(wi.m_raycastInfo.m_contactNormalWS) buffer->setNormal(i, Vec3(wi.m_raycastInfo.m_contactNormalWS)
.toIrrVector(); .toIrrVector());
} }
buffer->recalculateBoundingBox(); buffer->recalculateBoundingBox();
mesh->setBoundingBox(buffer->getBoundingBox()); mesh->setBoundingBox(buffer->getBoundingBox());