@khronosgroup/gltf-viewer
v1.1.0
Published
The official glTF sample viewer.
Downloads
40
Readme
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
- [x] glTF 2.0
- [x] KHR_animation_pointer
- [x] KHR_draco_mesh_compression
- [x] KHR_lights_punctual
- [x] KHR_materials_clearcoat
- [x] KHR_materials_emissive_strength
- [x] KHR_materials_pbrSpecularGlossiness
- [x] KHR_materials_ior
- [x] KHR_materials_sheen
- [x] KHR_materials_specular
- [x] KHR_materials_transmission
- [x] KHR_materials_unlit
- [x] KHR_materials_variants
- [x] KHR_materials_volume
- [x] KHR_materials_iridescence
- [x] KHR_materials_anisotropy
- [x] KHR_materials_dispersion
- [x] KHR_mesh_quantization
- [x] KHR_texture_basisu
- [x] EXT_texture_webp
- [x] KHR_texture_transform
- [x] KHR_xmp_json_ld
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.