rive-wasm
rive-wasm copied to clipboard
[Feature Request] Expose node box
Motivation
To trigger events based on Nodes we need to check if the target event is inside the node :
canvas.addEventListener('click', event => {
const insideX = event.offsetX > node.box.minX && event.offsetX < node.box.maxX;
const insideY = event.offsetY > node.box.minY && event.offsetY < node.box.maxY;
if (insideX && insideY) nodeClicked();
})
Current
Currently the node exposes x, y, scaleX, scaleY, rotation. This is not enough to
Request
Expose a AABB box on the node with { minX, minY, maxX, maxY }.
Considerations
I've looked at the cpp code of the NodeBase object and couldn't find any properties that could provide this information. But the Rive Editor is able to display it (blue border in image below), so I suppose this can be calculated. If you know how to do it, but don't have the bandwidth to implement it, I'm happy to create a PR if you can provide me a set of instructions.
Thanks.

Hi @GrandSchtroumpf, that's very kind of you! The reason it's not exposed yet is because computing the bounds correctly requires quite a bit of code which we strip out from the runtimes to keep them lean. We could just expose a rough bounds which would work for rectangular shapes, but the editor computes the extrema of the bezier curves to get the accurate bounds it displays. We're working on an elegant solution that will let you define hit regions in the editor and will clearly be of specific shapes.
We could also do a test exposing the super accurate bounds computation and see what the actual hit on WASM size is. We've been weary to do it to not encourage people to use an inefficient system when we plan on exposing something better, but perhaps we should bite the bullet...
I see. If it's not too much work on your side to expose it I'm happy to run some tests. But I definitely understand if it outside of you short term missions. Thanks for the feedback.
Maybe we should do it, let's keep this open for now as I know @mjtalbot has had this requested a few times on Android as well.
Hello, I've got a usecase where I need able to interact with the nodes of the canvas. A simple squared hitbox would be enough for me (no need for super precise boundaries). Would it be something easy to implement as a first step ?