I decided to make a simple hack to import static wavefront OBJ files into JavaFX, and when I say simple and hack I do mean both!
You run my converter like this
java -cp src obj2javafx resources/cube.obj > src/cube.java
you must ensure that you send the output to a java file with the same name as the OBJ file, so cube.obj becomes cube.java …
OBJ files must have triangulated mesh and include normals and texture UV’s additionally make sure it consists of just one group/shape
You then simply include this in your project, using it is quite straight forward
MeshView obj = new MeshView( new cube() ); PhongMaterial mat = new PhongMaterial(); mat.setDiffuseMap(new Image("file:cube.png")); obj.setMaterial(mat);
bare in mind that something like the default Blender cube which is 1x1x1 will look very very small so will need scaling! (or you can work in larger units in Blender)
When it breaks don’t forget you get to keep both pieces, use at your own risk and consider it public domain.