diff options
| author | ladevieq <ladevie.quentin@gmail.com> | 2022-06-15 23:02:29 +0200 |
|---|---|---|
| committer | ladevieq <ladevie.quentin@gmail.com> | 2022-06-15 23:17:36 +0200 |
| commit | 5692f616c6201b39184e4353b6a4cb850a84a450 (patch) | |
| tree | e03976fb7c855b7719d9b68bd129b89a8519b712 /src/gltf.cpp | |
| parent | 5a4595ec5990abc660acb48ca2fe1f282bbe213b (diff) | |
Fix formatting and linting
Diffstat (limited to 'src/gltf.cpp')
| -rw-r--r-- | src/gltf.cpp | 85 |
1 files changed, 44 insertions, 41 deletions
diff --git a/src/gltf.cpp b/src/gltf.cpp index 2f37a3c..982e76d 100644 --- a/src/gltf.cpp +++ b/src/gltf.cpp @@ -1,3 +1,4 @@ + #include "gltf.hpp" #include <fstream> @@ -19,7 +20,7 @@ node gltf::load(std::filesystem::path &path, std::string &filename, vkrenderer & auto &buffers = gltf_json["buffers"]; auto buffer_index = 0; auto buffers_content = std::vector<std::vector<uint8_t>>(buffers.size()); - for (auto &buffer: buffers) { + for (auto &buffer : buffers) { auto buffer_path = (path / buffer["uri"].get<std::string>()).string(); buffers_content[buffer_index] = read_file(buffer_path); buffer_index++; @@ -39,7 +40,7 @@ node gltf::load(std::filesystem::path &path, std::string &filename, vkrenderer & load_node(gltf_json, root_children[child_index].get<uint32_t>(), root_node.children[child_index], meshes); } - return std::move(root_node); + return root_node; } void gltf::load_node(json &gltf_json, uint32_t index, node &parent, std::vector<mesh> &meshes) { @@ -55,54 +56,54 @@ void gltf::load_node(json &gltf_json, uint32_t index, node &parent, std::vector< } } - if (gltf_node.contains("mesh")) { - parent.mesh = std::make_optional(meshes[gltf_node["mesh"].get<uint32_t>()]); - } + if (gltf_node.contains("mesh")) { parent.mesh = std::make_optional(meshes[gltf_node["mesh"].get<uint32_t>()]); } } -std::vector<mesh> gltf::load_meshes(json &gltf_json, std::vector<std::vector<uint8_t>> &buffers_content, std::vector<material> &materials) { +std::vector<mesh> gltf::load_meshes( + json &gltf_json, std::vector<std::vector<uint8_t>> &buffers_content, std::vector<material> &materials) { auto &gltf_meshes = gltf_json["meshes"]; auto meshes_count = gltf_meshes.size(); - std::vector<mesh> meshes { meshes_count }; + std::vector<mesh> meshes{meshes_count}; - for(size_t mesh_index = 0; mesh_index < meshes_count; mesh_index++) { + for (size_t mesh_index = 0; mesh_index < meshes_count; mesh_index++) { auto &gltf_mesh = gltf_meshes[mesh_index]; auto &primitives = gltf_mesh["primitives"]; auto &mesh = meshes[mesh_index]; - for (auto& primitive: primitives) { - auto &&part = load_primitive(gltf_json, primitive, buffers_content, materials); + for (auto &primitive : primitives) { + auto part = load_primitive(gltf_json, primitive, buffers_content, materials); mesh.vertices_count += part.vertices_count; mesh.triangles_count += part.triangles_count; mesh.parts.emplace_back(std::move(part)); } } - return std::move(meshes); + return meshes; } std::vector<texture> gltf::load_textures(json &gltf_json, std::filesystem::path &path, vkrenderer &renderer) { auto &gltf_images = gltf_json["images"]; auto images_count = gltf_images.size(); - std::vector<Texture*> images { images_count }; + std::vector<Texture *> images{images_count}; for (size_t image_index = 0; image_index < images_count; image_index++) { auto &gltf_image = gltf_images[image_index]; - int x,y,n; + int x, y, n; auto filepath = (path / gltf_image["uri"].get<std::string>()).string(); unsigned char *data = stbi_load(filepath.c_str(), &x, &y, &n, 4); - auto img = renderer.create_2d_texture(static_cast<uint32_t>(x), static_cast<uint32_t>(y), VK_FORMAT_R8G8B8A8_UNORM); + auto *img = + renderer.create_2d_texture(static_cast<uint32_t>(x), static_cast<uint32_t>(y), VK_FORMAT_R8G8B8A8_UNORM); renderer.update_image(img, data); stbi_image_free(data); - images[image_index] = std::move(img); + images[image_index] = img; } auto &gltf_samplers = gltf_json["samplers"]; auto samplers_count = gltf_samplers.size(); - std::vector<Sampler*> samplers { samplers_count }; + std::vector<Sampler *> samplers{samplers_count}; for (size_t sampler_index = 0; sampler_index < samplers_count; sampler_index++) { samplers[sampler_index] = renderer.create_sampler(VK_FILTER_LINEAR, VK_SAMPLER_ADDRESS_MODE_REPEAT); @@ -110,7 +111,7 @@ std::vector<texture> gltf::load_textures(json &gltf_json, std::filesystem::path auto &gltf_textures = gltf_json["textures"]; auto textures_count = gltf_textures.size(); - std::vector<texture> textures { textures_count }; + std::vector<texture> textures{textures_count}; for (size_t texture_index = 0; texture_index < textures_count; texture_index++) { auto gltf_texture = gltf_textures[texture_index]; @@ -125,23 +126,21 @@ std::vector<texture> gltf::load_textures(json &gltf_json, std::filesystem::path // sampler_id = sampler->device_sampler.bindless_index; // } - // textures[texture_index] = texture { - // .image_id = image->device_image.bindless_sampled_index, - // .sampler_id = sampler_id - // }; + // textures[texture_index] = + // texture{.image_id = image->device_image.bindless_sampled_index, .sampler_id = sampler_id}; } - return std::move(textures); + return textures; } std::vector<material> gltf::load_materials(json &gltf_json, std::vector<texture> &textures) { auto &gltf_materials = gltf_json["materials"]; auto materials_count = gltf_materials.size(); - std::vector<material> materials { materials_count }; + std::vector<material> materials{materials_count}; - for(size_t material_index = 0; material_index < materials_count; material_index++) { - auto& gltf_material = gltf_materials[material_index]; - auto& material = materials[material_index]; + for (size_t material_index = 0; material_index < materials_count; material_index++) { + auto &gltf_material = gltf_materials[material_index]; + auto &material = materials[material_index]; if (gltf_material.contains("pbrMetallicRoughness")) { auto &pbr_params = gltf_material["pbrMetallicRoughness"]; @@ -152,23 +151,26 @@ std::vector<material> gltf::load_materials(json &gltf_json, std::vector<texture> material.base_color.v[1] = base_color[1].get<float>(); material.base_color.v[2] = base_color[2].get<float>(); material.base_color.v[3] = base_color[3].get<float>(); - } else + } else { material.base_color = vec3(1.f); + } if (pbr_params.contains("baseColorTexture")) { auto base_color_index = pbr_params["baseColorTexture"]["index"].get<uint32_t>(); material.base_color_texture = textures[base_color_index]; } - if (pbr_params.contains("metallicFactor")) + if (pbr_params.contains("metallicFactor")) { material.metalness = pbr_params["metallicFactor"].get<float>(); - else + } else { material.metalness = 1.0; + } - if (pbr_params.contains("roughnessFactor")) + if (pbr_params.contains("roughnessFactor")) { material.roughness = pbr_params["roughnessFactor"].get<float>(); - else + } else { material.roughness = 1.0; + } if (pbr_params.contains("metallicRoughnessTexture")) { auto metallic_roughness_index = pbr_params["metallicRoughnessTexture"]["index"].get<uint32_t>(); @@ -177,10 +179,11 @@ std::vector<material> gltf::load_materials(json &gltf_json, std::vector<texture> } } - return std::move(materials); + return materials; } -mesh_part gltf::load_primitive(json &gltf_json, json &primitive, std::vector<std::vector<uint8_t>> &buffers_content, std::vector<material> &materials) { +mesh_part gltf::load_primitive(json &gltf_json, json &primitive, std::vector<std::vector<uint8_t>> &buffers_content, + std::vector<material> &materials) { auto part = mesh_part(); auto &accessors = gltf_json["accessors"]; @@ -194,7 +197,7 @@ mesh_part gltf::load_primitive(json &gltf_json, json &primitive, std::vector<std auto indices_length = indices_view["byteLength"].get<size_t>(); auto &indices_buffer = buffers_content[indices_buffer_index]; - uint16_t* indices_start = (uint16_t*)(indices_buffer.data() + indices_offset); + auto *indices_start = (uint16_t *)(indices_buffer.data() + indices_offset); part.indices.resize(indices_length / sizeof(uint16_t)); std::memcpy(part.indices.data(), indices_start, indices_length); @@ -210,9 +213,9 @@ mesh_part gltf::load_primitive(json &gltf_json, json &primitive, std::vector<std auto positions_length = positions_view["byteLength"].get<size_t>(); auto &positions_buffer = buffers_content[positions_buffer_index]; - float* positions_start = (float*)(positions_buffer.data() + positions_offset); + auto *positions_start = (float *)(positions_buffer.data() + positions_offset); - part.positions.resize(positions_length / sizeof(float)); + part.positions.resize(positions_length / sizeof(float)); std::memcpy(part.positions.data(), positions_start, positions_length); } @@ -226,9 +229,9 @@ mesh_part gltf::load_primitive(json &gltf_json, json &primitive, std::vector<std auto normals_length = normals_view["byteLength"].get<size_t>(); auto &normals_buffer = buffers_content[normals_buffer_index]; - float* normals_start = (float*)(normals_buffer.data() + normals_offset); + auto *normals_start = (float *)(normals_buffer.data() + normals_offset); - part.normals.resize(normals_length / sizeof(float)); + part.normals.resize(normals_length / sizeof(float)); std::memcpy(part.normals.data(), normals_start, normals_length); } @@ -242,9 +245,9 @@ mesh_part gltf::load_primitive(json &gltf_json, json &primitive, std::vector<std auto uvs_length = uvs_view["byteLength"].get<size_t>(); auto &uvs_buffer = buffers_content[uvs_buffer_index]; - float* uvs_start = (float*)(uvs_buffer.data() + uvs_offset); + auto *uvs_start = (float *)(uvs_buffer.data() + uvs_offset); - part.uvs.resize(uvs_length / sizeof(float)); + part.uvs.resize(uvs_length / sizeof(float)); std::memcpy(part.uvs.data(), uvs_start, uvs_length); } @@ -252,5 +255,5 @@ mesh_part gltf::load_primitive(json &gltf_json, json &primitive, std::vector<std part.vertices_count = part.positions.size() / 3; part.triangles_count = part.indices.size() / 3; - return std::move(part); + return part; } |
