1#include "scene/components/MeshComponent.h"
5#include "render/Material.h"
6#include "render/Mesh.h"
7#include "render/RenderQueue.h"
8#include "scene/GameObject.h"
21 if (!m_material || !m_mesh)
25 "MeshComponent on '%s' missing %s%s%s",
27 m_material ?
"" :
"material",
28 (!m_material && !m_mesh) ?
" and " :
"",
36 command.
mesh = m_mesh.get();
40 renderQueue.
Submit(command);
56 if (json.contains(
"material"))
58 auto &matObj = json[
"material"];
59 const str path = matObj.value(
"path",
"");
61 if (mat && matObj.contains(
"params"))
63 auto ¶msObj = matObj[
"params"];
66 if (paramsObj.contains(
"float"))
68 for (
auto ¶m : paramsObj[
"float"])
70 str name = param.value(
"name",
"");
71 f32 value = param.value(
"value", 0.0f);
72 mat->SetParam(name, value);
77 if (paramsObj.contains(
"float2"))
79 for (
auto ¶m : paramsObj[
"float2"])
81 str name = param.value(
"name",
"");
82 f32 v0 = param.value(
"value0", 0.0F);
83 f32 v1 = param.value(
"value1", 0.0F);
85 mat->SetParam(name, v0, v1);
90 if (paramsObj.contains(
"float3"))
92 for (
auto ¶m : paramsObj[
"float3"])
94 str name = param.value(
"name",
"");
95 f32 v0 = param.value(
"value0", 0.0F);
96 f32 v1 = param.value(
"value1", 0.0F);
97 f32 v2 = param.value(
"value2", 0.0F);
99 mat->SetParam(name,
vec3(v0, v1, v2));
104 if (paramsObj.contains(
"float4"))
106 for (
auto ¶m : paramsObj[
"float4"])
108 str name = param.value(
"name",
"");
109 f32 v0 = param.value(
"value0", 0.0F);
110 f32 v1 = param.value(
"value1", 0.0F);
111 f32 v2 = param.value(
"value2", 0.0F);
112 f32 v3 = param.value(
"value3", 0.0F);
114 mat->SetParam(name,
vec4(v0, v1, v2, v3));
119 if (paramsObj.contains(
"textures"))
121 for (
auto ¶m : paramsObj[
"textures"])
123 str name = param.value(
"name",
"");
124 str texPath = param.value(
"path",
"");
127 mat->SetParam(name, texture);
136 if (json.contains(
"mesh"))
138 const auto &
mesh = json[
"mesh"];
139 const std::string type =
mesh.value(
"type",
"box");
142 vec3 extents(
mesh.value(
"x", 1.0F),
mesh.value(
"y", 1.0F),
mesh.value(
"z", 1.0F));
145 }
else if (type ==
"sphere")
Console logging macros for all engine and game code.
#define LOG_WARN(fmt,...)
std::shared_ptr< Material > material
std::shared_ptr< Mesh > mesh
RenderQueue & GetRenderQueue()
Returns the per-frame command queue that batches and issues draw calls.
static Engine & GetInstance()
Returns the single Engine instance (created on first call).
const str & GetName() const
Returns the object's display name.
mat4 GetWorldTransform() const
Compute the world transform by walking up the parent chain.
static std::shared_ptr< Material > Load(const str &path)
Load a material from a descriptor file.
void LoadProperties(const nlohmann::json &json) override
MeshComponent()=default
Construct a MeshComponent with a mesh-material pair.
void Update(f32 deltaTime) override
Submit a RenderCommand for this object's current world transform.
void SetMesh(const std::shared_ptr< Mesh > &mesh)
void SetMaterial(const std::shared_ptr< Material > &material)
static std::shared_ptr< Mesh > CreateSphere(f32 radius, int sectors, int stacks)
static std::shared_ptr< Mesh > CreateBox(const glm::vec3 &extents=glm::vec3(1.0f))
void Submit(const RenderCommand &command)
Add a draw command to the queue for this frame.
static std::shared_ptr< Texture > Load(const std::string &path)
Load a texture from a file path using stb_image.
glm::vec4 vec4
4-component float vector (e.g. RGBA colour, homogeneous coords).
glm::vec3 vec3
3-component float vector (e.g. world position, RGB colour, normals).
std::string str
Convenience alias for std::string.
float f32
32-bit IEEE float — the standard GL scalar type.
One draw call unit: a Mesh + Material + world-space transform.
mat4 modelMatrix
Object → World transform for this draw call.
Mesh * mesh
Geometry to draw (non-owning raw pointer).
Material * material
Surface definition (non-owning raw pointer).