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);
}
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();
}
}
}
Aggregations