javafx.scene.shape.Sphere Java Examples

The following examples show how to use javafx.scene.shape.Sphere. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Globe.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
private void buildSphereGroup() {

        final PhongMaterial material = new PhongMaterial();

        material.setDiffuseColor(Color.WHITE);//TRANSPARENT);//BROWN);
        material.diffuseMapProperty().bind(Bindings.when(diffuseMap).then(dImage).otherwise((Image) null));
        material.bumpMapProperty().bind(Bindings.when(bumpMap).then(nImage).otherwise((Image) null));
        material.setSpecularColor(Color.LIGHTGRAY);
        //material.selfIlluminationMapProperty().bind(Bindings.when(selfIlluminationMap).then(siImage).otherwise((Image) null));

        Xform marsXform = new Xform();
        Sphere mars = new Sphere(300.0);
        mars.setMaterial(material);
        marsXform.getChildren().add(mars);
        sphereGroup.getChildren().add(marsXform);

        world.getChildren().addAll(sphereGroup);//, ambientXform);
    }
 
Example #2
Source File: CubeViewer.java    From FXyzLib with GNU General Public License v3.0 6 votes vote down vote up
/**
     * @param data the xAxisData to set
     */
    public void setxAxisData(ArrayList<Double> data) {
        xAxisData = data;
        scatterDataGroup.getChildren().clear();
        for(int i=0;i<xAxisData.size();i++) {
            final Sphere dataSphere = new Sphere(scatterRadius);
//            final Box dataSphere = new Box(getScatterRadius(), getScatterRadius(), getScatterRadius());
            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);
            scatterDataGroup.getChildren().add(dataSphere);
        }        
    }
 
Example #3
Source File: CubeViewer.java    From FXyzLib with GNU General Public License v3.0 6 votes vote down vote up
/**
     * @param data the yAxisData to set
     */
    public void setyAxisData(ArrayList<Double> data) {
        yAxisData = data;
        scatterDataGroup.getChildren().clear();
        for(int i=0;i<yAxisData.size();i++) {
            final Sphere dataSphere = new Sphere(scatterRadius);
//            final Box dataSphere = new Box(getScatterRadius(), getScatterRadius(), getScatterRadius());
            double translateX = 0.0;
            double translateZ = 0.0;
            if(!xAxisData.isEmpty() && xAxisData.size() > i)
                translateX = xAxisData.get(i);
            if(!zAxisData.isEmpty() && zAxisData.size() > i)
                translateZ = zAxisData.get(i);
            dataSphere.setTranslateX(translateX);
            dataSphere.setTranslateY(yAxisData.get(i));
            dataSphere.setTranslateZ(translateZ);
            scatterDataGroup.getChildren().add(dataSphere);
        }        
    }
 
Example #4
Source File: CubeViewer.java    From FXyzLib with GNU General Public License v3.0 6 votes vote down vote up
/**
     * @param data the zAxisData to set
     */
    public void setzAxisData(ArrayList<Double> data) {
        zAxisData = data;
        scatterDataGroup.getChildren().clear();
        for(int i=0;i<zAxisData.size();i++) {
            final Sphere dataSphere = new Sphere(scatterRadius);
//            final Box dataSphere = new Box(getScatterRadius(), getScatterRadius(), getScatterRadius());
        
            double translateX = 0.0;
            double translateY = 0.0;
            if(!xAxisData.isEmpty() && xAxisData.size() > i)
                translateX = xAxisData.get(i);
            if(!yAxisData.isEmpty() && yAxisData.size() > i)
                translateY = yAxisData.get(i);
            dataSphere.setTranslateX(translateX);
            dataSphere.setTranslateY(translateY);
            dataSphere.setTranslateZ(zAxisData.get(i));
            scatterDataGroup.getChildren().add(dataSphere);
        }       
    }
 
