-
Notifications
You must be signed in to change notification settings - Fork 0
/
volume_selector.py
39 lines (33 loc) · 1.41 KB
/
volume_selector.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import bpy, bmesh
class VolumeSelector():
@staticmethod
def get_volume(object, verbose = False, use_cached=False):
if ("sbv_volume" in object) and (use_cached):
volume = object["sbv_volume"]
else:
bm = bmesh.new()
bm.from_mesh(object.data)
volume = float(bm.calc_volume())
object["sbv_volume"] = volume
if verbose:
print("Object {} has volume {}".format(object.name, volume))
return volume
@classmethod
def select_items(cls, object_list, vol_min, vol_max, id_string=None, use_cached=False, verbose=False):
selected_items = []
first_active = False
for object in object_list:
volume = cls.get_volume(object, use_cached=use_cached, verbose=verbose)
is_neuron = id_string in object.name if id_string else True
if volume > vol_min and volume < vol_max and is_neuron:
if not first_active:
bpy.context.view_layer.objects.active = object
first_active = True
selected_items.append(object)
object.select_set(state=True)
#else: # too slow
# object.select_set(state=False)
return selected_items
@staticmethod
def get_meshes():
return [mesh for mesh in bpy.context.scene.objects if mesh.type == "MESH"]