theatre-js / theatre

Motion design editor for the web
https://www.theatrejs.com
Apache License 2.0
10.82k stars 337 forks source link

Add __experimental_sequenceProp to studio.transaction() #449

Closed akre54 closed 7 months ago

akre54 commented 8 months ago

I want the ability to programmatically add keyframes to a sequence, but it looks like the best way to do this is to use transaction(({set}) => {}). Unfortunately set doesn't create a Track from an unsequenced prop.

So let's say I have some data I want to turn into keyframes.

studio.transaction(({ set, unset }) => {
  const pos = sequence.position
  for (const keyframe of sequence.__experimental_getKeyframes(obj.props.x)) {
    sequence.position = keyframe.position
    unset(obj.props.x)
  }
  for (const {time, value} of data) {
    sequence.position = time
    set(obj.props.x, value)
  }
  sequence.position = pos
})

Currently, on main, If obj.props.x isn't already sequenced (i.e. manually from the Studio UI) then set will just set the static prop, which isn't what we want here. This pull allows you to at least tell Studio that you want to sequence the property.

@vimlesh1975 has some code that he posted to Discord that loops over all keyframes and unsets their value at the given time, but it would be really nice to be able to clear all keyframes for the initial track data, and ensure that the track is sequenced ahead of time.

See also #411

Ideally I'd like something like:

sequence.clearKeyframes(obj.props.x)
sequence.setKeyframeAtTime(obj.props.x, time, val)

But in the meantime at least this fixes the ambiguity of whether you want to set a static prop or a sequenced prop.

vercel[bot] commented 8 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
theatre-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 9, 2023 3:17pm
akre54 commented 8 months ago

Changed to draft. getArrayOfValidSequenceTracks (called by set, from getMapOfValidSequenceTracks_forStudio and createTransactionPrivateApi) returns empty, so this needs to be fixed first

AriaMinaei commented 7 months ago

Hi @akre54, this one is merged via 74b68c8f12698bd4b1c46c14f550295625630f88. Feel free to send PRs for these as well 🙏

sequence.clearKeyframes(obj.props.x)
sequence.setKeyframeAtTime(obj.props.x, time, val)
akre54 commented 5 months ago

Hey @AriaMinaei any hope for this to be released soon? I have a feature that deals a lot with editing the timeline. Thanks! 🙏