-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathhelper_funcs.py
47 lines (32 loc) · 1.26 KB
/
helper_funcs.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
40
41
42
43
44
45
46
47
import bpy
def create_quad(name, verts, faces, material, parentObj, edges=None):
if edges is None:
edges = []
mesh = bpy.data.meshes.new(name)
obj = bpy.data.objects.new(mesh.name, mesh)
bpy.context.collection.objects.link(obj)
bpy.context.view_layer.objects.active = obj
mesh.from_pydata(verts, edges, faces)
obj.data.materials.append(material)
obj.parent = parentObj
return obj
def create_materials(mat_name, color):
mat = (bpy.data.materials.get(mat_name) or
bpy.data.materials.new(mat_name))
mat.use_nodes = True
mat.node_tree.nodes.remove(mat.node_tree.nodes.get('Principled BSDF'))
material_output = mat.node_tree.nodes.get('Material Output')
diffuse = mat.node_tree.nodes.new('ShaderNodeBsdfDiffuse')
diffuse.inputs['Color'].default_value = color
mat.node_tree.links.new(material_output.inputs[0], diffuse.outputs[0])
return mat
def quad_min_max(quad_obj):
all_vert = []
for vert in quad_obj.data.vertices:
coord = vert.co
all_vert.append([coord.x, coord.y])
min_xy = min(all_vert, key=lambda x: (x[0], x[1]))
max_xy = max(all_vert, key=lambda x: (x[0], x[1]))
return (min_xy, max_xy)
def round_to_even(value):
return round(value / 2) * 2