Search in sources :

Example 1 with ClippingPlaneCollection

use of org.cesiumjs.cs.collections.ClippingPlaneCollection in project gwt-cs by iSergio.

the class TerrainClippingPlanes method buildPanel.

@Override
public void buildPanel() {
    ViewerOptions viewerOptions = new ViewerOptions();
    viewerOptions.skyAtmosphere = null;
    final ViewerPanel csVPanel = new ViewerPanel(viewerOptions);
    CesiumTerrainProviderOptions terrainProviderOptions = new CesiumTerrainProviderOptions();
    terrainProviderOptions.url = "https://assets.agi.com/stk-terrain/v1/tilesets/world/tiles";
    terrainProviderOptions.requestWaterMask = true;
    terrainProviderOptions.requestVertexNormals = true;
    csVPanel.getViewer().terrainProvider = new CesiumTerrainProvider(terrainProviderOptions);
    Cartesian3 position = Cartesian3.fromRadians(-2.0862979473351286, 0.6586620013036164, 1400.0);
    BoxGraphicsOptions boxGraphicsOptions = new BoxGraphicsOptions();
    boxGraphicsOptions.dimensions = new ConstantProperty<>(new Cartesian3(1400.0, 1400.0, 2800.0));
    boxGraphicsOptions.material = new ColorMaterialProperty(Color.WHITE().withAlpha(0.3f));
    boxGraphicsOptions.outline = new ConstantProperty<>(true);
    boxGraphicsOptions.outlineColor = new ConstantProperty<>(Color.WHITE());
    EntityOptions entityOptions = new EntityOptions();
    entityOptions.position = new ConstantPositionProperty(position);
    entityOptions.box = new BoxGraphics(boxGraphicsOptions);
    Entity entity = csVPanel.getViewer().entities().add(entityOptions);
    ModelGraphicsOptions modelGraphicsOptions = new ModelGraphicsOptions();
    modelGraphicsOptions.uri = new ConstantProperty<>(GWT.getModuleBaseURL() + "SampleData/models/CesiumMan/Cesium_Man.glb");
    modelGraphicsOptions.minimumPixelSize = new ConstantProperty<>(128);
    modelGraphicsOptions.maximumScale = new ConstantProperty<>(800);
    entityOptions = new EntityOptions();
    entityOptions.position = new ConstantPositionProperty(position);
    entityOptions.model = new ModelGraphics(modelGraphicsOptions);
    csVPanel.getViewer().entities().add(entityOptions);
    ClippingPlaneCollectionOptions clippingPlaneCollectionOptions = new ClippingPlaneCollectionOptions();
    clippingPlaneCollectionOptions.modelMatrix = entity.computeModelMatrix(JulianDate.now());
    clippingPlaneCollectionOptions.planes = new ClippingPlane[] { new ClippingPlane(new Cartesian3(1.0, 0.0, 0.0), -700.0), new ClippingPlane(new Cartesian3(-1.0, 0.0, 0.0), -700.0), new ClippingPlane(new Cartesian3(0.0, 1.0, 0.0), -700.0), new ClippingPlane(new Cartesian3(0.0, -1.0, 0.0), -700.0) };
    clippingPlaneCollectionOptions.edgeWidth = 1.0;
    clippingPlaneCollectionOptions.edgeColor = Color.WHITE();
    final Globe globe = csVPanel.getViewer().scene().globe;
    globe.depthTestAgainstTerrain = true;
    globe.clippingPlanes = new ClippingPlaneCollection(clippingPlaneCollectionOptions);
    csVPanel.getViewer().trackedEntity = entity;
    CheckBox globeClippingCBox = new CheckBox("Globe clipping planes enabled");
    globeClippingCBox.setValue(true);
    globeClippingCBox.getElement().getStyle().setColor("white");
    globeClippingCBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            globe.clippingPlanes.enabled = event.getValue();
        }
    });
    AbsolutePanel aPanel = new AbsolutePanel();
    aPanel.add(csVPanel);
    aPanel.add(globeClippingCBox, 20, 20);
    contentPanel.add(new HTML("<p>User-defined clipping planes applied to terrain.</p>"));
    contentPanel.add(aPanel);
    initWidget(contentPanel);
}
Also used : CesiumTerrainProviderOptions(org.cesiumjs.cs.core.providers.options.CesiumTerrainProviderOptions) Entity(org.cesiumjs.cs.datasources.Entity) ClippingPlaneCollection(org.cesiumjs.cs.collections.ClippingPlaneCollection) ViewerOptions(org.cesiumjs.cs.widgets.options.ViewerOptions) AbsolutePanel(com.google.gwt.user.client.ui.AbsolutePanel) ClippingPlaneCollectionOptions(org.cesiumjs.cs.collections.options.ClippingPlaneCollectionOptions) HTML(com.google.gwt.user.client.ui.HTML) ColorMaterialProperty(org.cesiumjs.cs.datasources.properties.ColorMaterialProperty) ModelGraphics(org.cesiumjs.cs.datasources.graphics.ModelGraphics) EntityOptions(org.cesiumjs.cs.datasources.options.EntityOptions) CesiumTerrainProvider(org.cesiumjs.cs.core.providers.CesiumTerrainProvider) ClippingPlane(org.cesiumjs.cs.scene.ClippingPlane) ViewerPanel(org.cesiumjs.cs.widgets.ViewerPanel) BoxGraphics(org.cesiumjs.cs.datasources.graphics.BoxGraphics) BoxGraphicsOptions(org.cesiumjs.cs.datasources.graphics.options.BoxGraphicsOptions) ConstantPositionProperty(org.cesiumjs.cs.datasources.properties.ConstantPositionProperty) ModelGraphicsOptions(org.cesiumjs.cs.datasources.graphics.options.ModelGraphicsOptions) CheckBox(com.google.gwt.user.client.ui.CheckBox)

