Skip to content

Commit

Permalink
Merge pull request #2213 from tsgcpp/feature/fix_for_byteoffset_zero
Browse files Browse the repository at this point in the history
attributesのbufferViewは連続であるが、indicesのbufferViewがprimitivesの順番で連続ではないVRM0.xをロードするとエラーになる問題の対策
  • Loading branch information
ousttrue authored Jan 9, 2024
2 parents 2c55dc9 + e348360 commit 54295da
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions Assets/VRM10/Runtime/IO/Vrm10ImportData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ bool AccessorsIsContinuous(int[] accessorIndices)
{
var firstAccessor = Gltf.accessors[accessorIndices[0]];
var firstView = Gltf.bufferViews[firstAccessor.bufferView.Value];
var start = firstView.byteOffset + firstAccessor.byteOffset;
var firstAccessorByteOffset = firstAccessor.byteOffset.GetValueOrDefault();
var start = firstView.byteOffset + firstAccessorByteOffset;
var pos = start;
foreach (var i in accessorIndices)
{
Expand All @@ -264,18 +265,25 @@ bool AccessorsIsContinuous(int[] accessorIndices)
{
throw new ArgumentException($"accessor.type: {current.type}");
}

if (firstAccessor.componentType != current.componentType)
{
return false;
}

var view = Gltf.bufferViews[current.bufferView.Value];
if (pos != view.byteOffset + current.byteOffset)
if (firstView.buffer != view.buffer)
{
return false;
}

var currentAccessorByteOffset = current.byteOffset.GetValueOrDefault();
if (pos != view.byteOffset + currentAccessorByteOffset)
{
return false;
}

var begin = view.byteOffset + current.byteOffset;
var begin = view.byteOffset + currentAccessorByteOffset;
var byteLength = current.CalcByteSize();

pos += byteLength;
Expand Down Expand Up @@ -312,7 +320,7 @@ public BufferAccessor CreateAccessor(int[] accessorIndices)
else
{
// IndexBufferが連続して格納されていない => Int[] を作り直す
using (var indices = new NativeArray<byte>(totalCount * Marshal.SizeOf(typeof(int)), Allocator.Persistent))
var indices = m_data.NativeArrayManager.CreateNativeArray<byte>(totalCount * Marshal.SizeOf(typeof(int)));
{
var span = indices.Reinterpret<Int32>(1);
var offset = 0;
Expand Down

0 comments on commit 54295da

Please sign in to comment.