Skip to content

KhronosGroup/glTF-Sample-Renderer

Repository files navigation

Khronos glTF Sample Renderer

This is the official Khronos glTF 2.0 Sample Renderer using WebGL.

Try out the glTF Sample Viewer which uses this renderer in combination with a custom frontend.

Table of Contents

Credits

Developed and refactored by UX3D. Supported by the Khronos Group and by Google for the glTF Draco mesh compression import. Formerly hosted together with the example frontend at the glTF Sample Viewer repository. Original code based on the concluded glTF-WebGL-PBR project. Previously supported by Facebook for animations, skinning and morphing.

Features

API

glTF Sample Renderer is made to be integrated into web applications (see glTF Sample Viewer) or to be used for automated testing (see Render Fidelity Tools).

The API consists of several components that in combination allow flexible configuration of the glTF viewer.

More detailed information about the API is listed in the api documentation.

GltfView

The GltfView component is associated with one WebGL2 context. In practice this means it will be associated with one HTML5 Canvas. This component manages the interaction between the canvas and the GL context. It therefore specifies the viewport, the swapchain and can be used to schedule frame renders.

const view = new GltfView(webGl2Context);

The view is also used to render frames, either on every window repaint event or on demand, e.g. when taking a frame capture.

const update = () =>
{
    view.renderFrame(state, canvas.width, canvas.height);
    window.requestAnimationFrame(update);
};
window.requestAnimationFrame(update);

GltfState

The GltfState encapsulates the state of the content of a GltfView. As currently some WebGL resources are stored directly in the Gltf objects, the state cannot be shared between views.

const state = view.createState();
state.sceneIndex = 0;
state.animationIndices = [0, 1, 2];
state.animationTimer.start();

The state is passed to the view.renderFrame function to specify the content that should be rendered.

ResourceLoader

The ResourceLoader can be used to load external resources and make them available to the renderer.

state.gltf = await resourceLoader.loadGltf("path/to/some.gltf");

Render Fidelity Tools

The glTF Sample Renderer is integrated into Google's render fidelity tools. The render fidelity tools allow the comparison of different renderers. To run the project follow the instructions here and here. For information on how the glTF Sample Renderer was integrated see the pull request on Github.