Example #5
Source File: Viewer3dParserDemo.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void buildStructure_goodInputWithComment_returnNewStructure() throws Exception
{
    String inputWithComment = "sphere(10, 20, 30, 10.0, 150, 160, 170, 1.0, \"This is round.\")";
    Xform struct = Viewer3d.buildStructure(new ByteArrayInputStream(inputWithComment.getBytes()));
    Sphere sphere = (Sphere) struct.getChildren().get(0);

    /* Check that the transforms are correct. */

    assertEquals(10, sphere.getTranslateX(), 0);
    assertEquals(20, sphere.getTranslateY(), 0);
    assertEquals(30, sphere.getTranslateZ(), 0);

    /* Check that the size is correct. */

    assertEquals(10.0, sphere.getRadius(), 0);

    /* Check that the color is correct. */

    PhongMaterial material = (PhongMaterial) sphere.getMaterial();
    Color color = material.getDiffuseColor();

    assertEquals(150/255.0, color.getRed(), 0.001);
    assertEquals(160/255.0, color.getGreen(), 0.001);
    assertEquals(170/255.0, color.getBlue(), 0.001);
    assertEquals(1.0, color.getOpacity(), 0.0);
}
 
Example #6
Source File: Viewer3dParserDemo.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void buildStructure_goodInput_returnNewStructure() throws Exception
{
    String input = "sphere(25, 20, 35, 108.0, 155, 24, 43, 0.565)";
    Xform struct = Viewer3d.buildStructure(new ByteArrayInputStream(input.getBytes()));
    Sphere sphere = (Sphere) struct.getChildren().get(0);

    /* Check that the transforms are correct. */

    assertEquals(25, sphere.getTranslateX(), 0);
    assertEquals(20, sphere.getTranslateY(), 0);
    assertEquals(35, sphere.getTranslateZ(), 0);

    /* Check that the size is correct. */

    assertEquals(108.0, sphere.getRadius(), 0);

    /* Check that the color is correct. */

    PhongMaterial material = (PhongMaterial) sphere.getMaterial();
    Color color = material.getDiffuseColor();

    assertEquals(155/255.0, color.getRed(), 0.001);
    assertEquals(24/255.0, color.getGreen(), 0.001);
    assertEquals(43/255.0, color.getBlue(), 0.001);
    assertEquals(0.565, color.getOpacity(), 0.001);
}
 
Example #7
Source File: ContentModel.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void buildAxes() {
    double length = 2d * dimModel;
    double width = dimModel / 100d;
    double radius = 2d * dimModel / 100d;
    final PhongMaterial redMaterial = new PhongMaterial();
    redMaterial.setDiffuseColor(Color.DARKRED);
    redMaterial.setSpecularColor(Color.RED);
    final PhongMaterial greenMaterial = new PhongMaterial();
    greenMaterial.setDiffuseColor(Color.DARKGREEN);
    greenMaterial.setSpecularColor(Color.GREEN);
    final PhongMaterial blueMaterial = new PhongMaterial();
    blueMaterial.setDiffuseColor(Color.DARKBLUE);
    blueMaterial.setSpecularColor(Color.BLUE);
    
    Sphere xSphere = new Sphere(radius);
    Sphere ySphere = new Sphere(radius);
    Sphere zSphere = new Sphere(radius);
    xSphere.setMaterial(redMaterial);
    ySphere.setMaterial(greenMaterial);
    zSphere.setMaterial(blueMaterial);
    
    xSphere.setTranslateX(dimModel);
    ySphere.setTranslateY(dimModel);
    zSphere.setTranslateZ(dimModel);
    
    Box xAxis = new Box(length, width, width);
    Box yAxis = new Box(width, length, width);
    Box zAxis = new Box(width, width, length);
    xAxis.setMaterial(redMaterial);
    yAxis.setMaterial(greenMaterial);
    zAxis.setMaterial(blueMaterial);
    
    autoScalingGroup.getChildren().addAll(xAxis, yAxis, zAxis);
    autoScalingGroup.getChildren().addAll(xSphere, ySphere, zSphere);
}
 
