]>
Commit | Line | Data |
---|---|---|
362f9116 RBR |
1 | import { System } from '@serpentity/serpentity'; |
2 | import Cameras from '../nodes/cameras'; | |
3 | import { settingsContainer, slider } from '../factories/ui'; | |
4 | ||
5 | const internals = { | |
6 | symbols: { | |
7 | x: '𝜃', | |
8 | y: '𝜓', | |
9 | z: '𝜙' | |
10 | } | |
11 | }; | |
12 | ||
32e2eed2 RBR |
13 | /** |
14 | * UI that adjusts the parameters of the camera | |
15 | */ | |
362f9116 RBR |
16 | export default class CameraAdjuster extends System { |
17 | ||
18 | constructor(container) { | |
19 | ||
20 | super(); | |
21 | this.container = container; | |
22 | } | |
23 | ||
24 | added(engine){ | |
25 | ||
26 | this.nodes = engine.getNodes(Cameras); | |
27 | this.adjusterContainer = settingsContainer({ | |
28 | id: 'camera-adjuster', | |
29 | label: 'Camera' | |
30 | }) | |
31 | ||
32 | let i = 0; | |
33 | for (const node of this.nodes) { | |
34 | const nodeElement = settingsContainer({ | |
35 | id: `camera-adjuster-${i}`, | |
36 | label: `C${i + 1}`, | |
37 | level: 3 | |
38 | }); | |
39 | ||
40 | nodeElement.appendChild(slider({ | |
6a87c253 | 41 | id: `camera-adjuster-${i}-slider-radius`, |
362f9116 RBR |
42 | min: '2', |
43 | max: '10', | |
44 | step: '0.1', | |
45 | label: '𝑟', | |
46 | className: 'radius', | |
47 | get: () => node.radius.radius.toString(), | |
48 | set: (value) => (node.radius.radius = parseFloat(value)) | |
49 | })); | |
50 | ||
51 | ['x', 'y', 'z'].forEach(key => { | |
52 | nodeElement.appendChild(slider({ | |
6a87c253 | 53 | id: `camera-adjuster-${i}-slider-${key}`, |
362f9116 RBR |
54 | min: '0', |
55 | max: '0.5', | |
56 | step: '0.001', | |
57 | label: internals.symbols[key], | |
58 | className: `rotation-${key}`, | |
59 | get: () => node.velocity[key].toString(), | |
60 | set: (value) => (node.velocity[key] = parseFloat(value)) | |
61 | })); | |
62 | }); | |
63 | ||
64 | this.adjusterContainer.appendChild(nodeElement); | |
65 | ++i; | |
66 | } | |
67 | ||
68 | this.container.appendChild(this.adjusterContainer); | |
69 | } | |
70 | ||
71 | removed(){ | |
72 | ||
73 | this.container.removeChild(this.adjusterContainer); | |
74 | delete this.adjusterContainer; | |
75 | delete this.nodes; | |
76 | } | |
77 | ||
78 | update(){} | |
79 | }; |