Example 2 with ClippingPlaneCollection

use of org.cesiumjs.cs.collections.ClippingPlaneCollection in project gwt-cs by iSergio.

the class Tiles3DClippingPlanes method loadModel.

private void loadModel(String url) {
    ClippingPlane[] clippingPlanes = new ClippingPlane[] { new ClippingPlane(new Cartesian3(0.0, 0.0, -1.0), -100.0) };
    ClippingPlaneCollectionOptions clippingPlaneCollectionOptions = new ClippingPlaneCollectionOptions();
    clippingPlaneCollectionOptions.planes = clippingPlanes;
    clippingPlaneCollectionOptions.edgeWidth = edgeStylingCBox.getValue() ? 1.0 : 0.0;
    modelEntityClippingPlanes = new ClippingPlaneCollection(clippingPlaneCollectionOptions);
    Cartesian3 position = Cartesian3.fromDegrees(-123.0744619, 44.0503706, 100.0);
    double heading = Math.toRadians(135.0);
    double pitch = 0.0;
    double roll = 0.0;
    HeadingPitchRoll hpr = new HeadingPitchRoll(heading, pitch, roll);
    Quaternion orientation = Transforms.headingPitchRollQuaternion(position, hpr);
    ModelGraphicsOptions modelGraphicsOptions = new ModelGraphicsOptions();
    modelGraphicsOptions.uri = new ConstantProperty<>(url);
    modelGraphicsOptions.scale = new ConstantProperty<>(8.0);
    modelGraphicsOptions.minimumPixelSize = new ConstantProperty<>(100.0);
    modelGraphicsOptions.clippingPlanes = new CallbackProperty(new CallbackProperty.Callback() {

        @Override
        public Object function(JulianDate time, Object result) {
            return modelEntityClippingPlanes;
        }
    }, false);
    EntityOptions entityOptions = new EntityOptions();
    entityOptions.name = url;
    entityOptions.position = new ConstantPositionProperty(position);
    entityOptions.orientation = new ConstantProperty<>(orientation);
    entityOptions.model = new ModelGraphics(modelGraphicsOptions);
    csVPanel.getViewer().trackedEntity = csVPanel.getViewer().entities().add(entityOptions);
    for (final ClippingPlane clippingPlane : clippingPlanes) {
        PlaneGraphicsOptions planeGraphicsOptions = new PlaneGraphicsOptions();
        planeGraphicsOptions.dimensions = new ConstantProperty<>(new Cartesian2(300.0, 300.0));
        planeGraphicsOptions.material = new ColorMaterialProperty(Color.WHITE().withAlpha(0.1f));
        planeGraphicsOptions.plane = new CallbackProperty(new CallbackProperty.Callback() {

            @Override
            public Object function(JulianDate time, Object result) {
                clippingPlane.distance = targetY;
                return ClippingPlane.transform(clippingPlane, Matrix4.IDENTITY(), scratchPlane);
            }
        }, false);
        planeGraphicsOptions.outline = new ConstantProperty<>(true);
        planeGraphicsOptions.outlineColor = new ConstantProperty<>(Color.WHITE());
        EntityOptions planeEntityOptions = new EntityOptions();
        planeEntityOptions.position = new ConstantPositionProperty(position);
        planeEntityOptions.plane = new PlaneGraphics(planeGraphicsOptions);
        planeEntities.add(csVPanel.getViewer().entities().add(planeEntityOptions));
    }
}
Also used : CallbackProperty(org.cesiumjs.cs.datasources.properties.CallbackProperty) ClippingPlaneCollection(org.cesiumjs.cs.collections.ClippingPlaneCollection) HeadingPitchRoll(org.cesiumjs.cs.core.HeadingPitchRoll) ClippingPlaneCollectionOptions(org.cesiumjs.cs.collections.options.ClippingPlaneCollectionOptions) ConstantPositionProperty(org.cesiumjs.cs.datasources.properties.ConstantPositionProperty) ColorMaterialProperty(org.cesiumjs.cs.datasources.properties.ColorMaterialProperty) ModelGraphics(org.cesiumjs.cs.datasources.graphics.ModelGraphics) EntityOptions(org.cesiumjs.cs.datasources.options.EntityOptions) PlaneGraphicsOptions(org.cesiumjs.cs.datasources.graphics.options.PlaneGraphicsOptions) ModelGraphicsOptions(org.cesiumjs.cs.datasources.graphics.options.ModelGraphicsOptions) PlaneGraphics(org.cesiumjs.cs.datasources.graphics.PlaneGraphics) JsObject(org.cesiumjs.cs.js.JsObject) ClippingPlane(org.cesiumjs.cs.scene.ClippingPlane)

