Skip to main content
added 12 characters in body
Source Link
simone
  • 807
  • 7
  • 19

Is it possible to get the screen XY coordinates in viewport for a vertex in orthographic view?

I get pixel locations as per a previous answer like this:

co2d = []
for v in cloth.data.vertices:
    p = bpy_extras.object_utils.world_to_camera_view(scene, camera, v.co)
    xy=list(p)
    xy[0] = xy[0] * 680
    xy[1] = xy[1] * 809
    co2d.append(xy)

(image width and height hardcoded here)

Where the camera is defined here:

def area_view_3d():
    areas = [a for a in bpy.context.screen.areas if a.type == "VIEW_3D"]
    if not areas:
        return
    return areas[0]

camera = area_view_3d().spaces[0].camera

but when I take the resulting coordinates and map them onto the screenshot it looks like this:

enter image description here

Clearly I get something that looks like coordinates, but isn't what I want.

What is it that I am getting wrong?

Is it possible to get the screen XY coordinates for a vertex in orthographic view?

I get pixel locations as per a previous answer like this:

co2d = []
for v in cloth.data.vertices:
    p = bpy_extras.object_utils.world_to_camera_view(scene, camera, v.co)
    xy=list(p)
    xy[0] = xy[0] * 680
    xy[1] = xy[1] * 809
    co2d.append(xy)

(image width and height hardcoded here)

Where the camera is defined here:

def area_view_3d():
    areas = [a for a in bpy.context.screen.areas if a.type == "VIEW_3D"]
    if not areas:
        return
    return areas[0]

camera = area_view_3d().spaces[0].camera

but when I take the resulting coordinates and map them onto the screenshot it looks like this:

enter image description here

Clearly I get something that looks like coordinates, but isn't what I want.

What is it that I am getting wrong?

Is it possible to get the screen XY coordinates in viewport for a vertex in orthographic view?

I get pixel locations as per a previous answer like this:

co2d = []
for v in cloth.data.vertices:
    p = bpy_extras.object_utils.world_to_camera_view(scene, camera, v.co)
    xy=list(p)
    xy[0] = xy[0] * 680
    xy[1] = xy[1] * 809
    co2d.append(xy)

(image width and height hardcoded here)

Where the camera is defined here:

def area_view_3d():
    areas = [a for a in bpy.context.screen.areas if a.type == "VIEW_3D"]
    if not areas:
        return
    return areas[0]

camera = area_view_3d().spaces[0].camera

but when I take the resulting coordinates and map them onto the screenshot it looks like this:

enter image description here

Clearly I get something that looks like coordinates, but isn't what I want.

What is it that I am getting wrong?

Source Link
simone
  • 807
  • 7
  • 19

Get pixel coords for vertex in viewport

Is it possible to get the screen XY coordinates for a vertex in orthographic view?

I get pixel locations as per a previous answer like this:

co2d = []
for v in cloth.data.vertices:
    p = bpy_extras.object_utils.world_to_camera_view(scene, camera, v.co)
    xy=list(p)
    xy[0] = xy[0] * 680
    xy[1] = xy[1] * 809
    co2d.append(xy)

(image width and height hardcoded here)

Where the camera is defined here:

def area_view_3d():
    areas = [a for a in bpy.context.screen.areas if a.type == "VIEW_3D"]
    if not areas:
        return
    return areas[0]

camera = area_view_3d().spaces[0].camera

but when I take the resulting coordinates and map them onto the screenshot it looks like this:

enter image description here

Clearly I get something that looks like coordinates, but isn't what I want.

What is it that I am getting wrong?