Example #8
Source File: MarsViewer.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
private Group buildScene() {
	    Sphere mars = new Sphere(MARS_RADIUS);
	    mars.setTranslateX(VIEWPORT_SIZE / 2d);
	    mars.setTranslateY(VIEWPORT_SIZE / 2d);

	    PhongMaterial material = new PhongMaterial();
	    material.setDiffuseMap(
	      new Image(this.getClass().getResource(DIFFUSE_MAP).toExternalForm(),
	        MAP_WIDTH,
	        MAP_HEIGHT,
	        true,
	        true
	      )
	    );

	    material.setBumpMap(
	      new Image(this.getClass().getResource(NORMAL_MAP).toExternalForm(),
	        MAP_WIDTH,
	        MAP_HEIGHT,
	        true,
	        true
	      )
	    );
/*
	    material.setSpecularMap(
	      new Image(this.getClass().getResource(SPECULAR_MAP).toExternalForm(),
	        MAP_WIDTH,
	        MAP_HEIGHT,
	        true,
	        true
	      )
	    );
*/
	    mars.setMaterial(
	        material
	    );

	    return new Group(mars);
	}
 
Example #9
Source File: EarthViewer.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
private Group buildScene() {
  Sphere earth = new Sphere(EARTH_RADIUS);
  earth.setTranslateX(VIEWPORT_SIZE / 2d);
  earth.setTranslateY(VIEWPORT_SIZE / 2d);

  PhongMaterial earthMaterial = new PhongMaterial();
  earthMaterial.setDiffuseMap(
    new Image(
      DIFFUSE_MAP,
      MAP_WIDTH,
      MAP_HEIGHT,
      true,
      true
    )
  );
  earthMaterial.setBumpMap(
    new Image(
      NORMAL_MAP,
      MAP_WIDTH,
      MAP_HEIGHT,
      true,
      true
    )
  );
  earthMaterial.setSpecularMap(
    new Image(
      SPECULAR_MAP,
      MAP_WIDTH,
      MAP_HEIGHT,
      true,
      true
    )
  );

  earth.setMaterial(
      earthMaterial
  );

  return new Group(earth);
}
 
Example #10
Source File: ScatterPlot.java    From FXyzLib with GNU General Public License v3.0 5 votes vote down vote up
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);    
    }
}
 
Example #11
Source File: Drag3DObject.java    From FXyzLib with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void start(Stage stage) {
    Box floor = new Box(1000, 10, 1000);
    floor.setTranslateY(150);
    root.getChildren().add(floor);

    Sphere s = new Sphere(150);
    s.setTranslateX(5);
    s.setPickOnBounds(true);
    root.getChildren().add(s);
    
    showStage(stage);
}
 
Example #12
Source File: JavaFX3DExample.java    From chuidiang-ejemplos with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void initFx(JFXPanel fxPanel) {

      sphere = new Sphere(100);
      sphere.setLayoutX(200);
      sphere.setLayoutY(200);
      Group root = new Group(sphere);

      Scene scene = new Scene(root, 900, 600);
      fxPanel.setScene(scene);
      fxPanel.setSize(900, 600);
   }
 
Example #13
Source File: ContentModel.java    From RubikFX with GNU General Public License v3.0 5 votes vote down vote up
private void buildAxes() {
    double length = 2d*dimModel;
    double width = dimModel/100d;
    double radius = 2d*dimModel/100d;
    final PhongMaterial redMaterial = new PhongMaterial();
    redMaterial.setDiffuseColor(Color.DARKRED);
    redMaterial.setSpecularColor(Color.RED);
    final PhongMaterial greenMaterial = new PhongMaterial();
    greenMaterial.setDiffuseColor(Color.DARKGREEN);
    greenMaterial.setSpecularColor(Color.GREEN);
    final PhongMaterial blueMaterial = new PhongMaterial();
    blueMaterial.setDiffuseColor(Color.DARKBLUE);
    blueMaterial.setSpecularColor(Color.BLUE);
    
    Sphere xSphere = new Sphere(radius);
    Sphere ySphere = new Sphere(radius);
    Sphere zSphere = new Sphere(radius);
    xSphere.setMaterial(redMaterial);
    ySphere.setMaterial(greenMaterial);
    zSphere.setMaterial(blueMaterial);
    
    xSphere.setTranslateX(dimModel);
    ySphere.setTranslateY(dimModel);
    zSphere.setTranslateZ(dimModel);
    
    Box xAxis = new Box(length, width, width);
    Box yAxis = new Box(width, length, width);
    Box zAxis = new Box(width, width, length);
    xAxis.setMaterial(redMaterial);
    yAxis.setMaterial(greenMaterial);
    zAxis.setMaterial(blueMaterial);
    
    autoScalingGroup.getChildren().addAll(xAxis, yAxis, zAxis);
    autoScalingGroup.getChildren().addAll(xSphere, ySphere, zSphere);
}
 
Example #14
Source File: Simple3DSphereApp.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
public Parent createContent() throws Exception {

        Image dImage = new Image(Simple3DSphereApp.class.getResource("/maps/earth-d.jpg").toExternalForm());
        Image nImage = new Image(Simple3DSphereApp.class.getResource("/maps/earth-n.jpg").toExternalForm());
        Image sImage = new Image(Simple3DSphereApp.class.getResource("/maps/earth-s.jpg").toExternalForm());
        Image siImage = new Image(Simple3DSphereApp.class.getResource("/maps/earth-l.jpg").toExternalForm());

        material = new PhongMaterial();
        material.setDiffuseColor(Color.WHITE);
        material.diffuseMapProperty().bind(
                Bindings.when(diffuseMap).then(dImage).otherwise((Image) null));
        material.setSpecularColor(Color.TRANSPARENT);
        material.specularMapProperty().bind(
                Bindings.when(specularMap).then(sImage).otherwise((Image) null));
        material.bumpMapProperty().bind(
                Bindings.when(bumpMap).then(nImage).otherwise((Image) null));
        material.selfIlluminationMapProperty().bind(
                Bindings.when(selfIlluminationMap).then(siImage).otherwise((Image) null));

        earth = new Sphere(5);
        earth.setMaterial(material);
        earth.setRotationAxis(Rotate.Y_AXIS);


        // Create and position camera
        PerspectiveCamera camera = new PerspectiveCamera(true);
        camera.getTransforms().addAll(
                new Rotate(-20, Rotate.Y_AXIS),
                new Rotate(-20, Rotate.X_AXIS),
                new Translate(0, 0, -20));

        sun = new PointLight(Color.rgb(255, 243, 234));
        sun.translateXProperty().bind(sunDistance.multiply(-0.82));
        sun.translateYProperty().bind(sunDistance.multiply(-0.41));
        sun.translateZProperty().bind(sunDistance.multiply(-0.41));
        sun.lightOnProperty().bind(sunLight);

        AmbientLight ambient = new AmbientLight(Color.rgb(1, 1, 1));

        // Build the Scene Graph
        Group root = new Group();
        root.getChildren().add(camera);
        root.getChildren().add(earth);
        root.getChildren().add(sun);
        root.getChildren().add(ambient);

        RotateTransition rt = new RotateTransition(Duration.seconds(24), earth);
        rt.setByAngle(360);
        rt.setInterpolator(Interpolator.LINEAR);
        rt.setCycleCount(Animation.INDEFINITE);
        rt.play();

        // Use a SubScene
        SubScene subScene = new SubScene(root, 400, 300, true, SceneAntialiasing.BALANCED);
        subScene.setFill(Color.TRANSPARENT);
        subScene.setCamera(camera);

        return new Group(subScene);
    }