diff --git a/irr/include/SkinnedMesh.h b/irr/include/SkinnedMesh.h index c4bc3ae23..ef6624c13 100644 --- a/irr/include/SkinnedMesh.h +++ b/irr/include/SkinnedMesh.h @@ -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 &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 animateMesh(f32 frame); + //! Calculates a bounding box given an animation in the form of global joint transforms. core::aabbox3df calculateBoundingBox( const std::vector &global_transforms); @@ -398,7 +399,10 @@ protected: std::vector> Vertices_Moved; //! Bounding box of just the static parts of the mesh - core::aabbox3d 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; diff --git a/irr/src/SkinnedMesh.cpp b/irr/src/SkinnedMesh.cpp index 3df925357..cc2cfbb45 100644 --- a/irr/src/SkinnedMesh.cpp +++ b/irr/src/SkinnedMesh.cpp @@ -74,7 +74,7 @@ core::aabbox3df SkinnedMesh::calculateBoundingBox( const std::vector &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; }