Search in sources :

Example 1 with BoxGraphics

use of org.cesiumjs.cs.datasources.graphics.BoxGraphics in project gwt-cs by iSergio.

the class Shadows method buildPanel.

@Override
public void buildPanel() {
    ViewerOptions viewerOptions = new ViewerOptions();
    viewerOptions.infoBox = false;
    viewerOptions.selectionIndicator = false;
    viewerOptions.shadows = true;
    viewerOptions.terrainShadows = ShadowMode.ENABLED();
    csVPanel = new ViewerPanel(viewerOptions);
    CesiumTerrainProviderOptions cesiumTerrainProviderOptions = new CesiumTerrainProviderOptions();
    cesiumTerrainProviderOptions.url = "https://assets.agi.com/stk-terrain/world";
    cesiumTerrainProviderOptions.requestVertexNormals = true;
    cesiumTerrainProviderOptions.requestWaterMask = true;
    csVPanel.getViewer().terrainProvider = new CesiumTerrainProvider(cesiumTerrainProviderOptions);
    shadowMap = csVPanel.getViewer().shadowMap();
    shadowMap.maximumDistance = 10000.0;
    ModelGraphicsOptions modelGraphicsOptions = new ModelGraphicsOptions();
    modelGraphicsOptions.uri = new ConstantProperty<>(GWT.getModuleBaseURL() + "SampleData/models/CesiumAir/Cesium_Air.glb");
    EntityOptions entityOptions = new EntityOptions();
    entityOptions.name = "Cesium Air";
    entityOptions.model = new ModelGraphics(modelGraphicsOptions);
    JsObject.$(entityOptions, "height", 20.0);
    cesiumAir = csVPanel.getViewer().entities().add(entityOptions);
    modelGraphicsOptions = new ModelGraphicsOptions();
    modelGraphicsOptions.uri = new ConstantProperty<>(GWT.getModuleBaseURL() + "SampleData/models/CesiumGround/Cesium_Ground.glb");
    entityOptions = new EntityOptions();
    entityOptions.name = "Ground Vehicle";
    JsObject.$(entityOptions, "height", 0.0);
    entityOptions.model = new ModelGraphics(modelGraphicsOptions);
    groundVehicle = csVPanel.getViewer().entities().add(entityOptions);
    modelGraphicsOptions = new ModelGraphicsOptions();
    modelGraphicsOptions.uri = new ConstantProperty<>(GWT.getModuleBaseURL() + "SampleData/models/CesiumMan/Cesium_Man.glb");
    entityOptions = new EntityOptions();
    entityOptions.name = "Cesium Man";
    JsObject.$(entityOptions, "height", 0.0);
    entityOptions.model = new ModelGraphics(modelGraphicsOptions);
    cesiumMan = csVPanel.getViewer().entities().add(entityOptions);
    modelGraphicsOptions = new ModelGraphicsOptions();
    modelGraphicsOptions.uri = new ConstantProperty<>(GWT.getModuleBaseURL() + "SampleData/models/WoodTower/Wood_Tower.gltf");
    entityOptions = new EntityOptions();
    entityOptions.name = "Wood Tower";
    JsObject.$(entityOptions, "height", 0.0);
    entityOptions.model = new ModelGraphics(modelGraphicsOptions);
    woodTower = csVPanel.getViewer().entities().add(entityOptions);
    modelGraphicsOptions = new ModelGraphicsOptions();
    modelGraphicsOptions.uri = new ConstantProperty<>(GWT.getModuleBaseURL() + "SampleData/models/ShadowTester/Shadow_Tester_4.gltf");
    entityOptions = new EntityOptions();
    entityOptions.name = "Simple City";
    JsObject.$(entityOptions, "height", 0.0);
    entityOptions.model = new ModelGraphics(modelGraphicsOptions);
    simpleCity = csVPanel.getViewer().entities().add(entityOptions);
    BoxGraphicsOptions boxGraphicsOptions = new BoxGraphicsOptions();
    boxGraphicsOptions.dimensions = new ConstantProperty<>(new Cartesian3(10.0, 10.0, 10.0));
    boxGraphicsOptions.material = new ColorMaterialProperty(Color.RED());
    boxGraphicsOptions.shadows = new ConstantProperty<>(ShadowMode.ENABLED());
    entityOptions = new EntityOptions();
    entityOptions.name = "Box";
    JsObject.$(entityOptions, "height", 10.0);
    entityOptions.box = new BoxGraphics(boxGraphicsOptions);
    boxEntity = csVPanel.getViewer().entities().add(entityOptions);
    CheckerboardMaterialPropertyOptions checkerboardMaterialPropertyOptions = new CheckerboardMaterialPropertyOptions();
    checkerboardMaterialPropertyOptions.evenColor = new ConstantProperty<>(Color.RED().withAlpha(0.5f));
    checkerboardMaterialPropertyOptions.oddColor = new ConstantProperty<>(Color.RED().withAlpha(0.0f));
    checkerboardMaterialPropertyOptions.repeat = new ConstantProperty<>(new Cartesian2(5.0, 10.0));
    CheckerboardMaterialProperty checkerMaterial = new CheckerboardMaterialProperty(checkerboardMaterialPropertyOptions);
    boxGraphicsOptions = new BoxGraphicsOptions();
    boxGraphicsOptions.dimensions = new ConstantProperty<>(new Cartesian3(10.0, 10.0, 10.0));
    boxGraphicsOptions.material = checkerMaterial;
    boxGraphicsOptions.outline = new ConstantProperty<>(true);
    boxGraphicsOptions.outlineColor = new ConstantProperty<>(Color.RED());
    boxGraphicsOptions.shadows = new ConstantProperty<>(ShadowMode.ENABLED());
    entityOptions = new EntityOptions();
    entityOptions.name = "Checkered Box";
    JsObject.$(entityOptions, "height", 10.0);
    entityOptions.box = new BoxGraphics(boxGraphicsOptions);
    checkerEntity = csVPanel.getViewer().entities().add(entityOptions);
    EllipsoidGraphicsOptions ellipsoidGraphicsOptions = new EllipsoidGraphicsOptions();
    ellipsoidGraphicsOptions.radii = new ConstantProperty<>(new Cartesian3(15.0, 15.0, 15.0));
    ellipsoidGraphicsOptions.material = new ColorMaterialProperty(Color.BLUE().withAlpha(0.5f));
    ellipsoidGraphicsOptions.slicePartitions = new ConstantProperty<>(24);
    ellipsoidGraphicsOptions.stackPartitions = new ConstantProperty<>(36);
    ellipsoidGraphicsOptions.shadows = new ConstantProperty<>(ShadowMode.ENABLED());
    entityOptions = new EntityOptions();
    entityOptions.name = "Sphere";
    JsObject.$(entityOptions, "height", 10.0);
    entityOptions.ellipsoid = new EllipsoidGraphics(ellipsoidGraphicsOptions);
    sphereEntity = csVPanel.getViewer().entities().add(entityOptions);
    setLocation(locations.get(0));
    setEntity(cesiumAir);
    ListBox locationLBox = new ListBox();
    for (int i = 0; i < locations.size(); i++) {
        Location location = locations.get(i);
        locationLBox.addItem(location.name, i + "");
    }
    locationLBox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent changeEvent) {
            ListBox source = (ListBox) changeEvent.getSource();
            setLocation(locations.get(Integer.parseInt(source.getSelectedValue())));
        }
    });
    ListBox entitiList = new ListBox();
    entitiList.addItem("Cesium Air");
    entitiList.addItem("Ground Vehicle");
    entitiList.addItem("Cesium Man");
    entitiList.addItem("Wood Tower");
    entitiList.addItem("Simple City");
    entitiList.addItem("Box");
    entitiList.addItem("Checkered Box");
    entitiList.addItem("Sphere");
    entitiList.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent changeEvent) {
            ListBox source = (ListBox) changeEvent.getSource();
            switch(source.getSelectedIndex()) {
                case 0:
                    setEntity(cesiumAir);
                    break;
                case 1:
                    setEntity(groundVehicle);
                    break;
                case 2:
                    setEntity(cesiumMan);
                    break;
                case 3:
                    setEntity(woodTower);
                    break;
                case 4:
                    setEntity(simpleCity);
                    break;
                case 5:
                    setEntity(boxEntity);
                    break;
                case 6:
                    setEntity(checkerEntity);
                    break;
                case 7:
                    setEntity(sphereEntity);
                    break;
                default:
                    break;
            }
        }
    });
    CheckBox shadowsCBox = new CheckBox("Shadows");
    shadowsCBox.getElement().getStyle().setColor("white");
    shadowsCBox.setValue(true);
    shadowsCBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> valueChangeEvent) {
            csVPanel.getViewer().shadows = !csVPanel.getViewer().shadows;
        }
    });
    CheckBox entitiShadowsCBox = new CheckBox("Entity Shadows");
    entitiShadowsCBox.getElement().getStyle().setColor("white");
    entitiShadowsCBox.setValue(true);
    entitiShadowsCBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> valueChangeEvent) {
            Number entityShadows = valueChangeEvent.getValue() ? ShadowMode.ENABLED() : ShadowMode.DISABLED();
            for (int i = 0; i < csVPanel.getViewer().entities().values().length; i++) {
                Entity entity = csVPanel.getViewer().entities().values()[i];
                if (entity.model != null) {
                    entity.model.shadows = new ConstantProperty<>(entityShadows);
                } else if (entity.box != null) {
                    entity.box.shadows = new ConstantProperty<>(entityShadows);
                } else if (entity.ellipsoid != null) {
                    entity.ellipsoid.shadows = new ConstantProperty<>(entityShadows);
                }
            }
        }
    });
    CheckBox terrainShadowsCBox = new CheckBox("Terrain Shadows");
    terrainShadowsCBox.getElement().getStyle().setColor("white");
    terrainShadowsCBox.setValue(true);
    terrainShadowsCBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> valueChangeEvent) {
            csVPanel.getViewer().terrainShadows = valueChangeEvent.getValue() ? ShadowMode.ENABLED() : ShadowMode.DISABLED();
        }
    });
    CheckBox softShadowsCBox = new CheckBox("Soft Shadows");
    softShadowsCBox.getElement().getStyle().setColor("white");
    softShadowsCBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> valueChangeEvent) {
            shadowMap.softShadows = valueChangeEvent.getValue();
        }
    });
    ListBox sizeLBox = new ListBox();
    sizeLBox.addItem("Size: 2048", "2048");
    sizeLBox.addItem("Size: 1024", "1024");
    sizeLBox.addItem("Size: 512", "512");
    sizeLBox.addItem("Size: 256", "256");
    sizeLBox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent changeEvent) {
            ListBox source = (ListBox) changeEvent.getSource();
            shadowMap.size = Integer.parseInt(source.getSelectedValue());
        }
    });
    VerticalPanel vPanel = new VerticalPanel();
    vPanel.add(locationLBox);
    vPanel.add(entitiList);
    vPanel.add(shadowsCBox);
    vPanel.add(entitiShadowsCBox);
    vPanel.add(terrainShadowsCBox);
    vPanel.add(softShadowsCBox);
    vPanel.add(sizeLBox);
    FlowPanel fPanel = new FlowPanel();
    AbsolutePanel aPanel = new AbsolutePanel();
    aPanel.add(csVPanel);
    aPanel.add(vPanel, 20, 20);
    fPanel.add(aPanel);
    contentPanel.add(new HTML("<p>Shadow maps.</p>"));
    contentPanel.add(fPanel);
    initWidget(contentPanel);
}
Also used : CesiumTerrainProviderOptions(org.cesiumjs.cs.core.providers.options.CesiumTerrainProviderOptions) Entity(org.cesiumjs.cs.datasources.Entity) ViewerOptions(org.cesiumjs.cs.widgets.options.ViewerOptions) CheckerboardMaterialProperty(org.cesiumjs.cs.datasources.properties.CheckerboardMaterialProperty) ColorMaterialProperty(org.cesiumjs.cs.datasources.properties.ColorMaterialProperty) ModelGraphics(org.cesiumjs.cs.datasources.graphics.ModelGraphics) EntityOptions(org.cesiumjs.cs.datasources.options.EntityOptions) EllipsoidGraphicsOptions(org.cesiumjs.cs.datasources.graphics.options.EllipsoidGraphicsOptions) Cartesian2(org.cesiumjs.cs.core.Cartesian2) EllipsoidGraphics(org.cesiumjs.cs.datasources.graphics.EllipsoidGraphics) Cartesian3(org.cesiumjs.cs.core.Cartesian3) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) CesiumTerrainProvider(org.cesiumjs.cs.core.providers.CesiumTerrainProvider) ViewerPanel(org.cesiumjs.cs.widgets.ViewerPanel) ConstantProperty(org.cesiumjs.cs.datasources.properties.ConstantProperty) BoxGraphics(org.cesiumjs.cs.datasources.graphics.BoxGraphics) BoxGraphicsOptions(org.cesiumjs.cs.datasources.graphics.options.BoxGraphicsOptions) CheckerboardMaterialPropertyOptions(org.cesiumjs.cs.datasources.properties.options.CheckerboardMaterialPropertyOptions) ModelGraphicsOptions(org.cesiumjs.cs.datasources.graphics.options.ModelGraphicsOptions) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent)

