JSFiddle - React, Tailwind, and code Playground
HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="style.css" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>gsplat.js - Viewer Demo</title>
</head>
<body>
<canvas id="canvas"></canvas>
<script src="index.js" type="module"></script>
</body>
</html>
CSS
body,
html {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #000;
}
canvas {
width: 100vw;
height: 100vh;
}
JavaScript
import * as SPLAT from "https://cdn.jsdelivr.net/npm/gsplat@latest";
const canvas = document.getElementById("canvas");
const renderer = new SPLAT.WebGLRenderer(canvas);
const scene = new SPLAT.Scene();
const camera = new SPLAT.Camera();
const controls = new SPLAT.OrbitControls(camera, canvas);
async function main() {
const url = "https://huggingface.co/datasets/dylanebert/3dgs/resolve/main/bonsai/bonsai-7k.splat";
await SPLAT.Loader.LoadAsync(url, scene, null);
const handleResize = () => {
renderer.setSize(window.innerWidth, window.innerHeight);
};
const frame = () => {
controls.update();
renderer.render(scene, camera);
requestAnimationFrame(frame);
};
handleResize();
window.addEventListener("resize", handleResize);
requestAnimationFrame(frame);
}
main();