From 45cedd0078bd7e06fbe0f78ed8e5f9d59e32abc1 Mon Sep 17 00:00:00 2001 From: Val Erastov Date: Mon, 11 Aug 2014 22:17:04 -0700 Subject: [PATCH] initial cube --- src/cad/fx/AppCtrl.java | 16 ++++++---------- src/cad/fx/CadContext.java | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/cad/fx/AppCtrl.java b/src/cad/fx/AppCtrl.java index fa708921..45317eaa 100644 --- a/src/cad/fx/AppCtrl.java +++ b/src/cad/fx/AppCtrl.java @@ -3,14 +3,12 @@ package cad.fx; import cad.fx.viewer.Viewer3D; import javafx.fxml.Initializable; import javafx.scene.Group; -import javafx.scene.Node; import javafx.scene.control.Button; import java.net.URL; +import java.util.List; import java.util.ResourceBundle; -import static java.util.Collections.singletonList; - public class AppCtrl implements Initializable { private final CadContext cadContext = new CadContext(); @@ -23,7 +21,8 @@ public class AppCtrl implements Initializable { @Override public void initialize(URL location, ResourceBundle resources) { - Group content = new Group(getInitObject()); + Group content = new Group(); + setInitObject(content); viewer.setContent(content); beginSketching.setOnAction(event -> { cadContext.beginSketching(); @@ -36,12 +35,9 @@ public class AppCtrl implements Initializable { }); } - private Node getInitObject() { - - Surface square = Utils3D.createSquare(100); -// square = square.flip(); - return new CSGNode(Utils3D.getMesh(singletonList(square)), cadContext); - + private void setInitObject(Group parent) { + List cube = Utils3D.createCube(100); + parent.getChildren().addAll(cadContext.toNodes(cube)); // // CSG init = new Cube(100).toCSG().difference(new Cylinder(30, 100, 10).toCSG()); // return new CSGNode(Utils3D.getFXMesh(init), cadContext); diff --git a/src/cad/fx/CadContext.java b/src/cad/fx/CadContext.java index 8ee8c437..893188ab 100644 --- a/src/cad/fx/CadContext.java +++ b/src/cad/fx/CadContext.java @@ -10,6 +10,11 @@ import javafx.scene.shape.MeshView; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.stream.Collector; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static java.util.stream.Collectors.toList; public class CadContext { @@ -120,12 +125,20 @@ public class CadContext { List extruded = Surface.extrude(surface, dir); for (Surface s : extruded) { - sketch.drawLayer.getChildren().addAll(new CSGNode( Utils3D.getMesh(Collections.singletonList(s)), this)); // fixme + sketch.drawLayer.getChildren().addAll(toNodes(extruded));// fixme } // CSG pad = Extrude.points(dir, polygon); } } + public List toNodes(List extruded) { + return extruded.stream().map(this::toNode).collect(toList()); + } + + public CSGNode toNode(Surface surface) { + return new CSGNode(Utils3D.getMesh(Collections.singletonList(surface)), this); + } + public static class Selection { public final CSGNode csgNode;