@Override protected void initKeys(Scene scene) { scene.addEventHandler(KeyEvent.ANY, new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent t) { switch (t.getText()) { case "1": setShape(Shape.Sphere); break; case "2": setShape(Shape.Box); break; case "3": setShape(Shape.Cylinder); break; } } }); }
private Group buildMultipleShapes3D() { Box box = new Box(100, 100, 100); Sphere sphere = new Sphere(50); Cylinder cyl = new Cylinder(50, 100); Cone cone = new Cone(50, 100); box.setTranslateX(-100); box.setTranslateY(-150); sphere.setTranslateX(100); sphere.setTranslateY(-50); cyl.setTranslateX(-100); cyl.setTranslateY(50); cone.getMesh().setTranslateX(100); cone.getMesh().setTranslateY(150); nodes.add(box); nodes.add(sphere); nodes.add(cyl); nodes.add(cone.getMesh()); return new Group(box, sphere, cyl, cone.getMesh()); }
private Cylinder createCylinderConnecting(Vector3D source, Vector3D target) { Vector3D delta = target.subtract(source); double distance = source.distanceTo(target); Cylinder bond = new Cylinder(0.4, distance, 10); Vector3D newLocation = delta.divide(2).add(source); bond.setTranslateX(newLocation.getX()); bond.setTranslateY(newLocation.getY()); bond.setTranslateZ(newLocation.getZ()); // phi bond.getTransforms().add(new Rotate(90 + Math.toDegrees(Math.atan2(delta.getY(), delta.getX())), Rotate.Z_AXIS)); // theta bond.getTransforms().add(new Rotate(90 + Math.toDegrees(Math.acos(delta.getZ() / distance)), Rotate.X_AXIS)); return bond; }
private Group makeBaseTube(double height, double r1, double r2) { // horizontal tube with heads double half = height / 2; Cylinder t0 = new Cylinder(r1, height); Cylinder t1 = new Cylinder(r2, 0.12); Cylinder t2 = new Cylinder(r2, 0.12); Cylinder t3 = new Cylinder(r2, 0.12); Cylinder t4 = new Cylinder(r2, 0.12); t0.setMaterial(material); t1.setMaterial(material); t2.setMaterial(material); t3.setMaterial(material); t4.setMaterial(material); t1.setTranslateY(half + 0.13); t2.setTranslateY(half); t3.setTranslateY(-half + 0.7); t4.setTranslateY(-half + 0.57); return new Group(t0, t1, t2, t3, t4); }
public CSG servoHeadMale(double headHeight, double headDiameter, int toothCount, double toothHeight, double toothWidth, double toothLength) { double clear = 0.3; double radius = headDiameter / 2 - toothHeight + clear; CSG cylinder = new eu.mihosoft.vrl.v3d.Cylinder(new Vector3d(0, 0, 0), new Vector3d(0, 0, headHeight), radius + 0.03, toothCount * 2).toCSG(); CSG t = Extrude.points(new Vector3d(0, 0, headHeight), new Vector3d(-toothLength / 2, 0), new Vector3d(-toothWidth / 2, toothHeight), new Vector3d(toothWidth / 2, toothHeight), new Vector3d(toothLength / 2, 0)); double delta = 360.0 / toothCount; CSG result = makeTooth(radius, 0, t); for (int i = 1; i < toothCount; i++) { CSG tooth = makeTooth(radius, i * delta, t); result = result.union(tooth); } return result.union(cylinder); }
public Bone(double scale, Point3D posJoint) { Box origin=new Box(10,10,10); origin.setMaterial(new PhongMaterial(Color.ORANGE)); Cylinder bone = new Cylinder(5, posJoint.magnitude()/scale); double angle = Math.toDegrees(Math.acos((new Point3D(0,1,0)).dotProduct(posJoint)/posJoint.magnitude())); Point3D axis = (new Point3D(0,1,0)).crossProduct(posJoint); bone.getTransforms().addAll(new Rotate(angle,0,0,0,axis), new Translate(0,posJoint.magnitude()/2d/scale, 0)); bone.setMaterial(new PhongMaterial(Color.CADETBLUE)); Sphere end = new Sphere(6); end.getTransforms().addAll(new Translate(posJoint.getX()/scale,posJoint.getY()/scale,posJoint.getZ()/scale)); end.setMaterial(new PhongMaterial(Color.YELLOW)); getChildren().addAll(origin, bone, end); getTransforms().add(new Scale(scale, scale, scale)); }
public Axes(double scale) { Cylinder axisX = new Cylinder(3, 60); axisX.getTransforms().addAll(new Rotate(90, Rotate.Z_AXIS), new Translate(0, 30, 0)); axisX.setMaterial(new PhongMaterial(Color.RED)); Cylinder axisY = new Cylinder(3, 60); axisY.getTransforms().add(new Translate(0, 30, 0)); axisY.setMaterial(new PhongMaterial(Color.GREEN)); Cylinder axisZ = new Cylinder(3, 60); axisZ.setMaterial(new PhongMaterial(Color.BLUE)); axisZ.getTransforms().addAll(new Rotate(90, Rotate.X_AXIS), new Translate(0, 30, 0)); getChildren().addAll(axisX, axisY, axisZ); getTransforms().add(new Scale(scale, scale, scale)); }
@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 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 Cylinder(1.5, 4), new Sphere(1.5) }; result[1].setTranslateX(1); return result; }
public void initTestCase(TestCaseType type) { if (isThereTestCase) { root.getChildren().clear(); nodes.clear(); lights.clear(); movers.clear(); } switch (type) { case SINGLE_SPHERE_CASE: root.getChildren().add(buildSingle(new Sphere(50))); break; case SINGLE_BOX_CASE: root.getChildren().add(buildSingle(new Box(100, 100, 100))); break; case SINGLE_CYLINDER_CASE: root.getChildren().add(buildSingle(new Cylinder(50, 100))); break; case SINGLE_MESH_CASE: Cone cone = new Cone(50, 100); root.getChildren().add(buildSingle(cone.getMesh())); break; case MULTIPLE_SHAPE3D_CASE: root.getChildren().add(buildMultipleShapes3D()); break; case MULTIPLE_SHAPE_CASE: root.getChildren().add(buildMultipleShapes()); break; } isThereTestCase = true; }
private Group buildMultipleShapes() { Box box = new Box(100, 100, 100); Sphere sphere = new Sphere(50); Cylinder cyl = new Cylinder(50, 100); Cone cone = new Cone(50, 100); Rectangle rect = new Rectangle(50, 50); rect.setFill(Color.WHITESMOKE); box.setTranslateX(-100); box.setTranslateY(-150); sphere.setTranslateX(100); sphere.setTranslateY(-50); cyl.setTranslateX(-100); cyl.setTranslateY(50); cone.getMesh().setTranslateX(100); cone.getMesh().setTranslateY(150); rect.setTranslateX(-25); rect.setTranslateY(-25); rect.setRotationAxis(Rotate.Y_AXIS); rect.setRotate(45); nodes.add(box); nodes.add(sphere); nodes.add(cyl); nodes.add(cone.getMesh()); nodes.add(rect); return new Group(box, sphere, cyl, cone.getMesh(), rect); }
private Node createDefaultNode(double barWidth, double barHeight) { switch (defaultNodeType) { case CYLINDER: return new Cylinder(barWidth / 2, barHeight); case CUBE: return new Box(barWidth, barHeight, barWidth); default: return new Box(barWidth, barHeight, barWidth); } }
@Test public void testGetCylinderAdjuster() { Adjuster adjuster = Adjuster.getAdjuster(Cylinder.class); assertThat(adjuster, is(instanceOf(NodeAdjuster.class))); assertThat(adjuster.getNodeClass(), is(sameInstance(Node.class))); }
private Group makePump(double height, double r1, double r2, PhongMaterial headMaterial) { double half = height / 2; Cylinder t1 = new Cylinder(r1, height); Cylinder t2 = new Cylinder(r2, 0.2); Cylinder t3 = new Cylinder(r2, 0.2); t2.setTranslateY(half); t3.setTranslateY(-half); t1.setMaterial(material); t2.setMaterial(headMaterial); t3.setMaterial(material); return new Group(t1, t2, t3); }
private Group makePump1(double height, double r1, double r2, PhongMaterial headMaterial) { double half = height / 2; Cylinder t1 = new Cylinder(r1, height); Cylinder t2 = new Cylinder(r2, 0.2); t2.setTranslateY(half); t1.setMaterial(material); t2.setMaterial(headMaterial); return new Group(t1, t2); }
@Override public void handle(KeyEvent t) { System.out.println(t.getText()); switch (t.getText()) { case "1": selectType(ShapeType.Box); break; case "2": selectType(ShapeType.Cone); break; case "3": selectType(ShapeType.Plane); break; case "4": selectType(ShapeType.SemiSphere); break; case "5": selectType(ShapeType.Sphere); break; case "6": selectType(ShapeType.Cylinder); break; case "l": setLight(true); break; case "k": setLight(false); break; case "z": moveObject(-100); break; case "x": moveObject(100); break; case "c": moveGroup(-100); break; case "v": moveGroup(100); break; case "a": moveCamera(-100); break; case "s": moveCamera(100); break; case "d": moveCameraGroup(-100); break; case "f": moveCameraGroup(100); break; } }
@Override public void start(Stage primaryStage) throws Exception { primaryStage.setResizable(false); Scene scene = new Scene(root, 1024, 800, true); // Create and position camera Camera camera = new PerspectiveCamera(); camera.getTransforms().addAll( new Rotate(0, Rotate.Y_AXIS), new Rotate(0, Rotate.X_AXIS), new Translate(-500, -425, 1200)); scene.setCamera(camera); scene.setFill(Paint.valueOf(Color.BLACK.toString())); // Box testObject = new Cylinder(10, 50); testObject.setMaterial(new PhongMaterial(Color.RED)); testObject.getTransforms().addAll(new Translate(50, 0, 0)); TdsModelImporter model_importer = new TdsModelImporter(); model_importer.read(getClass().getResource("/models/SpaceLaunchSystem.3DS")); Node[] nodes = model_importer.getImport(); model_importer.close(); Group rocket = new Group(nodes); rocket.getTransforms().addAll(new Translate(0, 25, 0)); // Build the Scene Graph root.getChildren().addAll(testObject, rocket); primaryStage.setScene(scene); primaryStage.show(); primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() { @Override public void handle(WindowEvent event) { System.out.println(event); if (event.getEventType().equals(WindowEvent.WINDOW_CLOSE_REQUEST)) { System.exit(0); } } }); mqttClient.subscribe(MQTT_TOPIC_IMU + "/#"); }
private void addLeafBond(LeafSubstructure origin, OakBond bond) { Cylinder bondShape = createCylinderConnecting(bond.getSource().getPosition(), bond.getTarget().getPosition()); bondShape.setMaterial(getMaterial(origin, bond)); moleculeGroup.getChildren().add(bondShape); }
private void addChainBond(Chain origin, OakBond bond) { Cylinder bondShape = createCylinderConnecting(bond.getSource().getPosition(), bond.getTarget().getPosition()); bondShape.setMaterial(getMaterial(origin, bond)); moleculeGroup.getChildren().add(bondShape); }
/** * Creates a cylinder between the start and end points of the edge. * * @return A JavaFX Cylinder representing the given LinearEdgeComponent */ private Cylinder createShape(Edge edgeComponent) { // If the edge does not have two vertices, a new shape cannot be created if (edgeComponent.getEntitiesFromCategory(MeshCategory.VERTICES) .size() != 2) { return null; } // Get the scale the vertices are being drawn at int scale = ((FXVertexController) edgeComponent .getEntitiesFromCategory(MeshCategory.VERTICES).get(0)) .getApplicationScale(); // Get the edge's endpoints double[] start = edgeComponent.getStartLocation(); double[] end = edgeComponent.getEndLocation(); for (int i = 0; i < 3; i++) { start[i] = start[i] * scale; end[i] = end[i] * scale; } // Create a cylinder situated at the edge's midpoint with the edge's // length. Cylinder edge = new Cylinder(.6, Math.sqrt((Math.pow(start[0] - end[0], 2)) + (Math.pow(start[1] - end[1], 2)) + (Math.pow(start[2] - end[2], 2)))); edge.setTranslateX((start[0] + end[0]) / 2); edge.setTranslateY((start[1] + end[1]) / 2); edge.setTranslateZ((start[2] + end[2]) / 2); // Get the angle between the two points Point3D start3D = new Point3D(start[0], start[1], start[2]); Point3D end3D = new Point3D(end[0], end[1], end[2]); Point3D angle = end3D.subtract(start3D); // Get the axis of rotation for the cylinder Point3D axis = angle.crossProduct(0f, 1f, 0f); // Calculate the number of degrees to rotate about the axis. double rotationAmount = Math .acos(angle.normalize().dotProduct(0, 1, 0)); // Apply the rotation to the cylinder Rotate rotation = new Rotate(-Math.toDegrees(rotationAmount), axis); edge.getTransforms().addAll(rotation); return edge; }
@Override public void start(Stage primaryStage) throws Exception { final PhongMaterial red = new PhongMaterial(Color.RED); final PhongMaterial green = new PhongMaterial(Color.GREEN); final PhongMaterial blue = new PhongMaterial(Color.BLUE); final Box cube = new Box(200, 200, 200); cube.setLayoutX(150); cube.setLayoutY(800); cube.setDrawMode(DrawMode.LINE); cube.setMaterial(red); final Cylinder cylinder = new Cylinder(150, 50); cylinder.setLayoutX(500); cylinder.setLayoutY(800); cylinder.setDrawMode(DrawMode.LINE); cylinder.setMaterial(green); final Sphere sphere = new Sphere(100); sphere.setLayoutX(850); sphere.setLayoutY(800); sphere.setDrawMode(DrawMode.LINE); sphere.setMaterial(blue); final AmbientLight light = new AmbientLight(Color.WHITE); final Pane root = new Pane(); root.setStyle("-fx-background-color: transparent;"); root.getChildren().addAll(cube, cylinder, sphere, light); final int[] tesselations = {1, 5, 10, 50, 100}; for (int index = 0; index < tesselations.length; index++) { final int dx = 1000 / tesselations.length; final int tesselation = tesselations[index]; final Sphere tesselatedSphere = new Sphere(75, tesselation); tesselatedSphere.setDrawMode(DrawMode.LINE); root.getChildren().add(tesselatedSphere); tesselatedSphere.setTranslateX(100 + dx * index); tesselatedSphere.setTranslateY(400); final Cylinder tesselatedCylinder = new Cylinder(75, 50, tesselation); tesselatedCylinder.setDrawMode(DrawMode.LINE); root.getChildren().add(tesselatedCylinder); tesselatedCylinder.setTranslateX(100 + dx * index); tesselatedCylinder.setTranslateY(100); } final Scene scene = new Scene(root, 1000, 1000); scene.setFill(Color.BLACK); scene.setCamera(new PerspectiveCamera()); primaryStage.setScene(scene); primaryStage.setTitle("Test_Triangle"); primaryStage.show(); }
private void buildMolecule() { final PhongMaterial redMaterial = new PhongMaterial(); redMaterial.setDiffuseColor(Color.DARKRED); redMaterial.setSpecularColor(Color.RED); final PhongMaterial whiteMaterial = new PhongMaterial(); whiteMaterial.setDiffuseColor(Color.WHITE); whiteMaterial.setSpecularColor(Color.LIGHTBLUE); final PhongMaterial greyMaterial = new PhongMaterial(); greyMaterial.setDiffuseColor(Color.DARKGREY); greyMaterial.setSpecularColor(Color.GREY); // Molecule Hierarchy // [*] moleculeXform // [*] oxygenXform // [*] oxygenSphere // [*] hydrogen1SideXform // [*] hydrogen1Xform // [*] hydrogen1Sphere // [*] bond1Cylinder // [*] hydrogen2SideXform // [*] hydrogen2Xform // [*] hydrogen2Sphere // [*] bond2Cylinder Xform moleculeXform = new Xform(); Xform oxygenXform = new Xform(); Xform hydrogen1SideXform = new Xform(); Xform hydrogen1Xform = new Xform(); Xform hydrogen2SideXform = new Xform(); Xform hydrogen2Xform = new Xform(); Sphere oxygenSphere = new Sphere(40.0); oxygenSphere.setMaterial(redMaterial); Sphere hydrogen1Sphere = new Sphere(30.0); hydrogen1Sphere.setMaterial(whiteMaterial); hydrogen1Sphere.setTranslateX(0.0); Sphere hydrogen2Sphere = new Sphere(30.0); hydrogen2Sphere.setMaterial(whiteMaterial); hydrogen2Sphere.setTranslateZ(0.0); Cylinder bond1Cylinder = new Cylinder(5, 100); bond1Cylinder.setMaterial(greyMaterial); bond1Cylinder.setTranslateX(50.0); bond1Cylinder.setRotationAxis(Rotate.Z_AXIS); bond1Cylinder.setRotate(90.0); Cylinder bond2Cylinder = new Cylinder(5, 100); bond2Cylinder.setMaterial(greyMaterial); bond2Cylinder.setTranslateX(50.0); bond2Cylinder.setRotationAxis(Rotate.Z_AXIS); bond2Cylinder.setRotate(90.0); moleculeXform.getChildren().add(oxygenXform); moleculeXform.getChildren().add(hydrogen1SideXform); moleculeXform.getChildren().add(hydrogen2SideXform); oxygenXform.getChildren().add(oxygenSphere); hydrogen1SideXform.getChildren().add(hydrogen1Xform); hydrogen2SideXform.getChildren().add(hydrogen2Xform); hydrogen1Xform.getChildren().add(hydrogen1Sphere); hydrogen2Xform.getChildren().add(hydrogen2Sphere); hydrogen1SideXform.getChildren().add(bond1Cylinder); hydrogen2SideXform.getChildren().add(bond2Cylinder); hydrogen1Xform.setTx(100.0); hydrogen2Xform.setTx(100.0); hydrogen2SideXform.setRotateY(104.5); moleculeGroup.getChildren().add(moleculeXform); world.getChildren().addAll(moleculeGroup); }
private Group makeGauge(double ratio) { Group group = new Group(); ObservableList<Node> children = group.getChildren(); CSG outer = new eu.mihosoft.vrl.v3d.Cylinder(1 * ratio, 1.5, 100).toCSG(); eu.mihosoft.vrl.v3d.Cylinder inner = new eu.mihosoft.vrl.v3d.Cylinder(0.93 * ratio, 0.3, 100); CSG sg = outer.difference(inner.toCSG()); double scales = 12; double dt = 360 / scales; // if do cylinder union verrrry slow CSG c = new Cube(0.1, 0.93 * 2 * ratio, 0.1).toCSG(); CSG result = null; // because the cube bar is symmetrical for (int i = 0; i < scales / 2; i++) { if (result == null) result = c.transformed(unity().rotZ(dt * i)); else result = result.union(c.transformed(unity().rotZ(dt * i))); } // remove inner of scale label inner = new eu.mihosoft.vrl.v3d.Cylinder(0.6 * ratio, 0.3, 100); result = result.transformed(unity().translateZ(0.15)).difference(inner.toCSG()); // center pol CSGMesh pol = new CSGMesh(sg); // PhongMaterial mat = new PhongMaterial(); // mat.setDiffuseColor(materialColor); // Image image = FXUtil.loadImage("/images/cw.png"); // // mat.setBumpMap(image); // mat.setSpecularMap(image); // mat.setSpecularPower(64); // // mat.setSelfIlluminationMap(image);//no effect // pol.setMaterial(mat); pol.setMaterial(material); children.add(pol); CSGMesh scal = new CSGMesh(result); scal.setMaterial(material2); children.add(scal); Torus ring = new Torus(0.885 * ratio, 0.21); ring.mesh.setMaterial(material2); ring.getTransforms().addAll(new Translate(0, 0, 0.1)); children.add(ring); String fontName= Font.getFontNames().get(0); double radius = 0.93 * ratio * 14; for (int i = 1; i <= 12; i++) { // Museo Slab 500 // Museo Sans 500 // Museo 500 Text3DMesh scaleLabel = new Text3DMesh(String.valueOf(i), fontName, 11, true, 0.1, 0, 1); // final int count=i; // scaleLabel.setTextureModeVertices3D(1530,p->(double)(p.y/(20+count))*(p.x/(10+count))); scaleLabel.setTextureModeNone(Color.ROYALBLUE); scaleLabel.getTransforms().add(new Scale(0.040346851, 0.040346851)); double rad = Math.toRadians(dt * i); double deltax = i < 10 ? 3 : 5; double deltay = i == 10 ? 6 : 4; scaleLabel.getTransforms().add(new Translate(-radius * Math.sin(rad) + deltax, // radius * Math.cos(rad) * 0.95 - deltay, 0.1)); scaleLabel.getTransforms().add(new Rotate(180, Rotate.Z_AXIS)); children.add(scaleLabel); } CSGMesh center = new CSGMesh(new Sphere(0.2, 40, 10).toCSG().transformed(unity().translateZ(0.15))); center.setMaterial(material2); children.add(center); FrustumMesh needle = new FrustumMesh(0.1, 0.035, 0.6 * ratio); needle.setMaterial(material2); needleTranslate = new Translate(0, -0.6, 0.05); needleRotate = new Rotate(0, Rotate.Z_AXIS); needle.getTransforms().addAll(needleTranslate, needleRotate); children.add(needle); return group; }
@Override public void start(Stage primaryStage) throws Exception { try { currentStage = primaryStage; ultraRoot = new Group(); // Create camera camera = new PerspectiveCamera(true); camera.setFarClip(100000); // and position it camera.getTransforms().addAll( new Rotate(0, Rotate.Y_AXIS), new Rotate(0, Rotate.X_AXIS), new Translate(0, 0, -50)); // add camera as node to scene graph VBox guiGroup = addGuiElements(); // Setup a scene SubScene subscene = createScene3D(ultraRoot, camera); VBox layout = new VBox( guiGroup, subscene); subscene.heightProperty().bind(layout.heightProperty()); subscene.widthProperty().bind(layout.widthProperty()); layout.setSpacing(0.0); scene = new Scene(layout, 1024, 768, true); scene.setFill(Color.DARKGRAY.darker().darker().darker().darker()); //Add the scene to the stage and show the stage PointLight light2 = new PointLight(Color.LIGHTGRAY); ultraRoot.getChildren().add(light2); light2.getTransforms().add(new Translate(-50, 10, -520)); AmbientLight light3 = new AmbientLight(new Color(0.35,0.35,0.35,1.0)); ultraRoot.getChildren().add(light3); primaryStage.setScene(scene); primaryStage.show(); handleKeyboard(scene, camera); //handleMouse(scene, camera); listener = new LeapMotionListener(); controller = new Controller(); controller.addListener(listener); addGlobalLeapMotionPropertyListener(); for (int i = 0; i < cArray.length; i++) { //initialize the cylinder array for the hand bones cArray[i] = new Cylinder(1, 1, 20); //using a fixed size array for the hand bones avoids memory issues cArray[i].setMouseTransparent(true); //but limits the max. amount of hands that can be registered at the same time //set it mouse transparent, so that it wont block the mouse click events by the robot cArray[i].setMaterial(handSphereMat); } } catch (Exception e) { e.printStackTrace(System.out); System.exit(1); } }