Search in sources :

Example 11 with PhongMaterial

use of javafx.scene.paint.PhongMaterial in project FXyzLib by Birdasaur.

the class ScatterPlotMesh method setXYZData.

public void setXYZData(ArrayList<Double> xData, ArrayList<Double> yData, ArrayList<Double> zData) {
    xAxisData = xData;
    yAxisData = yData;
    zAxisData = zData;
    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.
    ArrayList<Point3D> point3DList = new ArrayList<>();
    for (int i = 0; i < xAxisData.size(); i++) {
        //some safety checks for array sizes
        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);
        setTranslateX(xAxisData.get(i));
        //Convert to Floats and build list of adjusted points
        point3DList.add(new Point3D(new Float(xAxisData.get(i)), new Float(translateY), new Float(translateZ)));
        float width = 1;
        final TriangleMesh mesh = new TriangleMesh();
        //This extra point allows us to build triangles later
        for (Point3D point : point3DList) {
            //Rear points
            //top right rear point
            mesh.getPoints().addAll(point.x + width, point.y + width, point.z + width);
            //top left rear point
            mesh.getPoints().addAll(point.x - width, point.y + width, point.z + width);
            //bottom right rear point
            mesh.getPoints().addAll(point.x + width, point.y - width, point.z + width);
            //bottom left rear point
            mesh.getPoints().addAll(point.x - width, point.y - width, point.z + width);
            //Front points
            //top right front point
            mesh.getPoints().addAll(point.x + width, point.y + width, point.z - width);
            //top left front point
            mesh.getPoints().addAll(point.x - width, point.y + width, point.z - width);
            //bottom right front point
            mesh.getPoints().addAll(point.x + width, point.y - width, point.z - width);
            //bottom left front point
            mesh.getPoints().addAll(point.x - width, point.y - width, point.z - width);
        }
        //add dummy Texture Coordinate
        mesh.getTexCoords().addAll(0, 0);
        //Now generate nodes for each point
        for (int p = 8; p < point3DList.size() * 7; p += 8) {
            //add each segment
            //Wind the next 8 vertices as a cube.  The cube itself will represent the data
            //Vertices wound counter-clockwise which is the default front face of any Triangle
            //Rear triangle faces should be wound clockwise to face away from center
            //TRR,BLR,BRR
            mesh.getFaces().addAll(p, 0, p + 3, 0, p + 2, 0);
            //BLR,TRR,TLR
            mesh.getFaces().addAll(p + 3, 0, p, 0, p + 1, 0);
            //left side faces
            //TLR,TLF,BLR
            mesh.getFaces().addAll(p + 1, 0, p + 5, 0, p + 3, 0);
            //TLF,BLR,BLF
            mesh.getFaces().addAll(p + 5, 0, p + 7, 0, p + 3, 0);
            //front side faces
            //TLF,BLF,TLR
            mesh.getFaces().addAll(p + 5, 0, p + 7, 0, p + 4, 0);
            //TRF,BLF,BRF
            mesh.getFaces().addAll(p + 4, 0, p + 7, 0, p + 6, 0);
            //front side faces
            //TRF,BRF,BRR
            mesh.getFaces().addAll(p + 4, 0, p + 6, 0, p + 2, 0);
            //TRF,BRR,TRR
            mesh.getFaces().addAll(p + 4, 0, p + 2, 0, p, 0);
            //Top faces
            //TRR,TLR,TRF
            mesh.getFaces().addAll(p, 0, p + 1, 0, p + 3, 0);
            //TLR,TLF,TRF
            mesh.getFaces().addAll(p + 1, 0, p + 5, 0, p + 3, 0);
            //bottom faces
            //BLR,BLF,BRF
            mesh.getFaces().addAll(p + 3, 0, p + 7, 0, p + 6, 0);
            //BLR,BRF,BRR
            mesh.getFaces().addAll(p + 3, 0, p + 6, 0, p + 2, 0);
        }
        //Need to add the mesh to a MeshView before adding to our 3D scene
        MeshView meshView = new MeshView(mesh);
        //Fill so that the line shows width
        meshView.setDrawMode(DrawMode.FILL);
        Color hsb = Color.hsb((new Double(i) / 12) * 360, 1.0, 1.0, 0.5);
        PhongMaterial material = new PhongMaterial(hsb);
        material.setDiffuseColor(hsb);
        material.setSpecularColor(hsb);
        meshView.setMaterial(material);
        //Make sure you Cull the Back so that no black shows through
        meshView.setCullFace(CullFace.BACK);
        //            //Add some ambient light so folks can see it
        //            Group line = new Group();
        //            AmbientLight light = new AmbientLight(Color.WHITE);
        //            light.getScope().add(meshView);
        //            line.getChildren().add(light);
        //            line.getChildren().add(meshView);           
        getChildren().addAll(meshView);
    }
}
Also used : TriangleMesh(javafx.scene.shape.TriangleMesh) Point3D(org.fxyz.geometry.Point3D) Color(javafx.scene.paint.Color) ArrayList(java.util.ArrayList) PhongMaterial(javafx.scene.paint.PhongMaterial) MeshView(javafx.scene.shape.MeshView)

