TerraPrinter4,379 models built in last 24 hours
Sign in
Make your own

three.js · GLB

Real places, ready for three.js

This is Paris, live in your browser: a GLB from TerraPrinter, loaded by three.js as it is. Turn it, switch its layers on and off or change their colours, and tap the map to read its GPS position.

Or drop a GLB on the map. It's read in your browser and never uploaded.

Loading Paris
Layers from the file

    Tap the map to read its position

    Drag to turn · scroll or pinch to zoom

    What's in the file

    Everything above comes from the GLB itself. Nothing about Paris is written into this page.

    A part for every layer

    Each map layer is its own named mesh in its own colour: Terrain, Buildings, Water, Roads, Trees and the rest. The switches and colours above find them by name.

    const trees = model.getObjectByName('Trees');
    trees.visible = false;

    Upright, in metres

    Y is up and north is −Z, as three.js expects. The model comes at its printed size, 0.2 units across, and one line makes it as big as the real place. Try Real size above.

    const k = info.groundMetresPerUnit;
    root.scale.set(k, k / info.verticalExaggeration, k);

    GPS on the model

    The pins were placed from their longitude and latitude, and tapping the map works the other way round. Longitude and latitude are spread evenly across the map's box, with north towards −Z.

    const x = m.xWest + (lon - b.west) / (b.east - b.west) * (m.xEast - m.xWest);
    const z = m.zNorth + (b.north - lat) / (b.north - b.south) * (m.zSouth - m.zNorth);

    Where it is

    The place, its scale and the vertical exaggeration travel in the file, in the root's userData. This is this Paris:

    Loading the file…

    The whole page

    The guide's complete three.js page: a scene, two lights, a camera you can turn, and the model. Save it next to your GLB and open it through any local web server.

    <!doctype html>
    <html>
    <body style="margin: 0">
    <script type="importmap">
    { "imports": {
        "three": "https://cdn.jsdelivr.net/npm/three@0.183.1/build/three.module.js",
        "three/addons/": "https://cdn.jsdelivr.net/npm/three@0.183.1/examples/jsm/"
    } }
    </script>
    <script type="module">
    import * as THREE from 'three';
    import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
    import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
    
    const renderer = new THREE.WebGLRenderer({ antialias: true });
    renderer.setPixelRatio(devicePixelRatio);
    renderer.setSize(innerWidth, innerHeight);
    document.body.appendChild(renderer.domElement);
    
    const scene = new THREE.Scene();
    scene.background = new THREE.Color('#1b1f24');
    scene.add(new THREE.HemisphereLight(0xffffff, 0x445566, 1.5));
    const sun = new THREE.DirectionalLight(0xffffff, 2.5);
    sun.position.set(-1, 2, 1);
    scene.add(sun);
    
    // The model is at its printed size: a 200 mm print is 0.2 units across.
    const camera = new THREE.PerspectiveCamera(40, innerWidth / innerHeight, 0.001, 100);
    camera.position.set(0.2, 0.2, 0.25);
    const controls = new OrbitControls(camera, renderer.domElement);
    controls.target.set(0, 0.01, 0);
    
    const gltf = await new GLTFLoader().loadAsync('paris-terraprinter.com.glb');
    scene.add(gltf.scene);
    
    renderer.setAnimationLoop(() => {
        controls.update();
        renderer.render(scene, camera);
    });
    </script>
    </body>
    </html>

    From 65 MB to 4.3 MB

    This Paris comes out of TerraPrinter at 65 MB, most of it trees. glTF Transform shrinks it to a sixth without losing a single part or name, and gzip on the server halves that again.

    65 MBthe GLB from TerraPrinter
    10.5 MBafter weld and meshopt
    4.3 MBgzipped, what this page downloads
    npm install --global @gltf-transform/cli
    gltf-transform weld paris.glb paris-welded.glb
    gltf-transform meshopt paris-welded.glb paris-small.glb

    The loader then needs the decoder that comes with three.js:

    import { MeshoptDecoder } from 'three/addons/libs/meshopt_decoder.module.js';
    
    const loader = new GLTFLoader();
    loader.setMeshoptDecoder(MeshoptDecoder);
    const gltf = await loader.loadAsync('output.glb');

    Your place next

    Any place on Earth, the Moon or Mars, as a GLB like this one. Free, with no account, and free for any use, games and apps included.

    Download the compressed file this page uses (10.5 MB, meshopt: three.js needs the decoder above) · How to use a real 3D map in three.js

    Map data © OpenStreetMap contributors (ODbL). Elevation: Copernicus DEM GLO-30 (© DLR e.V. & Airbus) and Mapzen Terrain Tiles.