|
|
|
|
@ -7,22 +7,77 @@
|
|
|
|
|
#include "tiny_gltf.h" |
|
|
|
|
|
|
|
|
|
#include "asset.h" |
|
|
|
|
#include "dumbLog.h" |
|
|
|
|
|
|
|
|
|
const char* |
|
|
|
|
getTargetStr(int target) |
|
|
|
|
{ |
|
|
|
|
switch (target) { |
|
|
|
|
case 34962: return "GL_ARRAY_BUFFER"; |
|
|
|
|
case 34963: return "GL_ELEMENT_ARRAY_BUFFER"; |
|
|
|
|
default: return "UNKNOWN"; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const char* |
|
|
|
|
getElementType(int type) |
|
|
|
|
{ |
|
|
|
|
switch (type) { |
|
|
|
|
case 2: return "VEC2"; |
|
|
|
|
case 3: return "VEC3"; |
|
|
|
|
case 4: return "VEC4"; |
|
|
|
|
case 65: return "TINYGLTF_TYPE_SCALAR"; |
|
|
|
|
default: return "UNKNOWN"; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const char* |
|
|
|
|
getComponentType(int componentType) |
|
|
|
|
{ |
|
|
|
|
switch (componentType) { |
|
|
|
|
case 5123: return "TINYGLTF_COMPONENT_TYPE_UNSIGNED_SHORT"; |
|
|
|
|
case 5124: return "TINYGLTF_COMPONENT_TYPE_INT"; |
|
|
|
|
case 5125: return "TINYGLTF_COMPONENT_TYPE_UNSIGNED_INT"; |
|
|
|
|
case 5126: return "TINYGLTF_COMPONENT_TYPE_FLOAT"; |
|
|
|
|
case 5130: return "TINYGLTF_COMPONENT_TYPE_DOUBLE"; |
|
|
|
|
default: return "UNKOWN"; } |
|
|
|
|
} |
|
|
|
|
render_asset* |
|
|
|
|
assetLoadFromFile(const char* filename) |
|
|
|
|
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::TinyGLTF gltf_ctx; |
|
|
|
|
std::string err; |
|
|
|
|
std::string warn; |
|
|
|
|
bool ret = false; |
|
|
|
|
|
|
|
|
|
ret = gltf_ctx.LoadASCIIFromFile(&model, &err, &warn, filename); |
|
|
|
|
if (!gltf_ctx.LoadASCIIFromFile(&model, &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)); |
|
|
|
|
|
|
|
|
|
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]; |
|
|
|
|
|
|
|
|
|
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"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
return ra; |
|
|
|
|
} |
|
|
|
|
|