private static void MergeAccessorsBufferViewsAndBuffers(GLTFRoot mergeToRoot, GLTFRoot mergeFromRoot, PreviousGLTFSizes previousGLTFSizes) { if (mergeFromRoot.Buffers != null) { if (mergeToRoot.Buffers == null) { mergeToRoot.Buffers = new List <Buffer>(mergeFromRoot.Buffers.Count); } mergeToRoot.Buffers.AddRange(mergeFromRoot.Buffers); } if (mergeFromRoot.BufferViews != null) { if (mergeToRoot.BufferViews == null) { mergeToRoot.BufferViews = new List <BufferView>(mergeFromRoot.BufferViews.Count); } mergeToRoot.BufferViews.AddRange(mergeFromRoot.BufferViews); for (int i = previousGLTFSizes.PreviousBufferViewCount; i < mergeToRoot.BufferViews.Count; ++i) { GLTFId <Buffer> bufferId = mergeToRoot.BufferViews[i].Buffer; bufferId.Id += previousGLTFSizes.PreviousBufferCount; bufferId.Root = mergeToRoot; } } if (mergeFromRoot.Accessors != null) { if (mergeToRoot.Accessors == null) { mergeToRoot.Accessors = new List <Accessor>(mergeFromRoot.Accessors.Count); } mergeToRoot.Accessors.AddRange(mergeFromRoot.Accessors); for (int i = previousGLTFSizes.PreviousAccessorCount; i < mergeToRoot.Accessors.Count; ++i) { Accessor accessor = mergeToRoot.Accessors[i]; if (accessor.BufferView != null) { BufferViewId bufferViewId = accessor.BufferView; bufferViewId.Id += previousGLTFSizes.PreviousBufferViewCount; bufferViewId.Root = mergeToRoot; } AccessorSparse accessorSparse = accessor.Sparse; if (accessorSparse != null) { BufferViewId indicesId = accessorSparse.Indices.BufferView; indicesId.Id += previousGLTFSizes.PreviousBufferViewCount; indicesId.Root = mergeToRoot; BufferViewId valuesId = accessorSparse.Values.BufferView; valuesId.Id += previousGLTFSizes.PreviousBufferViewCount; valuesId.Root = mergeToRoot; } } } }
private static void MergeAccessorsBufferViewsAndBuffers(GLTFRoot mergeToRoot, GLTFRoot mergeFromRoot, PreviousGLTFSizes previousGLTFSizes) { bool isGLB = false; if (mergeFromRoot.Buffers != null) { if (mergeToRoot.Buffers == null) { mergeToRoot.Buffers = new List <GLTFBuffer>(mergeFromRoot.Buffers.Count); } foreach (GLTFBuffer buffer in mergeFromRoot.Buffers) { if (buffer.Uri != null) { mergeToRoot.Buffers.Add(buffer); } else { isGLB = true; // assume glb is a uri is null } } } if (mergeFromRoot.BufferViews != null) { if (mergeToRoot.BufferViews == null) { mergeToRoot.BufferViews = new List <BufferView>(mergeFromRoot.BufferViews.Count); } mergeToRoot.BufferViews.AddRange(mergeFromRoot.BufferViews); for (int i = previousGLTFSizes.PreviousBufferViewCount; i < mergeToRoot.BufferViews.Count; ++i) { GLTFId <GLTFBuffer> bufferId = mergeToRoot.BufferViews[i].Buffer; if (!(isGLB && bufferId.Id == 0)) // if it is pointing a the special glb buffer (index 0 of a glb) then we dont want to adjust the buffer view, otherwise we do { // adjusting bufferview id based on merge amount bufferId.Id += previousGLTFSizes.PreviousBufferCount; bufferId.Root = mergeToRoot; } } } if (mergeFromRoot.Accessors != null) { if (mergeToRoot.Accessors == null) { mergeToRoot.Accessors = new List <Accessor>(mergeFromRoot.Accessors.Count); } mergeToRoot.Accessors.AddRange(mergeFromRoot.Accessors); for (int i = previousGLTFSizes.PreviousAccessorCount; i < mergeToRoot.Accessors.Count; ++i) { Accessor accessor = mergeToRoot.Accessors[i]; if (accessor.BufferView != null) { BufferViewId bufferViewId = accessor.BufferView; bufferViewId.Id += previousGLTFSizes.PreviousBufferViewCount; bufferViewId.Root = mergeToRoot; } AccessorSparse accessorSparse = accessor.Sparse; if (accessorSparse != null) { BufferViewId indicesId = accessorSparse.Indices.BufferView; indicesId.Id += previousGLTFSizes.PreviousBufferViewCount; indicesId.Root = mergeToRoot; BufferViewId valuesId = accessorSparse.Values.BufferView; valuesId.Id += previousGLTFSizes.PreviousBufferViewCount; valuesId.Root = mergeToRoot; } } } }