Search in sources :

Example 1 with MouseDownEvent

use of org.cesiumjs.cs.core.events.MouseDownEvent in project gwt-cs by iSergio.

the class Tiles3DClippingPlanes method buildPanel.

@Override
public void buildPanel() {
    ViewerOptions viewerOptions = new ViewerOptions();
    viewerOptions.skyAtmosphere = null;
    viewerOptions.infoBox = false;
    viewerOptions.selectionIndicator = false;
    csVPanel = new ViewerPanel(viewerOptions);
    ScreenSpaceEventHandler downHandler = new ScreenSpaceEventHandler(csVPanel.getViewer().canvas());
    downHandler.setInputAction(new ScreenSpaceEventHandler.Listener() {

        @Override
        public void function(Object event) {
            MouseDownEvent mouseDownEvent = (MouseDownEvent) event;
            PickedObject pickedObject = csVPanel.getViewer().scene().pick(mouseDownEvent.position);
            if (!Cesium.defined(pickedObject)) {
                return;
            }
            if (!(pickedObject.id instanceof Entity)) {
                return;
            }
            if (Cesium.defined(pickedObject) && Cesium.defined(pickedObject.id) && Cesium.defined(((Entity) pickedObject.id).plane)) {
                selectedPlane = ((Entity) pickedObject.id).plane;
                selectedPlane.material = new ColorMaterialProperty(Color.WHITE().withAlpha(0.05f));
                selectedPlane.outlineColor = new ConstantProperty<>(Color.WHITE());
                csVPanel.getViewer().scene().screenSpaceCameraController().enableInputs = false;
            }
        }
    }, ScreenSpaceEventType.LEFT_DOWN());
    ScreenSpaceEventHandler upHandler = new ScreenSpaceEventHandler(csVPanel.getViewer().canvas());
    upHandler.setInputAction(new ScreenSpaceEventHandler.Listener() {

        @Override
        public void function(Object event) {
            if (Cesium.defined(selectedPlane)) {
                selectedPlane.material = new ColorMaterialProperty(Color.WHITE().withAlpha(0.1f));
                selectedPlane.outlineColor = new ConstantProperty<>(Color.WHITE());
                selectedPlane = (PlaneGraphics) JsObject.undefined();
            }
            csVPanel.getViewer().scene().screenSpaceCameraController().enableInputs = true;
        }
    }, ScreenSpaceEventType.LEFT_UP());
    ScreenSpaceEventHandler moveHandler = new ScreenSpaceEventHandler(csVPanel.getViewer().scene().canvas());
    moveHandler.setInputAction(new ScreenSpaceEventHandler.Listener() {

        @Override
        public void function(Object event) {
            if (Cesium.defined(selectedPlane)) {
                MouseMoveEvent mouseMoveEvent = (MouseMoveEvent) event;
                double deltaY = mouseMoveEvent.startPosition.y - mouseMoveEvent.endPosition.y;
                targetY += deltaY;
            }
        }
    }, ScreenSpaceEventType.MOUSE_MOVE());
    ListBox clipObjectLBox = new ListBox();
    clipObjectLBox.addItem("BIM");
    clipObjectLBox.addItem("Point Cloud");
    clipObjectLBox.addItem("Instanced");
    clipObjectLBox.addItem("Model");
    clipObjectLBox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            reset();
            ListBox source = (ListBox) event.getSource();
            switch(source.getSelectedIndex()) {
                case 0:
                    loadTileset(bimUrl);
                    break;
                case 1:
                    loadTileset(pointCloudUrl);
                    tileset.readyPromise().then(new Fulfill<Cesium3DTileset>() {

                        @Override
                        public void onFulfilled(Cesium3DTileset value) {
                            tileset.clippingPlanes.modelMatrix = Transforms.eastNorthUpToFixedFrame(tileset.boundingSphere().center);
                        }
                    });
                    break;
                case 2:
                    loadTileset(instancedUrl);
                    tileset.readyPromise().then(new Fulfill<Cesium3DTileset>() {

                        @Override
                        public void onFulfilled(Cesium3DTileset value) {
                            tileset.clippingPlanes.modelMatrix = Transforms.eastNorthUpToFixedFrame(tileset.boundingSphere().center);
                        }
                    });
                    break;
                case 3:
                    loadModel(modelUrl);
                    break;
                default:
                    break;
            }
        }
    });
    boundingVolumeCBox = new CheckBox("Show bounding volume");
    boundingVolumeCBox.setValue(false);
    boundingVolumeCBox.getElement().getStyle().setColor("white");
    boundingVolumeCBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            if (Cesium.defined(tileset)) {
                tileset.debugShowBoundingVolume = event.getValue();
            }
        }
    });
    edgeStylingCBox = new CheckBox("Enable edge styling");
    edgeStylingCBox.setValue(true);
    edgeStylingCBox.getElement().getStyle().setColor("white");
    edgeStylingCBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            double edgeWidth = event.getValue() ? 1.0 : 0.0;
            if (Cesium.defined(tileset)) {
                tileset.clippingPlanes.edgeWidth = edgeWidth;
            }
            if (Cesium.defined(modelEntityClippingPlanes)) {
                modelEntityClippingPlanes.edgeWidth = edgeWidth;
            }
        }
    });
    AbsolutePanel aPanel = new AbsolutePanel();
    aPanel.add(csVPanel);
    aPanel.add(clipObjectLBox, 20, 20);
    aPanel.add(boundingVolumeCBox, 20, 50);
    aPanel.add(edgeStylingCBox, 20, 70);
    contentPanel.add(new HTML("<p>User-defined clipping planes applied to a batched 3D Tileset, point cloud, and model.</p>"));
    contentPanel.add(aPanel);
    initWidget(contentPanel);
    loadTileset(bimUrl);
}
Also used : ViewerPanel(org.cesiumjs.cs.widgets.ViewerPanel) Entity(org.cesiumjs.cs.datasources.Entity) ConstantProperty(org.cesiumjs.cs.datasources.properties.ConstantProperty) MouseMoveEvent(org.cesiumjs.cs.core.events.MouseMoveEvent) ViewerOptions(org.cesiumjs.cs.widgets.options.ViewerOptions) MouseDownEvent(org.cesiumjs.cs.core.events.MouseDownEvent) AbsolutePanel(com.google.gwt.user.client.ui.AbsolutePanel) HTML(com.google.gwt.user.client.ui.HTML) ColorMaterialProperty(org.cesiumjs.cs.datasources.properties.ColorMaterialProperty) Cesium3DTileset(org.cesiumjs.cs.scene.Cesium3DTileset) PlaneGraphics(org.cesiumjs.cs.datasources.graphics.PlaneGraphics) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) CheckBox(com.google.gwt.user.client.ui.CheckBox) JsObject(org.cesiumjs.cs.js.JsObject) ListBox(com.google.gwt.user.client.ui.ListBox) Fulfill(org.cesiumjs.cs.promise.Fulfill)

