繁体   English   中英

3D表面JavaFX

[英]3D surface JavaFX

我正在尝试在JavaFX中实现自己的3D表面动画,但我不了解它应该起作用的一切,有人可以帮助我理解应该去哪里吗?

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

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

3D表面-堆栈

  • 纹理和面孔如何工作?

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

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

对于纹理,请看这篇文章

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

它还包括纹理,因此您可以根据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());

你会得到这个:

带纹理的SurfacePlotMesh

现在,如果要制作表面动画,则只需创建一个:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM