Android Question B4A and OpenGL to simulate a 3DPrinter

max123

Well-Known Member
Licensed User
Longtime User
Hi All,

I've developed a Java application capable to open gcode files, parse it line by line, draw a filament on a 3D View, the app can simulate as well 3D printers, CNC Routers and Laser Cutter machines and can connect with these with USB connection and control it manually or by loading a gcode file and execute it on real machine while draw on 3D view.

This application works even on Raspberry PI 3 with original 7 Inches touchscreen or on HDMI monitor, need just to connect the machine with USB cable and Go.

Compatible with Marlin and GRBL firmwares.

As 3D view I've used Java3D library, but now I want to port this application on Android using B4A and I'm a bit confused on how I can do it, because Java3D library works only on desktop machines.

With Java3D I create a cylinder to simulate the filament or just I draw 3D lines to show a CNC router toolpath. For filament I create a cylinder as explained, it is the same size of 3DPrinter Nozzle, the Java3D library create it to Zero position, then I rotate and translate in the right position on the 3D world. The application can even load STL and OBJ files (for future slicing) and can even load an STL file as body of real machine.

My question is, what is the best option to do this on B4A? I need to use Agraham OpenGL library 2.0 and GLSurfaceView?

There are other options? With it I can do all things I explained? Create 3D primitives like Box, Cylinder, sphere, add lights and even import OBJ and STL files?

I never used native OpenGL so this is a bit problematic, Java3D do large use of object oriented, so there are 3DCanvas, BranchGroups, TranformGroups, ViewingPlatform, Shapes3D and others. I searched on the Forum but not tried tutorials on an OpenGL 3D view.

I've attached some screens of my desktop application.

Many thanks for your suggestions ;)

2018-08-21 12_10_37-Greenshot.png
 

Attachments

  • 2018-08-21 20_44_54-Machine body STL file do not exists! Skip loading it and go to next task..png
    2018-08-21 20_44_54-Machine body STL file do not exists! Skip loading it and go to next task..png
    37.8 KB · Views: 580
  • 2018-08-21 20_32_21-Greenshot.png
    2018-08-21 20_32_21-Greenshot.png
    155.9 KB · Views: 574
  • 2018-08-21 20_33_48-Greenshot.png
    2018-08-21 20_33_48-Greenshot.png
    130.9 KB · Views: 525
  • 2018-08-21 20_36_35-Current File_  monochromatic_small.gcode   -   WORKING.png
    2018-08-21 20_36_35-Current File_ monochromatic_small.gcode - WORKING.png
    68.4 KB · Views: 508
  • 2018-07-20 16_18_57-Greenshot.png
    2018-07-20 16_18_57-Greenshot.png
    390.3 KB · Views: 575
  • 2018-07-20 16_55_29-Greenshot.png
    2018-07-20 16_55_29-Greenshot.png
    191.3 KB · Views: 580
  • 2018-07-20 16_59_19-Greenshot.png
    2018-07-20 16_59_19-Greenshot.png
    249.7 KB · Views: 612
  • 2018-08-06 19_00_33-Greenshot.png
    2018-08-06 19_00_33-Greenshot.png
    439.7 KB · Views: 598
  • 2018-08-18 15_24_47-Greenshot.png
    2018-08-18 15_24_47-Greenshot.png
    206.9 KB · Views: 537
  • 2018-08-18 15_50_52-Greenshot.png
    2018-08-18 15_50_52-Greenshot.png
    464.6 KB · Views: 539
  • 2018-08-18 15_52_09-Greenshot.png
    2018-08-18 15_52_09-Greenshot.png
    319.2 KB · Views: 534
  • 2018-08-18 16_12_33-Greenshot.png
    2018-08-18 16_12_33-Greenshot.png
    287.9 KB · Views: 544
  • 2018-08-19 21_54_41-Greenshot.png
    2018-08-19 21_54_41-Greenshot.png
    266.7 KB · Views: 1,028
  • 2018-08-19 21_56_23-Greenshot.png
    2018-08-19 21_56_23-Greenshot.png
    502.5 KB · Views: 508
  • 2018-08-19 22_02_02-Greenshot.png
    2018-08-19 22_02_02-Greenshot.png
    489.8 KB · Views: 527
  • 2018-08-19 22_04_01-Greenshot.png
    2018-08-19 22_04_01-Greenshot.png
    189.1 KB · Views: 575
  • 36944784_1984999961510253_6248535257939705856_n.png
    36944784_1984999961510253_6248535257939705856_n.png
    190.5 KB · Views: 486
  • 37000394_1989946537682262_1240523551656640512_n.png
    37000394_1989946537682262_1240523551656640512_n.png
    337.3 KB · Views: 516
  • 37065058_1989946464348936_1785047197729947648_n.png
    37065058_1989946464348936_1785047197729947648_n.png
    294.8 KB · Views: 507
Last edited:

MarkusR

Well-Known Member
Licensed User
Longtime User
Last edited:
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
Many thanks for your reply and suggestions MarkusR, I think too that WebGL is good thing but I've old devices and not WebGL enabled, so I can't test it. Maybe I can do it with my Nexus 7 2013... I will test it. Java3D even works on browser as Java Applet and on my old Monocore PC with 1GB of ram and only 64MB of video ram on an old ATI Radeon it works like a charm and I,ve a very high framerate, like 60 fps... It slow down If I add more and more to the scene, like 100.000 + cylinders.

But B4A OpenGL library can do that I developed on Java3D as my screenshots? You used it?

I can make primitives or I need to create myself with triangles and generate normals too? With Java3D make example a sphere require just one line of code, more if I want to add Appearance and or textures... But already has primitives like Box, ColorCube, Sphere, Cone, Cylinder and others.

Many thanks
 
Last edited:
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
Grazie Luca per avermi avvisato, correggo subito... Sto postando dal mio Nexus 7
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
Many thanks MarkusR, I use Eclipse too and have developed some B4A and B4J libraries... So if you have a Java code this is wonderful... and I can compile on Eclipse
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
Many thanks MarkusR, I use Eclipse too and have developed some B4A and B4J libraries... So if you have a Java code this is wonderful... and I can compile on Eclipse
ok i will prepare the project soon and upload it then at google drive tomorrow.
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
Ok Markus, thanks. I read your library post and seem very interesting, but only I see cubes, no other primitives, If you need I can send you original Java3D classes to construct a Sphere, a Cone, a Cylinder etc... by passing even a division resolution and others parameters, so if you have time and if you want, maybe you can add to your library.

Initially to develop my app I started with B4J, but due to work on Raspberry PI (not on browser but as real application) next I've developed it on Jabaco using directly Java3D Classes without intermediary wrappers (Java3D has 100 and plus classes, so make a wrapper is very difficult), so I created a Class to draw just what I need, a plane grid, primitives etc... It is a smal wrap of some Java3D that use it just by add 3 Java3D jars of library to the system and to the classpath, then reference it like B4A or B4J libraries. Jabaco has same syntax of VisualBasic and B4X and convert pure Java code to it is very simple.... If you need I can send my class.

Many thanks
 
Last edited:
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
ok, here the android studio project. https://drive.google.com/open?id=1_JJ04TRJD9qqwZqR2NVUoXXUjy1NFebG
its all together in a folder with the file threedimensional.java
(ignore the PhotoCube.Java file there)
this project also contains a test project to start at emulator or device.

currently i am not working at this lib. (just saw you have other templates for build primitives)
you can build primitives by triangles or rectangles.
or make a 3d loader that load a primitive objects.
i have some old blitz max code, you can open with notepad , search for AddCylinder there. https://drive.google.com/open?id=1fs9evbU4cU0kX2Kj8HtPqv4-co2xAndL
 
Last edited:
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
Many thanks MarkusR, I will try it.

But my question remains open, what is a best way to import STL and OBJ files without write myself a loader? Is that possible using your library? If not I can't use your library and I need to know if OpenGL or libGDX or jPCT-AE libraries can do this....

I need a fast possible rendering too.

Many thanks
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
best way to import STL and OBJ files
i did not had any import fileformat, i used a web api interface with json data and then i build the scene for it.
i believe that are text files, writing a importer need some time sure.

if OpenGL or libGDX or jPCT-AE libraries can do this.
u need to look in the provided documentation.
and if you find they say it can load stl or obj files, it did not means that it works with your files.
3d data exchange is still a disaster.
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
OBJ files are text (ASCII) format, STL file is a bit more complicated because there are ASCII or BINARY files.

Java3D by defaul has OBJ loader that even import and map textures on the model from .mtl file exported from CAD.

About the STL loader, I found java code (STL Loader) on the web, then I adapted and improved, now can import as well both ascii and binary files, from disk and even from URL without download it, just data are in RAM and model rendered.

Write a loader and parse a file yes is very long work to do with Tokenizer or Regex, so I don't want rewrite it because on Java3D required me 2 month of work.
 
Last edited:
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
I would love to know what Erel thinks of this ;)
Which library is best to use according to you?

Note that I have no knowledge of OpenGL because Java3D works on objects.

Many thanks
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
Thanks Erel for your fast reply.

But could you direct me indicating where to start?
Then if I have to study I will study. ;)

Many thanks
 
Last edited:
Upvote 0

alienhunter

Active Member
Licensed User
Longtime User
Hi Max123
very nice 3D , is there a Java3D library out there in the forum or did you made one for B4J , i am very i
interested in that one ;)
thanks AH
 
Upvote 0
Top