1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Implement [gs]etBoundingBox via the static pose

This commit is contained in:
Lars Mueller 2025-01-27 16:58:35 +01:00
parent de726bd41e
commit 66e779b87f
2 changed files with 14 additions and 9 deletions

View file

@ -96,15 +96,15 @@ public:
void setTextureSlot(u32 meshbufNr, u32 textureSlot); void setTextureSlot(u32 meshbufNr, u32 textureSlot);
//! returns an axis aligned bounding box //! Returns bounding box of the mesh *in static pose*.
const core::aabbox3d<f32> &getBoundingBox() const override { const core::aabbox3d<f32> &getBoundingBox() const override {
// assert(false); // TODO refactor IMesh so that we don't have to implement this // TODO ideally we shouldn't be forced to implement this
return StaticPartsBoundingBox; return StaticPoseBox;
} }
//! set user axis aligned bounding box //! Set bounding box of the mesh *in static pose*.
void setBoundingBox(const core::aabbox3df &box) override { void setBoundingBox(const core::aabbox3df &box) override {
// assert(false); // TODO refactor StaticPoseBox = box;
} }
//! set the hardware mapping hint, for driver //! set the hardware mapping hint, for driver
@ -357,6 +357,7 @@ public:
//! Animates joints based on frame input //! Animates joints based on frame input
std::vector<SJoint::VariantTransform> animateMesh(f32 frame); std::vector<SJoint::VariantTransform> animateMesh(f32 frame);
//! Calculates a bounding box given an animation in the form of global joint transforms.
core::aabbox3df calculateBoundingBox( core::aabbox3df calculateBoundingBox(
const std::vector<core::matrix4> &global_transforms); const std::vector<core::matrix4> &global_transforms);
@ -398,7 +399,10 @@ protected:
std::vector<std::vector<char>> Vertices_Moved; std::vector<std::vector<char>> Vertices_Moved;
//! Bounding box of just the static parts of the mesh //! Bounding box of just the static parts of the mesh
core::aabbox3d<f32> StaticPartsBoundingBox{{0, 0, 0}}; core::aabbox3df StaticPartsBox{{0, 0, 0}};
//! Bounding box of the mesh in static pose
core::aabbox3df StaticPoseBox{{0, 0, 0}};
f32 EndFrame; f32 EndFrame;
f32 FramesPerSecond; f32 FramesPerSecond;

View file

@ -74,7 +74,7 @@ core::aabbox3df SkinnedMesh::calculateBoundingBox(
const std::vector<core::matrix4> &global_transforms) const std::vector<core::matrix4> &global_transforms)
{ {
assert(global_transforms.size() == AllJoints.size()); assert(global_transforms.size() == AllJoints.size());
core::aabbox3df result = StaticPartsBoundingBox; core::aabbox3df result = StaticPartsBox;
// skeletal animation // skeletal animation
for (u16 i = 0; i < AllJoints.size(); ++i) { for (u16 i = 0; i < AllJoints.size(); ++i) {
auto box = AllJoints[i]->LocalBoundingBox; auto box = AllJoints[i]->LocalBoundingBox;
@ -364,9 +364,9 @@ void SkinnedMesh::calculateStaticBoundingBox()
if (!animated[mb][v]) { if (!animated[mb][v]) {
auto pos = getMeshBuffer(mb)->getVertexBuffer()->getPosition(v); auto pos = getMeshBuffer(mb)->getVertexBuffer()->getPosition(v);
if (!first) { if (!first) {
StaticPartsBoundingBox.addInternalPoint(pos); StaticPartsBox.addInternalPoint(pos);
} else { } else {
StaticPartsBoundingBox.reset(pos); StaticPartsBox.reset(pos);
first = false; first = false;
} }
} }
@ -487,6 +487,7 @@ SkinnedMesh *SkinnedMeshBuilder::finalize()
} }
recalculateBaseBoundingBoxes(); recalculateBaseBoundingBoxes();
StaticPoseBox = calculateBoundingBox(matrices);
return this; return this;
} }