Coordinate conversion from scene units to pixels


Hi!
I’m trying to dynamically display text on these paper grids. I pass the grid dimensions and their initial x and y values to my displaying function. The issue Is that I don’t know how to convert the values inherent to the scene to that of the viewport. I tried a conversion suggested by ChatGpt where essentially the vector with scene coordinates gets projected onto the camera and the result gets applied as follows:

const screenX = (vector.x + 1) / 2 * window.innerWidth;

const screenY = (-vector.y + 1) / 2 * window.innerHeight;

That’s why the bneofdk is randomly positioned here.

Can anyone please suggest a reliable way where I could for sure translate the scene coordinates to pixels?
Thank you!

Also, don’t mind the text in white. The plan is to display that on the grids. It’s not super relevant to the issue at hand

You’ll need to use vector.project(camera) on the point to take into account the camera viewpoint.

1 Like