Purpose
With WebGL, 3D formats can be displayed interactively in the browser control and thus directly on SAP screens.

In this example we will visualize a 3D model using three.js and WebGL.

Solution
- Choose an eligible visualization library (three.js)
- Embed an HTML control or WebView with this library
- Load the 3D model and display it interactively in the browser

The result is an interactive presentation of a 3D model directly on the SAP screen:


Live Demo

Implementation:

The 3D data must be available in a suitable format. In this example we use GLB (GL Transmission Format Binary), a compact, self-contained 3D format widely supported by CAD tools and 3D editors. The model files are served from a web server, since JavaScript cannot access the local file system directly.

An HTML file loads the three.js library and renders the 3D model in an interactive viewport. When embedded via a GuiXT WebView or browser control, the material number (or any other key) can be passed as a URL parameter so the correct model is loaded automatically.

GuiXT Script

The GuiXT script creates a box for the 3D view, builds the URL pointing to the HTML viewer, and embeds it using the browser control. The material number is appended as a URL parameter so the viewer can load the correct model automatically.


GuiXT
WebView (0.1,65) (18,130.3) "C:\Users\<user>\Desktop\Three\threejs_demo.html" _
    name="web"
Simple Three.js Viewer

The simplest possible three.js setup loads a single GLB model and lets the user orbit around it with the mouse. The entire implementation fits in one self-contained HTML file with no external scripts beyond the three.js CDN.

Live Demo
Download threejs_simple_demo.zip

The import map at the top of the file makes three.js and its add-ons available as ES module imports without any build step:

HTML
<script type="importmap">
{
  "imports": {
    "three": "https://cdn.jsdelivr.net/npm/three@0.164.1/build/three.module.js",
    "three/addons/": "https://cdn.jsdelivr.net/npm/three@0.164.1/examples/jsm/"
  }
}
</script>

The viewer script creates a renderer, scene, camera and orbit controls, loads the GLB model and runs the render loop. controls.update() is called every frame so the damping on the orbit animation works smoothly:

JavaScript
import * as THREE from 'three';
import { OrbitControls }
    from 'three/addons/controls/OrbitControls.js';
import { GLTFLoader }
    from 'three/addons/loaders/GLTFLoader.js';
import { EXRLoader }
    from 'three/addons/loaders/EXRLoader.js';

// Renderer – antialiased, tone mapped, fills the full window
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.4;
renderer.outputColorSpace = THREE.SRGBColorSpace;
document.body.appendChild(renderer.domElement);

const scene = new THREE.Scene();

// Perspective camera positioned in front of the model
const camera = new THREE.PerspectiveCamera(
    50, window.innerWidth / window.innerHeight, 0.01, 1000);
camera.position.set(0, 0.1, 0.3);

// Orbit controls – drag to orbit, scroll to zoom
const controls = new OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;

// Lighting: ambient fill + key light
scene.add(new THREE.AmbientLight(0xffffff, 1.5));
const key = new THREE.DirectionalLight(0xffffff, 3);
key.position.set(5, 8, 5);
scene.add(key);

// HDRI as both background and environment map
new EXRLoader().load('mirrored_hall_4k.exr', (texture) => {
    texture.mapping   = THREE.EquirectangularReflectionMapping;
    scene.environment = texture;
    scene.background  = texture;
});

// Load the GLB model and add it to the scene
new GLTFLoader().load('hand_watch__free_model.glb', (gltf) => {
    scene.add(gltf.scene);
});

// Keep renderer and camera in sync on resize
window.addEventListener('resize', () => {
    renderer.setSize(window.innerWidth, window.innerHeight);
    camera.aspect = window.innerWidth / window.innerHeight;
    camera.updateProjectionMatrix();
});

// Render loop
(function loop() {
    requestAnimationFrame(loop);
    controls.update();
    renderer.render(scene, camera);
})();
Three.js Disassembly Demo

The viewer is built as a modular three.js application. three.js and its add-ons are loaded directly from a CDN via an import map in threejs_demo.html, so no build step or local installation is required.

Live Demo
Download threejs_disassembly_demo.zip

HTML
<script type="importmap">
{
  "imports": {
    "three": "https://cdn.jsdelivr.net/npm/three@0.164.1/build/three.module.js",
    "three/addons/": "https://cdn.jsdelivr.net/npm/three@0.164.1/examples/jsm/"
  }
}
</script>

