my goal is to create an operator script that will add the specified color to the vertex color of the selected object based on distance (and lambert using the normals facing). this will essentially paint with a simulated point light. ideally id like to do this in vertex paint mode and just grab the current paint color. i have to figure out the falloff logic. its acting kinda wonky.
here is the script (blender 3.5):
import bpy
import mathutils
newcol = mathutils.Color([0.0, 1.0, 0.2])
# Get the active object and ensure it's a mesh
obj = bpy.context.active_object
if obj.type != 'MESH':
raise ValueError("The active object is not a mesh")
# Get the mesh data
mesh = obj.data
# Get the 3D cursor location
cursor_location = bpy.context.scene.cursor.location
# Get the vertex color data
colattr = obj.data.color_attributes[0]
for v_index in range(len(mesh.vertices)):
# Calculate the distance between the vertex and the cursor
distance = (mesh.vertices[v_index].co - cursor_location).length
# Apply quadratic falloff
falloff = 1 - (distance / 2) ** 2 # Adjust the divisor for desired falloff range
# Multiply the float color values by the falloff and add it to the current color
colattr.data[v_index].color[0] += newcol.r
colattr.data[v_index].color[1] += newcol.g
colattr.data[v_index].color[2] += newcol.b
# Update the mesh
mesh.update()
right now its assigning color, just not correctly falling off