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