2

我正在尝试在 JavaFX 中实现我自己的 3D 表面动画,但我不理解它应该工作的所有内容,有人可以帮助我理解哪个应该去哪里吗?

  • 已经知道使用类构建Mesh需要类对象TraingleMesh,然后必须使用方法添加点mesh.getPoints.addAll(...);但是..我Function<Double, Double>使用apply方法后对我一点帮助都没有,因为第一个参数必须是数组浮点类型,而不是double应用后的变量一些数据。

    • 我怎么能解决这个问题?
  • 我在这里找到了@Roland 创建的纹理和面的一些实现:

3D 表面 - 堆栈

  • 纹理和面是如何工作的?

这对我来说真的很重要,谢谢你的帮助!

4

1 回答 1

3

看看 FXyz。它是开源的,你可以从代码中学习。

对于纹理,看看这篇文章

FXyz 有一个类可以完全满足您的要求:使用参数SurfacePlotMesh绘制基于函数的 3D 表面。g = f(x,y)Function<Point2D, Number> function

它还包括纹理,因此您可以根据Function<Point3D, Number> density. 每个值都映射到一种颜色。

Function2DPlotTest 在此处检查此测试。

使用此代码段,您可以绘制一个函数:

@Override
public void start(Stage primaryStage) {
    PerspectiveCamera camera = new PerspectiveCamera(true);   
    camera.setTranslateZ(-30);
    SurfacePlotMesh surface = new SurfacePlotMesh(
            p-> Math.sin(p.magnitude() + 1e-10) / (p.magnitude() + 1e-10), 
            20, 20, 100, 100, 4); 
    surface.setCullFace(CullFace.NONE);
    surface.setTextureModeVertices3D(1530, p -> p.magnitude());
    surface.getTransforms().addAll(new Rotate(200, Rotate.X_AXIS), new Rotate(-20, Rotate.Y_AXIS));

    final Group group = new Group(surface);
    Scene scene = new Scene(group, 600, 400, true, SceneAntialiasing.BALANCED);
    scene.setCamera(camera);

    primaryStage.setScene(scene);
    primaryStage.show(); 
}

SurfacePlotMesh

如果添加密度图:

surface.setTextureModeVertices3D(1530, p -> p.magnitude());

你会得到这个:

纹理表面绘图网格

现在如果你想要一个表面的动画,你只需要创建一个:

private SurfacePlotMesh surface;
private long lastEffect;

@Override
public void start(Stage primaryStage) {
    PerspectiveCamera camera = new PerspectiveCamera(true);   
    camera.setTranslateZ(-30);
    surface = new SurfacePlotMesh(
            p-> Math.sin(p.magnitude() + 1e-10) / (p.magnitude() + 1e-10), 
            20, 20, 100, 100, 4); 
    surface.setCullFace(CullFace.NONE);
    surface.setTextureModeVertices3D(1530, p -> p.magnitude());
    surface.getTransforms().addAll(new Rotate(200, Rotate.X_AXIS), new Rotate(-20, Rotate.Y_AXIS));

    final Group group = new Group(surface);
    Scene scene = new Scene(group, 600, 400, true, SceneAntialiasing.BALANCED);
    scene.setCamera(camera);

    primaryStage.setScene(scene);
    primaryStage.show(); 

    lastEffect = System.nanoTime();
    AtomicInteger count=new AtomicInteger();
    AnimationTimer timerEffect = new AnimationTimer() {

        @Override
        public void handle(long now) {
            if (now > lastEffect + 1_000_000_000l) {
                double t = (count.get() % 5 + 1);
                surface.setFunction2D(p -> Math.sin(t * p.magnitude() + 1e-10)/(t * p.magnitude() + 1e-10));
                count.getAndIncrement();
                lastEffect = now;
            }
        }
    };
    timerEffect.start();
}

你会得到你的表面动画:

SurfacePlotMesh 2

SurfacePlotMesh 3

SurfacePlotMesh 4

于 2016-05-14T11:49:14.047 回答