2
$\begingroup$

I'd like to hide a part of an object based on a plane, like a bisect with clear inner/outer but i want to keep the possibility to make this change dynamic in real time (it is done with python through an handler).

Some precisions: Performances is my main problem. I dont really need a neat cut and a closing face, hiding a part of the vertices could be a good enough solution.

The different solutions I explored:

A first obious solution would be to use a boolean modifier but my object is too complex(between 50.000 en 200.000 vertex), the boolean operation could take several seconds and I need to be able to update it several times per second.

The bisect is maybe be fast enough but I need something that can be configured in real time, like when the bisect is in the "creation phase".

A last solution would give a less good result but maybe better performance is to add part of the vertex to a vertex group and use the mask modifier: I need a script to add each vertex to a vertex group based on my plain informations.

def hidePart(ob,normal,point):
    if(bpy.context.scene.hide_cutted):
        indexList = []
        for v in ob.data.vertices:
            vcow = ob.matrix_world * v.co
            distance = normal.dot(point-v.co)
            if distance >0:
                indexList.append(v.index)
        for elem in ob.vertex_groups:
            if elem.name == "cutted":
                ob.vertex_groups.remove(elem)
        vg = ob.vertex_groups.new(name="cutted")
        vg.add(indexList, 1.0, 'ADD')
        bpy.context.scene.objects.active =ob
        bpy.ops.object.mode_set(mode='OBJECT')

Unfortunately, even if it is faster than boolean modifier, it is still quite slow (between 0.5 and 1 seconde) and the update is jerky. I also need to make the object active and go to object mode to update the mask modifier.

A solution to only restrict the view like the alt+b shortcut but with a different one for each object would be a great solutions but i think it is impossible.

Any suggestion?

A new possibility: I discorvered the Vertex Weight Proximity Modifier. Combined with the Mask modifier we have something close from what i need exept that by default we remove a slice of that object around the plane, and not the upper part. Result slice

A solution is simply to put another plane parented to the first one, lets say 400 blender unit higher than the first one and give to the maximum a value near to 800 in the Weight Proximity Modifier.

Modifier stack

The result is very smooth when moving the plane with up to 100k vertices. But the computation of the distance between a face and a vertex is way more complex than the distance between an infinite plane and vertice. So basically this solution is more complex than the one I wrote in python and stay more efficient. An implementation of a modifier like that based on a normal and a point would be perfect to allow even more vertices.

At this points I have something working and almost maching my needs, but I'll wait a little to post this solution as an answer: maybe someone has a solution giving a cleaner result based on bisect, or an even smoother solution based on mask.

$\endgroup$
4
  • 1
    $\begingroup$ This is speculation, I don't know this for sure, but I imagine the reason alt+b clipping is so fast is because its part of the shader program running on the gpu. If there is a solution that is as fast as Blender's clipping its probably going to involve GLSL and the bpy opengl wrapper. docs.blender.org/api/blender_python_api_2_60_4/bgl.html $\endgroup$ Commented Jun 26, 2017 at 15:08
  • $\begingroup$ Thanks for this comment.. Doesn't look a easy way to do what i want since i didn't found a "hidePartOfObject" in the page but i'll try to figure out if there is something interresting there.:D $\endgroup$
    – Pyros
    Commented Jun 26, 2017 at 15:26
  • $\begingroup$ Check out the section on glClipPlane. I think that's exactly what you need. Here's a good explanation on clip planes: mrkaktus.org/opengl-clip-planes-explained $\endgroup$ Commented Jun 26, 2017 at 15:32
  • $\begingroup$ Thanks. It was a great idea but i don't figure out how to use this right now in my case and i don't really have the time to learn a lot about that without being sure that i'll found something interressting. glClipPlane look interrestiong for instance, but all the geometry are concernet, not only the geometry of one object. Thats the problem with a really "low level" solution. $\endgroup$
    – Pyros
    Commented Jun 27, 2017 at 7:48

0

You must log in to answer this question.

Browse other questions tagged .