From 0dafba17af044532fa2f14c61176e7994336f56c Mon Sep 17 00:00:00 2001 From: ladevieq Date: Sun, 1 Aug 2021 16:48:27 +0200 Subject: Use SAH to generate BVH & fix ray triangle intersection --- src/gltf.cpp | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'src/gltf.cpp') diff --git a/src/gltf.cpp b/src/gltf.cpp index 72219d6..055f2a6 100644 --- a/src/gltf.cpp +++ b/src/gltf.cpp @@ -5,6 +5,8 @@ #include "utils.hpp" +const vec3 scale (0.00800000037997961); + mesh gltf::load(std::filesystem::path &path, std::string &filename) { std::fstream f(path / filename); json gltf_json; @@ -61,7 +63,7 @@ void gltf::load_primitive(json &gltf_json, json &primitive, std::vector(); auto indices_buffer = buffers_content[indices_buffer_index]; - void* indices_start = indices_buffer.data() + indices_offset; + uint16_t* indices_start = (uint16_t*)(indices_buffer.data() + indices_offset); mesh_part.indices.resize(indices_length / sizeof(uint16_t)); @@ -83,25 +85,24 @@ void gltf::load_primitive(json &gltf_json, json &primitive, std::vector(); - auto normals_view_index = accessors[normals_accessor_index]["bufferView"].get(); - auto normals_view = gltf_json["bufferViews"][normals_view_index]; + // { + // auto normals_accessor_index = primitive["attributes"]["NORMAL"].get(); + // auto normals_view_index = accessors[normals_accessor_index]["bufferView"].get(); + // auto normals_view = gltf_json["bufferViews"][normals_view_index]; - auto normals_buffer_index = normals_view["buffer"].get(); - auto normals_offset = normals_view["byteOffset"].get(); - auto normals_length = normals_view["byteLength"].get(); + // auto normals_buffer_index = normals_view["buffer"].get(); + // auto normals_offset = normals_view["byteOffset"].get(); + // auto normals_length = normals_view["byteLength"].get(); - auto normals_buffer = buffers_content[normals_buffer_index]; - void* normals_start = normals_buffer.data() + normals_offset; + // auto normals_buffer = buffers_content[normals_buffer_index]; + // void* normals_start = normals_buffer.data() + normals_offset; - mesh_part.normals.resize(normals_length / (sizeof(float) * 3)); + // mesh_part.normals.resize(normals_length / (sizeof(float) * 3)); - std::memcpy(mesh_part.normals.data(), normals_start, normals_length); - } + // std::memcpy(mesh_part.normals.data(), normals_start, normals_length); + // } } -- cgit v1.3