0
我正在製作具有大量3D形狀的應用程序,我需要它們完全透明且帶有邊框。我試圖找到任何方式將邊框應用於Shape3D,特別是Box和Sphere,但我找不到任何東西。所以我的問題是:具有邊框的javafx Shape3D
- 有沒有辦法如何添加邊界到Shape3D?
- 如果是,該怎麼辦?
我正在製作具有大量3D形狀的應用程序,我需要它們完全透明且帶有邊框。我試圖找到任何方式將邊框應用於Shape3D,特別是Box和Sphere,但我找不到任何東西。所以我的問題是:具有邊框的javafx Shape3D
沒有,有沒有選擇添加邊框的3D形狀,但你可以使用非常薄cyllinders代替(僅適用於箱雖然):
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方法必須另外使用在不同的點之間劃線。 我不能提供很多意見,因爲我基本上從一些博客複製它。雖然我很難再次找到這個博客。
考慮在代碼中添加一些註釋以闡明它的功能。 –
我想你不是在談論使用'drawMode'' DrawMode.LINE'繪製線框? – fabian
您無法通過API將邊框添加到JavaFX中的任意Shape3D中。 – Birdasaur
您可以使用FXyz3d.org PolyLine3D算法等算法創建第二個網格,該網格基本上會跟蹤第一個網格的頂點。這實質上將創建一個骨架結構作爲單個網格。無論您採用哪種算法,都必須在一定程度上模擬原始網格的纏繞模式。這可能必須爲任何特定網格定製。我不確定有可能有這樣的通用跟蹤算法。 (至少在JavaFX 3D中) – Birdasaur