Example 2 with MouseDownEvent

use of org.cesiumjs.cs.core.events.MouseDownEvent in project gwt-cs by iSergio.

the class DrawInteraction method startDrawing.

private void startDrawing(Object event) {
    if (!active) {
        return;
    }
    MouseDownEvent mouseDownEvent = (MouseDownEvent) event;
    if (mouseDownEvent.position == null) {
        return;
    }
    Cartesian3 cartesian;
    if (scene.mode.equals(SceneMode.SCENE3D())) {
        Ray ray = scene.camera().getPickRay(mouseDownEvent.position);
        cartesian = scene.globe.pick(ray, scene);
    } else {
        cartesian = scene.camera().pickEllipsoid(mouseDownEvent.position, scene.globe.ellipsoid);
    }
    if (cartesian == null) {
        return;
    }
    Event startEvent = new Event(EventType.DRAW_START, options.type);
    if (type == PrimitiveType.RECTANGLE) {
        if (rectangle == null) {
            firstPoint = scene.globe.ellipsoid.cartesianToCartographic(cartesian);
            Rectangle value = getExtent(firstPoint, firstPoint);
            updateExtent(value);
        // startEvent.setPrimitive();
        } else {
            finishDrawing();
        }
    } else if (type == PrimitiveType.POLYGON || type == PrimitiveType.CORRIDOR) {
        if (polygon == null && type == PrimitiveType.POLYGON) {
            polygon = new PolygonPrimitive(options);
            JsObject.setProperty(polygon, "asynchronous", false);
            collection.add(polygon);
            startEvent.setPrimitive(polygon);
            for (Listener listener : drawStartListeners) {
                listener.onDraw(startEvent);
            }
        } else if (corridor == null && type == PrimitiveType.CORRIDOR) {
            corridor = new CorridorPrimitive(scene, new CorridorPrimitiveOptions(options));
            JsObject.setProperty(corridor, "asynchronous", false);
            collection.add(corridor);
            startEvent.setPrimitive(corridor);
            for (Listener listener : drawStartListeners) {
                listener.onDraw(startEvent);
            }
        }
        if (markers == null) {
            markers = new MarkerGroup(scene, options);
        }
        if (positions.size() == 0) {
            positions.add(cartesian.clone());
            markers.add(positions.get(0));
        }
        if (positions.size() >= options.minPoints) {
            if (type == PrimitiveType.POLYGON) {
                polygon.setPositions(positions.toArray(new Cartesian3[positions.size()]));
                polygon.createPrimitive = true;
            } else {
                corridor.setPositions(positions.toArray(new Cartesian3[positions.size()]));
                corridor.createPrimitive = true;
            }
        }
        positions.add(cartesian);
        markers.add(cartesian);
    } else if (type == PrimitiveType.CIRCLE) {
        if (circle == null) {
            CirclePrimitiveOptions circlePrimitiveOptions = new CirclePrimitiveOptions(options);
            circlePrimitiveOptions.center = cartesian;
            circlePrimitiveOptions.radius = 0;
            circle = new CirclePrimitive(circlePrimitiveOptions);
            collection.add(circle);
            startEvent.setPrimitive(circle);
            for (Listener listener : drawStartListeners) {
                listener.onDraw(startEvent);
            }
            // Markers
            markers = new MarkerGroup(scene, options);
            markers.add(cartesian);
            // Create radius
            CorridorPrimitiveOptions radiusOptions = new CorridorPrimitiveOptions(options);
            radiusOptions.color = Color.YELLOW();
            radiusOptions.minPoints = 2;
            radius = new CorridorPrimitive(scene, radiusOptions);
            JsObject.setProperty(radius, "asynchronous", false);
            collection.add(radius);
            if (positions.size() == 0) {
                positions.add(cartesian.clone());
            }
            radius.setPositions(positions.toArray(new Cartesian3[positions.size()]));
            radius.createPrimitive = true;
            positions.add(cartesian);
        } else {
            // Done
            finishDrawing();
        }
    } else if (type == PrimitiveType.POINT) {
        if (point == null) {
            point = new org.cesiumjs.cs.scene.interaction.PointPrimitive(scene, new CorridorPrimitiveOptions(options));
            positions.add(cartesian.clone());
            point.setPositions(positions.toArray(new Cartesian3[positions.size()]));
            collection.add(point);
            finishDrawing();
        }
    }
}
Also used : MouseDownEvent(org.cesiumjs.cs.core.events.MouseDownEvent) CirclePrimitiveOptions(org.cesiumjs.cs.scene.interaction.options.CirclePrimitiveOptions) PointPrimitive(org.cesiumjs.cs.scene.PointPrimitive) CorridorPrimitiveOptions(org.cesiumjs.cs.scene.interaction.options.CorridorPrimitiveOptions) KeyUpEvent(com.google.gwt.event.dom.client.KeyUpEvent) MouseDownEvent(org.cesiumjs.cs.core.events.MouseDownEvent) KeyDownEvent(com.google.gwt.event.dom.client.KeyDownEvent) MouseDblClickEvent(org.cesiumjs.cs.core.events.MouseDblClickEvent) MouseMoveEvent(org.cesiumjs.cs.core.events.MouseMoveEvent)

