-
Notifications
You must be signed in to change notification settings - Fork 15
/
dat-gui_panel.js
153 lines (133 loc) · 5.22 KB
/
dat-gui_panel.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
Q3D.gui = {
type: "dat-gui",
parameters: {
lyr: [],
cp: {
c: "#ffffff",
d: 0,
o: 1,
l: false
},
cmd: { // commands for touch screen devices
rot: false, // auto rotation
wf: false // wireframe mode
},
i: Q3D.application.showInfo
},
// initialize gui
// - setupDefaultItems: default is true
init: function (setupDefaultItems) {
this.gui = new dat.GUI();
this.gui.domElement.parentElement.style.zIndex = 1000; // display the panel on the front of labels
if (setupDefaultItems === undefined || setupDefaultItems == true) {
this.addLayersFolder();
this.addCustomPlaneFolder();
if (Q3D.isTouchDevice) this.addCommandsFolder();
this.addHelpButton();
}
},
addLayersFolder: function () {
var parameters = this.parameters;
var layersFolder = this.gui.addFolder('Layers');
var visibleChanged = function (value) { project.layers[this.object.i].setVisible(value); };
var opacityChanged = function (value) { project.layers[this.object.i].setOpacity(value); };
var sideVisibleChanged = function (value) { project.layers[this.object.i].setSideVisibility(value); };
project.layers.forEach(function (layer, i) {
parameters.lyr[i] = {i: i, v: layer.visible, o: layer.opacity};
var folder = layersFolder.addFolder(layer.name);
folder.add(parameters.lyr[i], 'v').name('Visible').onChange(visibleChanged);
if (layer.type == Q3D.LayerType.DEM) {
var itemName = '';
if (layer.blocks[0].sides) itemName = 'Sides and bottom';
else if (layer.blocks[0].frame) itemName = 'Frame';
if (itemName) {
parameters.lyr[i].sv = true;
folder.add(parameters.lyr[i], 'sv').name(itemName).onChange(sideVisibleChanged);
}
}
else if (layer.type == Q3D.LayerType.Polygon && layer.objType == 'Overlay') {
var j, f = layer.f, m = f.length;
for (j = 0; j < m; j++) {
if (f[j].mb === undefined) continue;
parameters.lyr[i].border = true;
folder.add(parameters.lyr[i], 'border').name('Borders').onChange(function (value) {
project.layers[this.object.i].setBorderVisibility(value);
});
break;
}
for (j = 0; j < m; j++) {
if (f[j].ms === undefined) continue;
parameters.lyr[i].side = true;
folder.add(parameters.lyr[i], 'side').name('Sides').onChange(function (value) {
project.layers[this.object.i].setSideVisibility(value);
});
break;
}
}
folder.add(parameters.lyr[i], 'o').min(0).max(1).name('Opacity').onChange(opacityChanged);
});
},
addCustomPlaneFolder: function () {
var customPlane;
var parameters = this.parameters;
var addPlane = function (color) {
// Add a new plane in the current scene
var geometry = new THREE.PlaneBufferGeometry(project.width, project.height, 1, 1),
material = new THREE.MeshLambertMaterial({color: color, transparent: true});
if (!Q3D.isIE) material.side = THREE.DoubleSide;
customPlane = new THREE.Mesh(geometry, material);
Q3D.application.scene.add(customPlane);
};
// Min/Max value for the plane
var layer = project.layers[0],
zMin = 0,
zMax = 9000;
if (layer.type == Q3D.LayerType.DEM) {
zMin = layer.stats.min;
zMax = layer.stats.max;
var buffer = (zMax - zMin) * 0.1;
if (buffer < 50) buffer = 50;
zMin -= buffer;
zMax += buffer;
}
parameters.cp.d = zMin;
// Create Custom Plane folder
var folder = this.gui.addFolder('Custom Plane');
// Plane color
folder.addColor(parameters.cp, 'c').name('Color').onChange(function (value) {
if (customPlane === undefined) addPlane(parameters.cp.c);
customPlane.material.color.setStyle(value);
});
// Plane height
folder.add(parameters.cp, 'd').min(zMin).max(zMax).name('Plane height').onChange(function (value) {
if (customPlane === undefined) addPlane(parameters.cp.c);
customPlane.position.z = (value + project.zShift) * project.zScale;
customPlane.updateMatrixWorld();
});
// Plane opacity
folder.add(parameters.cp, 'o').min(0).max(1).name('Opacity (0-1)').onChange(function (value) {
if (customPlane === undefined) addPlane(parameters.cp.c);
customPlane.material.opacity = value;
});
// Enlarge plane option
folder.add(parameters.cp, 'l').name('Enlarge').onChange(function (value) {
if (customPlane === undefined) addPlane(parameters.cp.c);
if (value) customPlane.scale.set(10, 10, 1);
else customPlane.scale.set(1, 1, 1);
customPlane.updateMatrixWorld();
});
},
// add commands folder for touch screen devices
addCommandsFolder: function () {
var folder = this.gui.addFolder('Commands');
if (Q3D.Controls.type == "OrbitControls") {
folder.add(this.parameters.cmd, 'rot').name('Auto Rotation').onChange(function (value) {
Q3D.application.controls.autoRotate = value;
});
}
folder.add(this.parameters.cmd, 'wf').name('Wireframe Mode').onChange(Q3D.application.setWireframeMode);
},
addHelpButton: function () {
this.gui.add(this.parameters, 'i').name('Help');
}
};