-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
522 lines (324 loc) · 13.5 KB
/
main.js
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
var anges_s
var angle_deg
var state = 0
var sts
//var xstate = 0
/*
// This component hides and shows certain elements as the camera moves
AFRAME.registerComponent('portal', {
schema: {
width: {default: 4},
height: {default: 6},
depth: {default: 1},
},
init: function(){
this.camera = document.getElementById('camera')
this.contents = document.getElementById('portal-contents')
},
tick: function() {
const position = this.camera.object3D.position
const rotation = this.camera.object3D.rotation
content_info_pos = this.contents.object3D.position
content_info_ro = this.contents.object3D.rotation
const obj_Pos = this.contents.object3D.position
const angleRad = Math.atan2(position.z - obj_Pos.z, position.x - obj_Pos.x)
anges_s = (angleRad).toFixed(2)
angle_deg = ((angleRad).toFixed(2) * (180/Math.PI)).toFixed(2)
document.getElementById('PosX').innerHTML = ("PostioX: " + (position.x).toFixed(2))
document.getElementById('PosY').innerHTML = ("PostioY: " + (position.y).toFixed(2))
document.getElementById('PosZ').innerHTML = ("PostioZ: " + (position.z).toFixed(2))
document.getElementById('OriX').innerHTML = ("OriX: " + (rotation.x).toFixed(2))
document.getElementById('OriY').innerHTML = ("OriY: " + (rotation.y).toFixed(2))
document.getElementById('OriZ').innerHTML = ("OriZ: " + (rotation.z).toFixed(2))
document.getElementById('angle').innerHTML = ("angle: " + ((angleRad).toFixed(2) * (180/Math.PI)).toFixed(2))
document.getElementById('state_s').innerHTML = sts
if(anges_s < 0.6 && anges_s > -1 ){
sts = "Right Area"
}else if(anges_s < -1.5 && anges_s > -2 ){
sts = "Back Area"
}else if(anges_s < -2.2 && anges_s > -3.1 ){
sts = "Left Area"
}else{
sts = "UnTrack Area"
}
}
})
AFRAME.registerComponent('playvid', {
init: function () {
const obj3D = this.el.object3D
const v1 = document.querySelector('#vid1')
const v2 = document.querySelector('#vid2')
const v3 = document.querySelector('#vid3')
const el = this.el
const scene = this.el.sceneEl
const playvideos = function(){
obj3D.visible = false
v1.pause()
v2.pause()
v3.pause()
}
const pvid = function(evt){
el.setAttribute('material','src','#vid1')
obj3D.visible = true
v1.play()
v2.pause()
v3.pause()
//document.getElementById('state_t').innerHTML = v1.currentTime
}
const kvid = function(evt){
el.setAttribute('material','src','#vid2')
obj3D.visible = true
v2.play()
v1.pause()
v3.pause()
}
const nvid = function(evt){
el.setAttribute('material','src','#vid3')
obj3D.visible = true
v3.play()
v1.pause()
v2.pause()
}
const stx = function(evt){
v1.pause()
v2.pause()
v3.pause()
obj3D.visible = false
}
scene.addEventListener('realityready',playvideos)
scene.addEventListener('playvid1evt',pvid)
scene.addEventListener('playvid2evt',kvid)
scene.addEventListener('playvid3evt',nvid)
scene.addEventListener('stops',stx)
},
tick: function(){
if(anges_s < 0.6 && anges_s > -1 ){
this.el.emit('playvid1evt',{value:1})
}else if(anges_s < -1.5 && anges_s > -2 ){
this.el.emit('playvid2evt',{value:1})
}else if(anges_s < -2.2 && anges_s > -3.1 ){
this.el.emit('playvid3evt',{value:1})
}else{
this.el.emit('stops',{value:1})
}
}
})
AFRAME.registerComponent('seekvid', {
init: function(){
const obj3D = this.el.object3D
const v = document.getElementById('vid4')
const el = this.el
const scene = this.el.sceneEl
obj3D.visible = true
const one = function(evt){
v.currentTime = 2
v.pause()
}
const two = function(evt){
v.currentTime = 3
v.pause()
}
const three = function(evt){
v.currentTime = 4
v.pause()
}
const stopv = function(evt){
v.currentTime = 0
v.pause()
}
scene.addEventListener('angleone',one)
scene.addEventListener('angletwo',two)
scene.addEventListener('anglethree',three)
scene.addEventListener('anglestop',stopv)
},
tick: function(){
if(anges_s < 0.6 && anges_s > -1 ){
this.el.emit('angleone',{value:1})
}else if(anges_s < -1.5 && anges_s > -2 ){
this.el.emit('angletwo',{value:1})
}else if(anges_s < -2.2 && anges_s > -3.1 ){
this.el.emit('anglethree',{value:1})
}else{
this.el.emit('anglestop',{value:1})
}
}
})
*/
var xstate = 0
var curTimes = 0
AFRAME.registerComponent('target-vids', {
schema:{
name:{type: 'string'}
},
init: function(){
const obj3D = this.el.object3D
const el = this.el
const scene = this.el.sceneEl
const v1 = document.getElementById('vid1')
const v2 = document.getElementById('vid2')
const v3 = document.getElementById('vid3')
// const setvVidentity = document.getElementById('setvid1').object3D
const setvidOp1 = document.getElementById('vvid1')
const setvidOp2 = document.getElementById('vvid2')
const setvidOp3 = document.getElementById('vvid3')
this.camera = document.getElementById('camera')
obj3D.visible = false
//setvVidentity.visible = false
setvidOp1.setAttribute('opacity',0)
setvidOp2.setAttribute('opacity',0)
setvidOp3.setAttribute('opacity',0)
v1.pause()
v2.pause()
v3.pause()
scene.emit('recenter')
const showImgge = ({detail}) =>{
if(detail.name != this.data.name){
return
}
const position = this.camera.object3D.position
const angleRad = Math.atan2(position.z - detail.position.z, position.x - detail.position.x)
angle_deg = ((angleRad).toFixed(2) * (180/Math.PI)).toFixed(2)
document.getElementById('angle').innerHTML = ("angle: " + angle_deg)
obj3D.position.copy(detail.position)
obj3D.quaternion.copy(detail.rotation)
obj3D.scale.set(detail.scale,detail.scale,detail.scale)
obj3D.visible = true
//object position
//var qua = new THREE.Quaternion(detail.rotation.x ,detail.rotation.y,detail.rotation.z,detail.rotation.w)
// qua.setFromAxisAngle(new THREE.Vector3(0,1,0),Math.PI/2)
// setvVidentity.position.copy(detail.position)
// setvVidentity.quaternion.copy(qua)
//setvVidentity.rotation.y = 90
// setvVidentity.scale.set(detail.scale * .15 ,detail.scale * .15,detail.scale * .15)
// setvVidentity.visible = true
// if angle
if(angle_deg < 70 && angle_deg > 0){
this.el.emit('setvid1',{value:1})
state = 1
}else if(angle_deg < -40 && angle_deg > -80 ){
this.el.emit('setvid2',{value:1})
state = 2
}else if( (angle_deg < -110 && angle_deg >= -180) || (angle_deg > 140 && angle_deg <= 180)){
this.el.emit('setvid3',{value:1})
state = 3
}
else{
if(state == 1){
curTimes = v1.currentTime
}else if(state == 2){
curTimes = v2.currentTime
}else if(state == 3){
curTimes = v3.currentTime
}
this.el.emit('setvidx',{value:1})
}
//end if engle
document.getElementById('PosX').innerHTML = ("PostioX: " + (detail.position.x).toFixed(2))
document.getElementById('PosY').innerHTML = ("PostioY: " + (detail.position.y).toFixed(2))
document.getElementById('PosZ').innerHTML = ("PostioZ: " + (detail.position.z).toFixed(2))
document.getElementById('OriX').innerHTML = ("CrrentTime: " + (curTimes).toFixed(2))
document.getElementById('state_t').innerHTML = detail.name
}
const hideImage = ({detail}) => {
if(detail.name != this.data.name){
return
}
obj3D.visible = false
v1.pause()
v2.pause()
v3.pause()
if(state == 1){
curTimes = v1.currentTime
}else if(state == 2){
curTimes = v2.currentTime
}else if(state == 3){
curTimes = v3.currentTime
}
xstate = 0
// document.getElementById('OriY').innerHTML = ("state: " + state)
// document.getElementById('OriZ').innerHTML = ("xstate: " + xstate)
document.getElementById('state_t').innerHTML = 'Lost'
}
const spvid1 = function(evt){
setvidOp1.setAttribute('opacity',1)
setvidOp2.setAttribute('opacity',0)
setvidOp3.setAttribute('opacity',0)
if(xstate == 0){
v1.currentTime = curTimes
document.getElementById('OriZ').innerHTML = '1state'
xstate = 1
}
v1.play()
v2.pause()
v3.pause()
}
const spvid2 = function(evt){
setvidOp1.setAttribute('opacity',0)
setvidOp2.setAttribute('opacity',1)
setvidOp3.setAttribute('opacity',0)
if(xstate == 0){
v2.currentTime = curTimes
document.getElementById('OriZ').innerHTML = '2state'
xstate = 1
}
v2.play()
v1.pause()
v3.pause()
}
const spvid3 = function(evt){
setvidOp1.setAttribute('opacity',0)
setvidOp2.setAttribute('opacity',0)
setvidOp3.setAttribute('opacity',1)
if(xstate == 0){
v3.currentTime = curTimes
document.getElementById('OriZ').innerHTML = '3state'
xstate = 1
}
v3.play()
v1.pause()
v2.pause()
}
const sxvid = function(evt){
setvidOp1.setAttribute('opacity',0)
setvidOp2.setAttribute('opacity',0)
setvidOp3.setAttribute('opacity',0)
v1.pause()
v2.pause()
v3.pause()
xstate = 0
}
scene.addEventListener('xrimagefound', showImgge)
scene.addEventListener('xrimageupdated', showImgge)
scene.addEventListener('xrimagelost', hideImage)
scene.addEventListener('setvid1',spvid1)
scene.addEventListener('setvid2',spvid2)
scene.addEventListener('setvid3',spvid3)
scene.addEventListener('setvidx',sxvid)
}
})
/*
AFRAME.registerComponent('settri', {
init: function(){
const obj3D = this.el.object3D
const el = this.el
const scene = this.el.sceneEl
const v = document.getElementById('vid2')
const b = document.getElementById('vid1')
v.pause()
obj3D.visible = true
const setvid1 = function(evt){
v.play()
b.play()
// obj3D.visible = true
document.getElementById('PosX').innerHTML = 'setV1'
}
const setx = function(evt){
// v.pause()
// obj3D.visible = false
document.getElementById('PosX').innerHTML = 'XXX'
}
scene.addEventListener('setvid',setvid1)
scene.addEventListener('setvidx',setx)
}
})
*/