import { makePropertyChangeObservable } from '../PropertyChangeObservable';
import { Plane, Vector3 } from './babylonjs-import';
/**
 * Represents a single clipping plane in a 3D scene.
 *
 * A ClipPlane defines a plane by position and normal, and can be enabled or disabled.
 * When enabled, geometry intersecting the plane is clipped and the intersection is colored using the plane's color.
 * The `fadeSize` property controls how much the color is smudged (faded) over the clipped area.
 *
 * ClipPlane instances are used to clip IFC geometry in a scene.
 */
export class ClipPlane {
    /**
     * Whether this clip plane is enabled and actively clipping geometry.
     */
    enabled;
    /**
     * The name/index of this clip plane (e.g. 'clipPlane', 'clipPlane2', ...).
     */
    index;
    /**
     * The position (origin) of the clip plane in 3D space.
     */
    position;
    /**
     * The normal vector of the clip plane. Should always be normalized.
     */
    normal;
    /**
     * The color applied to the intersection where geometry is clipped by this plane.
     */
    color;
    /**
     * The underlying Babylon.js Plane object representing this clip plane.
     */
    plane;
    /**
     * Controls how much the clip color is faded (smudged) over the clipped area. Higher values increase the fade distance.
     */
    fadeSize;
    /**
     * If `true`, disables depth writing for geometry clipped by this plane.
     */
    ignoreDepthWrite;
    /**
     * Set of all valid clip plane names supported by the system.
     */
    static allClipPlanes = new Set();
    static _clipPlanes = {};
    /**
     * Creates a set of observable ClipPlane instances from a configuration object.
     * @param o An object mapping clip plane names to their initial color.
     * @returns A map of clip plane names to observable ClipPlane instances.
     */
    static create(o) {
        const clipPlanes = {};
        for (const [planeName, plane] of ClipPlane.entries(o)) {
            clipPlanes[planeName] = makePropertyChangeObservable(new ClipPlane(planeName, plane.color));
        }
        return clipPlanes;
    }
    static {
        ClipPlane.allClipPlanes.add('clipPlane');
        ClipPlane.allClipPlanes.add('clipPlane2');
        ClipPlane.allClipPlanes.add('clipPlane3');
        ClipPlane.allClipPlanes.add('clipPlane4');
        ClipPlane.allClipPlanes.add('clipPlane5');
        ClipPlane.allClipPlanes.add('clipPlane6');
    }
    /**
     * Constructs a new ClipPlane.
     * @param index The name/index of the clip plane.
     * @param color The color to use for the clipped intersection.
     */
    constructor(index, color) {
        this.index = index;
        this.enabled = false;
        this.plane = new Plane(0.0, 0.0, 0.0, 0.0);
        this.color = color;
        this.position = new Vector3(0.0, 0.0, 0.0);
        this.normal = new Vector3(0.0, 0.0, 0.0);
        this.fadeSize = 0.25;
        this.ignoreDepthWrite = false;
    }
    /**
     * Iterates over all valid entries in a ClipPlanes object.
     * @param o The ClipPlanes object to iterate.
     */
    static *entries(o) {
        for (const clipPlane of ClipPlane.allClipPlanes) {
            const plane = o[clipPlane];
            if (plane != null) {
                yield [clipPlane, plane];
            }
        }
    }
    /**
     * Iterates over all valid values in a ClipPlanes object.
     * @param o The ClipPlanes object to iterate.
     */
    static *values(o) {
        for (const clipPlane of ClipPlane.allClipPlanes) {
            const plane = o[clipPlane];
            if (plane != null) {
                yield plane;
            }
        }
    }
    /**
     * Looks up a ClipPlane by name.
     * @param name The name of the clip plane.
     * @returns The ClipPlane instance.
     * @throws If the clip plane does not exist.
     */
    static entry(name) {
        const clipPlane = ClipPlane._clipPlanes[name];
        if (clipPlane) {
            return clipPlane;
        }
        else {
            throw new Error('Clipplane for ' + name + ' missing');
        }
    }
}
//# sourceMappingURL=ClipPlane.js.map