-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
Copy pathindex.js
74 lines (63 loc) · 1.54 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
//UI
var gui = new dat.GUI();
var options = {
texture: "standard",
mesh: "sphere",
hemisphericLight: true,
pointLight: false,
directionalLight: false,
castShadows: false,
spotLight: false,
fog: false,
skybox: false
}
var registeredUIs = {};
var textureui;
window.registerColorPicker = function(texture, name, color, onChange, onSet) {
if (!registeredUIs[texture]) {
registeredUIs[texture] = [];
}
registeredUIs[texture].push({
name: name,
color: "#ff0000",
onChange: onChange,
onSet: onSet
});
};
window.registerRangeUI = function(texture, name, minValue, maxValue, onChange, onSet) {
if (!registeredUIs[texture]) {
registeredUIs[texture] = [];
}
registeredUIs[texture].push({
name: name,
minValue: minValue,
maxValue: maxValue,
onChange: onChange,
onSet: onSet
});
}
var setUi = function(ui) {
options[ui.name] = ui.onSet();
if (ui.color) {
textureui.addColor(options, ui.name).onChange(function(value) {
ui.onChange(value);
});
} else {
textureui.add(options, ui.name, ui.minValue, ui.maxValue).onChange(function(value) {
ui.onChange(value);
});
}
}
window.enableTexture = function(texture) {
if (textureui) {
textureui.domElement.parentElement.removeChild(textureui.domElement);
textureui = null;
}
if (registeredUIs[texture]) {
textureui = new dat.GUI();
for (var index = 0; index < registeredUIs[texture].length; index++) {
var ui = registeredUIs[texture][index];
setUi(ui);
}
}
}