コード例 #1
0
        private static BufferViewInfo[] ExtractBufferViews(glTFLoader.Schema.Gltf model)
        {
            var copyFromBufferView = new BufferViewInfo[model.BufferViews.Length];

            for (var i = 0; i < copyFromBufferView.Length; i += 1)
            {
                var src = model.BufferViews[i];
                var dst = new BufferViewInfo()
                {
                    BufferIndex = src.Buffer,
                    ByteStride  = src.ByteStride,
                };
                switch (src.Target)
                {
                case glTFLoader.Schema.BufferView.TargetEnum.ARRAY_BUFFER:
                    dst.Usage = MgBufferUsageFlagBits.VERTEX_BUFFER_BIT;
                    break;

                case glTFLoader.Schema.BufferView.TargetEnum.ELEMENT_ARRAY_BUFFER:
                    dst.Usage = MgBufferUsageFlagBits.INDEX_BUFFER_BIT;
                    break;

                default:
                    throw new NotSupportedException($"specified target:({src.Target}) not supported");
                }
                copyFromBufferView[i] = dst;
            }

            return(copyFromBufferView);
        }
コード例 #2
0
        private static List <byte[]> LoadModelBuffers(glTFLoader.Schema.Gltf model, string baseDir)
        {
            var cachedBuffers = new List <byte[]>();

            foreach (var selectedBuffer in model.Buffers)
            {
                if (selectedBuffer.Uri.StartsWith("data:") && DataURL.FromUri(selectedBuffer.Uri, out DataURL output))
                {
                    if (output.Data.Length != selectedBuffer.ByteLength)
                    {
                        throw new InvalidDataException($"The specified length of embedded data chunk ({selectedBuffer.ByteLength}) is not equal to the actual length of the data chunk ({output.Data.Length}).");
                    }
                    cachedBuffers.Add(output.Data);
                }
                else
                {
                    // OPEN FILE
                    string additionalFilePath = System.IO.Path.Combine(baseDir, selectedBuffer.Uri);
                    using (var fs = File.Open(additionalFilePath, FileMode.Open))
                        using (var br = new BinaryReader(fs))
                        {
                            // ONLY READ SPECIFIED CHUNK SIZE
                            cachedBuffers.Add(br.ReadBytes(selectedBuffer.ByteLength));
                        }
                }
            }
            return(cachedBuffers);
        }
コード例 #3
0
ファイル: glTFLoader.cs プロジェクト: jpbruyere/vke.net
		public glTFLoader (string path, Queue _transferQ, CommandPool _cmdPool) {
			this.path = path;
			transferQ = _transferQ;
			cmdPool = _cmdPool;
			baseDirectory = Path.GetDirectoryName (path);
			gltf = Interface.LoadModel (path);
			loadedBuffers = new Memory<byte> [gltf.Buffers.Length];
		}
コード例 #4
0
ファイル: MainWindow.xaml.cs プロジェクト: yuaiqaing/XbimGltf
        private void report(gltf.Gltf t)
        {
            var sb = new StringBuilder();

            ReportAllProperties(t, sb);
            Debug.WriteLine(sb.ToString());
            // PrintProperties(t, 0);
        }
コード例 #5
0
ファイル: MainWindow.xaml.cs プロジェクト: yuaiqaing/XbimGltf
        private static void AddMesh(gltf.Gltf gltf, XbimMesher mesh)
        {
            gltf.Buffers = new glTFLoader.Schema.Buffer[1];
            var buf = new glTFLoader.Schema.Buffer();

            gltf.Buffers[0]  = buf;
            gltf.BufferViews = new gltf.BufferView[2];
        }
コード例 #6
0
 private static glTFLoader.Schema.Gltf CreateModel()
 {
     glTFLoader.Schema.Gltf gltf = new glTFLoader.Schema.Gltf();
     gltf.Asset = new glTFLoader.Schema.Asset()
     {
         Generator = "Xbim.GLTF.IO",
         Version   = "2.0"
     };
     return(gltf);
 }
コード例 #7
0
ファイル: glTFLoader.cs プロジェクト: Svengali/vk.net
 public glTFLoader(string path, Queue _transferQ, CommandPool _cmdPool)
 {
     this.path     = path;
     transferQ     = _transferQ;
     cmdPool       = _cmdPool;
     baseDirectory = System.IO.Path.GetDirectoryName(path);
     gltf          = Interface.LoadModel(path);;
     loadedBuffers = new byte[gltf.Buffers.Length][];
     bufferHandles = new GCHandle[gltf.Buffers.Length];
 }
コード例 #8
0
        private static GltfBufferView[] ExtractBufferViews(glTFLoader.Schema.Gltf model)
        {
            var noOfItems = model.BufferViews != null ? model.BufferViews.Length : 0;
            var output    = new GltfBufferView[noOfItems];

            for (var i = 0; i < noOfItems; i += 1)
            {
                output[i] = new GltfBufferView(model.BufferViews[i]);
            }
            return(output);
        }
コード例 #9
0
        private MgOptimizedStorageContainer GenerateMesh(
            glTFLoader.Schema.Gltf model,
            glTFLoader.Schema.Mesh mesh,
            IEffect effect,
            List <byte[]> buffers,
            BufferViewInfo[] bufferViews
            )
        {
            var  shaderLocations = effect.GetShaderAttributeLocations();
            var  accessors       = new List <GltfMeshAccessor>();
            uint primitiveIndex  = 0U;

            foreach (var primitive in mesh.Primitives)
            {
                if (primitive.Indices.HasValue)
                {
                    var accessor = ExtractAccessor(model, primitive.Indices.Value);
                    accessor.PrimitiveIndex = primitiveIndex;
                    accessor.Usage          = MgBufferUsageFlagBits.INDEX_BUFFER_BIT;
                    accessors.Add(accessor);
                }

                foreach (var attr in primitive.Attributes)
                {
                    var locationName  = attr.Key;
                    var accessorIndex = attr.Value;

                    var accessor = ExtractAccessor(model, accessorIndex);
                    accessor.PrimitiveIndex = primitiveIndex;
                    accessor.Usage          = MgBufferUsageFlagBits.VERTEX_BUFFER_BIT;
                    accessor.LocationIndex  = shaderLocations[locationName];
                    accessor.LocationName   = locationName;

                    accessors.Add(accessor);
                }
                primitiveIndex += 1;
            }

            var usedBufferViews  = new bool[bufferViews.Length];
            var blockAllocations = new List <MgStorageBlockAllocationInfo>();

            foreach (var attr in accessors)
            {
                var allocation = new MgStorageBlockAllocationInfo
                {
                    MemoryPropertyFlags = MgMemoryPropertyFlagBits.HOST_COHERENT_BIT,
                    Usage           = attr.Usage,
                    ElementByteSize = attr.ElementByteSize,
                    Size            = (ulong)(attr.NoOfComponents * attr.ElementCount * attr.ElementByteSize),
                };

                if (attr.BufferViewIndex.HasValue)
                {
                    usedBufferViews[attr.BufferViewIndex.Value] = true;
                }

                blockAllocations.Add(allocation);
            }

            var createInfo = new MgOptimizedStorageCreateInfo
            {
                Allocations = blockAllocations.ToArray(),
            };

            var meshData = mBuilder.Build(createInfo);

            var metaData = InitializeMetaData(meshData, usedBufferViews, bufferViews, accessors);

            // copy buffer data into device memory
            CopyBuffersInto(meshData, buffers, bufferViews, accessors);

            return(meshData);
        }