diff --git a/examples/render_groups/main.cpp b/examples/render_groups/main.cpp index 62b99e8..e377685 100644 --- a/examples/render_groups/main.cpp +++ b/examples/render_groups/main.cpp @@ -180,10 +180,10 @@ main() rs->arena = arenaInit(); rs->asset_list = (render_asset*) arenaAllocateBlock(rs->arena, sizeof(render_asset)); + // TODO: need to update render_asset->next somewhere - //mesh_group mg; - //meLoadFromFile(mg, "../data/blender/icosphere.gltf"); - render_asset* rass = assetLoadFromFile("../data/blender/icosphere.gltf"); + render_asset* rass = + assetLoadFromFile(rs->arena, "../data/blender/icosphere.gltf"); renShutdown(rs); return 0; diff --git a/include/asset.h b/include/asset.h index 8d70af1..5df4af2 100644 --- a/include/asset.h +++ b/include/asset.h @@ -37,5 +37,5 @@ struct render_asset }; render_asset* -assetLoadFromFile(const char* filename); +assetLoadFromFile(memory_arena* arena, const char* filename); diff --git a/src/asset.cpp b/src/asset.cpp index 04e1399..18c4ec8 100644 --- a/src/asset.cpp +++ b/src/asset.cpp @@ -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; }