The application is split across four JavaScript modules. Third-party model attributions are listed in CREDITS.txt.

scene.js – Renderer, Camera, Lighting and Environment
This module sets up the core three.js infrastructure and exports it so all other modules can share a single renderer, scene graph and camera. A WebGLRenderer is attached to the canvas element, sized to fill the full window, and a pixel ratio cap of 2 prevents excessive load on high-DPI displays. A PerspectiveCamera with a 50° field of view is placed at a distance that frames the model comfortably. OrbitControls with damping enabled gives the user smooth mouse-driven orbit, pan and zoom. Two lights are added: a soft ambient fill and a stronger directional key light from above. Finally an EXR panorama is loaded as both the scene background and the environment map, so all PBR materials receive correct reflections automatically:

JavaScript
import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { EXRLoader }     from 'three/addons/loaders/EXRLoader.js';

const canvas = document.getElementById('c');

// Renderer – antialiased, fills the viewport
export const renderer = new THREE.WebGLRenderer({ canvas, antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));

// Scene graph and camera
export const scene  = new THREE.Scene();
export const camera = new THREE.PerspectiveCamera(
    50, window.innerWidth / window.innerHeight, 0.01, 1000);
camera.position.set(4, 3, 5);

// Orbit controls with smooth damping
export const controls = new OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;

// Lighting: soft ambient fill + directional key light
scene.add(new THREE.AmbientLight(0xffffff, 0.8));
const key = new THREE.DirectionalLight(0xffffff, 2);
key.position.set(5, 8, 5);
scene.add(key);

// HDRI environment map for realistic reflections and background
new EXRLoader().load('mirrored_hall_4k.exr', (texture) => {
    texture.mapping   = THREE.EquirectangularReflectionMapping;
    scene.environment = texture;   // used by all PBR materials for reflections
    scene.background  = texture;   // also rendered as the visible background
});

// Keep camera and renderer in sync when the window is resized
window.addEventListener('resize', () => {
    renderer.setSize(window.innerWidth, window.innerHeight);
    camera.aspect = window.innerWidth / window.innerHeight;
    camera.updateProjectionMatrix();
});

materials.js – PBR Material Definitions
This module defines the three physically-based materials used by the table model: a metal material for screws, a wood material for structural parts, and a plastic material for the leg stops. Each material uses a set of 4K texture maps loaded via TextureLoader. The map (diffuse/albedo) provides base colour, normalMap adds surface micro-detail without extra geometry, roughnessMap controls how sharp or blurry reflections are per-texel, metalnessMap marks which areas are conductive metal, and aoMap (ambient occlusion) darkens crevices for added depth. All three materials are exported so sceneState.js can assign them when loading GLB parts:

JavaScript
import * as THREE from 'three';

const T = new THREE.TextureLoader();

// Metal material – used for screws and cylindrical connectors
export const ScrewMat = new THREE.MeshStandardMaterial({
    map:           T.load('TableBlend/Metal/diff_4k.jpg'),
    normalMap:     T.load('TableBlend/Metal/nor_gl_4k.jpg'),
    normalMapType: THREE.TangentSpaceNormalMap,
    roughnessMap:  T.load('TableBlend/Metal/rough_4k.jpg'),
    metalnessMap:  T.load('TableBlend/Metal/metal_4k.jpg'),
    roughness: 1.0, metalness: 1.0,
});

// Wood material – used for the table top and legs
export const WoodMat = new THREE.MeshStandardMaterial({
    map:            T.load('TableBlend/WoodTableMat/diff_4k.jpg'),
    normalMap:      T.load('TableBlend/WoodTableMat/nor_gl_4k.jpg'),
    normalMapType:  THREE.TangentSpaceNormalMap,
    roughnessMap:   T.load('TableBlend/WoodTableMat/rough_4k.jpg'),
    aoMap:          T.load('TableBlend/WoodTableMat/ao_4k.jpg'),
    aoMapIntensity: 1.0, roughness: 1.0, metalness: 0.0,
});

// Plastic material – used for the leg stop caps
export const PlasticMat = new THREE.MeshStandardMaterial({
    map:           T.load('TableBlend/Plastic/diff_4k.jpg'),
    normalMap:     T.load('TableBlend/Plastic/nor_gl_4k.jpg'),
    normalMapType: THREE.TangentSpaceNormalMap,
    roughnessMap:  T.load('TableBlend/Plastic/rough_4k.jpg'),
    roughness: 1.0, metalness: 0.0,
});

