Friday 3 October 2014

Boolean operations - the powerful Cork!

Model created with boolean (Cork) operation using a face and a skull (Taung child)

I always read in 3D modeling websites that Boolean operations were not things that should be part of everyday life for an artist involved with that environment. Besides generating meshes polluted, not always the command works. It just to put a slightly more complex model in the scene for the  algorithm to crash or even have an outcome far, far away from the expected.

Examples of Blender's boolean modifier, union, intersection and difference
But this viewpoint did not survive the advent of 3D printing and evolution of fields such as surgery planning and preparation of prostheses and orthoses. I even had to adapt myself and surrender the facilities offered by Boolean operations, including the forensic facial reconstruction ... where, for example, I use ears ready merging them with a previously sculpted head ... no one deserves to make new ears every modeling :)

Blender, as presented above has a modifier where we can apply Boolean operations, but these operations (although the algorithm shows improvement with each release) lie very far from ideal when we speak of the fields of action above. I suffered a lot when I started teaching classes for students who wish to apply Blender studies in medicine, dentistry, research-oriented human locomotion and prosthesis manufacturing. Everything worked fine, but when we began to enter the area involving the subtraction of a mesh by another ... ah my friends! I assure you that my hair was subtracted before, when they fell because of my concerns, because I never knew the surprise that the Boolean modifier was preparing us.

Model ready to be printed in 3D
Things got really tense when I needed to cut bones with spongy tissue. Besides being a heavy mesh had all the complexity of "an object inside the other," a deadly reality for subtraction of meshes. It was then that I thought a bit, Blender uses a library called CARVE to effect these operations ... then surely there should be alternatives, although they were more verbose in order to manipulate them. Reading a bit, I found a comment from the creator of CloudCompare, a fantastic comparison tool meshes. In this post he quoted a library called Cork, claiming to be interested in adapting it to the software code developed by him.

UPDATED! CloudCompare already have a plugin to use Cork! ->
http://www.cloudcompare.org/doc/wiki/index.php?title=PluginCork

I entered the Cork's site, downloaded the library and compiled it. For those who were fearful diantes the words "compile", can be carefree because the process is quite simple, just take the GCC, the Clang 3.1+ library and the GMP library (GNU Multi-precision arithmetic library), which are easily installable via apt-get (tested on Ubuntu and soon I will have to compile for Windows and Mac).

Within the directory "samples" comes in two files OFF (Object File Format) format for you to test the software, which works on the command line and is very easy to be used.

The files are two spheres, the ballA.off (right) and ballB.off (left). After compiling the program, please refer to the executable, or if you're lazy like me, just copy the files into the just ~/bin (not the system, of course) where is the executable.

Above is the result of an operation, the intersection between ballA and ballB. Follows the command used:

$ ./cork -isct ballA.off ballB.off balINT.off

Where "-isct" is the type of intended operation and ballINT.off the output file. Needless to say, the $ should not be entered because it serves only to inform that it is the terminal.



Above we have the difference operation, where we subtract the ballB of ballB.

$ ./cork -diff BallA.off ballB.off ballDIFF.off

The "-diff" comes from difference. You can order files and reverse (A and B) to produce a different result.



 Finally we have the union operation between two meshes:

$ ./cork -union BallA.off ballB.off ballUNION.off


Taking the opportunity, it is common that individuals are initiating boolean studies do not understand the difference, for example, the two spheres (first image showing both mesh), a slightly within the other and a mesh created by union (picture above). Basically the difference is that with the "union" we have a clean mesh, with nothing inside their domains than an empty space.


Examples of spheres was used solely for explanation of the operation of Cork. If you need to do simple operations and to manipulate objects in real time ... since they are simple ... I advise you to use Blender. The Cork must be activated in case of using complex meshes, like illustrated the top of the post.


See above how the operations based on the face and the skull of a hominid were made. See how the right plot of the mesh is dense ... it's almost a miracle that the boolean has worked so well!

To make this "miracle" however, you need to export the file in OFF format because the Cork only works with him. If by default Blender does not provide this exporter, the problem can be solved quickly by downloading an add-on created for this purpose.


Tip 1 (gross mode to solve triangulated export):

Before exporting the mesh, please change to edit mode and activate the Triangulate faces through the Ctrl + T command, this will ensure the functioning of operations, since the Cork only works with meshes formed by these elements.

Tip 2 (smart mode):

After I post the link of that material in the discussion group BlenderDEV-BR, the user Dalai Felinto (who wrote the book Game Development with Blender), pointed out that Blender has a modifier that triangulates the mesh, preventing the original object be modified. Thanks for the tip!


Go to Add Modifier -> Triangulate.


However, when I tested the export in default mode I got an error of mesh. To prevent this from happening, take care to keep the "Quad Method" and as the "Ngon Method" both in "Beauty", as in the screenshot above, then yes will work perfectly without errors.

Acknowledgements

I thank my students Dr. Everton Rosa, Marcia Pietrobon and Dr. Rodrigo Dornelles. Also Hermano Peixoto de Oliveira Junior (CTI Renato Archer), thanks to all these people I search this solution and fortunately I found it, so that is now enabling a number of very interesting projects.

I thank my friend Luís Cláudio Sampaio Marques (patola) which has supported this project sedendo its expertise in 3D printing to validate the projections and even an impression, that will materialize the results.

I thank the creator of Cork, Mr. Gilbert Bernstein for the excellent tool and the attention he has given the experiences that I have done.

I thank the creator of CloudCompare, Daniel Girardeau-Montaut, which besides giving me indirectly hint of Cork, also implemented a plugin  for it to be used directly in application developed by him!

A big hug for all and to you, dear reader. See you next time!




No comments:

Post a Comment

BlogItalia - La directory italiana dei blog Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.