Added Mesh:getVertices (resolves issue #771)

This commit is contained in:
Alex Szpakowski
2013-10-23 21:23:24 -03:00
parent b2725f8cf5
commit 206a1abd81
4 changed files with 64 additions and 0 deletions
+11
View File
@@ -76,6 +76,17 @@ void Mesh::setVertices(const std::vector<Vertex> &verts)
memcpy(vbo_mapper.get(), &verts[0], size);
}
const Vertex *Mesh::getVertices() const
{
if (vbo)
{
VertexBuffer::Bind vbo_bind(*vbo);
return (Vertex *) vbo->map();
}
return nullptr;
}
void Mesh::setVertex(size_t index, const Vertex &v)
{
if (index >= vertex_count)
+5
View File
@@ -71,6 +71,11 @@ public:
**/
void setVertices(const std::vector<Vertex> &verts);
/**
* Gets all of the vertices in the Mesh as an array.
**/
const Vertex *getVertices() const;
/**
* Sets an individual vertex in the Mesh.
* @param index The index into the list of vertices to use.
+47
View File
@@ -133,6 +133,52 @@ int w_Mesh_setVertices(lua_State *L)
return 0;
}
int w_Mesh_getVertices(lua_State *L)
{
Mesh *t = luax_checkmesh(L, 1);
const Vertex *vertices = t->getVertices();
size_t count = t->getVertexCount();
lua_createtable(L, count, 0);
for (size_t i = 0; i < count; i++)
{
// Create vertex table.
lua_createtable(L, 8, 0);
lua_pushnumber(L, vertices[i].x);
lua_rawseti(L, -2, 1);
lua_pushnumber(L, vertices[i].y);
lua_rawseti(L, -2, 2);
lua_pushnumber(L, vertices[i].s);
lua_rawseti(L, -2, 3);
lua_pushnumber(L, vertices[i].t);
lua_rawseti(L, -2, 4);
lua_pushnumber(L, vertices[i].r);
lua_rawseti(L, -2, 5);
lua_pushnumber(L, vertices[i].g);
lua_rawseti(L, -2, 6);
lua_pushnumber(L, vertices[i].b);
lua_rawseti(L, -2, 7);
lua_pushnumber(L, vertices[i].a);
lua_rawseti(L, -2, 8);
// Insert vertex table into vertices table.
lua_rawseti(L, -2, i + 1);
}
// Return vertices table.
return 1;
}
int w_Mesh_getVertexCount(lua_State *L)
{
Mesh *t = luax_checkmesh(L, 1);
@@ -258,6 +304,7 @@ static const luaL_Reg functions[] =
{ "setVertex", w_Mesh_setVertex },
{ "getVertex", w_Mesh_getVertex },
{ "setVertices", w_Mesh_setVertices },
{ "getVertices", w_Mesh_getVertices },
{ "getVertexCount", w_Mesh_getVertexCount },
{ "setVertexMap", w_Mesh_setVertexMap },
{ "getVertexMap", w_Mesh_getVertexMap },
+1
View File
@@ -37,6 +37,7 @@ Mesh *luax_checkmesh(lua_State *L, int idx);
int w_Mesh_setVertex(lua_State *L);
int w_Mesh_getVertex(lua_State *L);
int w_Mesh_setVertices(lua_State *L);
int w_Mesh_getVertices(lua_State *L);
int w_Mesh_getVertexCount(lua_State *L);
int w_Mesh_setVertexMap(lua_State *L);
int w_Mesh_getVertexMap(lua_State *L);