[WIP] Boolean operations helper script. My first script.

I’m attempting to recreate the abilities demonstrated in the first few pictures in the above tutorial (which is for 3dsmax). Blender’s boolean operations can be used to achieve similar behaviour.

Below is my first version.

The last selected object (the one that is a brighter color of pink than the rest) will be used as the cutter, and cut through all other selected objects. (Any terminology which might help my description?)

There are a few bugs with this version:

  1. If an object is not cut, it will result in an empty object.
  2. With complex shapes (which usually result from performing cuts multiple times), objects may have stray verts, faces, etc, or may not be a closed object, just a set of 2d faces which never meet together.

The first bug is first priority to fix, and I know it can be fixed.
Two might take more work because I expect the problem is inherent in the blender boolean operations.

I hope to add new behaviors and options. Specifically, I want to make it so the last selected object (the bright pink one) will be cut by all other selected objects. Currently you cut many objects with one, but I want to be able to cut one with many.

Also, I hope to make it so cutting does not produce multiple objects, but simply modifies the existing mesh. You could then seperate the mesh into seperate objects the seperate operation, or you could remove doubles and have interal faces added to the object (which might be useful?).

import bpy
import Blender
from Blender import *

def cut(obj1, obj2):
    scn = Scene.GetCurrent()
    mod = obj1.modifiers.append(Blender.Modifier.Type.BOOLEAN)  # add boolean modifier
    mod[Modifier.Settings.OBJECT] = obj2                        # defines the object to operate
    mod[Modifier.Settings.OPERATION] = 0                        # defines the operation
    obj1.makeDisplayList()                                      # Needed to apply the modifier
    mi = Mesh.New()
    mod[Modifier.Settings.OPERATION] = 2
    md = Mesh.New()
    dobj = scn.objects.new(md, obj1.name)

objects = Object.GetSelected()
cutter = objects[0]

for obj in objects:
    cut(obj, cutter)

Any participation or requests for improvements are welcome.

Impressive! I’ve tested it and it works great! i’ll tell you more later when i post my results… :smiley:

The first thing i’ve noticed: it will be nice to assign automatically another material to inner faces…
Here’s my test:

Download Blend + pics

I agree that would be a priority feature to add.

I appreciate the feedback. Thanks for the demonstration blend; very effective.

hello, did u see my fracture-me script? it does something very similar in more ways.

the script basically does everything described in that tutorial, breaks object, sets up a simulation, so after starting game engine you can bake explosions or demolitions.

I am currently not updating the script because i’ve been waiting for 2.5 api to be finished.
the thing with assigning materials and uv’s is missing in my script, maybe we could start to cooperate :wink:

I’d be happy to help. How many are working on the project and where can I find the code?

If you work with blender through function calls (like the cut function in my little script), you should be able to continue working, and simply change the functions to conform to 2.5 once it’s released?

Fracture Script <–> Fracture API <–> Blender API <–> Blender Internals

If Blenders Internals and the Blender API change, you should only have to change your own API, but not the core logic?

wow guys! it would be amazing to get you working together. Personally i’ve seen the pildanovak’s scripts, and i’ve tested only heaper (Really wonderful!). I think that i’ll test fractureme soon then…
Thanks guys!

the last code is here:
here are some videos:

with api it’s true that most of the logic of a script should stay the same. But api for the UI(which Is my reason to wait) will be completely different. Also you cannot yet really access well mesh elements, only through the operators, which is very non-comfortable. I could probably allready port the 2d crack generation, but the 3d version relies on booleans operations and other standart tools, to which access will be changed completely…

Thank you for making this script… I am so very grateful for a script that just works.
Im not sure why I have it named break it tho.