Skip to content

Commit

Permalink
fix(animation): add getTimeRangeFilterKeyframes prop for export-video…
Browse files Browse the repository at this point in the history
…-panel-container (#221)

* add getTimeRangeFilterKeyframes prop
  • Loading branch information
igorDykhta authored Jan 19, 2022
1 parent 82eab71 commit b88efcb
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 9 deletions.
12 changes: 10 additions & 2 deletions modules/core/src/animations/kepler-animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export default class KeplerAnimation extends Animation {
layerKeyframes = [],
filters = [],
filterKeyframes = [],
getTimeRangeFilterKeyframes = undefined,
animationConfig = undefined,
tripKeyframe = undefined,
cameraKeyframe = undefined,
Expand All @@ -76,7 +77,8 @@ export default class KeplerAnimation extends Animation {
filterKeyframes,
cameraKeyframe,
animationConfig,
tripKeyframe
tripKeyframe,
getTimeRangeFilterKeyframes
});
this.draw();
}
Expand All @@ -86,6 +88,7 @@ export default class KeplerAnimation extends Animation {
layerKeyframes = [],
filters = [],
filterKeyframes = [],
getTimeRangeFilterKeyframes = undefined,
animationConfig = undefined,
tripKeyframe = undefined,
cameraKeyframe = undefined,
Expand Down Expand Up @@ -129,7 +132,12 @@ export default class KeplerAnimation extends Animation {
if (acc[filter.id]) {
acc[filter.id].set({filter, ...filterKeyframe});
} else {
acc[filter.id] = new KeplerFilterKeyframes({filter, filterIdx, ...filterKeyframe});
acc[filter.id] = new KeplerFilterKeyframes({
filter,
filterIdx,
getTimeRangeFilterKeyframes,
...filterKeyframe
});
this.unattachedKeyframes.push(acc[filter.id]);
}
}
Expand Down
43 changes: 38 additions & 5 deletions modules/core/src/keyframes/kepler-filter-keyframes.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,35 @@ class KeplerFilterKeyframes extends Keyframes {
id;
type;
filterIdx;
getTimeRangeFilterKeyframes;

constructor({filter, filterIdx, timings, keyframes, easings, interpolators}) {
constructor({
filter,
filterIdx,
timings,
keyframes,
easings,
interpolators,
getTimeRangeFilterKeyframes = undefined
}) {
if (filter.type === 'input') {
throw new Error("filter type 'input' is not supported.");
}
super(
KeplerFilterKeyframes._processParams({filter, timings, keyframes, easings, interpolators})
KeplerFilterKeyframes._processParams({
filter,
timings,
keyframes,
easings,
interpolators,
getTimeRangeFilterKeyframes
})
);
this.id = filter.id;
this.type = filter.type;
this.animationWindow = filter.animationWindow;
this.filterIdx = filterIdx;
this.getTimeRangeFilterKeyframes = getTimeRangeFilterKeyframes;
}

set({filter = undefined, filterIdx = undefined, timings, keyframes, easings, interpolators}) {
Expand All @@ -136,7 +153,14 @@ class KeplerFilterKeyframes extends Keyframes {
this.filterIdx = filterIdx;
}
super.set(
KeplerFilterKeyframes._processParams({filter, timings, keyframes, easings, interpolators})
KeplerFilterKeyframes._processParams({
filter,
timings,
keyframes,
easings,
interpolators,
getTimeRangeFilterKeyframes: this.getTimeRangeFilterKeyframes
})
);
}

Expand Down Expand Up @@ -178,13 +202,22 @@ class KeplerFilterKeyframes extends Keyframes {
return super.getFrame();
}

static _processParams({filter = undefined, timings, keyframes, easings, interpolators}) {
static _processParams({
filter = undefined,
timings,
keyframes,
easings,
interpolators,
getTimeRangeFilterKeyframes = undefined
}) {
let params = {features: ['value'], timings, keyframes, easings, interpolators};
if (filter && filter.type === 'timeRange' && keyframes === undefined) {
if (timings.length !== 2) throw new Error('[start, end] timings required.');
params = {
...params,
...timeRangeKeyframes({filter, timings})
...(getTimeRangeFilterKeyframes
? getTimeRangeFilterKeyframes({filter, timings})
: timeRangeKeyframes({filter, timings}))
};
}
return params;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,15 @@ export class ExportVideoPanelContainer extends Component {
}

componentDidMount() {
const {onTripFrameUpdate, onFilterFrameUpdate} = this.props;
const {onTripFrameUpdate, onFilterFrameUpdate, getTimeRangeFilterKeyframes} = this.props;
const animation = new KeplerAnimation({
...this.getFilterKeyframes(),
...this.getTripKeyframes(),
cameraKeyframe: this.getCameraKeyframes(),
onCameraFrameUpdate: this.setViewState,
onTripFrameUpdate,
onFilterFrameUpdate
onFilterFrameUpdate,
getTimeRangeFilterKeyframes
});
this.state.adapter.animationManager.attachAnimation(animation);
}
Expand Down

0 comments on commit b88efcb

Please sign in to comment.