-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyGuiInterface.js
More file actions
66 lines (54 loc) · 1.87 KB
/
MyGuiInterface.js
File metadata and controls
66 lines (54 loc) · 1.87 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
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
/**
This class customizes the gui interface for the app
*/
class MyGuiInterface {
/**
*
* @param {MyApp} app The application object
*/
constructor(app) {
this.app = app;
this.datgui = new GUI();
this.contents = null;
}
/**
* Set the contents object
* @param {MyContents} contents the contents objects
*/
setContents(contents) {
this.contents = contents;
}
/**
* Initialize the gui interface
*/
init() {
// adds a folder to the gui interface for the camera
const cameraFolder = this.datgui.addFolder('Camera');
cameraFolder.add(this.app, 'activeCameraName', [ 'Perspective', 'Perspective 2', 'Left', 'Top', 'Front', 'Back', 'Right' ] ).name("active camera");
// note that we are using a property from the app
cameraFolder.add(this.app.activeCamera.position, 'x', 0, 10).name("x coord");
const objectsFolder = this.datgui.addFolder('Objects');
const toggleVisibility = {
visible: true,
}
const controllers = [];
objectsFolder.add(toggleVisibility, 'visible').name('ALL').onChange((value) => {
if (this.contents && this.contents.objects) {
this.contents.objects.forEach((object, index) => {
object.visible = value;
controllers[index].updateDisplay();
});
}
});
console.log(this.contents);
if (this.contents && this.contents.objects) {
this.contents.objects.forEach((object) => {
const controller = objectsFolder.add(object, 'visible').name(object.name);
controllers.push(controller);
});
}
objectsFolder.close();
}
}
export { MyGuiInterface };