feat: changed material property to color3
This commit is contained in:
parent
a3d2026a35
commit
fe0dca875c
|
@ -50,11 +50,7 @@ int main() {
|
|||
.position = glm::vec3(0, -5, 0),
|
||||
.rotation = glm::vec3(0),
|
||||
.scale = glm::vec3(512, 1.2, 512),
|
||||
.material = Material {
|
||||
.diffuse = glm::vec3(0.388235, 0.372549, 0.384314),
|
||||
.specular = glm::vec3(0.5f, 0.5f, 0.5f),
|
||||
.shininess = 32.0f,
|
||||
},
|
||||
.color = glm::vec3(0.388235, 0.372549, 0.384314),
|
||||
.anchored = true,
|
||||
}));
|
||||
|
||||
|
@ -62,11 +58,7 @@ int main() {
|
|||
.position = glm::vec3(0),
|
||||
.rotation = glm::vec3(0),
|
||||
.scale = glm::vec3(4, 1.2, 2),
|
||||
.material = Material {
|
||||
.diffuse = glm::vec3(0.639216f, 0.635294f, 0.647059f),
|
||||
.specular = glm::vec3(0.5f, 0.5f, 0.5f),
|
||||
.shininess = 32.0f,
|
||||
}
|
||||
.color = glm::vec3(0.639216f, 0.635294f, 0.647059f),
|
||||
}));
|
||||
|
||||
for (InstanceRef inst : workspace()->GetChildren()) {
|
||||
|
@ -166,11 +158,7 @@ void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods
|
|||
.position = camera.cameraPos + camera.cameraFront * glm::vec3(3),
|
||||
.rotation = glm::vec3(0),
|
||||
.scale = glm::vec3(1, 1, 1),
|
||||
.material = Material {
|
||||
.diffuse = glm::vec3(1.0f, 0.5f, 0.31f),
|
||||
.specular = glm::vec3(0.5f, 0.5f, 0.5f),
|
||||
.shininess = 32.0f,
|
||||
}
|
||||
.color = glm::vec3(1.0f, 0.5f, 0.31f),
|
||||
}));
|
||||
syncPartPhysics(lastPart);
|
||||
}
|
||||
|
|
|
@ -157,11 +157,7 @@ void MainGLWidget::keyPressEvent(QKeyEvent* evt) {
|
|||
.position = camera.cameraPos + camera.cameraFront * glm::vec3(3),
|
||||
.rotation = glm::vec3(0),
|
||||
.scale = glm::vec3(1, 1, 1),
|
||||
.material = Material {
|
||||
.diffuse = glm::vec3(1.0f, 0.5f, 0.31f),
|
||||
.specular = glm::vec3(0.5f, 0.5f, 0.5f),
|
||||
.shininess = 32.0f,
|
||||
}
|
||||
.color = glm::vec3(1.0f, 0.5f, 0.31f),
|
||||
}));
|
||||
syncPartPhysics(lastPart);
|
||||
}
|
||||
|
|
|
@ -87,11 +87,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
.position = glm::vec3(0, -5, 0),
|
||||
.rotation = glm::vec3(0),
|
||||
.scale = glm::vec3(512, 1.2, 512),
|
||||
.material = Material {
|
||||
.diffuse = glm::vec3(0.388235, 0.372549, 0.384314),
|
||||
.specular = glm::vec3(0.5f, 0.5f, 0.5f),
|
||||
.shininess = 32.0f,
|
||||
},
|
||||
.color = glm::vec3(0.388235, 0.372549, 0.384314),
|
||||
.anchored = true,
|
||||
}));
|
||||
ui->mainWidget->lastPart->name = "Baseplate";
|
||||
|
@ -101,11 +97,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
.position = glm::vec3(0),
|
||||
.rotation = glm::vec3(0),
|
||||
.scale = glm::vec3(4, 1.2, 2),
|
||||
.material = Material {
|
||||
.diffuse = glm::vec3(0.639216f, 0.635294f, 0.647059f),
|
||||
.specular = glm::vec3(0.5f, 0.5f, 0.5f),
|
||||
.shininess = 32.0f,
|
||||
}
|
||||
.color = glm::vec3(0.639216f, 0.635294f, 0.647059f),
|
||||
}));
|
||||
syncPartPhysics(ui->mainWidget->lastPart);
|
||||
}
|
||||
|
|
52
src/datatypes/color3.cpp
Normal file
52
src/datatypes/color3.cpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
#include "color3.h"
|
||||
#include <algorithm>
|
||||
#include <glm/ext/quaternion_geometric.hpp>
|
||||
#include <iomanip>
|
||||
#include <ios>
|
||||
#include <string>
|
||||
#include "meta.h" // IWYU pragma: keep
|
||||
|
||||
Data::Color3::Color3(float r, float g, float b) : r(std::clamp(r, 0.f, 1.f)), g(std::clamp(g, 0.f, 1.f)), b(std::clamp(b, 0.f, 1.f)) {};
|
||||
Data::Color3::Color3(const glm::vec3& vec) : r(std::clamp(vec.x, 0.f, 1.f)), g(std::clamp(vec.y, 0.f, 1.f)), b(std::clamp(vec.z, 0.f, 1.f)) {};
|
||||
|
||||
Data::Color3::~Color3() = default;
|
||||
const Data::TypeInfo Data::Color3::TYPE = {
|
||||
.name = "Color3",
|
||||
.deserializer = &Data::Color3::Deserialize,
|
||||
};
|
||||
|
||||
const Data::TypeInfo& Data::Color3::GetType() const { return Data::Color3::TYPE; };
|
||||
|
||||
const Data::String Data::Color3::ToString() const {
|
||||
return std::to_string(r) + ", " + std::to_string(g) + ", " + std::to_string(b);
|
||||
}
|
||||
|
||||
Data::Color3::operator glm::vec3() const { return glm::vec3(r, g, b); };
|
||||
|
||||
std::string Data::Color3::ToHex() const {
|
||||
std::stringstream ss;
|
||||
ss << "FF" << std::hex << std::uppercase << std::setfill('0')
|
||||
<< std::setw(2) << int(r*255)
|
||||
<< std::setw(2) << int(g*255)
|
||||
<< std::setw(2) << int(b*255);
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
|
||||
Data::Color3 Data::Color3::FromHex(std::string hex) {
|
||||
float r = float(std::stoi(hex.substr(2, 2), nullptr, 16)) / 255;
|
||||
float g = float(std::stoi(hex.substr(4, 2), nullptr, 16)) / 255;
|
||||
float b = float(std::stoi(hex.substr(6, 2), nullptr, 16)) / 255;
|
||||
|
||||
return Color3(r, g, b);
|
||||
}
|
||||
|
||||
// Serialization
|
||||
|
||||
void Data::Color3::Serialize(pugi::xml_node* node) const {
|
||||
node->text().set(this->ToHex());
|
||||
}
|
||||
|
||||
Data::Variant Data::Color3::Deserialize(pugi::xml_node* node) {
|
||||
return Color3::FromHex(node->text().get());
|
||||
}
|
37
src/datatypes/color3.h
Normal file
37
src/datatypes/color3.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
#pragma once
|
||||
|
||||
#include "base.h"
|
||||
#include <glm/ext/quaternion_geometric.hpp>
|
||||
#include <glm/ext/vector_float3.hpp>
|
||||
#include <reactphysics3d/reactphysics3d.h>
|
||||
|
||||
namespace rp = reactphysics3d;
|
||||
|
||||
namespace Data {
|
||||
class Color3 : Base {
|
||||
float r;
|
||||
float g;
|
||||
float b;
|
||||
|
||||
public:
|
||||
Color3(float r, float g, float b);
|
||||
Color3(const glm::vec3&);
|
||||
~Color3();
|
||||
|
||||
static Color3 FromHex(std::string hex);
|
||||
|
||||
virtual const TypeInfo& GetType() const override;
|
||||
static const TypeInfo TYPE;
|
||||
|
||||
virtual const Data::String ToString() const override;
|
||||
std::string ToHex() const;
|
||||
virtual void Serialize(pugi::xml_node* node) const override;
|
||||
static Data::Variant Deserialize(pugi::xml_node* node);
|
||||
|
||||
operator glm::vec3() const;
|
||||
|
||||
inline float R() const { return r; }
|
||||
inline float G() const { return g; }
|
||||
inline float B() const { return b; }
|
||||
};
|
||||
}
|
|
@ -33,4 +33,5 @@ std::map<std::string, const Data::TypeInfo*> Data::TYPE_MAP = {
|
|||
{ "string", &Data::String::TYPE },
|
||||
{ "Vector3", &Data::Vector3::TYPE },
|
||||
{ "CoordinateFrame", &Data::CFrame::TYPE },
|
||||
{ "Color3", &Data::Color3::TYPE },
|
||||
};
|
|
@ -3,6 +3,7 @@
|
|||
#include <variant>
|
||||
#include <map>
|
||||
#include "base.h"
|
||||
#include "datatypes/color3.h"
|
||||
#include "vector.h"
|
||||
#include "cframe.h"
|
||||
|
||||
|
@ -22,7 +23,8 @@ namespace Data {
|
|||
Float,
|
||||
String,
|
||||
Vector3,
|
||||
CFrame
|
||||
CFrame,
|
||||
Color3
|
||||
> __VARIANT_TYPE;
|
||||
|
||||
class Variant {
|
||||
|
|
|
@ -70,7 +70,6 @@ void DataModel::DeserializeService(pugi::xml_node* node) {
|
|||
abort();
|
||||
}
|
||||
|
||||
printf("Adding a workspace. %d:%d:%d\n", services.count(className), services.size(), GetChildren().size());
|
||||
if (services.count(className) != 0) {
|
||||
fprintf(stderr, "Service %s defined multiple times in file\n", className.c_str());
|
||||
return;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "base/instance.h"
|
||||
#include "datatypes/base.h"
|
||||
#include "datatypes/cframe.h"
|
||||
#include "datatypes/color3.h"
|
||||
#include "datatypes/vector.h"
|
||||
#include "objects/base/member.h"
|
||||
#include <memory>
|
||||
|
@ -55,11 +56,11 @@ const InstanceType* Part::GetClass() {
|
|||
return &TYPE;
|
||||
}
|
||||
|
||||
Part::Part(): Part(PartConstructParams {}) {
|
||||
Part::Part(): Part(PartConstructParams { .color = Data::Color3(0.639216f, 0.635294f, 0.647059f) }) {
|
||||
}
|
||||
|
||||
Part::Part(PartConstructParams params): Instance(&TYPE), cframe(Data::CFrame(params.position, params.rotation)),
|
||||
scale(params.scale), material(params.material), anchored(params.anchored) {
|
||||
scale(params.scale), color(params.color), anchored(params.anchored) {
|
||||
this->memberMap = std::make_unique<MemberMap>(MemberMap {
|
||||
.super = std::move(this->memberMap),
|
||||
.members = {
|
||||
|
@ -85,11 +86,15 @@ Part::Part(PartConstructParams params): Instance(&TYPE), cframe(Data::CFrame(par
|
|||
.type = &Data::CFrame::TYPE,
|
||||
.codec = fieldCodecOf<Data::CFrame>(),
|
||||
.updateCallback = memberFunctionOf(&Part::onUpdated, this),
|
||||
} }, { "scale", {
|
||||
} }, { "Size", {
|
||||
.backingField = &scale,
|
||||
.type = &Data::Vector3::TYPE,
|
||||
.codec = fieldCodecOf<Data::Vector3, glm::vec3>(),
|
||||
.updateCallback = memberFunctionOf(&Part::onUpdated, this)
|
||||
} }, { "Color", {
|
||||
.backingField = &color,
|
||||
.type = &Data::Color3::TYPE,
|
||||
.codec = fieldCodecOf<Data::Color3>(),
|
||||
} }
|
||||
}
|
||||
});
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <glm/ext.hpp>
|
||||
#include "../rendering/material.h"
|
||||
#include "datatypes/cframe.h"
|
||||
#include "datatypes/color3.h"
|
||||
#include "datatypes/vector.h"
|
||||
#include <reactphysics3d/reactphysics3d.h>
|
||||
|
||||
|
@ -16,7 +17,7 @@ struct PartConstructParams {
|
|||
glm::vec3 position;
|
||||
glm::quat rotation = glm::identity<glm::quat>();
|
||||
glm::vec3 scale;
|
||||
Material material;
|
||||
Data::Color3 color;
|
||||
|
||||
bool anchored = false;
|
||||
};
|
||||
|
@ -28,14 +29,9 @@ protected:
|
|||
public:
|
||||
const static InstanceType TYPE;
|
||||
|
||||
// TODO: Switch these over to our dedicated datatypes
|
||||
Data::CFrame cframe;
|
||||
glm::vec3 scale;
|
||||
Material material {
|
||||
.diffuse = glm::vec3(0.639216f, 0.635294f, 0.647059f),
|
||||
.specular = glm::vec3(0.5f, 0.5f, 0.5f),
|
||||
.shininess = 32.0f,
|
||||
};
|
||||
Data::Color3 color;
|
||||
bool selected = false;
|
||||
|
||||
bool anchored = false;
|
||||
|
|
|
@ -128,7 +128,11 @@ void renderParts() {
|
|||
glm::mat4 model = part->cframe;
|
||||
model = glm::scale(model, part->scale);
|
||||
shader->set("model", model);
|
||||
shader->set("material", part->material);
|
||||
shader->set("material", Material {
|
||||
.diffuse = part->color,
|
||||
.specular = glm::vec3(0.5f, 0.5f, 0.5f),
|
||||
.shininess = 16.0f,
|
||||
});
|
||||
glm::mat3 normalMatrix = glm::mat3(glm::transpose(glm::inverse(model)));
|
||||
shader->set("normalMatrix", normalMatrix);
|
||||
shader->set("texScale", part->scale);
|
||||
|
|
Loading…
Reference in a new issue