Example 12 with PhongMaterial

use of javafx.scene.paint.PhongMaterial in project FXyzLib by Birdasaur.

the class SurfacePlot method setHeightData.

public void setHeightData(float[][] arrayY, int spacing, Color color, boolean ambient, boolean fill) {
    material = new PhongMaterial();
    material.setSpecularColor(color);
    material.setDiffuseColor(color);
    mesh = new TriangleMesh();
    // Fill Points
    for (int x = 0; x < arrayY.length; x++) {
        for (int z = 0; z < arrayY[0].length; z++) {
            mesh.getPoints().addAll(x * spacing, arrayY[x][z], z * spacing);
        }
    }
    //for now we'll just make an empty texCoordinate group
    mesh.getTexCoords().addAll(0, 0);
    int total = arrayY.length * arrayY.length;
    int nextRow = arrayY.length;
    //Add the faces "winding" the points generally counter clock wise
    for (int i = 0; i < total - nextRow - 1; i++) {
        //Top upper left triangle
        mesh.getFaces().addAll(i, 0, i + nextRow, 0, i + 1, 0);
        //Top lower right triangle
        mesh.getFaces().addAll(i + nextRow, 0, i + nextRow + 1, 0, i + 1, 0);
    //Bottom            
    }
    //Create a viewable MeshView to be added to the scene
    //To add a TriangleMesh to a 3D scene you need a MeshView container object
    meshView = new MeshView(mesh);
    //The MeshView allows you to control how the TriangleMesh is rendered
    if (fill) {
        meshView.setDrawMode(DrawMode.FILL);
    } else {
        //show lines only by default
        meshView.setDrawMode(DrawMode.LINE);
    }
    //Removing culling to show back lines
    meshView.setCullFace(CullFace.BACK);
    getChildren().add(meshView);
    meshView.setMaterial(material);
    if (ambient) {
        selfLight.getScope().add(meshView);
        if (!getChildren().contains(selfLight))
            getChildren().add(selfLight);
    } else if (getChildren().contains(selfLight))
        getChildren().remove(selfLight);
    setDepthTest(DepthTest.ENABLE);
}
Also used : TriangleMesh(javafx.scene.shape.TriangleMesh) PhongMaterial(javafx.scene.paint.PhongMaterial) MeshView(javafx.scene.shape.MeshView)

Example 13 with PhongMaterial

use of javafx.scene.paint.PhongMaterial in project FXyzLib by Birdasaur.

the class BezierTest method start.

