remove model struct
This commit is contained in:
parent
6d1f6bf5c9
commit
443329b2dc
47
assets.d
47
assets.d
@ -40,7 +40,10 @@ struct ImageData
|
|||||||
|
|
||||||
struct ModelData
|
struct ModelData
|
||||||
{
|
{
|
||||||
Model model;
|
Vertex[] vtx_buf;
|
||||||
|
u32[] idx_buf;
|
||||||
|
Mesh[] meshes;
|
||||||
|
Material[] mats;
|
||||||
ImageData[] tex;
|
ImageData[] tex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,19 +105,6 @@ struct Mesh
|
|||||||
u32 mat_id;
|
u32 mat_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Model
|
|
||||||
{
|
|
||||||
Mat4 transform;
|
|
||||||
|
|
||||||
Vertex[] vtx_buf;
|
|
||||||
u32[] idx_buf;
|
|
||||||
|
|
||||||
Mesh[] meshes;
|
|
||||||
Material[] mats;
|
|
||||||
|
|
||||||
// TODO: bones/animations
|
|
||||||
}
|
|
||||||
|
|
||||||
/**************************
|
/**************************
|
||||||
***** GFX STRUCTURES *****
|
***** GFX STRUCTURES *****
|
||||||
**************************/
|
**************************/
|
||||||
@ -326,8 +316,7 @@ LoadImage(cgltf_image* asset_image, string tex_path)
|
|||||||
ModelData
|
ModelData
|
||||||
LoadGLTF(Arena* arena, string file_name)
|
LoadGLTF(Arena* arena, string file_name)
|
||||||
{
|
{
|
||||||
ModelData m_data;
|
ModelData model;
|
||||||
Model* model = &m_data.model;
|
|
||||||
|
|
||||||
u8[] file_data = OpenFile(file_name);
|
u8[] file_data = OpenFile(file_name);
|
||||||
assert(file_data != null);
|
assert(file_data != null);
|
||||||
@ -386,7 +375,7 @@ LoadGLTF(Arena* arena, string file_name)
|
|||||||
model.vtx_buf = Alloc!(Vertex)(vtx_count);
|
model.vtx_buf = Alloc!(Vertex)(vtx_count);
|
||||||
model.meshes = Alloc!(Mesh)(primitive_count);
|
model.meshes = Alloc!(Mesh)(primitive_count);
|
||||||
model.mats = Alloc!(Material)(data.materials_count+1);
|
model.mats = Alloc!(Material)(data.materials_count+1);
|
||||||
m_data.tex = Alloc!(ImageData)(data.textures_count+1);
|
model.tex = Alloc!(ImageData)(data.textures_count+1);
|
||||||
|
|
||||||
model.mats[0] = DEFAULT_MATERIAL;
|
model.mats[0] = DEFAULT_MATERIAL;
|
||||||
|
|
||||||
@ -403,7 +392,7 @@ LoadGLTF(Arena* arena, string file_name)
|
|||||||
auto pbr_mr = &data.materials[i].pbr_metallic_roughness;
|
auto pbr_mr = &data.materials[i].pbr_metallic_roughness;
|
||||||
if(pbr_mr.base_color_texture.texture)
|
if(pbr_mr.base_color_texture.texture)
|
||||||
{
|
{
|
||||||
m_data.tex[tex_idx] = LoadImage(pbr_mr.base_color_texture.texture.image, file_path);
|
model.tex[tex_idx] = LoadImage(pbr_mr.base_color_texture.texture.image, file_path);
|
||||||
model.mats[mat_idx].maps[MMI.Albedo].tex_id = tex_idx++;
|
model.mats[mat_idx].maps[MMI.Albedo].tex_id = tex_idx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -411,7 +400,7 @@ LoadGLTF(Arena* arena, string file_name)
|
|||||||
|
|
||||||
if(pbr_mr.metallic_roughness_texture.texture)
|
if(pbr_mr.metallic_roughness_texture.texture)
|
||||||
{
|
{
|
||||||
m_data.tex[tex_idx] = LoadImage(pbr_mr.base_color_texture.texture.image, file_path);
|
model.tex[tex_idx] = LoadImage(pbr_mr.base_color_texture.texture.image, file_path);
|
||||||
model.mats[mat_idx].maps[MMI.Metallic].tex_id = tex_idx;
|
model.mats[mat_idx].maps[MMI.Metallic].tex_id = tex_idx;
|
||||||
model.mats[mat_idx].maps[MMI.Roughness].tex_id = tex_idx;
|
model.mats[mat_idx].maps[MMI.Roughness].tex_id = tex_idx;
|
||||||
tex_idx += 1;
|
tex_idx += 1;
|
||||||
@ -422,19 +411,19 @@ LoadGLTF(Arena* arena, string file_name)
|
|||||||
|
|
||||||
if(data.materials[i].normal_texture.texture)
|
if(data.materials[i].normal_texture.texture)
|
||||||
{
|
{
|
||||||
m_data.tex[tex_idx] = LoadImage(data.materials[i].normal_texture.texture.image, file_path);
|
model.tex[tex_idx] = LoadImage(data.materials[i].normal_texture.texture.image, file_path);
|
||||||
model.mats[mat_idx].maps[MMI.Normal].tex_id = tex_idx++;
|
model.mats[mat_idx].maps[MMI.Normal].tex_id = tex_idx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(data.materials[i].occlusion_texture.texture)
|
if(data.materials[i].occlusion_texture.texture)
|
||||||
{
|
{
|
||||||
m_data.tex[tex_idx] = LoadImage(data.materials[i].occlusion_texture.texture.image, file_path);
|
model.tex[tex_idx] = LoadImage(data.materials[i].occlusion_texture.texture.image, file_path);
|
||||||
model.mats[mat_idx].maps[MMI.Occlusion].tex_id = tex_idx++;
|
model.mats[mat_idx].maps[MMI.Occlusion].tex_id = tex_idx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(data.materials[i].emissive_texture.texture)
|
if(data.materials[i].emissive_texture.texture)
|
||||||
{
|
{
|
||||||
m_data.tex[tex_idx] = LoadImage(data.materials[i].emissive_texture.texture.image, file_path);
|
model.tex[tex_idx] = LoadImage(data.materials[i].emissive_texture.texture.image, file_path);
|
||||||
model.mats[mat_idx].maps[MMI.Emission].tex_id = tex_idx++;
|
model.mats[mat_idx].maps[MMI.Emission].tex_id = tex_idx++;
|
||||||
|
|
||||||
model.mats[mat_idx].maps[MMI.Emission].col.v[0 .. 3] = data.materials[i].emissive_factor;
|
model.mats[mat_idx].maps[MMI.Emission].col.v[0 .. 3] = data.materials[i].emissive_factor;
|
||||||
@ -476,7 +465,7 @@ LoadGLTF(Arena* arena, string file_name)
|
|||||||
|
|
||||||
if(attr.type == cgltf_type_vec3 && attr.component_type == cgltf_component_type_r_32f)
|
if(attr.type == cgltf_type_vec3 && attr.component_type == cgltf_component_type_r_32f)
|
||||||
{
|
{
|
||||||
AddMeshVertices(attr, model, mesh_index, &vtx_count);
|
AddMeshVertices(attr, &model, mesh_index, &vtx_count);
|
||||||
|
|
||||||
f32* buffer = GetGLTFBuffer!(f32)(attr);
|
f32* buffer = GetGLTFBuffer!(f32)(attr);
|
||||||
for(u64 k = 0; k < model.meshes[mesh_index].vtx.length; k += 1)
|
for(u64 k = 0; k < model.meshes[mesh_index].vtx.length; k += 1)
|
||||||
@ -493,7 +482,7 @@ LoadGLTF(Arena* arena, string file_name)
|
|||||||
|
|
||||||
if(attr.type == cgltf_type_vec3 && attr.component_type == cgltf_component_type_r_32f)
|
if(attr.type == cgltf_type_vec3 && attr.component_type == cgltf_component_type_r_32f)
|
||||||
{
|
{
|
||||||
AddMeshVertices(attr, model, mesh_index, &vtx_count);
|
AddMeshVertices(attr, &model, mesh_index, &vtx_count);
|
||||||
|
|
||||||
f32* buffer = GetGLTFBuffer!(f32)(attr);
|
f32* buffer = GetGLTFBuffer!(f32)(attr);
|
||||||
for(u64 k = 0; k < model.meshes[mesh_index].vtx.length; k += 1)
|
for(u64 k = 0; k < model.meshes[mesh_index].vtx.length; k += 1)
|
||||||
@ -510,7 +499,7 @@ LoadGLTF(Arena* arena, string file_name)
|
|||||||
|
|
||||||
if(attr.type == cgltf_type_vec4 && attr.component_type == cgltf_component_type_r_32f)
|
if(attr.type == cgltf_type_vec4 && attr.component_type == cgltf_component_type_r_32f)
|
||||||
{
|
{
|
||||||
AddMeshVertices(attr, model, mesh_index, &vtx_count);
|
AddMeshVertices(attr, &model, mesh_index, &vtx_count);
|
||||||
|
|
||||||
f32* buffer = GetGLTFBuffer!(f32)(attr);
|
f32* buffer = GetGLTFBuffer!(f32)(attr);
|
||||||
for(u64 k = 0; k < model.meshes[mesh_index].vtx.length; k += 1)
|
for(u64 k = 0; k < model.meshes[mesh_index].vtx.length; k += 1)
|
||||||
@ -526,7 +515,7 @@ LoadGLTF(Arena* arena, string file_name)
|
|||||||
|
|
||||||
if(attr.type == cgltf_type_vec2)
|
if(attr.type == cgltf_type_vec2)
|
||||||
{
|
{
|
||||||
AddMeshVertices(attr, model, mesh_index, &vtx_count);
|
AddMeshVertices(attr, &model, mesh_index, &vtx_count);
|
||||||
|
|
||||||
u32 uv_idx = prim.attributes[j].index;
|
u32 uv_idx = prim.attributes[j].index;
|
||||||
if(uv_idx >= 2)
|
if(uv_idx >= 2)
|
||||||
@ -571,7 +560,7 @@ LoadGLTF(Arena* arena, string file_name)
|
|||||||
|
|
||||||
if(attr.type == cgltf_type_vec3 || attr.type == cgltf_type_vec4)
|
if(attr.type == cgltf_type_vec3 || attr.type == cgltf_type_vec4)
|
||||||
{
|
{
|
||||||
AddMeshVertices(attr, model, mesh_index, &vtx_count);
|
AddMeshVertices(attr, &model, mesh_index, &vtx_count);
|
||||||
|
|
||||||
if(attr.type == cgltf_type_vec3)
|
if(attr.type == cgltf_type_vec3)
|
||||||
{
|
{
|
||||||
@ -716,11 +705,11 @@ LoadGLTF(Arena* arena, string file_name)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_data;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
AddMeshVertices(cgltf_accessor* accessor, Model* model, u64 mesh_index, u64* vtx_count)
|
AddMeshVertices(cgltf_accessor* accessor, ModelData* model, u64 mesh_index, u64* vtx_count)
|
||||||
{
|
{
|
||||||
if(model.meshes[mesh_index].vtx == null)
|
if(model.meshes[mesh_index].vtx == null)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user