Skip to content

Commit

Permalink
fix: Loading glTFs with nothing but accessors/bufferViews/buffers (fixes
Browse files Browse the repository at this point in the history
 #422)

fix: Loading glTFs with invalid embed buffers (fixes #422)
  • Loading branch information
atteneder committed Jul 1, 2022
1 parent 6484f83 commit eada50d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
5 changes: 5 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased] -
### Fixed
- Loading glTFs with nothing but accessors/bufferViews/buffers (#422)
- Loading glTFs with invalid embed buffers (#422)

## [4.8.2] - 2022-06-15
### Changed
- Load textures/images, even when not referenced by material (#418)
Expand Down
26 changes: 14 additions & 12 deletions Runtime/Scripts/GltfImport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ async Task<bool> ParseJsonAndLoadBuffers( string json, Uri baseUri ) {
buffer.uri,
true // usually there's just one buffer and it's time-critical
);
buffers[i] = decodedBuffer.Item1;
buffers[i] = decodedBuffer?.Item1;
if(buffers[i]==null) {
logger?.Error(LogCode.EmbedBufferLoadFailed);
return false;
Expand Down Expand Up @@ -2244,17 +2244,19 @@ async Task<bool> LoadAccessorData( Root gltf ) {
}
}

foreach (var node in gltf.nodes) {
var attr = node.extensions?.EXT_mesh_gpu_instancing?.attributes;
if ( attr != null) {
if (attr.TRANSLATION >= 0) {
SetAccessorUsage(attr.TRANSLATION,AccessorUsage.Translation | AccessorUsage.RequiredForInstantiation);
}
if (attr.ROTATION >= 0) {
SetAccessorUsage(attr.ROTATION,AccessorUsage.Rotation | AccessorUsage.RequiredForInstantiation);
}
if (attr.SCALE >= 0) {
SetAccessorUsage(attr.SCALE,AccessorUsage.Scale | AccessorUsage.RequiredForInstantiation);
if (gltf.nodes != null) {
foreach (var node in gltf.nodes) {
var attr = node.extensions?.EXT_mesh_gpu_instancing?.attributes;
if ( attr != null) {
if (attr.TRANSLATION >= 0) {
SetAccessorUsage(attr.TRANSLATION,AccessorUsage.Translation | AccessorUsage.RequiredForInstantiation);
}
if (attr.ROTATION >= 0) {
SetAccessorUsage(attr.ROTATION,AccessorUsage.Rotation | AccessorUsage.RequiredForInstantiation);
}
if (attr.SCALE >= 0) {
SetAccessorUsage(attr.SCALE,AccessorUsage.Scale | AccessorUsage.RequiredForInstantiation);
}
}
}
}
Expand Down

0 comments on commit eada50d

Please sign in to comment.