protected Group buildGroup() { material = new PhongMaterial(); material.setDiffuseColor(Color.ANTIQUEWHITE); material.setSpecularColor(Color.rgb(255, 255, 255)); material.setSpecularPower(4); ss = new SemiSphere(2, 120, 120); Shape3D sh = ss.getMesh(); // Shape3D sh = new Sphere(); sh.setMaterial(material); sh.setScaleX(SCALE); sh.setScaleY(SCALE); sh.setScaleZ(SCALE); light1Group = new Group(); light2Group = new Group(); light1mv = new GroupMover(light1Group); light2mv = new GroupMover(light2Group); root = new Group(light1mv.getGroup(), light2mv.getGroup(), ss.getGroup()); rootmv = new GroupMover(root); return rootmv.getGroup(); }
private void rotate3Dto(Shape3D shape, float tx, float ty, float tz){ if (rotationToInProgress){ return; } //System.out.printf("rotate3Dto:%s %f | %f | %f\n", shape.getId(), tx, ty, tz); rotationToInProgress = true; Rotate rxBox = new Rotate(0, 0, 0, 0, Rotate.X_AXIS); Rotate ryBox = new Rotate(0, 0, 0, 0, Rotate.Y_AXIS); Rotate rzBox = new Rotate(0, 0, 0, 0, Rotate.Z_AXIS); float rx = tx - originX; float ry = ty - originY; float rz = tz - originZ; rxBox.setAngle(rx); ryBox.setAngle(ry); rzBox.setAngle(rz); shape.getTransforms().addAll(rxBox, ryBox, rzBox); originX = tx; originY = ty; originZ = tz; rotationToInProgress = false; }
public void setXYZData(List<Double> xData, List<Double> yData, List<Double> zData, List<Color> colors) { xAxisData = xData; yAxisData = yData; zAxisData = zData; scatterDataGroup.getChildren().clear(); //for now we will always default to x axis //later we could maybe dynamically determine the smallest axis and then //uses 0's for the other axes that are larger. for(int i=0;i<xAxisData.size();i++) { final Shape3D dataSphere = createDefaultNode(nodeRadius); double translateY = 0.0; double translateZ = 0.0; if(!yAxisData.isEmpty() && yAxisData.size() > i) translateY = yAxisData.get(i); if(!zAxisData.isEmpty() && zAxisData.size() > i) translateZ = zAxisData.get(i); dataSphere.setTranslateX(xAxisData.get(i)); dataSphere.setTranslateY(translateY); dataSphere.setTranslateZ(translateZ); dataSphere.setMaterial(new PhongMaterial(colors.get(i))); scatterDataGroup.getChildren().add(dataSphere); } }
protected void bindMaterial(Group group) { Material material = createMaterial(); for (Node node : group.getChildren()) if (node instanceof Shape3D) ((Shape3D) node).setMaterial(material); else if (node instanceof SkinMultipleCubes) ((SkinMultipleCubes) node).updateSkin(skin); else if (node instanceof Group) bindMaterial((Group) node); }
public Group buildGroup() { initMaterials(); meshView = new Shape3D[(int) Math.pow(side, 3) - (int) Math.pow(side - 2, 3)]; int i = 0; for (int x = 0; x < side; x++) { for (int y = 0; y < side; y++) { for (int z = 0; z < side; z++) { if (x == 0 || y == 0 || z == 0 || z == side - 1 || y == side - 1 || x == side - 1) { meshView[i] = new Sphere(radius); meshView[i].setMaterial(getMtrl(x, y, z)); meshView[i].setScaleX(SCALE); meshView[i].setScaleY(SCALE); meshView[i].setScaleZ(SCALE); meshView[i].setTranslateX((x - (side) / 2) * SCALE * 2 * radius + SCALE * radius); meshView[i].setTranslateY((y - (side) / 2) * SCALE * 2 * radius + SCALE * radius); meshView[i].setTranslateZ((z - (side) / 2) * SCALE * 2 * radius + SCALE * radius); i++; } } } } root = new Group(meshView); root.setFocusTraversable(true); grp = new Group(root); return grp; }
@Override protected Shape3D[] getShapes() { Shape3D[] result = { new Sphere(1), new Sphere(1), }; result[1].setTranslateX(1); result[0].setTranslateX(-1); return result; }
@Override protected Shape3D[] getShapes() { Shape3D[] result = { new Box(2, 2, 2), new Box(2, 2, 2) }; result[1].setTranslateX(1.5); result[0].setTranslateX(-1.5); return result; }
@Override protected Shape3D[] getShapes() { Shape3D[] result = { new Cylinder(1.3, 2), new Cylinder(1.3, 2) }; result[1].setTranslateX(2); result[0].setTranslateX(-1); return result; }
@Override protected Shape3D[] getShapes() { Shape3D[] result = { new Sphere(1), new Sphere(1.5) }; result[1].setTranslateX(1.5); result[1].setTranslateY(1.5); return result; }
@Override protected Shape3D[] getShapes() { Shape3D[] result = { new Box(4, 4, 1), new Box(2, 2, 2) }; result[0].setRotationAxis(Rotate.Y_AXIS); result[0].setRotate(45); result[1].setRotationAxis(Rotate.X_AXIS); result[1].setRotate(45); return result; }
@Override protected Shape3D[] getShapes() { Shape3D[] result = { new Box(2, 2, 2), new Cylinder(1, 4) }; result[0].setTranslateX(1); result[0].setRotationAxis(Rotate.Y_AXIS); result[0].setRotate(45); result[1].setRotationAxis(Rotate.X_AXIS); result[1].setRotate(45); return result; }
@Override protected Shape3D[] getShapes() { Shape3D[] result = { new Cylinder(1, 4), new Cylinder(1, 4) }; result[0].setTranslateX(1); result[0].setRotationAxis(Rotate.Y_AXIS); result[0].setRotate(45); result[1].setRotationAxis(Rotate.X_AXIS); result[1].setRotate(45); return result; }
@Override protected Shape3D[] getShapes() { Shape3D[] result = { new Box(2, 2, 2), new Sphere(2) }; result[1].setTranslateX(1); result[1].setTranslateY(1); result[0].setRotationAxis(Rotate.Y_AXIS); result[0].setRotate(45); return result; }
@Override protected Shape3D[] getShapes() { Shape3D[] result = { new Cylinder(1.5, 4), new Sphere(1.5) }; result[1].setTranslateX(1); return result; }
protected Group buildGroup() { material = new PhongMaterial(Color.RED); ss = new SemiSphere(); Shape3D sh = ss.getMesh(); sh.setMaterial(material); sh.setScaleX(SCALE); sh.setScaleY(SCALE); sh.setScaleZ(SCALE); lightGroup = new Group(); lightmv = new GroupMover(lightGroup); root = new Group(lightmv.getGroup(), ss.getGroup()); rootmv = new GroupMover(root); return rootmv.getGroup(); }
/** * Test that the edge can be drawn transparently */ @Test @Ignore public void checkTransparency() { // Create a view for a vertex FXVertexView view = new FXVertexView(new Vertex(0, 0, 0)); // The view should start off opaque assertFalse(view.isTransparent()); // Make the view transparent view.setTransparentMode(true); // Check that the transparency flag is set assertTrue(view.isTransparent()); // Whether a sphere shape has been found while searching the JavaFX // node's children. boolean sphereFound = false; // Get the group containing the node Representation<Group> representation = view.getRepresentation(); // Search all of the node's children for (Node node : (representation.getData()).getChildren()) { // If the child is a 3D shape, it should be transparent if (node instanceof Shape3D) { assertTrue(((Shape3D) node).getOpacity() == 0d); sphereFound = true; break; } } // A child sphere corresponding to the vertex should have been found assertTrue(sphereFound); }
/** * Test that the vertex can be drawn in wireframe mode */ @Test @Ignore public void checkWireframe() { // Create a view for a vertex FXVertexView view = new FXVertexView(new Vertex(0, 0, 0)); // The view should start off opaque assertFalse(view.isWireframe()); // Make the view transparent view.setWireframeMode(true); // Check that the transparency flag is set assertTrue(view.isWireframe()); // Whether a sphere shape has been found while searching the JavaFX // node's children. boolean sphereFound = false; // Get the group containing the node Representation<Group> representation = view.getRepresentation(); // Search all of the node's children for (Node node : (representation.getData()).getChildren()) { // If the child is a 3D shape, it should be transparent if (node instanceof Shape3D) { assertTrue(((Shape3D) node).getDrawMode() == DrawMode.LINE); sphereFound = true; break; } } // A child sphere corresponding to the vertex should have been found assertTrue(sphereFound); }
private Shape3D createDefaultNode(double radius) { switch(defaultNodeType) { case SPHERE: return new Sphere(radius); case CUBE: return new Box(radius, radius, radius); default: return new Box(radius, radius, radius); } }
@Test public void testGetShape3DAdjuster() { Adjuster adjuster = Adjuster.getAdjuster(Shape3D.class); assertThat(adjuster, is(instanceOf(NodeAdjuster.class))); assertThat(adjuster.getNodeClass(), is(sameInstance(Node.class))); }
@Override public Shape3D getShape() { box = new Box(2, 2, 2); return box; }
@Override protected Shape3D getShape() { triMesh = buildTriMesh(); meshView = new MeshView(triMesh); return meshView; }
private Group buildSingle(Shape3D shape) { Group grp = new Group(shape); nodes.add(shape); return grp; }
/** * Test that the edge can be drawn transparently */ @Test @Ignore public void checkTransparency() { // Create a view for an edge FXVertexController v1 = new FXVertexController(new Vertex(0, 0, 0), new FXVertexView(new Vertex(0, 0, 0))); FXVertexController v2 = new FXVertexController(new Vertex(1, 1, 1), new FXVertexView(new Vertex(1, 1, 1))); LinearEdge edge = new LinearEdge(v1, v2); FXLinearEdgeView view = new FXLinearEdgeView(edge); // The view should start off opaque assertFalse(view.isTransparent()); // Make the view transparent view.setTransparentMode(true); // Check that the transparency flag is set assertTrue(view.isTransparent()); // Whether a clinder shape has been found while searching the JavaFX // node's // children. boolean edgeFound = false; // Get the group containing the node Representation<Group> representation = view.getRepresentation(); // Search all of the node's children for (Node node : (representation.getData()).getChildren()) { // If the child is a 3D shape, it should be transparent if (node instanceof Shape3D) { assertTrue(((Shape3D) node).getOpacity() == 0d); edgeFound = true; break; } } // A child box corresponding to the cube should have been found assertTrue(edgeFound); }
/** * Test that the edge can be drawn transparently */ @Test @Ignore public void checkWireframe() { // Create a view for an edge FXVertexController v1 = new FXVertexController(new Vertex(0, 0, 0), new FXVertexView(new Vertex(0, 0, 0))); FXVertexController v2 = new FXVertexController(new Vertex(1, 1, 1), new FXVertexView(new Vertex(1, 1, 1))); LinearEdge edge = new LinearEdge(v1, v2); FXLinearEdgeView view = new FXLinearEdgeView(edge); // The view should start off opaque assertFalse(view.isWireframe()); // Make the view transparent view.setWireframeMode(true); // Check that the transparency flag is set assertTrue(view.isWireframe()); // Whether a clinder shape has been found while searching the JavaFX // node's children. boolean edgeFound = false; // Get the group containing the node Representation<Group> representation = view.getRepresentation(); // Search all of the node's children for (Node node : (representation.getData()).getChildren()) { // If the child is a 3D shape, it should be transparent if (node instanceof Shape3D) { assertTrue(((Shape3D) node).getDrawMode() == DrawMode.LINE); edgeFound = true; break; } } // A child box corresponding to the cube should have been found assertTrue(edgeFound); }
/** * <p> * Hooks up JavaFX picking with JFace selections. * </p> */ protected void wireSelectionHandling() { scene.setOnMousePressed(new EventHandler<MouseEvent>() { Group lastSelection = null; @Override public void handle(MouseEvent event) { // Pick PickResult pickResult = event.getPickResult(); Node intersectedNode = pickResult.getIntersectedNode(); if (intersectedNode == null) { return; } if (!(intersectedNode instanceof Shape3D)) { return; } // Resolve the parent Group nodeParent = (Group) intersectedNode.getParent(); if (nodeParent == lastSelection) { return; } // Resolve the shape IRenderElement modelShape = (IRenderElement) nodeParent .getProperties().get(ShapeController.class); if (modelShape == null) { return; } // Create and set the viewer selection // (event gets fired in parent class) FXSelection selection = new FXSelection(modelShape); setSelection(selection); lastSelection = nodeParent; } }); }
/** * The function called whenever the user clicks the mouse while in Edit * mode. * * @param event * The event that prompted the invocation of this function. */ private void handleEditModeClick(MouseEvent event) { // Get the mouse position mousePosX = event.getSceneX(); mousePosY = event.getSceneY(); mouseOldX = event.getSceneX(); mouseOldY = event.getSceneY(); // Get the user's selection PickResult pickResult = event.getPickResult(); Node intersectedNode = pickResult.getIntersectedNode(); if (intersectedNode instanceof Shape3D) { // Resolve the parent Group nodeParent = (Group) intersectedNode.getParent(); // Resolve the shape IController modelShape = (IController) nodeParent.getProperties() .get(IController.class); // If the user clicked a vertex, handle it if (modelShape instanceof VertexController) { // If shift is down, add the vertex to the selection if (event.isShiftDown()) { selectedVertices.add(modelShape); modelShape.setProperty(MeshProperty.SELECTED, "True"); } // If shift is not down and control is, either add the // vertex to the selection if it is not present already // or remove it if it is. else if (event.isControlDown()) { if (selectedVertices.contains(modelShape)) { selectedVertices.remove(modelShape); modelShape.setProperty(MeshProperty.SELECTED, "False"); } else { selectedVertices.add(modelShape); modelShape.setProperty(MeshProperty.SELECTED, "True"); } } // If nothing is pressed, select that vertex and nothing // else else { clearSelection(); selectedVertices.add(modelShape); modelShape.setProperty(MeshProperty.SELECTED, "True"); } } } }
/** * Updates the transformation matrix. * can change the Translate for fixed distance */ default void updateMatrix(){ Transform cam = getOther().getLocalToSceneTransform(), self = getBillboardNode().getLocalToSceneTransform(); Bounds b; double cX, cY, cZ; if(!(getBillboardNode() instanceof Shape3D)){ b = getBillboardNode().getBoundsInLocal(); cX = b.getWidth() / 2; cY = b.getHeight() / 2; cZ = b.getDepth() / 2; }else{ cX = self.getTx(); cY = self.getTy(); cZ = self.getTz(); } Point3D camPos = new Point3D(cam.getTx(), cam.getTy(), cam.getTz()); Point3D selfPos = new Point3D(cX, cY, cZ); Vector3D up = Vector3D.UP, forward = new Vector3D( (selfPos.getX()) - camPos.getX(), (selfPos.getY()) - camPos.getY(), (selfPos.getZ()) - camPos.getZ() ).toNormal(), right = up.crossProduct(forward).toNormal(); up = forward.crossProduct(right).toNormal(); switch(getBillboardMode()){ case SPHERICAL: affine.setMxx(right.x); affine.setMxy(up.x); affine.setMzx(forward.x); affine.setMyx(right.y); affine.setMyy(up.y); affine.setMzy(forward.y); affine.setMzx(right.z); affine.setMzy(up.z); affine.setMzz(forward.z); affine.setTx(cX * (1 - affine.getMxx()) - cY * affine.getMxy() - cZ * affine.getMxz()); affine.setTy(cY * (1 - affine.getMyy()) - cX * affine.getMyx() - cZ * affine.getMyz()); affine.setTz(cZ * (1 - affine.getMzz()) - cX * affine.getMzx() - cY * affine.getMzy()); break; case CYLINDRICAL: affine.setMxx(right.x); affine.setMxy(0); affine.setMzx(forward.x); affine.setMyx(0); affine.setMyy(1); affine.setMzy(0); affine.setMzx(right.z); affine.setMzy(0); affine.setMzz(forward.z); affine.setTx(cX * (1 - affine.getMxx()) - cY * affine.getMxy() - cZ * affine.getMxz()); affine.setTy(cY * (1 - affine.getMyy()) - cX * affine.getMyx() - cZ * affine.getMyz()); affine.setTz(cZ * (1 - affine.getMzz()) - cX * affine.getMzx() - cY * affine.getMzy()); break; } }
/**Adds the low resolution interaction to the low resolution model. * Do not use this on the high resolution model. * @param shape the node (spheres,MeshViews) that should be selectable **/ private void addLowResolutionInteraction(Shape3D shape){ shape.addEventHandler(MouseEvent.MOUSE_CLICKED, mouseClick -> { if (mouseClick.getButton().toString().matches("SECONDARY")) { Node pickedNode = mouseClick.getPickResult().getIntersectedNode(); if (debugMode) { System.out.println("CLICKED NODE "+pickedNode); } //handleSelection(subsetNodeSelection, subsetNodeSelectionMaterial, pickedNode, new MeshView()); handleLowResolutionSelection(pickedNode); } }); }
protected abstract Shape3D getShape();
protected abstract Shape3D[] getShapes();