From c7a7c8ddf2b210e6de5c2122c3c56cc254c8404a Mon Sep 17 00:00:00 2001 From: MaxYari Date: Wed, 5 Mar 2025 09:38:59 +0100 Subject: [PATCH] WIP --- apps/openmw/mwlua/types/actor.cpp | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/apps/openmw/mwlua/types/actor.cpp b/apps/openmw/mwlua/types/actor.cpp index 413a656e90..75e1f86bbf 100644 --- a/apps/openmw/mwlua/types/actor.cpp +++ b/apps/openmw/mwlua/types/actor.cpp @@ -2,6 +2,8 @@ #include +#include + #include #include #include @@ -170,6 +172,29 @@ namespace MWLua MWBase::Environment::get().getWindowManager()->setSelectedEnchantItem(*it); } + static std::optional findBoneWorldTransform( + const osg::ref_ptr parentNode, const std::string_view boneName) + { + if (!parentNode) + return; + const osg::Group* parentNodeGroup = parentNode->asGroup(); + if (!parentNodeGroup) + return; + + for (unsigned int i = 0; i < parentNodeGroup->getNumChildren(); ++i) + { + osg::ref_ptr child = parentNodeGroup->getChild(i); + + // asMatrixTransform will break if its not a bone + if (child->getName() == boneName) + { + return osg::computeLocalToWorld(child->getParentalNodePaths()[0]); + } + + findBoneWorldTransform(child, boneName); + } + } + void addActorBindings(sol::table actor, const Context& context) { sol::state_view lua = context.sol(); @@ -195,7 +220,17 @@ namespace MWLua { "CarriedRight", MWWorld::InventoryStore::Slot_CarriedRight }, { "CarriedLeft", MWWorld::InventoryStore::Slot_CarriedLeft }, { "Ammunition", MWWorld::InventoryStore::Slot_Ammunition } })); + actor["getBonePosition"] = [](const SelfObject& self, std::string_view boneName) { + const MWWorld::Class& cls = self.ptr().getClass(); + if (!cls.isActor()) + throw std::runtime_error("Actor expected"); + std::optional boneTransform + = findBoneWorldTransform(self.ptr().getRefData().getBaseNode()->asGroup(), boneName); + return boneTransform; + // return o.ptr().getRefData().getPosition().asVec3(); + // return Misc::Convert::makeOsgQuat(pos.rot); + }; actor["getStance"] = [](const Object& o) { const MWWorld::Class& cls = o.ptr().getClass(); if (cls.isActor())