Changed View3D add-remove interface to an ObservableList

#story[1196]
This commit is contained in:
Connor Taylor-Brown
2017-08-31 00:59:36 +12:00
parent b6e56d815c
commit fb7bf572d8
2 changed files with 23 additions and 8 deletions
@@ -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) {