Remove ball (meshes must be loaded from file)
This commit is contained in:
parent
57c1874412
commit
cce51dc747
@ -30,7 +30,7 @@ set_property(SOURCE scripting/couch.i PROPERTY CPLUSPLUS ON)
|
|||||||
swig_add_library(couchlua
|
swig_add_library(couchlua
|
||||||
TYPE STATIC
|
TYPE STATIC
|
||||||
LANGUAGE lua
|
LANGUAGE lua
|
||||||
SOURCES scripting/couch.i)
|
SOURCES scripting/couch.i scripting/lua/helpers.i)
|
||||||
target_link_libraries(couchlua ${LUA_LIBRARIES})
|
target_link_libraries(couchlua ${LUA_LIBRARIES})
|
||||||
target_link_libraries(couch couchlua)
|
target_link_libraries(couch couchlua)
|
||||||
|
|
||||||
|
@ -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));
|
|
||||||
}
|
|
||||||
|
|
11
core/Ball.h
11
core/Ball.h
@ -1,11 +0,0 @@
|
|||||||
#ifndef BALL_H
|
|
||||||
#define BALL_H
|
|
||||||
|
|
||||||
#include "Mesh.h"
|
|
||||||
|
|
||||||
class Ball : public Mesh {
|
|
||||||
public:
|
|
||||||
Ball();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* BALL_H */
|
|
@ -80,6 +80,8 @@ Mesh* Mesh::FromFile(const char *filename) {
|
|||||||
my_mesh->submeshes.push_back(aiMesh2SubMesh(mesh_to_import));
|
my_mesh->submeshes.push_back(aiMesh2SubMesh(mesh_to_import));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my_mesh->SetupMesh();
|
||||||
|
|
||||||
return my_mesh;
|
return my_mesh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,10 +25,11 @@ public:
|
|||||||
VertexList vertices;
|
VertexList vertices;
|
||||||
IndexList indices;
|
IndexList indices;
|
||||||
Material material;
|
Material material;
|
||||||
void SetupSubMesh();
|
|
||||||
void Draw(Shader *shader);
|
void Draw(Shader *shader);
|
||||||
private:
|
private:
|
||||||
Id VAO, VBO, EBO;
|
Id VAO, VBO, EBO;
|
||||||
|
void SetupSubMesh();
|
||||||
|
friend class Mesh;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<SubMesh*> SubMeshList;
|
typedef std::vector<SubMesh*> SubMeshList;
|
||||||
@ -41,9 +42,9 @@ public:
|
|||||||
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);
|
||||||
virtual void SetupMesh();
|
|
||||||
protected:
|
protected:
|
||||||
SubMeshList submeshes;
|
SubMeshList submeshes;
|
||||||
|
virtual void SetupMesh();
|
||||||
private:
|
private:
|
||||||
static SubMesh *aiMesh2SubMesh(aiMesh *mesh);
|
static SubMesh *aiMesh2SubMesh(aiMesh *mesh);
|
||||||
};
|
};
|
||||||
|
@ -13,10 +13,10 @@
|
|||||||
|
|
||||||
#include "Screen.h"
|
#include "Screen.h"
|
||||||
|
|
||||||
#include "Ball.h"
|
|
||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
#include "Input.h"
|
#include "Input.h"
|
||||||
#include "Node.h"
|
#include "Node.h"
|
||||||
|
#include "Mesh.h"
|
||||||
#include "Scripting/Lua.h"
|
#include "Scripting/Lua.h"
|
||||||
|
|
||||||
// Thirdparty Includes
|
// Thirdparty Includes
|
||||||
|
BIN
demo/cube.glb
Normal file
BIN
demo/cube.glb
Normal file
Binary file not shown.
@ -29,15 +29,15 @@ function init()
|
|||||||
camera = couch.Camera()
|
camera = couch.Camera()
|
||||||
camera:MakeCurrent()
|
camera:MakeCurrent()
|
||||||
camera.transform:Translate(0.0, 0.0, 10.0)
|
camera.transform:Translate(0.0, 0.0, 10.0)
|
||||||
ball = couch.Ball()
|
|
||||||
ball:SetupMesh()
|
ball = couch.Mesh.FromFile("cube.glb")
|
||||||
material = couch.Material()
|
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:SetupMesh()
|
ball1 = couch.Mesh.FromFile("cube.glb")
|
||||||
material = couch.Material()
|
material = couch.Material()
|
||||||
material.tex = couch.Texture.FromFile("container.png")
|
material.tex = couch.Texture.FromFile("container.png")
|
||||||
material.usesTex = true
|
material.usesTex = true
|
||||||
@ -46,25 +46,11 @@ function init()
|
|||||||
|
|
||||||
ball1.transform:Translate(0.0, 3.0, 0.0)
|
ball1.transform:Translate(0.0, 3.0, 0.0)
|
||||||
|
|
||||||
trough = couch.Mesh.FromFile("trough.glb")
|
trough = couch.TexturedMesh("trough.glb", "wood_lowres.png")
|
||||||
trough:SetupMesh()
|
|
||||||
material = couch.Material()
|
|
||||||
material.tex = couch.Texture.FromFile("wood_lowres.png")
|
|
||||||
material.usesTex = true
|
|
||||||
trough:SetMaterial(0, material)
|
|
||||||
couch.Node.GetRoot().children:Append(trough)
|
couch.Node.GetRoot().children:Append(trough)
|
||||||
trough.transform:Translate(10.0, 0.0, 0.0)
|
trough.transform:Translate(10.0, 0.0, 0.0)
|
||||||
|
|
||||||
scaffold = couch.Mesh.FromFile("scaffold.glb")
|
scaffold = couch.TexturedMesh("scaffold.glb", "grate_floor_lowres.png", "railing.png")
|
||||||
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)
|
|
||||||
couch.Node.GetRoot().children:Append(scaffold)
|
couch.Node.GetRoot().children:Append(scaffold)
|
||||||
scaffold.transform:Translate(-10.0, 0.0, 0.0)
|
scaffold.transform:Translate(-10.0, 0.0, 0.0)
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
%module couch
|
%module couch
|
||||||
|
|
||||||
%include "typemaps.i"
|
%include "typemaps.i"
|
||||||
|
#ifdef SWIGLUA
|
||||||
|
%include "lua/helpers.i"
|
||||||
|
#endif // SWIGLUA
|
||||||
|
|
||||||
%{
|
%{
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
@ -8,7 +11,6 @@
|
|||||||
#include "Transform.h"
|
#include "Transform.h"
|
||||||
#include "Spatial.h"
|
#include "Spatial.h"
|
||||||
#include "Mesh.h"
|
#include "Mesh.h"
|
||||||
#include "Ball.h"
|
|
||||||
#include "Material.h"
|
#include "Material.h"
|
||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
%}
|
%}
|
||||||
@ -38,7 +40,6 @@ public:
|
|||||||
%include "Node.h"
|
%include "Node.h"
|
||||||
%include "Spatial.h"
|
%include "Spatial.h"
|
||||||
%include "Mesh.h"
|
%include "Mesh.h"
|
||||||
%include "Ball.h"
|
|
||||||
%include "Transform.h"
|
%include "Transform.h"
|
||||||
%include "Material.h"
|
%include "Material.h"
|
||||||
%include "Camera.h"
|
%include "Camera.h"
|
||||||
|
19
scripting/lua/helpers.i
Normal file
19
scripting/lua/helpers.i
Normal 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:
|
Loading…
Reference in New Issue
Block a user