Last active
September 30, 2020 21:37
-
-
Save RH2/956895379daa01a2b69679bb5dc05d21 to your computer and use it in GitHub Desktop.
Vertex color from first material slot with baked cavity pass.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
import random | |
#matcol = bpy.data.materials["Material.001"].diffuse_color | |
#for m in bpy.context.object.material_slots: | |
for obj in bpy.context.selected_objects: | |
bpy.ops.object.mode_set(mode='OBJECT') | |
matname = bpy.context.selected_objects[0].material_slots[0].name | |
#specialColor = bpy.data.materials[matname].diffuse_color | |
specialColor = bpy.data.materials[matname].node_tree.nodes['Principled BSDF'].inputs[0].default_value | |
# start in object mode | |
mesh = obj.data | |
if not mesh.vertex_colors: | |
mesh.vertex_colors.new() | |
color_layer = mesh.vertex_colors["Col"] | |
# or you could avoid using the color_layer name | |
# color_layer = mesh.vertex_colors.active | |
i = 0 | |
for poly in mesh.polygons: | |
for idx in poly.loop_indices: | |
#r, g, b = [random.random() for i in range(3)] | |
#color_layer.data[i].color = (r, g, b, 1.0) | |
color_layer.data[i].color = specialColor | |
bpy.ops.paint.vertex_color_dirt(blur_strength=1, clean_angle=1.74533, dirt_angle=0, dirt_only=True, normalize=False) | |
i += 1 | |
# set to vertex paint mode to see the result | |
bpy.ops.object.mode_set(mode='VERTEX_PAINT') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment