[Feature Request] Expose 2D positions of objects #90
-
Use case: clicking on an object can trigger an popover card (or dialogue box) open. Note that this dialogue box is a custom react component defined outside of spline. Why need 2D positions: currently a SplineEvent in onMouseDown only contains the target’s name and ID without telling us where the object is. Without its 2D position, we can’t position the dialogue box properly. Desired behavior: SplineEvent provides the 2D position of the object. Or alternatively, the results from findObjectByName and findObjectByID contains the 2D position of the object (currently only has 3D). Please let me know if there’re other ways to implement this functionality, but otherwise please take a moment to review this feature request! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You can convert the 3D coordinates of the object to 2D coordinates by using the camera, you can do it like this: const obj = spline.findObjectByName(event.target.name);
const camera = spline.findObjectByName('Camera'); // or the name of the camera you're using
const { x, y } = toScreenPosition(obj, camera); You can get the code of the |
Beta Was this translation helpful? Give feedback.
You can convert the 3D coordinates of the object to 2D coordinates by using the camera, you can do it like this:
You can get the code of the
toScreenPosition()
function from this stackoverflow answer.