带边框的javafx Shape3D

时间:2017-03-23 18:31:12

标签: javafx-8 javafx-3d

我正在使用大量的3D形状进行应用,我需要它们完全透明并带有边框。我试图找到任何方法将边框应用到Shape3D,特别是Box和Sphere,但我找不到任何东西。所以我的问题是:

  • 有什么方法可以为Shape3D添加边框吗?
  • 如果是,该怎么做?

2 个答案:

答案 0 :(得分:0)

不,没有选项可以为3d形状添加边框,但是你可以使用非常薄的圆柱形(尽管只适用于盒子):

    public void createBoxLines(double contW, double contH, double contD, double x, double y, double z) {
       //You call this method to create a box with a size and location you put in
        //This method calls the createLine method for all the sides of your rectangle
        Point3D p1 = new Point3D(x, y, z);
        Point3D p2 = new Point3D(contW + x, y, z);
        Point3D p3 = new Point3D(x, contH + y, z);
        Point3D p4 = new Point3D(contW + x, contH + y, z);
        createLine(p1, p2);
        createLine(p1, p3);
        createLine(p3, p4);
        createLine(p2, p4);

        Point3D p5 = new Point3D(x, y, contD + z);
        Point3D p6 = new Point3D(contW + x, y, contD + z);
        Point3D p7 = new Point3D(x, contH + y, contD + z);
        Point3D p8 = new Point3D(contW + x, contH + y, contD + z);
        createLine(p5, p6);
        createLine(p5, p7);
        createLine(p7, p8);
        createLine(p6, p8);

        createLine(p1, p5);
        createLine(p2, p6);
        createLine(p3, p7);
        createLine(p4, p8);
    }

    double strokewidth = 1;
    public void createLine(Point3D origin, Point3D target) {        
        //creates a line from one point3d to another

        Point3D yAxis = new Point3D(0, 1, 0);
        Point3D diff = target.subtract(origin);
        double height = diff.magnitude();

        Point3D mid = target.midpoint(origin);
        Translate moveToMidpoint = new Translate(mid.getX(), mid.getY(), mid.getZ());

        Point3D axisOfRotation = diff.crossProduct(yAxis);
        double angle = Math.acos(diff.normalize().dotProduct(yAxis));
        Rotate rotateAroundCenter = new Rotate(-Math.toDegrees(angle), axisOfRotation);

        Cylinder line = new Cylinder(strokewidth, height);

        line.getTransforms().addAll(moveToMidpoint, rotateAroundCenter);

        myGroup.getChildren().add(line);
    }

createLine方法可以单独使用,以在不同点之间创建线。 我不能为该方法提供很多评论,因为我基本上是从一些博客中复制它。虽然我很难再次找到该博客。

答案 1 :(得分:0)

谢谢Alex Quilliam,感谢我提供的代码,我能够改善自己的程序。 https://i.imgur.com/HY2x9vF.png

Cylinder line = new Cylinder(strokewidth, height);

Box line = new Box(strokewidth, height, strokewidth);

JavaFX_3D_Cube_Outline_Test