[英]3D surface JavaFX
我正在嘗試在JavaFX中實現自己的3D表面動畫,但我不了解它應該起作用的一切,有人可以幫助我理解應該去哪里嗎?
已經知道使用類構建網格需要類對象TraingleMesh
,然后必須使用mesh.getPoints.addAll(...);
方法添加點mesh.getPoints.addAll(...);
但是..使用apply
方法后Function<Double, Double>
我的Function<Double, Double>
完全對我沒有幫助,因為第一個參數必須為數組浮點類型,而不是應用一些數據后的double
變量。
我在這里找到了@Roland創建的紋理和面的一些實現:
這對我來說真的很重要,謝謝您的幫助!
看看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();
}
如果添加密度圖:
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();
}
然后您將獲得表面動畫:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.