Example 3 with ClippingPlaneCollection

use of org.cesiumjs.cs.collections.ClippingPlaneCollection in project gwt-cs by iSergio.

the class Tiles3DClippingPlanes method loadTileset.

private void loadTileset(Promise<IonResource, Void> resource) {
    final ClippingPlane[] clippingPlanes = new ClippingPlane[] { new ClippingPlane(new Cartesian3(0.0, 0.0, -1.0), -100.0) };
    ClippingPlaneCollectionOptions clippingPlaneCollectionOptions = new ClippingPlaneCollectionOptions();
    clippingPlaneCollectionOptions.planes = clippingPlanes;
    clippingPlaneCollectionOptions.edgeWidth = edgeStylingCBox.getValue() ? 1.0 : 0.0;
    Cesium3DTilesetOptions tilesetOptions = Cesium3DTilesetOptions.create(resource);
    tilesetOptions.clippingPlanes = new ClippingPlaneCollection(clippingPlaneCollectionOptions);
    tileset = (Cesium3DTileset) csVPanel.getViewer().scene().primitives().add(new Cesium3DTileset(tilesetOptions));
    tileset.debugShowBoundingVolume = boundingVolumeCBox.getValue();
    tileset.readyPromise().then(new Fulfill<Cesium3DTileset>() {

        @Override
        public void onFulfilled(Cesium3DTileset value) {
            BoundingSphere boundingSphere = tileset.boundingSphere();
            double radius = boundingSphere.radius;
            csVPanel.getViewer().zoomTo(tileset, new HeadingPitchRange(0.5, -0.2, radius * 4.0));
            for (final ClippingPlane plane : clippingPlanes) {
                PlaneGraphicsOptions planeGraphicsOptions = new PlaneGraphicsOptions();
                planeGraphicsOptions.dimensions = new ConstantProperty<>(new Cartesian2(radius * 2.5, radius * 2.5));
                planeGraphicsOptions.material = new ColorMaterialProperty(Color.WHITE().withAlpha(0.1f));
                planeGraphicsOptions.plane = new CallbackProperty(new CallbackProperty.Callback() {

                    @Override
                    public Object function(JulianDate time, Object result) {
                        plane.distance = targetY;
                        return ClippingPlane.transform(plane, tileset.modelMatrix, scratchPlane);
                    }
                }, false);
                planeGraphicsOptions.outline = new ConstantProperty<>(true);
                planeGraphicsOptions.outlineColor = new ConstantProperty<>(Color.WHITE());
                EntityOptions entityOptions = new EntityOptions();
                entityOptions.position = new ConstantPositionProperty(boundingSphere.center);
                entityOptions.plane = new PlaneGraphics(planeGraphicsOptions);
                planeEntities.add(csVPanel.getViewer().entities().add(entityOptions));
            }
        }
    });
}
Also used : CallbackProperty(org.cesiumjs.cs.datasources.properties.CallbackProperty) ConstantProperty(org.cesiumjs.cs.datasources.properties.ConstantProperty) ClippingPlaneCollection(org.cesiumjs.cs.collections.ClippingPlaneCollection) ClippingPlaneCollectionOptions(org.cesiumjs.cs.collections.options.ClippingPlaneCollectionOptions) ColorMaterialProperty(org.cesiumjs.cs.datasources.properties.ColorMaterialProperty) ConstantPositionProperty(org.cesiumjs.cs.datasources.properties.ConstantPositionProperty) EntityOptions(org.cesiumjs.cs.datasources.options.EntityOptions) Cesium3DTileset(org.cesiumjs.cs.scene.Cesium3DTileset) Cesium3DTilesetOptions(org.cesiumjs.cs.scene.options.Cesium3DTilesetOptions) PlaneGraphicsOptions(org.cesiumjs.cs.datasources.graphics.options.PlaneGraphicsOptions) PlaneGraphics(org.cesiumjs.cs.datasources.graphics.PlaneGraphics) JsObject(org.cesiumjs.cs.js.JsObject) ClippingPlane(org.cesiumjs.cs.scene.ClippingPlane)

Aggregations

ClippingPlaneCollection (org.cesiumjs.cs.collections.ClippingPlaneCollection)3 ClippingPlaneCollectionOptions (org.cesiumjs.cs.collections.options.ClippingPlaneCollectionOptions)3 EntityOptions (org.cesiumjs.cs.datasources.options.EntityOptions)3 ColorMaterialProperty (org.cesiumjs.cs.datasources.properties.ColorMaterialProperty)3 ConstantPositionProperty (org.cesiumjs.cs.datasources.properties.ConstantPositionProperty)3 ClippingPlane (org.cesiumjs.cs.scene.ClippingPlane)3 ModelGraphics (org.cesiumjs.cs.datasources.graphics.ModelGraphics)2 PlaneGraphics (org.cesiumjs.cs.datasources.graphics.PlaneGraphics)2 ModelGraphicsOptions (org.cesiumjs.cs.datasources.graphics.options.ModelGraphicsOptions)2 PlaneGraphicsOptions (org.cesiumjs.cs.datasources.graphics.options.PlaneGraphicsOptions)2 CallbackProperty (org.cesiumjs.cs.datasources.properties.CallbackProperty)2 JsObject (org.cesiumjs.cs.js.JsObject)2 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 HeadingPitchRoll (org.cesiumjs.cs.core.HeadingPitchRoll)1 CesiumTerrainProvider (org.cesiumjs.cs.core.providers.CesiumTerrainProvider)1 CesiumTerrainProviderOptions (org.cesiumjs.cs.core.providers.options.CesiumTerrainProviderOptions)1 Entity (org.cesiumjs.cs.datasources.Entity)1 BoxGraphics (org.cesiumjs.cs.datasources.graphics.BoxGraphics)1