Commit 9827839c authored by Matthias Betz's avatar Matthias Betz
Browse files

remove different coloring from point frag shader

fix healer gui with new OpenGL viewports
parent 8ea7e372
Pipeline #12413 failed with stage
in 49 seconds
......@@ -8,11 +8,5 @@ void main() {
if (r2 > 1.0) {
discard; // outside the sphere's silhouette
}
float z = sqrt(1.0 - r2);
vec3 normal = normalize(vec3(vQuad.x, vQuad.y, z));
vec3 lightDir = normalize(vec3(0.3, 0.3, 1.0));
float diff = max(dot(normal, lightDir), 0.0);
float ambient = 0.45;
vec3 color = vColor * (ambient + (1.0 - ambient) * diff);
fragColor = vec4(color, 1.0);
fragColor = vec4(vColor, 1.0);
}
......@@ -31,15 +31,16 @@ import de.hft.stuttgart.citydoctor2.datastructure.Opening;
import de.hft.stuttgart.citydoctor2.datastructure.Polygon;
import de.hft.stuttgart.citydoctor2.gui.HighlightController;
import de.hft.stuttgart.citydoctor2.gui.ListErrorVisitor;
import de.hft.stuttgart.citydoctor2.gui.TriangulatedGeometry;
import de.hft.stuttgart.citydoctor2.gui.gl.IndexSetBuilder;
import de.hft.stuttgart.citydoctor2.gui.gl.SceneBuilder;
import de.hft.stuttgart.citydoctor2.gui.gl.SceneData;
import de.hft.stuttgart.citydoctor2.healer.Healer;
import de.hft.stuttgart.citydoctor2.optimization.MeshGenerator;
import de.hft.stuttgart.citydoctor2.utils.Copy;
import javafx.collections.ObservableList;
import javafx.scene.control.TextInputDialog;
import javafx.scene.control.TreeItem;
import javafx.scene.shape.CullFace;
import javafx.scene.shape.DrawMode;
import javafx.scene.paint.Color;
public class HealerController {
......@@ -53,11 +54,11 @@ public class HealerController {
private Geometry nextGeometry;
private Checker checker;
private CullFace culling = CullFace.BACK;
private DrawMode drawMode = DrawMode.FILL;
private boolean culling = false;
private boolean wireframe = false;
private TriangulatedGeometry nextTriangulatedGeometry;
private TriangulatedGeometry currentTriangulatedGeometry;
private SceneData currentScene;
private SceneData nextScene;
private ListErrorVisitor currentErrorVisitor;
private ListErrorVisitor nextErrorVisitor;
......@@ -69,14 +70,54 @@ public class HealerController {
public HealerController(HealerView healerView) {
this.healerView = healerView;
this.currentHighlights = new HighlightController(healerView.getCurrentWorld());
this.nextHighlights = new HighlightController(healerView.getNextWorld());
this.currentHighlights = new HighlightController(healerView.getCurrentViewport());
this.nextHighlights = new HighlightController(healerView.getNextViewport());
currentHighlights.setCenterSupplier(() -> currentScene == null ? new double[3] : currentScene.center());
nextHighlights.setCenterSupplier(() -> nextScene == null ? new double[3] : nextScene.center());
currentErrorVisitor = new ListErrorVisitor(currentHighlights);
nextErrorVisitor = new ListErrorVisitor(nextHighlights);
healerView.translateZProperty().addListener((obs, oldV, newV) -> {
currentHighlights.changeScaling(-newV.doubleValue());
nextHighlights.changeScaling(-newV.doubleValue());
});
}
/** Installs the current scene into the current viewport and applies the current view options. */
private void showCurrentScene() {
currentHighlights.clearHighlights();
healerView.getCurrentViewport().setScene(currentScene);
// the viewport draws nothing until it is told which triangles are visible; the healer has no
// LOD/roof filtering, so show every triangle of the scene
healerView.getCurrentViewport().setIndexSet(allTriangles(currentScene));
healerView.getCurrentViewport().setWireframe(wireframe);
healerView.getCurrentViewport().setCulling(culling);
}
/** Installs the next scene into the next viewport and applies the current view options. */
private void showNextScene() {
nextHighlights.clearHighlights();
healerView.getNextViewport().setScene(nextScene);
// the viewport draws nothing until it is told which triangles are visible; the healer has no
// LOD/roof filtering, so show every triangle of the scene
healerView.getNextViewport().setIndexSet(allTriangles(nextScene));
healerView.getNextViewport().setWireframe(wireframe);
healerView.getNextViewport().setCulling(culling);
}
/** Builds an index set covering every triangle of the scene (no filtering). */
private static int[] allTriangles(SceneData scene) {
if (scene == null) {
return new int[0];
}
return IndexSetBuilder.build(scene.triangleMetas(), m -> true);
}
private void clearCurrentScene() {
currentScene = null;
currentHighlights.clearHighlights();
healerView.getCurrentViewport().clearScene();
}
private void clearNextScene() {
nextScene = null;
nextHighlights.clearHighlights();
healerView.getNextViewport().clearScene();
}
public void showSimplyfication() {
......@@ -91,8 +132,8 @@ public class HealerController {
public void setCurrentModel(CityDoctorModel model) {
if (this.model != model) {
healerView.getCurrentMeshGroup().getChildren().clear();
healerView.getNextMeshGroup().getChildren().clear();
clearCurrentScene();
clearNextScene();
healerView.getCurrentErrorList().getItems().clear();
}
this.model = model;
......@@ -274,18 +315,14 @@ public class HealerController {
SelectableGeometry selectedGeometry = (SelectableGeometry) selectedItem;
currentGeometry = selectedGeometry.getGeometry();
currentFeature = selectedGeometry.getFeature();
currentTriangulatedGeometry = TriangulatedGeometry.of(currentGeometry);
currentErrorVisitor.setGeometry(currentTriangulatedGeometry);
currentTriangulatedGeometry.setCullFace(culling);
currentTriangulatedGeometry.setDrawMode(drawMode);
currentScene = SceneBuilder.fromPolygons(currentGeometry.getPolygons(), Color.WHITE);
healerView.setSelectedFeatureText(currentFeature.getGmlId().getGmlString());
healerView.setFeatureTypeText(currentFeature.getFeatureType().toString());
healerView.setGeometryText(currentGeometry.getLod().toString() + ", " + currentGeometry.getType().toString());
updateCurrentErrors();
healerView.zoomOutForBoundingBox(currentGeometry.calculateBoundingBox());
healerView.getCurrentMeshGroup().getChildren().clear();
healerView.getNextMeshGroup().getChildren().clear();
healerView.getCurrentMeshGroup().getChildren().addAll(currentTriangulatedGeometry.getMeshes());
showCurrentScene();
clearNextScene();
healerView.getNextStepBtn().setDisable(false);
healerView.getHealCompleteBtn().setDisable(false);
healerView.getAcceptBtn().setDisable(true);
......@@ -322,12 +359,8 @@ public class HealerController {
}
private void updateNextGeometryView() {
nextTriangulatedGeometry = TriangulatedGeometry.of(nextGeometry);
nextErrorVisitor.setGeometry(nextTriangulatedGeometry);
nextTriangulatedGeometry.setCullFace(culling);
nextTriangulatedGeometry.setDrawMode(drawMode);
healerView.getNextMeshGroup().getChildren().clear();
healerView.getNextMeshGroup().getChildren().addAll(nextTriangulatedGeometry.getMeshes());
nextScene = SceneBuilder.fromPolygons(nextGeometry.getPolygons(), Color.WHITE);
showNextScene();
healerView.getAcceptBtn().setDisable(false);
healerView.getCancelBtn().setDisable(false);
healerView.getSolidInjectorBtn().setDisable(true);
......@@ -346,12 +379,8 @@ public class HealerController {
Healer healer = new Healer(checker);
healer.heal(nextGeometry, nextFeature);
updateNextErrors();
nextTriangulatedGeometry = TriangulatedGeometry.of(nextGeometry);
nextErrorVisitor.setGeometry(nextTriangulatedGeometry);
nextTriangulatedGeometry.setCullFace(culling);
nextTriangulatedGeometry.setDrawMode(drawMode);
healerView.getNextMeshGroup().getChildren().clear();
healerView.getNextMeshGroup().getChildren().addAll(nextTriangulatedGeometry.getMeshes());
nextScene = SceneBuilder.fromPolygons(nextGeometry.getPolygons(), Color.WHITE);
showNextScene();
healerView.getAcceptBtn().setDisable(false);
healerView.getNextStepBtn().setDisable(true);
healerView.getHealCompleteBtn().setDisable(true);
......@@ -414,14 +443,9 @@ public class HealerController {
currentGeometry = nextGeometry;
updateCurrentErrors();
healerView.getNextErrorList().getItems().clear();
healerView.getCurrentMeshGroup().getChildren().clear();
healerView.getCurrentMeshGroup().getChildren().addAll(nextTriangulatedGeometry.getMeshes());
currentTriangulatedGeometry = nextTriangulatedGeometry;
currentErrorVisitor.setGeometry(currentTriangulatedGeometry);
nextTriangulatedGeometry = null;
// nextHighlights = new HighlightController(healerView.getNextWorld());
// nextErrorVisitor = new ListErrorVisitor(nextHighlights);
healerView.getNextMeshGroup().getChildren().clear();
currentScene = nextScene;
showCurrentScene();
clearNextScene();
healerView.getHealCompleteBtn().setDisable(false);
healerView.getNextStepBtn().setDisable(false);
healerView.getAcceptBtn().setDisable(true);
......@@ -429,27 +453,15 @@ public class HealerController {
}
public void setWireframe(boolean b) {
if (b) {
drawMode = DrawMode.LINE;
} else {
drawMode = DrawMode.FILL;
}
if (currentTriangulatedGeometry != null) {
currentTriangulatedGeometry.setDrawMode(drawMode);
}
if (nextTriangulatedGeometry != null) {
nextTriangulatedGeometry.setDrawMode(drawMode);
}
this.wireframe = b;
healerView.getCurrentViewport().setWireframe(b);
healerView.getNextViewport().setWireframe(b);
}
public void setCulling(CullFace culling) {
public void setCulling(boolean culling) {
this.culling = culling;
if (currentTriangulatedGeometry != null) {
currentTriangulatedGeometry.setCullFace(culling);
}
if (nextTriangulatedGeometry != null) {
nextTriangulatedGeometry.setCullFace(culling);
}
healerView.getCurrentViewport().setCulling(culling);
healerView.getNextViewport().setCulling(culling);
}
public void cancelClicked() {
......@@ -457,14 +469,13 @@ public class HealerController {
return;
}
healerView.getNextErrorList().getItems().clear();
healerView.getNextMeshGroup().getChildren().clear();
clearNextScene();
healerView.getAcceptBtn().setDisable(true);
healerView.getCancelBtn().setDisable(true);
healerView.getNextStepBtn().setDisable(false);
healerView.getHealCompleteBtn().setDisable(false);
nextFeature = null;
nextGeometry = null;
nextTriangulatedGeometry = null;
}
public void currentHighlight(CheckError err) {
......@@ -527,8 +538,8 @@ public class HealerController {
healerView.getHealCompleteBtn().setDisable(true);
healerView.getCurrentErrorList().getItems().clear();
healerView.getNextErrorList().getItems().clear();
healerView.getCurrentMeshGroup().getChildren().clear();
healerView.getNextMeshGroup().getChildren().clear();
clearCurrentScene();
clearNextScene();
healerView.setSelectedFeatureText("");
healerView.setFeatureTypeText("");
healerView.setGeometryText("");
......
......@@ -13,7 +13,6 @@ import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.shape.CullFace;
public class HealerToolbar {
......@@ -63,13 +62,7 @@ public class HealerToolbar {
wireframeImage.setImage(new Image(MainToolBar.class.getResourceAsStream("icons/wireframe32x32.png")));
simplyImageView.setImage(new Image(HealerToolbar.class.getResourceAsStream("autopro32x32.png")));
wireframeBtn.selectedProperty().addListener((obs, oldV, newV) -> controller.setWireframe(newV));
cullingBtn.selectedProperty().addListener((obs, oldV, newV) -> {
if (Boolean.TRUE.equals(newV)) {
controller.setCulling(CullFace.BACK);
} else {
controller.setCulling(CullFace.NONE);
}
});
cullingBtn.selectedProperty().addListener((obs, oldV, newV) -> controller.setCulling(Boolean.TRUE.equals(newV)));
saveBtn.setOnAction(ae -> cdController.askAndSave());
saveBtn.setDisable(true);
saveImage.setImage(new Image(MainWindow.class.getResourceAsStream("icons/save.png")));
......
......@@ -13,16 +13,10 @@ import de.hft.stuttgart.citydoctor2.datastructure.CityDoctorModel;
import de.hft.stuttgart.citydoctor2.gui.FilterPane;
import de.hft.stuttgart.citydoctor2.gui.MainWindow;
import de.hft.stuttgart.citydoctor2.gui.View;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import de.hft.stuttgart.citydoctor2.gui.gl.GLViewport;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.AmbientLight;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.PerspectiveCamera;
import javafx.scene.SceneAntialiasing;
import javafx.scene.SubScene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
......@@ -30,11 +24,9 @@ import javafx.scene.control.Tooltip;
import javafx.scene.control.cell.TextFieldListCell;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseButton;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.transform.Rotate;
import javafx.scene.layout.Region;
import javafx.stage.Window;
import javafx.util.StringConverter;
......@@ -42,10 +34,6 @@ public class HealerView extends View {
private static final Logger logger = LogManager.getLogger(HealerView.class);
private static final double CAMERA_TRANSLATE_Z = -100.0;
private static final double CAMERA_INITIAL_X_ANGLE = 20.0;
private static final double CAMERA_INITIAL_Y_ANGLE = 120.0;
private Image image;
private Node healerWindow;
......@@ -55,13 +43,6 @@ public class HealerView extends View {
private ChooseFeatureDialog chooseFeatureDialog;
private HealerToolbar toolBar;
private DoubleProperty translateZ;
private DoubleProperty cameraXRot;
private DoubleProperty cameraYRot;
private double dragX;
private double dragY;
@FXML
private Button fixBtn;
......@@ -121,11 +102,9 @@ public class HealerView extends View {
@FXML
private Button meshBtn;
private Group currentWorld;
private Group nextWorld;
private Group currentMeshGroup;
private Group nextMeshGroup;
private GLViewport currentViewport;
private GLViewport nextViewport;
public HealerView() {
image = new Image(getClass().getResourceAsStream("healing.png"));
......@@ -198,104 +177,40 @@ public class HealerView extends View {
}
private void setup3dViews() {
translateZ = new SimpleDoubleProperty(CAMERA_TRANSLATE_Z);
cameraXRot = new SimpleDoubleProperty(CAMERA_INITIAL_X_ANGLE);
cameraYRot = new SimpleDoubleProperty(CAMERA_INITIAL_Y_ANGLE);
buildCurrent3dView();
buildNext3dView();
}
private void buildCurrent3dView() {
Group currentRoot = new Group();
SubScene currentScene = new SubScene(currentRoot, 500, 300, true, SceneAntialiasing.BALANCED);
currentScene.heightProperty().bind(currentCanvas.heightProperty());
currentScene.widthProperty().bind(currentCanvas.widthProperty());
currentScene.setFill(Color.AZURE);
currentCanvas.getChildren().add(currentScene);
currentWorld = new Group();
currentRoot.getChildren().add(currentWorld);
currentMeshGroup = new Group();
currentWorld.getChildren().add(currentMeshGroup);
AmbientLight al = new AmbientLight(Color.WHITE);
currentRoot.getChildren().add(al);
PerspectiveCamera currentCamera = new PerspectiveCamera(true);
currentCamera.setNearClip(0.1);
currentCamera.setFarClip(10000d);
currentCamera.translateZProperty().bind(translateZ);
Rotate cameraZRotation = new Rotate();
Rotate cameraXRotation = new Rotate();
cameraXRotation.setAxis(Rotate.X_AXIS);
cameraZRotation.setAxis(Rotate.Z_AXIS);
cameraZRotation.angleProperty().bind(cameraXRot);
cameraXRotation.angleProperty().bind(cameraYRot);
currentWorld.getTransforms().add(cameraXRotation);
currentWorld.getTransforms().add(cameraZRotation);
currentRoot.getChildren().add(currentCamera);
currentScene.setCamera(currentCamera);
setupMeshViewControls(currentCanvas);
}
private void buildNext3dView() {
Group nextRoot = new Group();
SubScene nextScene = new SubScene(nextRoot, 500, 300, true, SceneAntialiasing.BALANCED);
nextScene.heightProperty().bind(nextCanvas.heightProperty());
nextScene.widthProperty().bind(nextCanvas.widthProperty());
nextScene.setFill(Color.AZURE);
nextCanvas.getChildren().add(nextScene);
nextWorld = new Group();
nextRoot.getChildren().add(nextWorld);
nextMeshGroup = new Group();
nextWorld.getChildren().add(nextMeshGroup);
AmbientLight al = new AmbientLight(Color.WHITE);
nextRoot.getChildren().add(al);
PerspectiveCamera nextCamera = new PerspectiveCamera(true);
nextCamera.setNearClip(0.1);
nextCamera.setFarClip(10000d);
nextCamera.translateZProperty().bind(translateZ);
Rotate cameraZRotation = new Rotate();
Rotate cameraXRotation = new Rotate();
cameraXRotation.setAxis(Rotate.X_AXIS);
cameraZRotation.setAxis(Rotate.Z_AXIS);
cameraZRotation.angleProperty().bind(cameraXRot);
cameraXRotation.angleProperty().bind(cameraYRot);
nextWorld.getTransforms().add(cameraXRotation);
nextWorld.getTransforms().add(cameraZRotation);
nextRoot.getChildren().add(nextCamera);
nextScene.setCamera(nextCamera);
setupMeshViewControls(nextCanvas);
currentViewport = new GLViewport();
nextViewport = new GLViewport();
attachViewport(currentCanvas, currentViewport);
attachViewport(nextCanvas, nextViewport);
coupleViewports();
}
private void attachViewport(Pane canvas, GLViewport viewport) {
Region node = viewport.getNode();
node.prefWidthProperty().bind(canvas.widthProperty());
node.prefHeightProperty().bind(canvas.heightProperty());
canvas.getChildren().add(node);
}
/**
* Keeps the two viewports' cameras in sync: orbiting/panning/zooming one mirrors the camera into
* the other and redraws it, reproducing the legacy shared-camera behaviour of the dual SubScenes.
*/
private void coupleViewports() {
currentViewport.setInteractionListener(() -> {
nextViewport.camera().copyOrbitFrom(currentViewport.camera());
nextViewport.requestRedraw();
});
nextViewport.setInteractionListener(() -> {
currentViewport.camera().copyOrbitFrom(nextViewport.camera());
currentViewport.requestRedraw();
});
}
public void zoomOutForBoundingBox(BoundingBox b) {
double longestSide = b.getDiagonalLength() * 0.4;
double d = longestSide / Math.tan(Math.toRadians(30) / 2);
translateZ.set(-d);
}
private void setupMeshViewControls(Pane canvas) {
canvas.setOnMousePressed(me -> {
if (me.getButton() == MouseButton.PRIMARY) {
dragX = me.getScreenX();
dragY = me.getScreenY();
}
});
canvas.setOnScroll(se -> translateZ.set(translateZ.get() + se.getDeltaY() / 10d));
canvas.setOnMouseDragged(me -> {
if (me.getButton() == MouseButton.PRIMARY) {
double deltaX = me.getScreenX() - dragX;
double deltaY = me.getScreenY() - dragY;
dragX = me.getScreenX();
dragY = me.getScreenY();
cameraXRot.set(cameraXRot.get() + ((deltaX / 3d) % 360));
cameraYRot.set(cameraYRot.get() + ((deltaY / 3d) % 360));
}
});
currentViewport.camera().zoomOutForBoundingBox(b.getDiagonalLength());
nextViewport.camera().copyOrbitFrom(currentViewport.camera());
currentViewport.requestRedraw();
nextViewport.requestRedraw();
}
@Override
......@@ -330,12 +245,12 @@ public class HealerView extends View {
return chooseFeatureDialog;
}
public Group getCurrentWorld() {
return currentWorld;
public GLViewport getCurrentViewport() {
return currentViewport;
}
public Group getNextWorld() {
return nextWorld;
public GLViewport getNextViewport() {
return nextViewport;
}
public void setSelectedFeatureText(String text) {
......@@ -378,18 +293,6 @@ public class HealerView extends View {
return cancelButton;
}
public DoubleProperty translateZProperty() {
return translateZ;
}
public Group getNextMeshGroup() {
return nextMeshGroup;
}
public Group getCurrentMeshGroup() {
return currentMeshGroup;
}
public Button getSolidInjectorBtn() {
return solidInjectorBtn;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment