glTF provides a practical format for transmitting and loading 3D scenes and models. Its binary bundle form uses the .glb extension. section 15.2
Use the format through a component when you want to avoid handling the underlying 3D complexity directly:
- Point a model-viewer element at an Astronaut.glb file to load and display a 3D model. section 15.2
- Add auto-rotate or controls to make the displayed model rotate automatically or respond to dragging. section 15.2
Minimal model preview
Load the component script, size the element, and provide the binary model: <model-viewer src="Astronaut.glb" controls></model-viewer>. The component handles unpacking and parsing the 3D format before rendering it. section 15.2
Listing 15.3. A model-viewer component demo
<html>
<head>
<script src="model-viewer.js"></script> #1
<title>Simple Demo for Model Viewer</title>
<style>
body {
margin: 0;
}
model-viewer { #2
width: 100vw;
height: 100vh;
}
</style>
</head>
<body>
<model-viewer src="Astronaut.glb"></model-viewer> #3
</body>
</html>
Browse the complete minimal HTML example for loading an Astronaut.glb model with model-viewer. section 15.2
