mirror of https://github.com/bjornbytes/lovr.git
luax_readtriangles -> luax_readmesh; Model support;
This commit is contained in:
parent
e1195a92a0
commit
fe0eedea20
|
@ -6,6 +6,9 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#ifndef LOVR_DISABLE_GRAPHICS
|
||||
#include "graphics/model.h"
|
||||
#endif
|
||||
|
||||
typedef void voidFn(void);
|
||||
typedef void destructorFn(void*);
|
||||
|
@ -408,7 +411,7 @@ void luax_readcolor(lua_State* L, int index, Color* color) {
|
|||
}
|
||||
}
|
||||
|
||||
int luax_readtriangles(lua_State* L, int index, float** vertices, uint32_t* vertexCount, uint32_t** indices, uint32_t* indexCount, bool* shouldFree) {
|
||||
int luax_readmesh(lua_State* L, int index, float** vertices, uint32_t* vertexCount, uint32_t** indices, uint32_t* indexCount, bool* shouldFree) {
|
||||
if (lua_istable(L, index)) {
|
||||
luaL_checktype(L, index + 1, LUA_TTABLE);
|
||||
*vertexCount = luax_len(L, index) / 3;
|
||||
|
@ -434,5 +437,13 @@ int luax_readtriangles(lua_State* L, int index, float** vertices, uint32_t* vert
|
|||
return index + 2;
|
||||
}
|
||||
|
||||
#ifndef LOVR_DISABLE_GRAPHICS
|
||||
Model* model = luax_totype(L, index, Model);
|
||||
if (model) {
|
||||
lovrModelGetTriangles(model, vertices, vertexCount, indices, indexCount);
|
||||
*shouldFree = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return luaL_argerror(L, index, "table or Model");
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ int luax_setconf(struct lua_State* L);
|
|||
void luax_setmainthread(struct lua_State* L);
|
||||
void luax_atexit(struct lua_State* L, void (*destructor)(void));
|
||||
void luax_readcolor(struct lua_State* L, int index, struct Color* color);
|
||||
int luax_readtriangles(struct lua_State* L, int index, float** vertices, uint32_t* vertexCount, uint32_t** indices, uint32_t* indexCount, bool* shouldFree);
|
||||
int luax_readmesh(struct lua_State* L, int index, float** vertices, uint32_t* vertexCount, uint32_t** indices, uint32_t* indexCount, bool* shouldFree);
|
||||
|
||||
// Module helpers
|
||||
|
||||
|
|
|
@ -186,7 +186,7 @@ static int l_lovrAudioSetGeometry(lua_State* L) {
|
|||
uint32_t* indices;
|
||||
uint32_t vertexCount, indexCount;
|
||||
bool shouldFree;
|
||||
int index = luax_readtriangles(L, 1, &vertices, &vertexCount, &indices, &indexCount, &shouldFree);
|
||||
int index = luax_readmesh(L, 1, &vertices, &vertexCount, &indices, &indexCount, &shouldFree);
|
||||
AudioMaterial material = luax_checkenum(L, index, AudioMaterial, "generic");
|
||||
bool success = lovrAudioSetGeometry(vertices, indices, vertexCount, indexCount, material);
|
||||
if (shouldFree) {
|
||||
|
|
Loading…
Reference in New Issue