@Override
public void start(Stage primaryStage) throws Exception {
    Group sceneRoot = new Group();
    Scene scene = new Scene(sceneRoot, sceneWidth, sceneHeight, true, SceneAntialiasing.BALANCED);
    scene.setFill(Color.BLACK);
    camera = new PerspectiveCamera(true);
    //setup camera transform for rotational support
    cameraTransform.setTranslate(0, 0, 0);
    cameraTransform.getChildren().add(camera);
    camera.setNearClip(0.1);
    camera.setFarClip(10000.0);
    camera.setTranslateZ(-10);
    cameraTransform.ry.setAngle(-45.0);
    cameraTransform.rx.setAngle(-10.0);
    //add a Point Light for better viewing of the grid coordinate system
    PointLight light = new PointLight(Color.WHITE);
    cameraTransform.getChildren().add(light);
    cameraTransform.getChildren().add(new AmbientLight(Color.WHITE));
    light.setTranslateX(camera.getTranslateX());
    light.setTranslateY(camera.getTranslateY());
    light.setTranslateZ(camera.getTranslateZ());
    scene.setCamera(camera);
    rotateY = new Rotate(0, 0, 0, 0, Rotate.Y_AXIS);
    Group group = new Group();
    group.getChildren().add(cameraTransform);
    //        List<Point3D> knots=Arrays.asList(new Point3D(0f,0f,0f),new Point3D(3f,0f,2f),
    //                new Point3D(5f,2f,3f),new Point3D(7f,-3f,0f),new Point3D(6f,-1f,-4f));
    List<Point3D> knots = Arrays.asList(new Point3D(3f, 0f, 0f), new Point3D(0.77171f, 1.68981f, 0.989821f), new Point3D(-0.681387f, 0.786363f, -0.281733f), new Point3D(-2.31757f, -0.680501f, -0.909632f), new Point3D(-0.404353f, -2.81233f, 0.540641f), new Point3D(1.1316f, -0.727237f, 0.75575f), new Point3D(1.1316f, 0.727237f, -0.75575f), new Point3D(-0.404353f, 2.81233f, -0.540641f), new Point3D(-2.31757f, 0.680501f, 0.909632f), new Point3D(-0.681387f, -0.786363f, 0.281733f), new Point3D(0.77171f, -1.68981f, -0.989821f), new Point3D(3f, 0f, 0f));
    boolean showControlPoints = true;
    boolean showKnots = true;
    InterpolateBezier interpolate = new InterpolateBezier(knots);
    beziers = new ArrayList<>();
    AtomicInteger sp = new AtomicInteger();
    if (showKnots || showControlPoints) {
        interpolate.getSplines().forEach(spline -> {
            Point3D k0 = spline.getPoints().get(0);
            Point3D k1 = spline.getPoints().get(1);
            Point3D k2 = spline.getPoints().get(2);
            Point3D k3 = spline.getPoints().get(3);
            if (showKnots) {
                Sphere s = new Sphere(0.2d);
                s.getTransforms().add(new Translate(k0.x, k0.y, k0.z));
                s.setMaterial(new PhongMaterial(Color.GREENYELLOW));
                group.getChildren().add(s);
                s = new Sphere(0.2d);
                s.getTransforms().add(new Translate(k3.x, k3.y, k3.z));
                s.setMaterial(new PhongMaterial(Color.GREENYELLOW));
                group.getChildren().add(s);
            }
            if (showControlPoints) {
                PrismMesh c = new PrismMesh(0.03d, 1d, 1, k0, k1);
                c.setTextureModeNone(Color.GREEN);
                group.getChildren().add(c);
                c = new PrismMesh(0.03d, 1d, 1, k1, k2);
                c.setTextureModeNone(Color.GREEN);
                group.getChildren().add(c);
                c = new PrismMesh(0.03d, 1d, 1, k2, k3);
                c.setTextureModeNone(Color.GREEN);
                group.getChildren().add(c);
                Sphere s = new Sphere(0.1d);
                s.getTransforms().add(new Translate(k1.x, k1.y, k1.z));
                s.setMaterial(new PhongMaterial(Color.RED));
                group.getChildren().add(s);
                s = new Sphere(0.1d);
                s.getTransforms().add(new Translate(k2.x, k2.y, k2.z));
                s.setMaterial(new PhongMaterial(Color.RED));
                group.getChildren().add(s);
            }
        });
    }
    long time = System.currentTimeMillis();
    interpolate.getSplines().stream().forEach(spline -> {
        BezierMesh bezier = new BezierMesh(spline, 0.1d, 300, 20, 0, 0);
        bezier.setTextureModeVertices1D(1530, t -> spline.getKappa(t.doubleValue()));
        bezier.getTransforms().addAll(new Rotate(0, Rotate.X_AXIS), rotateY);
        beziers.add(bezier);
    });
    //43.815->25.606->15
    System.out.println("time: " + (System.currentTimeMillis() - time));
    group.getChildren().addAll(beziers);
    sceneRoot.getChildren().addAll(group);
    //First person shooter keyboard movement 
    scene.setOnKeyPressed(event -> {
        double change = 10.0;
        if (event.isShiftDown()) {
            change = 50.0;
        }
        KeyCode keycode = event.getCode();
        if (keycode == KeyCode.W) {
            camera.setTranslateZ(camera.getTranslateZ() + change);
        }
        if (keycode == KeyCode.S) {
            camera.setTranslateZ(camera.getTranslateZ() - change);
        }
        if (keycode == KeyCode.A) {
            camera.setTranslateX(camera.getTranslateX() - change);
        }
        if (keycode == KeyCode.D) {
            camera.setTranslateX(camera.getTranslateX() + change);
        }
    });
    scene.setOnMousePressed((MouseEvent me) -> {
        mousePosX = me.getSceneX();
        mousePosY = me.getSceneY();
        mouseOldX = me.getSceneX();
        mouseOldY = me.getSceneY();
    });
    scene.setOnMouseDragged((MouseEvent me) -> {
        mouseOldX = mousePosX;
        mouseOldY = mousePosY;
        mousePosX = me.getSceneX();
        mousePosY = me.getSceneY();
        mouseDeltaX = (mousePosX - mouseOldX);
        mouseDeltaY = (mousePosY - mouseOldY);
        double modifier = 10.0;
        double modifierFactor = 0.1;
        if (me.isControlDown()) {
            modifier = 0.1;
        }
        if (me.isShiftDown()) {
            modifier = 50.0;
        }
        if (me.isPrimaryButtonDown()) {
            // +
            cameraTransform.ry.setAngle(((cameraTransform.ry.getAngle() + mouseDeltaX * modifierFactor * modifier * 2.0) % 360 + 540) % 360 - 180);
            // -
            cameraTransform.rx.setAngle(((cameraTransform.rx.getAngle() - mouseDeltaY * modifierFactor * modifier * 2.0) % 360 + 540) % 360 - 180);
        } else if (me.isSecondaryButtonDown()) {
            double z = camera.getTranslateZ();
            double newZ = z + mouseDeltaX * modifierFactor * modifier;
            camera.setTranslateZ(newZ);
        } else if (me.isMiddleButtonDown()) {
            // -
            cameraTransform.t.setX(cameraTransform.t.getX() + mouseDeltaX * modifierFactor * modifier * 0.3);
            // -
            cameraTransform.t.setY(cameraTransform.t.getY() + mouseDeltaY * modifierFactor * modifier * 0.3);
        }
    });
    lastEffect = System.nanoTime();
    AtomicInteger count = new AtomicInteger();
    AnimationTimer timerEffect = new AnimationTimer() {

        @Override
        public void handle(long now) {
            if (now > lastEffect + 1_000_000_000l) {
                //                    Point3D loc = knot.getPositionAt((count.get()%100)*2d*Math.PI/100d);
                //                    Point3D dir = knot.getTangentAt((count.get()%100)*2d*Math.PI/100d);
                //                    cameraTransform.t.setX(loc.x);
                //                    cameraTransform.t.setY(loc.y);
                //                    cameraTransform.t.setZ(-loc.z);
                //                    javafx.geometry.Point3D axis = cameraTransform.rx.getAxis();
                //                    javafx.geometry.Point3D cross = axis.crossProduct(-dir.x,-dir.y,-dir.z);
                //                    double angle = axis.angle(-dir.x,-dir.y,-dir.z);
                //                    cameraTransform.rx.setAngle(angle);
                //                    cameraTransform.rx.setAxis(new javafx.geometry.Point3D(cross.getX(),-cross.getY(),cross.getZ()));
                //                    dens = p->(float)(p.x*Math.cos(count.get()%100d*2d*Math.PI/50d)+p.y*Math.sin(count.get()%100d*2d*Math.PI/50d));
                func = t -> Math.pow(t.doubleValue(), (count.get() % 5d));
                beziers.forEach(b -> b.setFunction(func));
                //                    knot.setP(1+(count.get()%5));
                //                    knot.setQ(2+(count.get()%15));
                //                    if(count.get()%100<50){
                //                        knot.setDrawMode(DrawMode.LINE);
                //                    } else {
                //                        knot.setDrawMode(DrawMode.FILL);
                //                    }
                //                    beziers.forEach(b->b.setColors((int)Math.pow(2,count.get()%16)));
                //                    beziers.forEach(b->b.setWireRadius(0.1d+(count.get()%6)/10d));
                //                    beziers.forEach(b->b.setPatternScale(1d+(count.get()%10)*3d));
                //                    beziers.forEach(b->b.setSectionType(SectionType.values()[count.get()%SectionType.values().length]));
                count.getAndIncrement();
                lastEffect = now;
            }
        }
    };
    primaryStage.setTitle("F(X)yz - Bezier Splines");
    primaryStage.setScene(scene);
    primaryStage.show();
    timerEffect.start();
}
Also used : Group(javafx.scene.Group) MouseEvent(javafx.scene.input.MouseEvent) Rotate(javafx.scene.transform.Rotate) AnimationTimer(javafx.animation.AnimationTimer) PerspectiveCamera(javafx.scene.PerspectiveCamera) Scene(javafx.scene.Scene) Sphere(javafx.scene.shape.Sphere) InterpolateBezier(org.fxyz.shapes.primitives.helper.InterpolateBezier) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Point3D(org.fxyz.geometry.Point3D) PrismMesh(org.fxyz.shapes.primitives.PrismMesh) KeyCode(javafx.scene.input.KeyCode) PointLight(javafx.scene.PointLight) PhongMaterial(javafx.scene.paint.PhongMaterial) Translate(javafx.scene.transform.Translate) BezierMesh(org.fxyz.shapes.primitives.BezierMesh) AmbientLight(javafx.scene.AmbientLight)

