From 0c9935a3c0e8e5b2615729458b93ae0cfaf35548 Mon Sep 17 00:00:00 2001 From: Dane Johnson Date: Wed, 20 Jan 2021 15:16:44 -0600 Subject: [PATCH] Materials are just structs --- core/Mesh.cpp | 10 ++++------ core/Mesh.h | 4 ++-- demo/main.lua | 10 +++++----- scripting/couch.i | 6 ------ 4 files changed, 11 insertions(+), 19 deletions(-) diff --git a/core/Mesh.cpp b/core/Mesh.cpp index 4dcb830..b6b1206 100644 --- a/core/Mesh.cpp +++ b/core/Mesh.cpp @@ -1,8 +1,6 @@ #include "Mesh.h" -SubMesh::SubMesh() { - material = new Material(); -} +SubMesh::SubMesh() {} SubMesh::SubMesh(VertexList vertices, IndexList indices) { this->vertices = vertices; @@ -35,8 +33,8 @@ void SubMesh::SetupSubMesh() { } void SubMesh::Draw(Shader *shader) { - shader->UpdateColor(material->usesColor, material->color); - shader->UpdateTex(material->usesTex, material->tex); + shader->UpdateColor(material.usesColor, material.color); + shader->UpdateTex(material.usesTex, material.tex); glBindVertexArray(VAO); glDrawElements(GL_TRIANGLES, indices.size() * 3, GL_UNSIGNED_INT, 0); glBindVertexArray(0); @@ -56,7 +54,7 @@ void Mesh::SetupMesh() { } } -void Mesh::SetMaterial(int submesh, Material *material) { +void Mesh::SetMaterial(int submesh, Material material) { submeshes[submesh]->material = material; } diff --git a/core/Mesh.h b/core/Mesh.h index f045f55..cde76ef 100644 --- a/core/Mesh.h +++ b/core/Mesh.h @@ -24,7 +24,7 @@ public: SubMesh(VertexList vertices, IndexList indices); VertexList vertices; IndexList indices; - Material *material; + Material material; void SetupSubMesh(); void Draw(Shader *shader); private: @@ -37,7 +37,7 @@ class Mesh : public Spatial { public: Mesh(); ~Mesh(); - void SetMaterial(int submesh, Material *material); + void SetMaterial(int submesh, Material material); static Mesh *FromFile(const char *filename); virtual bool IsDrawable() const {return true;} virtual void Draw(Shader *shader); diff --git a/demo/main.lua b/demo/main.lua index 8a7fc26..f78fd02 100644 --- a/demo/main.lua +++ b/demo/main.lua @@ -31,14 +31,14 @@ function init() camera.transform:Translate(0.0, 0.0, 10.0) ball = couch.Ball() ball:SetupMesh() - material = couch.Material.new() + material = couch.Material() material.color = RED material.usesColor = true ball:SetMaterial(0, material) couch.Node.GetRoot().children:Append(ball) ball1 = couch.Ball() ball1:SetupMesh() - material = couch.Material.new() + material = couch.Material() material.tex = couch.Texture.FromFile("container.png") material.usesTex = true ball1:SetMaterial(0, material) @@ -48,7 +48,7 @@ function init() trough = couch.Mesh.FromFile("trough.glb") trough:SetupMesh() - material = couch.Material.new() + material = couch.Material() material.tex = couch.Texture.FromFile("wood_lowres.png") material.usesTex = true trough:SetMaterial(0, material) @@ -57,11 +57,11 @@ function init() scaffold = couch.Mesh.FromFile("scaffold.glb") scaffold:SetupMesh() - material = couch.Material.new() + material = couch.Material() material.tex = couch.Texture.FromFile("grate_floor_lowres.png") material.usesTex = true scaffold:SetMaterial(0, material) - material = couch.Material.new() + material = couch.Material() material.tex = couch.Texture.FromFile("railing.png") material.usesTex = true scaffold:SetMaterial(1, material) diff --git a/scripting/couch.i b/scripting/couch.i index 07691a4..92b2fed 100644 --- a/scripting/couch.i +++ b/scripting/couch.i @@ -34,12 +34,6 @@ public: } %ignore "Vector3"; -%extend Material { - static Material* Material::script_new() { - return new Material(); - } -} - %include "types.h" %include "Node.h" %include "Spatial.h"