adding materials, adding serialization for meshes and materials, random fixes
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
#include "imgui.h"
|
||||
#include "open_engine/renderer/renderer3d.hpp"
|
||||
#include "open_engine/scene/components.hpp"
|
||||
#include <editor_component.hpp>
|
||||
#include <entt/entity/fwd.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <open_engine.hpp>
|
||||
|
||||
namespace OpenEngine {
|
||||
@@ -101,6 +105,7 @@ namespace OpenEngine {
|
||||
DrawVec3Control("Rotation", rotation_comp);
|
||||
transform.rotation = glm::radians(rotation_comp);
|
||||
DrawVec3Control("Scale", transform.scale);
|
||||
ImGui::Spacing();
|
||||
};
|
||||
|
||||
void SpriteOnImGuiRender(entt::registry& registry, entt::entity entity)
|
||||
@@ -171,8 +176,66 @@ namespace OpenEngine {
|
||||
|
||||
};
|
||||
|
||||
void MeshOnImGuiRender(entt::registry®istry, entt::entity entity)
|
||||
void MeshOnImGuiRender(entt::registry& registry, entt::entity entity)
|
||||
{
|
||||
auto& mesh_component = registry.get<MeshComponent>(entity);
|
||||
|
||||
const char* items[] = { "Quad", "Cube" };
|
||||
static int item_selected_idx = 0;
|
||||
|
||||
if (ImGui::BeginCombo("Mesh", items[item_selected_idx])) {
|
||||
for (int n = 0; n < 2; n++)
|
||||
{
|
||||
const bool is_selected = (item_selected_idx == n);
|
||||
if (ImGui::Selectable(items[n], is_selected))
|
||||
item_selected_idx = n;
|
||||
|
||||
// Set the initial focus when opening the combo (scrolling + keyboard navigation focus)
|
||||
if (is_selected)
|
||||
ImGui::SetItemDefaultFocus();
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
|
||||
if ((int)mesh_component.primitive_type == (item_selected_idx + 1))
|
||||
return;
|
||||
|
||||
mesh_component.primitive_type = (PrimitiveType)(item_selected_idx + 1);
|
||||
switch (mesh_component.primitive_type) {
|
||||
case OpenEngine::PrimitiveType::Quad:
|
||||
{
|
||||
mesh_component.mesh = CreateQuad((uint32_t)entity);
|
||||
break;
|
||||
}
|
||||
case OpenEngine::PrimitiveType::Cube:
|
||||
{
|
||||
mesh_component.mesh = CreateCube((uint32_t)entity);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MaterialOnImGuiRender(entt::registry& registry, entt::entity entity)
|
||||
{
|
||||
auto& material = registry.get<MaterialComponent>(entity).material;
|
||||
|
||||
auto& albedo = material.albedo;
|
||||
auto& roughness = material.roughness;
|
||||
auto& metallic = material.metallic;
|
||||
auto& ambient = material.ambient_strength;
|
||||
auto& specular = material.specular_strength;
|
||||
|
||||
if (ImGui::SliderFloat4("Albedo", glm::value_ptr(albedo), 0, 1))
|
||||
material.albedo = albedo;
|
||||
if (ImGui::SliderFloat("Roughness", &roughness, 0, 1))
|
||||
material.roughness = roughness;
|
||||
if (ImGui::SliderFloat("Metallic", &metallic, 0, 1))
|
||||
material.metallic = metallic;
|
||||
if (ImGui::SliderFloat("Ambient strength", &ambient, 0, 1))
|
||||
material.ambient_strength = ambient;
|
||||
if (ImGui::SliderFloat("Specular strength", &specular, 0, 10))
|
||||
material.specular_strength = specular;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user