sceneState.js – Model Loading and Scene State
This module manages which model is currently displayed and holds the shared animation state. The ctx object is the single source of truth: it tracks the current screen (0 = table, 1 = watch), how many GLB parts have finished loading, the disassembly progress value (0–1), and whether the animation is currently running. Because the object is exported by reference, every module that imports it always sees the latest values.

sceneParts maps each screen state to an array of [path, material, yOffset] tuples. The yOffset is how far upward (in world units) that part moves when the model is fully disassembled, giving each piece its own vertical layer in the exploded view.

loadState(s) first calls clearScene() to remove all existing models and reset the state, then loads each GLB file with GLTFLoader. Once a file has loaded, the mesh material is replaced with the corresponding PBR material from materials.js, the mesh is registered in clickableMeshes so the raycaster can detect clicks on it, and the part is added to the scene. When all parts for the current screen have loaded, each part's resting Y position is recorded in originY so the animation always returns to the correct baseline:

JavaScript
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { scene }                         from './scene.js';
import { ScrewMat, WoodMat, PlasticMat } from './materials.js';

const loader = new GLTFLoader();

// Shared state object – all modules import this by reference
export const ctx = {
    screen_state: 0,     // which model is active (0 = table, 1 = watch)
    loadCount:    0,     // how many GLB parts have finished loading
    progress:     0,     // disassembly animation progress 0→1
    disassembled: false, // whether the model is currently in the exploded state
    animating:    false, // whether the animation loop should advance progress
};

export const loadedParts     = [];  // { model, yOff, originY } per loaded part
export const clickableMeshes = [];  // flat list of meshes the raycaster tests

// Part list per screen: [GLB path, PBR material, Y-offset in exploded view]
export const sceneParts = {
    0: [
        ['TableBlend/PlateSmooth.glb',         WoodMat,     1.6],
        ['TableBlend/ScrewsPlate.glb',         ScrewMat,    1.2],
        ['TableBlend/TablePlateholder.glb',    WoodMat,     0.8],
        ['TableBlend/ScrewCylinder.glb',       ScrewMat,    0.3],
        ['TableBlend/CylinderSmooth.glb',      ScrewMat,   -0.1],
        ['TableBlend/ScrewLegCylinderCon.glb', ScrewMat,   -0.4],
        ['TableBlend/Leg.glb',                 WoodMat,    -0.9],
        ['TableBlend/LegStops.glb',            PlasticMat, -1.3],
        ['TableBlend/ScrewsLegstop.glb',       ScrewMat,   -1.7],
    ],
};

// Remove all models from the scene and reset all state values
export function clearScene() {
    for (const p of loadedParts) scene.remove(p.model);
    loadedParts.length     = 0;
    clickableMeshes.length = 0;
    ctx.loadCount    = 0;
    ctx.progress     = 0;
    ctx.disassembled = false;
    ctx.animating    = false;
}

// Load a scene by its state index, replacing whatever is currently shown
export function loadState(s) {
    clearScene();
    ctx.screen_state = s;
    const parts = sceneParts[s] ?? [];

    switch (s) {
        case 0:
            // Load each table part individually and assign its PBR material
            for (const [path, mat, yOff] of parts) {
                loader.load(path, (gltf) => {
                    const model = gltf.scene;
                    model.scale.setScalar(0.25);
                    model.traverse((child) => {
                        if (child.isMesh) {
                            child.material = mat;
                            clickableMeshes.push(child);
                        }
                    });
                    scene.add(model);
                    loadedParts.push({ model, yOff });
                    ctx.loadCount++;
                    // All parts loaded – save each part's resting Y
                    if (ctx.loadCount === parts.length) {
                        for (const p of loadedParts)
                            p.originY = p.model.position.y;
                    }
                }, undefined, (err) => console.error(err));
            }
            break;

        case 1:
            // Watch model: loaded as a single GLB, no disassembly
            loader.load('hand_watch__free_model.glb', (gltf) => {
                const model = gltf.scene;
                scene.add(model);
                loadedParts.push({ model, yOff: 0 });
                ctx.loadCount++;
            });
            break;
    }
}

