-
Notifications
You must be signed in to change notification settings - Fork 3
/
oculus.html
781 lines (628 loc) · 24.9 KB
/
oculus.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-161822888-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'UA-161822888-1');
</script>
<title>Oculus example</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
margin: 0;
}
</style>
</head>
<body>
<script type="module">
import * as THREE from 'https://cdn.jsdelivr.net/npm/[email protected]/build/three.module.js';
import { OrbitControls } from 'https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/controls/OrbitControls.js';
import { VRButton } from 'https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/webxr/VRButton.js';
import {GLTFLoader} from 'https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/loaders/GLTFLoader.js';
var camera, scene, renderer;
var geometry, material, mesh;
//var collectionBrainCoordinates = new THREE.Geometry();
var controller1, controller2;
var controls;
var POIs = new Array();
var points;
var movingSpeed = 0.0;
var cursor = new THREE.Vector3();
var nodes = new Array();
var bboxnodes = new Array();
var linesList = new Array();
var handMesh1;
var handMesh2;
var realcont1;
var realcont1connected = false;
var realcont2;
var realcont2connected = false;
var colorBuffer;
var placePOIButtonPressed = false;
var user = new THREE.Group();
var showAxes = getQueryVariable('showAxes', false);
var autoRotate = getQueryVariable('autoRotate', false);
// Start functions
init();
animate();
// Option 1 (legacy?): pass the name variable to download that specific file from S3
var filename = getQueryVariable('name', null);
// Option 2: get a base64 encoded json from the header...
var json_base64 = getQueryVariable('jsonb64', null);
// Option 3: get a base64 encoded pointcloud
var base64_str = getQueryVariable('base64', null);
if(filename){
var url = "https://pointcloudvisualization.s3.eu-central-1.amazonaws.com/"+filename;
if(url.endsWith("xyzi")){
startLoadingData(url, "XYZI");
}
else{
startLoadingData(url, "XYZRGB");
}
}
else if(base64_str){
var tempPoints = getPointsFromBase64String(base64_str, "XYZI");
scene.add(tempPoints);
}
else if(json_base64){
var decodedData = JSON.parse(atob(json_base64));
// Parse the JSON
if("points" in decodedData){
// Currently multiple point clouds are not fully supported, but I'll give it a try:
for (var i = 0; i < decodedData["points"].length; i++) {
var pointToLoad = decodedData["points"][i];
var pointSize = 0.04
if('pointSize' in pointToLoad){
pointSize = pointToLoad['pointSize'];
console.log('adjusting size');
}
if(pointToLoad['source'] == 'url'){
startLoadingData(pointToLoad['url'], pointToLoad["type"], pointSize);
}
else if(pointToLoad['source'] == 'base64'){
var tempPoints = getPointsFromBase64String(pointToLoad["base64"], pointToLoad["type"]);
scene.add(tempPoints);
}
}
}
if("lines" in decodedData){
console.log("found some lines")
var pointToLoad = decodedData["lines"][0];
if(pointToLoad['source'] == 'url'){
startLoadingLines(pointToLoad['url']);
}
}
if("bboxes" in decodedData){
var boxesToLoad = decodedData["bboxes"][0];
if(boxesToLoad['source'] == 'url'){
startLoadingBoxes(boxesToLoad['url']);
}
}
if("objects" in decodedData){
var objectsToLoad = decodedData['objects'];
startLoadingObjects(objectsToLoad);
}
}
else{
// For now: always load something just because it's cool...
var url = "https://pointcloudvisualization.s3.eu-central-1.amazonaws.com/cars3.npy";
startLoadingData(url, "XYZI");
}
/*
Example JSON:
{
"points": [
{
"source": "url",
"url": https://pointcloudvisualization.s3.eu-central-1.amazonaws.com/e2652aab-4ace-4a09-86f4-374b23cb677b.xyzi",
"type": "XYZI",
},
{
"source": "base64",
"base64": "Pttmyz4gkd8/BK5QPwvLhz3XReU9+osQPpbxoD9Yolw+tjy9PwRGQD8KfRU9YXGEP1TPlD9AG2M/M/e+Pv8/8j7JjBE/TdywPsiFpz9x8sg=",
"type": "XYZRGB"
}
]
"bboxes": [
{
"source": "url",
"url": "https://pointcloudvisualization.s3.eu-central-1.amazonaws.com/test1.bbox"
},
{
"source": "base64",
"base64": "SDFLksf459fjssfhwDHFFhfs+fsfh=",
}
]
"lines": [
{
"source": "url",
"url": "https://pointcloudvisualization.s3.eu-central-1.amazonaws.com/test1.lines"
},
]
"objects": [
{
"source": "url",
"url": "https://pointcloudvisualization.s3.eu-central-1.amazonaws.com/test1.glb",
"position": [1.0, 2.0, 3.0],
"rotation": [1.0, 1.1, 1.2],
"scale": [1.0, 1.0, 1.0],
}
]
}
*/
/*
For the points you can have either XYZI points, or XYZRGB points.
This means you either have input as a float32 array with 4 columns, or 6 columns (encoding the RGB colours).
For the XYZI points the intensity part is encoded as Hue (between 0 and 1) as a float32
*/
/*
For the lines you give an array with X1, Y1, Z1, X2, Y2, Z2. It draws lines between the start end the end point.
*/
/*
For the boxes this goes:
Center X (forwards) float32
Center Y (upwards) float32
Center Z (left) float32
Size X float32
Size Y float32
Size Z float32
Rotation around X float32
Rotation around Y float32
Rotation around Z float32
Red (between 0 and 1) float32
Green (between 0 and 1) float32
Blue (between 0 and 1) float32
Opacity (between 0 and 1) float32
*/
function get_bbox_vehicle(posx, posy, posz, sizex, sizey, sizez, rotationx, rotationy, rotationz, red, green, blue, opacity){
var geometry = new THREE.BoxGeometry( sizex, sizey, sizez);
var material = new THREE.MeshPhongMaterial({
color: new THREE.Color(red, green, blue),
opacity: opacity,
transparent: true,
});
// parent
parent = new THREE.Object3D();
parent.rotation.x = rotationx;
parent.rotation.y = rotationy;
parent.rotation.z = rotationz;
parent.position.x = posx;
parent.position.y = posy;
parent.position.z = posz;
// mesh
var mesh1 = new THREE.Mesh( geometry, material );
parent.add( mesh1 );
return parent;
}
function loadObject(object){
const loader = new GLTFLoader();
loader.load( object['url'], function ( gltf ) {
gltf.scene.traverse( function ( child ) {
if ( child.isMesh ) {
child.material.opacity = 0.5;
child.material.transparent = true;
}
} );
gltf.scene.scale.x = object['scale'][0];
gltf.scene.scale.y = object['scale'][1];
gltf.scene.scale.z = object['scale'][2];
gltf.scene.rotation.x = object['rotation'][0];
gltf.scene.rotation.y = object['rotation'][1];
gltf.scene.rotation.z = object['rotation'][2];
gltf.scene.position.x = object['position'][0];
gltf.scene.position.y = object['position'][1];
gltf.scene.position.z = object['position'][2];
scene.add( gltf.scene );
}, undefined, function ( error ) {
console.error( error );
} );
}
function startLoadingObjects(objectsToLoad){
for(var index in objectsToLoad){
var object = objectsToLoad[index];
loadObject(object);
}
}
function startLoadingBoxes(url){
var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function() {
if (httpRequest.readyState === 4){
// everything is good, the response is received
if ((httpRequest.status == 200) || (httpRequest.status == 0)){
var buffer = httpRequest.response;
var dataview = new DataView(buffer);
var points_per_row = 13;
// Note: divide by 4 because of float32 has 4 bytes
var ints = dataViewToFloat32Array(dataview, buffer.byteLength / 4)
for(var row=0; row < ints.length; row=row+points_per_row) {
bboxnodes[row/points_per_row] = new Array();
for(var p=0; p < points_per_row; p++){ //xyz...
bboxnodes[row/points_per_row][p] = ints[row+p]
}
}
console.log("Loaded num bboxes " + bboxnodes.length)
var particles = bboxnodes.length;
var geometry = new THREE.BufferGeometry();
var positions = [];
var colors = [];
var color = new THREE.Color();
for ( var i = 0; i < particles; i ++ ) {
var temp = get_bbox_vehicle(bboxnodes[i][0], bboxnodes[i][1], bboxnodes[i][2], bboxnodes[i][3], bboxnodes[i][4], bboxnodes[i][5], bboxnodes[i][6], bboxnodes[i][7], bboxnodes[i][8], bboxnodes[i][9], bboxnodes[i][10], bboxnodes[i][11], bboxnodes[i][12]);
scene.add(temp);
}}}}
// Send the request
console.log("Getting url for boxes", url)
httpRequest.open("GET", url, true);
httpRequest.responseType = "arraybuffer";
httpRequest.send();
}
function startLoadingLines(url)
{
var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function() {
if (httpRequest.readyState === 4){
// everything is good, the response is received
if ((httpRequest.status == 200) || (httpRequest.status == 0)){
var buffer = httpRequest.response;
var dataview = new DataView(buffer);
console.log('got them lines')
// Note: divide by 4 because of float32 has 4 bytes
var ints = dataViewToFloat32Array(dataview, buffer.byteLength / 4)
/*
This is actually a bit counter intuitive.
We are assuming the input is X1, Y1, Z1, X2, Y2, Z2.
However, we load each point separately, which gives us a points per row of 3.
*/
var points_per_row = 3 ;
for(var row=0; row < ints.length; row=row+points_per_row) {
linesList[row/points_per_row] = new THREE.Vector3(ints[row+0], ints[row+1] , ints[row+2] );
}
var idx = new Array();
for(var i=0; i < linesList.length; i=i+2){
idx.push(i);
idx.push(i+1);
}
console.log("Loaded num lines " + linesList.length + " with ppr: " + points_per_row)
const bg = new THREE.BufferGeometry().setFromPoints(linesList);
bg.setIndex(idx);
var geometry = bg;
var material = new THREE.LineBasicMaterial( { color: 0xffffff } );
var line = new THREE.LineSegments( geometry, material );
scene.add( line );
}}}
// Send the request
httpRequest.open("GET", url, true);
httpRequest.responseType = "arraybuffer";
httpRequest.send();
}
// Takes the text in the address-bar in the browser, and parses what's behind the ampersend (&) character.
// You can query a variable, and if the string contains variable=value it returns the value.
// If not found it will return the elsevalue supplied by whoever calls the function
function getQueryVariable(variable, elsevalue) {
var query = window.location.search.substring(1);
var vars = query.split('&');
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');
if (decodeURIComponent(pair[0]) == variable) {
return decodeURIComponent(pair[1]);
}
}
return elsevalue;
}
function _base64ToArrayBuffer(base64) {
var binary_string = window.atob(base64);
var len = binary_string.length;
var bytes = new Uint8Array(len);
for (var i = 0; i < len; i++) {
bytes[i] = binary_string.charCodeAt(i);
}
return bytes.buffer;
}
// Given a so-called dataviwe object (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)
// and the length of the array this function will return a new filled array from the dataview
// given that the dataview contains float32 values.
function dataViewToFloat32Array(dataview, lengthArray){
var ints = new Float32Array(lengthArray);
for (var i = 0; i < ints.length; i++) {
ints[i] = dataview.getFloat32(i * 4);
}
return ints;
}
function fillNodes(nodes, ints, pointsPerRow){
for(var row=0; row < ints.length; row=row+pointsPerRow) {
nodes[row/pointsPerRow] = new Array();
for(var p=0; p < pointsPerRow; p++){ //xyz...
nodes[row/pointsPerRow][p] = ints[row+p]
}
}
}
function getPointsFromBase64String(buffer, pointType){
buffer = _base64ToArrayBuffer(buffer);
var dataview = new DataView(buffer);
// Note: divide by 4 because of float32 has 4 bytes
var ints = dataViewToFloat32Array(dataview, buffer.byteLength / 4)
var tempNodes = new Array();
var points_per_row = get_points_per_row(pointType);
fillNodes(tempNodes, ints, points_per_row);
console.log("Loaded num points " + tempNodes.length)
var temp = getPositionsAndColors(tempNodes, pointType);
var geometry = new THREE.BufferGeometry();
geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( temp.positions, 3 ) );
colorBuffer = new THREE.Float32BufferAttribute( temp.colors, 3 );
geometry.setAttribute( 'color', colorBuffer );
geometry.computeBoundingSphere();
var material = new THREE.PointsMaterial( { size: 0.04, vertexColors: THREE.VertexColors } );
var tempPoints = new THREE.Points( geometry, material );
return tempPoints;
}
function get_points_per_row(pointType){
if(pointType == "XYZ"){
return 3;
}
else if(pointType == "XYZI"){
return 4;
}
else if(pointType == "XYZRGB"){
return 6;
}
}
function getPositionsAndColors(nodes, pointType){
var positions = [];
var colors = [];
var color = new THREE.Color();
for ( var i = 0; i < nodes.length; i ++ ) {
// positions
var x = nodes[i][0];
var y = nodes[i][1];
var z = nodes[i][2];
positions.push( x, y, z );
if(pointType == "XYZI"){
color.setHSL(nodes[i][3], 1.0, 0.5);
colors.push( color.r, color.g, color.b );
}
else if(pointType == "XYZRGB"){
colors.push( nodes[i][3], nodes[i][4], nodes[i][5] );
}
}
return {
positions: positions,
colors: colors
};
}
function startLoadingData(url, pointType, pointSize=1.5)
{
var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function() {
if (httpRequest.readyState === 4){
// everything is good, the response is received
if ((httpRequest.status == 200) || (httpRequest.status == 0)){
var buffer = httpRequest.response;
var dataview = new DataView(buffer);
// Note: divide by 4 because of float32 has 4 bytes
var ints = dataViewToFloat32Array(dataview, buffer.byteLength / 4)
var points_per_row = get_points_per_row(pointType);
fillNodes(nodes, ints, points_per_row);
console.log("Loaded num points " + nodes.length + " of point type " + pointType + " with ppr: " + points_per_row)
var particles = nodes.length;
var geometry = new THREE.BufferGeometry();
var temp = getPositionsAndColors(nodes, pointType);
geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( temp.positions, 3 ) );
colorBuffer = new THREE.Float32BufferAttribute( temp.colors, 3 );
geometry.setAttribute( 'color', colorBuffer );
geometry.computeBoundingSphere();
//
var material = new THREE.PointsMaterial( { size: pointSize, vertexColors: THREE.VertexColors, sizeAttenuation: false} );
points = new THREE.Points( geometry, material );
//points.frustumCulled = false;
scene.add( points );
}}}
// Send the request
httpRequest.open("GET", url, true);
httpRequest.responseType = "arraybuffer";
httpRequest.send();
}
function onSelectStart(){
movingSpeed = 1.0 * points.scale.x;
}
function onSelectEnd(){
movingSpeed = 0.0;
}
function onSelectStartRight(){
movingSpeed = -1.0 * points.scale.x;
}
function onSelectEndRight(){
movingSpeed = 0.0;
}
// Returns the 3D mesh object for a hand...
// Currently a cone.
function getHand(){
var radius = 0.08;
var geometry = new THREE.ConeGeometry( radius, 4*radius, 8 );
var handmesh =new THREE.Mesh( geometry, new THREE.MeshLambertMaterial( { color: Math.random() * 0xffffff } ) );
return handmesh;
}
function init() {
camera = new THREE.PerspectiveCamera( 27, window.innerWidth / window.innerHeight, 0.1, 1000 );
camera.position.z = 20;
user.add( camera );
scene = new THREE.Scene();
scene.background = new THREE.Color( 0x2d4aa8 );
renderer = new THREE.WebGLRenderer();
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.xr.enabled = true;
// Add the events to the first found controller and add it to the scene.
controller1 = renderer.xr.getController( 0 );
controller1.addEventListener( 'selectstart', onSelectStart );
controller1.addEventListener( 'selectend', onSelectEnd );
controller1.addEventListener( 'connected', function ( event ) {
console.log("Controller 1 connected");
console.log(event);
realcont1 = event.data;
realcont1connected = true;
} );
scene.add( controller1 );
// Add the events to the second found controller and add it to the scene.
controller2 = renderer.xr.getController( 1 );
scene.add( controller2 );
controller2.addEventListener( 'selectstart', onSelectStartRight );
controller2.addEventListener( 'selectend', onSelectEndRight );
controller2.addEventListener( 'connected', function ( event ) {
console.log("Controller 2 connected");
console.log(event);
realcont2 = event.data;
realcont2connected = true;
} );
// Add the render to the website
document.body.appendChild( renderer.domElement );
// Add controls so you can also use your mouse and keyboard to look at the scene.
controls = new OrbitControls( camera, renderer.domElement );
controls.autoRotate=autoRotate;
controls.target.set( 0, 0, 0 );
controls.keyPanSpeed = 28.0;
controls.update();
// Add the virtual reality button to the site.
document.body.appendChild( VRButton.createButton( renderer ) );
// Add a white light to the whole scene so you can see all objects
// var light = new THREE.AmbientLight( 0xffffff ); // soft white light
// scene.add( light );
// Add both hand objects to the scene.
handMesh1 = getHand();
scene.add(handMesh1);
handMesh2 = getHand();
scene.add(handMesh2);
// Possibly add an axis helper to the scene.
if(showAxes){
var axesHelper = new THREE.AxesHelper( 5 );
scene.add( axesHelper );
}
window.addEventListener( 'resize', onWindowResize, false );
}
function setLocationController( controllerMesh, controller ) {
controllerMesh.position.set(controller.position.x, controller.position.y, controller.position.z);
controllerMesh.position.add(user.position);
controllerMesh.rotation.set(controller.rotation.x, controller.rotation.y, controller.rotation.z);
controllerMesh.rotateX(-3.1415926/2);
}
function placePOI(location){
// Place a point of interest in the given location
var geometry = new THREE.CylinderGeometry( 0.1, 0.1, 0.6, 6 );
var material = new THREE.MeshPhongMaterial({
color: 0x00ff00,
opacity: 0.5,
transparent: true,
});
//var material = new THREE.MeshBasicMaterial( {color: 0x00ff00} );
var cube = new THREE.Mesh( geometry, material );
var geometry2 = new THREE.CylinderGeometry( 0.1, 0.1, 2.0, 6 );
var cube2 = new THREE.Mesh( geometry2, material );
scene.add( cube );
cube.position.x = location.x;
cube.position.y = location.y;
cube.position.z = location.z;
POIs.push([cube, location]);
}
function onWindowResize(){
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
function animate() {
renderer.setAnimationLoop( function () {
controls.update(); // Very important otherwise you spend a few evenings debugging stuff...
// Change colors in whatever way I want...
// if(colorBuffer){
// for(var i=0; i < colorBuffer.count*3; i++){
// colorBuffer.array[i] = 1.0;
// }
// colorBuffer.needsUpdate = true;
// }
//
if(realcont1connected){
var gamepad = realcont1.gamepad;
if(gamepad.buttons[4].pressed){
// points.scale.x = 4.0
// points.scale.y = 4.0
// points.scale.z = 4.0
//
// for(var property in POIs){
// property = POIs[property];
// property[0].position.x = property[1].x*4.0;
// property[0].position.y = property[1].y*4.0;
// property[0].position.z = property[1].z*4.0;
//
// property[0].scale.x = 4.0
// property[0].scale.y = 4.0
// property[0].scale.z = 4.0
// }
}
if(gamepad.buttons[5].pressed){
// points.scale.x = 1.0
// points.scale.y = 1.0
// points.scale.z = 1.0
//
// for(var property in POIs){
// property = POIs[property];
// property[0].position.x = property[1].x*1.0;
// property[0].position.y = property[1].y*1.0;
// property[0].position.z = property[1].z*1.0;
//
// property[0].scale.x = 1.0
// property[0].scale.y = 1.0
// property[0].scale.z = 1.0
// }
}
if (gamepad.buttons[1].pressed){
if(!placePOIButtonPressed){
placePOIButtonPressed = true;
placePOI(handMesh1.position);
}
}
else{
placePOIButtonPressed = false;
}
for(var i=0; i < gamepad.buttons.length; i++){
// A = 4
// B = 5
// grip = 1
// center joystick = 3
// Select = 0
// if (gamepad.buttons[i].pressed){
// console.log(i);
// }
}
}
if(realcont2connected){
var gamepad = realcont2.gamepad;
if (gamepad.buttons[1].pressed){
// This removes everything....
// for(var property in POIs){
// property = POIs[property];
// scene.remove(property[0]);
// }
}
}
// Draw the controllers
// If something triggered the selection-direction the user position moves in the direction of where the user is looking at.
if (movingSpeed != 0.0){
// Get the direction the user is looking at.
let xrCamera = renderer.xr.getCamera(camera);
let e = xrCamera.matrixWorld.elements;
let direction = new THREE.Vector3(movingSpeed*e[8], movingSpeed*e[9], movingSpeed*e[10]).normalize();
direction.multiplyScalar(-0.05);
user.position.add(direction);// HEY! Maybe this IS working after all!
}
setLocationController( handMesh1, controller1 );
setLocationController( handMesh2, controller2 );
renderer.render( scene, camera );
} );
}
</script>
</body></html>