mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-07-13 14:42:48 -05:00
Merge pull request #1748 from ousttrue/fix/negative_index
-1 を index の無効値に使っている場合の対策
This commit is contained in:
commit
abb3d384d2
19
Assets/UniGLTF/Runtime/Extensions/IndexExtensions.cs
Normal file
19
Assets/UniGLTF/Runtime/Extensions/IndexExtensions.cs
Normal file
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/UniGLTF/Runtime/Extensions/IndexExtensions.cs.meta
Normal file
11
Assets/UniGLTF/Runtime/Extensions/IndexExtensions.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e0989fbb259f59149ab310387ea69835
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -318,7 +318,6 @@ namespace UniGLTF
|
|||
componentType = (glComponentType)ComponentType,
|
||||
type = AccessorType.ToString(),
|
||||
count = Count,
|
||||
byteOffset = -1,
|
||||
sparse = new glTFSparse
|
||||
{
|
||||
count = sparseValuesWithIndex.Count,
|
||||
|
|
|
|||
|
|
@ -218,7 +218,7 @@ namespace UniGLTF
|
|||
|
||||
if (vertexAccessor.count <= 0) return NativeArrayManager.CreateNativeArray<T>(0);
|
||||
|
||||
var result = (vertexAccessor.bufferView.HasValue)
|
||||
var result = (vertexAccessor.bufferView.HasValidIndex())
|
||||
? GetTypedFromAccessor<T>(vertexAccessor, GLTF.bufferViews[vertexAccessor.bufferView.Value])
|
||||
: NativeArrayManager.CreateNativeArray<T>(vertexAccessor.count)
|
||||
;
|
||||
|
|
@ -277,7 +277,7 @@ namespace UniGLTF
|
|||
var bufferCount = vertexAccessor.count * vertexAccessor.TypeCount;
|
||||
|
||||
NativeArray<float> result = default;
|
||||
if (vertexAccessor.bufferView.HasValue)
|
||||
if (vertexAccessor.bufferView.HasValidIndex())
|
||||
{
|
||||
var view = GLTF.bufferViews[vertexAccessor.bufferView.Value];
|
||||
var segment = GetBytesFromBuffer(view.buffer);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user