Last active
December 10, 2015 00:49
-
-
Save tamask/4354178 to your computer and use it in GitHub Desktop.
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 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