Example 2 with BoxGraphics

use of org.cesiumjs.cs.datasources.graphics.BoxGraphics 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)

Aggregations

CesiumTerrainProvider (org.cesiumjs.cs.core.providers.CesiumTerrainProvider)2 CesiumTerrainProviderOptions (org.cesiumjs.cs.core.providers.options.CesiumTerrainProviderOptions)2 Entity (org.cesiumjs.cs.datasources.Entity)2 BoxGraphics (org.cesiumjs.cs.datasources.graphics.BoxGraphics)2 ModelGraphics (org.cesiumjs.cs.datasources.graphics.ModelGraphics)2 BoxGraphicsOptions (org.cesiumjs.cs.datasources.graphics.options.BoxGraphicsOptions)2 ModelGraphicsOptions (org.cesiumjs.cs.datasources.graphics.options.ModelGraphicsOptions)2 EntityOptions (org.cesiumjs.cs.datasources.options.EntityOptions)2 ColorMaterialProperty (org.cesiumjs.cs.datasources.properties.ColorMaterialProperty)2 ViewerPanel (org.cesiumjs.cs.widgets.ViewerPanel)2 ViewerOptions (org.cesiumjs.cs.widgets.options.ViewerOptions)2 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)1 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)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 ClippingPlaneCollection (org.cesiumjs.cs.collections.ClippingPlaneCollection)1 ClippingPlaneCollectionOptions (org.cesiumjs.cs.collections.options.ClippingPlaneCollectionOptions)1