1

I have a file of 3D data (time,x,y,z) and I want to create a JavaFX interactive animation with play, pause buttons, and the option of rotating the 3d objects.

I don't find in JavaFX any base example, it seems like I have to recreate my own mediaplayer.

double-beep
  • 5,031
  • 17
  • 33
  • 41
user1828433
  • 252
  • 2
  • 11
  • Could you please elaborate more on what it is you're trying to accomplish? What kind of Data file? – jdub1581 Feb 12 '15 at 17:41
  • @jdub1581 It's a csv file, with comma as separator, the format of the file is the following : time,x1,y1,z1,x2,y2,z2,... (x1,y1,z1) are the coordinates of the first point and (x2,y2,z2) are the coordinates of the seconde etc... I have to read data from that file and display the result as 3D animation where i can turn the camera around. And I need to add video controls (play/pause, stop, and the time slider ) to navigate in the animation. – user1828433 Feb 12 '15 at 18:15
  • Ok, I think I understand a little more now, MediaPlayer was throwing me off.. So are the {x,y,z} values - vertices in a Mesh?, or say a "Sphere's" position? Are you needing to interpolate forward and reverse? – jdub1581 Feb 12 '15 at 23:47
  • @jdub1581 {x,y,z} values represente a sphere position and no, i don't need to do interpolation. – user1828433 Feb 13 '15 at 08:25
  • Well I don't think you will find much of anything "pre-made" .. (just thinking out loud) First you need a parser .. A List<> to store your points and another for Times. You could use Timeline, but this has it's own difficulties. You could also use AnimationTimer (like a constant running game loop) this will probably be the easiest in combination with standard Animations. Build your GUI (buttons etc..) and have it start and stop the timer. In the Timer, create some boolean flags : if(canRotate())-> startRotate() ... Where startRotate starts a RotateTransition .. – jdub1581 Feb 13 '15 at 15:16
  • @jdub1581 thanks a lot for your help. I'll follow your indications. – user1828433 Feb 17 '15 at 13:48

1 Answers1

0

Have a look at this library, F(X)yz is an open source

JavaFX 3D library that provides additional primitives, composite objects, controls and data visualizations that the base JavaFX 8 3D packages do not have.

There are several components that may help you. For instance, all the TexturedMesh subclasses are 3D shapes that allow using mathematical expressions to create contour plots (by using textures).

As an example, have a look at the icosahedron test.

private IcosahedronMesh ico;
private DensityFunction<Point3D> dens = p-> (double)p.x*p.y*p.z;

@Override
public void start(Stage primaryStage) throws Exception {
     ...
     ico = new IcosahedronMesh(5,1f);
     ico.setTextureModeVertices3D(1530,dens);

     Group sceneRoot = new Group(ico);
     Scene scene = new Scene(sceneRoot, 800, 600, true, SceneAntialiasing.BALANCED);
     ...
}

This short snippet will create something like this:

Icosahedron

Now you can add some animation:

long lastEffect = System.nanoTime();
AtomicInteger count=new AtomicInteger();

AnimationTimer timerEffect = new AnimationTimer() {
    @Override public void handle(long now) {
        if (now > lastEffect + 50_000_000l) {
            double t=count.getAndIncrement()%10;
            dens = p->(double)(p.x+t)*(p.y+t)*(p.z+t);
            ico.setDensity(dens);
            lastEffect = now;
        }
    }
};
timerEffect.start();

and you will see something like this.

You could add on top of the subscene the usual media player controls, and bind them to the animation. Also you can add other animations to rotate the 3D shapes.

So the only thing you will have to add is a way of passing your data files to the shapes... You can add a feature request on the F(X)yz repository, providing some specific format of the data, the shapes you need...

For more information, you can also have a look at this post.

José Pereda
  • 44,311
  • 7
  • 104
  • 132