Skip to content

Commit

Permalink
Add NiAVObject::GetMass
Browse files Browse the repository at this point in the history
  • Loading branch information
powerof3 committed May 28, 2024
1 parent 51593d0 commit f71d05c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/RE/N/NiAVObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ namespace RE
[[nodiscard]] bhkCollisionObject* GetCollisionObject() const;
[[nodiscard]] COL_LAYER GetCollisionLayer() const;
[[nodiscard]] BSGeometry* GetFirstGeometryOfShaderType(BSShaderMaterial::Feature a_type);
[[nodiscard]] float GetMass();
[[nodiscard]] TESObjectREFR* GetUserData() const;
[[nodiscard]] bool HasAnimation() const;
[[nodiscard]] bool HasShaderType(BSShaderMaterial::Feature a_type);
Expand Down
14 changes: 14 additions & 0 deletions src/RE/N/NiAVObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ namespace RE
return firstGeometry;
}

float NiAVObject::GetMass()
{
float mass = 0.0f;

BSVisit::TraverseScenegraphCollision(this, [&](bhkNiCollisionObject* a_col) -> BSVisit::BSVisitControl {
if (auto hkpBody = a_col->body ? static_cast<RE::hkpRigidBody*>(a_col->body->referencedObject.get()) : nullptr) {
mass += hkpBody->motion.GetMass();
}
return BSVisit::BSVisitControl::kContinue;
});

return mass;
}

TESObjectREFR* NiAVObject::GetUserData() const
{
if (userData) {
Expand Down

0 comments on commit f71d05c

Please sign in to comment.