Example 14 with PhongMaterial

use of javafx.scene.paint.PhongMaterial in project FXyzLib by Birdasaur.

the class CubeWorld method buildGrids.

private void buildGrids(double size, double spacing) {
    //fill in grid lines for X Axis
    PhongMaterial phong = new PhongMaterial();
    phong.setSpecularColor(gridLinesWallColor);
    phong.setDiffuseColor(gridLinesWallColor);
    ArrayList xy1Cyls = new ArrayList<>();
    for (int i = 0; i < size; i += spacing) {
        Cylinder newCyl = new Cylinder(gridSize, size);
        newCyl.setMaterial(phong);
        newCyl.setTranslateX((-size / 2) + i);
        newCyl.setTranslateZ(-size / 2);
        xy1Cyls.add(newCyl);
    }
    xy1GridLinesGroup = new Group(xy1Cyls);
    //Now build the grids for the mirror image
    ArrayList xy2Cyls = new ArrayList<>();
    for (int i = 0; i < size; i += spacing) {
        Cylinder newCyl = new Cylinder(gridSize, size);
        newCyl.setMaterial(phong);
        newCyl.setTranslateX((-size / 2) + i);
        newCyl.setTranslateZ(size / 2);
        xy2Cyls.add(newCyl);
    }
    xy2GridLinesGroup = new Group(xy2Cyls);
    ArrayList xx1Cyls = new ArrayList<>();
    for (int i = 0; i < size; i += spacing) {
        Cylinder newCyl = new Cylinder(gridSize, size);
        newCyl.setMaterial(phong);
        newCyl.setTranslateZ(-size / 2);
        newCyl.setTranslateY((size / 2) - i);
        newCyl.setRotationAxis(Rotate.Z_AXIS);
        newCyl.setRotate(90);
        xx1Cyls.add(newCyl);
    }
    xx1GridLinesGroup = new Group(xx1Cyls);
    //Now build the grids for the mirror image
    ArrayList xx2Cyls = new ArrayList<>();
    for (int i = 0; i < size; i += spacing) {
        Cylinder newCyl = new Cylinder(gridSize, size);
        newCyl.setMaterial(phong);
        newCyl.setTranslateZ(size / 2);
        newCyl.setTranslateY((size / 2) - i);
        newCyl.setRotationAxis(Rotate.Z_AXIS);
        newCyl.setRotate(90);
        xx2Cyls.add(newCyl);
    }
    xx2GridLinesGroup = new Group(xx2Cyls);
    //Add the sub groups to the parent group 
    getChildren().addAll(xy1GridLinesGroup);
    getChildren().addAll(xx1GridLinesGroup);
    getChildren().addAll(xy2GridLinesGroup);
    getChildren().addAll(xx2GridLinesGroup);
    // File in grid Lines for Y Axis //////////////////////////
    ArrayList yy1Cyls = new ArrayList<>();
    for (int i = 0; i < size; i += spacing) {
        Cylinder newCyl = new Cylinder(gridSize, size);
        newCyl.setMaterial(phong);
        newCyl.setTranslateX(-size / 2);
        newCyl.setTranslateZ((-size / 2) + i);
        yy1Cyls.add(newCyl);
    }
    yy1GridLinesGroup = new Group(yy1Cyls);
    //Now build the grids for the mirror image
    ArrayList yy2Cyls = new ArrayList<>();
    for (int i = 0; i < size; i += spacing) {
        Cylinder newCyl = new Cylinder(gridSize, size);
        newCyl.setMaterial(phong);
        newCyl.setTranslateX(size / 2);
        newCyl.setTranslateZ((-size / 2) + i);
        yy2Cyls.add(newCyl);
    }
    yy2GridLinesGroup = new Group(yy2Cyls);
    ArrayList yx1Cyls = new ArrayList<>();
    for (int i = 0; i < size; i += spacing) {
        Cylinder newCyl = new Cylinder(gridSize, size);
        newCyl.setMaterial(phong);
        newCyl.setTranslateX(-size / 2);
        newCyl.setTranslateY((size / 2) - i);
        newCyl.setRotationAxis(Rotate.X_AXIS);
        newCyl.setRotate(90);
        yx1Cyls.add(newCyl);
    }
    yx1GridLinesGroup = new Group(yx1Cyls);
    //Now build the grids for the mirror image
    ArrayList yx2Cyls = new ArrayList<>();
    for (int i = 0; i < size; i += spacing) {
        Cylinder newCyl = new Cylinder(gridSize, size);
        newCyl.setMaterial(phong);
        newCyl.setTranslateX(size / 2);
        newCyl.setTranslateY((size / 2) - i);
        newCyl.setRotationAxis(Rotate.X_AXIS);
        newCyl.setRotate(90);
        yx2Cyls.add(newCyl);
    }
    yx2GridLinesGroup = new Group(yx2Cyls);
    //Add the sub groups to the parent group
    getChildren().addAll(yy1GridLinesGroup);
    getChildren().addAll(yx1GridLinesGroup);
    getChildren().addAll(yy2GridLinesGroup);
    getChildren().addAll(yx2GridLinesGroup);
    // File in grid Lines for Z Axis //////////////////////////
    phong = new PhongMaterial();
    phong.setSpecularColor(gridLinesFloorColor);
    phong.setDiffuseColor(gridLinesFloorColor);
    ArrayList zy1Cyls = new ArrayList<>();
    for (int i = 0; i < size; i += spacing) {
        Cylinder newCyl = new Cylinder(gridSize, size);
        newCyl.setMaterial(phong);
        newCyl.setTranslateY(size / 2);
        newCyl.setTranslateX((-size / 2) + i);
        newCyl.setRotationAxis(Rotate.X_AXIS);
        newCyl.setRotate(90);
        zy1Cyls.add(newCyl);
    }
    zy1GridLinesGroup = new Group(zy1Cyls);
    //Now build the grids for the mirror image
    ArrayList zy2Cyls = new ArrayList<>();
    for (int i = 0; i < size; i += spacing) {
        Cylinder newCyl = new Cylinder(gridSize, size);
        newCyl.setMaterial(phong);
        newCyl.setTranslateY(-size / 2);
        newCyl.setTranslateX((-size / 2) + i);
        newCyl.setRotationAxis(Rotate.X_AXIS);
        newCyl.setRotate(90);
        zy2Cyls.add(newCyl);
    }
    zy2GridLinesGroup = new Group(zy2Cyls);
    ArrayList zx1Cyls = new ArrayList<>();
    for (int i = 0; i < size; i += spacing) {
        Cylinder newCyl = new Cylinder(gridSize, size);
        newCyl.setMaterial(phong);
        newCyl.setTranslateY(size / 2);
        newCyl.setTranslateZ((-size / 2) + i);
        newCyl.setRotationAxis(Rotate.Z_AXIS);
        newCyl.setRotate(90);
        zx1Cyls.add(newCyl);
    }
    zx1GridLinesGroup = new Group(zx1Cyls);
    //Now build the grids for the mirror image
    ArrayList zx2Cyls = new ArrayList<>();
    for (int i = 0; i < size; i += spacing) {
        Cylinder newCyl = new Cylinder(gridSize, size);
        newCyl.setMaterial(phong);
        newCyl.setTranslateY(-size / 2);
        newCyl.setTranslateZ((-size / 2) + i);
        newCyl.setRotationAxis(Rotate.Z_AXIS);
        newCyl.setRotate(90);
        zx2Cyls.add(newCyl);
    }
    zx2GridLinesGroup = new Group(zx2Cyls);
    //Add the sub groups to the parent group
    getChildren().addAll(zy1GridLinesGroup);
    getChildren().addAll(zx1GridLinesGroup);
    getChildren().addAll(zy2GridLinesGroup);
    getChildren().addAll(zx2GridLinesGroup);
}
Also used : Cylinder(javafx.scene.shape.Cylinder) Group(javafx.scene.Group) ArrayList(java.util.ArrayList) PhongMaterial(javafx.scene.paint.PhongMaterial)

Aggregations

PhongMaterial (javafx.scene.paint.PhongMaterial)14 Group (javafx.scene.Group)7 PerspectiveCamera (javafx.scene.PerspectiveCamera)6 PointLight (javafx.scene.PointLight)6 KeyCode (javafx.scene.input.KeyCode)6 MouseEvent (javafx.scene.input.MouseEvent)6 Sphere (javafx.scene.shape.Sphere)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 Scene (javafx.scene.Scene)5 Cylinder (javafx.scene.shape.Cylinder)5 Rotate (javafx.scene.transform.Rotate)5 Translate (javafx.scene.transform.Translate)5 Point3D (org.fxyz.geometry.Point3D)5 ArrayList (java.util.ArrayList)3 AnimationTimer (javafx.animation.AnimationTimer)3 AmbientLight (javafx.scene.AmbientLight)3 Bounds (javafx.geometry.Bounds)2 Color (javafx.scene.paint.Color)2 Box (javafx.scene.shape.Box)2 MeshView (javafx.scene.shape.MeshView)2