-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
1107 lines (991 loc) · 32.1 KB
/
main.js
File metadata and controls
1107 lines (991 loc) · 32.1 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
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import './style.css';
import * as THREE from 'three';
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
import Stats from 'three/examples/jsm/libs/stats.module.js';
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
import { gsap } from 'gsap';
import {
CSS2DRenderer,
CSS2DObject
} from 'three/examples/jsm/renderers/CSS2DRenderer.js';
const debugMode = false;
// initialize scene
const scene = new THREE.Scene();
// make scene background black
scene.background = new THREE.Color(0x000000);
// initialize renderer
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// initialize camera
const camera = new THREE.PerspectiveCamera(
75,
window.innerWidth / window.innerHeight,
0.1,
1000
);
camera.position.set(-6, 4, 6);
// add orbit controls
const controls = new OrbitControls(camera, renderer.domElement);
controls.target.set(0, 0, 0);
controls.enablePan = false;
controls.enableDamping = true;
// for playing model with animation
// let mixer;
const dracoLoader = new DRACOLoader();
dracoLoader.setDecoderPath('./node_modules/three/examples/js/libs/draco/gltf/');
const loadingDiv = document.getElementById('loading');
const loader = new GLTFLoader();
loader.setDRACOLoader(dracoLoader);
loader.load(
'/VR Therapy Scene.glb',
function (gltf) {
// hide loading div
loadingDiv.style.display = 'none';
const model = gltf.scene;
model.position.set(0, -0.98, 0);
model.scale.set(0.8, 0.8, 0.8);
// block light from shining through model
model.traverse((o) => {
if (o.isMesh) {
o.castShadow = true;
o.receiveShadow = true;
}
});
scene.add(model);
// play model animation if it has one
// mixer = new THREE.AnimationMixer(model);
// mixer.clipAction(gltf.animations[0]).play();
animate();
},
onProgress,
function (e) {
console.log('error', e);
}
);
// add html to scene
const labelRenderer = new CSS2DRenderer();
labelRenderer.setSize(window.innerWidth, window.innerHeight);
labelRenderer.domElement.style.position = 'absolute';
labelRenderer.domElement.style.top = '0px';
labelRenderer.domElement.style.pointerEvents = 'none';
document.body.appendChild(labelRenderer.domElement);
// const p = document.createElement('p');
// p.textContent = 'Hello';
// const cPointLabel = new CSS2DObject(p);
// scene.add(cPointLabel);
// cPointLabel.position.set(1, 3, -3);
// const div = document.createElement('div');
// div.appendChild(p);
// const divContainer = new CSS2DObject(div);
// scene.add(divContainer);
// loading percent
const loadingPercent = document.getElementById('loadingPercent');
function onProgress(xhr) {
if (xhr.lengthComputable) {
const percentComplete = (xhr.loaded / xhr.total) * 100;
console.log(Math.round(percentComplete) + '% downloaded');
loadingPercent.innerHTML = 'Loading: ' + Math.round(percentComplete) + '%';
}
}
// object interaction listener material
const objectInteractionListenerMaterial = new THREE.MeshBasicMaterial({
wireframe: true,
opacity: 0.0,
transparent: debugMode ? false : true
});
// add folder interaction listener to scene
const folderBox = new THREE.BoxGeometry();
const folder = new THREE.Mesh(folderBox, objectInteractionListenerMaterial);
folder.name = 'folder';
// set dimensions of folder
folder.scale.set(0.7, 0.1, 0.85);
// set position of folder
const folderX = -2.9;
const folderY = 0.3;
const folderZ = -2.55;
folder.position.set(folderX, folderY, folderZ);
scene.add(folder);
// add monitor interaction listener to scene
const monitorBox = new THREE.BoxGeometry();
const monitor = new THREE.Mesh(monitorBox, objectInteractionListenerMaterial);
monitor.name = 'monitor';
// set dimensions of monitor
monitor.scale.set(1.9, 0.1, 1);
// set position of monitor
const monitorX = -1.5;
const monitorY = 1.25;
const monitorZ = -3;
monitor.position.set(monitorX, monitorY, monitorZ);
// rotate 90 degrees around x axis
monitor.rotateX(Math.PI / 2);
scene.add(monitor);
// add book interaction listener to scene
const bookBox = new THREE.BoxGeometry();
const book = new THREE.Mesh(bookBox, objectInteractionListenerMaterial);
book.name = 'book';
// set dimensions of book
book.scale.set(0.85, 0.3, 1.1);
// set position of book
const bookX = 0.45;
const bookY = 0.35;
const bookZ = -2.6;
book.position.set(bookX, bookY, bookZ);
scene.add(book);
// add smart screen interaction listener to scene
const smartScreenBox = new THREE.BoxGeometry();
const smartScreen = new THREE.Mesh(
smartScreenBox,
objectInteractionListenerMaterial
);
smartScreen.name = 'smartScreen';
// set dimensions of smart screen
smartScreen.scale.set(1, 0.1, 1);
// set position of smart screen
const smartScreenX = 2.77;
const smartScreenY = 0.6;
const smartScreenZ = -0.65;
smartScreen.position.set(smartScreenX, smartScreenY, smartScreenZ);
// rotate 30 degrees around z axis
smartScreen.rotateZ(Math.PI / 6);
scene.add(smartScreen);
// add picture 1 interaction listener to scene
const picture1Box = new THREE.BoxGeometry();
const picture1 = new THREE.Mesh(picture1Box, objectInteractionListenerMaterial);
picture1.name = 'picture1';
// set dimensions of picture 1
picture1.scale.set(1.6, 0.1, 1.6);
// set position of picture 1
const picture1X = -1.65;
const picture1Y = 2.95;
const picture1Z = -3.3;
picture1.position.set(picture1X, picture1Y, picture1Z);
// rotate 90 degrees around x axis
picture1.rotateX(Math.PI / 2);
scene.add(picture1);
// add picture 2 interaction listener to scene
const picture2Box = new THREE.BoxGeometry();
const picture2 = new THREE.Mesh(picture2Box, objectInteractionListenerMaterial);
picture2.name = 'picture2';
// set dimensions of picture 2
picture2.scale.set(1.6, 0.1, 1.6);
// set position of picture 2
const picture2X = 1.05;
const picture2Y = 2.95;
const picture2Z = -3.3;
picture2.position.set(picture2X, picture2Y, picture2Z);
// rotate 90 degrees around x axis
picture2.rotateX(Math.PI / 2);
scene.add(picture2);
// add picture 3 interaction listener to scene
const picture3Box = new THREE.BoxGeometry();
const picture3 = new THREE.Mesh(picture3Box, objectInteractionListenerMaterial);
picture3.name = 'picture3';
// set dimensions of picture 3
picture3.scale.set(1.6, 0.1, 1.6);
// set position of picture 3
const picture3X = 3.3;
const picture3Y = 2.95;
const picture3Z = -1.45;
picture3.position.set(picture3X, picture3Y, picture3Z);
// rotate 90 degrees around z axis
picture3.rotateZ(Math.PI / 2);
scene.add(picture3);
// add picture 4 interaction listener to scene
const picture4Box = new THREE.BoxGeometry();
const picture4 = new THREE.Mesh(picture4Box, objectInteractionListenerMaterial);
picture4.name = 'picture4';
// set dimensions of picture 4
picture4.scale.set(1.6, 0.1, 2.5);
// set position of picture 4
const picture4X = 3.3;
const picture4Y = 2.95;
const picture4Z = 1.62;
picture4.position.set(picture4X, picture4Y, picture4Z);
// rotate 90 degrees around z axis
picture4.rotateZ(Math.PI / 2);
scene.add(picture4);
// flags
let lookingAtFolder = false;
let lookingAtMonitor = false;
let lookingAtBook = false;
let lookingAtSmartScreen = false;
let lookingAtPicture1 = false;
let lookingAtPicture2 = false;
let lookingAtPicture3 = false;
let lookingAtPicture4 = false;
function updateFlags(item) {
lookingAtFolder = false;
lookingAtMonitor = false;
lookingAtBook = false;
lookingAtSmartScreen = false;
lookingAtPicture1 = false;
lookingAtPicture2 = false;
lookingAtPicture3 = false;
lookingAtPicture4 = false;
switch (item) {
case 'folder': {
lookingAtFolder = true;
break;
}
case 'monitor': {
lookingAtMonitor = true;
break;
}
case 'book': {
lookingAtBook = true;
break;
}
case 'smartScreen': {
lookingAtSmartScreen = true;
break;
}
case 'picture1': {
lookingAtPicture1 = true;
break;
}
case 'picture2': {
lookingAtPicture2 = true;
break;
}
case 'picture3': {
lookingAtPicture3 = true;
break;
}
case 'picture4': {
lookingAtPicture4 = true;
break;
}
}
}
// check if mouse is over cube
const raycaster = new THREE.Raycaster();
const mouse = new THREE.Vector2();
const onMouseMove = (event) => {
// calculate mouse position in normalized device coordinates
// (-1 to +1) for both components
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
// update the picking ray with the camera and mouse position
raycaster.setFromCamera(mouse, camera);
// calculate objects intersecting the picking ray
const intersects = raycaster.intersectObjects(scene.children);
for (let i = 0; i < intersects.length; i++) {
// console.log(intersects[i].object.name);
if (intersects[i].object.name === 'title') {
console.log('title clicked');
moveToStartPosition();
} else if (intersects[i].object.name === 'folder') {
console.log('folder clicked', lookingAtFolder);
if (!lookingAtFolder) {
moveToLocation(
folderX,
folderY + 1,
folderZ,
folderX,
folderY,
folderZ
);
updateFlags('folder');
} else {
moveToStartPosition();
}
} else if (intersects[i].object.name === 'monitor') {
console.log('monitor clicked', lookingAtMonitor);
if (!lookingAtMonitor) {
moveToLocation(
monitorX,
monitorY,
monitorZ + 1,
monitorX,
monitorY,
monitorZ
);
updateFlags('monitor');
} else {
moveToStartPosition();
}
} else if (intersects[i].object.name === 'book') {
console.log('book clicked', lookingAtBook);
if (!lookingAtBook) {
moveToLocation(bookX, bookY + 1, bookZ, bookX, bookY, bookZ);
updateFlags('book');
} else {
moveToStartPosition();
}
} else if (intersects[i].object.name === 'smartScreen') {
console.log('smartScreen clicked', lookingAtSmartScreen);
if (!lookingAtSmartScreen) {
moveToLocation(
smartScreenX - 0.75,
smartScreenY + 0.75,
smartScreenZ,
smartScreenX,
smartScreenY,
smartScreenZ
);
updateFlags('smartScreen');
} else {
moveToStartPosition();
}
} else if (intersects[i].object.name === 'picture1') {
console.log('picture1 clicked', lookingAtPicture1);
if (!lookingAtPicture1) {
moveToLocation(
picture1X,
picture1Y,
picture1Z + 1.5,
picture1X,
picture1Y,
picture1Z
);
updateFlags('picture1');
} else {
moveToStartPosition();
}
} else if (intersects[i].object.name === 'picture2') {
console.log('picture2 clicked', lookingAtPicture2);
if (!lookingAtPicture2) {
moveToLocation(
picture2X,
picture2Y,
picture2Z + 1.5,
picture2X,
picture2Y,
picture2Z
);
updateFlags('picture2');
} else {
moveToStartPosition();
}
} else if (intersects[i].object.name === 'picture3') {
console.log('picture3 clicked', lookingAtPicture3);
if (!lookingAtPicture3) {
moveToLocation(
picture3X - 1.5,
picture3Y,
picture3Z,
picture3X,
picture3Y,
picture3Z
);
updateFlags('picture3');
} else {
moveToStartPosition();
}
} else if (intersects[i].object.name === 'picture4') {
console.log('picture4 clicked', lookingAtPicture4);
if (!lookingAtPicture4) {
moveToLocation(
picture4X - 1.5,
picture4Y,
picture4Z,
picture4X,
picture4Y,
picture4Z
);
updateFlags('picture4');
} else {
moveToStartPosition();
}
}
}
};
function moveToLocation(cameraX, cameraY, cameraZ, lookAtX, lookAtY, lookAtZ) {
controls.minDistance = 0;
// ignore click until camera has finished moving
window.removeEventListener('click', onMouseMove);
// disable orbit and zoom
controls.enableRotate = false;
controls.enableZoom = false;
let rateX;
let rateY;
let rateZ;
let setRates = false;
gsap.to(camera.position, {
duration: 2,
x: cameraX,
y: cameraY,
z: cameraZ,
ease: 'power3.inOut',
onUpdate: () => {
if (!setRates) {
setRates = true;
// console.log(camera.target);
console.log('controls.target.x', controls.target.x);
console.log('controls.target.y', controls.target.y);
console.log('controls.target.z', controls.target.z);
// need to copy values in order to avoid error for undefined for some reason
const currentTargetX = controls.target.x;
const currentTargetY = controls.target.y;
const currentTargetZ = controls.target.z;
// calculate rateX
rateX = Math.abs((lookAtX - currentTargetX) / 25);
// calculate rateY
rateY = Math.abs((lookAtY - currentTargetY) / 25);
// calculate rateZ
rateZ = Math.abs((lookAtZ - currentTargetZ) / 25);
console.log('rateX', rateX);
console.log('rateY', rateY);
console.log('rateZ', rateZ);
}
if (controls.target.x > lookAtX) {
controls.target.x -= rateX;
if (controls.target.x <= lookAtX) {
controls.target.x = lookAtX;
}
} else {
controls.target.x += rateX;
if (controls.target.x >= lookAtX) {
controls.target.x = lookAtX;
}
}
// update controls.target.y towards y
if (controls.target.y > lookAtY) {
controls.target.y -= rateY;
if (controls.target.y <= lookAtY) {
controls.target.y = lookAtY;
}
} else {
controls.target.y += rateY;
if (controls.target.y >= lookAtY) {
controls.target.y = lookAtY;
}
}
// update controls.target.z towards z
if (controls.target.z > lookAtZ) {
controls.target.z -= rateZ;
if (controls.target.z <= lookAtZ) {
controls.target.z = lookAtZ;
}
} else {
controls.target.z += rateZ;
if (controls.target.z >= lookAtZ) {
controls.target.z = lookAtZ;
}
}
},
onComplete: () => {
controls.target.set(lookAtX, lookAtY, lookAtZ);
// prevent zoom forwards from current position
const currentPos = camera.position.distanceTo(controls.target);
controls.minDistance = currentPos;
controls.maxDistance = currentPos + 2;
window.addEventListener('click', onMouseMove);
controls.enableZoom = true;
}
});
}
function moveToStartPosition() {
lookingAtFolder = false;
lookingAtMonitor = false;
lookingAtBook = false;
lookingAtSmartScreen = false;
lookingAtPicture1 = false;
lookingAtPicture2 = false;
lookingAtPicture3 = false;
lookingAtPicture4 = false;
const cameraX = -6;
const cameraY = 4;
const cameraZ = 6;
const lookAtX = 0;
const lookAtY = 0;
const lookAtZ = 0;
controls.minDistance = 0;
controls.maxDistance = 15;
// ignore click until camera has finished moving
window.removeEventListener('click', onMouseMove);
// disable orbit and zoom
controls.enableRotate = false;
controls.enableZoom = false;
let rateX;
let rateY;
let rateZ;
let setRates = false;
gsap.to(camera.position, {
duration: 2,
x: cameraX,
y: cameraY,
z: cameraZ,
ease: 'power3.inOut',
onUpdate: () => {
if (!setRates) {
setRates = true;
// console.log(camera.target);
console.log('controls.target.x', controls.target.x);
console.log('controls.target.y', controls.target.y);
console.log('controls.target.z', controls.target.z);
// need to copy values in order to avoid error for undefined for some reason
const currentTargetX = controls.target.x;
const currentTargetY = controls.target.y;
const currentTargetZ = controls.target.z;
// calculate rateX
rateX = Math.abs((lookAtX - currentTargetX) / 50);
// calculate rateY
rateY = Math.abs((lookAtY - currentTargetY) / 50);
// calculate rateZ
rateZ = Math.abs((lookAtZ - currentTargetZ) / 50);
console.log('rateX', rateX);
console.log('rateY', rateY);
console.log('rateZ', rateZ);
}
// update controls.target.x towards x
if (controls.target.x > lookAtX) {
controls.target.x -= rateX;
if (controls.target.x <= lookAtX) {
controls.target.x = lookAtX;
}
} else {
controls.target.x += rateX;
if (controls.target.x >= lookAtX) {
controls.target.x = lookAtX;
}
}
// update controls.target.y towards y
if (controls.target.y > lookAtY) {
controls.target.y -= rateY;
if (controls.target.y <= lookAtY) {
controls.target.y = lookAtY;
}
} else {
controls.target.y += rateY;
if (controls.target.y >= lookAtY) {
controls.target.y = lookAtY;
}
}
// update controls.target.z towards z
if (controls.target.z > lookAtZ) {
controls.target.z -= rateZ;
if (controls.target.z <= lookAtZ) {
controls.target.z = lookAtZ;
}
} else {
controls.target.z += rateZ;
if (controls.target.z >= lookAtZ) {
controls.target.z = lookAtZ;
}
}
},
onComplete: () => {
controls.target.set(lookAtX, lookAtY, lookAtZ);
controls.minDistance = 4;
controls.maxDistance = 15;
window.addEventListener('click', onMouseMove);
controls.enableRotate = true;
controls.enableZoom = true;
}
});
}
window.addEventListener('click', onMouseMove, false);
// import FontLoader
import { FontLoader } from 'three/examples/jsm/loaders/FontLoader.js';
// import TextGeometry
import { TextGeometry } from 'three/examples/jsm/geometries/TextGeometry.js';
// add 3d text that says Hello World!
const loader2 = new FontLoader();
loader2.load(
'https://threejs.org/examples/fonts/helvetiker_regular.typeface.json',
function (font) {
const geometry = new TextGeometry('VR Therapy', {
font: font,
size: 0.35,
height: 0.2
});
const material = new THREE.MeshNormalMaterial();
const text = new THREE.Mesh(geometry, material);
text.position.set(-3.25, -0.8, 3);
text.name = 'title';
scene.add(text);
// item text material
// set text color to white
const whiteTextMaterial = new THREE.MeshBasicMaterial({
color: 0xffffff
});
// set text color to black
const blackTextMaterial = new THREE.MeshBasicMaterial({
color: 0x000000
});
// add folder text
const folderTextGeometry = new TextGeometry(
'The Problem\n\n-Out of every 100 students in college,\naround 18 of us has an anxiety disorder\nAs many as 500,000 U.S. troops who\nserved over the past 13 years have been\ndiagnosed with PTSD\n- Anxiety disorders, including panic\ndisorder, specific phobias, PTSD are too\ncommon\n- Current exposure treatment success\nrate is 60-90%\n- However these methods can be\nimproved in a more innovative way with\nVR technology',
{
font: font,
size: 0.025,
height: 0
}
);
const folderText = new THREE.Mesh(folderTextGeometry, whiteTextMaterial);
folderText.position.set(folderX - 0.32, folderY, folderZ - 0.3);
// rotate text -90 degrees around x axis
folderText.rotateX(-Math.PI / 2);
folderText.name = 'folderText';
scene.add(folderText);
// add monitor text
const monitorTextGeometry = new TextGeometry(
'How VR Therapy Works\n\n- Exposure therapy aims to decrease the\nintensity of your response to stressful situations\n- You put on a VR goggle and are exposed to PTSD\ntriggers in a a controlled and safe environment\n- As you continue to expose yourself to the triggers,\nyour brain will learn to associate the triggers with a\nsafe environment, and you will be able to overcome\nyour fear and anxiety',
{
font: font,
size: 0.05,
height: 0
}
);
const monitorText = new THREE.Mesh(monitorTextGeometry, blackTextMaterial);
monitorText.position.set(monitorX - 0.8, monitorY + 0.35, monitorZ);
monitorText.name = 'monitorText';
scene.add(monitorText);
// add book text
const bookTextGeometry = new TextGeometry(
'The Science of\nVR Therapy\n\n- The VR experience tricks your brain into\nbelieving that you are physically in the\nenvironment because it shares the same\nbasic mechanism: embodied simulations\n- According to neuroscience, the brain\ndevelops an embodied simulation of the\n body in an environment to make\npredictions and respond to the world\nappropriately\n- VR therapy tries to accomplish the same\nthing by maintaining a simulation of the\nbody and the space around it\n- VR therapy simply alters the experience\nof the body and the facilitating virtual\nenvironment',
{
font: font,
size: 0.025,
height: 0
}
);
const bookText = new THREE.Mesh(bookTextGeometry, whiteTextMaterial);
bookText.position.set(bookX - 0.32, bookY + 0.15, bookZ - 0.3);
// rotate text -90 degrees around x axis
bookText.rotateX(-Math.PI / 2);
bookText.name = 'bookText';
scene.add(bookText);
// add smart screen text
const smartScreenTextGeometry = new TextGeometry(
"VR Rehabilitation vs.\nConventional Therapy\n\n- According to a paper published in them\nNational Library of Medicine, 12 weeks of\nVR rehabilitation resulted in a greater\nimprovement in patients over traditional\ntherapy\n- About 30% of patients who tried VR\ntherapy prefer conversing with virtual\nbeings rather than face-to-face interactions\n- VR therapy allows for greater control over\na patient's personal exposure to a\nparticular environment",
{
font: font,
size: 0.03,
height: 0
}
);
const smartScreenText = new THREE.Mesh(
smartScreenTextGeometry,
blackTextMaterial
);
smartScreenText.position.set(
smartScreenX + 0.24,
smartScreenY + 0.18,
smartScreenZ - 0.4
);
// rotate 30 degrees around z axis
smartScreenText.rotateZ(Math.PI / 6);
// rotate 90 degrees around x axis
smartScreenText.rotateX(-Math.PI / 2);
// rotate -90 degrees around z axis
smartScreenText.rotateZ(-Math.PI / 2);
smartScreenText.name = 'smartScreenText';
scene.add(smartScreenText);
// add picture 1 text
const picture1TextGeometry = new TextGeometry(
"Benefits of VR Therapy\n\n- Digital realities are getting more complex and\nrealistic, making it more believable\n- VR Therapy is conducted in a safe and secure\nenvironment\n- Personalizing one's experience is much easier\nand better\n- Therapeutic sessions are consistent and\nrepeatable or progressive\n- Sessions can be replayed for re-assessment",
{
font: font,
size: 0.04,
height: 0
}
);
const picture1Text = new THREE.Mesh(
picture1TextGeometry,
blackTextMaterial
);
picture1Text.position.set(picture1X - 0.6, picture1Y, picture1Z);
picture1Text.name = 'picture1Text';
scene.add(picture1Text);
// add picture 2 text
const picture2TextGeometry = new TextGeometry(
'Testimonials\n\n- "The biggest problem I have found as a person living with chronic\npain is that, although there is a lot of information about chronic pain\navailable, it is not easily accessible – you have to search so many\nplaces to get part of the BIG picture! You have created a clean and\nclear source that anyone can use to access and\nunderstand information on VR!"\n- "Having used VR during the birth of both of my daughters, I know\nfirsthand how this can be an effective tool in managing the most\npainful moments of childbirth."\n- "VR could play an important role, providing immersive and\nimmediate solutions to help alleviate stress, reduce anxiety and\nmanage pain. I believe VR represents the next generation of digital\nhealth solutions."',
{
font: font,
size: 0.03,
height: 0
}
);
const picture2Text = new THREE.Mesh(
picture2TextGeometry,
blackTextMaterial
);
picture2Text.position.set(picture2X - 0.6, picture2Y, picture2Z);
picture2Text.name = 'picture2Text';
scene.add(picture2Text);
// add picture 3 text
const picture3TextGeometry = new TextGeometry(
'Why I built this site\n\n- To raise awareness of the importance\nof VR in therapy\n- Practice Blender and Three.Js\n- Learn new tools and developing an\napplication that can be used as a basis\nfor other projects',
{
font: font,
size: 0.05,
height: 0
}
);
const picture3Text = new THREE.Mesh(
picture3TextGeometry,
blackTextMaterial
);
picture3Text.position.set(picture3X, picture3Y, picture3Z - 0.6);
// rotate 90 degrees around y axis
picture3Text.rotateY(-Math.PI / 2);
picture3Text.name = 'picture3Text';
scene.add(picture3Text);
// add picture 4 text
const picture4TextGeometry = new TextGeometry(
'The Future of VR Therapy\n\n- As VR softwares and apps get better (easy to use and more\nrealistic), VR is likely to become commonplace for therapy\n- Jan CES 2023 unveiled the most expansive solutions to VR\nincluding haptics for body and hands, 3D holograms, and\n advanced AI softwares which could take VR to the next step\nof realism',
{
font: font,
size: 0.05,
height: 0
}
);
const picture4Text = new THREE.Mesh(
picture4TextGeometry,
blackTextMaterial
);
picture4Text.position.set(picture4X, picture4Y, picture4Z - 1);
// rotate 90 degrees around y axis
picture4Text.rotateY(-Math.PI / 2);
picture4Text.name = 'picture4Text';
scene.add(picture4Text);
}
);
// add images to pictures
// instantiate a loader
const imgLoader = new THREE.ImageLoader();
// load picture 1 image with transparent background
imgLoader.load('/img/vr-6770800_640.png', function (image) {
// create the texture
const texture = new THREE.Texture(image);
texture.needsUpdate = true;
// create the material
const material = new THREE.MeshBasicMaterial({
map: texture,
transparent: true
});
// create the geometry
const geometry = new THREE.PlaneGeometry(1, 1);
// create the mesh
const mesh = new THREE.Mesh(geometry, material);
// scale the mesh
mesh.scale.set(0.7, 0.5, 1);
mesh.position.set(picture1X, picture1Y + 0.35, picture1Z);
mesh.name = 'picture1Img';
scene.add(mesh);
});
// load picture 2 image with transparent background
imgLoader.load('/img/trophy-png-23.png', function (image) {
// create the texture
const texture = new THREE.Texture(image);
texture.needsUpdate = true;
// create the material
const material = new THREE.MeshBasicMaterial({
map: texture,
transparent: true
});
// create the geometry
const geometry = new THREE.PlaneGeometry(1, 1);
// create the mesh
const mesh = new THREE.Mesh(geometry, material);
// scale the mesh
mesh.scale.set(0.6, 0.6, 1);
mesh.position.set(picture2X, picture2Y + 0.35, picture2Z);
mesh.name = 'picture2Img';
scene.add(mesh);
});
// load picture 3 image with transparent background
imgLoader.load('/img/1377892.png', function (image) {
// create the texture
const texture = new THREE.Texture(image);
texture.needsUpdate = true;
// create the material
const material = new THREE.MeshBasicMaterial({
map: texture,
transparent: true
});
// create the geometry
const geometry = new THREE.PlaneGeometry(1, 1);
// create the mesh
const mesh = new THREE.Mesh(geometry, material);
// scale the mesh
mesh.scale.set(0.5, 0.5, 1);
mesh.position.set(picture3X, picture3Y + 0.35, picture3Z);
// rotate 90 degrees around y axis
mesh.rotateY(-Math.PI / 2);
mesh.name = 'picture3Img';
scene.add(mesh);
});
// load picture 4 image with transparent background
imgLoader.load(
'/img/Oculus-Rift-CV1-Headset-Front_with_transparent_background.png',
function (image) {
// create the texture
const texture = new THREE.Texture(image);
texture.needsUpdate = true;
// create the material
const material = new THREE.MeshBasicMaterial({
map: texture,
transparent: true
});
// create the geometry
const geometry = new THREE.PlaneGeometry(1, 1);
// create the mesh
const mesh = new THREE.Mesh(geometry, material);
// scale the mesh
mesh.scale.set(1, 0.65, 1);
mesh.position.set(picture4X, picture4Y + 0.35, picture4Z);
// rotate 90 degrees around y axis
mesh.rotateY(-Math.PI / 2);
mesh.name = 'picture4Img';
scene.add(mesh);
}
);
// add black floor that absorbs light
// dark grey
const color = 0x222222;
const size = 500;
const floorGeometry = new THREE.CircleGeometry(size, size);
const floorMaterial = new THREE.MeshPhongMaterial({
color: color,
side: THREE.DoubleSide
});
const floor = new THREE.Mesh(floorGeometry, floorMaterial);
floor.rotation.x = Math.PI / 2;
floor.position.y = -1;
scene.add(floor);
// resize renderer on window resize
window.addEventListener('resize', function () {
renderer.setSize(window.innerWidth, window.innerHeight);
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
labelRenderer.setSize(window.innerWidth, window.innerHeight);
});
const xyPos = 5;
const lightYPos = 3;
const lightIntensity = 3;
const lightDist = 20;
// add 4 lights pointing downward to illuminate scene in green, blue, purple, red in 4 corners
const white = 0xffffff;
// 0x00ff00
// add omni directional light
const light1 = new THREE.PointLight(0x00ff00, lightIntensity, lightDist);
light1.position.set(xyPos, lightYPos, xyPos);
light1.castShadow = true;
scene.add(light1);
if (debugMode) {
const light1Helper = new THREE.PointLightHelper(light1, 0.2);
scene.add(light1Helper);
}
const light2 = new THREE.PointLight(0x0000ff, lightIntensity, lightDist);
light2.position.set(-xyPos, lightYPos, xyPos);
light2.castShadow = true;
scene.add(light2);
if (debugMode) {
const light2Helper = new THREE.PointLightHelper(light2, 0.2);
scene.add(light2Helper);
}
const light3 = new THREE.PointLight(0x800080, lightIntensity, lightDist);
light3.position.set(xyPos, lightYPos, -xyPos);
light3.castShadow = true;
scene.add(light3);
if (debugMode) {
const light3Helper = new THREE.PointLightHelper(light3, 0.2);
scene.add(light3Helper);
}
const light4 = new THREE.PointLight(0xff0000, lightIntensity, lightDist);
light4.position.set(-xyPos, lightYPos, -xyPos);
light4.castShadow = true;
scene.add(light4);
if (debugMode) {
const light4Helper = new THREE.PointLightHelper(light4, 0.2);
scene.add(light4Helper);
}
// add spot light coming out of desk lamp
const yellow = 0xffff00;
const deskLight = new THREE.SpotLight(yellow, 10, 3);
deskLight.position.set(1.84, 1.31, -2.42);
deskLight.target.position.set(0, -1, -2.4);