|
|
|
|
@ -41,8 +41,23 @@ getComponentType(int componentType)
|
|
|
|
|
default: return "UNKOWN"; } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const char* |
|
|
|
|
getDrawMode(int drawMode) |
|
|
|
|
{ |
|
|
|
|
switch (drawMode) { |
|
|
|
|
case 0: return "TINYGLTF_MODE_POINTS"; |
|
|
|
|
case 1: return "TINYGLTF_MODE_LINE"; |
|
|
|
|
case 2: return "TINYGLTF_MODE_LINE_LOOP"; |
|
|
|
|
case 3: return "TINYGLTF_MODE_LINE_STRIP"; |
|
|
|
|
case 4: return "TINYGLTF_MODE_TRIANGLES"; |
|
|
|
|
case 5: return "TINYGLTF_MODE_TRIANGLE_STRIP"; |
|
|
|
|
case 6: return "TINYGLTF_MODE_TRIANGLE_FAN"; |
|
|
|
|
default: return "UNKOWN MODE"; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
model_assets* |
|
|
|
|
assetInit(memory_arena* arena, uint asset_count) |
|
|
|
|
assetInitBlock(memory_arena* arena, uint asset_count) |
|
|
|
|
{ |
|
|
|
|
model_assets* assets = |
|
|
|
|
(model_assets*) arenaAllocateBlock(arena, sizeof(model_assets)); |
|
|
|
|
@ -76,8 +91,9 @@ dumpBuffer(tinygltf::Model model, tinygltf::Accessor acc)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
model* |
|
|
|
|
assetLoadFromFile(model_assets* assets, |
|
|
|
|
initModel(model_assets* assets, |
|
|
|
|
memory_arena* arena, |
|
|
|
|
tinygltf::Model t_mdl, |
|
|
|
|
const char* filename) |
|
|
|
|
{ |
|
|
|
|
// TODO: re-alloc array when out of space
|
|
|
|
|
@ -85,16 +101,6 @@ assetLoadFromFile(model_assets* assets,
|
|
|
|
|
model* mdl = &assets->models[assets->count]; |
|
|
|
|
assets->count++; |
|
|
|
|
|
|
|
|
|
tinygltf::Model t_mdl; |
|
|
|
|
tinygltf::TinyGLTF gltf_ctx; |
|
|
|
|
std::string err; |
|
|
|
|
std::string warn; |
|
|
|
|
|
|
|
|
|
if (!gltf_ctx.LoadASCIIFromFile(&t_mdl, &err, &warn, filename)) { |
|
|
|
|
LOG(Error) << "Error loading file: " << filename << "\n"; |
|
|
|
|
return nullptr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
uint buf_count = t_mdl.bufferViews.size(); |
|
|
|
|
mdl->meshes = (mesh*) arenaAllocateBlock(arena, buf_count * sizeof(mesh)); |
|
|
|
|
mdl->num_meshes = t_mdl.meshes.size(); |
|
|
|
|
@ -104,17 +110,24 @@ assetLoadFromFile(model_assets* assets,
|
|
|
|
|
std::strncpy(mdl->filepath, filename, name_len); |
|
|
|
|
mdl->filepath_hash = utilFNV64a_str(mdl->filepath); |
|
|
|
|
|
|
|
|
|
// TODO: also need to get each node xform
|
|
|
|
|
// TODO: also need to dump textures
|
|
|
|
|
return mdl; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
dumpNodes(tinygltf::Model t_mdl) |
|
|
|
|
{ |
|
|
|
|
for (tinygltf::Node node : t_mdl.nodes) { |
|
|
|
|
LOG(Debug) << "##################\n"; |
|
|
|
|
LOG(Debug) << "node mesh idx: " << node.mesh << "\n"; |
|
|
|
|
|
|
|
|
|
if (node.mesh >= 0) { |
|
|
|
|
LOG(Debug) << "node mesh name: " |
|
|
|
|
<< t_mdl.meshes[node.mesh].name << "\n"; |
|
|
|
|
tinygltf::Mesh t_mesh = t_mdl.meshes[node.mesh]; |
|
|
|
|
LOG(Debug) << "node mesh name: " << t_mesh.name << "\n"; |
|
|
|
|
// NOTE: assume only 1 primitive object per mesh
|
|
|
|
|
assert(t_mdl.meshes[node.mesh].primitives.size() == 1); |
|
|
|
|
tinygltf::Primitive prim = t_mesh.primitives[0]; |
|
|
|
|
LOG(Debug) << "node draw mode: " << getDrawMode(prim.mode) << "\n"; |
|
|
|
|
|
|
|
|
|
tinygltf::Primitive prim = t_mdl.meshes[node.mesh].primitives[0]; |
|
|
|
|
for (auto& att : prim.attributes) { |
|
|
|
|
LOG(Debug) << "dumping buffer: " << att.first << "\n"; |
|
|
|
|
dumpBuffer(t_mdl, t_mdl.accessors[att.second]); |
|
|
|
|
@ -126,6 +139,29 @@ assetLoadFromFile(model_assets* assets,
|
|
|
|
|
LOG(Debug) << "Not a mesh node\n"; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
model* |
|
|
|
|
assetLoadFromFile(model_assets* assets, |
|
|
|
|
memory_arena* arena, |
|
|
|
|
const char* filename) |
|
|
|
|
{ |
|
|
|
|
tinygltf::Model t_mdl; |
|
|
|
|
tinygltf::TinyGLTF gltf_ctx; |
|
|
|
|
std::string err; |
|
|
|
|
std::string warn; |
|
|
|
|
|
|
|
|
|
if (!gltf_ctx.LoadASCIIFromFile(&t_mdl, &err, &warn, filename)) { |
|
|
|
|
LOG(Error) << "Error loading file: " << filename |
|
|
|
|
<< " , msg: " << err << "\n"; |
|
|
|
|
return nullptr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
model* mdl = initModel(assets, arena, t_mdl, filename); |
|
|
|
|
// TODO: also need to get each node xform
|
|
|
|
|
// TODO: also need to dump textures/materials
|
|
|
|
|
dumpNodes(t_mdl); |
|
|
|
|
|
|
|
|
|
return mdl; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|