Halloween Costume ideas 2015

MODIFIER X PYTHON / Boolean Modifier for Cutting and Slicing


Have you ever wished that you can Cut and Slice a 3D object using Cutting Plane of some sort in Blender? Let's explore on how this can be done in Blender.

MAYA POLY CUT FACES TOOL
From someone coming from Maya background, I have another wish that Blender has Maya feature to do Poly Cut Faces Tool (polyCut node). Basically a function to be able to slice and cut any mesh using Cutting Plane. I am sure this can be done in Blender.

Maya Poly Cut Tool slices like Fruit Ninja.
To further describe this "cutting" function, we can observe slicing games such as:

BLENDER KNIFE TOOL
In case you don't know, there is actually a Knife Tool (K) in Blender that allows user to Cut Slice 3D mesh in Edit Mode. Blender Knife Tool is one of the best out there. It slices through everything (front and back faces), if you hold Z while using the Knife Tool.

Blender Knife Tool, in Edit Mode.

BLENDER DUAL-SIDED BOOLEAN (AKA BLENDER POLY CUT TOOL)

Now, I will propose a strange method that you can use to simulate Maya's Poly Cut Tool in Blender to slice and cut through 3D mesh.

What is the trick? The almighty Blender Boolean.

How does it work? Let's take a look by an example.

1. Start with the default Cube and a Poly Plane.

Make sure that our "cutting plane", the Poly Plane geometry really cutting through and covering the area you want to slice.

2. Apply Boolean
Next, we just apply Boolean Modifier (Difference) to minus the Poly Cube - with Poly Plane:



We get 1/2 cut of the Poly Cube. You see how interesting that Blender understands and respects the Plane Face normal and giving the result like above:

Poly Plane Face Normal and Boolean Result respecting the normal.

3. Duplicate the PolyCube + PolyPlane + Boolean and Flip the "Cutting Plane"
Now, we will do a simple hack here, we will duplicate the Poly Cube + Poly Plane with Boolean Difference (while the modifier is still live).

The result will be the exact same thing. Unless, we actually reverse and flip the normal of "cutting plane". And so we get something like below:


If the Boolean Modifier is applied to both 1/2 slice of the cube, we will get exactly what we want, I will give color to both slices so you can see exactly what just happened:

This is exactly what we want! Super easy, right?

THE LIMITATION:
The limit of this method is solely depending on Boolean result. If the object to be cut and slice is made of multiple objects, then the cutting and slicing won't work. Better off slicing and cutting on just a single mesh and then re-join them again later.

ALTERNATIVE WAY OF CUTTING, GREAT FOR MULTIPLE CUTS

We can actually use a Plane with very tiny amount of thickness that will result it both side of cuts at the same time, instead needing to duplicate.

Blender Boolean is pretty stable and powerful in this case that it will "slice" and "cut" even when the thickness of reference Boolean is very tiny (value like 0.0001).

So, for our "Cutting Plane" (Poly Plane) we simply extrude it with a super tiny value that our eyes cannot see.

Then, we use it with Boolean Modifier to cut slice our object.


As you can see it works great with multiple cuts. Below is example on how the Boolean Modifier got stacked. Don't attempt to join the Cutting Plane and do a single cut. You better off doing multiple Boolean Modifiers this way. For simple and evenly distributed Cutting, you can use Array Modifier to the "cutting plane".


Doing it manually is pretty simple, just click on Copy and replace the Slicer object. Here is the resulting cut pieces after we also click Apply on every Modifier, one by one. We will script this later, I promise.

Randomize each pieces using my previous script that gives random color on selected objects.

Especially nice if we then apply Blender Bullet Physics. This is obviously less cool than Blender Cell Fracture (Voronoi shatter), but still useful in some case, especially if like to specifically Cut and Slice objects.



LIMITATION:
When the object is too complex, it is possible that the Boolean failed. Fox example, if mesh to be cut and slice has holes like Suzanne eyes, or made of multiple pieces.


However, regardless of limitation, the use of Solidify Modifier and Array Modifier for Poly Plane (Cutting Plane) and Boolean Modifier for the object to be sliced is actually quite robust and procedural. The effect is live and you can cut and slice and adjust it and see the result right away, what else can we ask?



AUTOMATING THE PROCESS USING PYTHON

Below scripts will automate the process of Cutting and Slicing for you.


BLENDER SUSHI SCRIPT: Convert selected Planes into Boolean Cutting Planes


"""
Auto apply Boolean Modifier for cutting and slicing.

Copyright (c) 2013 Jimmy Gunawan at Blender Sushi Blog
Name: Name of the script
Version: 001
Author: Jimmy Gunawan
Contact: blendersushi@gmail.com
Date Created: 2013.05.02

How to use the script:
1. Prepare some Poly Planes in which you already apply "Solidify Modifier"
as your cutting planes.
2. Select all the Cutting Planes, and your Mesh (to be cut) last.
3. Run the script to connect every Cutting Planes to the objet.

"""


import bpy

# Get all selected except Active Object
slave_objects = (bpy.context.selected_objects)

