---
title: Export to glTF
summary: Export a model, or the objects a BQL condition selects, as binary glTF (GLB) for three.js, Blender, game engines and AR viewers; what is in the file, the one-time download URL, several models in one file, and exporting through a versions token.
order: 51
languages: [javascript, java]
terms: [version, vid, bql, versions-token]
see-also: [how-to/models/download-a-model, how-to/auth/create-a-versions-token, how-to/query/run-a-bql-query, explanation/geometry-and-the-viewers]
---

# Export to glTF

BIM.works exports the triangulated geometry it generated for a model as glTF 2.0 in the binary container (GLB), the format three.js, Babylon.js, Blender, Unity, Unreal and most AR viewers read. A [[term:bql|BQL]] condition limits the export to some of the objects.

## Live demo

```demo
name: gltf-export
title: Export, download and inspect a GLB
models: schependomlaan
height: 520
notes: |
  Each export runs on the server and is fetched once. The preview is drawn from the file's own triangles and vertex colours, the panel reads its JSON chunk, and **Save** stores the bytes. **Export** picks the objects; **BQL…** takes a condition of your own. **Through a versions token** does the same export on a second client that has nothing but `geometry:read` on this one model.
```

## Before you start

A client whose credential has the `geometry:read` scope on the version, and the [[term:vid|Vid]] of a processed IFC version. The export uses the geometry BIM.works stored at check-in; a point cloud or a PDF gives an empty file.

## 1. Export

```code-group {#export}
```javascript
const url = await client.geometry3d.downloadGltf([BIM_WORKS_FIRST_MODEL], "type != IFCSPACE");
const glb = await (await fetch(url)).arrayBuffer();
```
```java
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.Set;

try (InputStream glb = client.geometry3d.downloadGltf(Set.of(UUID.fromString(BIM_WORKS_FIRST_MODEL)), false, "type != IFCSPACE")) {
	Files.copy(glb, Paths.get("model.glb"), StandardCopyOption.REPLACE_EXISTING);
}
```
```

The condition is the `WHERE` part of a query, with or without `GET qid WHERE` in front of it: `type = IFCDOOR` and `GET qid WHERE type = IFCDOOR` export the same doors. Leave it out to export every object with geometry, the spaces included, which most viewers then draw as large translucent volumes; `type != IFCSPACE` leaves them out. A condition that selects nothing gives a valid file without meshes. Check a condition with [[page:how-to/query/validate-a-query]] first: one the server cannot run fails the export.

In JavaScript, `downloadGltf` on [[js:@bimworks/jssdk/Geometry3d|Geometry3d]] answers a URL. In Java, `downloadGltf` on [[java:nl.bimbase.bimworks.client.apis.Geometry3dApi|Geometry3dApi]] answers the stream itself and takes one more argument, `onlyOutsideTriangles`: `true` keeps only the triangles on the outside of the model, for a lighter shell. The .NET client has no glTF export.

Over HTTP the operation is [[openapi:ExportGeometry]], which answers the file itself (`model/gltf-binary`) rather than a URL: `models`, the condition as `query`, `only_outside_triangles`, and `colors`, a colour per object (qid → `[r, g, b, a]`, each 0 to 1) instead of the model's own.

```try-it
operation: ExportGeometry
method: POST
path: /openapi/model/ExportGeometry
```

```example
name: export-gltf
code: javascript/export-gltf.js
run: none
notes: Fetches the GLB once and offers it as a file. In Node.js, write the bytes with `fs.writeFile` instead.
```

## 2. Use the download URL once

The URL points at `<instance>/download?identifier=…` and is a capability: it needs no credentials and answers to any origin, so a page can fetch it or a browser can open it. It serves the file **once**; a second request answers 404. Fetch it and keep the bytes, as the examples do, or export again. The `Content-Disposition` header names the file after the model, `<file name>.glb`.

## 3. Know what is in the file

| Part | What |
|---|---|
| Nodes | A root node *Axis Rotation* turns the model's Z-up into glTF's Y-up. Under it, one node per model, named after the model's file, and under each the meshes, scaled by 0.001 because the coordinates are millimetres: a loader that applies the node transforms gets metres, Y up. |
| Meshes | All objects merged into a few meshes, split by transparency (`alphaMode` `OPAQUE` or `BLEND`) and by whether the geometry is two-sided. Triangles are not indexed. |
| Colours | The model's own colours as vertex colours (`COLOR_0`), with a plain material per mesh. |
| Objects | Not separate: the file has no per-object nodes or ids, so it cannot be picked by object. For a viewer that knows the objects, use the 3D viewer ([[page:how-to/viewer3d/embed-the-viewer]]). |

```example
name: export-gltf-every-model
code: javascript/export-gltf-every-model.js
notes: |
  Several versions in one call give one GLB with a node per model, each in its own coordinates, so models that share an origin line up. The file is named after one of the models, not always the first of your list.
```

## 4. Export through a versions token

To let a browser export a model without giving it your credential, mint a [[term:versions-token|versions token]] on your server with `geometry:read` on that version only and hand its `auth` to the page ([[page:how-to/auth/create-a-versions-token]]). The page can export and read the footprint; a query is refused with [[error:NON_AUTHORIZED_SCOPE]].

```example
name: export-gltf-with-a-versions-token
code: javascript/export-gltf-with-a-versions-token.js
run: none
notes: Both halves are in one file here; in an application the first runs on your server and the second in the browser.
```

## In the app

With [[feature:EXPORT_GLTF]], **Export → GLTF...** in a model's menu opens a dialog that exports the loaded, the visible or the selected objects of the 3D viewer, in their original colours or in the colours the viewer gives them now, as a one-time download.

## Check

The file starts with the four bytes `glTF`, and the [Khronos glTF validator](https://github.khronos.org/glTF-Validator/) or a drop into any glTF viewer shows the model standing upright at its real size.
