Skip to content

Instantly share code, notes, and snippets.

@JoseMiguelPizarro
Last active February 15, 2024 09:05
Show Gist options
  • Save JoseMiguelPizarro/0b6f1a3534dc74912321fbc98f99eb95 to your computer and use it in GitHub Desktop.
Save JoseMiguelPizarro/0b6f1a3534dc74912321fbc98f99eb95 to your computer and use it in GitHub Desktop.
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