Changed View3D add-remove interface to an ObservableList
#story[1196]
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package visualiser.Controllers;
|
||||
|
||||
import com.interactivemesh.jfx.importer.stl.StlMeshImporter;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.ButtonType;
|
||||
@@ -11,6 +13,7 @@ import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.shape.Box;
|
||||
import javafx.scene.shape.Mesh;
|
||||
import javafx.scene.shape.MeshView;
|
||||
import javafx.scene.shape.Shape3D;
|
||||
import javafx.scene.transform.Rotate;
|
||||
import mock.app.Event;
|
||||
import mock.exceptions.EventConstructionException;
|
||||
@@ -60,7 +63,10 @@ public class HostController extends Controller {
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
ObservableList<Shape3D> shapes = FXCollections.observableArrayList();
|
||||
|
||||
view3D = new View3D();
|
||||
view3D.setItems(shapes);
|
||||
playerContainer.add(view3D, 0,0);
|
||||
|
||||
URL asset = HostController.class.getClassLoader().getResource("assets/V1.2 Complete Boat.stl");
|
||||
@@ -68,10 +74,9 @@ public class HostController extends Controller {
|
||||
StlMeshImporter importer = new StlMeshImporter();
|
||||
importer.read(asset);
|
||||
MeshView mesh = new MeshView(importer.getImport());
|
||||
|
||||
mesh.getTransforms().add(new Rotate(-90, Rotate.X_AXIS));
|
||||
shapes.add(mesh);
|
||||
|
||||
view3D.addShape(mesh);
|
||||
view3D.setPivot(mesh);
|
||||
view3D.setDistance(50);
|
||||
view3D.setYaw(45);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package visualiser.model;
|
||||
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.Group;
|
||||
import javafx.scene.PerspectiveCamera;
|
||||
import javafx.scene.SubScene;
|
||||
@@ -15,6 +17,10 @@ import javafx.scene.transform.Translate;
|
||||
* sky box, whose textures are set with special methods.
|
||||
*/
|
||||
public class View3D extends Pane {
|
||||
/**
|
||||
* Observable list of renderable items
|
||||
*/
|
||||
private ObservableList<Shape3D> items;
|
||||
/**
|
||||
* Rendering container for shapes
|
||||
*/
|
||||
@@ -83,12 +89,16 @@ public class View3D extends Pane {
|
||||
return camera;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds new Shape3D object to scene
|
||||
* @param shape to add
|
||||
*/
|
||||
public void addShape(Shape3D shape) {
|
||||
world.getChildren().add(shape);
|
||||
public void setItems(ObservableList<Shape3D> items) {
|
||||
this.items = items;
|
||||
this.items.addListener((ListChangeListener<? super Shape3D>) c -> {
|
||||
while(c.next()) {
|
||||
if (c.wasRemoved() || c.wasAdded()) {
|
||||
for (Shape3D shape : c.getRemoved()) world.getChildren().remove(shape);
|
||||
for (Shape3D shape : c.getAddedSubList()) world.getChildren().add(shape);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setNearClip(double nearClip) {
|
||||
|
||||
Reference in New Issue
Block a user