Aspose.3D  for .NET

Extract Assets from GLTF via C#

Build your own .NET apps to Extract Assets from GLTF files using server-side APIs.

How to Extract Assets from GLTF File Using C#

In order to extract assets from GLTF file, we’ll use

Aspose.3D for .NET

API which is a feature-rich, powerful and easy to use API for C# platform to be used with extract assets. Open


package manager, search for Aspose.3D and install. You may also use the following command from the Package Manager Console.

Package Manager Console Command

PM> Install-Package Aspose.3D

Steps to Extract Assets from GLTF via C#

Aspose.3D makes it easy for the developers to extract assets from the GLTF file with just few lines of code.

  • Load GLTF file via the constructor of Scene class
  • Create zip file format object as output file format
  • Create archive class and handle extract asset class
  • Call the Extract method and save the file

System Requirements

Aspose.3D for .NET is supported on all major operating systems. Just make sure that you have the following prerequisites.

  • Microsoft Windows or a compatible OS with .NET Framework, .NET Core, Mono
  • Development environment like Microsoft Visual Studio
  • Aspose.3D for .NET referenced in your project

C# code to Extract Assets from GLTF

//Source files that need to extract assets
string file = "template.gltf";
Scene scene = new Scene(file);  

//The output is in a compressed file format, and Directory represents the name of an existing folder
var zipOutput = Path.Combine("Directory", "");
using var output = new FileStream(zipOutput, FileMode.Create);
using var za = new Zip(output);

//Call the Extract method to perform asset extraction operations

//Callable Extract method,The parameter texture indicates: whether to extract the texture
private void Extract(Scene scene, Zip za,bool texture)
    var extractor = new Extractor(za,texture);

//Create a compressed file processing class
class Zip : IDisposable
    private ZipArchive archive;
    private HashSet<string> entries = new HashSet<string>();

    public Zip(Stream stream)
        archive = new ZipArchive(stream, ZipArchiveMode.Create);
    public void Dispose()

    public void Add(string fileName, byte[] content, bool enableCompression)
        var entryName = PickName(fileName);
        var compressionLevel = enableCompression ? CompressionLevel.Fastest : CompressionLevel.NoCompression;
        var entry = archive.CreateEntry(entryName, compressionLevel);
        using var stream = entry.Open();
        stream.Write(content, 0, content.Length);
    private string PickName(string fileName)
        if (!entries.Contains(fileName))
            return fileName;
        var baseName = Path.GetFileNameWithoutExtension(fileName);
        var ext = Path.GetExtension(fileName);
        for (var idx = 2; ; idx++)
            var newName = baseName + "_" + idx;
            if (!string.IsNullOrEmpty(ext))
                newName += ext;
            if (entries.Contains(newName))
            return newName;

//Create an asset extraction processing class
class Extractor
    private Zip zip;
    private bool texture;
    HashSet<A3DObject> visited = new HashSet<A3DObject>();
    public Extractor(Zip zip,bool texture)
    { = zip;
        this.texture = texture;

    private bool CanVisit(A3DObject obj)
        if (visited.Contains(obj))
            return false;
        return true;
    public void Extract(Scene scene)
        if (scene.Library != null && scene.Library.Count > 0)
            foreach (var obj in scene.Library)
    private void VisitNode(Node node)
        if (!CanVisit(node))
        if (texture)
            foreach (var mat in node.Materials)

        foreach (var entity in node.Entities)
            if (entity is Mesh)
                Save((Mesh)entity, node.Name);
        foreach (var child in node.ChildNodes)
    private void VisitMaterial(Material mat)
        if (!CanVisit(mat))
        if (!texture)
        foreach (var tslot in mat)
            if (tslot.Texture is Texture)
    private void Visit(A3DObject obj)
        if (texture && obj is Texture)
        else if (obj is Mesh)
            Save((Mesh)obj, null);
        else if (obj is Node)
    private void Save(Mesh mesh, string? nodeName)
        if (!CanVisit(mesh))
        Scene scene = new Scene(mesh);
        using (var ms = new MemoryStream())
            scene.Save(ms, FileFormat.FBX7400ASCII);
            var name = nodeName;
            if (string.IsNullOrEmpty(name))
                name = mesh.Name;
            if (string.IsNullOrEmpty(name))
                name = "mesh";
            var ext = ".fbx";
            zip.Add(name + ext, ms.ToArray(), true);
    private void Save(Texture tex)
        if (tex.Content == null || !CanVisit(tex))
        var fileName = tex.FileName != null ? Path.GetFileName(tex.FileName) : null;
        zip.Add(fileName, tex.Content, false);
  • About Aspose.3D for .NET API

    Aspose.3D is a CAD and Gameware API to load, modify and convert 3D files. API is a standalone and does not require any any 3D modeling or rendering software. One can easily use API for Discreet3DS, WavefrontOBJ, STL (ASCII, Binary), Universal3D, FBX (ASCII, Binary), Collada, glTF, PLY, GLB, DirectX and more formats.

    Free App to Extract Assets from GLTF

    Check our live demos to Extractor GLTF with following benefits.

      No need to download or setup anything
      No need to write or compile code
      Just upload GLTF file and hit the "Extract" button
      Download GLTF file from the link, if required

    GLTF What is GLTF File Format?

    glTF (GL Transmission Format) is a 3D file format that stores 3D model information in JSON format. The use of JSON minimizes both the size of 3D assets and the runtime processing needed to unpack and use those assets. It was adopted for the efficient transmission and loading of 3D scenes and models by applications.

    Read More

    Other Supported App to Extract Assets from Formats

    Using C#, One can also extract assets from many other file formats including.

    3MF (3D Manufacturing Format)
    AMF (Additive Manufacturing Format)
    ASE (2D Animation File)
    DAE (Digital Asset Exchange)
    DXF (Drawing Interchange Format)
    DRC (Google Draco)
    FBX (3D Format)
    GLB (3D File Binary Representation)
    3DS (3D Studio Mesh File Format)
    JT (Jupiter Tessellation File)
    OBJ (3D File Format)
    PLY (Polygon File Format)
    PDF (3D PDF)
    RVM (AVEVA Plant Design Model)
    STL (Interchangeable 3D Surface Geometry)
    U3D (Universal 3D)
    VRML (Virtual Reality Modeling Language)
    X (DirectX Model Image)
    USD (Universal Scene Description)
    USDZ (Universal Scene Description Zip Archive)