-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
50 lines (38 loc) · 1.1 KB
/
Copy pathutils.py
File metadata and controls
50 lines (38 loc) · 1.1 KB
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
40
41
42
43
44
45
46
47
48
49
50
import bpy
import bmesh
def redraw_ui():
for area in bpy.context.screen.areas:
area.tag_redraw()
def all_parents(ob):
parent = ob.parent
parent_list = []
while parent:
parent_list.append(parent)
parent = parent.parent
return parent_list
def triangle_count(ob):
if isinstance(ob, bpy.types.Object) and ob.type == "MESH":
bm = bmesh.new()
bm.from_mesh(ob.data)
bmesh.ops.triangulate(bm, faces=bm.faces[:])
triagles = len(bm.faces)
bm.free()
return triagles
else:
return 0
def volume(ob):
if isinstance(ob, bpy.types.Object) and ob.type == "MESH":
return ob.dimensions.x * ob.dimensions.y * ob.dimensions.z
else:
return 0
def surface_area(ob):
if isinstance(ob, bpy.types.Object) and ob.type == "MESH":
bm = bmesh.new()
bm.from_mesh(ob.data)
for v in bm.verts:
v.co = ob.matrix_world @ v.co # Reverse world matrix
surface_area = sum(f.calc_area() for f in bm.faces)
bm.free()
return surface_area
else:
return 0