Babylon.js Viewer (V1)
Display 3D models on your webpage
The Babylon.js viewer is the simplest way to display 3D content on a web page.
To display a 3D model on your web page:
-
Add a script reference to the viewer
<script src="https://cdn.babylonjs.com/viewer/babylon.viewer.js"></script> -
Add a
<babylon>tag and set the model attribute to point to a.gltfor.glbfile<babylon model="model.gltf"></babylon>We recommend using the glTF format (
.gltfor.glb) for displaying 3D models on your webpage. Other formats supported by Babylon.js loaders are also supported by the viewer component, including.babylon,.obj, and.stl.
The Babylon.js viewer automatically provides a default viewing experience for 3D models. All aspects of this experience are configurable. See Configuring the viewer for more information on customizing the viewing experience.
Example
See the Pen Babylon.js Viewer - Display a 3D model by BabylonJS.
Resizing
Controlling the size of the viewer is one of the most common configuration operations. It is fairly easy, as the viewer in default mode fills 100% of the width and height of its container. To control the viewer, you can simply style its enclosing container.
See the Pen Babylon.js Viewer - Resize the viewer by BabylonJS.
Using the viewer in your project
The Babylon.js viewer is available on a CDN as well as an NPM package. The Babylon.js viewer is a wrapper around the Babylon.js engine and follows the same versioning scheme as the engine. The current stable version of the Babylon.js viewer uses the current stable version of the Babylon.js engine, and the preview version of the Babylon.js viewer uses the preview version of the Babylon.js engine.
CDN
Stable versions of the viewer are available on:
- https://cdn.babylonjs.com/viewer/babylon.viewer.js (minified)
- https://cdn.babylonjs.com/viewer/babylon.viewer.max.js
Preview releases (nightlies) of the viewer are available on:
- https://preview.babylonjs.com/viewer/babylon.viewer.js (minified)
- https://preview.babylonjs.com/viewer/babylon.viewer.max.js
NPM
To install the Babylon.js viewer through NPM, use:
npm install --save babylonjs-viewerThis will install the latest stable version of the viewer, including its needed dependencies.
Afterward, it can be imported into the project using:
import "babylonjs-viewer";This will enable the BabylonViewer namespace.
Further reading
Configuring the Babylon.js Viewer
How to configure the Babylon.js viewer.

Babylon.js Viewer Templating System
Using and extending the viewer's simple integrated templating system.

Modify the Babylon.js Viewer
Modifying the Babylon.js viewer using HTML.

Babylon.js Viewer - Advanced usage
Advanced uses of the viewer.

Babylon.js Viewer Examples
Examples of using the viewer

Coming next
Babylon.js Viewer Templating System
Using and extending the viewer's simple integrated templating system.

Modify the Babylon.js Viewer
Modifying the Babylon.js viewer using HTML.

Babylon.js Viewer - Advanced usage
Advanced uses of the viewer.

Babylon.js Viewer Examples
Examples of using the viewer

Configuring the Babylon.js Viewer
How to configure the Babylon.js viewer.
