Changed View3D add-remove interface to an ObservableList
#story[1196]
This commit is contained in:
@@ -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