1
$\begingroup$

I'm trying to export mask spline points x and y data by using:

bpy.data.masks['Mask'].layers['0'].splines[0].points[0].co

but i get an x, y vector with an unknown coordinates like:

(0.40345168113708496, 0.4609205424785614)

i think they are a percentage of the image i made the mask on, i need to convert it to pixel format where it should show something like:

(402,503)

i tried to do some math, and multiplied it with image the resolution, but the resulting numbers are wrong! i do not get the formula behind this vector after searching many posts, can some please point me to it or how to convert it to image space?

$\endgroup$
0
$\begingroup$

Strangely enough, Blender calculates the relativ dimensions with respect to the larger dimension.
These words are not very well choosen. Here is a graphic that show a large orange square. Blender gives us relativ coordinates in this reference frame. The green rectangle is our movie aspect ratio.

graphic

import bpy

render = bpy.context.scene.render

coordinate = bpy.data.masks[0].layers[0].splines[0].points[0].co.copy()
coordinate.x *= render.resolution_x
coordinate.y = coordinate.y * render.resolution_x - (render.resolution_x - render.resolution_y) / 2

# at 100%, this gives us the correct coordinate
print(coordinate)
| improve this answer | |
$\endgroup$
  • $\begingroup$ thanks this is the math i was looking for, it worked but it is flipped on the y axis! $\endgroup$ – bat3a Jan 2 '19 at 8:34
  • $\begingroup$ please see this illustration this imgur.com/a/5QHucjD $\endgroup$ – bat3a Jan 2 '19 at 8:40
  • $\begingroup$ okay i fixed it by using co_y = res_y - co_y $\endgroup$ – bat3a Jan 2 '19 at 9:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.