Skip to content

Instantly share code, notes, and snippets.

@tamask
Last active December 10, 2015 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tamask/4354178 to your computer and use it in GitHub Desktop.
Save tamask/4354178 to your computer and use it in GitHub Desktop.
import bpy
import math
import mathutils
def magnitude(v):
return math.sqrt(v.x ** 2 + v.y ** 2 + v.z ** 2)
COLOR = mathutils.Color((1, 1, 1))
RADIUS = 10
obj = bpy.context.active_object
center = bpy.context.scene.cursor_location
vcolors = obj.data.vertex_colors.active.data
for poly in obj.data.polygons:
colors = []
for idx in poly.vertices:
vert = obj.data.vertices[idx].co
delta = vert - center
distance = magnitude(delta)
atten = 1 - min(distance / RADIUS, 1)
color = COLOR.copy()
color.v *= atten
colors.append(color)
for idx, ptr in enumerate(poly.loop_indices):
color = colors[idx]
vcolor = vcolors[ptr].color.copy()
vcolor.r *= color.r
vcolor.g *= color.g
vcolor.b *= color.b
vcolors[ptr].color = vcolor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment