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:
parent
de726bd41e
commit
66e779b87f
2 changed files with 14 additions and 9 deletions
|
@ -96,15 +96,15 @@ public:
|
|||
|
||||
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 {
|
||||
// assert(false); // TODO refactor IMesh so that we don't have to implement this
|
||||
return StaticPartsBoundingBox;
|
||||
// TODO ideally we shouldn't be forced to implement this
|
||||
return StaticPoseBox;
|
||||
}
|
||||
|
||||
//! set user axis aligned bounding box
|
||||
//! Set bounding box of the mesh *in static pose*.
|
||||
void setBoundingBox(const core::aabbox3df &box) override {
|
||||
// assert(false); // TODO refactor
|
||||
StaticPoseBox = box;
|
||||
}
|
||||
|
||||
//! set the hardware mapping hint, for driver
|
||||
|
@ -357,6 +357,7 @@ public:
|
|||
//! Animates joints based on frame input
|
||||
std::vector<SJoint::VariantTransform> animateMesh(f32 frame);
|
||||
|
||||
//! Calculates a bounding box given an animation in the form of global joint transforms.
|
||||
core::aabbox3df calculateBoundingBox(
|
||||
const std::vector<core::matrix4> &global_transforms);
|
||||
|
||||
|
@ -398,7 +399,10 @@ protected:
|
|||
std::vector<std::vector<char>> Vertices_Moved;
|
||||
|
||||
//! 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 FramesPerSecond;
|
||||
|
|
|
@ -74,7 +74,7 @@ core::aabbox3df SkinnedMesh::calculateBoundingBox(
|
|||
const std::vector<core::matrix4> &global_transforms)
|
||||
{
|
||||
assert(global_transforms.size() == AllJoints.size());
|
||||
core::aabbox3df result = StaticPartsBoundingBox;
|
||||
core::aabbox3df result = StaticPartsBox;
|
||||
// skeletal animation
|
||||
for (u16 i = 0; i < AllJoints.size(); ++i) {
|
||||
auto box = AllJoints[i]->LocalBoundingBox;
|
||||
|
@ -364,9 +364,9 @@ void SkinnedMesh::calculateStaticBoundingBox()
|
|||
if (!animated[mb][v]) {
|
||||
auto pos = getMeshBuffer(mb)->getVertexBuffer()->getPosition(v);
|
||||
if (!first) {
|
||||
StaticPartsBoundingBox.addInternalPoint(pos);
|
||||
StaticPartsBox.addInternalPoint(pos);
|
||||
} else {
|
||||
StaticPartsBoundingBox.reset(pos);
|
||||
StaticPartsBox.reset(pos);
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
|
@ -487,6 +487,7 @@ SkinnedMesh *SkinnedMeshBuilder::finalize()
|
|||
}
|
||||
|
||||
recalculateBaseBoundingBoxes();
|
||||
StaticPoseBox = calculateBoundingBox(matrices);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue