Visitar URL original
feat(core): add clipper config · ThatOpen/engine_components@288cb3d · GitHub
Skip to content

Commit 288cb3d

Browse files
committed
feat(core): add clipper config
1 parent df3350d commit 288cb3d

8 files changed

Lines changed: 154 additions & 14 deletions

File tree

‎packages/core/src/core/Clipper/example.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,34 +187,34 @@ const panel = BUI.Component.create<BUI.PanelSection>(() => {
187187
188188
<bim-checkbox label="Clipper enabled" checked
189189
@change="${({ target }: { target: BUI.Checkbox }) => {
190-
clipper.enabled = target.value;
190+
clipper.config.enabled = target.value;
191191
}}">
192192
</bim-checkbox>
193193
194194
<bim-checkbox label="Clipper visible" checked
195195
@change="${({ target }: { target: BUI.Checkbox }) => {
196-
clipper.visible = target.value;
196+
clipper.config.visible = target.value;
197197
}}">
198198
</bim-checkbox>
199199
200200
<bim-color-input
201201
label="Planes Color" color="#202932"
202202
@input="${({ target }: { target: BUI.ColorInput }) => {
203-
clipper.material.color.set(target.color);
203+
clipper.config.color = new THREE.Color(target.color);
204204
}}">
205205
</bim-color-input>
206206
207207
<bim-number-input
208208
slider step="0.01" label="Planes opacity" value="0.2" min="0.1" max="1"
209209
@change="${({ target }: { target: BUI.NumberInput }) => {
210-
clipper.material.opacity = target.value;
210+
clipper.config.opacity = target.value;
211211
}}">
212212
</bim-number-input>
213213
214214
<bim-number-input
215215
slider step="0.1" label="Planes size" value="5" min="2" max="10"
216216
@change="${({ target }: { target: BUI.NumberInput }) => {
217-
clipper.size = target.value;
217+
clipper.config.size = target.value;
218218
}}">
219219
</bim-number-input>
220220

