-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
Slice AnimationClip #15615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Slice AnimationClip #15615
Conversation
To create a new clip from a existing from-to frame with optional new name.
donmccurdy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related: #13430
I'm OK with merging either of the PRs; mine would need a rebase anyway. Do you have an example model with multiple subclips, to test that this works as expected and gives smoothly-looping clips? There are some edge cases to be aware of — like:
-------------clip1-------------↓-------------clip2-------------↓-------------clip3-------------|
track1 ----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|---|
track2----|------------------------------------------------------------------------------------|
track3----|----|----|----|----|-------------------------------------|----|----|----|----|----|-|
... where track2 and track3 actually do have values in clip2, but no keyframes. For a correctly authored animation that wouldn't be a problem, but automatic optimizations at export or import can mess things up...
|
|
||
| var track = this.tracks[i]; | ||
|
|
||
| var stride = track.values.length / track.times.length; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would use track.getValueSize() here.
|
|
||
| tracks.push( | ||
| new track.constructor( track.name, times, values, track.createInterpolant ) | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible that some of the tracks won't have any keyframes in the sliced range, so it might be best to keep empty tracks out of the new clip.
|
|
||
| } | ||
|
|
||
| duration = Math.max(times[ to ], duration); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: Duration is computed automatically, so it might be simpler just to pass it undefined in the constructor.
|
|
||
| slice: function(from, to, name) { | ||
|
|
||
| var frames = to - from, duration = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code style: We use hard tabs, not soft tabs.
|
|
||
| }, | ||
|
|
||
| slice: function(from, to, name) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code style: Extra spaces are necessary after opening bracket and before closing bracket slice: function( from, to, name ) {
https://github.com/mrdoob/three.js/wiki/Mr.doob's-Code-Style%E2%84%A2#blocks
|
|
||
| for ( var i = 0, l = this.tracks.length; i < l; i ++ ) { | ||
|
|
||
| var track = this.tracks[i]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code style: Extra spaces are necessary after opening bracket and before closing bracket.
https://github.com/mrdoob/three.js/wiki/Mr.doob's-Code-Style%E2%84%A2#arrays
|
When i export animations with optimizations it will basically remove the start/end keyframe of the desired sequence of a track when smoothing it out in some cases. I'll change it to compute the values at these times, |
|
Thanks for the work here but I think it's better to focus on #13430 (which is already tested and approved). |
To create a new clip from a existing from-to frame with optional new name. Some tools only export animations as a single clip.