Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bpy
- from mathutils import Color, Vector
- my_object = bpy.context.active_object.data
- vert_list = my_object.vertices
- color_map_collection = my_object.vertex_colors
- if len(color_map_collection) == 0:
- color_map_collection.new()
- color_map = color_map_collection['Col']
- torus = bpy.data.objects['Torus']
- i = 0
- for poly in my_object.polygons:
- for idx in poly.loop_indices:
- loop = my_object.loops[idx]
- v = loop.vertex_index
- selfWC = bpy.context.active_object.matrix_world @ vert_list[v].co
- torusLocalSelfPoint = torus.matrix_world.inverted() @ selfWC
- result,newLocation,newNormal,newIndex = torus.closest_point_on_mesh(torusLocalSelfPoint)
- if result is True:
- finalDirection = (newLocation - selfWC).normalized()
- x = (finalDirection.x + 1) / 2
- y = (finalDirection.y + 1) / 2
- z = (finalDirection.z + 1) / 2
- t = 0
- final = (x,y,z,t)
- color_map.data[i].color = final
- else:
- final = (0.5,0.5,0.5,0)
- color_map.data[i].color = final
- i += 1
- # set to vertex paint mode to see the result
- bpy.ops.object.mode_set(mode='VERTEX_PAINT')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement