11import * as THREE from "three" ;
22import {
33 Component ,
4+ Configurable ,
45 Createable ,
56 Disposable ,
67 Event ,
@@ -11,6 +12,7 @@ import { SimplePlane } from "./src";
1112import { Components } from "../Components" ;
1213import { Raycasters } from "../Raycasters" ;
1314import { Worlds } from "../Worlds" ;
15+ import { ClipperConfig , ClipperConfigManager } from "./src/clipper-config" ;
1416
1517export * from "./src" ;
1618
@@ -22,14 +24,21 @@ export * from "./src";
2224 */
2325export 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 ) {
0 commit comments