Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
SkinnedMeshComponent.cpp
Go to the documentation of this file.
2
3#include "Engine.h"
4#include "Log.h"
6#include "render/Material.h"
7#include "render/Mesh.h"
8#include "render/RenderQueue.h"
9#include "scene/GameObject.h"
10#include "scene/components/AnimationComponent.h"
11
12namespace mnd
13{
14
16 const std::shared_ptr<Mesh> &mesh,
17 const std::shared_ptr<Skeleton> &skeleton)
18 : m_material(material)
19 , m_mesh(mesh)
20 , m_skeleton(skeleton)
21{
22 if (m_skeleton)
23 {
24 m_identityPalette.assign(m_skeleton->Size(), glm::mat4(1.0f));
25 }
26}
27
29{
30 if (!m_material || !m_mesh)
31 {
32 return;
33 }
34
35 const std::vector<glm::mat4> *palette = &m_identityPalette;
36 if (m_paletteSource)
37 {
38 const auto &live = m_paletteSource->GetPalette();
39 if (!live.empty())
40 {
41 palette = &live;
42 }
43 }
44
45 if (!palette->empty())
46 {
47 m_material->SetParam("uBones", *palette);
48 }
49
50 RenderCommand command;
51 command.material = m_material.get();
52 command.mesh = m_mesh.get();
54
56}
57
58void SkinnedMeshComponent::SetMaterial(const std::shared_ptr<Material> &material)
59{
60 m_material = material;
61}
62
63void SkinnedMeshComponent::SetMesh(const std::shared_ptr<Mesh> &mesh)
64{
65 m_mesh = mesh;
66}
67
68void SkinnedMeshComponent::SetSkeleton(const std::shared_ptr<Skeleton> &skeleton)
69{
70 m_skeleton = skeleton;
71 if (m_skeleton)
72 {
73 m_identityPalette.assign(m_skeleton->Size(), glm::mat4(1.0f));
74 }
75}
76
78{
79 m_paletteSource = anim;
80}
81
82} // namespace mnd
Console logging macros for all engine and game code.
std::shared_ptr< Material > material
std::shared_ptr< Mesh > mesh
Bone hierarchy + bind/offset matrices for GPU-skinned meshes.
Renderable component for GPU-skinned meshes driven by a Skeleton.
Drives transform animation on a hierarchy of GameObjects.
const std::vector< glm::mat4 > & GetPalette() const
Read-only access to the bone palette computed at the last Update().
GameObject * GetOwner()
Definition Component.cpp:12
RenderQueue & GetRenderQueue()
Returns the per-frame command queue that batches and issues draw calls.
Definition Engine.cpp:423
static Engine & GetInstance()
Returns the single Engine instance (created on first call).
Definition Engine.cpp:59
mat4 GetWorldTransform() const
Compute the world transform by walking up the parent chain.
void Submit(const RenderCommand &command)
Add a draw command to the queue for this frame.
void SetMaterial(const std::shared_ptr< Material > &material)
void SetPaletteSource(AnimationComponent *anim)
Plug an AnimationComponent (typically on the model root) as the live palette source.
void SetMesh(const std::shared_ptr< Mesh > &mesh)
void Update(f32 deltaTime) override
void SetSkeleton(const std::shared_ptr< Skeleton > &skeleton)
float f32
32-bit IEEE float — the standard GL scalar type.
Definition Types.h:40
One draw call unit: a Mesh + Material + world-space transform.
Definition RenderQueue.h:44
mat4 modelMatrix
Object → World transform for this draw call.
Definition RenderQueue.h:47
Mesh * mesh
Geometry to draw (non-owning raw pointer).
Definition RenderQueue.h:45
Material * material
Surface definition (non-owning raw pointer).
Definition RenderQueue.h:46