use of org.cesiumjs.cs.datasources.properties.ColorMaterialProperty 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);
}
use of org.cesiumjs.cs.datasources.properties.ColorMaterialProperty in project gwt-cs by iSergio.
the class SpheresAndEllipsoids method buildPanel.
@Override
public void buildPanel() {
ViewerPanel csVPanel = new ViewerPanel();
EllipsoidGraphicsOptions ellipsoidGraphicsOptions = new EllipsoidGraphicsOptions();
ellipsoidGraphicsOptions.radii = new ConstantProperty<>(new Cartesian3(200000.0, 200000.0, 300000.0));
ellipsoidGraphicsOptions.material = new ColorMaterialProperty(new ConstantProperty<>(Color.BLUE()));
EntityOptions entityOptions = new EntityOptions();
entityOptions.name = "Blue ellipsoid";
entityOptions.position = new ConstantPositionProperty(Cartesian3.fromDegrees(-114.0, 40.0, 300000.0));
entityOptions.ellipsoid = new EllipsoidGraphics(ellipsoidGraphicsOptions);
Entity blueEllpsoid = csVPanel.getViewer().entities().add(entityOptions);
ellipsoidGraphicsOptions = new EllipsoidGraphicsOptions();
ellipsoidGraphicsOptions.radii = new ConstantProperty<>(new Cartesian3(300000.0, 300000.0, 300000.0));
ellipsoidGraphicsOptions.material = new ColorMaterialProperty(new ConstantProperty<>(Color.RED().withAlpha(0.5f)));
ellipsoidGraphicsOptions.outline = new ConstantProperty<>(true);
ellipsoidGraphicsOptions.outlineColor = new ConstantProperty<>(Color.BLACK());
entityOptions = new EntityOptions();
entityOptions.name = "Red sphere with black outline";
entityOptions.position = new ConstantPositionProperty(Cartesian3.fromDegrees(-107.0, 40.0, 300000.0));
entityOptions.ellipsoid = new EllipsoidGraphics(ellipsoidGraphicsOptions);
Entity redSphere = csVPanel.getViewer().entities().add(entityOptions);
ellipsoidGraphicsOptions = new EllipsoidGraphicsOptions();
ellipsoidGraphicsOptions.radii = new ConstantProperty<>(new Cartesian3(200000.0, 200000.0, 300000.0));
ellipsoidGraphicsOptions.outline = new ConstantProperty<>(true);
ellipsoidGraphicsOptions.outlineColor = new ConstantProperty<>(Color.YELLOW());
ellipsoidGraphicsOptions.fill = new ConstantProperty<>(false);
ellipsoidGraphicsOptions.slicePartitions = new ConstantProperty<>(24);
ellipsoidGraphicsOptions.stackPartitions = new ConstantProperty<>(36);
entityOptions = new EntityOptions();
entityOptions.name = "Yellow ellipsoid outline";
entityOptions.position = new ConstantPositionProperty(Cartesian3.fromDegrees(-100.0, 40.0, 300000.0));
entityOptions.ellipsoid = new EllipsoidGraphics(ellipsoidGraphicsOptions);
Entity outlineOnly = csVPanel.getViewer().entities().add(entityOptions);
csVPanel.getViewer().zoomTo(csVPanel.getViewer().entities());
contentPanel.add(new HTML("<p>Draw spheres and ellipsoids.</p>"));
contentPanel.add(csVPanel);
initWidget(contentPanel);
}
use of org.cesiumjs.cs.datasources.properties.ColorMaterialProperty 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);
}
use of org.cesiumjs.cs.datasources.properties.ColorMaterialProperty 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));
}
}
use of org.cesiumjs.cs.datasources.properties.ColorMaterialProperty 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));
}
}
});
}
Aggregations