Commit 7fe8c118 authored by iSergio's avatar iSergio
Browse files

Added ClippingPolygon and ClippingPolygonCollection for applying multiple...

Added ClippingPolygon and ClippingPolygonCollection for applying multiple clipping regions, with support for concave regions and inverse clipping regions, to 3D Tiles and Terrain
parent 35758e98
Loading
Loading
Loading
Loading
+44 −0
Original line number Diff line number Diff line
/*
 * Copyright 2024 iSergio, Gis4Fun.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.cesiumjs.cs.collections;

import jsinterop.annotations.JsConstructor;
import jsinterop.annotations.JsType;
import org.cesiumjs.cs.scene.Scene;
import org.cesiumjs.cs.scene.options.ClippingPolygon;
import org.cesiumjs.cs.scene.options.ClippingPolygonOptions;

/**
 * Specifies a set of clipping polygons. Clipping polygons selectively disable rendering in a region inside or outside
 * the specified list of ClippingPolygon objects for a single glTF model, 3D Tileset, or the globe. Clipping Polygons
 * are only supported in WebGL 2 contexts.
 */
@JsType(isNative = true, namespace = "Cesium", name = "ClippingPolygonCollection")
public class ClippingPolygonCollection extends Collection<ClippingPolygon> {
    /**
     * Function for checking if the context will allow clipping polygons, which require floating point textures.
     * @param scene The scene that will contain clipped objects and clipping textures.
     * @return true if the context supports clipping polygons.
     */
    public static native boolean isSupported(Scene scene);

    @JsConstructor
    public ClippingPolygonCollection() {}

    @JsConstructor
    public ClippingPolygonCollection(ClippingPolygonOptions options) {}
}
+49 −0
Original line number Diff line number Diff line
/*
 * Copyright 2024 iSergio, Gis4Fun.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.cesiumjs.cs.collections.options;

import jsinterop.annotations.JsConstructor;
import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsProperty;
import jsinterop.annotations.JsType;
import org.cesiumjs.cs.scene.options.ClippingPolygon;

@JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object")
public class ClippingPolygonCollectionOptions {
    /**
     * An array of ClippingPolygon objects used to selectively disable rendering on the inside of each polygon.
     */
    @JsProperty
    public ClippingPolygon[] polygons;

    /**
     * Determines whether the clipping polygons are active.
     * Default: true
     */
    @JsProperty
    public boolean enabled;

    /**
     * If true, a region will be clipped if it is outside of every polygon in the collection. Otherwise, a region will only be clipped if it is on the inside of any polygon.
     * Default: false
     */
    @JsProperty
    public boolean inverse;

    @JsConstructor
    public ClippingPolygonCollectionOptions() {}
}
+100 −0
Original line number Diff line number Diff line
/*
 * Copyright 2024 iSergio, Gis4Fun.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.cesiumjs.cs.scene.options;

import jsinterop.annotations.*;
import org.cesiumjs.cs.core.Cartesian3;
import org.cesiumjs.cs.core.Ellipsoid;
import org.cesiumjs.cs.core.Plane;
import org.cesiumjs.cs.core.Rectangle;

/**
 * A geodesic polygon to be used with ClippingPlaneCollection for selectively hiding regions in a model, a 3D tileset, or the globe.
 */
@JsType(isNative = true, namespace = "Cesium", name = "ClippingPolygon")
public class ClippingPolygon {
    /**
     * Returns the ellipsoid used to project the polygon onto surfaces when clipping.
     */
    @JsProperty(name = "ellipsoid")
    public native Ellipsoid ellipsoid();

    /**
     * Returns the total number of positions in the polygon, include any holes.
     */
    @JsProperty(name = "length")
    public native Number length();

    /**
     * Returns the outer ring of positions.
     */
    @JsProperty(name = "positions")
    public native Cartesian3[] positions();

    @JsConstructor
    public ClippingPolygon(ClippingPolygonOptions options) {
    }

    @JsOverlay
    public static ClippingPolygon create(Cartesian3[] positions) {
        ClippingPolygonOptions options = ClippingPolygonOptions.create(positions);
        return new ClippingPolygon(options);
    }

    /**
     * Clones the ClippingPolygon without setting its ownership.
     * @param polygon The ClippingPolygon to be cloned
     * @return a clone of the input ClippingPolygon
     */
    @JsMethod
    public static native ClippingPolygon clone(ClippingPolygon polygon);

    /**
     * Clones the ClippingPolygon without setting its ownership.
     * @param polygon The ClippingPolygon to be cloned
     * @param result The object on which to store the cloned parameters.
     * @return a clone of the input ClippingPolygon
     */
    @JsMethod
    public static native ClippingPolygon clone(ClippingPolygon polygon, ClippingPolygon result);

    /**
     * Compares the provided ClippingPolygons and returns true if they are equal, false otherwise.
     * @param left The first polygon.
     * @param right The second polygon.
     * @return true if left and right are equal, false otherwise.
     */
    @JsMethod
    public static native boolean equals(Plane left, Plane right);

    /**
     * Computes a cartographic rectangle which encloses the polygon defined by the list of positions,
     * including cases over the international date line and the poles.
     * @return The result rectangle
     */
    @JsMethod
    public native org.cesiumjs.cs.core.Rectangle computeRectangle();

    /**
     * Computes a cartographic rectangle which encloses the polygon defined by the list of positions,
     * including cases over the international date line and the poles.
     * @param result An object in which to store the result.
     * @return The result rectangle
     */
    @JsMethod
    public native org.cesiumjs.cs.core.Rectangle computeRectangle(Rectangle result);
}
+55 −0
Original line number Diff line number Diff line
/*
 * Copyright 2024 iSergio, Gis4Fun.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.cesiumjs.cs.scene.options;

import jsinterop.annotations.*;
import org.cesiumjs.cs.core.Cartesian3;
import org.cesiumjs.cs.core.Ellipsoid;

@JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object")
public class ClippingPolygonOptions {
    /**
     * A list of three or more Cartesian coordinates defining the outer ring of the clipping polygon.
     */
    @JsProperty
    public Cartesian3[] positions;

    /**
     * Default: {@link org.cesiumjs.cs.core.Ellipsoid#WGS84()}
     */
    @JsProperty
    public Ellipsoid ellipsoid;

    @JsConstructor
    public ClippingPolygonOptions() {
    }

    @JsOverlay
    public static ClippingPolygonOptions create(Cartesian3[] positions) {
        ClippingPolygonOptions options = new ClippingPolygonOptions();
        options.positions = positions;
        return options;
    }

    @JsOverlay
    public static ClippingPolygonOptions create(Cartesian3[] positions, Ellipsoid ellipsoid) {
        ClippingPolygonOptions options = new ClippingPolygonOptions();
        options.positions = positions;
        options.ellipsoid = ellipsoid;
        return options;
    }
}