I got my object and I need to know all pixels that are displaying this object in my rendered picture.
I read about a smiliar question here.
update I tried this code from here:
def tocam(scene, ob):
cam_vec = cam.matrix_world.to_3x3() * Vector((0, 0, -1))
R = cam_vec.to_track_quat('-Z', 'Y').to_matrix().to_4x4()
# scale based on resolution
S = Matrix() # resX=resY
# translate such that origin is middle point of image (and hence cam)
T = Matrix.Translation((-0.5, -0.5, 0))
ob.data.transform(ob.matrix_world)
ob.matrix_world = Matrix()
for v in ob.data.vertices:
vec = w2cv(scene, cam, v.co)
v.co = vec.x, vec.y, 0
ob.data.transform(S * T)
ob.matrix_world = R
angle_x = cam.data.angle_x
x = (0.5 / tan(angle_x / 2)) * cam_vec.normalized()
ob.matrix_world.translation = cam.matrix_world.translation + x
if cam.data.type == 'ORTHO':
ob.scale *= cam.data.ortho_scale
res_x = 640
res_y = 640
# 2d data printout:
rnd = lambda i: round(i)
for v in ob.data.vertices:
print("{},{}".format(rnd(res_x*v.co.x), rnd(res_y*v.co.y)))
when I plot the points I get this:
but my rendered image is this:
So you can see, that it is not on the correct position and also the shape is not really correct.
Can anyone help me on this? Thanks a lot!




./blender first.blend --background --python render.py– blenderNewbie Feb 07 '20 at 14:26