private static GltfInterleavedOperation GenerateCopyOperation(MgtfAccessor accessor, MgtfBufferView[] bufferViews) { if (!accessor.BufferView.HasValue) { throw new InvalidOperationException("unable to locate bufferview"); } var view = bufferViews[accessor.BufferView.Value]; var op = new GltfInterleavedOperation { BufferIndex = view.BufferIndex, Count = accessor.ElementCount, SrcOffset = (ulong)(view.BufferOffset + accessor.ViewOffset), TotalSize = (uint)(accessor.ElementCount * accessor.NoOfComponents * accessor.ElementByteSize), ByteStride = (view.ByteStride.HasValue) ? (uint)view.ByteStride.Value : accessor.NoOfComponents * accessor.ElementByteSize, }; return(op); }
private GltfPrimitiveStorageLocation[] AllocateMeshes( MgStorageBlockAllocationRequest request, MgtfMesh[] meshes, MgtfAccessor[] accessors, MgtfBufferView[] bufferViews) { var noOfMeshes = meshes != null ? meshes.Length : 0; var locations = new List <GltfPrimitiveStorageLocation>(); for (var i = 0; i < noOfMeshes; i += 1) { var mesh = meshes[i]; var noOfPrimitives = mesh.Primitives != null ? mesh.Primitives.Length : 0; for (var j = 0; j < noOfPrimitives; j += 1) { var primitive = mesh.Primitives[j]; var locator = primitive.VertexLocations; int?indexLocation = null; GltfInterleavedOperation indexCopy = null; if (locator.Indices.HasValue) { var accessor = accessors[locator.Indices.Value]; indexCopy = GenerateCopyOperation(accessor, bufferViews); indexCopy.DstStride = accessor.ElementByteSize; indexLocation = request.Insert(GetIndexAllocation(accessor)); } var vertexLocation = ExtractVertices( primitive.VertexCount, request, accessors, bufferViews, locator, out GltfInterleavedOperation[] vertexCopies); var copyOperations = new List <GltfInterleavedOperation>(); if (indexCopy != null) { copyOperations.Add(indexCopy); } copyOperations.AddRange(vertexCopies); var location = new GltfPrimitiveStorageLocation { Mesh = i, MeshPrimitive = j, FinalDefinition = PadVertexDefinition(primitive.InitialDefinition), Index = indexLocation, Vertex = vertexLocation, CopyOperations = copyOperations.ToArray(), }; locations.Add(location); } } return(locations.ToArray()); }