diff --git a/Assets/UniGLTF/Runtime/Extensions/IndexExtensions.cs b/Assets/UniGLTF/Runtime/Extensions/IndexExtensions.cs new file mode 100644 index 000000000..7599e5b95 --- /dev/null +++ b/Assets/UniGLTF/Runtime/Extensions/IndexExtensions.cs @@ -0,0 +1,19 @@ +namespace UniGLTF +{ + public static class IndexExtensions + { + public static bool HasValidIndex(this int? self) + { + if (!self.HasValue) + { + return false; + } + if (self.Value < 0) + { + // 古いモデルで index の無効値に -1 を使っている場合がある + return false; + } + return true; + } + } +} diff --git a/Assets/UniGLTF/Runtime/Extensions/IndexExtensions.cs.meta b/Assets/UniGLTF/Runtime/Extensions/IndexExtensions.cs.meta new file mode 100644 index 000000000..c34759131 --- /dev/null +++ b/Assets/UniGLTF/Runtime/Extensions/IndexExtensions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e0989fbb259f59149ab310387ea69835 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/BufferAccessor.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/BufferAccessor.cs index 6ead44a56..faf01bfe1 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/BufferAccessor.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/BufferAccessor.cs @@ -318,7 +318,6 @@ namespace UniGLTF componentType = (glComponentType)ComponentType, type = AccessorType.ToString(), count = Count, - byteOffset = -1, sparse = new glTFSparse { count = sparseValuesWithIndex.Count, diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs index 6e4feffe4..2a37c94b7 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs @@ -218,7 +218,7 @@ namespace UniGLTF if (vertexAccessor.count <= 0) return NativeArrayManager.CreateNativeArray(0); - var result = (vertexAccessor.bufferView.HasValue) + var result = (vertexAccessor.bufferView.HasValidIndex()) ? GetTypedFromAccessor(vertexAccessor, GLTF.bufferViews[vertexAccessor.bufferView.Value]) : NativeArrayManager.CreateNativeArray(vertexAccessor.count) ; @@ -277,7 +277,7 @@ namespace UniGLTF var bufferCount = vertexAccessor.count * vertexAccessor.TypeCount; NativeArray result = default; - if (vertexAccessor.bufferView.HasValue) + if (vertexAccessor.bufferView.HasValidIndex()) { var view = GLTF.bufferViews[vertexAccessor.bufferView.Value]; var segment = GetBytesFromBuffer(view.buffer);