-
Notifications
You must be signed in to change notification settings - Fork 0
/
trynagetsomemoney.html
300 lines (224 loc) · 8.41 KB
/
trynagetsomemoney.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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
<!DOCTYPE html>
<html lang="en">
<head>
<title>get</title>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, user-scalable=no"
/>
<style>
body {
font-family: Monospace;
background-color: #101010;
color: #fff;
margin: 0;
}
canvas {
display: block;
}
a {
color: #48f;
}
</style>
<script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.3.0/socket.io.slim.js"></script>
<script src="/easyrtc/easyrtc.js"></script>
<script src="/dist/networked-aframe.js"></script>
</head>
<body>
<script type="module">
import * as THREE from "https://unpkg.com/three@0.111.0/build/three.module.js";
import { OBJLoader } from "https://unpkg.com/three@0.111.0/examples/jsm/loaders/OBJLoader.js";
import { VRButton } from "https://unpkg.com/three@0.111.0/examples/jsm/webxr/VRButton.js";
var container;
var camera, scene, renderer;
var controller1, controller2;
var room;
var count = 0;
var normal = new THREE.Vector3();
var relativeVelocity = new THREE.Vector3();
var clock = new THREE.Clock();
init();
animate();
function init() {
container = document.createElement("div");
document.body.appendChild(container);
var info = document.createElement("div");
info.style.position = "absolute";
info.style.top = "10px";
info.style.width = "100%";
info.style.textAlign = "center";
info.innerHTML =
'<a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> vr - make it rain<br><a href="https://poly.google.com/view/btWmPNVSKUc" target="_blank">hand</a> by poly';
container.appendChild(info);
scene = new THREE.Scene();
scene.background = new THREE.Color(0x404040);
scene.fog = new THREE.Fog(scene.background, 10, 15);
camera = new THREE.PerspectiveCamera(
70,
window.innerWidth / window.innerHeight,
0.1,
20
);
camera.position.set(0, 1.6, 0);
var geometry = new THREE.PlaneBufferGeometry(15, 15);
geometry.rotateX(-Math.PI / 2);
geometry.translate(0, -0.01, 0);
var material = new THREE.MeshBasicMaterial({ color: 0x202020 });
room = new THREE.Mesh(geometry, material);
scene.add(room);
// money
var geometry = new THREE.PlaneBufferGeometry(0.2, 0.09);
geometry.rotateZ(Math.PI / 2);
geometry.rotateX(-Math.PI / 2);
var texture = new THREE.TextureLoader().load(
"https://cdn.glitch.com/cf086db5-7af7-4f20-8220-93d1d99150b7%2F100_dollar_bill_vector.png?1558543607686"
);
texture.anisotropy = 8;
var material = new THREE.MeshBasicMaterial({
map: texture,
side: THREE.DoubleSide
});
for (var i = 0; i < 400; i++) {
var object = new THREE.Mesh(geometry, material);
object.position.x = random() * 8;
object.position.y = Math.random() * 6;
object.position.z = random() * 8;
object.rotation.y = random() * Math.PI * 2;
object.userData.velocity = new THREE.Vector3();
object.userData.velocity.x = random() * 0.01;
object.userData.velocity.y = random() * 0.01;
object.userData.velocity.z = random() * 0.01;
object.userData.noise = random() * 0.1;
room.add(object);
}
//
renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.vr.enabled = true;
container.appendChild(renderer.domElement);
//
document.body.appendChild(VRButton.createButton(renderer));
// controllers
function onSelectStart() {
this.userData.isSelecting = true;
}
function onSelectEnd() {
this.userData.isSelecting = false;
}
// TODO: Update this code to r112
controller1 = renderer.vr.getController(0);
// controller1.addEventListener( 'selectstart', onSelectStart );
// controller1.addEventListener( 'selectend', onSelectEnd );
scene.add(controller1);
controller2 = renderer.vr.getController(1);
controller2.addEventListener("selectstart", onSelectStart);
controller2.addEventListener("selectend", onSelectEnd);
scene.add(controller2);
// hands
var file =
"https://cdn.glitch.com/7ae766be-18fb-4945-ad9d-8cc3be027694%2Fhand.obj?1558677422910";
var loader = new OBJLoader();
loader.load(file, function(group) {
// console.log( group.children[ 0 ] );
var texture = new THREE.TextureLoader().load(
"https://cdn.glitch.com/7ae766be-18fb-4945-ad9d-8cc3be027694%2FBazC_SkinMat.jpg?1558678160164"
);
var mesh = group.children[0];
mesh.geometry.rotateZ(-Math.PI / 2);
mesh.geometry.rotateY(Math.PI);
mesh.geometry.translate(1, -0.2, 0.25);
mesh.geometry.scale(0.1, 0.1, 0.1);
mesh.material = new THREE.MeshMatcapMaterial({ matcap: texture });
mesh.scale.x = -1;
controller1.add(mesh.clone());
mesh.scale.x = 1;
for (var i = 0; i < 10; i++) {
var bill = room.children[0].clone();
bill.position.set(i * 0.003 + 0.02, -0.05, 0);
bill.rotation.set(random() * 0.3, random() * 0.1, -Math.PI / 2);
mesh.add(bill);
}
controller2.add(mesh.clone());
});
//
window.addEventListener("resize", onWindowResize, false);
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
function handleController(controller) {
if (controller.userData.isSelecting) {
var object = room.children[count++];
var emitter = controller.children[0].children[9];
emitter.matrixWorld.decompose(
object.position,
object.quaternion,
object.scale
);
object.userData.velocity.x = random();
object.userData.velocity.y = random() + 0.5;
object.userData.velocity.z = Math.random() - 5;
object.userData.velocity.applyQuaternion(object.quaternion);
object.userData.noise = random() * 0.1;
if (count === room.children.length) count = 0;
}
}
//
function animate() {
renderer.setAnimationLoop(render);
}
function render() {
handleController(controller1);
handleController(controller2);
//
var delta = clock.getDelta() * 0.5; // slow down simulation
for (var i = 0; i < room.children.length; i++) {
var object = room.children[i];
var userData = object.userData;
var velocity = userData.velocity;
object.position.x += velocity.x * delta;
object.position.y += velocity.y * delta;
object.position.z += velocity.z * delta;
// flatten rotation
object.rotation.x *= 0.99;
object.rotation.z *= 0.99;
// handle floor
if (object.position.y <= 0) {
object.position.y = 0;
velocity.x *= 0.85;
velocity.y = 0;
velocity.z *= 0.85;
}
var height = object.position.y * 0.1;
if (height > 0) {
velocity.x += userData.noise * height;
velocity.y -= 9.8 * delta;
velocity.z += userData.noise * height;
object.rotation.y += userData.noise * height;
}
}
renderer.render(scene, camera);
}
function random() {
return Math.random() - 0.5;
}
</script>
<a-video
id="video-screen"
src="https://www.youtube.com/watch?v=yRsgm0cFgq0"
position="-1.02132 0.89195 -0.56798"
rotation="0 0 0"
scale="1.50761 1.49394 1"
width="8"
height="8"
visible="true"
material=""
geometry=""
></a-video>
</body>
</html>