motion-canvas
motion-canvas copied to clipboard
New API for absolute transforms
Description The current way of accessing absolute transform is a bit verbose. Additionally, there's no easy way to get the transform of a node relative to another node.
Proposed solution The current way of retrieving absolute positions/rotations/scales of nodes could be improved to accommodate this:
// current API:
const absolutePosition = node().absolutePosition();
const absoluteRotation = node().absoluteRotation();
// new API:
const absolutePosition = node().abs.position();
const absoluteRotation = node().abs.rotation();
const absoluteLeft = layout().abs.left();
// relative to another node:
const relativePosition = node().abs(anotherNode()).position();
const relativeRotation = node().abs(anotherNode()).rotation();
const relativeLeft = layout().abs(anotherNode()).left();
Here, abs
would be a separate entity (a signal-like function with a context), similar to filters
, which would reduce the complexity of the Node
and Layout
classes.
Considered alternatives You can multiply the matrices of two nodes manually but it's verbose and tedious.
Additional context Related to #391
After some more thinking, a better idea worth exploring could be dedicated methods on the Vector2
signals themselves:
// current API:
const absolutePosition = node().absolutePosition();
// new API:
const absolutePosition = node().position.abs();
const absoluteLeft = layout().left.abs();
// relative to another node:
const relativePosition = node().position.relativeTo(anotherNode());
const relativeLeft = layout().left.relativeTo(anotherNode());
This could open the door to other helpful transformations, like
// position in view space:
const position = node().position.view();
// left position in local space:
const left = layout().left.local();
SignalContext
already has access to the owner node which should make this possible.
Supporting rotation
would require a dedicated scalar
signal but it should be worth it.
This solution would also make things like #881 less verbose.