‎packages/core/src/core/Clipper/index.ts‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as THREE from "three";
22
import {
33
Component,
4+
Configurable,
45
Createable,
56
Disposable,
67
Event,
@@ -11,6 +12,7 @@ import { SimplePlane } from "./src";
1112
import { Components } from "../Components";
1213
import { Raycasters } from "../Raycasters";
1314
import { Worlds } from "../Worlds";
15+
import { ClipperConfig, ClipperConfigManager } from "./src/clipper-config";
1416

1517
export * from "./src";
1618

@@ -22,14 +24,21 @@ export * from "./src";
2224
*/
2325
export class Clipper
2426
extends Component
25-
implements Createable, Disposable, Hideable
27+
implements
28+
Createable,
29+
Disposable,
30+
Hideable,
31+
Configurable<ClipperConfigManager, ClipperConfig>
2632
{
2733
/**
2834
* A unique identifier for the component.
2935
* This UUID is used to register the component within the Components system.
3036
*/
3137
static readonly uuid = "66290bc5-18c4-4cd1-9379-2e17a0617611" as const;
3238

39+
/** {@link Configurable.onSetup} */
40+
readonly onSetup = new Event();
41+
3342
/** Event that fires when the user starts dragging a clipping plane. */
3443
readonly onBeforeDrag = new Event<void>();
3544

@@ -71,6 +80,9 @@ export class Clipper
7180
/** {@link Disposable.onDisposed} */
7281
readonly onDisposed = new Event<string>();
7382

83+
/** {@link Configurable.isSetup} */
84+
isSetup = false;
85+
7486
/**
7587
* Whether to force the clipping plane to be orthogonal in the Y direction
7688
* (up). This is desirable when clipping a building horizontally and a
@@ -97,6 +109,15 @@ export class Clipper
97109
*/
98110
list: SimplePlane[] = [];
99111

112+
/** {@link Configurable.config} */
113+
config = new ClipperConfigManager(this, this.components, "Clipper");
114+
115+
protected _defaultConfig: ClipperConfig = {
116+
color: new THREE.Color(0xbb00ff),
117+
opacity: 0.2,
118+
size: 2,
119+
};
120+
100121
/** The material used in all the clipping planes. */
101122
private _material = new THREE.MeshBasicMaterial({
102123
color: 0xbb00ff,
@@ -253,6 +274,18 @@ export class Clipper
253274
}
254275
}
255276

277+
/** {@link Configurable.setup} */
278+
setup(config?: Partial<ClipperConfig>) {
279+
const fullConfig = { ...this._defaultConfig, ...config };
280+
281+
this.config.color = fullConfig.color;
282+
this.config.opacity = fullConfig.opacity;
283+
this.config.size = fullConfig.size;
284+
285+
this.isSetup = true;
286+
this.onSetup.trigger();
287+
}
288+
256289
private deletePlane(plane: SimplePlane) {
257290
const index = this.list.indexOf(plane);
258291
if (index !== -1) {
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// eslint-disable-next-line max-classes-per-file
2+
import * as THREE from "three";
3+
import {
4+
BooleanSettingsControl,
5+
ColorSettingsControl,
6+
NumberSettingControl,
7+
} from "../../Types";
8+
import { Configurator } from "../../ConfigManager";
9+
import { Clipper } from "../index";
10+
11+
type ClipperConfigType = {
12+
enabled: BooleanSettingsControl;
13+
visible: BooleanSettingsControl;
14+
color: ColorSettingsControl;
15+
opacity: NumberSettingControl;
16+
size: NumberSettingControl;
17+
};
18+
19+
/**
20+
* Configuration interface for the {@link Clipper}.
21+
*/
22+
export interface ClipperConfig {
23+
color: THREE.Color;
24+
opacity: number;
25+
size: number;
26+
}
27+
28+
export class ClipperConfigManager extends Configurator<
29+
Clipper,
30+
ClipperConfigType
31+
> {
32+
protected _config = {
33+
enabled: {
34+
value: true,
35+
type: "Boolean" as const,
36+
},
37+
visible: {
38+
value: true,
39+
type: "Boolean" as const,
40+
},
41+
color: {
42+
value: new THREE.Color() as THREE.Color,
43+
type: "Color" as const,
44+
},
45+
opacity: {
46+
type: "Number" as const,
47+
interpolable: true,
48+
value: 1,
49+
min: 0,
50+
max: 1,
51+
},
52+
size: {
53+
type: "Number" as const,
54+
interpolable: true,
55+
value: 2,
56+
min: 0,
57+
max: 100,
58+
},
59+
};
60+
61+
get enabled() {
62+
return this._config.enabled.value;
63+
}
64+
65+
set enabled(value: boolean) {
66+
this._config.enabled.value = value;
67+
this._component.enabled = value;
68+
}
69+
70+
get visible() {
71+
return this._config.visible.value;
72+
}
73+
74+
set visible(value: boolean) {
75+
this._config.visible.value = value;
76+
this._component.visible = value;
77+
}
78+
79+
get color() {
80+
return this._config.color.value;
81+
}
82+
83+
set color(value: THREE.Color) {
84+
this._config.color.value = value;
85+
this._component.material.color.copy(value);
86+
}
87+
88+
get opacity() {
89+
return this._config.opacity.value;
90+
}
91+
92+
set opacity(value: number) {
93+
this._config.opacity.value = value;
94+
this._component.material.opacity = value;
95+
}
96+
97+
get size() {
98+
return this._config.size.value;
99+
}
100+
101+
set size(value: number) {
102+
this._config.size.value = value;
103+
this._component.size = value;
104+
}
105+
}

‎packages/core/src/core/ConfigManager/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class ConfigManager extends Component {
1717
* A unique identifier for the component.
1818
* This UUID is used to register the component within the Components system.
1919
*/
20-
static readonly uuid = "dc86e7e9-a8fd-5473-9ef6-724c67fecb0f" as const;
20+
static readonly uuid = "b8c764e0-6b24-4e77-9a32-35fa728ee5b4" as const;
2121

2222
constructor(components: Components) {
2323
super(components);

‎packages/core/src/core/ConfigManager/src/configurator.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ export abstract class Configurator<T, U extends ControlsSchema> {
4848
const entry = controlEntry as ColorSettingsControl;
4949
return {
5050
type: entry.type,
51-
opacity: entry.opacity,
5251
value: entry.value.clone(),
5352
};
5453
}

‎packages/core/src/core/Types/src/config-types.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export interface BooleanSettingsControl {
77

88
export interface ColorSettingsControl {
99
type: "Color";
10-
opacity: number;
1110
value: THREE.Color;
1211
}
1312

‎packages/core/src/core/Worlds/src/simple-scene-config.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ export class SimpleSceneConfigManager extends Configurator<
130130
},
131131
intensity: {
132132
type: "Number" as const,
133-
interpolable: false,
133+
interpolable: true,
134+
min: 0,
135+
max: 10,
134136
value: 2,
135137
},
136138
},
@@ -142,7 +144,9 @@ export class SimpleSceneConfigManager extends Configurator<
142144
},
143145
intensity: {
144146
type: "Number" as const,
145-
interpolable: false,
147+
interpolable: true,
148+
min: 0,
149+
max: 10,
146150
value: 2,
147151
},
148152
position: {

‎packages/core/src/core/Worlds/src/simple-scene.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ export class SimpleScene
1313
extends BaseScene
1414
implements Configurable<SimpleSceneConfigManager, SimpleSceneConfig>
1515
{
16+
/** {@link Configurable.onSetup} */
17+
readonly onSetup = new Event();
18+
1619
/** {@link Configurable.isSetup} */
1720
isSetup = false;
1821

@@ -22,9 +25,6 @@ export class SimpleScene
2225
*/
2326
three: THREE.Scene;
2427

25-
/** {@link Configurable.onSetup} */
26-
readonly onSetup = new Event<SimpleScene>();
27-
2828
/** {@link Configurable.config} */
2929
config = new SimpleSceneConfigManager(this, this.components, "Scene");
3030

0 commit comments

Comments
 (0)