-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaframe-web-gui-component.js
More file actions
67 lines (62 loc) · 2.46 KB
/
aframe-web-gui-component.js
File metadata and controls
67 lines (62 loc) · 2.46 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
AFRAME.registerComponent("gui", {
schema: {
name: { type: "string" },
properties: { type: "array" },
position: { type: "vec3" },
inheritPosition: { default: false }
},
init: function() {
// setup mouse interaction
var that = this;
this.el.sceneEl.addEventListener("camera-set-active", function() {
const scene = that.el.sceneEl.object3D;
const { camera, renderer } = that.el.sceneEl;
const gazeInput = dat.GUIVR.addInputObject(camera);
dat.GUIVR.enableMouse(camera, renderer);
scene.add(gazeInput.cursor);
['mousedown','touchstart']
.forEach( function(e){
window.addEventListener(e, function(){
gazeInput.pressed( true );
}, false );
});
['mouseup','touchend']
.forEach( function(e){
window.addEventListener(e, function(){
gazeInput.pressed( false );
}, false );
});
});
var scene = this.el.sceneEl.object3D;
var gui = dat.GUIVR.create(this.data.name);
//console.log("pos:", this.el.object3D.position.clone());
var guiPos = new THREE.Vector3(0, 0, 0);
if (this.data.position) {
["x", "y", "z"].forEach(function(axis) {
guiPos[axis] = this[axis];
}, this.data.position);
}
if (this.data.inheritPosition) {
["x", "y", "z"].forEach(function(axis) {
guiPos[axis] += this[axis];
}, this.el.object3D.position);
}
gui.position.set(guiPos.x, guiPos.y, guiPos.z);
//console.log("data:", this.data.properties);
var thisObject = this.el.object3D;
this.data.properties.forEach(function(prop) {
prop = prop.split(".");
console.log("len", prop.length);
var min = 0;
var max = 10;
if (prop.length == 1) {
gui.add(thisObject[prop[0]], min, max);
} else {
var propController = gui.add(thisObject[prop[0]], prop[1], min, max);
propController.name(prop[0] + "." + prop[1]);
}
});
gui.name = this.data.name + "GUI";
scene.add(gui);
}
});