Clone from Background Images?

I would really love to be able to clone from the Background Images-movieclip in the 3d View Properties panel directly, onto a new image in Texture Paint Mode. There I have a perfect match with the fit option enabled, since the images in the movieclip have different dimensions.
I could use an image sequence instead, but I just find it a bit slower and more difficult to load and refresh.
I tried the UV project modifier, and it could work, but the I have to use an image sequence instead of a movieclip and the process of cloning with help of the modifier is a bit slow.
Anyway, are there any way to clone in Texture Paint from Background Images?

Sorry, just saw that some asked the same question some days ago!

Ok, I think I solved it (not so pretty but it seems to work) I found this very useful script from Ideasman42 here http://blender.stackexchange.com/questions/6377/coordinates-of-corners-of-camera-view-border and just added some lines to it.

I added this line to refresh the image sequence in the stencil texture

bpy.data.brushes[‘TexDraw’].texture=bpy.data.textures[‘Texture’]

just to match up perfect I change the render resolution to the image resolution, (the image resolution changes in my sequence)

bpy.data.scenes[‘Scene’].render.resolution_x=bpy.data.textures[‘Texture’].image.size[0]
bpy.data.scenes[‘Scene’].render.resolution_y=bpy.data.textures[‘Texture’].image.size[1]

then I pasted Ideasman42´s script from the link before adding

bpy.data.brushes[‘TexDraw’].stencil_pos[0]=frame_px[2][0]/2+frame_px[0][0]/2
bpy.data.brushes[‘TexDraw’].stencil_pos[1]=frame_px[1][1]/2+frame_px[0][1]/2
bpy.data.brushes[‘TexDraw’].stencil_dimension[0]=(frame_px[0][0]-frame_px[2][0])/2
bpy.data.brushes[‘TexDraw’].stencil_dimension[1]=(frame_px[0][1]-frame_px[1][1])/2

It was not so clever to change the resolution for the render, so I will think some more…

This is what I got so far - I think it kind of works, it is not exactly pixelmatch with the backgroundimage (with the FIT option) but almost (If someone knows how the FIT option in the background images is calculated (and rounded) or if I can have access to the Background image with the help of python, please help :)). It matches up nice with the mesh anyway.

It is still WIP and I am absolutely not a coder, but it is probably better than match it by hand. I only tried it by fit the Y axis, so I don´t know if the else works…

I post what I have if someone feels to try it out or help me :slight_smile:

###########################################################
############# Match Stencil with Background Image WIP

import bpy

bpy.data.brushes[‘TexDraw’].texture=bpy.data.textures[‘Texture’]

################################ pasted from of Ideasman42 code
def view3d_find():
# returns first 3d view, normally we get from context
for area in bpy.context.window.screen.areas:
if area.type == ‘VIEW_3D’:
v3d = area.spaces[0]
rv3d = v3d.region_3d
for region in area.regions:
if region.type == ‘WINDOW’:
return region, rv3d
return None, None

def view3d_camera_border(scene):
obj = scene.camera
cam = obj.data

frame = cam.view_frame(scene)

# move into object space
frame = [obj.matrix_world * v for v in frame]

# move into pixelspace
from bpy_extras.view3d_utils import location_3d_to_region_2d
region, rv3d = view3d_find()
frame_px = [location_3d_to_region_2d(region, rv3d, v) for v in frame]
return frame_px

frame_px = view3d_camera_border(bpy.context.scene)
#print(“Camera frame:”, frame_px)
################################ end of Ideasman42 code

bpy.data.brushes[‘TexDraw’].stencil_pos[0]=frame_px[2][0]/2+frame_px[0][0]/2
bpy.data.brushes[‘TexDraw’].stencil_pos[1]=frame_px[1][1]/2+frame_px[0][1]/2

y=frame_px[0][1]-frame_px[1][1]
x=frame_px[0][0]-frame_px[2][0]

ratioRENDER=bpy.data.scenes[‘Scene’].render.resolution_x/bpy.data.scenes[‘Scene’].render.resolution_y
ratioIMG=bpy.data.textures[‘Texture’].image.size[0]/bpy.data.textures[‘Texture’].image.size[1]

if ratioRENDER>=ratioIMG:
bpy.data.brushes[‘TexDraw’].stencil_dimension[1]=y/2
bpy.data.brushes[‘TexDraw’].stencil_dimension[0]=bpy.data.brushes[‘TexDraw’].stencil_dimension[1]*ratioIMG

else:
bpy.data.brushes[‘TexDraw’].stencil_dimension[0]=x/2
bpy.data.brushes[‘TexDraw’].stencil_dimension[1]=bpy.data.brushes[‘TexDraw’].stencil_dimension[0]*ratioIMG

######################################################################