Aggregations

MouseDownEvent (org.cesiumjs.cs.core.events.MouseDownEvent)2 MouseMoveEvent (org.cesiumjs.cs.core.events.MouseMoveEvent)2 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)1 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)1 KeyDownEvent (com.google.gwt.event.dom.client.KeyDownEvent)1 KeyUpEvent (com.google.gwt.event.dom.client.KeyUpEvent)1 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)1 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)1 AbsolutePanel (com.google.gwt.user.client.ui.AbsolutePanel)1 CheckBox (com.google.gwt.user.client.ui.CheckBox)1 HTML (com.google.gwt.user.client.ui.HTML)1 ListBox (com.google.gwt.user.client.ui.ListBox)1 MouseDblClickEvent (org.cesiumjs.cs.core.events.MouseDblClickEvent)1 Entity (org.cesiumjs.cs.datasources.Entity)1 PlaneGraphics (org.cesiumjs.cs.datasources.graphics.PlaneGraphics)1 ColorMaterialProperty (org.cesiumjs.cs.datasources.properties.ColorMaterialProperty)1 ConstantProperty (org.cesiumjs.cs.datasources.properties.ConstantProperty)1 JsObject (org.cesiumjs.cs.js.JsObject)1 Fulfill (org.cesiumjs.cs.promise.Fulfill)1 Cesium3DTileset (org.cesiumjs.cs.scene.Cesium3DTileset)1