use of org.cesiumjs.cs.datasources.graphics.options.ModelGraphicsOptions in project gwt-cs by iSergio.
the class Models3D method buildPanel.
@Override
public void buildPanel() {
ViewerOptions csViewerOptions = new ViewerOptions();
csViewerOptions.infoBox = false;
csViewerOptions.selectionIndicator = false;
csViewerOptions.shadows = false;
csVPanel = new ViewerPanel(csViewerOptions);
ModelGraphicsOptions modelGraphicsOptions = new ModelGraphicsOptions();
modelGraphicsOptions.uri = new ConstantProperty<>(GWT.getModuleBaseURL() + "SampleData/models/CesiumAir/Cesium_Air.glb");
modelGraphicsOptions.minimumPixelSize = new ConstantProperty<>(128);
modelGraphicsOptions.maximumScale = new ConstantProperty<>(20000);
ModelGraphics modelGraphics = new ModelGraphics(modelGraphicsOptions);
Cartesian3 position = Cartesian3.fromDegrees(-123.0744619, 44.0503706, 5000.0);
double heading = Math.toRadians(135);
double pitch = 0;
double roll = 0;
Quaternion orientation = Transforms.headingPitchRollQuaternion(position, new org.cesiumjs.cs.core.HeadingPitchRoll(heading, pitch, roll));
EntityOptions entityOptions = new EntityOptions();
entityOptions.name = GWT.getModuleBaseURL() + "SampleData/models/CesiumAir/Cesium_Air.glb";
entityOptions.position = new ConstantPositionProperty(position);
entityOptions.orientation = new ConstantProperty<>(orientation);
entityOptions.model = modelGraphics;
csVPanel.getViewer().trackedEntity = csVPanel.getViewer().entities().add(entityOptions);
final ListBox modelsLBox = new ListBox();
modelsLBox.addItem("Aircraft", "0");
modelsLBox.addItem("Ground vehicle", "1");
modelsLBox.addItem("Hot Air Balloon", "2");
modelsLBox.addItem("Milk truck", "3");
modelsLBox.addItem("Skinned character", "4");
modelsLBox.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent changeEvent) {
csVPanel.getViewer().entities().removeAll();
switch(modelsLBox.getSelectedValue()) {
case "0":
createModel(GWT.getModuleBaseURL() + "SampleData/models/CesiumAir/Cesium_Air.glb", 5000.0);
break;
case "1":
createModel(GWT.getModuleBaseURL() + "SampleData/models/CesiumGround/Cesium_Ground.glb", 0);
break;
case "2":
createModel(GWT.getModuleBaseURL() + "SampleData/models/CesiumBalloon/CesiumBalloon.glb", 1000.0);
break;
case "3":
createModel(GWT.getModuleBaseURL() + "SampleData/models/CesiumMilkTruck/CesiumMilkTruck-kmc.glb", 0);
break;
case "4":
createModel(GWT.getModuleBaseURL() + "SampleData/models/CesiumMan/Cesium_Man.glb", 0);
break;
default:
break;
}
}
});
AbsolutePanel aPanel = new AbsolutePanel();
aPanel.add(csVPanel);
aPanel.add(modelsLBox, 20, 20);
contentPanel.add(new HTML("<p>Create 3D models using glTF.</p>"));
contentPanel.add(aPanel);
initWidget(contentPanel);
}
use of org.cesiumjs.cs.datasources.graphics.options.ModelGraphicsOptions in project gwt-cs by iSergio.
the class ParticleSystem method buildPanel.
@Override
public void buildPanel() {
ViewerPanel csVPanel = new ViewerPanel();
// Set the random number seed for consistent results.
Math.setRandomNumberSeed(3);
// Make sure viewer is at the desired time.
csVPanel.getViewer().clock().startTime = start.clone();
csVPanel.getViewer().clock().stopTime = stop.clone();
csVPanel.getViewer().clock().currentTime = start.clone();
// Loop at the end
csVPanel.getViewer().clock().clockRange = ClockRange.LOOP_STOP();
csVPanel.getViewer().clock().multiplier = 1;
// Set timeline to simulation bounds
csVPanel.getViewer().timeline().zoomTo(start, stop);
// Compute the entity position property.
circularPosition = computeCirclularFlight(-112.110693, 36.0994841, 0.03);
staticPosition = Cartesian3.fromDegrees(-112.110693, 36.0994841, 1000);
TimeIntervalOptions timeIntervalOptions = new TimeIntervalOptions();
timeIntervalOptions.start = start;
timeIntervalOptions.stop = stop;
ModelGraphicsOptions modelGraphicsOptions = new ModelGraphicsOptions();
modelGraphicsOptions.uri = new ConstantProperty<>(GWT.getModuleBaseURL() + "SampleData/models/CesiumAir/Cesium_Air.gltf");
modelGraphicsOptions.minimumPixelSize = new ConstantProperty<>(64);
EntityOptions entityOptions = new EntityOptions();
entityOptions.availability = new TimeIntervalCollection(new TimeInterval[] { new TimeInterval(timeIntervalOptions) });
entityOptions.model = new ModelGraphics(modelGraphicsOptions);
entityOptions.position = new ConstantPositionProperty(staticPosition);
entity = csVPanel.getViewer().entities().add(entityOptions);
csVPanel.getViewer().trackedEntity = entity;
ParticleSystemOptions particleSystemOptions = new ParticleSystemOptions();
particleSystemOptions.image = GWT.getModuleBaseURL() + "SampleData/fire.png";
particleSystemOptions.startColor = Color.RED().withAlpha(0.7f);
particleSystemOptions.endColor = Color.YELLOW().withAlpha(0.3f);
particleSystemOptions.startScale = viewModel.startScale;
particleSystemOptions.endScale = viewModel.endScale;
particleSystemOptions.minimumLife = viewModel.minimumLife;
particleSystemOptions.maximumLife = viewModel.maximumLife;
particleSystemOptions.minimumSpeed = viewModel.minimumSpeed;
particleSystemOptions.maximumSpeed = viewModel.maximumSpeed;
particleSystemOptions.minimumWidth = viewModel.particleSize;
particleSystemOptions.minimumHeight = viewModel.particleSize;
particleSystemOptions.maximumWidth = viewModel.particleSize;
particleSystemOptions.maximumHeight = viewModel.particleSize;
particleSystemOptions.rate = viewModel.rate;
particleSystemOptions.bursts = new ParticleBurst[] { ParticleBurst.create(5.0, 300, 500), ParticleBurst.create(10.0, 50, 100), ParticleBurst.create(15.0, 200, 300) };
particleSystemOptions.lifeTime = 16;
particleSystemOptions.emitter = new CircleEmitter(0.5);
particleSystemOptions.emitterModelMatrix = computeEmitterModelMatrix();
particleSystemOptions.forces = new org.cesiumjs.cs.scene.particle.ParticleSystem.ApplyForce[] { new org.cesiumjs.cs.scene.particle.ParticleSystem.ApplyForce() {
@Override
public void function(Particle particle, double dt) {
Cartesian3 position = particle.position;
Cartesian3.normalize(position, gravityScratch);
Cartesian3.multiplyByScalar(gravityScratch, viewModel.gravity * dt, gravityScratch);
particle.velocity = Cartesian3.add(particle.velocity, gravityScratch, particle.velocity);
}
} };
particleSystem = (org.cesiumjs.cs.scene.particle.ParticleSystem) csVPanel.getViewer().scene().primitives().add(new org.cesiumjs.cs.scene.particle.ParticleSystem(particleSystemOptions));
csVPanel.getViewer().scene().preRender().addEventListener(new Event.Listener() {
@Override
public void function(Object... o) {
Scene scene = (Scene) o[0];
JulianDate time = (JulianDate) o[1];
particleSystem.modelMatrix = computeModelMatrix(entity, time);
// Account for any changes to the emitter model matrix.
particleSystem.emitterModelMatrix = computeEmitterModelMatrix();
// Spin the emitter if enabled.
if (viewModel.spin) {
viewModel.heading += 1.0;
viewModel.pitch += 1.0;
viewModel.roll += 1.0;
rotationHTBox.setValue(viewModel.heading + "");
rotationPTBox.setValue(viewModel.pitch + "");
rotationRTBox.setValue(viewModel.roll + "");
}
}
});
AbsolutePanel aPanel = new AbsolutePanel();
aPanel.add(csVPanel);
aPanel.add(createWidget(), 20, 20);
contentPanel.add(new HTML("<p>Particle systems.</p>"));
contentPanel.add(aPanel);
initWidget(contentPanel);
}
use of org.cesiumjs.cs.datasources.graphics.options.ModelGraphicsOptions 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.graphics.options.ModelGraphicsOptions in project gwt-cs by iSergio.
the class Models3DColoring method buildPanel.
@Override
public void buildPanel() {
ViewerOptions csViewerOptions = new ViewerOptions();
csViewerOptions.infoBox = false;
csViewerOptions.selectionIndicator = false;
csViewerOptions.shadows = false;
csVPanel = new ViewerPanel(csViewerOptions);
ModelGraphicsOptions modelGraphicsOptions = new ModelGraphicsOptions();
modelGraphicsOptions.uri = new ConstantProperty<>(GWT.getModuleBaseURL() + "SampleData/models/CesiumAir/Cesium_Air.glb");
modelGraphicsOptions.minimumPixelSize = new ConstantProperty<>(128);
modelGraphicsOptions.maximumScale = new ConstantProperty<>(20000);
modelGraphicsOptions.color = new ConstantProperty<>(getColor("red", alpha));
modelGraphicsOptions.colorBlendMode = new ConstantProperty<>(ColorBlendMode.HIGHLIGHT());
modelGraphicsOptions.colorBlendAmount = new ConstantProperty<>(colorBlendAmount);
modelGraphicsOptions.silhouetteColor = new ConstantProperty<>(getColor("red", alpha));
modelGraphicsOptions.silhouetteSize = new ConstantProperty<>(silhouetteSize);
ModelGraphics modelGraphics = new ModelGraphics(modelGraphicsOptions);
Cartesian3 position = Cartesian3.fromDegrees(-123.0744619, 44.0503706, 5000.0);
double heading = Math.toRadians(135);
double pitch = 0;
double roll = 0;
org.cesiumjs.cs.core.HeadingPitchRoll hpr = new org.cesiumjs.cs.core.HeadingPitchRoll(heading, pitch, roll);
Quaternion orientation = Transforms.headingPitchRollQuaternion(position, hpr);
EntityOptions entityOptions = new EntityOptions();
entityOptions.name = GWT.getModuleBaseURL() + "SampleData/models/CesiumAir/Cesium_Air.glb";
entityOptions.position = new ConstantPositionProperty(position);
entityOptions.orientation = new ConstantProperty<>(orientation);
entityOptions.model = modelGraphics;
csVPanel.getViewer().trackedEntity = csVPanel.getViewer().entities().add(entityOptions);
ListBox modeLBox = new ListBox();
modeLBox.addItem("Hightlight", "0");
modeLBox.addItem("Replace", "1");
modeLBox.addItem("Mix", "2");
modeLBox.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
ListBox source = (ListBox) event.getSource();
mixSlider.setVisible(false);
mixTBox.setVisible(false);
if (source.getSelectedValue().equalsIgnoreCase("0")) {
colorBlendMode = ColorBlendMode.HIGHLIGHT();
} else if (source.getSelectedValue().equalsIgnoreCase("1")) {
colorBlendMode = ColorBlendMode.REPLACE();
} else if (source.getSelectedValue().equalsIgnoreCase("2")) {
colorBlendMode = ColorBlendMode.MIX();
mixSlider.setVisible(true);
mixTBox.setVisible(true);
}
csVPanel.getViewer().trackedEntity.model.colorBlendMode = new ConstantProperty<>(colorBlendMode);
}
});
ListBox colorLBox = new ListBox();
colorLBox.addItem("White", "White");
colorLBox.addItem("Red", "Red");
colorLBox.addItem("Green", "Green");
colorLBox.addItem("Blue", "Blue");
colorLBox.addItem("Yellow", "Yellow");
colorLBox.addItem("Gray", "Gray");
colorLBox.setSelectedIndex(1);
colorLBox.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
ListBox source = (ListBox) event.getSource();
colorStr = source.getSelectedValue();
csVPanel.getViewer().trackedEntity.model.color = new ConstantProperty<>(getColor(source.getSelectedValue(), alpha));
}
});
alphaSlider = new Slider("Alpha", 0, 100, 100);
alphaSlider.setWidth("100px");
alphaSlider.setStep(1);
alphaSlider.addListener(new MSliderListener());
alphaTBox = new TextBox();
alphaTBox.setSize("30px", "12px");
alphaTBox.setValue("" + 1);
alphaTBox.addChangeHandler(new MChangeHandler());
mixSlider = new Slider("Mix", 0, 100, 50);
mixSlider.setStep(1);
mixSlider.setVisible(false);
mixSlider.addListener(new MSliderListener());
mixTBox = new TextBox();
mixTBox.setSize("30px", "12px");
mixTBox.setValue("0.5");
mixTBox.setVisible(false);
mixTBox.addChangeHandler(new MChangeHandler());
ListBox silhouetteColorLBox = new ListBox();
silhouetteColorLBox.addItem("Red", "Red");
silhouetteColorLBox.addItem("Green", "Green");
silhouetteColorLBox.addItem("Blue", "Blue");
silhouetteColorLBox.addItem("Yellow", "Yellow");
silhouetteColorLBox.addItem("Gray", "Gray");
silhouetteColorLBox.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
ListBox source = (ListBox) event.getSource();
silhouetteColorStr = source.getSelectedValue();
silhouetteColor = getColor(source.getSelectedValue(), alpha);
csVPanel.getViewer().trackedEntity.model.silhouetteColor = new ConstantProperty<>(getColor(silhouetteColorStr, silhouetteAlpha));
}
});
silhouetteAlphaSlider = new Slider("SilhouetteAlpha", 0, 100, 100);
silhouetteAlphaSlider.setStep(1);
silhouetteAlphaSlider.addListener(new MSliderListener());
silhouetteAlphaTBox = new TextBox();
silhouetteAlphaTBox.setSize("30px", "12px");
silhouetteAlphaTBox.setValue("" + 1);
silhouetteAlphaTBox.addChangeHandler(new MChangeHandler());
silhouetteSizeSlider = new Slider("SizeAlpha", 0, 1000, 20);
silhouetteSizeSlider.setStep(1);
silhouetteSizeSlider.addListener(new MSliderListener());
silhouetteSizeTBox = new TextBox();
silhouetteSizeTBox.setSize("30px", "12px");
silhouetteSizeTBox.setValue("" + 2);
silhouetteSizeTBox.addChangeHandler(new MChangeHandler());
final ListBox modelsLBox = new ListBox();
modelsLBox.addItem("Aircraft", "0");
modelsLBox.addItem("Ground vehicle", "1");
modelsLBox.addItem("Hot Air Balloon", "2");
modelsLBox.addItem("Milk truck", "3");
modelsLBox.addItem("Skinned character", "4");
modelsLBox.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent changeEvent) {
csVPanel.getViewer().entities().removeAll();
switch(modelsLBox.getSelectedValue()) {
case "0":
createModel(GWT.getModuleBaseURL() + "SampleData/models/CesiumAir/Cesium_Air.glb", 5000.0);
break;
case "1":
createModel(GWT.getModuleBaseURL() + "SampleData/models/CesiumGround/Cesium_Ground.glb", 0);
break;
case "2":
createModel(GWT.getModuleBaseURL() + "SampleData/models/CesiumBalloon/CesiumBalloon.glb", 1000.0);
break;
case "3":
createModel(GWT.getModuleBaseURL() + "SampleData/models/CesiumMilkTruck/CesiumMilkTruck-kmc.glb", 0);
break;
case "4":
createModel(GWT.getModuleBaseURL() + "SampleData/models/CesiumMan/Cesium_Man.glb", 0);
break;
default:
break;
}
}
});
CheckBox shadowsCBox = new CheckBox("Shadows");
shadowsCBox.getElement().getStyle().setColor("white");
shadowsCBox.setWidth("100px");
shadowsCBox.setValue(true);
shadowsCBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
@Override
public void onValueChange(ValueChangeEvent<Boolean> event) {
csVPanel.getViewer().shadows = event.getValue();
}
});
FlexTable flexTable = new FlexTable();
flexTable.setHTML(1, 0, "<font color=\"white\">Model Color</font>");
flexTable.setHTML(2, 0, "<font color=\"white\">Mode</font>");
flexTable.setWidget(2, 1, modeLBox);
flexTable.setHTML(3, 0, "<font color=\"white\">Color</font>");
flexTable.setWidget(3, 1, colorLBox);
flexTable.setHTML(4, 0, "<font color=\"white\">Alpha</font>");
flexTable.setWidget(4, 1, alphaSlider);
flexTable.setWidget(4, 2, alphaTBox);
flexTable.setHTML(5, 0, "<font color=\"white\">Mix</font>");
flexTable.setWidget(5, 1, mixSlider);
flexTable.setWidget(5, 2, mixTBox);
flexTable.setHTML(6, 0, "<font color=\"white\">Model Silhouette</font>");
flexTable.setHTML(7, 0, "<font color=\"white\">Color</font>");
flexTable.setWidget(7, 1, silhouetteColorLBox);
flexTable.setHTML(8, 0, "<font color=\"white\">Alpha</font>");
flexTable.setWidget(8, 1, silhouetteAlphaSlider);
flexTable.setWidget(8, 2, silhouetteAlphaTBox);
flexTable.setHTML(9, 0, "<font color=\"white\">Size</font>");
flexTable.setWidget(9, 1, silhouetteSizeSlider);
flexTable.setWidget(9, 2, silhouetteSizeTBox);
flexTable.setWidget(10, 0, modelsLBox);
flexTable.setWidget(10, 1, shadowsCBox);
AbsolutePanel aPanel = new AbsolutePanel();
aPanel.add(csVPanel);
aPanel.add(flexTable, 20, 20);
contentPanel.add(new HTML("<p>Create 3D coloring models.</p>"));
contentPanel.add(aPanel);
initWidget(contentPanel);
}
use of org.cesiumjs.cs.datasources.graphics.options.ModelGraphicsOptions in project gwt-cs by iSergio.
the class Cardboard method buildPanel.
@Override
public void buildPanel() {
ViewerOptions viewerOptions = new ViewerOptions();
viewerOptions.vrButton = true;
ViewerPanel csVPanel = new ViewerPanel(viewerOptions);
csVPanel.getViewer().scene().globe.enableLighting = true;
CesiumTerrainProviderOptions cesiumTerrainProviderOptions = new CesiumTerrainProviderOptions();
cesiumTerrainProviderOptions.url = "https://assets.agi.com/stk-terrain/world";
cesiumTerrainProviderOptions.requestVertexNormals = true;
csVPanel.getViewer().terrainProvider = new CesiumTerrainProvider(cesiumTerrainProviderOptions);
csVPanel.getViewer().scene().globe.depthTestAgainstTerrain = true;
// Follow the path of a plane. See the interpolation Sandcastle example.
Math.setRandomNumberSeed(3);
start = JulianDate.fromDate(new JsDate(2015, 2, 25, 16));
stop = JulianDate.addSeconds(start, 360, new JulianDate());
csVPanel.getViewer().clock().startTime = start.clone();
csVPanel.getViewer().clock().stopTime = stop.clone();
csVPanel.getViewer().clock().currentTime = start.clone();
csVPanel.getViewer().clock().clockRange = ClockRange.LOOP_STOP();
csVPanel.getViewer().clock().multiplier = 1.0;
double lon = -112.110693;
double lat = 36.0994841;
double radius = 0.03;
String modelURI = GWT.getModuleBaseURL() + "SampleData/models/CesiumBalloon/CesiumBalloon.glb";
EntityOptions entityOptions = new EntityOptions();
TimeIntervalOptions timeIntervalOptions = new TimeIntervalOptions();
timeIntervalOptions.start = start;
timeIntervalOptions.stop = stop;
entityOptions.availability = new TimeIntervalCollection(new TimeInterval[] { new TimeInterval(timeIntervalOptions) });
entityOptions.position = computeCirclularFlight(lon, lat, radius);
ModelGraphicsOptions modelGraphicsOptions = new ModelGraphicsOptions();
modelGraphicsOptions.uri = new ConstantProperty<>(modelURI);
modelGraphicsOptions.minimumPixelSize = new ConstantProperty<>(64);
entityOptions.model = new ModelGraphics(modelGraphicsOptions);
entity = csVPanel.getViewer().entities().add(entityOptions);
SampledPropertyInterpolationOptions sampledPropertyInterpolationOptions = new SampledPropertyInterpolationOptions();
sampledPropertyInterpolationOptions.interpolationDegree = 2;
sampledPropertyInterpolationOptions.interpolationAlgorithm = HermitePolynomialApproximation.instance();
((SampledPositionProperty) entity.position).setInterpolationOptions(sampledPropertyInterpolationOptions);
// Set initial camera position and orientation to be when in the model's reference frame.
final org.cesiumjs.cs.scene.Camera camera = csVPanel.getViewer().camera;
camera.position = new Cartesian3(0.25, 0.0, 0.0);
camera.direction = new Cartesian3(1.0, 0.0, 0.0);
camera.up = new Cartesian3(0.0, 0.0, 1.0);
camera.right = new Cartesian3(0.0, -1.0, 0.0);
csVPanel.getViewer().scene().preRender().addEventListener(new Scene.Listener() {
@Override
public void function(Scene scene, JulianDate time) {
Cartesian3 position = entity.position.getValue(time);
if (position == null || !Cesium.defined(position)) {
return;
}
Matrix4 transform;
if (!Cesium.defined(entity.orientation)) {
transform = Transforms.eastNorthUpToFixedFrame(position);
} else {
Quaternion orientation = (Quaternion) entity.orientation.getValue(time);
if (!Cesium.defined(orientation)) {
return;
}
transform = Matrix4.fromRotationTranslation(Matrix3.fromQuaternion(orientation), position);
}
// Save camera state
Cartesian3 offset = camera.position.clone();
Cartesian3 direction = camera.direction.clone();
Cartesian3 up = camera.up.clone();
// Set camera to be in model's reference frame.
camera.lookAtTransform(transform);
// Reset the camera state to the saved state so it appears fixed in the model's frame.
offset.clone(camera.position);
direction.clone(camera.direction);
up.clone(camera.up);
Cartesian3.cross(direction, up, camera.right);
}
});
// Add a few more balloons flying with the one the viewer is in.
int numBalloons = 12;
for (int i = 0; i < numBalloons; ++i) {
double balloonRadius = (Math.nextRandomNumber() * 2.0 - 1.0) * 0.01 + radius;
entityOptions = new EntityOptions();
timeIntervalOptions = new TimeIntervalOptions();
timeIntervalOptions.start = start;
timeIntervalOptions.stop = stop;
entityOptions.availability = new TimeIntervalCollection(new TimeInterval[] { new TimeInterval(timeIntervalOptions) });
entityOptions.position = computeCirclularFlight(lon, lat, balloonRadius);
modelGraphicsOptions = new ModelGraphicsOptions();
modelGraphicsOptions.uri = new ConstantProperty<>(modelURI);
modelGraphicsOptions.minimumPixelSize = new ConstantProperty<>(64);
entityOptions.model = new ModelGraphics(modelGraphicsOptions);
Entity balloon = csVPanel.getViewer().entities().add(entityOptions);
sampledPropertyInterpolationOptions = new SampledPropertyInterpolationOptions();
sampledPropertyInterpolationOptions.interpolationDegree = 2;
sampledPropertyInterpolationOptions.interpolationAlgorithm = HermitePolynomialApproximation.instance();
((SampledPositionProperty) balloon.position).setInterpolationOptions(sampledPropertyInterpolationOptions);
}
contentPanel.add(new HTML("<p>Configure viewer to add a button enabling look at a mobile device with cardboard.</p>"));
contentPanel.add(csVPanel);
initWidget(contentPanel);
}
Aggregations