Advertisement
Guest User

Untitled

a guest
Jan 29th, 2021
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. import bpy
  2.  
  3. from mathutils import Color, Vector
  4.  
  5. my_object = bpy.context.active_object.data
  6.  
  7. vert_list = my_object.vertices
  8. color_map_collection = my_object.vertex_colors
  9.  
  10. if len(color_map_collection) == 0:
  11.     color_map_collection.new()
  12.  
  13. color_map = color_map_collection['Col']
  14.  
  15.  
  16. torus = bpy.data.objects['Torus']
  17.  
  18. i = 0
  19. for poly in my_object.polygons:
  20.     for idx in poly.loop_indices:
  21.         loop = my_object.loops[idx]
  22.         v = loop.vertex_index
  23.        
  24.         selfWC = bpy.context.active_object.matrix_world @ vert_list[v].co
  25.         torusLocalSelfPoint = torus.matrix_world.inverted() @ selfWC
  26.         result,newLocation,newNormal,newIndex = torus.closest_point_on_mesh(torusLocalSelfPoint)
  27.         if result is True:
  28.             finalDirection = (newLocation - selfWC).normalized()
  29.             x = (finalDirection.x + 1) / 2
  30.             y = (finalDirection.y + 1) / 2
  31.             z = (finalDirection.z + 1) / 2
  32.             t = 0
  33.             final = (x,y,z,t)
  34.             color_map.data[i].color = final
  35.         else:
  36.             final = (0.5,0.5,0.5,0)
  37.             color_map.data[i].color = final
  38.         i += 1
  39.  
  40.  
  41. # set to vertex paint mode to see the result
  42. bpy.ops.object.mode_set(mode='VERTEX_PAINT')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement