Top Related Projects
JavaScript 3D Library.
Babylon.js is a powerful, beautiful, simple, and open game and rendering engine packed into a friendly JavaScript framework.
JavaScript game engine built on WebGL, WebGPU, WebXR and glTF
:a: Web framework for building virtual reality experiences.
🇨🇭 A React renderer for Three.js
Easily display interactive 3D models on the web and in AR!
Quick Overview
The glTF Sample Viewer is an open-source project by the Khronos Group that provides a web-based viewer for glTF 3D models. It allows users to load, view, and interact with glTF assets, showcasing various features of the glTF format and demonstrating how to implement a glTF viewer using WebGL.
Pros
- Offers a comprehensive showcase of glTF features and capabilities
- Provides a reference implementation for developers working with glTF
- Supports a wide range of glTF extensions and features
- Regularly updated to reflect the latest glTF specifications
Cons
- May have a steep learning curve for beginners unfamiliar with 3D graphics or WebGL
- Performance can vary depending on the complexity of the loaded models and the user's hardware
- Limited customization options for end-users without modifying the source code
- Requires a modern web browser with WebGL support
Code Examples
// Load a glTF model
const gltf = await viewer.loadModel('path/to/model.gltf');
// Change the environment
viewer.setEnvironment('path/to/environment.hdr');
// Animate the model
viewer.playAnimation(0);
Getting Started
-
Clone the repository:
git clone https://github.com/KhronosGroup/glTF-Sample-Viewer.git
-
Install dependencies:
cd glTF-Sample-Viewer npm install
-
Start the development server:
npm start
-
Open your browser and navigate to
http://localhost:8000
to view the sample viewer.
Competitor Comparisons
JavaScript 3D Library.
Pros of three.js
- More comprehensive 3D library with a wider range of features and capabilities
- Larger community and ecosystem, resulting in more resources, plugins, and third-party support
- Flexible and can be used for various 3D applications beyond glTF rendering
Cons of three.js
- Steeper learning curve due to its extensive feature set
- Larger file size and potentially higher performance overhead for simpler projects
- Less specialized for glTF rendering compared to glTF-Sample-Viewer
Code Comparison
three.js:
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
glTF-Sample-Viewer:
const viewer = new GltfView();
const canvas = document.getElementById('canvas');
viewer.loadGltf('path/to/model.gltf').then(() => {
viewer.setupScene();
});
The code snippets demonstrate that three.js requires more setup for a basic scene, while glTF-Sample-Viewer is more focused on loading and displaying glTF models with less boilerplate code.
Babylon.js is a powerful, beautiful, simple, and open game and rendering engine packed into a friendly JavaScript framework.
Pros of Babylon.js
- Full-featured 3D engine with extensive capabilities beyond glTF rendering
- Active community and regular updates
- Comprehensive documentation and tutorials
Cons of Babylon.js
- Larger file size and potentially higher learning curve
- May be overkill for simple glTF viewing tasks
Code Comparison
glTF-Sample-Viewer:
const viewer = new Viewer({
canvas: document.getElementById('canvas'),
modelIndex: 0
});
viewer.loadModel();
Babylon.js:
const engine = new BABYLON.Engine(canvas);
const scene = new BABYLON.Scene(engine);
BABYLON.SceneLoader.Append("path/to/model/", "model.gltf", scene, function (scene) {
scene.createDefaultCameraOrLight(true, true, true);
});
The glTF-Sample-Viewer provides a more straightforward API for loading and viewing glTF models, while Babylon.js offers a more comprehensive scene setup with additional features and flexibility.
glTF-Sample-Viewer is specifically designed for viewing and testing glTF models, making it ideal for quick previews and validations. Babylon.js, on the other hand, is a full 3D engine that can handle complex scenes, animations, and interactions, making it suitable for more advanced 3D applications and games.
JavaScript game engine built on WebGL, WebGPU, WebXR and glTF
Pros of PlayCanvas Engine
- Full-featured game engine with comprehensive 3D capabilities
- Supports multiple platforms including web, mobile, and desktop
- Active development and community support
Cons of PlayCanvas Engine
- Larger learning curve due to more complex API
- Heavier footprint, may not be suitable for simple 3D viewing tasks
- Less focused on glTF specifics compared to glTF-Sample-Viewer
Code Comparison
glTF-Sample-Viewer:
const viewer = new GltfViewer(canvas, options);
viewer.loadModel(gltfUrl);
viewer.render();
PlayCanvas Engine:
const app = new pc.Application(canvas);
app.start();
const entity = new pc.Entity();
entity.addComponent('model', { type: 'asset', asset: gltfAsset });
app.root.addChild(entity);
Summary
PlayCanvas Engine is a comprehensive game engine offering more features and platform support, while glTF-Sample-Viewer is focused specifically on glTF model viewing. PlayCanvas has a steeper learning curve but provides more flexibility for complex 3D applications. glTF-Sample-Viewer is simpler to use for basic glTF rendering tasks. The code comparison shows PlayCanvas requires more setup but offers greater control over the 3D environment.
:a: Web framework for building virtual reality experiences.
Pros of A-Frame
- More comprehensive framework for building VR experiences
- Easier to use for beginners with declarative HTML syntax
- Larger community and ecosystem of components
Cons of A-Frame
- Heavier and potentially slower for simple 3D model viewing
- Less focused on glTF specifics and advanced rendering features
- May have a steeper learning curve for experienced 3D developers
Code Comparison
A-Frame example:
<a-scene>
<a-entity gltf-model="url(path/to/model.gltf)"></a-entity>
</a-scene>
glTF Sample Viewer example:
const viewer = new Viewer({
canvas: document.getElementById('canvas'),
modelFile: 'path/to/model.gltf'
});
A-Frame provides a higher-level abstraction with HTML-like syntax, while the glTF Sample Viewer offers more direct control over the rendering process. A-Frame is better suited for building complete VR experiences, whereas the glTF Sample Viewer is more focused on showcasing and testing glTF models with advanced rendering options.
🇨🇭 A React renderer for Three.js
Pros of react-three-fiber
- Integrates seamlessly with React, allowing for declarative 3D scene creation
- Provides a more flexible and customizable environment for building complex 3D applications
- Offers a larger ecosystem of compatible libraries and tools
Cons of react-three-fiber
- Steeper learning curve for developers not familiar with React or Three.js
- May have higher performance overhead due to React's reconciliation process
- Less focused on glTF specifics compared to glTF-Sample-Viewer
Code Comparison
glTF-Sample-Viewer:
const viewer = new GltfView();
const scene = await viewer.createScene(gltf);
viewer.renderFrame();
react-three-fiber:
function Scene() {
return (
<Canvas>
<mesh>
<boxGeometry />
<meshStandardMaterial />
</mesh>
</Canvas>
);
}
The glTF-Sample-Viewer code demonstrates a more straightforward approach to loading and rendering glTF models, while react-three-fiber showcases its integration with React components for creating 3D scenes.
Easily display interactive 3D models on the web and in AR!
Pros of model-viewer
- Easier to use for web developers, with a simple HTML custom element
- Built-in AR support for mobile devices
- More extensive documentation and examples for quick implementation
Cons of model-viewer
- Less flexible for advanced customization compared to glTF-Sample-Viewer
- Limited to glTF format, while glTF-Sample-Viewer supports multiple file types
- Smaller community and fewer contributors than the Khronos Group project
Code Comparison
model-viewer:
<model-viewer src="path/to/model.glb"
alt="A 3D model"
auto-rotate
camera-controls>
</model-viewer>
glTF-Sample-Viewer:
const viewer = new GltfView();
const scene = await viewer.loadScene('path/to/model.gltf');
viewer.createCamera();
viewer.createControls();
viewer.renderFrame();
The model-viewer example shows a simpler implementation with an HTML custom element, while the glTF-Sample-Viewer requires more JavaScript setup but offers greater control over the rendering process.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
glTF Sample Viewer Web App
This is the official Khronos glTF 2.0 Sample Viewer using WebGL: glTF 2.0 Sample Viewer
Viewer
Link to the live glTF 2.0 Sample Viewer.
Usage
Controls
click + drag
: Rotate model
scroll
: Zoom camera
GUI
: Use to change models and settings
Change glTF model
- Choose one of the glTF models in the selection list
- Drag and drop glTF files into viewer
Change the environment map
- Drag and drop a .hdr panorama file
Setup
For local usage and debugging, please follow these instructions:
-
Checkout the
main
branch -
Pull the submodule for the required glTF-Sample-Renderer
git submodule update --init --recursive
-
Build the web app
- run
npm install
- start a demo in the browser with
npm run dev
, and open http://localhost:8000.
- run
When making changes, the project is automatically rebuilt and the ./dist
directory is populated with the web app. This directory contains all files necessary for deployment to a webserver.
Debugging
- Requirements
- Install the Debugger for Chrome or Debugger for Firefox extension for Visual Studio Code
- Open the project directory in Visual Studio Code and select
Debug->Add Configuration->Chrome
orDebug->Add Configuration->Firefox
so the.vscode/launch.json
file is created. - For chrome: Append
/dist
to${workspaceFolder}
in thelaunch.json
file Debug->Start Debugging
should now launch a Chrome or Firefox window with the sample viewer and VS Code breakpoints should be hit.
Known Issues
npm install / npm run dev give the following warnings:
The following warning comes from a thirdparty and does not affect sample viewer since the mentioned line 179 is never executed.
(!) "this" has been rewritten to "undefined"
https://rollupjs.org/troubleshooting/#error-this-is-undefined
node_modules/iobuffer/lib-esm/text-encoding-polyfill.js
177: : typeof self !== 'undefined'
178: ? self
179: : this);
^
180: //# sourceMappingURL=text-encoding-polyfill.js.map
The following warning is caused by an old bulma version, which buefy-next currently depends on. This should be fixed in an upcoming release: https://github.com/ntohq/buefy-next/issues/208
[0] [build] DEPRECATION WARNING: Sass's behavior for declarations that appear after nested
[0] rules will be changing to match the behavior specified by CSS in an upcoming
[0] version. To keep the existing behavior, move the declaration above the nested
[0] rule. To opt into the new behavior, wrap the declaration in `& {}`.
[0]
[0] More info: https://sass-lang.com/d/mixed-decls
[0]
[0] â·
[0] 51 â â &:not(.is-rounded)
[0] 52 â â border-radius: $radius-small
[0] â ââââ nested rule
[0] 53 â font-size: $size-small
[0] â ^^^^^^^^^^^^^^^^^^^^^^ declaration
[0] âµ
[0] node_modules\bulma\sass\elements\button.sass 53:3 button-small()
[0] node_modules\bulma\sass\elements\button.sass 252:5 @import
[0] node_modules\bulma\sass\elements\_all.sass 5:9 @import
[0] node_modules\bulma\bulma.sass 5:9 @import
[0] stdin 60:9 root stylesheet
The following warnings stem from the rollup copy plugin, which is only used for development to copy files to the dist folder.
npm WARN deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm WARN deprecated source-map-resolve@0.6.0: See https://github.com/lydell/source-map-resolve#deprecated
npm WARN deprecated rimraf@2.7.1: Rimraf versions prior to v4 are no longer supported
npm WARN deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
npm WARN deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
npm WARN deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
npm WARN deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
Top Related Projects
JavaScript 3D Library.
Babylon.js is a powerful, beautiful, simple, and open game and rendering engine packed into a friendly JavaScript framework.
JavaScript game engine built on WebGL, WebGPU, WebXR and glTF
:a: Web framework for building virtual reality experiences.
🇨🇭 A React renderer for Three.js
Easily display interactive 3D models on the web and in AR!
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot