|
|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
|
|
|
|
|
#include <iostream> |
|
|
|
|
#include <cassert> |
|
|
|
|
#include <cstring> |
|
|
|
|
|
|
|
|
|
#define TINYGLTF_IMPLEMENTATION |
|
|
|
|
//#define STB_IMAGE_IMPLEMENTATION
|
|
|
|
|
@ -42,41 +43,48 @@ getComponentType(int componentType)
|
|
|
|
|
case 5130: return "TINYGLTF_COMPONENT_TYPE_DOUBLE"; |
|
|
|
|
default: return "UNKOWN"; } |
|
|
|
|
} |
|
|
|
|
render_asset* |
|
|
|
|
|
|
|
|
|
model* |
|
|
|
|
assetLoadFromFile(memory_arena* arena, const char* filename) |
|
|
|
|
{ |
|
|
|
|
tinygltf::Model model; |
|
|
|
|
// TODO: see if there's any impact in creating a new context for each file
|
|
|
|
|
tinygltf::Model mdl; |
|
|
|
|
tinygltf::TinyGLTF gltf_ctx; |
|
|
|
|
std::string err; |
|
|
|
|
std::string warn; |
|
|
|
|
|
|
|
|
|
if (!gltf_ctx.LoadASCIIFromFile(&model, &err, &warn, filename)) { |
|
|
|
|
if (!gltf_ctx.LoadASCIIFromFile(&mdl, &err, &warn, filename)) { |
|
|
|
|
LOG(Error) << "Error loading file: " << filename << "\n"; |
|
|
|
|
return nullptr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
uint buf_count = model.bufferViews.size(); |
|
|
|
|
render_asset* ra = |
|
|
|
|
(render_asset*) arenaAllocateBlock(arena, sizeof(render_asset)); |
|
|
|
|
ra->meshes = |
|
|
|
|
(mesh_asset*) arenaAllocateBlock(arena, buf_count * sizeof(mesh_asset)); |
|
|
|
|
uint buf_count = mdl.bufferViews.size(); |
|
|
|
|
model* ra = (model*) arenaAllocateBlock(arena, sizeof(model)); |
|
|
|
|
ra->meshes = (mesh*) arenaAllocateBlock(arena, buf_count * sizeof(mesh)); |
|
|
|
|
ra->num_meshes = mdl.meshes.size(); |
|
|
|
|
uint name_len = std::strlen(filename); |
|
|
|
|
assert(name_len < MAX_PATH_SIZE); |
|
|
|
|
ra->filepath = (char*) arenaAllocateBlock(arena, name_len + 1); |
|
|
|
|
std::strncpy(ra->filepath, filename, name_len); |
|
|
|
|
ra->filepath_hash = utilFNV64a_str(ra->filepath); |
|
|
|
|
|
|
|
|
|
for (uint i = 0; i < model.accessors.size(); i++) { |
|
|
|
|
tinygltf::Accessor acc = model.accessors[i]; |
|
|
|
|
size_t bv_idx = acc.bufferView; |
|
|
|
|
assert(bv_idx >= 0 && bv_idx < model.bufferViews.size()); |
|
|
|
|
tinygltf::BufferView bv = model.bufferViews[bv_idx]; |
|
|
|
|
// FIXME: need to recreate node hierarchy
|
|
|
|
|
for (tinygltf::Node node : mdl.nodes) { |
|
|
|
|
for (tinygltf::Accessor acc : mdl.accessors) { |
|
|
|
|
size_t bv_idx = acc.bufferView; |
|
|
|
|
assert(bv_idx >= 0 && bv_idx < mdl.bufferViews.size()); |
|
|
|
|
tinygltf::BufferView bv = mdl.bufferViews[bv_idx]; |
|
|
|
|
|
|
|
|
|
LOG(Debug) << "-----------------------\n"; |
|
|
|
|
LOG(Debug) << "buf idx: " << i << "\n"; |
|
|
|
|
LOG(Debug) << "buf target: " << getTargetStr(bv.target) << "\n"; |
|
|
|
|
LOG(Debug) << "buf len: " << bv.byteLength << "\n"; |
|
|
|
|
LOG(Debug) << "buf offset: " << bv.byteOffset << "\n"; |
|
|
|
|
LOG(Debug) << "buf stride: " << bv.byteStride << "\n"; |
|
|
|
|
LOG(Debug) << "buf component type: " |
|
|
|
|
<< getComponentType(acc.componentType) << "\n"; |
|
|
|
|
LOG(Debug) << "buf element type: " << getElementType(acc.type) << "\n"; |
|
|
|
|
LOG(Debug) << "-----------------------\n"; |
|
|
|
|
LOG(Debug) << "buf idx: " << bv_idx << "\n"; |
|
|
|
|
LOG(Debug) << "buf target: " << getTargetStr(bv.target) << "\n"; |
|
|
|
|
LOG(Debug) << "buf len: " << bv.byteLength << "\n"; |
|
|
|
|
LOG(Debug) << "buf offset: " << bv.byteOffset << "\n"; |
|
|
|
|
LOG(Debug) << "buf stride: " << bv.byteStride << "\n"; |
|
|
|
|
LOG(Debug) << "acc component type: " |
|
|
|
|
<< getComponentType(acc.componentType) << "\n"; |
|
|
|
|
LOG(Debug) << "acc element type: " |
|
|
|
|
<< getElementType(acc.type) << "\n"; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return ra; |
|
|
|
|
|