|
|
|
|
@ -13,22 +13,22 @@
|
|
|
|
|
|
|
|
|
|
// TODO: move to GLDebug.h?
|
|
|
|
|
void dumpNodes(tinygltf::Model t_mdl); |
|
|
|
|
bool parseMeshNode(mesh* m, |
|
|
|
|
bool parseMeshNode(Mesh* m, |
|
|
|
|
MemoryArena* arena, |
|
|
|
|
const tinygltf::Node& node, |
|
|
|
|
const tinygltf::Model& t_mdl); |
|
|
|
|
|
|
|
|
|
model* getCachedModel(Assets* assets, u64 path_hash); |
|
|
|
|
model* loadModelFile(Assets* assets, const char* filename); |
|
|
|
|
util_image* getCachedTexture(Assets* assets, u64 path_hash); |
|
|
|
|
Model* getCachedModel(Assets* assets, u64 path_hash); |
|
|
|
|
Model* loadModelFile(Assets* assets, const char* filename); |
|
|
|
|
Texture* getCachedTexture(Assets* assets, u64 path_hash); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// interface
|
|
|
|
|
|
|
|
|
|
model* |
|
|
|
|
Model* |
|
|
|
|
getModelByPath(Assets* assets, const char* filepath) |
|
|
|
|
{ |
|
|
|
|
model* mdl = getCachedModel(assets, utilFNV64a_str(filepath)); |
|
|
|
|
Model* mdl = getCachedModel(assets, utilFNV64a_str(filepath)); |
|
|
|
|
|
|
|
|
|
if (!mdl) |
|
|
|
|
mdl = loadModelFile(assets, filepath); |
|
|
|
|
@ -36,10 +36,10 @@ getModelByPath(Assets* assets, const char* filepath)
|
|
|
|
|
return mdl; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
util_image* |
|
|
|
|
Texture* |
|
|
|
|
getTextureByPath(Assets* assets, const char* filepath) |
|
|
|
|
{ |
|
|
|
|
util_image* texture = |
|
|
|
|
Texture* texture = |
|
|
|
|
getCachedTexture(assets, utilFNV64a_str(filepath)); |
|
|
|
|
|
|
|
|
|
// NOTE: the texture should be loaded when the model is loaded, so it's an
|
|
|
|
|
@ -55,18 +55,18 @@ getTextureByPath(Assets* assets, const char* filepath)
|
|
|
|
|
|
|
|
|
|
// internal
|
|
|
|
|
|
|
|
|
|
model* |
|
|
|
|
Model* |
|
|
|
|
initModel(Assets* assets, |
|
|
|
|
tinygltf::Model t_mdl, |
|
|
|
|
const char* filename) |
|
|
|
|
{ |
|
|
|
|
// TODO: re-alloc array when out of space
|
|
|
|
|
assert(assets->num_models < assets->max_models && assets->arena != nullptr); |
|
|
|
|
model* mdl = &assets->models[assets->num_models]; |
|
|
|
|
Model* mdl = &assets->models[assets->num_models]; |
|
|
|
|
assets->num_models++; |
|
|
|
|
|
|
|
|
|
uint buf_count = t_mdl.bufferViews.size(); |
|
|
|
|
mdl->meshes = ARENA_ALLOC(assets->arena, mesh, buf_count); |
|
|
|
|
mdl->meshes = ARENA_ALLOC(assets->arena, Mesh, buf_count); |
|
|
|
|
mdl->num_meshes = t_mdl.meshes.size(); |
|
|
|
|
mdl->filepath = arenaCopyCStr(assets->arena, filename, MAX_PATH_SIZE); |
|
|
|
|
mdl->filepath_hash = utilFNV64a_str(mdl->filepath); |
|
|
|
|
@ -74,7 +74,7 @@ initModel(Assets* assets,
|
|
|
|
|
return mdl; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
util_image* |
|
|
|
|
Texture* |
|
|
|
|
getFreeTexture(Assets* assets) |
|
|
|
|
{ |
|
|
|
|
if (assets->num_textures < assets->max_textures) |
|
|
|
|
@ -84,7 +84,7 @@ getFreeTexture(Assets* assets)
|
|
|
|
|
return nullptr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
util_image* |
|
|
|
|
Texture* |
|
|
|
|
copyDiffuseTexture(Assets* assets, const tinygltf::Model& t_mdl) |
|
|
|
|
{ |
|
|
|
|
// NOTE: assuming material[0] since we're using pallete texture
|
|
|
|
|
@ -93,7 +93,7 @@ copyDiffuseTexture(Assets* assets, const tinygltf::Model& t_mdl)
|
|
|
|
|
&& t_mdl.images.size() == 1 |
|
|
|
|
&& t_mdl.images[0].image.size() > 0); |
|
|
|
|
tinygltf::Image t_img = t_mdl.images[0]; |
|
|
|
|
util_image* dtex = getFreeTexture(assets); |
|
|
|
|
Texture* dtex = getFreeTexture(assets); |
|
|
|
|
|
|
|
|
|
if (!dtex) { |
|
|
|
|
LOG(Error) << "Error Loading diffuse texture\n"; |
|
|
|
|
@ -114,7 +114,7 @@ copyDiffuseTexture(Assets* assets, const tinygltf::Model& t_mdl)
|
|
|
|
|
return dtex; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
model* |
|
|
|
|
Model* |
|
|
|
|
loadModelFile(Assets* assets, const char* filename) |
|
|
|
|
{ |
|
|
|
|
tinygltf::Model t_mdl; |
|
|
|
|
@ -136,7 +136,7 @@ loadModelFile(Assets* assets, const char* filename)
|
|
|
|
|
|
|
|
|
|
// NOTE: assume we're working with a single buffer
|
|
|
|
|
assert(t_mdl.buffers.size() == 1); |
|
|
|
|
model* mdl = initModel(assets, t_mdl, filename); |
|
|
|
|
Model* mdl = initModel(assets, t_mdl, filename); |
|
|
|
|
mdl->diffuse_texture = copyDiffuseTexture(assets, t_mdl); |
|
|
|
|
if (mdl->diffuse_texture == nullptr) return nullptr; |
|
|
|
|
|
|
|
|
|
@ -158,7 +158,7 @@ loadModelFile(Assets* assets, const char* filename)
|
|
|
|
|
return mdl; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
model* |
|
|
|
|
Model* |
|
|
|
|
getCachedModel(Assets* assets, u64 path_hash) |
|
|
|
|
{ |
|
|
|
|
for (u32 i = 0; i < assets->num_models; i++) { |
|
|
|
|
@ -170,7 +170,7 @@ getCachedModel(Assets* assets, u64 path_hash)
|
|
|
|
|
return nullptr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
util_image* |
|
|
|
|
Texture* |
|
|
|
|
getCachedTexture(Assets* assets, u64 path_hash) |
|
|
|
|
{ |
|
|
|
|
for (u32 i = 0; i < assets->num_textures; i++) { |
|
|
|
|
@ -246,7 +246,7 @@ parseNodeTransform(MemoryArena* arena, const tinygltf::Node* node)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool |
|
|
|
|
parseMeshNode(mesh* m, |
|
|
|
|
parseMeshNode(Mesh* m, |
|
|
|
|
MemoryArena* arena, |
|
|
|
|
const tinygltf::Node& node, |
|
|
|
|
const tinygltf::Model& t_mdl) |
|
|
|
|
@ -341,11 +341,11 @@ getDrawMode(int drawMode)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
dumpBuffer(tinygltf::Model model, tinygltf::Accessor acc) |
|
|
|
|
dumpBuffer(tinygltf::Model mdl, tinygltf::Accessor acc) |
|
|
|
|
{ |
|
|
|
|
size_t bv_idx = acc.bufferView; |
|
|
|
|
assert(bv_idx >= 0 && bv_idx < model.bufferViews.size()); |
|
|
|
|
tinygltf::BufferView bv = model.bufferViews[bv_idx]; |
|
|
|
|
assert(bv_idx >= 0 && bv_idx < mdl.bufferViews.size()); |
|
|
|
|
tinygltf::BufferView bv = mdl.bufferViews[bv_idx]; |
|
|
|
|
|
|
|
|
|
LOG(Debug) << "-----------------------\n"; |
|
|
|
|
LOG(Debug) << "buf idx: " << bv_idx << "\n"; |
|
|
|
|
|