Update fastgltf to 0.9.0
This commit is contained in:
@@ -165,12 +165,12 @@ vk::PrimitiveTopology convert(fastgltf::PrimitiveType type)
|
||||
throw std::invalid_argument("type");
|
||||
}
|
||||
|
||||
glm::vec4 convert(const std::array<float, 4> & v)
|
||||
glm::vec4 convert(const fastgltf::math::nvec4 & v)
|
||||
{
|
||||
return {v[0], v[1], v[2], v[3]};
|
||||
}
|
||||
|
||||
glm::vec3 convert(const std::array<float, 3> & v)
|
||||
glm::vec3 convert(const fastgltf::math::nvec3 & v)
|
||||
{
|
||||
return {v[0], v[1], v[2]};
|
||||
}
|
||||
@@ -196,7 +196,7 @@ void copy_vertex_attributes(
|
||||
if (it == primitive.attributes.end())
|
||||
continue;
|
||||
|
||||
const fastgltf::Accessor & accessor = asset.accessors.at(it->second);
|
||||
const fastgltf::Accessor & accessor = asset.accessors.at(it->accessorIndex);
|
||||
|
||||
if (vertices.size() < accessor.count)
|
||||
vertices.resize(accessor.count, {});
|
||||
@@ -221,7 +221,7 @@ void copy_vertex_attributes(
|
||||
if (it == primitive.attributes.end())
|
||||
return;
|
||||
|
||||
const fastgltf::Accessor & accessor = asset.accessors.at(it->second);
|
||||
const fastgltf::Accessor & accessor = asset.accessors.at(it->accessorIndex);
|
||||
|
||||
if (vertices.size() < accessor.count)
|
||||
vertices.resize(accessor.count, {});
|
||||
@@ -285,6 +285,21 @@ loaded_image do_load_image(
|
||||
}
|
||||
// END
|
||||
|
||||
// BEGIN Error category
|
||||
struct : std::error_category
|
||||
{
|
||||
const char * name() const noexcept override
|
||||
{
|
||||
return "fastgltf";
|
||||
}
|
||||
|
||||
std::string message(int condition) const override
|
||||
{
|
||||
return (std::string)fastgltf::getErrorMessage(static_cast<fastgltf::Error>(condition));
|
||||
}
|
||||
} fastgltf_error_category;
|
||||
// END
|
||||
|
||||
fastgltf::Asset load_gltf_asset(fastgltf::GltfDataBuffer & buffer, const std::filesystem::path & directory)
|
||||
{
|
||||
fastgltf::Parser parser(fastgltf::Extensions::KHR_texture_basisu);
|
||||
@@ -292,13 +307,12 @@ fastgltf::Asset load_gltf_asset(fastgltf::GltfDataBuffer & buffer, const std::fi
|
||||
auto gltf_options =
|
||||
fastgltf::Options::DontRequireValidAssetMember |
|
||||
fastgltf::Options::AllowDouble |
|
||||
fastgltf::Options::LoadGLBBuffers |
|
||||
fastgltf::Options::DecomposeNodeMatrices;
|
||||
|
||||
auto expected_asset = parser.loadGltf(&buffer, directory, gltf_options);
|
||||
auto expected_asset = parser.loadGltf(buffer, directory, gltf_options);
|
||||
|
||||
if (auto error = expected_asset.error(); error != fastgltf::Error::None)
|
||||
throw std::runtime_error(std::string(fastgltf::getErrorMessage(error)));
|
||||
throw std::system_error((int)error, fastgltf_error_category);
|
||||
|
||||
return std::move(expected_asset.get());
|
||||
}
|
||||
@@ -776,15 +790,17 @@ entt::registry scene_loader::operator()(const std::filesystem::path & gltf_path)
|
||||
spdlog::debug("Loading {}", gltf_path.native());
|
||||
|
||||
asset asset_file(gltf_path);
|
||||
fastgltf::GltfDataBuffer data_buffer;
|
||||
data_buffer.copyBytes(reinterpret_cast<const uint8_t *>(asset_file.data()), asset_file.size());
|
||||
|
||||
fastgltf::Asset asset = load_gltf_asset(data_buffer, gltf_path.parent_path());
|
||||
auto data_buffer = fastgltf::GltfDataBuffer::FromBytes(asset_file.data(), asset_file.size());
|
||||
if (auto error = data_buffer.error(); error != fastgltf::Error::None)
|
||||
throw std::system_error((int)error, fastgltf_error_category);
|
||||
|
||||
fastgltf::Asset asset = load_gltf_asset(data_buffer.get(), gltf_path.parent_path());
|
||||
loader_context ctx(gltf_path.parent_path(), gltf_path, asset, physical_device, device, queue, cb_pool);
|
||||
|
||||
#ifndef NDEBUG
|
||||
if (auto error = fastgltf::validate(asset); error != fastgltf::Error::None)
|
||||
throw std::runtime_error(std::string(fastgltf::getErrorMessage(error)));
|
||||
throw std::system_error((int)error, fastgltf_error_category);
|
||||
#endif
|
||||
|
||||
// Load all buffers from URIs
|
||||
|
||||
Reference in New Issue
Block a user