I recommend using a data model like Dukescript based on tags, not only is it highly readable for Java programmers, but it can also be converted directly to the javascript object ( json ) and be processed in any external application or service of your choice.
In his book Java everywhere Mr. Anton Epple shares the code of how to create a fully portable example using a data model of 3D figures ( dukescript run on PC, Mac, Linux, Android , iOS and Netbeans currently).
The functionality that is achieved is similar to your demo with bck2brwsr you can find on youtube .
From the code of the book there is a API in process for Dukescript, unlike the API java3d , it is not necessary to make a complex model of the renderizable Universe and generate webgl (A variant of opengl ) on a Canvas
.
Sample Code
Assuming that in your class you have a generic model that contains the origin coordinate for the X, Y, and Z axes and the width, height, and background size
@Model(className="MiCubo3D", properties = {
@Property(name="origenX", type=double.class),
@Property(name="origenY", type=double.class),
@Property(name="origenZ", type=double.class),
@Property(name="ancho", type=double.class),
@Property(name="alto", type=double.class),
@Property(name="fondo", type=double.class)
})
Class MiCubo3D{
public void drawMyCube(Micubo3D modelo){
ProyectodeJavascript.drawCube(modelo.getOrigenX(), modelo.getOrigenY(), modelo.getOrigenZ(), modelo.getAncho(), modelo.getAlto(), modelo.getFondo());
}
}
And your javascript project with the method to render it:
@JavaScriptBody(args = {"x","y","z","width","height","depth"},
body = "var canvas = document.getElementById('mycanvas');\n" +
"var context3d = canvas.getContext('experimental-webgl');\n" +
"var vertexBuffer;"+
"vertexBuffer = context3d.createBuffer();"
"context3d.bindBuffer(context3d.ARRAY_BUFFER, vertexBuffer);"
" var verts = ["+
.
.
.
public static native void drawCube(double x, double y, double z, double width, double height double depth);
You get your data model perfectly separated from the rendering and / or logic of the application. A great advantage is that if for example you want to add color, the data model is easily customizable.
If you want to delve into rendering code you can check out this book .