-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtojinbocoaster_fly.html
More file actions
124 lines (106 loc) · 3.39 KB
/
tojinbocoaster_fly.html
File metadata and controls
124 lines (106 loc) · 3.39 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width"><link rel="icon" href="data:">
<title>VR東尋坊コースター俯瞰 - VR-Tojinbo-Coaster fly</title>
<style>
body {
margin: 0;
}
</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://code4fukui.github.io/three.js/build/three.module.js",
"three/addons/": "https://code4fukui.github.io/three.js/examples/jsm/"
}
}
</script>
<script type="module">
import * as THREE from "three";
import { Curve, addCoaster } from "./TojinboCoaster.js";
import { OrbitControls } from "three/addons/controls/OrbitControls.js";
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.xr.enabled = true;
renderer.outputEncoding = THREE.sRGBEncoding;
renderer.xr.setReferenceSpaceType("local");
document.body.appendChild(renderer.domElement);
//document.body.appendChild(VRButton.createButton(renderer));
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
const scene = new THREE.Scene();
class Curve0 extends Curve {
getPointAt(t) {
t *= Math.PI * 2;
const x = Math.sin(t) * 50;
const y = Math.sin(t * 10) * 2 + 36;
const z = Math.cos(t) * 50;
return this.vector.set(x, y, z);
}
}
class Curve2 extends Curve {
getPointAt(t) {
t *= Math.PI * 2;
const x = Math.sin(t * 3) * Math.cos(t * 4) * 50;
const y = Math.sin(t * 10) * 2 + Math.cos(t * 17) * 2 + 35;
const z = Math.sin(t) * Math.sin(t * 4) * 50;
return this.vector.set(x, y, z);
}
}
const makeCurve = (hash) => {
switch (hash) {
case "#0":
return new Curve0();
case "#2":
return new Curve2();
}
return new Curve();
};
const curve = makeCurve(location.hash);
await addCoaster(scene, curve);
//const train = new THREE.Object3D();
const geometry = new THREE.BoxGeometry(.5, .5, 1);
const color = 0xee7777;
const material = new THREE.MeshBasicMaterial({ color });
const train = new THREE.Mesh(geometry, material);
scene.add(train);
const camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 0.1, 1000);
const controls = new OrbitControls(camera, renderer.domElement);
controls.listenToKeyEvents(window);
camera.position.set(0, 20, 100);
//camera.position.set(0, 0, 0);
controls.update();
//train.add(camera);
const position = new THREE.Vector3();
const tangent = new THREE.Vector3();
const lookAt = new THREE.Vector3();
let velocity = 0;
let progress = 0;
let prevTime = performance.now();
renderer.setAnimationLoop(() => {
const time = performance.now();
const delta = time - prevTime;
progress += velocity;
progress = progress % 1;
position.copy(curve.getPointAt(progress));
position.y += 0.2; // 0.3
train.position.copy(position);
tangent.copy(curve.getTangentAt(progress));
const vc = 10;
velocity -= tangent.y * 0.0000001 * delta * vc;
velocity = Math.max(0.00004 * vc, Math.min(0.0002 * vc, velocity));
train.lookAt(lookAt.copy(position).sub(tangent));
controls.update();
renderer.render(scene, camera);
prevTime = time;
});
</script>
</body>
</html>