Commit b3825ec8 authored by iSergio's avatar iSergio
Browse files

Extend functional. Fix example.

parent f34d5a05
Loading
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -33,6 +33,9 @@ public class JsArray<T extends Object> {
    @JsProperty(name = "length")
    public native int length();

    @JsMethod
    public native T at(int index);

    /**
     * Fills all the elements of an array from a start index to an end index with a
     * static value.
+8 −0
Original line number Diff line number Diff line
@@ -19,8 +19,10 @@ package org.cesiumjs.cs.scene;
import jsinterop.annotations.*;
import org.cesiumjs.cs.core.BoundingRectangle;
import org.cesiumjs.cs.core.Color;
import org.cesiumjs.cs.core.PickedObject;
import org.cesiumjs.cs.core.enums.PixelDatatype;
import org.cesiumjs.cs.core.enums.PixelFormat;
import org.cesiumjs.cs.js.JsArray;
import org.cesiumjs.cs.js.JsObject;
import org.cesiumjs.cs.scene.enums.PostProcessStageSampleMode;
import org.cesiumjs.cs.scene.options.PostProcessStageOptions;
@@ -118,6 +120,12 @@ public class PostProcessStage implements PostProcess {
    @JsProperty(name = "scissorRectangle")
    public native BoundingRectangle scissorRectangle();

    /**
     * The features selected for applying the post-process.
     */
    @JsProperty
    public JsArray<PickedObject<?>> selected;

    /**
     * A number in the range (0.0, 1.0] used to scale the output texture dimensions.
     * A scale of 1.0 will render this post-process stage to a texture the size of
+17 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package org.cesiumjs.cs.scene;
import jsinterop.annotations.JsConstructor;
import jsinterop.annotations.JsMethod;
import jsinterop.annotations.JsType;
import org.cesiumjs.cs.js.JsArray;

/**
 * Contains functions for creating common post-process stages.
@@ -83,6 +84,19 @@ public class PostProcessStageLibrary {
    @JsMethod
    public static native PostProcessStageComposite createDepthOfFieldStage();

    /**
     * Creates a post-process stage that detects edges.
     *
     * <p>Writes the color to the output texture with alpha set to 1.0 when it is on an edge.</p>
     * <p>This stage has the following uniforms: color and length</p>
     * <p>color is the color of the highlighted edge. The default is Color#BLACK.
     * length is the length of the edges in pixels. The default is 0.5.
     * This stage is not supported in 2D.</p>
     * @return A post-process stage that applies an edge detection effect.
     */
    @JsMethod
    public static native PostProcessStage createEdgeDetectionStage();

    /**
     * Creates a post-process stage that applies an effect simulating light flaring
     * a camera lens. This stage has the following uniforms: dirtTexture,
@@ -126,6 +140,9 @@ public class PostProcessStageLibrary {
    @JsMethod
    public static native PostProcessStageComposite createSilhouetteStage();

    @JsMethod
    public static native PostProcessStageComposite createSilhouetteStage(JsArray<PostProcessStage> array);

    /**
     * Whether or not an ambient occlusion stage is supported. This stage requires
     * the WEBGL_depth_texture extension.
+135 −91
Original line number Diff line number Diff line
@@ -24,17 +24,20 @@ import com.google.gwt.user.client.ui.RootPanel;
import org.cesiumjs.cs.Cesium;
import org.cesiumjs.cs.core.Cartesian3;
import org.cesiumjs.cs.core.Color;
import org.cesiumjs.cs.core.IonResource;
import org.cesiumjs.cs.core.Matrix4;
import org.cesiumjs.cs.core.ScreenSpaceEventHandler;
import org.cesiumjs.cs.core.enums.ScreenSpaceEventType;
import org.cesiumjs.cs.core.events.MouseClickEvent;
import org.cesiumjs.cs.core.events.MouseMoveEvent;
import org.cesiumjs.cs.datasources.Entity;
import org.cesiumjs.cs.datasources.properties.ConstantProperty;
import org.cesiumjs.cs.js.JsArray;
import org.cesiumjs.cs.js.JsObject;
import org.cesiumjs.cs.promise.Function;
import org.cesiumjs.cs.scene.Cesium3DTileFeature;
import org.cesiumjs.cs.scene.Cesium3DTileset;
import org.cesiumjs.cs.scene.PostProcessStage;
import org.cesiumjs.cs.scene.PostProcessStageLibrary;
import org.cesiumjs.cs.scene.options.ViewOptions;
import org.cesiumjs.cs.widgets.ViewerPanel;
import org.cleanlogic.cesiumjs4gwt.showcase.basic.AbstractExample;
@@ -46,6 +49,7 @@ import javax.inject.Inject;
 * @author Serge Silaev aka iSergio
 */
public class Tiles3DFeaturePicking extends AbstractExample {
    private ViewerPanel csVPanel;
    // HTML overlay for showing feature name on mouseover
    private DivElement nameOverlay;
    // Information about the currently selected feature
@@ -56,6 +60,9 @@ public class Tiles3DFeaturePicking extends AbstractExample {
    // for infobox display
    private final Entity selectedEntity = new Entity();

    private PostProcessStage silhouetteBlue = null;
    private PostProcessStage silhouetteGreen = null;

    @Inject
    public Tiles3DFeaturePicking(ShowcaseExampleStore store) {
        super("3D Tiles Feature Picking", "Pick features in a 3D Tiles tileset.",
@@ -64,7 +71,7 @@ public class Tiles3DFeaturePicking extends AbstractExample {

    @Override
    public void buildPanel() {
        final ViewerPanel csVPanel = new ViewerPanel();
        csVPanel = new ViewerPanel();

        nameOverlay = RootPanel.get().getElement().getOwnerDocument().createDivElement();
        csVPanel.getViewer().container().appendChild(nameOverlay);
@@ -87,12 +94,55 @@ public class Tiles3DFeaturePicking extends AbstractExample {
        csVPanel.getViewer().scene().camera().setView(viewOptions);

        // Load the NYC buildings tileset
        Cesium3DTileset tileset = (Cesium3DTileset) csVPanel.getViewer().scene().primitives().add(Cesium3DTileset.create(
                "https://beta.cesium.com/api/assets/1461?access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJkYWJmM2MzNS02OWM5LTQ3OWItYjEyYS0xZmNlODM5ZDNkMTYiLCJpZCI6NDQsImFzc2V0cyI6WzE0NjFdLCJpYXQiOjE0OTkyNjQ3NDN9.vuR75SqPDKcggvUrG_vpx0Av02jdiAxnnB1fNf-9f7s"));
        Cesium3DTileset tileset = Cesium3DTileset.create(IonResource.fromAssetId(75343));
        csVPanel.getViewer().scene().primitives().add(tileset);

        if (PostProcessStageLibrary.isSilhouetteSupported(csVPanel.getViewer().scene())) {
            silhouetteBlue = PostProcessStageLibrary.createEdgeDetectionStage();
            silhouetteBlue.uniforms().setProperty("color", Color.BLUE());
            silhouetteBlue.uniforms().setProperty("length", 0.01);
            silhouetteBlue.selected = new JsArray<>();

            silhouetteGreen = PostProcessStageLibrary.createEdgeDetectionStage();
            silhouetteGreen.uniforms().setProperty("color", Color.LIME());
            silhouetteGreen.uniforms().setProperty("length", 0.01);
            silhouetteGreen.selected = new JsArray<>();

            JsArray<PostProcessStage> stages = new JsArray<>();
            stages.push(silhouetteBlue, silhouetteGreen);
            csVPanel.getViewer().scene().postProcessStages.add(PostProcessStageLibrary.createSilhouetteStage(stages));
        }

        csVPanel.getViewer().screenSpaceEventHandler().setInputAction(this::onMouseMove, ScreenSpaceEventType.MOUSE_MOVE());
        csVPanel.getViewer().screenSpaceEventHandler().setInputAction(this::onMouseLeftClick, ScreenSpaceEventType.LEFT_CLICK());

        contentPanel.add(new HTML("<p>Pick features in a 3D Tiles tileset.</p>"));
        contentPanel.add(csVPanel);

        initWidget(contentPanel);
    }

        csVPanel.getViewer().screenSpaceEventHandler().setInputAction(new ScreenSpaceEventHandler.Listener() {
    @Override
            public void function(Object event) {
    public String[] getSourceCodeURLs() {
        String[] sourceCodeURLs = new String[1];
        sourceCodeURLs[0] = GWT.getModuleBaseURL() + "examples/" + "Tiles3DFeaturePicking.txt";
        return sourceCodeURLs;
    }

    private static class Selected {
        Cesium3DTileFeature feature = (Cesium3DTileFeature) JsObject.undefined();
        Color originalColor = new Color();
    }

    private static class Highlighted {
        Cesium3DTileFeature feature = (Cesium3DTileFeature) JsObject.undefined();
        Color originalColor = new Color();
    }

    private void onMouseMove(Object event) {
        if (silhouetteBlue != null) {
            silhouetteBlue.selected = new JsArray<>();
        }
        MouseMoveEvent movement = (MouseMoveEvent) event;
        // If a feature was previously highlighted, undo the highlight
        if (Cesium.defined(highlighted.feature)) {
@@ -113,7 +163,7 @@ public class Tiles3DFeaturePicking extends AbstractExample {
        nameOverlay.getStyle().setBottom(csVPanel.getViewer().canvas().getClientHeight() - movement.endPosition.y + 26,
                Style.Unit.PX);
        nameOverlay.getStyle().setLeft(movement.endPosition.x + 26, Style.Unit.PX);
                String name = pickedFeature.getProperty("name").toString();
        String name = pickedFeature.getProperty("BIN").toString();
        if (!Cesium.defined(name)) {
            name = pickedFeature.getProperty("id").toString();
        }
@@ -121,18 +171,20 @@ public class Tiles3DFeaturePicking extends AbstractExample {

        // Highlight the feature if it's not already selected.
        if (!pickedFeature.equals(selected.feature)) {
            if (silhouetteBlue != null) {
                silhouetteBlue.selected.push(pickedFeature);
            } else {
                highlighted.feature = pickedFeature;
                Color.clone(pickedFeature.color, highlighted.originalColor);
                pickedFeature.color = Color.YELLOW();
            }
        }
        }, ScreenSpaceEventType.MOUSE_MOVE());
    }

        final Function clickHandler = csVPanel.getViewer().screenSpaceEventHandler()
                .getInputAction(ScreenSpaceEventType.LEFT_CLICK());
        csVPanel.getViewer().screenSpaceEventHandler().setInputAction(new ScreenSpaceEventHandler.Listener() {
            @Override
            public void function(Object event) {
    private void onMouseLeftClick(Object event) {
        if (silhouetteGreen != null) {
            silhouetteGreen.selected = new JsArray<>();
        }
        MouseClickEvent movement = (MouseClickEvent) event;
        // If a feature was previously selected, undo the highlight
        if (Cesium.defined(selected.feature)) {
@@ -140,6 +192,9 @@ public class Tiles3DFeaturePicking extends AbstractExample {
            selected.feature = (Cesium3DTileFeature) JsObject.undefined();
        }

        final Function clickHandler = csVPanel.getViewer().screenSpaceEventHandler()
                .getInputAction(ScreenSpaceEventType.LEFT_CLICK());

        // Pick a new feature
        Cesium3DTileFeature pickedFeature = (Cesium3DTileFeature) csVPanel.getViewer().scene().pick(movement.position);
        if (!Cesium.defined(pickedFeature)) {
@@ -148,6 +203,21 @@ public class Tiles3DFeaturePicking extends AbstractExample {
            return;
        }

        if (silhouetteGreen != null) {
            // Select the feature if it's not already selected
            if (pickedFeature.equals(silhouetteGreen.selected.at(0))) {
                return;
            }

            // Save the selected feature's original color
            Cesium3DTileFeature highlightedFeature = (Cesium3DTileFeature) silhouetteBlue.selected.at(0);
            if (pickedFeature.equals(highlightedFeature)) {
                silhouetteBlue.selected = new JsArray<>();
            }

            // Highlight newly selected feature
            silhouetteGreen.selected.push(pickedFeature);
        } else {
            // Select the feature if it's not already selected
            if (selected.feature == pickedFeature) {
                return;
@@ -161,13 +231,11 @@ public class Tiles3DFeaturePicking extends AbstractExample {
            } else {
                Color.clone(pickedFeature.color, selected.originalColor);
            }

            // Highlight newly selected feature
            pickedFeature.color = Color.LIME();
        }

        // Set feature infobox description
                String featureName = pickedFeature.getProperty("name").toString();
                selectedEntity.name = featureName;
        selectedEntity.description = new ConstantProperty<>("Loading <div class=\"cesium-infoBox-loading\"></div>");
        csVPanel.getViewer().selectedEntity = selectedEntity;
        selectedEntity.description = new ConstantProperty<>(
@@ -176,28 +244,4 @@ public class Tiles3DFeaturePicking extends AbstractExample {
                        + pickedFeature.getProperty("DOITT_ID").toString() + "</td></tr>" + "<tr><th>SOURCE ID</th><td>"
                        + pickedFeature.getProperty("SOURCE_ID").toString() + "</td></tr>" + "</tbody></table>");
    }
        }, ScreenSpaceEventType.LEFT_CLICK());

        contentPanel.add(new HTML("<p>Pick features in a 3D Tiles tileset.</p>"));
        contentPanel.add(csVPanel);

        initWidget(contentPanel);
    }

    @Override
    public String[] getSourceCodeURLs() {
        String[] sourceCodeURLs = new String[1];
        sourceCodeURLs[0] = GWT.getModuleBaseURL() + "examples/" + "Tiles3DFeaturePicking.txt";
        return sourceCodeURLs;
    }

    private static class Selected {
        Cesium3DTileFeature feature = (Cesium3DTileFeature) JsObject.undefined();
        Color originalColor = new Color();
    }

    private static class Highlighted {
        Cesium3DTileFeature feature = (Cesium3DTileFeature) JsObject.undefined();
        Color originalColor = new Color();
    }
}
 No newline at end of file
+166 −97

File changed.

Preview size limit exceeded, changes collapsed.