diff --git a/src/api/l_data.c b/src/api/l_data.c index 691dc195..c9275936 100644 --- a/src/api/l_data.c +++ b/src/api/l_data.c @@ -18,20 +18,20 @@ StringEntry lovrAnimationProperty[] = { }; StringEntry lovrAttributeType[] = { - [I8] = ENTRY("byte"), - [U8] = ENTRY("ubyte"), - [I16] = ENTRY("short"), - [U16] = ENTRY("ushort"), - [I32] = ENTRY("int"), - [U32] = ENTRY("uint"), - [F32] = ENTRY("float"), + [I8] = ENTRY("i8"), + [U8] = ENTRY("u8"), + [I16] = ENTRY("i16"), + [U16] = ENTRY("u16"), + [I32] = ENTRY("i32"), + [U32] = ENTRY("u32"), + [F32] = ENTRY("f32"), { 0 } }; StringEntry lovrDefaultAttribute[] = { [ATTR_POSITION] = ENTRY("position"), [ATTR_NORMAL] = ENTRY("normal"), - [ATTR_TEXCOORD] = ENTRY("texcoord"), + [ATTR_UV] = ENTRY("uv"), [ATTR_COLOR] = ENTRY("color"), [ATTR_TANGENT] = ENTRY("tangent"), [ATTR_JOINTS] = ENTRY("joints"), diff --git a/src/api/l_data_modelData.c b/src/api/l_data_modelData.c index dcb0345d..7f0d049d 100644 --- a/src/api/l_data_modelData.c +++ b/src/api/l_data_modelData.c @@ -102,74 +102,6 @@ static int l_lovrModelDataGetImage(lua_State* L) { return 1; } -static int l_lovrModelDataGetWidth(lua_State* L) { - ModelData* model = luax_checktype(L, 1, ModelData); - float bounds[6]; - lovrModelDataGetBoundingBox(model, bounds); - lua_pushnumber(L, bounds[1] - bounds[0]); - return 1; -} - -static int l_lovrModelDataGetHeight(lua_State* L) { - ModelData* model = luax_checktype(L, 1, ModelData); - float bounds[6]; - lovrModelDataGetBoundingBox(model, bounds); - lua_pushnumber(L, bounds[3] - bounds[2]); - return 1; -} - -static int l_lovrModelDataGetDepth(lua_State* L) { - ModelData* model = luax_checktype(L, 1, ModelData); - float bounds[6]; - lovrModelDataGetBoundingBox(model, bounds); - lua_pushnumber(L, bounds[5] - bounds[4]); - return 1; -} - -static int l_lovrModelDataGetDimensions(lua_State* L) { - ModelData* model = luax_checktype(L, 1, ModelData); - float bounds[6]; - lovrModelDataGetBoundingBox(model, bounds); - lua_pushnumber(L, bounds[1] - bounds[0]); - lua_pushnumber(L, bounds[3] - bounds[2]); - lua_pushnumber(L, bounds[5] - bounds[4]); - return 3; -} - -static int l_lovrModelDataGetCenter(lua_State* L) { - ModelData* model = luax_checktype(L, 1, ModelData); - float bounds[6]; - lovrModelDataGetBoundingBox(model, bounds); - lua_pushnumber(L, (bounds[0] + bounds[1]) / 2.f); - lua_pushnumber(L, (bounds[2] + bounds[3]) / 2.f); - lua_pushnumber(L, (bounds[4] + bounds[5]) / 2.f); - return 3; -} - -static int l_lovrModelDataGetBoundingBox(lua_State* L) { - ModelData* model = luax_checktype(L, 1, ModelData); - float bounds[6]; - lovrModelDataGetBoundingBox(model, bounds); - lua_pushnumber(L, bounds[0]); - lua_pushnumber(L, bounds[1]); - lua_pushnumber(L, bounds[2]); - lua_pushnumber(L, bounds[3]); - lua_pushnumber(L, bounds[4]); - lua_pushnumber(L, bounds[5]); - return 6; -} - -static int l_lovrModelDataGetBoundingSphere(lua_State* L) { - ModelData* model = luax_checktype(L, 1, ModelData); - float sphere[4]; - lovrModelDataGetBoundingSphere(model, sphere); - lua_pushnumber(L, sphere[0]); - lua_pushnumber(L, sphere[1]); - lua_pushnumber(L, sphere[2]); - lua_pushnumber(L, sphere[3]); - return 4; -} - static int l_lovrModelDataGetRootNode(lua_State* L) { ModelData* model = luax_checktype(L, 1, ModelData); lua_pushinteger(L, model->rootNode + 1); @@ -546,6 +478,74 @@ static int l_lovrModelDataGetVertexCount(lua_State* L) { return 1; } +static int l_lovrModelDataGetWidth(lua_State* L) { + ModelData* model = luax_checktype(L, 1, ModelData); + float bounds[6]; + lovrModelDataGetBoundingBox(model, bounds); + lua_pushnumber(L, bounds[1] - bounds[0]); + return 1; +} + +static int l_lovrModelDataGetHeight(lua_State* L) { + ModelData* model = luax_checktype(L, 1, ModelData); + float bounds[6]; + lovrModelDataGetBoundingBox(model, bounds); + lua_pushnumber(L, bounds[3] - bounds[2]); + return 1; +} + +static int l_lovrModelDataGetDepth(lua_State* L) { + ModelData* model = luax_checktype(L, 1, ModelData); + float bounds[6]; + lovrModelDataGetBoundingBox(model, bounds); + lua_pushnumber(L, bounds[5] - bounds[4]); + return 1; +} + +static int l_lovrModelDataGetDimensions(lua_State* L) { + ModelData* model = luax_checktype(L, 1, ModelData); + float bounds[6]; + lovrModelDataGetBoundingBox(model, bounds); + lua_pushnumber(L, bounds[1] - bounds[0]); + lua_pushnumber(L, bounds[3] - bounds[2]); + lua_pushnumber(L, bounds[5] - bounds[4]); + return 3; +} + +static int l_lovrModelDataGetCenter(lua_State* L) { + ModelData* model = luax_checktype(L, 1, ModelData); + float bounds[6]; + lovrModelDataGetBoundingBox(model, bounds); + lua_pushnumber(L, (bounds[0] + bounds[1]) / 2.f); + lua_pushnumber(L, (bounds[2] + bounds[3]) / 2.f); + lua_pushnumber(L, (bounds[4] + bounds[5]) / 2.f); + return 3; +} + +static int l_lovrModelDataGetBoundingBox(lua_State* L) { + ModelData* model = luax_checktype(L, 1, ModelData); + float bounds[6]; + lovrModelDataGetBoundingBox(model, bounds); + lua_pushnumber(L, bounds[0]); + lua_pushnumber(L, bounds[1]); + lua_pushnumber(L, bounds[2]); + lua_pushnumber(L, bounds[3]); + lua_pushnumber(L, bounds[4]); + lua_pushnumber(L, bounds[5]); + return 6; +} + +static int l_lovrModelDataGetBoundingSphere(lua_State* L) { + ModelData* model = luax_checktype(L, 1, ModelData); + float sphere[4]; + lovrModelDataGetBoundingSphere(model, sphere); + lua_pushnumber(L, sphere[0]); + lua_pushnumber(L, sphere[1]); + lua_pushnumber(L, sphere[2]); + lua_pushnumber(L, sphere[3]); + return 4; +} + static int l_lovrModelDataGetMaterialCount(lua_State* L) { ModelData* model = luax_checktype(L, 1, ModelData); lua_pushinteger(L, model->materialCount); diff --git a/src/modules/data/modelData.h b/src/modules/data/modelData.h index 5b76ca01..d1abb43b 100644 --- a/src/modules/data/modelData.h +++ b/src/modules/data/modelData.h @@ -19,7 +19,7 @@ typedef struct { typedef enum { ATTR_POSITION, ATTR_NORMAL, - ATTR_TEXCOORD, + ATTR_UV, ATTR_COLOR, ATTR_TANGENT, ATTR_JOINTS, diff --git a/src/modules/data/modelData_gltf.c b/src/modules/data/modelData_gltf.c index d1fd8140..b089d99d 100644 --- a/src/modules/data/modelData_gltf.c +++ b/src/modules/data/modelData_gltf.c @@ -813,7 +813,7 @@ ModelData* lovrModelDataInitGltf(ModelData* model, Blob* source, ModelDataIO* io uint32_t attributeIndex = NOM_INT(json, token); if (STR_EQ(name, "POSITION")) { attributeType = ATTR_POSITION; } else if (STR_EQ(name, "NORMAL")) { attributeType = ATTR_NORMAL; } - else if (STR_EQ(name, "TEXCOORD_0")) { attributeType = ATTR_TEXCOORD; } + else if (STR_EQ(name, "TEXCOORD_0")) { attributeType = ATTR_UV; } else if (STR_EQ(name, "COLOR_0")) { attributeType = ATTR_COLOR; } else if (STR_EQ(name, "TANGENT")) { attributeType = ATTR_TANGENT; } else if (STR_EQ(name, "JOINTS_0")) { attributeType = ATTR_JOINTS; } diff --git a/src/modules/data/modelData_obj.c b/src/modules/data/modelData_obj.c index a742bf26..5a562ff2 100644 --- a/src/modules/data/modelData_obj.c +++ b/src/modules/data/modelData_obj.c @@ -361,7 +361,7 @@ ModelData* lovrModelDataInitObj(ModelData* model, Blob* source, ModelDataIO* io) .attributes = { [ATTR_POSITION] = &model->attributes[0], [ATTR_NORMAL] = &model->attributes[1], - [ATTR_TEXCOORD] = &model->attributes[2] + [ATTR_UV] = &model->attributes[2] }, .indices = &model->attributes[3 + i], .material = group->material diff --git a/src/modules/graphics/graphics.c b/src/modules/graphics/graphics.c index 13d5e676..76ea3163 100644 --- a/src/modules/graphics/graphics.c +++ b/src/modules/graphics/graphics.c @@ -2634,7 +2634,7 @@ Model* lovrModelCreate(const ModelInfo* info) { lovrModelDataCopyAttribute(data, attributes[ATTR_POSITION], vertices + 0, F32, 3, false, count, stride, 0); lovrModelDataCopyAttribute(data, attributes[ATTR_NORMAL], vertices + 12, F32, 3, false, count, stride, 0); - lovrModelDataCopyAttribute(data, attributes[ATTR_TEXCOORD], vertices + 24, F32, 2, false, count, stride, 0); + lovrModelDataCopyAttribute(data, attributes[ATTR_UV], vertices + 24, F32, 2, false, count, stride, 0); lovrModelDataCopyAttribute(data, attributes[ATTR_COLOR], vertices + 32, U8, 4, true, count, stride, 255); lovrModelDataCopyAttribute(data, attributes[ATTR_TANGENT], vertices + 36, F32, 3, false, count, stride, 0); vertices += count * stride; diff --git a/src/modules/headset/headset_openxr.c b/src/modules/headset/headset_openxr.c index 852639e8..3a9537b0 100644 --- a/src/modules/headset/headset_openxr.c +++ b/src/modules/headset/headset_openxr.c @@ -1588,7 +1588,7 @@ static ModelData* openxr_newModelData(Device device, bool animated) { .attributes = { [ATTR_POSITION] = &model->attributes[0], [ATTR_NORMAL] = &model->attributes[1], - [ATTR_TEXCOORD] = &model->attributes[2], + [ATTR_UV] = &model->attributes[2], [ATTR_JOINTS] = &model->attributes[3], [ATTR_WEIGHTS] = &model->attributes[4] },