Polyphase Game Engine
Loading...
Searching...
No Matches
BoneMaskEditor.h
Go to the documentation of this file.
1#pragma once
2
3#if EDITOR
4
5#include <cstdint>
6#include <vector>
7#include <string>
8
9#include "AssetRef.h"
10#include "Maths.h"
11#include "imgui.h"
12
13class BoneMaskAsset;
14class SkeletalMesh;
15class SkeletalMesh3D;
16class Camera3D;
18class World;
19class Image;
20
21// Hierarchical bone-tree picker for authoring BoneMaskAssets, with a live
22// 3D preview viewport that mirrors AnimationBrowser's setup. The included
23// bones are tinted green in the preview by drawing parent->child segments
24// via World::AddLine, so the author can verify the mask visually while
25// playing back a real animation on the target rig.
26class BoneMaskEditor
27{
28public:
29
30 void Open(BoneMaskAsset* mask);
31 void Close();
32 void DrawPanel();
33 void Render();
34
35 bool IsEnabled() const { return mEnabled; }
36
37private:
38
39 void RebuildHierarchy(SkeletalMesh* mesh);
40 void DrawBoneRow(int32_t boneIndex, const std::vector<uint8_t>& resolved);
41 bool ContainsName(const std::vector<std::string>& list, const std::string& name) const;
42
43 void EnsurePreviewWorld();
44 void CreateRenderTargets(uint32_t w, uint32_t h);
45 void DestroyRenderTargets();
46 void FrameMesh();
47 void ApplyOrbitCamera();
48 void BuildGrid();
49 void DrawBoneOverlay(const std::vector<uint8_t>& resolved);
50 void HandleViewportInput();
51 void SelectAnimation(int32_t index);
52 void SetPlaying(bool playing);
53 void SyncPreviewMesh();
54
55 const char* GetCurrentAnimName() const;
56
57 bool mEnabled = false;
58 BoneMaskRef mEditedMask;
59
60 // Cached bone hierarchy from the target mesh; rebuilt when the mesh
61 // pointer differs from mCachedMesh.
62 const SkeletalMesh* mCachedMesh = nullptr;
63 std::vector<std::vector<int32_t>> mChildren;
64 int32_t mRootBone = -1;
65
66 // Preview world / nodes (mirror AnimationBrowser).
67 World* mPreviewWorld = nullptr;
68 Camera3D* mPreviewCamera = nullptr;
69 DirectionalLight3D* mPreviewLight = nullptr;
70 SkeletalMesh3D* mPreviewNode = nullptr;
71 const SkeletalMesh* mPreviewMeshCached = nullptr;
72
73 // Offscreen render targets.
74 Image* mColorTarget = nullptr;
75 Image* mDepthTarget = nullptr;
76 ImTextureID mImGuiTexId = 0;
77 uint32_t mCurrentWidth = 0;
78 uint32_t mCurrentHeight = 0;
79
80 // Orbit camera state.
81 float mCamYaw = 0.6f;
82 float mCamPitch = 0.25f;
83 float mCamDistance = 5.0f;
84 glm::vec3 mCamPivot = { 0.0f, 1.0f, 0.0f };
85 float mPreviewScale = 1.0f;
86 bool mShowGrid = true;
87
88 // Playback state.
89 int32_t mSelectedAnimIndex = -1;
90 bool mPlaying = true;
91 bool mLoop = true;
92 float mScrubTime = 0.0f;
93
94 // Viewport rect captured during DrawPanel for hover/input gating.
95 ImVec2 mImageMin = { 0, 0 };
96 ImVec2 mImageMax = { 0, 0 };
97};
98
99BoneMaskEditor* GetBoneMaskEditor();
100
101#endif
Definition AssetRef.h:18
Definition BoneMaskAsset.h:19
Definition Camera3d.h:12
Definition DirectionalLight3d.h:6
Definition SkeletalMesh3d.h:85
Definition SkeletalMesh.h:99
Definition World.h:24