-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlighting.py
53 lines (38 loc) · 1.23 KB
/
lighting.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
48
49
50
51
52
53
import bpy
import random
from .utils import *
def color_mul(a, b):
return tuple([
a[i] * b[i]
for i in range(4)
])
def color_add(dest, a, b):
for i in range(3):
dest[i] = a[i] + b[i]
def merge_vertex_colors(scene):
for obj in bpy.data.objects:
if obj.type == 'MESH':
if obj.data.color_attributes.get('Multiply'):
merge_vertex_colors_for_object(obj)
def merge_vertex_colors_for_object(geom_obj):
mesh = geom_obj.data
layer_col = mesh.color_attributes['Col']
layer_ao = mesh.color_attributes['AO']
layer_mul = mesh.color_attributes['Multiply']
log('col', len(layer_col.data))
log('ao', len(layer_ao.data))
log('mul', len(layer_mul.data))
i = 0
for poly in mesh.polygons:
for idx in poly.loop_indices:
if i < len(layer_col.data):
if i < len(layer_mul.data):
mul = layer_mul.data[i].color
else:
mul = (1, 1, 1, 1)
if i < len(layer_ao.data):
ao = layer_ao.data[i].color
else:
ao = (1, 1, 1, 1)
layer_col.data[i].color = color_mul(mul, ao)
i += 1