2016-05-14 182 views
2

我想在JavaFX中實現我自己的3D表面動畫,但我不明白它應該起作用的一切,有人可以幫助我理解哪些應該去哪裏?3D表面JavaFX

  • 已經知道,通過使用類構建網格需要類對象TraingleMesh,然後必須使用方法mesh.getPoints.addAll(...);但要加點..我的​​使用apply方法並不能幫助我在所有以後的辯論,因爲第一個參數必須是數組浮點類型,而不是double變量在應用一些數據後。

    • 我該如何解決這個問題?
  • 我發現@Roland這裏創建質感的一些實現和麪:

3D surface - stack

  • 如何紋理和麪臨的工作?

這對我來說非常重要,感謝您的幫助!

+0

這是關於動畫「c瞬間「表面或關於改變表面? – fabian

+0

它會根據時間更改新數據表面 – yerpy

回答

3

看看FXyz library。它是開源的,你可以從代碼中學習。

對於紋理,看看這個post

FXyz有SurfacePlotMesh的類,它正是你想要的:情節基於函數g = f(x,y),通過使用Function<Point2D, Number> function參數3D表面。

它還包含紋理,因此您可以根據Function<Point3D, Number> density包含密度圖。每個值都映射到一種顏色。

檢查此項測試Function2DPlotTesthere

有了這段代碼可以繪製一個函數:

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

你會得到這樣的:

Textured 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

+0

我將jar包括到java項目中,它不起作用,仍然有例如「SurfacePlotMesh」無法解析符號。 – yerpy

+0

您使用的是什麼版本的Java?你的進口是什麼?也許你錯過了正確的導入? – Birdasaur

+0

我通過將所有源代碼導入到項目中解決了這個問題,不僅是jar的 – yerpy