-
Notifications
You must be signed in to change notification settings - Fork 0
/
component-hit-testing.js
71 lines (61 loc) · 2.07 KB
/
component-hit-testing.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
//////////////////////////////////////////////////////////////////////////////
// arjs-hit-testing
//////////////////////////////////////////////////////////////////////////////
AFRAME.registerComponent('arjs-hit-testing', {
dependencies: ['arjs', 'artoolkit'],
schema: {
enabled : {
type: 'boolean',
default: false,
},
renderDebug : {
type: 'boolean',
default: false,
},
},
init: function () {
var _this = this
var arjsSystem = this.el.sceneEl.systems.arjs || this.el.sceneEl.systems.artoolkit
// TODO make it work on cameraTransformMatrix too
//
_this.isReady = false
_this._arAnchor = null
_this._arHitTesting = null
// trick to wait until arjsSystem is isReady
var startedAt = Date.now()
var timerId = setInterval(function(){
var anchorEl = _this.el
var anchorComponent = anchorEl.components['arjs-anchor']
// wait until anchorComponent is isReady
if( anchorComponent === undefined || anchorComponent.isReady === false ) return
clearInterval(timerId)
//////////////////////////////////////////////////////////////////////////////
// create arAnchor
//////////////////////////////////////////////////////////////////////////////
var arAnchor = anchorComponent._arAnchor
var arSession = arjsSystem._arSession
var renderer = arSession.parameters.renderer
var hitTesting = _this._arHitTesting = new ARjs.HitTesting(arSession)
hitTesting.enabled = _this.data.enabled
_this.isReady = true
}, 1000/60)
},
remove : function(){
},
update: function () {
},
tick: function(){
var _this = this
// if not yet isReady, do nothing
if( this.isReady === false ) return
var arjsSystem = this.el.sceneEl.systems.arjs || this.el.sceneEl.systems.artoolkit
var arSession = arjsSystem._arSession
var anchorEl = _this.el
var anchorComponent = anchorEl.components['arjs-anchor']
var arAnchor = anchorComponent._arAnchor
var hitTesting = this._arHitTesting
var camera = arSession.parameters.camera
// console.log(camera.position)
hitTesting.update(camera, arAnchor.object3d, arAnchor.parameters.changeMatrixMode)
}
});