-
Notifications
You must be signed in to change notification settings - Fork 0
/
index-jsm.html
91 lines (75 loc) · 3.17 KB
/
index-jsm.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Volograms-js demo - with module</title>
<style>
body { margin: 0; }
#gui{
position: absolute;
color: white;
text-align: center;
width: 100%;
user-select: none;
}
</style>
</head>
<body>
<!-- Import maps polyfill -->
<!-- Remove this when import maps will be widely supported -->
<script async src="https://unpkg.com/es-module-shims@1.3.6/dist/es-module-shims.js"></script>
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.148.0/build/three.module.js"
}
}
</script>
<script type="module">
import * as THREE from 'three'
import {OrbitControls} from 'https://cdn.jsdelivr.net/npm/three@0.148.0/examples/jsm/controls/OrbitControls.js'
import {Vologram} from 'https://cdn.jsdelivr.net/npm/volograms-js@latest/src/Vologram.js' //replace latest with version eg 0.1.116 for production usage
// if package not yet published on npm :
// import {Vologram} from 'https://rawcdn.githack.com/remmel/volograms-js/9e3267899a5172d5af0a66ab06b575da06ea4ec7/src/Vologram.js'
// Skypack can also be used instead of all code above, but
// three version in https://cdn.skypack.dev/three must match three version in https://cdn.skypack.dev/volograms-js
// import * as THREE from 'https://cdn.skypack.dev/three@0.148.0'
// import {OrbitControls} from 'https://cdn.skypack.dev/three@0.148.0/examples/jsm/controls/OrbitControls.js'
// import {Vologram} from 'https://cdn.skypack.dev/volograms-js'
// setup render, scene, light, orbitcontrol
const renderer = new THREE.WebGLRenderer()
renderer.setSize(window.innerWidth, window.innerHeight)
document.body.appendChild(renderer.domElement)
const scene = new THREE.Scene()
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000)
scene.add(new THREE.AmbientLight(0xFFFFFF, 1))
const controls = new OrbitControls(camera, renderer.domElement)
camera.position.set(0, 2, 2)
controls.target.set(0, 0.9, 0)
controls.update()
//setup some helper on the scene
scene.add(new THREE.AxesHelper(1))
scene.add(new THREE.GridHelper(10, 10))
// as a volograms takes time to be downloaded, display loading information
const updateLoading = p => {
const el = document.getElementById('loading')
el.innerText = Math.round(p*100) + '%'
}
document.getElementById('playpause').onclick = e => vologram.elVideo.paused ? vologram.elVideo.play() : vologram.elVideo.pause()
document.getElementById('sound').onclick = e => vologram.elVideo.muted = !vologram.elVideo.muted
let url = 'https://www.metalograms.com/ftp/vv/volograms/1670754904327_ld'
let vologram = new Vologram(url, updateLoading)
scene.add(vologram)
function animate() {
requestAnimationFrame(animate)
renderer.render(scene, camera)
}
animate()
</script>
<span id="gui">
<span id="loading">...</span>
<button id="playpause">⏯︎</button>
<button id="sound">🔈</button>
</span>
</body>
</html>