我正在使用大量 3D 形状制作应用程序,我需要它们完全透明并带有边框。我尝试找到任何方法将边框应用于 Shape3D,特别是 Box 和 Sphere,但我找不到任何东西。所以我的问题是:
- 有什么方法可以为 Shape3D 添加边框吗?
- 如果是,该怎么做?
不,没有为 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 方法可以单独用于在不同点之间制作线。我无法为该方法提供很多评论,因为我基本上是从某个博客中复制的。虽然我很难再次找到那个博客。
感谢 Alex Quilliam 感谢我能够改进我的程序的代码。 https://i.imgur.com/HY2x9vF.png
Cylinder line = new Cylinder(strokewidth, height);
↓</p>
Box line = new Box(strokewidth, height, strokewidth);