1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-14 01:19:59 +00:00
This commit is contained in:
MaxYari 2025-03-05 09:38:59 +01:00
parent a49a900a7b
commit c7a7c8ddf2

View File

@ -2,6 +2,8 @@
#include <array>
#include <osg/Matrix>
#include <components/detournavigator/agentbounds.hpp>
#include <components/lua/luastate.hpp>
#include <components/settings/values.hpp>
@ -170,6 +172,29 @@ namespace MWLua
MWBase::Environment::get().getWindowManager()->setSelectedEnchantItem(*it);
}
static std::optional<osg::Matrix> findBoneWorldTransform(
const osg::ref_ptr<osg::Node> 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<const osg::Node> 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<osg::Matrix> 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())