Remove ball (meshes must be loaded from file)

This commit is contained in:
Dane Johnson 2021-01-20 17:05:59 -06:00
parent 0c9935a3c0
commit 391060d9ba
10 changed files with 35 additions and 76 deletions

View File

@ -30,7 +30,7 @@ set_property(SOURCE scripting/couch.i PROPERTY CPLUSPLUS ON)
swig_add_library(couchlua
TYPE STATIC
LANGUAGE lua
SOURCES scripting/couch.i)
SOURCES scripting/couch.i scripting/lua/helpers.i)
target_link_libraries(couchlua ${LUA_LIBRARIES})
target_link_libraries(couch couchlua)

View File

@ -1,39 +0,0 @@
#include "Ball.h"
Ball::Ball() {
IndexList indices;
VertexList vertices;
// It's a cube really
// Front
vertices.push_back(Vertex(1.0f, 1.0f, 1.0f, 0.0f, 1.0f));
vertices.push_back(Vertex(1.0f, -1.0f, 1.0f, 0.0f, 0.0f));
vertices.push_back(Vertex(-1.0f, 1.0f, 1.0f, 1.0f, 1.0f));
vertices.push_back(Vertex(-1.0f, -1.0f, 1.0f, 1.0f, 0.0f));
// Back
vertices.push_back(Vertex(1.0f, 1.0f, -1.0f, 0.0f, 0.0f));
vertices.push_back(Vertex(1.0f, -1.0f, -1.0f, 0.0f, 1.0f));
vertices.push_back(Vertex(-1.0f, 1.0f, -1.0f, 1.0f, 0.0f));
vertices.push_back(Vertex(-1.0f, -1.0f, -1.0f, 1.0f, 1.0f));
//Front
indices.push_back(Index(0, 1, 2));
indices.push_back(Index(1, 2, 3));
//Back
indices.push_back(Index(4, 5, 6));
indices.push_back(Index(5, 6, 7));
// Top
indices.push_back(Index(0, 4, 6));
indices.push_back(Index(0, 2, 6));
// Bottom
indices.push_back(Index(1, 3, 7));
indices.push_back(Index(1, 5, 7));
// Left side
indices.push_back(Index(0, 1, 5));
indices.push_back(Index(0, 4, 5));
// Right side
indices.push_back(Index(2, 3, 7));
indices.push_back(Index(2, 6, 7));
submeshes.push_back(new SubMesh(vertices, indices));
}

View File

@ -1,11 +0,0 @@
#ifndef BALL_H
#define BALL_H
#include "Mesh.h"
class Ball : public Mesh {
public:
Ball();
};
#endif /* BALL_H */

View File

@ -80,6 +80,8 @@ Mesh* Mesh::FromFile(const char *filename) {
my_mesh->submeshes.push_back(aiMesh2SubMesh(mesh_to_import));
}
my_mesh->SetupMesh();
return my_mesh;
}

View File

@ -25,10 +25,11 @@ public:
VertexList vertices;
IndexList indices;
Material material;
void SetupSubMesh();
void Draw(Shader *shader);
private:
Id VAO, VBO, EBO;
void SetupSubMesh();
friend class Mesh;
};
typedef std::vector<SubMesh*> SubMeshList;
@ -41,9 +42,9 @@ public:
static Mesh *FromFile(const char *filename);
virtual bool IsDrawable() const {return true;}
virtual void Draw(Shader *shader);
virtual void SetupMesh();
protected:
SubMeshList submeshes;
virtual void SetupMesh();
private:
static SubMesh *aiMesh2SubMesh(aiMesh *mesh);
};

View File

@ -13,10 +13,10 @@
#include "Screen.h"
#include "Ball.h"
#include "Camera.h"
#include "Input.h"
#include "Node.h"
#include "Mesh.h"
#include "Scripting/Lua.h"
// Thirdparty Includes

BIN
demo/cube.glb Normal file

Binary file not shown.

View File

@ -29,15 +29,15 @@ function init()
camera = couch.Camera()
camera:MakeCurrent()
camera.transform:Translate(0.0, 0.0, 10.0)
ball = couch.Ball()
ball:SetupMesh()
ball = couch.Mesh.FromFile("cube.glb")
material = couch.Material()
material.color = RED
material.usesColor = true
ball:SetMaterial(0, material)
couch.Node.GetRoot().children:Append(ball)
ball1 = couch.Ball()
ball1:SetupMesh()
ball1 = couch.Mesh.FromFile("cube.glb")
material = couch.Material()
material.tex = couch.Texture.FromFile("container.png")
material.usesTex = true
@ -46,25 +46,11 @@ function init()
ball1.transform:Translate(0.0, 3.0, 0.0)
trough = couch.Mesh.FromFile("trough.glb")
trough:SetupMesh()
material = couch.Material()
material.tex = couch.Texture.FromFile("wood_lowres.png")
material.usesTex = true
trough:SetMaterial(0, material)
trough = couch.TexturedMesh("trough.glb", "wood_lowres.png")
couch.Node.GetRoot().children:Append(trough)
trough.transform:Translate(10.0, 0.0, 0.0)
scaffold = couch.Mesh.FromFile("scaffold.glb")
scaffold:SetupMesh()
material = couch.Material()
material.tex = couch.Texture.FromFile("grate_floor_lowres.png")
material.usesTex = true
scaffold:SetMaterial(0, material)
material = couch.Material()
material.tex = couch.Texture.FromFile("railing.png")
material.usesTex = true
scaffold:SetMaterial(1, material)
scaffold = couch.TexturedMesh("scaffold.glb", "grate_floor_lowres.png", "railing.png")
couch.Node.GetRoot().children:Append(scaffold)
scaffold.transform:Translate(-10.0, 0.0, 0.0)
end

View File

@ -1,6 +1,9 @@
%module couch
%include "typemaps.i"
#ifdef SWIGLUA
%include "lua/helpers.i"
#endif // SWIGLUA
%{
#include "types.h"
@ -8,7 +11,6 @@
#include "Transform.h"
#include "Spatial.h"
#include "Mesh.h"
#include "Ball.h"
#include "Material.h"
#include "Camera.h"
%}
@ -38,7 +40,6 @@ public:
%include "Node.h"
%include "Spatial.h"
%include "Mesh.h"
%include "Ball.h"
%include "Transform.h"
%include "Material.h"
%include "Camera.h"

19
scripting/lua/helpers.i Normal file
View File

@ -0,0 +1,19 @@
%module helpers
%luacode {
function couch.TexturedMesh(meshfile, ...)
local mesh = couch.Mesh.FromFile(meshfile)
for i, texturefile in ipairs({...}) do
local material = couch.Material()
material.usesTex = true
material.tex = couch.Texture.FromFile(texturefile)
mesh:SetMaterial(i - 1, material)
end
return mesh
end
} // luacode
// Local Variables:
// mode: poly-swig
// End: