Added Subject3D selection to View3D
- Changed how View3D is added to canvasBase to allow events to get through #story[1190]
This commit is contained in:
@@ -175,8 +175,6 @@ public class RaceController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initialiseView3D(VisualiserRaceEvent race) {
|
private void initialiseView3D(VisualiserRaceEvent race) {
|
||||||
int scale = 1;
|
|
||||||
|
|
||||||
viewSubjects = FXCollections.observableArrayList();
|
viewSubjects = FXCollections.observableArrayList();
|
||||||
|
|
||||||
URL asset = HostController.class.getClassLoader().getResource("assets/V1.2 Complete Boat.stl");
|
URL asset = HostController.class.getClassLoader().getResource("assets/V1.2 Complete Boat.stl");
|
||||||
@@ -196,12 +194,12 @@ public class RaceController extends Controller {
|
|||||||
final GPSConverter gpsConverter = new GPSConverter(lat1, long1, lat2, long2, 450, 450);
|
final GPSConverter gpsConverter = new GPSConverter(lat1, long1, lat2, long2, 450, 450);
|
||||||
|
|
||||||
view3D.setItems(viewSubjects);
|
view3D.setItems(viewSubjects);
|
||||||
canvasBase.getChildren().add(0, view3D);
|
canvasBase.add(view3D, 0, 0);
|
||||||
|
|
||||||
for(Mark mark: race.getVisualiserRaceState().getMarks()) {
|
for(Mark mark: race.getVisualiserRaceState().getMarks()) {
|
||||||
Subject3D subject = new Subject3D(new Sphere(5));
|
Subject3D subject = new Subject3D(new Sphere(5));
|
||||||
subject.setX(gpsConverter.convertGPS(mark.getPosition()).getX() * scale);
|
subject.setX(gpsConverter.convertGPS(mark.getPosition()).getX());
|
||||||
subject.setZ(gpsConverter.convertGPS(mark.getPosition()).getY() * scale);
|
subject.setZ(gpsConverter.convertGPS(mark.getPosition()).getY());
|
||||||
|
|
||||||
viewSubjects.add(subject);
|
viewSubjects.add(subject);
|
||||||
}
|
}
|
||||||
@@ -215,9 +213,9 @@ public class RaceController extends Controller {
|
|||||||
@Override
|
@Override
|
||||||
public void handle(long now) {
|
public void handle(long now) {
|
||||||
subject.setHeading(boat.getBearing().degrees());
|
subject.setHeading(boat.getBearing().degrees());
|
||||||
double x = gpsConverter.convertGPS(boat.getPosition()).getX() * scale;
|
double x = gpsConverter.convertGPS(boat.getPosition()).getX();
|
||||||
subject.setX(x);
|
subject.setX(x);
|
||||||
subject.setZ(gpsConverter.convertGPS(boat.getPosition()).getY() * scale);
|
subject.setZ(gpsConverter.convertGPS(boat.getPosition()).getY());
|
||||||
if(boat.getSourceID() == race.getVisualiserRaceState().getPlayerBoatID()) {
|
if(boat.getSourceID() == race.getVisualiserRaceState().getPlayerBoatID()) {
|
||||||
//view3D.updatePivot(subject.getPosition());
|
//view3D.updatePivot(subject.getPosition());
|
||||||
}
|
}
|
||||||
@@ -227,10 +225,6 @@ public class RaceController extends Controller {
|
|||||||
trackBoat.start();
|
trackBoat.start();
|
||||||
}
|
}
|
||||||
view3D.updatePivot(new Translate(250, 0, 210));
|
view3D.updatePivot(new Translate(250, 0, 210));
|
||||||
|
|
||||||
racePane.setOnScroll(e -> {
|
|
||||||
view3D.updateDistance(e.getDeltaY());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -33,9 +33,6 @@ public class Subject3D {
|
|||||||
this.heading = new Rotate(0, Rotate.Y_AXIS);
|
this.heading = new Rotate(0, Rotate.Y_AXIS);
|
||||||
|
|
||||||
this.mesh.getTransforms().addAll(position, heading, new Rotate(90, Rotate.X_AXIS), new Rotate(180, Rotate.Y_AXIS));
|
this.mesh.getTransforms().addAll(position, heading, new Rotate(90, Rotate.X_AXIS), new Rotate(180, Rotate.Y_AXIS));
|
||||||
this.position.xProperty().addListener(((observable, oldValue, newValue) -> System.out.println("Boat x: " + newValue)));
|
|
||||||
this.position.yProperty().addListener(((observable, oldValue, newValue) -> System.out.println("Boat y: " + newValue)));
|
|
||||||
this.position.zProperty().addListener(((observable, oldValue, newValue) -> System.out.println("Boat z: " + newValue)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Shape3D getMesh() {
|
public Shape3D getMesh() {
|
||||||
|
|||||||
@@ -6,12 +6,17 @@ import javafx.geometry.Point3D;
|
|||||||
import javafx.scene.Group;
|
import javafx.scene.Group;
|
||||||
import javafx.scene.PerspectiveCamera;
|
import javafx.scene.PerspectiveCamera;
|
||||||
import javafx.scene.SubScene;
|
import javafx.scene.SubScene;
|
||||||
|
import javafx.scene.input.PickResult;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
|
import javafx.scene.shape.Shape;
|
||||||
import javafx.scene.shape.Shape3D;
|
import javafx.scene.shape.Shape3D;
|
||||||
import javafx.scene.transform.Rotate;
|
import javafx.scene.transform.Rotate;
|
||||||
import javafx.scene.transform.Translate;
|
import javafx.scene.transform.Translate;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Control for rendering 3D objects visible through a PerspectiveCamera. Implements Adapter Pattern to
|
* Control for rendering 3D objects visible through a PerspectiveCamera. Implements Adapter Pattern to
|
||||||
* interface with camera, and allows clients to add shapes to the scene. All scenes contain sea plane and
|
* interface with camera, and allows clients to add shapes to the scene. All scenes contain sea plane and
|
||||||
@@ -22,6 +27,10 @@ public class View3D extends Pane {
|
|||||||
* Observable list of renderable items
|
* Observable list of renderable items
|
||||||
*/
|
*/
|
||||||
private ObservableList<Subject3D> items;
|
private ObservableList<Subject3D> items;
|
||||||
|
/**
|
||||||
|
* Map for selecting Subject3D from Shape3D
|
||||||
|
*/
|
||||||
|
private Map<Shape3D, Subject3D> selectionMap;
|
||||||
/**
|
/**
|
||||||
* Rendering container for shapes
|
* Rendering container for shapes
|
||||||
*/
|
*/
|
||||||
@@ -56,6 +65,7 @@ public class View3D extends Pane {
|
|||||||
*/
|
*/
|
||||||
public View3D() {
|
public View3D() {
|
||||||
world = new Group();
|
world = new Group();
|
||||||
|
selectionMap = new HashMap<>();
|
||||||
|
|
||||||
SubScene scene = new SubScene(world, 300, 300);
|
SubScene scene = new SubScene(world, 300, 300);
|
||||||
scene.widthProperty().bind(this.widthProperty());
|
scene.widthProperty().bind(this.widthProperty());
|
||||||
@@ -64,6 +74,13 @@ public class View3D extends Pane {
|
|||||||
|
|
||||||
scene.setCamera(buildCamera());
|
scene.setCamera(buildCamera());
|
||||||
|
|
||||||
|
scene.setOnMousePressed(e -> {
|
||||||
|
PickResult result = e.getPickResult();
|
||||||
|
if(result != null && result.getIntersectedNode() != null && result.getIntersectedNode() instanceof Shape3D) {
|
||||||
|
System.out.println(selectionMap.get(result.getIntersectedNode()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
this.getChildren().add(scene);
|
this.getChildren().add(scene);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,8 +112,14 @@ public class View3D extends Pane {
|
|||||||
this.items.addListener((ListChangeListener<? super Subject3D>) c -> {
|
this.items.addListener((ListChangeListener<? super Subject3D>) c -> {
|
||||||
while(c.next()) {
|
while(c.next()) {
|
||||||
if (c.wasRemoved() || c.wasAdded()) {
|
if (c.wasRemoved() || c.wasAdded()) {
|
||||||
for (Subject3D shape : c.getRemoved()) world.getChildren().remove(shape.getMesh());
|
for (Subject3D shape : c.getRemoved()) {
|
||||||
for (Subject3D shape : c.getAddedSubList()) world.getChildren().add(shape.getMesh());
|
world.getChildren().remove(shape.getMesh());
|
||||||
|
selectionMap.remove(shape.getMesh());
|
||||||
|
}
|
||||||
|
for (Subject3D shape : c.getAddedSubList()) {
|
||||||
|
world.getChildren().add(shape.getMesh());
|
||||||
|
selectionMap.put(shape.getMesh(), shape);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user