Create a class for a 3D model

1

I am making a data model, in principle in Java , but that is valid for any language, so that everyone uses the same classes and attributes. It's a kind of DTO. Within this data model I need to represent / use modelos 3D (of a building, for example). I need to create a class in which one of its attributes is a 3D object, or create a class that represents that model in 3D.

I'm a bit lost about 3D and I do not know how to model it. I know I need to represent coordinates, the name of the model and a unique identifier. But I do not know if the approach is correct. I do not know if I just have to use the Java3D package importing some special class or if that is outdated.

Can you help me?

    
asked by jjmartinez 25.02.2016 в 13:12
source

1 answer

-1

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 () 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 ( run on PC, Mac, Linux, Android , iOS and Netbeans currently).

The functionality that is achieved is similar to your demo with you can find on youtube .

From the code of the book there is a API in process for Dukescript, unlike the API , it is not necessary to make a complex model of the renderizable Universe and generate (A variant of ) 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 .

    
answered by 25.02.2016 в 16:55