|
1 | 1 | #include "animationbindings.hpp" |
2 | 2 |
|
3 | 3 | #include <components/lua/luastate.hpp> |
| 4 | +#include <components/lua/utilpackage.hpp> |
4 | 5 | #include <components/misc/finitevalues.hpp> |
5 | 6 |
|
6 | 7 | #include "../mwbase/environment.hpp" |
@@ -243,15 +244,26 @@ namespace MWLua |
243 | 244 | api["addVfx"] = [context](const SelfObject& object, std::string_view model, sol::optional<sol::table> options) { |
244 | 245 | if (options) |
245 | 246 | { |
| 247 | + sol::object transformObject = options->get<sol::object>("transform"); |
| 248 | + std::optional<osg::Matrix> transform; |
| 249 | + if (transformObject.is<LuaUtil::TransformM>()) |
| 250 | + transform = LuaUtil::cast<LuaUtil::TransformM>(transformObject).mM; |
| 251 | + else if (transformObject.is<LuaUtil::TransformQ>()) |
| 252 | + transform = osg::Matrix(LuaUtil::cast<LuaUtil::TransformQ>(transformObject).mQ); |
| 253 | + if (transform.has_value() && !transform->valid()) |
| 254 | + throw std::runtime_error("Transform provided for 'addVfx' is invalid"); |
| 255 | + |
246 | 256 | context.mLuaManager->addAction( |
247 | 257 | [object = Object(object), model = std::string(model), |
248 | 258 | effectId = options->get_or<std::string>("vfxId", ""), loop = options->get_or("loop", false), |
249 | 259 | boneName = options->get_or<std::string>("boneName", ""), |
250 | 260 | particleTexture = options->get_or<std::string>("particleTextureOverride", ""), |
251 | | - useAmbientLight = options->get_or("useAmbientLight", true)] { |
| 261 | + useAmbientLight = options->get_or("useAmbientLight", true), |
| 262 | + autoTransform = options->get_or("autoTransform", true), transform] { |
252 | 263 | MWRender::Animation* anim = getMutableAnimationOrThrow(object); |
253 | 264 |
|
254 | | - anim->addEffect(model, effectId, loop, boneName, particleTexture, useAmbientLight); |
| 265 | + anim->addEffect(model, effectId, loop, boneName, particleTexture, useAmbientLight, |
| 266 | + autoTransform, transform); |
255 | 267 | }, |
256 | 268 | "addVfxAction"); |
257 | 269 | } |
|
0 commit comments