diff options
author | omnisci3nce <omniscient.oce@gmail.com> | 2024-07-13 16:34:48 +1000 |
---|---|---|
committer | omnisci3nce <omniscient.oce@gmail.com> | 2024-07-13 16:34:48 +1000 |
commit | 8d6b838d0a5919620ca8562ac6be1da5c0c3237e (patch) | |
tree | 0cffbe159b23464e64cde1165e9e58031d0623b8 /src/resources | |
parent | f74cf52946f4e569a26bc81105537b40be95c2c7 (diff) |
add empty shell scripts
Diffstat (limited to 'src/resources')
-rw-r--r-- | src/resources/gltf.c | 90 | ||||
-rw-r--r-- | src/resources/obj.c | 366 |
2 files changed, 228 insertions, 228 deletions
diff --git a/src/resources/gltf.c b/src/resources/gltf.c index 5947bad..e381954 100644 --- a/src/resources/gltf.c +++ b/src/resources/gltf.c @@ -35,7 +35,7 @@ KITC_DECL_TYPED_ARRAY(Vec4) KITC_DECL_TYPED_ARRAY(face) // KITC_DECL_TYPED_ARRAY(joint) -bool model_load_gltf_str(const char *file_string, const char *filepath, str8 relative_path, +bool model_load_gltf_str(const char *file_string, const char *filepath, Str8 relative_path, Model *out_model, bool invert_textures_y); ModelHandle model_load_gltf(const char *path, bool invert_texture_y) { @@ -85,7 +85,7 @@ typedef struct model { u32 mesh_count; } model; */ -bool model_load_gltf_str(const char *file_string, const char *filepath, str8 relative_path, +bool model_load_gltf_str(const char *file_string, const char *filepath, Str8 relative_path, Model *out_model, bool invert_textures_y) { // TRACE("Load GLTF from string"); @@ -100,7 +100,7 @@ bool model_load_gltf_str(const char *file_string, const char *filepath, str8 rel // // vertex_bone_data_darray *tmp_vertex_bone_data = vertex_bone_data_darray_new(1000); // cgltf_options options = { 0 }; - // cgltf_data *data = NULL; + cgltf_data *data = NULL; // cgltf_result result = cgltf_parse_file(&options, filepath, &data); // if (result != cgltf_result_success) { // WARN("gltf load failed"); @@ -183,13 +183,13 @@ bool model_load_gltf_str(const char *file_string, const char *filepath, str8 rel snprintf(normal_map_path, sizeof(normal_map_path), "%s/%s", relative_path.buf, normal_tex_view.texture->image->uri); - material our_material = - pbr_material_load(albedo_map_path, normal_map_path, true, metal_rough_map_path, NULL, NULL); + // material our_material = + // pbr_material_load(albedo_map_path, normal_map_path, true, metal_rough_map_path, NULL, NULL); - our_material.name = malloc(strlen(gltf_material.name) + 1); - strcpy(our_material.name, gltf_material.name); + // our_material.name = malloc(strlen(gltf_material.name) + 1); + // strcpy(our_material.name, gltf_material.name); - material_darray_push(out_model->materials, our_material); + // material_darray_push(out_model->materials, our_material); } // TEMP @@ -204,7 +204,7 @@ bool model_load_gltf_str(const char *file_string, const char *filepath, str8 rel // DEBUG("Number of this primitive %d", primitive.) for (cgltf_size a = 0; a < data->meshes[m].primitives[0].attributes_count; a++) { - // cgltf_attribute attribute = data->meshes[m].primitives[0].attributes[a]; + cgltf_attribute attribute = data->meshes[m].primitives[0].attributes[a]; if (attribute.type == cgltf_attribute_type_position) { TRACE("Load positions from accessor"); @@ -322,34 +322,34 @@ bool model_load_gltf_str(const char *file_string, const char *filepath, str8 rel // // } bool has_indices = false; - vertex_darray *geo_vertices = vertex_darray_new(3); + Vertex_darray *geo_vertices = Vertex_darray_new(3); u32_darray *geo_indices = u32_darray_new(0); // Store vertices - printf("Positions %d Normals %d UVs %d\n", tmp_positions->len, tmp_normals->len, tmp_uvs->len); - assert(tmp_positions->len == tmp_normals->len); - assert(tmp_normals->len == tmp_uvs->len); - for (u32 v_i = 0; v_i < tmp_positions->len; v_i++) { - vertex v = { .static_3d = { - .position = tmp_positions->data[v_i], - .normal = tmp_normals->data[v_i], - .tex_coords = tmp_uvs->data[v_i], - } }; - vertex_darray_push(geo_vertices, v); + // printf("Positions %d Normals %d UVs %d\n", tmp_positions->len, tmp_normals->len, tmp_uvs->len); + // assert(tmp_positions->len == tmp_normals->len); + // assert(tmp_normals->len == tmp_uvs->len); + // for (u32 v_i = 0; v_i < tmp_positions->len; v_i++) { + // vertex v = { .static_3d = { + // .position = tmp_positions->data[v_i], + // .normal = tmp_normals->data[v_i], + // .tex_coords = tmp_uvs->data[v_i], + // } }; + // vertex_darray_push(geo_vertices, v); } // Store indices - cgltf_accessor *indices = primitive.indices; - if (primitive.indices > 0) { - WARN("indices! %d", indices->count); - has_indices = true; - - // store indices - for (cgltf_size i = 0; i < indices->count; ++i) { - cgltf_uint ei; - cgltf_accessor_read_uint(indices, i, &ei, 1); - u32_darray_push(geo_indices, ei); - } + // cgltf_accessor *indices = primitive.indices; + // if (primitive.indices > 0) { + // WARN("indices! %d", indices->count); + // has_indices = true; + + // // store indices + // for (cgltf_size i = 0; i < indices->count; ++i) { + // cgltf_uint ei; + // cgltf_accessor_read_uint(indices, i, &ei, 1); + // u32_darray_push(geo_indices, ei); + // } // fetch and store vertices for each index // for (cgltf_size i = 0; i < indices->count; ++i) { @@ -366,23 +366,23 @@ bool model_load_gltf_str(const char *file_string, const char *filepath, str8 rel // } // // for each vertex do the bone data // } - } else { - has_indices = false; - return false; // TODO: handle this - } + // } else { + // has_indices = false; + // return false; // TODO: handle this + // } - geometry_data *geometry = malloc(sizeof(geometry_data)); - geometry->format = VERTEX_STATIC_3D; - geometry->colour = (rgba){ 1, 1, 1, 1 }; - geometry->vertices = geo_vertices; - geometry->indices = geo_indices; - geometry->has_indices = has_indices; + // geometry_data *geometry = malloc(sizeof(geometry_data)); + // geometry->format = VERTEX_STATIC_3D; + // geometry->colour = (rgba){ 1, 1, 1, 1 }; + // geometry->vertices = geo_vertices; + // geometry->indices = geo_indices; + // geometry->has_indices = has_indices; - mesh m = mesh_create(geometry, true); - m.material_index = (u32_opt){ .has_value = mat_idx == 9999, .value = mat_idx }; + // mesh m = mesh_create(geometry, true); + // m.material_index = (u32_opt){ .has_value = mat_idx == 9999, .value = mat_idx }; - mesh_darray_push(out_model->meshes, m); - } + // mesh_darray_push(out_model->meshes, m); + // } // // clear data for each mesh // vec3_darray_clear(tmp_positions); diff --git a/src/resources/obj.c b/src/resources/obj.c index bf2f353..87d3ed6 100644 --- a/src/resources/obj.c +++ b/src/resources/obj.c @@ -36,14 +36,14 @@ KITC_DECL_TYPED_ARRAY(Vec2) KITC_DECL_TYPED_ARRAY(face) // Forward declarations -void create_submesh(mesh_darray *meshes, Vec3_darray *tmp_positions, Vec3_darray *tmp_normals, - Vec2_darray *tmp_uvs, face_darray *tmp_faces, material_darray *materials, - bool material_loaded, char current_material_name[256]); -bool load_material_lib(const char *path, str8 relative_path, material_darray *materials); -bool model_load_obj_str(const char *file_string, str8 relative_path, Model *out_model, - bool invert_textures_y); - -model_handle model_load_obj(Core *core, const char *path, bool invert_textures_y) { +// void create_submesh(mesh_darray *meshes, Vec3_darray *tmp_positions, Vec3_darray *tmp_normals, +// Vec2_darray *tmp_uvs, face_darray *tmp_faces, material_darray *materials, +// bool material_loaded, char current_material_name[256]); +// bool load_material_lib(const char *path, str8 relative_path, material_darray *materials); +// bool model_load_obj_str(const char *file_string, str8 relative_path, Model *out_model, +// bool invert_textures_y); + +ModelHandle model_load_obj(Core *core, const char *path, bool invert_textures_y) { size_t arena_size = 1024; arena scratch = arena_create(malloc(arena_size), arena_size); @@ -54,24 +54,24 @@ model_handle model_load_obj(Core *core, const char *path, bool invert_textures_y } const char *file_string = string_from_file(path); - model_handle handle; - model *model = model_pool_alloc(&g_core.models, &handle); - model->name = str8_cstr_view(path); - model->meshes = mesh_darray_new(1); + ModelHandle handle; + // model *model = model_pool_alloc(&g_core.models, &handle); + // model->name = str8_cstr_view(path); + // model->meshes = mesh_darray_new(1); - bool success = model_load_obj_str(file_string, relative_path.path, &model, invert_textures_y); + // bool success = model_load_obj_str(file_string, relative_path.path, &model, invert_textures_y); - if (!success) { - FATAL("Couldnt load OBJ file at path %s", path); - ERROR_EXIT("Load fails are considered crash-worthy right now. This will change later.\n"); - } + // if (!success) { + // FATAL("Couldnt load OBJ file at path %s", path); + // ERROR_EXIT("Load fails are considered crash-worthy right now. This will change later.\n"); + // } - arena_free_all(&scratch); - arena_free_storage(&scratch); + // arena_free_all(&scratch); + // arena_free_storage(&scratch); return handle; } -bool model_load_obj_str(const char *file_string, str8 relative_path, model *out_model, +bool model_load_obj_str(const char *file_string, Str8 relative_path, Model *out_model, bool invert_textures_y) { TRACE("Load OBJ from string"); @@ -232,166 +232,166 @@ bool model_load_obj_str(const char *file_string, str8 relative_path, model *out_ return true; } -/** - * @brief Takes the current positions, normals, uvs arrays and constructs the vertex array - * from those indices. - */ -void create_submesh(mesh_darray *meshes, vec3_darray *tmp_positions, vec3_darray *tmp_normals, - vec2_darray *tmp_uvs, face_darray *tmp_faces, material_darray *materials, - bool material_loaded, char current_material_name[256]) { - // size_t num_verts = face_darray_len(tmp_faces) * 3; - // vertex_darray *out_vertices = vertex_darray_new(num_verts); - - // face_darray_iter face_iter = face_darray_iter_new(tmp_faces); - // struct face *f; - - // while ((f = face_darray_iter_next(&face_iter))) { - // for (int j = 0; j < 3; j++) { - // vertex vert = { 0 }; - // vert.position = tmp_positions->data[f->vertex_indices[j] - 1]; - // if (vec3_darray_len(tmp_normals) == 0) { - // vert.normal = vec3_create(0.0, 0.0, 0.0); - // } else { - // vert.normal = tmp_normals->data[f->normal_indices[j] - 1]; - // } - // vert.uv = tmp_uvs->data[f->uv_indices[j] - 1]; - // vertex_darray_push(out_vertices, vert); - // } - // } - - // DEBUG("Loaded submesh\n vertices: %zu\n uvs: %zu\n normals: %zu\n faces: %zu", - // vec3_darray_len(tmp_positions), vec2_darray_len(tmp_uvs), vec3_darray_len(tmp_normals), - // face_darray_len(tmp_faces)); - - // // Clear current object faces - // face_darray_clear(tmp_faces); - - // mesh m = { .vertices = out_vertices }; - // if (material_loaded) { - // // linear scan to find material - // bool found = false; - // DEBUG("Num of materials : %ld", material_darray_len(materials)); - // material_darray_iter mat_iter = material_darray_iter_new(materials); - // blinn_phong_material *cur_material; - // while ((cur_material = material_darray_iter_next(&mat_iter))) { - // if (strcmp(cur_material->name, current_material_name) == 0) { - // DEBUG("Found match"); - // m.material_index = mat_iter.current_idx - 1; - // found = true; - // break; - // } - // } - - // if (!found) { - // // TODO: default material - // m.material_index = 0; - // DEBUG("Set default material"); - // } - // } - // mesh_darray_push(meshes, m); -} - -bool load_material_lib(const char *path, str8 relative_path, material_darray *materials) { - TRACE("BEGIN load material lib at %s", path); - - // const char *file_string = string_from_file(path); - // if (file_string == NULL) { - // ERROR("couldnt load %s", path); - // return false; - // } - - // char *pch; - // char *saveptr; - // pch = strtok_r((char *)file_string, "\n", &saveptr); - - // material current_material = DEFAULT_MATERIAL; - - // bool material_set = false; - - // while (pch != NULL) { - // char line_header[128]; - // int offset = 0; - // // read the first word of the line - // int res = sscanf(pch, "%s %n", line_header, &offset); - // if (res != 1) { - // break; - // } - - // // When we see "newmtl", start a new material, or flush the previous one - // if (strcmp(line_header, "newmtl") == 0) { - // if (material_set) { - // // a material was being parsed, so flush that one and start a new one - // material_darray_push(materials, current_material); - // DEBUG("pushed material with name %s", current_material.name); - // WARN("Reset current material"); - // current_material = DEFAULT_MATERIAL; - // } else { - // material_set = true; - // } - // // scan the new material name - // char material_name[64]; - // sscanf(pch + offset, "%s", current_material.name); - // DEBUG("material name %s\n", current_material.name); - // // current_material.name = material_name; - // } else if (strcmp(line_header, "Ka") == 0) { - // // ambient - // sscanf(pch + offset, "%f %f %f", ¤t_material.ambient_colour.x, - // ¤t_material.ambient_colour.y, ¤t_material.ambient_colour.z); - // } else if (strcmp(line_header, "Kd") == 0) { - // // diffuse - // sscanf(pch + offset, "%f %f %f", ¤t_material.diffuse.x, ¤t_material.diffuse.y, - // ¤t_material.diffuse.z); - // } else if (strcmp(line_header, "Ks") == 0) { - // // specular - // sscanf(pch + offset, "%f %f %f", ¤t_material.specular.x, - // ¤t_material.specular.y, - // ¤t_material.specular.z); - // } else if (strcmp(line_header, "Ns") == 0) { - // // specular exponent - // sscanf(pch + offset, "%f", ¤t_material.spec_exponent); - // } else if (strcmp(line_header, "map_Kd") == 0) { - // char diffuse_map_filename[1024]; - // sscanf(pch + offset, "%s", diffuse_map_filename); - // char diffuse_map_path[1024]; - // snprintf(diffuse_map_path, sizeof(diffuse_map_path), "%s/%s", relative_path.buf, - // diffuse_map_filename); - // printf("load from %s\n", diffuse_map_path); - - // // -------------- - // texture diffuse_texture = texture_data_load(diffuse_map_path, true); - // current_material.diffuse_texture = diffuse_texture; - // strcpy(current_material.diffuse_tex_path, diffuse_map_path); - // texture_data_upload(¤t_material.diffuse_texture); - // // -------------- - // } else if (strcmp(line_header, "map_Ks") == 0) { - // // char specular_map_path[1024] = "assets/"; - // // sscanf(pch + offset, "%s", specular_map_path + 7); - // char specular_map_filename[1024]; - // sscanf(pch + offset, "%s", specular_map_filename); - // char specular_map_path[1024]; - // snprintf(specular_map_path, sizeof(specular_map_path), "%s/%s", relative_path.buf, - // specular_map_filename); - // printf("load from %s\n", specular_map_path); - // // -------------- - // texture specular_texture = texture_data_load(specular_map_path, true); - // current_material.specular_texture = specular_texture; - // strcpy(current_material.specular_tex_path, specular_map_path); - // texture_data_upload(¤t_material.specular_texture); - // // -------------- - // } else if (strcmp(line_header, "map_Bump") == 0) { - // // TODO - // } - - // pch = strtok_r(NULL, "\n", &saveptr); - // } - - // TRACE("end load material lib"); - - // // last mesh or if one wasnt created with 'o' directive - // // TRACE("Last leftover material"); - // material_darray_push(materials, current_material); - - // INFO("Loaded %ld materials", material_darray_len(materials)); - TRACE("END load material lib"); - return true; -} +// /** +// * @brief Takes the current positions, normals, uvs arrays and constructs the vertex array +// * from those indices. +// */ +// void create_submesh(mesh_darray *meshes, vec3_darray *tmp_positions, vec3_darray *tmp_normals, +// vec2_darray *tmp_uvs, face_darray *tmp_faces, material_darray *materials, +// bool material_loaded, char current_material_name[256]) { +// // size_t num_verts = face_darray_len(tmp_faces) * 3; +// // vertex_darray *out_vertices = vertex_darray_new(num_verts); + +// // face_darray_iter face_iter = face_darray_iter_new(tmp_faces); +// // struct face *f; + +// // while ((f = face_darray_iter_next(&face_iter))) { +// // for (int j = 0; j < 3; j++) { +// // vertex vert = { 0 }; +// // vert.position = tmp_positions->data[f->vertex_indices[j] - 1]; +// // if (vec3_darray_len(tmp_normals) == 0) { +// // vert.normal = vec3_create(0.0, 0.0, 0.0); +// // } else { +// // vert.normal = tmp_normals->data[f->normal_indices[j] - 1]; +// // } +// // vert.uv = tmp_uvs->data[f->uv_indices[j] - 1]; +// // vertex_darray_push(out_vertices, vert); +// // } +// // } + +// // DEBUG("Loaded submesh\n vertices: %zu\n uvs: %zu\n normals: %zu\n faces: %zu", +// // vec3_darray_len(tmp_positions), vec2_darray_len(tmp_uvs), vec3_darray_len(tmp_normals), +// // face_darray_len(tmp_faces)); + +// // // Clear current object faces +// // face_darray_clear(tmp_faces); + +// // mesh m = { .vertices = out_vertices }; +// // if (material_loaded) { +// // // linear scan to find material +// // bool found = false; +// // DEBUG("Num of materials : %ld", material_darray_len(materials)); +// // material_darray_iter mat_iter = material_darray_iter_new(materials); +// // blinn_phong_material *cur_material; +// // while ((cur_material = material_darray_iter_next(&mat_iter))) { +// // if (strcmp(cur_material->name, current_material_name) == 0) { +// // DEBUG("Found match"); +// // m.material_index = mat_iter.current_idx - 1; +// // found = true; +// // break; +// // } +// // } + +// // if (!found) { +// // // TODO: default material +// // m.material_index = 0; +// // DEBUG("Set default material"); +// // } +// // } +// // mesh_darray_push(meshes, m); +// } + +// bool load_material_lib(const char *path, str8 relative_path, material_darray *materials) { +// TRACE("BEGIN load material lib at %s", path); + +// // const char *file_string = string_from_file(path); +// // if (file_string == NULL) { +// // ERROR("couldnt load %s", path); +// // return false; +// // } + +// // char *pch; +// // char *saveptr; +// // pch = strtok_r((char *)file_string, "\n", &saveptr); + +// // material current_material = DEFAULT_MATERIAL; + +// // bool material_set = false; + +// // while (pch != NULL) { +// // char line_header[128]; +// // int offset = 0; +// // // read the first word of the line +// // int res = sscanf(pch, "%s %n", line_header, &offset); +// // if (res != 1) { +// // break; +// // } + +// // // When we see "newmtl", start a new material, or flush the previous one +// // if (strcmp(line_header, "newmtl") == 0) { +// // if (material_set) { +// // // a material was being parsed, so flush that one and start a new one +// // material_darray_push(materials, current_material); +// // DEBUG("pushed material with name %s", current_material.name); +// // WARN("Reset current material"); +// // current_material = DEFAULT_MATERIAL; +// // } else { +// // material_set = true; +// // } +// // // scan the new material name +// // char material_name[64]; +// // sscanf(pch + offset, "%s", current_material.name); +// // DEBUG("material name %s\n", current_material.name); +// // // current_material.name = material_name; +// // } else if (strcmp(line_header, "Ka") == 0) { +// // // ambient +// // sscanf(pch + offset, "%f %f %f", ¤t_material.ambient_colour.x, +// // ¤t_material.ambient_colour.y, ¤t_material.ambient_colour.z); +// // } else if (strcmp(line_header, "Kd") == 0) { +// // // diffuse +// // sscanf(pch + offset, "%f %f %f", ¤t_material.diffuse.x, ¤t_material.diffuse.y, +// // ¤t_material.diffuse.z); +// // } else if (strcmp(line_header, "Ks") == 0) { +// // // specular +// // sscanf(pch + offset, "%f %f %f", ¤t_material.specular.x, +// // ¤t_material.specular.y, +// // ¤t_material.specular.z); +// // } else if (strcmp(line_header, "Ns") == 0) { +// // // specular exponent +// // sscanf(pch + offset, "%f", ¤t_material.spec_exponent); +// // } else if (strcmp(line_header, "map_Kd") == 0) { +// // char diffuse_map_filename[1024]; +// // sscanf(pch + offset, "%s", diffuse_map_filename); +// // char diffuse_map_path[1024]; +// // snprintf(diffuse_map_path, sizeof(diffuse_map_path), "%s/%s", relative_path.buf, +// // diffuse_map_filename); +// // printf("load from %s\n", diffuse_map_path); + +// // // -------------- +// // texture diffuse_texture = texture_data_load(diffuse_map_path, true); +// // current_material.diffuse_texture = diffuse_texture; +// // strcpy(current_material.diffuse_tex_path, diffuse_map_path); +// // texture_data_upload(¤t_material.diffuse_texture); +// // // -------------- +// // } else if (strcmp(line_header, "map_Ks") == 0) { +// // // char specular_map_path[1024] = "assets/"; +// // // sscanf(pch + offset, "%s", specular_map_path + 7); +// // char specular_map_filename[1024]; +// // sscanf(pch + offset, "%s", specular_map_filename); +// // char specular_map_path[1024]; +// // snprintf(specular_map_path, sizeof(specular_map_path), "%s/%s", relative_path.buf, +// // specular_map_filename); +// // printf("load from %s\n", specular_map_path); +// // // -------------- +// // texture specular_texture = texture_data_load(specular_map_path, true); +// // current_material.specular_texture = specular_texture; +// // strcpy(current_material.specular_tex_path, specular_map_path); +// // texture_data_upload(¤t_material.specular_texture); +// // // -------------- +// // } else if (strcmp(line_header, "map_Bump") == 0) { +// // // TODO +// // } + +// // pch = strtok_r(NULL, "\n", &saveptr); +// // } + +// // TRACE("end load material lib"); + +// // // last mesh or if one wasnt created with 'o' directive +// // // TRACE("Last leftover material"); +// // material_darray_push(materials, current_material); + +// // INFO("Loaded %ld materials", material_darray_len(materials)); +// TRACE("END load material lib"); +// return true; +// } |