Exemple #1
0
        public static async Task <IndexedMesh> loadStlAsync(IRenderDevice device, Stream stream, float?minCosAngle, string name)
        {
            int triangles = readStlHeader(stream);

            if (triangles <= 0)
            {
                throw new ArgumentException("Malformed STL file");
            }

            int trianglesPerBatch   = Math.Min(triangles, 1024);
            sMeshIndexerSetup setup = stlIndexerSetup(trianglesPerBatch);

            using (var indexer = device.CreateMeshIndexer(ref setup))
            {
                Func <BoundingBox> fn   = () => loadStlImpl(indexer, stream, triangles, trianglesPerBatch, minCosAngle);
                BoundingBox        bbox = await Task.Run(fn);

                indexer.createMesh(out var vb, out var ib, out var metadata, nameVb(name), nameIb(name));
                return(new IndexedMesh(vb, ib, metadata.countIndices, metadata.indexType, bbox));
            }
        }
Exemple #2
0
        public static IndexedMesh loadStl(IRenderDevice device, Stream stream, float?minCosAngle, string name)
        {
            int triangles = readStlHeader(stream);

            if (triangles <= 0)
            {
                throw new ArgumentException("Malformed STL file");
            }

            // BTW, the default threshold for LOH is about 83kb, or 6.9k Vector3 vertices:
            // https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/large-object-heap

            int trianglesPerBatch   = Math.Min(triangles, 1024);
            sMeshIndexerSetup setup = stlIndexerSetup(trianglesPerBatch);

            using (var indexer = device.CreateMeshIndexer(ref setup))
            {
                BoundingBox bbox = loadStlImpl(indexer, stream, triangles, trianglesPerBatch, minCosAngle);
                indexer.createMesh(out var vb, out var ib, out var metadata, nameVb(name), nameIb(name));
                return(new IndexedMesh(vb, ib, metadata.countIndices, metadata.indexType, bbox));
            }
        }