forked from ngokevin/aframe-component-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
58 lines (48 loc) · 1.28 KB
/
index.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
if (typeof AFRAME === 'undefined') {
throw new Error('Component attempted to register before AFRAME was available.');
}
/**
* Fence component for A-Frame.
*
* Thanks to Don McCurdy <https://github.com/donmccurdy>
* for his initial code
* and ngokevin's Component Boilerplate <https://github.com/ngokevin/aframe-component-boilerplate>
*
*/
AFRAME.registerComponent('fence', {
schema: {
width: {
type: 'number',
default: 10
},
depth: {
type: 'number',
default: 10
},
x0: {
type: 'number',
default: 0
},
z0: {
type: 'number',
default: 0
}
},
tick: function() {
var data = this.data;
var thiswidth = data.width;
var thisdepth = data.depth;
var x0 = data.x0;
var z0 = data.z0;
minX = thiswidth / 2 + x0;
maxX = ( -1 * thiswidth / 2 ) + x0;
minZ = thisdepth / 2 + z0;
maxZ = ( -1 * thisdepth / 2 ) + z0;
var position = this.el.getAttribute('position');
position.x = Math.min( minX, position.x);
position.x = Math.max( maxX, position.x);
position.z = Math.min( minZ, position.z);
position.z = Math.max( maxZ, position.z);
this.el.setAttribute('position', position);
},
});