Cube minus cylinder - the perfect solution

Of course it is not a perfect solution, but it may be interesting in some cases.
The idea is to keep the cube, but to make the material of the cube transparent where the cube intersect the cylinder.
In the material node, the upper left part is made to keep “transparentable” only the front and the back face.
The lower left part is made to make the hole (choose transparent in the final mix node)
It is a simple formula of the surface of a disk: (x-x1)² + (z-z1)² < r²
The cylinder is simple with blue material, positioned at (0.5,0.5,0.5)

This kind of material may be interesting for architecture with volume rendering and with complex formulas, to make perferect renders.

Attachments



Level 2!
Still with the basic cube and the basic cylinder.

I added “displacement” bevel, see the blend file joined, and see the cycles documentation:

  • render panel: select ‘Experimental’ as Feature set in the Render section,
  • object data panel: select ‘True’ for method in displacement section for the cylinder.

The node tree for the cylinder may appear complicated but this is only to make bevel on x and z zaxes depending on the y axe. It is not OK, the bevel should have a 0.1 radius.

Still two problems:

  • a black hole between the cube and the cylinder. It may be due to the fact that the disk hole in the cube is “perfect” (depending on x and z position), whereas there is no perfect cylinder in blender. It also may be due to the subsurf of the cylinder.
  • lighting of the meshes is different between the cube and the circle. Perhaps it is not a bug.


    Level 3 goal:
  • Suzanne minus cylinder: use Suzanne, intersect cylinder and Suzanne,
    • apply the intersection to the cylinder
    • remove the two intersect faces of the cylinder, add them to Suzannne to make transparency for this faces (I tried but did not find a solution).

Level 4 goal:

I am interested in tests from readers of this thread.

Just as a side comment, these are very nice tests showing what all is possible to do with nodes if you get your head around them :slight_smile:
I haven’t studied this more closely, making a perfect cylinder is nice, but is it possible to do boolean with mesh objects and nodes?

@Tame: thanks for your reply. Yes you can use boolean with mesh objects, it is faster.
But there are drawbacks, you introduce more complex geometry, so:

  • if you want to bevel for example the result may be bad. Though since n-gones, it is not an argument I think.
  • if you have to apply your boolean transformers, you will have a more important mesh so maybe long rendering time.

This test (to keep simple meshes and to modify at render time) may prevent that. This will be usable only if there is a simple method and a simple node tree.

It was not a good idea to displace the cylinder, too complicated.

Here is the test with a mesh minus a cylinder.
The result seems OK
Limits:

  • only cylinder on the x axe. Need other axes and rotation
  • OK for a still image but the modifications in the material node are not linked to the cylinder mesh for animation

How to:
1/ Install object intersection add-on
see this page http://airplanes3d.net/scripts-253_e.xml
Big thanks to Witold Jaworski !
2/ Save your work
3/ Make a copy of your mesh on another layer
4/ position the 3D cursor where you want to create the cylinder. You will need the 3D cursor position (x,y,z)
5/ add your cylinder. Choose a huge number of vertices. You will need the radius.
6/ position your cylinder on the x axe, scale it on the x axe and apply (Ctrl +A) the transformations.
You will need its size (on the x axe).
7/apply all your modifiers to your mesh.
8/ in object mode :
select your mesh
shift select the cylinder
press spacebar
choose intersection add-on
9/in edit mode for the cylinder
delete all the vertices but the two mesh created
press spacebar
choose Bridge Two Edge Loops add-on
10/append the suzanne in the blend file joined to this thread and use the material
11/ change the Red ‘Diffuse BSDF’ by you own material
12/change the values for the nodes
CylinderRadius
CylinderX
CylinderY
CylinderZ
CylinderSize
13/ delete your mesh with modifiers applied (see 7)
14/ ShiftD your saved mesh (see 3)
15/ Move your mesh to your original layer

You can then render your mesh

Attachments


SUZANNE_MINUS_CYLINDER.blend.zip (139 KB)

The cool thing about nodes, once you have created a primitive, you can group all nodes and do whatever you want with outputs, for example adding jagged radius with noise texture or repeating with a simple cascade:
http://i.imgur.com/gn7K51J.png