-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
83 lines (71 loc) · 2.23 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
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
import * as AFRAME from "AFRAME";
import { attachEffects, attach } from "three-effects";
AFRAME.registerSystem("fx", {
schema: {
type: 'array',
default: []
},
init: function () {
this.timeUniform = { value: 0 };
this.fx = attachEffects(this.sceneEl.object3D);
},
update: function () {
this.fx(this.data.length ? this.data : null);
},
tick: function (t) {
this.timeUniform.value = t;
}
});
AFRAME.registerComponent("fx", {
schema: {
},
multiple: true,
init: function () {
var att = attach[this.id];
this.control = att(this.el.object3D);
var ud = this.el.object3D.userData[this.id];
var schema = {}, t;
for( var k in ud) {
var p = ud[k];
if(p.value.isVector2) {
t = "vec2";
} else if(p.value.isVector3) {
t = "vec3";
} else if(p.value.isVector4) {
t = "vec4";
} else if(p.value.isColor) {
t = "color";
}else if(p.value.isTexture) {
t = "asset";
p.value.image.addEventListener("load", function () {
p.value.needsUpdate = true;
})
} else {
t = "number";
}
schema[k] = { type: t, default: p.value.getHexString ? "#" + p.value.getHexString() : p.value };
}
this.updateSchema(schema);
},
update: function () {
var ud = this.el.object3D.userData[this.id];
for(var k in this.schema) {
var s = this.schema[k];
if(s.type === "asset") {
if(!ud[k].value.isCanvasTexture && ud[k].value.isDataTexture) {
if(ud[k].value.image.src !== this.data[k]) ud[k].value.image.src = this.data[k];
}
} else if(s.type === "color") {
ud[k].value.set(this.data[k]);
} else if(s.type === "number") {
ud[k].value = this.data[k];
} else {
ud[k].value.copy(this.data[k]);
}
}
ud.needsUpdate = true;
},
remove: function () {
this.control(null);
}
});