Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import bpy
def paintVerteces():
ob = bpy.context.object
print(ob.name)
bpy.ops.object.mode_set(mode='VERTEX_PAINT')
maxZ = float(“-inf”)
minZ = float(“inf”)
for face in ob.data.polygons:
for vert_idx in face.vertices:
position = ob.data.vertices[vert_idx].co
z = position.z
if z<minZ:
minZ = z
if z>maxZ:
maxZ = z
for face in ob.data.polygons:
for vert_idx, loop_idx in zip(face.vertices, face.loop_indices):
position = ob.data.vertices[vert_idx].co
z = position.z
color = remap(minZ,0,maxZ,1,z)
bpy.context.object.data.vertex_colors["Col"].data[loop_idx].color = (color,color,color,255)
ob.data.update()
def remap(min1,min2,max1,max2, value):
return min2 + (value - min1) * (max2 - min2) / (max1 - min1)
if __name__ == "__main__":
paintVerteces()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.