Materials are just structs

This commit is contained in:
Dane Johnson 2021-01-20 15:16:44 -06:00
parent 745f03d8a2
commit 0c9935a3c0
4 changed files with 11 additions and 19 deletions

View File

@ -1,8 +1,6 @@
#include "Mesh.h" #include "Mesh.h"
SubMesh::SubMesh() { SubMesh::SubMesh() {}
material = new Material();
}
SubMesh::SubMesh(VertexList vertices, IndexList indices) { SubMesh::SubMesh(VertexList vertices, IndexList indices) {
this->vertices = vertices; this->vertices = vertices;
@ -35,8 +33,8 @@ void SubMesh::SetupSubMesh() {
} }
void SubMesh::Draw(Shader *shader) { void SubMesh::Draw(Shader *shader) {
shader->UpdateColor(material->usesColor, material->color); shader->UpdateColor(material.usesColor, material.color);
shader->UpdateTex(material->usesTex, material->tex); shader->UpdateTex(material.usesTex, material.tex);
glBindVertexArray(VAO); glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, indices.size() * 3, GL_UNSIGNED_INT, 0); glDrawElements(GL_TRIANGLES, indices.size() * 3, GL_UNSIGNED_INT, 0);
glBindVertexArray(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; submeshes[submesh]->material = material;
} }

View File

@ -24,7 +24,7 @@ public:
SubMesh(VertexList vertices, IndexList indices); SubMesh(VertexList vertices, IndexList indices);
VertexList vertices; VertexList vertices;
IndexList indices; IndexList indices;
Material *material; Material material;
void SetupSubMesh(); void SetupSubMesh();
void Draw(Shader *shader); void Draw(Shader *shader);
private: private:
@ -37,7 +37,7 @@ class Mesh : public Spatial {
public: public:
Mesh(); Mesh();
~Mesh(); ~Mesh();
void SetMaterial(int submesh, Material *material); void SetMaterial(int submesh, Material material);
static Mesh *FromFile(const char *filename); static Mesh *FromFile(const char *filename);
virtual bool IsDrawable() const {return true;} virtual bool IsDrawable() const {return true;}
virtual void Draw(Shader *shader); virtual void Draw(Shader *shader);

View File

@ -31,14 +31,14 @@ function init()
camera.transform:Translate(0.0, 0.0, 10.0) camera.transform:Translate(0.0, 0.0, 10.0)
ball = couch.Ball() ball = couch.Ball()
ball:SetupMesh() ball:SetupMesh()
material = couch.Material.new() material = couch.Material()
material.color = RED material.color = RED
material.usesColor = true material.usesColor = true
ball:SetMaterial(0, material) ball:SetMaterial(0, material)
couch.Node.GetRoot().children:Append(ball) couch.Node.GetRoot().children:Append(ball)
ball1 = couch.Ball() ball1 = couch.Ball()
ball1:SetupMesh() ball1:SetupMesh()
material = couch.Material.new() material = couch.Material()
material.tex = couch.Texture.FromFile("container.png") material.tex = couch.Texture.FromFile("container.png")
material.usesTex = true material.usesTex = true
ball1:SetMaterial(0, material) ball1:SetMaterial(0, material)
@ -48,7 +48,7 @@ function init()
trough = couch.Mesh.FromFile("trough.glb") trough = couch.Mesh.FromFile("trough.glb")
trough:SetupMesh() trough:SetupMesh()
material = couch.Material.new() material = couch.Material()
material.tex = couch.Texture.FromFile("wood_lowres.png") material.tex = couch.Texture.FromFile("wood_lowres.png")
material.usesTex = true material.usesTex = true
trough:SetMaterial(0, material) trough:SetMaterial(0, material)
@ -57,11 +57,11 @@ function init()
scaffold = couch.Mesh.FromFile("scaffold.glb") scaffold = couch.Mesh.FromFile("scaffold.glb")
scaffold:SetupMesh() scaffold:SetupMesh()
material = couch.Material.new() material = couch.Material()
material.tex = couch.Texture.FromFile("grate_floor_lowres.png") material.tex = couch.Texture.FromFile("grate_floor_lowres.png")
material.usesTex = true material.usesTex = true
scaffold:SetMaterial(0, material) scaffold:SetMaterial(0, material)
material = couch.Material.new() material = couch.Material()
material.tex = couch.Texture.FromFile("railing.png") material.tex = couch.Texture.FromFile("railing.png")
material.usesTex = true material.usesTex = true
scaffold:SetMaterial(1, material) scaffold:SetMaterial(1, material)

View File

@ -34,12 +34,6 @@ public:
} }
%ignore "Vector3"; %ignore "Vector3";
%extend Material {
static Material* Material::script_new() {
return new Material();
}
}
%include "types.h" %include "types.h"
%include "Node.h" %include "Node.h"
%include "Spatial.h" %include "Spatial.h"