mirror of
https://github.com/storytold/spark.git
synced 2026-10-17 00:12:59 +00:00
Initial commit
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Forge • Multiple Splats</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
a,
|
||||
footer {
|
||||
color: #797979
|
||||
}
|
||||
|
||||
footer {
|
||||
position: absolute;
|
||||
margin: 10px;
|
||||
bottom: 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<footer>
|
||||
<div>Food scans by <a href="https://x.com/tipatat">Tipatat</a></div>
|
||||
</footer>
|
||||
<script type="importmap">
|
||||
{
|
||||
"imports": {
|
||||
"three": "/examples/js/vendor/three/build/three.module.js",
|
||||
"three/addons/": "/examples/js/vendor/three/examples/jsm/",
|
||||
"@forge-gfx/forge": "/dist/forge.module.js"
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<script type="module">
|
||||
import * as THREE from "three";
|
||||
import { SplatMesh } from "@forge-gfx/forge";
|
||||
import { EXRLoader } from "three/addons/loaders/EXRLoader.js";
|
||||
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
|
||||
import { getAssetFileURL } from "/examples/js/get-asset-url.js";
|
||||
import { FOOD_ASSETS } from "/examples/interactivity/food.js";
|
||||
|
||||
const scene = new THREE.Scene();
|
||||
const camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 0.1, 1000);
|
||||
camera.position.set(0, 0, 6.5);
|
||||
camera.lookAt(0, 0, 0);
|
||||
|
||||
const renderer = new THREE.WebGLRenderer();
|
||||
renderer.setSize(window.innerWidth, window.innerHeight);
|
||||
renderer.setClearColor(new THREE.Color(0xFFFFFF), 1);
|
||||
document.body.appendChild(renderer.domElement)
|
||||
|
||||
// add food
|
||||
const foods = [];
|
||||
for (let i = 0; i < FOOD_ASSETS.length; i++) {
|
||||
let splatURL = await getAssetFileURL(FOOD_ASSETS[i].file);
|
||||
const splat = new SplatMesh({ url: splatURL });
|
||||
splat.quaternion.set(1, 0, 0, 0);
|
||||
splat.scale.setScalar(FOOD_ASSETS[i].scale);
|
||||
scene.add(splat);
|
||||
foods.push(splat);
|
||||
}
|
||||
|
||||
// add food master
|
||||
let splatURL = await getAssetFileURL("cat.spz");
|
||||
const master = new SplatMesh({ url: splatURL });
|
||||
master.quaternion.set(1, 0, 0, 0);
|
||||
master.scale.setScalar(0.5);
|
||||
scene.add(master);
|
||||
|
||||
// Setup mouse controls to orbit the camera around
|
||||
const controls = new OrbitControls(camera, renderer.domElement);
|
||||
controls.target.set(0, 0, 0);
|
||||
controls.minDistance = 0.3;
|
||||
controls.maxDistance = 20;
|
||||
controls.update();
|
||||
|
||||
const RADIUS = 2;
|
||||
|
||||
renderer.setAnimationLoop(function animate(time) {
|
||||
controls.update();
|
||||
|
||||
// Rotate food
|
||||
for (let i = 0; i < foods.length; i++) {
|
||||
const ang = (-time / 10000) + i / FOOD_ASSETS.length * Math.PI * 2;
|
||||
foods[i].position.set(Math.cos(ang) * RADIUS, Math.sin(ang) * RADIUS - 0.2, 0);
|
||||
foods[i].rotation.y = i + time / 4000;
|
||||
}
|
||||
|
||||
// Animate food master
|
||||
master.position.y = -0.8 + Math.sin(time / 1000) * 0.1;
|
||||
|
||||
renderer.render(scene, camera);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user