1

I'd like to be able to generate a Black and White texture using the distance the distance each face is from a specific point, scaled between zero and one (i.e. the closest face is a value of one, while the farthest face is a value of zero, while all other faces are linearly interpolated). The calculation for each face is easy enough to do using python, but is there a built in method of applying these values to a texture? Like a face-by-face texture bake?

Kruglord
  • 173
  • 1
  • 12
  • One pixel per face? You can generate an image fairly easily in blender and set pixel values. Here's an example: http://blender.stackexchange.com/questions/47378/save-every-other-pixel-of-an-image-at-half-res/47594#47594 – TLousky Jun 01 '16 at 08:27

2 Answers2

1

enter image description here

This script will generate a vertex color map, where each face's color is represented by a grayscale value matching the normalized distance of that face's center from the cursor, inverted (closer is brighter, farther is darker).

You can run this, then bake the vertex color to a texture file to get the image texture based on the distance. You can of course also use another object instead of the 3D cursor as your distance reference.

import bpy

o = bpy.context.object
d = o.data

if not d.vertex_colors:
    d.vertex_colors.new()

color_layer = d.vertex_colors["Col"]
curloc = bpy.context.scene.cursor_location

distances = [ ( p.center - curloc ).length for p in d.polygons ]

# Normalize distances
normalize      = lambda x, minX, maxX: round( ( x - minX ) / ( maxX - minX ), 2 )
minD, maxD     = min( distances ), max( distances )
distNormalized = [ 1 - normalize( v, minD, maxD ) for v in distances ]

for i, poly in enumerate( d.polygons ):
    for li in poly.loop_indices:
        color_layer.data[li].color = [ distNormalized[i] for c in 'rgb' ]
TLousky
  • 16,043
  • 1
  • 40
  • 72
0

Baking with a lamp at the position of your specific point ? Approximated solution... to lower the faces orientations impact I added a transparent shader here.

The bake option can be diffuse or combine.

The result is not normalized between 0 and 1. But I hope that can help.

enter image description here

lemon
  • 60,295
  • 3
  • 66
  • 136