# Get Active Object
master_object = bpy.context.active_object

# Iterate each newly created Modifier to point to corresponding slave objects

for num, slave in enumerate(slave_objects[:-1]):
print(slave.name)
bpy.context.scene.objects.active = master_object
bpy.ops.object.modifier_add(type='BOOLEAN')


current_modifier_name = bpy.context.object.modifiers[num].name

bpy.context.object.modifiers["{current_modifier_name}".format(current_modifier_name=current_modifier_name)].operation = 'DIFFERENCE'
bpy.context.object.modifiers["{current_modifier_name}".format(current_modifier_name=current_modifier_name)].object = bpy.data.objects["{slave_name}".format(slave_name = slave.name)]





VIDEO:


BLENDER SUSHI SCRIPT: Quick Apply Modifiers
If you then want to Apply all Modifiers, you can quickly do that by selecting the object with Modifier stacks, and then run the script below:

'''

Quick script to apply all modifiers of currently selected object(s)
'''

import bpy

def applyModifier():

# Get list of currently selected objects
selected_objects = bpy.context.selected_objects

for object in selected_objects:
    # Make object in the list as active one by one
    bpy.context.scene.objects.active = bpy.data.objects[object.name]
    
    # Get all current object modifiers
    current_object_modifiers = bpy.context.object.modifiers
    
    # Iterate every modifier of current object
    for modifier in current_object_modifiers:
        print(modifier, 'is deleted')
        bpy.ops.object.modifier_apply(apply_as='DATA', modifier="{modifier_name}".format(modifier_name=modifier.name))
        
applyModifier()



BLENDER SUSHI SCRIPT: Auto-Random Cutting and Slicing of Selected Object(s)

<< SCRIPT COMING SOON>>


WISHLIST: Actual Cut Face/Cut Plane Tool

I think, it is possible for Blender to have Cut Plane Tool that work more like Knife Tool. Maybe a more experienced Blender Developer can create such tool.

For now, this easy and fun hack will work fine for us.

ABSTRACT CUBISM ART

The reason I am writing this article on Cutting and Slicing is because one of my students Goreisha, asking me how to create Abstract Cubism Art using Adobe Illustrator. The Abstract Cubism that she wanted to create resembles slicing of planes into triangles pattern (Delaunay triangulation).

I told her it's probably easier to do using Blender in 3D.

Well, of course with Illustrator, we can use some random lines and Pathfinder tool to do something like Boolean but in 2D.  And then maybe with some scripting, Illustrator can randomize the Fill Color of each pieces. But it is a pain to do, I imagine.

Anyhow, I think it is much more flexible to do it in 3D and render it out, everyone agree? We can have all kind of beautiful renders by adjust light and materials.


Random RGB abstract cubism.

Random HSB abstract cubism.
Remember the RGB vs HSB thing that I have mentioned in the past? HSB Hue variation is more pleasing to the eyes. Of course, you can also specify a bunch of color that Blender can sample and then apply in random fashion.

This is for my student "wallpaper design", so we can be random about the slicing. In the future I will think on a way to actually create a more interesting Cubism Art based on photograph or something.

CONVEX HULL
Probably not directly related, but it is still about messing around and remeshing around with mesh and Nicholas Bishop "Convex Hull" implementation in Blender is super interesting for me.

Kind of know that Convex Hull is used in Blender Bullet Physics, but I didn't know until today that we can simply go to Edit Mode and apply Convex Hull to selected Vertices of Mesh, do you?
http://wiki.blender.org/index.php/User:Nicholasbishop/Convex_Hull

FURTHER CHALLENGE: Delaunay Triangulation?
Thinking about creation of Delaunay Triangulation Pattern on a Mesh, I actually always wanted a kind of Modifier in Blender that does pattern slicing and cutting based on Particles and scattering of Points, which should result in Delaunay Triangulation.

Maybe we can actually create something like that via Python scripting. Anyway, I will save that for future. Maybe Blender developers interested to add this feature.

Not sure 100% what I am looking for, but I just like the idea to Remesh as Delaunay.

Below some links related to Delaunay Triangulation:
http://blenderartists.org/forum/showthread.php?255237-Addon-Points-cloud-Delaunay-triangulation-amp-Voronoi-diagram
http://www.codeproject.com/Articles/492435/Delaunay-Triangulation-For-Fast-Mesh-Generation
http://blenderartists.org/forum/showthread.php?104071-Delaunay-triangulation-script
http://blenderartists.org/forum/showthread.php?65240-Triangle-Mesh-Fill-Script-for-Bezier-Curves
http://blenderartists.org/forum/showthread.php?255237-Addon-Points-cloud-Delaunay-triangulation-amp-Voronoi-diagram
http://blenderartists.org/forum/showthread.php?280085-Polygon-reduction-edge-collapsing
http://blenderartists.org/forum/showthread.php?265368-Delaunay-based-volume-rendering-in-Blender

SEE ALSO:
http://blenderartists.org/forum/showthread.php?175265-A-Blender-cutting-tool-for-meshes

Post a Comment

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget