generated from stadtentwicklung/map3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dat-gui_panel.js
126 lines (107 loc) · 4.34 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
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
// - params: parameter values to pass to dat.GUI constructor
init: function (setupDefaultItems, params) {
this.gui = new dat.GUI(params);
this.gui.domElement.parentElement.style.zIndex = 2000; // display the panel on the front of labels
if (setupDefaultItems === undefined || setupDefaultItems == true) {
this.layersFolder = this.gui.addFolder('Layers');
this.customPlaneFolder = this.gui.addFolder('Custom Plane');
if (Q3D.isTouchDevice) this.addCommandsFolder();
this.addHelpButton();
}
},
initLayersFolder: function (scene) {
var mapLayers = scene.mapLayers;
var parameters = this.parameters;
var visibleChanged = function (value) { mapLayers[this.object.i].visible = value; };
var opacityChanged = function (value) { mapLayers[this.object.i].opacity = value; };
var layer, subfolder;
for (var layerId in mapLayers) {
layer = mapLayers[layerId];
parameters.lyr[layerId] = {i: layerId, v: layer.visible, o: layer.opacity};
subfolder = this.layersFolder.addFolder(layer.properties.name);
subfolder.add(parameters.lyr[layerId], 'v').name('Visible').onChange(visibleChanged);
subfolder.add(parameters.lyr[layerId], 'o').min(0).max(1).name('Opacity').onChange(opacityChanged);
}
return this.layersFolder;
},
customPlaneMaterial: function (color) {
var m = new THREE.MeshLambertMaterial({color: color, transparent: true})
if (!Q3D.isIE) m.side = THREE.DoubleSide;
return m;
},
initCustomPlaneFolder: function (zMin, zMax) {
var app = Q3D.application,
gui = Q3D.gui;
var scene = app.scene,
p = scene.userData,
parameters = gui.parameters;
if (zMin === undefined || zMax === undefined) {
var box = new THREE.Box3().setFromObject(scene);
if (zMin === undefined) zMin = scene.toMapCoordinates(0, 0, box.min.z).z;
if (zMax === undefined) zMax = scene.toMapCoordinates(0, 0, box.max.z).z;
}
var addPlane = function (color) {
// Add a new plane in the current scene
var geometry = new THREE.PlaneBufferGeometry(p.width,p.height, 1, 1),
material = gui.customPlaneMaterial(color);
gui.customPlane = new THREE.Mesh(geometry, material);
scene.add(gui.customPlane);
app.render();
};
parameters.cp.d = zMin;
// Plane color
this.customPlaneFolder.addColor(parameters.cp, 'c').name('Color').onChange(function (value) {
if (gui.customPlane === undefined) addPlane(parameters.cp.c);
gui.customPlane.material.color.setStyle(value);
app.render();
});
// Plane altitude
this.customPlaneFolder.add(parameters.cp, 'd').min(zMin).max(zMax).name('Altitude').onChange(function (value) {
if (gui.customPlane === undefined) addPlane(parameters.cp.c);
gui.customPlane.position.z = (value + p.zShift) * p.zScale;
gui.customPlane.updateMatrixWorld();
app.render();
});
// Plane opacity
this.customPlaneFolder.add(parameters.cp, 'o').min(0).max(1).name('Opacity (0-1)').onChange(function (value) {
if (gui.customPlane === undefined) addPlane(parameters.cp.c);
gui.customPlane.material.opacity = value;
app.render();
});
// Enlarge plane option
this.customPlaneFolder.add(parameters.cp, 'l').name('Enlarge').onChange(function (value) {
if (gui.customPlane === undefined) addPlane(parameters.cp.c);
if (value) gui.customPlane.scale.set(80, 80, 1);
else gui.customPlane.scale.set(1, 1, 1);
gui.customPlane.updateMatrixWorld();
app.render();
});
},
// add commands folder for touch screen devices
addCommandsFolder: function () {
var folder = this.gui.addFolder('Commands');
folder.add(this.parameters.cmd, 'rot').name('Rotate Animation').onChange(Q3D.application.setRotateAnimationMode);
folder.add(this.parameters.cmd, 'wf').name('Wireframe Mode').onChange(Q3D.application.setWireframeMode);
},
addHelpButton: function () {
this.gui.add(this.parameters, 'i').name('Help');
}
};