mirror of
https://github.com/bjornbytes/lovr.git
synced 2024-07-04 13:33:34 +00:00
Fix OpenVR controller model materials;
This commit is contained in:
parent
cca1f32d10
commit
3287b0acb6
|
@ -1,5 +1,4 @@
|
||||||
#include "data/modelData.h"
|
#include "data/modelData.h"
|
||||||
#include "data/textureData.h"
|
|
||||||
#include "filesystem/filesystem.h"
|
#include "filesystem/filesystem.h"
|
||||||
#include "filesystem/file.h"
|
#include "filesystem/file.h"
|
||||||
#include "math/math.h"
|
#include "math/math.h"
|
||||||
|
@ -117,18 +116,20 @@ static Color readMaterialColor(struct aiMaterial* assimpMaterial, const char* ke
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int readMaterialTexture(struct aiMaterial* assimpMaterial, enum aiTextureType type, ModelData* modelData, map_int_t* textureCache, const char* dirname) {
|
static TextureData* readMaterialTexture(struct aiMaterial* assimpMaterial, enum aiTextureType type, ModelData* modelData, map_int_t* textureCache, const char* dirname) {
|
||||||
struct aiString str;
|
struct aiString str;
|
||||||
if (aiGetMaterialTexture(assimpMaterial, type, 0, &str, NULL, NULL, NULL, NULL, NULL, NULL) == aiReturn_SUCCESS) {
|
|
||||||
|
if (aiGetMaterialTexture(assimpMaterial, type, 0, &str, NULL, NULL, NULL, NULL, NULL, NULL) != aiReturn_SUCCESS) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
char* path = str.data;
|
char* path = str.data;
|
||||||
|
|
||||||
int* cachedTexture = map_get(textureCache, path);
|
int* cachedTexture = (TextureData**) map_get(textureCache, path);
|
||||||
if (cachedTexture) {
|
if (cachedTexture) {
|
||||||
return *cachedTexture;
|
return *cachedTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
int textureIndex = modelData->textures.length;
|
|
||||||
|
|
||||||
char fullPath[LOVR_PATH_MAX];
|
char fullPath[LOVR_PATH_MAX];
|
||||||
char normalizedPath[LOVR_PATH_MAX];
|
char normalizedPath[LOVR_PATH_MAX];
|
||||||
strncpy(fullPath, dirname, LOVR_PATH_MAX);
|
strncpy(fullPath, dirname, LOVR_PATH_MAX);
|
||||||
|
@ -139,20 +140,16 @@ static int readMaterialTexture(struct aiMaterial* assimpMaterial, enum aiTexture
|
||||||
|
|
||||||
size_t size;
|
size_t size;
|
||||||
void* data = lovrFilesystemRead(normalizedPath, &size);
|
void* data = lovrFilesystemRead(normalizedPath, &size);
|
||||||
if (data) {
|
if (!data) {
|
||||||
Blob* blob = lovrBlobCreate(data, size, path);
|
return 0;
|
||||||
vec_push(&modelData->textures, lovrTextureDataFromBlob(blob));
|
|
||||||
} else {
|
|
||||||
vec_push(&modelData->textures, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Blob* blob = lovrBlobCreate(data, size, path);
|
||||||
|
TextureData* textureData = lovrTextureDataFromBlob(blob);
|
||||||
|
int textureIndex = modelData->textures.length;
|
||||||
|
vec_push(&modelData->textures, textureData);
|
||||||
map_set(textureCache, path, textureIndex);
|
map_set(textureCache, path, textureIndex);
|
||||||
return textureIndex;
|
return textureIndex;
|
||||||
} else {
|
|
||||||
int textureIndex = modelData->textures.length;
|
|
||||||
vec_push(&modelData->textures, NULL);
|
|
||||||
return textureIndex;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Blob IO (to avoid reading data twice)
|
// Blob IO (to avoid reading data twice)
|
||||||
|
@ -420,6 +417,7 @@ ModelData* lovrModelDataCreate(Blob* blob) {
|
||||||
map_int_t textureCache;
|
map_int_t textureCache;
|
||||||
map_init(&textureCache);
|
map_init(&textureCache);
|
||||||
vec_init(&modelData->textures);
|
vec_init(&modelData->textures);
|
||||||
|
vec_push(&modelData->textures, NULL);
|
||||||
modelData->materialCount = scene->mNumMaterials;
|
modelData->materialCount = scene->mNumMaterials;
|
||||||
modelData->materials = malloc(modelData->materialCount * sizeof(ModelMaterial));
|
modelData->materials = malloc(modelData->materialCount * sizeof(ModelMaterial));
|
||||||
for (unsigned int m = 0; m < scene->mNumMaterials; m++) {
|
for (unsigned int m = 0; m < scene->mNumMaterials; m++) {
|
||||||
|
@ -532,8 +530,10 @@ void lovrModelDataDestroy(const Ref* ref) {
|
||||||
|
|
||||||
for (int i = 0; i < modelData->textures.length; i++) {
|
for (int i = 0; i < modelData->textures.length; i++) {
|
||||||
TextureData* textureData = modelData->textures.data[i];
|
TextureData* textureData = modelData->textures.data[i];
|
||||||
|
if (textureData) {
|
||||||
lovrRelease(&textureData->ref);
|
lovrRelease(&textureData->ref);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
vec_deinit(&modelData->textures);
|
vec_deinit(&modelData->textures);
|
||||||
map_deinit(&modelData->nodeMap);
|
map_deinit(&modelData->nodeMap);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "filesystem/blob.h"
|
#include "filesystem/blob.h"
|
||||||
|
#include "data/textureData.h"
|
||||||
#include "data/vertexData.h"
|
#include "data/vertexData.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "lib/map/map.h"
|
#include "lib/map/map.h"
|
||||||
|
|
|
@ -700,6 +700,8 @@ static ModelData* openvrControllerNewModelData(Controller* controller) {
|
||||||
TextureData* textureData = malloc(sizeof(TextureData));
|
TextureData* textureData = malloc(sizeof(TextureData));
|
||||||
if (!textureData) return NULL;
|
if (!textureData) return NULL;
|
||||||
|
|
||||||
|
vec_init(&modelData->textures);
|
||||||
|
vec_push(&modelData->textures, NULL);
|
||||||
vec_push(&modelData->textures, textureData);
|
vec_push(&modelData->textures, textureData);
|
||||||
|
|
||||||
int width = vrTexture->unWidth;
|
int width = vrTexture->unWidth;
|
||||||
|
@ -715,7 +717,15 @@ static ModelData* openvrControllerNewModelData(Controller* controller) {
|
||||||
vec_init(&textureData->mipmaps);
|
vec_init(&textureData->mipmaps);
|
||||||
|
|
||||||
modelData->materials[0].diffuseColor = (Color) { 1, 1, 1, 1 };
|
modelData->materials[0].diffuseColor = (Color) { 1, 1, 1, 1 };
|
||||||
modelData->materials[0].diffuseTexture = 0;
|
modelData->materials[0].emissiveColor = (Color) { 0, 0, 0, 1 };
|
||||||
|
modelData->materials[0].diffuseTexture = 1;
|
||||||
|
modelData->materials[0].emissiveTexture = 0;
|
||||||
|
modelData->materials[0].metalnessTexture = 0;
|
||||||
|
modelData->materials[0].roughnessTexture = 0;
|
||||||
|
modelData->materials[0].occlusionTexture = 0;
|
||||||
|
modelData->materials[0].normalTexture = 0;
|
||||||
|
modelData->materials[0].metalness = 0;
|
||||||
|
modelData->materials[0].roughness = 0;
|
||||||
|
|
||||||
return modelData;
|
return modelData;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue