3D表面JavaFX [英] 3D surface JavaFX

查看:87
本文介绍了3D表面JavaFX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to implement my own 3D surface animation in JavaFX but i do not understand everything like it should works, could someone help me with understanding which should go where ?

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

  • Already know that to build Mesh by using class need class object TraingleMesh and then have to add points by using method mesh.getPoints.addAll(...); but.. my Function<Double, Double> after using apply method does not help me at all, cuz the first argument has to be array float type, not double variable after applying some data.

  • 我该如何解决这个问题?

我在这里找到了@Roland创建的一些纹理和面的实现:

I found some implementations of texture and faces created by @Roland here :

3D表面-堆栈

  • 纹理和面孔如何工作?

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

It's really important for me, thanks for help!

推荐答案

看看FXyz 图书馆.它是开源的,您可以从代码中学习.

Have a look at the FXyz library. It is open source, and you can learn from the code.

对于纹理,请查看以下帖子.

For textures, have a look at this post.

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

FXyz has a SurfacePlotMesh class that does exactly what you want: plot a 3D surface based on a function g = f(x,y), by using a Function<Point2D, Number> function parameter.

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

It also includes texturing, so you can include a density map in terms of Function<Point3D, Number> density. Each value is mapped to a color.

检查此测试Function2DPlotTest 此处.

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

With this code snippet you can plot a function:

@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(); 
}

如果您添加密度图:

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

您会得到的:

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

Now if you want an animation of the surface, you just need to create one:

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();
}

然后您将获得表面动画:

And you'll get your surface animation:

这篇关于3D表面JavaFX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