【问题标题】:javafx Shape3D with borderjavafx Shape3D带边框
【发布时间】:2017-08-16 11:45:55
【问题描述】:

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

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

【问题讨论】:

  • 我猜你说的不是用drawModeDrawMode.LINE绘制线框???
  • 您无法通过 API 在 JavaFX 中为任意 Shape3D 添加边框。
  • 您可以使用类似于 FXyz3d.org PolyLine3D 算法的算法创建第二个网格,该网格基本上跟踪第一个网格的顶点。这实际上将创建一个骨架结构作为单个网格。无论您实施何种算法,都必须在一定程度上模仿原始网格的缠绕模式。这可能必须为任何特定的网格定制。我不确定是否有可能拥有这样的通用跟踪算法。 (至少在 JavaFX 3D 中)

标签: javafx-8 javafx-3d


【解决方案1】:

感谢 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

【讨论】:

    【解决方案2】:

    不,没有为 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 方法可以单独使用,在不同点之间画线。 我无法为该方法提供很多 cmets,因为我基本上是从某个博客中复制的。虽然我很难再找到那个博客了。

    【讨论】:

    • 考虑在你的代码中添加一些 cmets 来阐明它的作用。
    猜你喜欢
    • 1970-01-01
    • 2019-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多