Product Family

Extract Assets from GLTF via Java

Extract Assets from GLTF using Java library without any 3D modeling software.

How to Extract Assets from GLTF File Using Java

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

Aspose.3D for Java

API which is a feature-rich, powerful and easy to use API for Java platform. You can download its latest version directly from

Aspose Maven Repository

and install it within your Maven-based project by adding the following configurations to the pom.xml.


<name>Aspose Java API</name>


<version>version of aspose-3d API</version>

Steps to Extract Assets from GLTF via Java

Java programmers can easily extract assets from GLTF in just a 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 JAVA is supported on all major operating systems. Just make sure that you have the following prerequisites.

  • Microsoft Windows or a compatible OS with Java Runtime Environment for JSP/JSF Application and Desktop Applications.
  • Get latest version of Aspose.3D for Java directly from Maven.

JAVA code to Extract Assets from GLTF

//Source files that need to extract assets
String file = "template.gltf";

//create an instance of Scene
Scene scene = new Scene(file);

//Create zip files and perform asset extraction on source files
String zipOutput ="";
File newFile=new File(zipOutput);
FileOutputStream output = new FileOutputStream(zipOutput);
Zip za = new Zip(output);

//close stream resource

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

//Create a compressed file processing class
class Zip
    private ZipOutputStream archive;
    private HashSet<String> entries = new HashSet<String>();

    public Zip(OutputStream stream)
        archive = new ZipOutputStream(stream);

    public void Add(String fileName, byte[] content, boolean enableCompression) throws IOException {
        String entryName = PickName(fileName);
        ZipEntry entry = new ZipEntry(entryName);
        archive.write(content, 0, content.length);

    public void closeIo(){
            try {
            } catch (IOException e) {

    private String PickName(String fileName)
        if (!entries.contains(fileName))
            return fileName;
        String arrFile[]=fileName.split(".");
        String baseName = arrFile[0];
        String ext = arrFile[1];
        for (int idx = 2; ; idx++)
            String newName = baseName + "_" + idx;
            if (!StringUtils.isBlank(ext))
                newName += ext;
            if (entries.contains(newName))
            return newName;

//Create an asset extraction processing class
class Extractor
    private Zip zip;
    private boolean texture;
    HashSet<A3DObject> visited = new HashSet<A3DObject>();

    public Extractor(Zip zip,boolean texture)
    { = zip;
        this.texture = texture;

    private boolean CanVisit(A3DObject obj)
        if (visited.contains(obj))
            return false;
        return true;

    public void Extract(Scene scene) throws IOException {
        if (scene.getLibrary() != null && scene.getLibrary().size() > 0)
            for (A3DObject obj:scene.getLibrary())

    private void VisitNode(Node node) throws IOException {
        if (!CanVisit(node))
        if (texture)
            for (Material mat:node.getMaterials())

        for (Entity entity:node.getEntities())
            if (entity instanceof Mesh){
                Save((Mesh)entity, node.getName());

        for (Node child:node.getChildNodes())

    private void VisitMaterial(Material mat) throws IOException {
        if (!CanVisit(mat))
        if (!texture)
        for (TextureSlot tslot: mat)
            if (tslot.getTexture() instanceof Texture)

    private void Visit(A3DObject obj) throws IOException {
        if (texture && obj instanceof Texture)
            else if (obj instanceof Mesh)
            Save((Mesh)obj, null);
            else if (obj instanceof Node)

    private void Save(Mesh mesh, String nodeName) throws IOException {
        if (!CanVisit(mesh))
        Scene scene = new Scene(mesh);
        MemoryStream ms=new MemoryStream();, FileFormat.FBX7400ASCII);
        String name = nodeName;
        if (StringUtils.isBlank(name))
            name = mesh.getName();
        if (StringUtils.isBlank(name))
            name = "mesh";
        String ext = ".fbx";
        zip.Add(name + ext, ms.toArray(), true);

    private void Save(Texture tex) throws IOException {
        if (tex.getContent() == null || !CanVisit(tex))
        String fileName=tex.getFileName();
            String arrFile[]=fileName.split(".");
            fileName = arrFile[0];
        zip.Add(fileName, tex.getContent(), false);
  • Free App to Extract Assets from GLTF

    Extractor GLTF right now by visiting our Live Demos website.The live demo has the following benefits

      No need to download Aspose API.
      No need to write any code.
      Just upload GLTF file and hit the "Extract" button
      You will get the download link.

    Java 3D Scene Manipulation Library

    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.

    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 JAVA, One can also extract assets from many other file formats including.

    3DS (3D Studio Mesh File Format)
    3MF (3D Manufacturing Format)
    AMF (Additive Manufacturing Format)
    ASE (Aseprite Sprite File)
    DAE (Digital Asset Exchange File Format)
    DXF (Autodesk Drawing Exchange File Format)
    DRC (Google Draco)
    FBX (Filmbox Interchange File)
    GLB (Binary GlTF File)
    GLTF (GL Transmission Format)
    JT (JT File Format)
    OBJ (OBJ File Format)
    PLY (Polygon File Format)
    PDF (3D PDF)
    RVM (RVM File Format)
    STL (Stereolithography)
    U3D (Universal 3D File Format)
    VRML (Virtual Reality Modeling Language)
    X (DirectX Model File)
    USD (Universal Scene Description)
    USDZ (Universal Scene Description Zip Archive)