raycaster.js – Click-to-Disassemble Interaction
This module wires up the click interaction on the canvas. A Raycaster casts a ray from the camera through the pixel the user clicked and tests it against all meshes in clickableMeshes. To avoid triggering on a drag (orbit) that ends on a mesh, the module tracks whether the pointer moved between pointerdown and pointerup using a boolean flag. A click is only registered on pointerup if the pointer did not move. When a hit is detected and all parts have finished loading, state.disassembled is toggled and state.animating is set to true, which tells the render loop in threejs_demo.html to start advancing the progress value. The info text at the top of the viewport is also updated to reflect the current state:

JavaScript
import * as THREE from 'three';

export function initRaycaster(canvas, camera, refs, state) {
    const raycaster = new THREE.Raycaster();
    const pointer   = new THREE.Vector2();
    let pointerMoved = false;

    // Track whether the pointer moved so drags do not count as clicks
    canvas.addEventListener('pointerdown', () => { pointerMoved = false; });
    canvas.addEventListener('pointermove', () => { pointerMoved = true;  });

    canvas.addEventListener('pointerup', (e) => {
        if (pointerMoved) return;  // ignore drag-end events

        // Convert pixel coordinates to normalised device coordinates (-1 to +1)
        pointer.x =  (e.clientX / window.innerWidth)  * 2 - 1;
        pointer.y = -(e.clientY / window.innerHeight)  * 2 + 1;

        raycaster.setFromCamera(pointer, camera);
        const hits = raycaster.intersectObjects(refs.clickableMeshes, false);

        // Only respond if something was hit and all parts have finished loading
        if (hits.length > 0 && refs.loadCount() === refs.expectedCount()) {
            state.disassembled = !state.disassembled;
            state.animating    = true;

            document.getElementById('info').textContent =
            state.disassembled
            ? 'click any part to reassemble · drag to orbit · scroll to zoom'
            : 'click any part to disassemble · drag to orbit · scroll to zoom';
        }
    });
}

threejs_demo.html – Entry Point and Render Loop
The HTML file ties all modules together. After importing the shared state and calling loadState(0) to show the table on startup, it wires the panel buttons so switching between models calls loadState with the new index. It then initialises the raycaster and starts the render loop. The loop calls controls.update() every frame for damping to work, and when ctx.animating is true it advances ctx.progress by a fixed step (assembling or disassembling depending on ctx.disassembled). An ease-in-out curve is applied so the animation starts and ends smoothly rather than at a constant speed. Each part is repositioned by interpolating between originY and originY + yOff using the eased progress value:

HTML
<script type="module">
    import { renderer, scene, camera, controls } from './scene.js';
    import {
        ctx, loadedParts, clickableMeshes, sceneParts, loadState
    } from './sceneState.js';
    import { initRaycaster } from './raycaster.js';

    const SPEED = 0.03;

    // Load the default model (table) on startup
    loadState(ctx.screen_state);

    // Wire panel buttons – each button stores its target state in data-state
    document.querySelectorAll('.panel-btn').forEach(btn => {
        btn.addEventListener('click', () => {
            const s = parseInt(btn.dataset.state);
            if (s === ctx.screen_state) return;
            document.querySelectorAll('.panel-btn')
                .forEach(b => b.classList.remove('active'));
            btn.classList.add('active');
            loadState(s);
        });
    });

    // Initialise click-to-disassemble raycasting
    initRaycaster(document.getElementById('c'), camera, {
        clickableMeshes,
        loadCount:     () => ctx.loadCount,
        expectedCount: () => sceneParts[ctx.screen_state]?.length ?? 0,
    }, ctx);

    // Main render loop
    (function loop() {
        requestAnimationFrame(loop);
        controls.update();  // required for OrbitControls damping

        if (ctx.animating) {
            // Advance progress toward 1 (disassemble) or 0 (reassemble)
            ctx.progress += ctx.disassembled ? SPEED : -SPEED;
            ctx.progress  = Math.max(0, Math.min(1, ctx.progress));

            // Ease-in-out curve so the animation starts and ends smoothly
            const t = ctx.progress < 0.5
                ? 2 * ctx.progress * ctx.progress
                : 1 - Math.pow(-2 * ctx.progress + 2, 2) / 2;

            // Move each part to its exploded or resting position
            for (const p of loadedParts) {
                p.model.position.y = p.originY + p.yOff * t;
            }

            if (ctx.progress === 0 || ctx.progress === 1) ctx.animating = false;
        }

        renderer.render(scene, camera);
    })();
</script>

Components
InputAssistant + Controls