Skip to content

Commit

Permalink
Add setNormal and setTCoords for IMeshBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
Benau committed Nov 27, 2022
1 parent 641dbcf commit fd57911
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
4 changes: 4 additions & 0 deletions lib/graphics_engine/include/ge_spm_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ class GESPMBuffer : public irr::scene::IMeshBuffer
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;
Expand All @@ -119,6 +121,8 @@ class GESPMBuffer : public irr::scene::IMeshBuffer
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; }
// ------------------------------------------------------------------------
Expand Down
15 changes: 15 additions & 0 deletions lib/graphics_engine/src/ge_spm_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include <algorithm>

#include "mini_glm.hpp"

namespace GE
{
// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -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

}
6 changes: 6 additions & 0 deletions lib/irrlicht/include/IMeshBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
12 changes: 6 additions & 6 deletions src/graphics/shadow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit fd57911

Please sign in to comment.