cleanup; fixed shutdown; improved anim editor UI

This commit is contained in:
Mikulas Florek 2020-03-20 20:47:31 +01:00
parent f6ff62fab5
commit 5b3221bdbc
11 changed files with 644 additions and 475 deletions

View file

@ -446,6 +446,10 @@ struct AnimationSceneImpl final : AnimationScene
}
}
Anim::Controller* getAnimatorController(EntityRef entity) override {
const Animator& animator = m_animators[m_animator_map[entity]];
return animator.resource;
}
Path getAnimatorSource(EntityRef entity) override
{
@ -545,8 +549,8 @@ struct AnimationSceneImpl final : AnimationScene
void setAnimatorInput(EntityRef entity, u32 input_idx, float value) override {
Animator& animator = m_animators[m_animator_map[entity]];
const Anim::InputDecl& decl = animator.resource->m_inputs;
ASSERT(input_idx >= lengthOf(decl.inputs));
ASSERT(decl.inputs[input_idx].type != Anim::InputDecl::FLOAT);
ASSERT(input_idx < lengthOf(decl.inputs));
ASSERT(decl.inputs[input_idx].type == Anim::InputDecl::FLOAT);
*(float*)&animator.ctx->inputs[decl.inputs[input_idx].offset] = value;
}
@ -554,17 +558,44 @@ struct AnimationSceneImpl final : AnimationScene
void setAnimatorInput(EntityRef entity, u32 input_idx, bool value) override {
Animator& animator = m_animators[m_animator_map[entity]];
const Anim::InputDecl& decl = animator.resource->m_inputs;
ASSERT(input_idx >= lengthOf(decl.inputs));
ASSERT(decl.inputs[input_idx].type != Anim::InputDecl::BOOL);
ASSERT(input_idx < lengthOf(decl.inputs));
ASSERT(decl.inputs[input_idx].type == Anim::InputDecl::BOOL);
*(bool*)&animator.ctx->inputs[decl.inputs[input_idx].offset] = value;
}
float getAnimatorFloatInput(EntityRef entity, u32 input_idx) override {
Animator& animator = m_animators[m_animator_map[entity]];
const Anim::InputDecl& decl = animator.resource->m_inputs;
ASSERT(input_idx < lengthOf(decl.inputs));
ASSERT(decl.inputs[input_idx].type == Anim::InputDecl::FLOAT);
return *(float*)&animator.ctx->inputs[decl.inputs[input_idx].offset];
}
bool getAnimatorBoolInput(EntityRef entity, u32 input_idx) override {
Animator& animator = m_animators[m_animator_map[entity]];
const Anim::InputDecl& decl = animator.resource->m_inputs;
ASSERT(input_idx < lengthOf(decl.inputs));
ASSERT(decl.inputs[input_idx].type == Anim::InputDecl::BOOL);
return *(bool*)&animator.ctx->inputs[decl.inputs[input_idx].offset];
}
u32 getAnimatorU32Input(EntityRef entity, u32 input_idx) override {
Animator& animator = m_animators[m_animator_map[entity]];
const Anim::InputDecl& decl = animator.resource->m_inputs;
ASSERT(input_idx < lengthOf(decl.inputs));
ASSERT(decl.inputs[input_idx].type == Anim::InputDecl::U32);
return *(u32*)&animator.ctx->inputs[decl.inputs[input_idx].offset];
}
void setAnimatorInput(EntityRef entity, u32 input_idx, u32 value) override {
Animator& animator = m_animators[m_animator_map[entity]];
const Anim::InputDecl& decl = animator.resource->m_inputs;
ASSERT(input_idx >= lengthOf(decl.inputs));
ASSERT(decl.inputs[input_idx].type != Anim::InputDecl::U32);
ASSERT(input_idx < lengthOf(decl.inputs));
ASSERT(decl.inputs[input_idx].type == Anim::InputDecl::U32);
*(u32*)&animator.ctx->inputs[decl.inputs[input_idx].offset] = value;
}

View file

@ -1,43 +1,28 @@
#pragma once
#include "engine/lumix.h"
#include "engine/plugin.h"
struct lua_State;
namespace Lumix
{
struct Animation;
struct IAllocator;
struct OutputMemoryStream;
struct Path;
namespace Anim { struct Controller; }
namespace Anim
{
struct Controller;
}
struct Animable
{
struct Animable {
Time time;
Animation* animation;
struct Animation* animation;
EntityRef entity;
};
struct AnimationScene : IScene
{
static AnimationScene* create(Engine& engine, IPlugin& plugin, Universe& universe, IAllocator& allocator);
struct AnimationScene : IScene {
static AnimationScene* create(Engine& engine, IPlugin& plugin, Universe& universe, struct IAllocator& allocator);
static void destroy(AnimationScene& scene);
static void registerLuaAPI(lua_State* L);
virtual const OutputMemoryStream& getEventStream() const = 0;
virtual Path getPropertyAnimation(EntityRef entity) = 0;
virtual const struct OutputMemoryStream& getEventStream() const = 0;
virtual struct Path getPropertyAnimation(EntityRef entity) = 0;
virtual void setPropertyAnimation(EntityRef entity, const Path& path) = 0;
virtual bool isPropertyAnimatorEnabled(EntityRef entity) = 0;
virtual void enablePropertyAnimator(EntityRef entity, bool enabled) = 0;
@ -50,6 +35,9 @@ struct AnimationScene : IScene
virtual void setAnimatorInput(EntityRef entity, u32 input_idx, u32 value) = 0;
virtual void setAnimatorInput(EntityRef entity, u32 input_idx, float value) = 0;
virtual void setAnimatorInput(EntityRef entity, u32 input_idx, bool value) = 0;
virtual float getAnimatorFloatInput(EntityRef entity, u32 input_idx) = 0;
virtual bool getAnimatorBoolInput(EntityRef entity, u32 input_idx) = 0;
virtual u32 getAnimatorU32Input(EntityRef entity, u32 input_idx) = 0;
virtual struct LocalRigidTransform getAnimatorRootMotion(EntityRef entity) = 0;
virtual void setAnimatorSource(EntityRef entity, const Path& path) = 0;
virtual struct Path getAnimatorSource(EntityRef entity) = 0;
@ -57,6 +45,7 @@ struct AnimationScene : IScene
virtual void applyAnimatorSet(EntityRef entity, u32 idx) = 0;
virtual void setAnimatorDefaultSet(EntityRef entity, u32 idx) = 0;
virtual u32 getAnimatorDefaultSet(EntityRef entity) = 0;
virtual Anim::Controller* getAnimatorController(EntityRef entity) = 0;
virtual float getAnimationLength(int animation_idx) = 0;
};

View file

@ -35,6 +35,7 @@ void Controller::unload() {
void Controller::initEmpty() {
ASSERT(!m_root);
m_root = LUMIX_NEW(m_allocator, GroupNode)(nullptr, m_allocator);
m_root->m_name = "Root";
}
bool Controller::load(u64 size, const u8* mem) {
@ -63,6 +64,7 @@ void Controller::destroyRuntime(RuntimeContext& ctx) {
RuntimeContext* Controller::createRuntime(u32 anim_set) {
RuntimeContext* ctx = LUMIX_NEW(m_allocator, RuntimeContext)(*this, m_allocator);
ctx->inputs.resize(computeInputsSize(*this));
memset(ctx->inputs.begin(), 0, ctx->inputs.byte_size());
ctx->animations.resize(m_animation_slots.size());
memset(ctx->animations.begin(), 0, ctx->animations.byte_size());
for (AnimationEntry& anim : m_animation_entries) {

File diff suppressed because it is too large Load diff

View file

@ -12,16 +12,10 @@ namespace Anim {
struct ControllerEditor : StudioApp::GUIPlugin {
ControllerEditor(StudioApp& app);
~ControllerEditor();
static ControllerEditor& create(StudioApp& app);
static void destroy(ControllerEditor& editor);
void onWindowGUI() override;
const char* getName() const override { return "Animation Editor"; }
StudioApp& m_app;
struct Controller* m_controller;
struct GroupNode* m_current_level;
Model* m_model = nullptr;
virtual ~ControllerEditor() {}
};

View file

@ -373,7 +373,7 @@ struct StudioAppPlugin : StudioApp::IPlugin
{
explicit StudioAppPlugin(StudioApp& app)
: m_app(app)
, m_anim_editor(app)
, m_anim_editor(nullptr)
{
}
@ -404,7 +404,8 @@ struct StudioAppPlugin : StudioApp::IPlugin
m_animable_plugin = LUMIX_NEW(allocator, AnimablePropertyGridPlugin)(m_app);
m_app.getPropertyGrid().addPlugin(*m_animable_plugin);
m_app.addPlugin(m_anim_editor);
m_anim_editor = &Anim::ControllerEditor::create(m_app);
m_app.addPlugin(*m_anim_editor);
}
bool showGizmo(UniverseView&, ComponentUID) override { return false; }
@ -426,7 +427,8 @@ struct StudioAppPlugin : StudioApp::IPlugin
m_app.getPropertyGrid().removePlugin(*m_animable_plugin);
LUMIX_DELETE(allocator, m_animable_plugin);
m_app.removePlugin(m_anim_editor);
m_app.removePlugin(*m_anim_editor);
Anim::ControllerEditor::destroy(*m_anim_editor);
}
@ -435,7 +437,7 @@ struct StudioAppPlugin : StudioApp::IPlugin
AnimationAssetBrowserPlugin* m_animtion_plugin;
PropertyAnimationAssetBrowserPlugin* m_prop_anim_plugin;
AnimControllerAssetBrowserPlugin* m_anim_ctrl_plugin;
Lumix::Anim::ControllerEditor m_anim_editor;
Anim::ControllerEditor* m_anim_editor;
};

View file

@ -21,7 +21,7 @@ static LUMIX_FORCE_INLINE LocalRigidTransform getRootMotion(const Animation* ani
root_motion.pos = Vec3::ZERO;
}
if (rotation_idx >= 0) {
root_motion.rot = anim->getRotation(time, translation_idx);
root_motion.rot = anim->getRotation(time, rotation_idx);
}
else {
root_motion.rot = Quat::IDENTITY;

View file

@ -962,7 +962,7 @@ void ProfilerUIImpl::onGUICPUProfiler()
}
if (ImGui::IsMouseHoveringRect(ImVec2(from_x, from_y), ImVec2(to_x, ImGui::GetCursorScreenPos().y))) {
if (ImGui::IsMouseDragging()) {
if (ImGui::IsMouseDragging(ImGuiMouseButton_Left)) {
m_end -= i64((ImGui::GetIO().MouseDelta.x / (to_x - from_x)) * m_range);
}
const u64 cursor = u64(((ImGui::GetMousePos().x - from_x) / (to_x - from_x)) * m_range) + view_start;

View file

@ -403,7 +403,7 @@ void Settings::showToolbarSettings() const
dragged = nullptr;
break;
}
if (ImGui::IsItemActive() && ImGui::IsMouseDragging())
if (ImGui::IsItemActive() && ImGui::IsMouseDragging(ImGuiMouseButton_Left))
{
dragged = action;
actions.eraseItem(action);

View file

@ -140,7 +140,7 @@ struct SpritePlugin final : AssetBrowser::IPlugin
if (ImGui::IsItemActive())
{
static int start_drag_value;
if (ImGui::IsMouseDragging())
if (ImGui::IsMouseDragging(ImGuiMouseButton_Left))
{
ImVec2 drag = ImGui::GetMouseDragDelta();
if (vertical)

View file

@ -1282,7 +1282,7 @@ void swapBuffers()
#ifdef _WIN32
for (WindowContext& ctx : g_gpu.contexts) {
if (!ctx.window_handle) continue;
if (g_gpu.frame == ctx.last_frame) {
if (g_gpu.frame == ctx.last_frame || &ctx == g_gpu.contexts) {
SwapBuffers(ctx.device_context);
}
else {