Mesh:getVertexMap with tables and Blobs;

This commit is contained in:
bjorn 2018-04-01 21:25:48 -07:00
parent 25a267acd1
commit b180b28037
2 changed files with 19 additions and 2 deletions

View File

@ -185,11 +185,22 @@ int l_lovrMeshGetVertexMap(lua_State* L) {
return 1;
}
lua_newtable(L);
if (lua_istable(L, 2)) {
lua_settop(L, 2);
} else if (lua_isuserdata(L, 2)) {
Blob* blob = luax_checktypeof(L, 2, Blob);
lovrAssert(size * count <= blob->size, "Mesh vertex map is %zu bytes, but Blob can only hold %zu", size * count, blob->size);
memcpy(blob->data, indices.raw, size * count);
return 0;
} else {
lua_settop(L, 1);
lua_createtable(L, count, 0);
}
for (size_t i = 0; i < count; i++) {
uint32_t index = size == sizeof(uint32_t) ? indices.ints[i] : indices.shorts[i];
lua_pushinteger(L, index + 1);
lua_rawseti(L, -2, i + 1);
lua_rawseti(L, 2, i + 1);
}
return 1;

View File

@ -237,6 +237,8 @@ void lovrMeshUnmapVertices(Mesh* mesh) {
IndexPointer lovrMeshReadIndices(Mesh* mesh, uint32_t* count, size_t* size) {
if (mesh->indexCount == 0) {
return (IndexPointer) { .raw = NULL };
} else if (mesh->mappedIndices) {
lovrMeshUnmapIndices(mesh);
}
*size = mesh->indexSize;
@ -252,6 +254,10 @@ IndexPointer lovrMeshReadIndices(Mesh* mesh, uint32_t* count, size_t* size) {
}
IndexPointer lovrMeshWriteIndices(Mesh* mesh, uint32_t count, size_t size) {
if (mesh->mappedIndices) {
lovrMeshUnmapIndices(mesh);
}
mesh->indexSize = size;
mesh->indexCount = count;