类似于如何在 javafx 中获取 3D 对象窗口上的 2D 坐标,但我无法使解决方案起作用。
我想为 3D 形状绘制 2D 边框或更类似于其投影。我写了这个示例代码供参考:
import javafx.application.Application;
import javafx.geometry.Point3D;
import javafx.scene.Group;
import javafx.scene.PerspectiveCamera;
import javafx.scene.Scene;
import javafx.scene.SceneAntialiasing;
import javafx.scene.SubScene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.Box;
import javafx.scene.shape.Rectangle;
import javafx.scene.transform.Rotate;
import javafx.stage.Stage;
public class CoordinateConversion extends Application {
@Override
public void start(Stage stage) {
var box = new Box(20, 20, 20);
box.setMaterial(new PhongMaterial(Color.TEAL));
box.getTransforms().add(new Rotate(45, new Point3D(1, 1, 1)));
var …Run Code Online (Sandbox Code Playgroud) 我知道如果我旋转一个扩展的对象,javafx.scene.shape.Shape我可以将它转换为3D空间,即使它主要设计为2D(至少据我所知).
假设我有一个3D场景(使用透视摄像头和深度缓冲器),其中MeshView出现各种s.有些用于区域,有些用于线路.在这两种情况下,这些形状必须进行三角测量,以便用a绘制它们TriangleMesh,这通常是非常重要的.
现在,当我改变这些线的绘图以使用Polyline该类时,性能崩溃是可怕的,并且有一些奇怪的文物.我认为我可以从以下事实中受益:折线具有较少的顶点,并且开发人员不必以编程方式进行三角测量.
不鼓励使用javafx.scene.shape.Shape在3D空间内延伸的形状吗?他们是如何在内部绘制的?
如何使用线性渐变(如 2d Circle)填充 JavaFX 3D 球体?我使用 JavaFX Scene Builder。


问题
我想将漫反射贴图应用于 MeshView。当我将带有漫反射贴图的材质应用到 MeshView 时,它不可见。然而,应用于 Box 的相同材质是可见的。
题
我需要做什么才能将漫反射贴图应用到 MeshView?
代码
该代码生成带有随机噪声的图像。该图像用作 PhongMaterial 中的漫反射贴图。显示图像,其上方是应用了材质的框,框上方是应用了材质的 MeshView(金字塔)。该材料在金字塔上不可见。您可以使用鼠标拖动进行旋转。
import java.util.Random;
import javafx.application.Application;
import javafx.geometry.Point3D;
import javafx.scene.Group;
import javafx.scene.PerspectiveCamera;
import javafx.scene.Scene;
import javafx.scene.SceneAntialiasing;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.image.PixelWriter;
import javafx.scene.image.WritableImage;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.Box;
import javafx.scene.shape.DrawMode;
import javafx.scene.shape.MeshView;
import javafx.scene.shape.TriangleMesh;
import javafx.scene.transform.Rotate;
import javafx.stage.Stage;
public class Test extends Application {
private double mousePosX, mousePosY;
private double mouseOldX, mouseOldY;
private final Rotate rotateX = new Rotate(20, Rotate.X_AXIS);
private final Rotate …Run Code Online (Sandbox Code Playgroud) 我试图制作一个魔方,但javafx最终得到了一个非常糟糕的模型,如图所示。我给出了我的代码源代码,其中我使用RectangleBuilder类来创建矩形并在 3d 中进行转换。为了修复图形,我还尝试构建使用TriangleMesh类的矩形,并在向它们添加材质后,将它们转换为 3D,最终再次出现相同的糟糕图形。为什么会出现这种情况以及如何消除它?
import javafx.scene.transform.Rotate;
import javafx.scene.PerspectiveCamera;
import javafx.scene.transform.Translate;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.SceneAntialiasing;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.shape.RectangleBuilder;
import javafx.scene.transform.Rotate;
import javafx.util.Duration;
public class NewFXMain1 extends Application {
public class Cube extends Group {
final Rotate rx = new Rotate(0,Rotate.X_AXIS);
final Rotate ry = new Rotate(0,Rotate.Y_AXIS);
final Rotate rz = …Run Code Online (Sandbox Code Playgroud) 我的目标是在 javafx 中将 2D 文本叠加在 3D 场景上,如所示
使用子场景不是一个有效的选择,因为我希望 3D 模型能够占据屏幕上的整个空间。
我尝试向场景添加标签并关闭深度缓冲,但是一旦模型旋转(实际相机改变位置),正确的定位就会中断。(使用代码来控制相机)
我是否可以通过使用锚点窗格并使用具有透明背景的 2D 场景,以某种方式在 3D 场景上覆盖静态 2D GUI?
is there a way to show uv coords on gui like blender blender uv ?
许多 3d 程序使用轮廓来提示用户选择 3d 对象。
有没有办法模仿 javafx 中的这种行为?