1
$\begingroup$

I have an image plane that I would like to constraint to itself, so that it would be scaled when I translate it.

I know how to use a transformation constraint from one object to another, but it does not seem like it works for a single object.

I need to make it a script, but the first step would be to make it work in the GUI. Thank you for your help!

$\endgroup$

2 Answers 2

2
$\begingroup$

Thanks! For those who might be interested in the bpy code, something like that worked:

img_vid_path = r'D:\data\Anais\Mathieu\cam01.mp4'
bpy.ops.object.load_reference_image(filepath=img_vid_path)
img = bpy.context.active_object

bpy.ops.object.empty_add(type='PLAIN_AXES')
empty= bpy.context.active_object
img.parent = empty

img.constraints.new(type='TRANSFORM')
img.constraints['Transformation'].target = empty
img.constraints['Transformation'].use_motion_extrapolate = True
img.constraints['Transformation'].target_space = 'LOCAL'
img.constraints['Transformation'].map_to = 'SCALE'
img.constraints['Transformation'].from_max_z = 1
img.constraints['Transformation'].map_to_x_from = 'Z'
img.constraints['Transformation'].to_min_x_scale = 0
img.constraints['Transformation'].to_max_x_scale = 1

However, this lead me into discovering drivers, which I ended up finding a bit more clean and intuitive (it may be my own bias).
It does not require adding any parent empty, and it is more versatile when you need to express a coordinate as a complex linear combination of several variables (for the record, you first need to add your variable in the driver namespace with bpy.app.driver_namespace['new_var'] = new_var

img_vid_path = r'D:\data\Anais\Mathieu\cam01.mp4'
bpy.ops.object.load_reference_image(filepath=img_vid_path)
img = bpy.context.active_object

driver_scalex = img.driver_add('scale', 0) 
d_scalex = img.driver_add('scale', 0) 
v_scalex = d_scalex.driver.variables.new()
v_scalex.name = 'scaleX'
v_scalex.targets[0].id = img
v_scalex.type = 'TRANSFORMS'
v_scalex.targets[0].transform_type = 'LOC_Z'
v_scalex.targets[0].transform_space = 'LOCAL_SPACE'
d_scalex.driver.expression = '-scaleX'
$\endgroup$
1
$\begingroup$

the first step would be to make it work in the GUI

You can add a layer of indirection, and then it works fine.

Start by making an empty at the location of the plane. Parent your plane to this empty. Give your plane a transformation constraint targeting the empty.

Now, you don't interact with the plane directly; you control it via its empty parent. You might consider disabling "selection" on the plane. When you move the empty, the plane follows because it is its child, and the plane scales because of the transformation constraint targeting the empty.

$\endgroup$
1
  • $\begingroup$ Thank you @Nathan! I ended up doing things a bit differently, but it did help me getting unstuck :) $\endgroup$ Commented Jan 31 at 9:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .