initial cube

This commit is contained in:
Val Erastov 2014-08-11 22:17:04 -07:00
parent 435dd9f02c
commit 45cedd0078
2 changed files with 20 additions and 11 deletions

View file

@ -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<Surface> 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);

View file

@ -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<Surface> 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<CSGNode> toNodes(List<Surface> 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;