|
@@ -166,7 +166,10 @@ interface IAnimationCurveEditorComponentState {
|
|
|
* @property {GlobalState} globalState the playground globalstate
|
|
|
* Check the IAnimationCurveEditorComponentState for state functionality
|
|
|
*/
|
|
|
-export class AnimationCurveEditorComponent extends React.Component<IAnimationCurveEditorComponentProps, IAnimationCurveEditorComponentState> {
|
|
|
+export class AnimationCurveEditorComponent extends React.Component<
|
|
|
+ IAnimationCurveEditorComponentProps,
|
|
|
+ IAnimationCurveEditorComponentState
|
|
|
+> {
|
|
|
// Global properties
|
|
|
readonly _entityName: string;
|
|
|
private _snippetUrl = "https://snippet.babylonjs.com";
|
|
@@ -215,10 +218,16 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
} else {
|
|
|
this._isTargetedAnimation = false;
|
|
|
|
|
|
- let hasAnimations = this.props.entity.animations !== undefined || this.props.entity.animations !== null ? this.props.entity.animations : false;
|
|
|
+ let hasAnimations =
|
|
|
+ this.props.entity.animations !== undefined || this.props.entity.animations !== null
|
|
|
+ ? this.props.entity.animations
|
|
|
+ : false;
|
|
|
initialSelection = hasAnimations !== false ? hasAnimations && hasAnimations[0] : null;
|
|
|
|
|
|
- initialLerpMode = initialSelection !== undefined ? this.analyzeAnimationForLerp(this.props.entity.animations && initialSelection) : false;
|
|
|
+ initialLerpMode =
|
|
|
+ initialSelection !== undefined
|
|
|
+ ? this.analyzeAnimationForLerp(this.props.entity.animations && initialSelection)
|
|
|
+ : false;
|
|
|
initialPathData = initialSelection && this.getPathData(initialSelection);
|
|
|
initialPathData = initialPathData === null || initialPathData === undefined ? undefined : initialPathData;
|
|
|
}
|
|
@@ -237,7 +246,9 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
isTangentMode: false,
|
|
|
isBrokenMode: false,
|
|
|
lerpMode: initialLerpMode,
|
|
|
- playheadOffset: this._graphCanvas.current ? this._graphCanvas.current.children[0].clientWidth / (_canvasLength * 10) : 0,
|
|
|
+ playheadOffset: this._graphCanvas.current
|
|
|
+ ? this._graphCanvas.current.children[0].clientWidth / (_canvasLength * 10)
|
|
|
+ : 0,
|
|
|
// Set default frame for visible canvas
|
|
|
frameAxisLength: this.setFrameAxis(_canvasLength),
|
|
|
// Set default values for the visible canvas
|
|
@@ -275,7 +286,11 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
componentDidMount() {
|
|
|
this.state.selected && this.selectAnimation(this.state.selected);
|
|
|
// Control the window resize event
|
|
|
- if (this._editor.current && this._editor.current.ownerDocument && this._editor.current.ownerDocument.defaultView) {
|
|
|
+ if (
|
|
|
+ this._editor.current &&
|
|
|
+ this._editor.current.ownerDocument &&
|
|
|
+ this._editor.current.ownerDocument.defaultView
|
|
|
+ ) {
|
|
|
this._editorWindow = this._editor.current.ownerDocument.defaultView;
|
|
|
this._editorWindow.addEventListener("resize", this.onWindowResizeWidth.bind(this));
|
|
|
}
|
|
@@ -594,7 +609,12 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
* @param newValue New value of animated property
|
|
|
* @param coordinate The selected property coordinate to animate (i.e. x, y, z)
|
|
|
*/
|
|
|
- updateValuePerCoordinate(dataType: number, value: number | Vector2 | Vector3 | Color3 | Color4 | Size | Quaternion, newValue: number, coordinate?: number) {
|
|
|
+ updateValuePerCoordinate(
|
|
|
+ dataType: number,
|
|
|
+ value: number | Vector2 | Vector3 | Color3 | Color4 | Size | Quaternion,
|
|
|
+ newValue: number,
|
|
|
+ coordinate?: number
|
|
|
+ ) {
|
|
|
if (dataType === Animation.ANIMATIONTYPE_FLOAT) {
|
|
|
value = newValue;
|
|
|
}
|
|
@@ -757,9 +777,15 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- let updatedValue = ((this._heightScale - updatedSvgKeyFrame.keyframePoint.y) / this._heightScale) * this._scaleFactor;
|
|
|
+ let updatedValue =
|
|
|
+ ((this._heightScale - updatedSvgKeyFrame.keyframePoint.y) / this._heightScale) * this._scaleFactor;
|
|
|
|
|
|
- const updatedValueInCoordinate = this.updateValuePerCoordinate(animation.dataType, keys[index].value, updatedValue, coordinate);
|
|
|
+ const updatedValueInCoordinate = this.updateValuePerCoordinate(
|
|
|
+ animation.dataType,
|
|
|
+ keys[index].value,
|
|
|
+ updatedValue,
|
|
|
+ coordinate
|
|
|
+ );
|
|
|
|
|
|
keys[index].value = updatedValueInCoordinate;
|
|
|
|
|
@@ -786,7 +812,12 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
* @param dataType type of animation
|
|
|
* @param coordinate coordinate to change its value (x, y, or z)
|
|
|
*/
|
|
|
- updateLeftControlPoint(updatedSvgKeyFrame: IKeyframeSvgPoint, key: IAnimationKey, dataType: number, coordinate: number) {
|
|
|
+ updateLeftControlPoint(
|
|
|
+ updatedSvgKeyFrame: IKeyframeSvgPoint,
|
|
|
+ key: IAnimationKey,
|
|
|
+ dataType: number,
|
|
|
+ coordinate: number
|
|
|
+ ) {
|
|
|
if (updatedSvgKeyFrame.isLeftActive) {
|
|
|
if (updatedSvgKeyFrame.leftControlPoint !== null) {
|
|
|
// Rotate Control Points
|
|
@@ -795,11 +826,16 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
|
|
|
let distanceAmplitudeOfX = updatedSvgKeyFrame.leftControlPoint.x - distanceWithPreviousKeyframe;
|
|
|
|
|
|
- let slope = (updatedSvgKeyFrame.leftControlPoint.y - updatedSvgKeyFrame.keyframePoint.y) / (updatedSvgKeyFrame.leftControlPoint.x - updatedSvgKeyFrame.keyframePoint.x);
|
|
|
+ let slope =
|
|
|
+ (updatedSvgKeyFrame.leftControlPoint.y - updatedSvgKeyFrame.keyframePoint.y) /
|
|
|
+ (updatedSvgKeyFrame.leftControlPoint.x - updatedSvgKeyFrame.keyframePoint.x);
|
|
|
|
|
|
- let newValueOfY = (distanceAmplitudeOfX - updatedSvgKeyFrame.leftControlPoint.x) * slope + updatedSvgKeyFrame.keyframePoint.y;
|
|
|
+ let newValueOfY =
|
|
|
+ (distanceAmplitudeOfX - updatedSvgKeyFrame.leftControlPoint.x) * slope +
|
|
|
+ updatedSvgKeyFrame.keyframePoint.y;
|
|
|
|
|
|
- let updatedValue = ((newValueOfY - updatedSvgKeyFrame.keyframePoint.y) * this._scaleFactor) / this._heightScale;
|
|
|
+ let updatedValue =
|
|
|
+ ((newValueOfY - updatedSvgKeyFrame.keyframePoint.y) * this._scaleFactor) / this._heightScale;
|
|
|
|
|
|
if (updatedValue > -100 && updatedValue < 100) {
|
|
|
key.inTangent = slope;
|
|
@@ -822,7 +858,12 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
* @param dataType type of animation
|
|
|
* @param coordinate coordinate to change its value (x, y, or z)
|
|
|
*/
|
|
|
- updateRightControlPoint(updatedSvgKeyFrame: IKeyframeSvgPoint, key: IAnimationKey, dataType: number, coordinate: number) {
|
|
|
+ updateRightControlPoint(
|
|
|
+ updatedSvgKeyFrame: IKeyframeSvgPoint,
|
|
|
+ key: IAnimationKey,
|
|
|
+ dataType: number,
|
|
|
+ coordinate: number
|
|
|
+ ) {
|
|
|
if (updatedSvgKeyFrame.isRightActive) {
|
|
|
if (updatedSvgKeyFrame.rightControlPoint !== null) {
|
|
|
// Get the next svgKeyframe and measure distance between these two points
|
|
@@ -830,11 +871,16 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
|
|
|
let distanceAmplitudeOfX = updatedSvgKeyFrame.rightControlPoint.x + distanceWithNextKeyframe;
|
|
|
|
|
|
- let slope = (updatedSvgKeyFrame.rightControlPoint.y - updatedSvgKeyFrame.keyframePoint.y) / (updatedSvgKeyFrame.rightControlPoint.x - updatedSvgKeyFrame.keyframePoint.x);
|
|
|
+ let slope =
|
|
|
+ (updatedSvgKeyFrame.rightControlPoint.y - updatedSvgKeyFrame.keyframePoint.y) /
|
|
|
+ (updatedSvgKeyFrame.rightControlPoint.x - updatedSvgKeyFrame.keyframePoint.x);
|
|
|
|
|
|
- let newValueOfY = (distanceAmplitudeOfX - updatedSvgKeyFrame.rightControlPoint.x) * slope + updatedSvgKeyFrame.keyframePoint.y;
|
|
|
+ let newValueOfY =
|
|
|
+ (distanceAmplitudeOfX - updatedSvgKeyFrame.rightControlPoint.x) * slope +
|
|
|
+ updatedSvgKeyFrame.keyframePoint.y;
|
|
|
|
|
|
- let updatedValue = ((newValueOfY - updatedSvgKeyFrame.keyframePoint.y) * this._scaleFactor) / this._heightScale;
|
|
|
+ let updatedValue =
|
|
|
+ ((newValueOfY - updatedSvgKeyFrame.keyframePoint.y) * this._scaleFactor) / this._heightScale;
|
|
|
|
|
|
if (updatedValue > -100 && updatedValue < 100) {
|
|
|
key.outTangent = slope * -1;
|
|
@@ -860,7 +906,8 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
let indexOfKeyframe = this.state.svgKeyframes.indexOf(updatedSvgKeyFrame);
|
|
|
let previousKeyframe = this.state.svgKeyframes[indexOfKeyframe - 1];
|
|
|
if (previousKeyframe?.keyframePoint) {
|
|
|
- distanceWithPreviousKeyframe = Vector2.Distance(updatedSvgKeyFrame.keyframePoint, previousKeyframe.keyframePoint) / 2;
|
|
|
+ distanceWithPreviousKeyframe =
|
|
|
+ Vector2.Distance(updatedSvgKeyFrame.keyframePoint, previousKeyframe.keyframePoint) / 2;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -869,7 +916,8 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
let indexOfKeyframe = this.state.svgKeyframes.indexOf(updatedSvgKeyFrame);
|
|
|
let nextKeyframe = this.state.svgKeyframes[indexOfKeyframe + 1];
|
|
|
if (nextKeyframe?.keyframePoint) {
|
|
|
- distanceWithNextKeyframe = Vector2.Distance(nextKeyframe.keyframePoint, updatedSvgKeyFrame.keyframePoint) / 2;
|
|
|
+ distanceWithNextKeyframe =
|
|
|
+ Vector2.Distance(nextKeyframe.keyframePoint, updatedSvgKeyFrame.keyframePoint) / 2;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -954,7 +1002,12 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
* Finds the selected svg keyframe and passes the correct value to the correct animated keyframe.
|
|
|
*/
|
|
|
setKeyframeValue = () => {
|
|
|
- if (this.state.actionableKeyframe.frame !== "" && this.state.actionableKeyframe.frame !== undefined && this.state.actionableKeyframe.value !== "" && this.state.actionableKeyframe.value !== undefined) {
|
|
|
+ if (
|
|
|
+ this.state.actionableKeyframe.frame !== "" &&
|
|
|
+ this.state.actionableKeyframe.frame !== undefined &&
|
|
|
+ this.state.actionableKeyframe.value !== "" &&
|
|
|
+ this.state.actionableKeyframe.value !== undefined
|
|
|
+ ) {
|
|
|
if (this.state.selected !== null) {
|
|
|
let currentSelected = this.state.svgKeyframes?.find((kf) => kf.selected);
|
|
|
if (currentSelected) {
|
|
@@ -981,7 +1034,9 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
frame: this.state.actionableKeyframe.frame as number,
|
|
|
value: this.state.actionableKeyframe.value,
|
|
|
});
|
|
|
- const { prev, next } = this.getPreviousAndNextKeyframe(this.state.actionableKeyframe.frame as number);
|
|
|
+ const { prev, next } = this.getPreviousAndNextKeyframe(
|
|
|
+ this.state.actionableKeyframe.frame as number
|
|
|
+ );
|
|
|
this.setState({ maxFrame: next, minFrame: prev });
|
|
|
}
|
|
|
}
|
|
@@ -1032,7 +1087,9 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
setBrokenMode = () => {
|
|
|
if (this.state.selected !== null) {
|
|
|
let animation = this.state.selected;
|
|
|
- this.setState({ isBrokenMode: !this.state.isBrokenMode }, () => this.selectAnimation(animation, this.state.selectedCoordinate));
|
|
|
+ this.setState({ isBrokenMode: !this.state.isBrokenMode }, () =>
|
|
|
+ this.selectAnimation(animation, this.state.selectedCoordinate)
|
|
|
+ );
|
|
|
}
|
|
|
};
|
|
|
|
|
@@ -1044,7 +1101,9 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
const animation = this.state.selected;
|
|
|
if (this.state.svgKeyframes && animation) {
|
|
|
const keys = animation.getKeys();
|
|
|
- const selectedKeyframe = this.state.svgKeyframes.find((keyframe: IKeyframeSvgPoint) => keyframe.selected && (keyframe.isLeftActive || keyframe.isRightActive));
|
|
|
+ const selectedKeyframe = this.state.svgKeyframes.find(
|
|
|
+ (keyframe: IKeyframeSvgPoint) => keyframe.selected && (keyframe.isLeftActive || keyframe.isRightActive)
|
|
|
+ );
|
|
|
|
|
|
if (selectedKeyframe !== null && selectedKeyframe) {
|
|
|
const { order, coordinate } = this.decodeCurveId(selectedKeyframe.id);
|
|
@@ -1372,7 +1431,15 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
return undefined;
|
|
|
} else {
|
|
|
// Get the animation properties
|
|
|
- const { easingMode, easingType, usesTangents, valueType, highestFrame, name, targetProperty } = this.getAnimationData(animation);
|
|
|
+ const {
|
|
|
+ easingMode,
|
|
|
+ easingType,
|
|
|
+ usesTangents,
|
|
|
+ valueType,
|
|
|
+ highestFrame,
|
|
|
+ name,
|
|
|
+ targetProperty,
|
|
|
+ } = this.getAnimationData(animation);
|
|
|
|
|
|
// Set the initial point of the curve
|
|
|
const startKey = keyframes[0];
|
|
@@ -1391,7 +1458,9 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
|
|
|
const curveColor = valueType === Animation.ANIMATIONTYPE_FLOAT ? colors[4] : colors[d];
|
|
|
// START OF LINE/CURVE
|
|
|
- let data: string | undefined = `M${startKey.frame * this._pixelFrameUnit}, ${this._heightScale - startValue[d] * middle}`; //
|
|
|
+ let data: string | undefined = `M${startKey.frame * this._pixelFrameUnit}, ${
|
|
|
+ this._heightScale - startValue[d] * middle
|
|
|
+ }`; //
|
|
|
|
|
|
if (this.state) {
|
|
|
if (usesTangents) {
|
|
@@ -1438,7 +1507,11 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
let targetPropertyPath = animation.targetPropertyPath;
|
|
|
let framesPerSecond = animation.framePerSecond;
|
|
|
let highestFrame = animation.getHighestFrame();
|
|
|
- let usesTangents = animation.getKeys().find((kf) => kf.hasOwnProperty("inTangent") || kf.hasOwnProperty("outTangent")) !== undefined ? true : false;
|
|
|
+ let usesTangents =
|
|
|
+ animation.getKeys().find((kf) => kf.hasOwnProperty("inTangent") || kf.hasOwnProperty("outTangent")) !==
|
|
|
+ undefined
|
|
|
+ ? true
|
|
|
+ : false;
|
|
|
let valueType = animation.dataType;
|
|
|
let easingType, easingMode;
|
|
|
let easingFunction: EasingFunction = animation.getEasingFunction() as EasingFunction;
|
|
@@ -1505,7 +1578,14 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
* @param coordinate (x, y, z) value
|
|
|
* @param animationName The animation name to generate the curve id
|
|
|
*/
|
|
|
- curvePathWithoutTangents(keyframes: IAnimationKey[], data: string, middle: number, type: number, coordinate: number, animationName: string) {
|
|
|
+ curvePathWithoutTangents(
|
|
|
+ keyframes: IAnimationKey[],
|
|
|
+ data: string,
|
|
|
+ middle: number,
|
|
|
+ type: number,
|
|
|
+ coordinate: number,
|
|
|
+ animationName: string
|
|
|
+ ) {
|
|
|
const updatedKeyframes = this.calculateLinearTangents(keyframes);
|
|
|
return this.curvePathWithTangents(updatedKeyframes, data, middle, type, coordinate, animationName);
|
|
|
}
|
|
@@ -1519,7 +1599,14 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
* @param coordinate (x, y, z) value
|
|
|
* @param animationName The animation name to generate the curve id
|
|
|
*/
|
|
|
- curvePathWithTangents(keyframes: IAnimationKey[], data: string, middle: number, type: number, coordinate: number, animationName: string) {
|
|
|
+ curvePathWithTangents(
|
|
|
+ keyframes: IAnimationKey[],
|
|
|
+ data: string,
|
|
|
+ middle: number,
|
|
|
+ type: number,
|
|
|
+ coordinate: number,
|
|
|
+ animationName: string
|
|
|
+ ) {
|
|
|
keyframes.forEach((key, i) => {
|
|
|
// Create a unique id for curve
|
|
|
const curveId = this.encodeCurveId(animationName, i);
|
|
@@ -1574,8 +1661,14 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
}
|
|
|
|
|
|
// Calculate the control points from the specified tangent values
|
|
|
- var inT = key.inTangent === null || key.inTangent === undefined ? defaultTangent : this.getValueAsArray(type, key.inTangent)[coordinate];
|
|
|
- var outT = key.outTangent === null || key.outTangent === undefined ? defaultTangent : this.getValueAsArray(type, key.outTangent)[coordinate];
|
|
|
+ var inT =
|
|
|
+ key.inTangent === null || key.inTangent === undefined
|
|
|
+ ? defaultTangent
|
|
|
+ : this.getValueAsArray(type, key.inTangent)[coordinate];
|
|
|
+ var outT =
|
|
|
+ key.outTangent === null || key.outTangent === undefined
|
|
|
+ ? defaultTangent
|
|
|
+ : this.getValueAsArray(type, key.outTangent)[coordinate];
|
|
|
|
|
|
defaultWeight = 1 * this._pixelFrameUnit; // update based on control points
|
|
|
|
|
@@ -1598,7 +1691,10 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
// Define each point of the cuvre and the value on the SVG Path.
|
|
|
if (i === 0) {
|
|
|
svgKeyframe = {
|
|
|
- keyframePoint: new Vector2(key.frame * this._pixelFrameUnit, this._heightScale - keyframe_valueAsArray * middle),
|
|
|
+ keyframePoint: new Vector2(
|
|
|
+ key.frame * this._pixelFrameUnit,
|
|
|
+ this._heightScale - keyframe_valueAsArray * middle
|
|
|
+ ),
|
|
|
rightControlPoint: outTangent,
|
|
|
leftControlPoint: null,
|
|
|
id: curveId,
|
|
@@ -1613,7 +1709,10 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
}
|
|
|
} else {
|
|
|
svgKeyframe = {
|
|
|
- keyframePoint: new Vector2(key.frame * this._pixelFrameUnit, this._heightScale - keyframe_valueAsArray * middle),
|
|
|
+ keyframePoint: new Vector2(
|
|
|
+ key.frame * this._pixelFrameUnit,
|
|
|
+ this._heightScale - keyframe_valueAsArray * middle
|
|
|
+ ),
|
|
|
rightControlPoint: outTangent,
|
|
|
leftControlPoint: inTangent,
|
|
|
id: curveId,
|
|
@@ -1714,7 +1813,14 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
let intermediatePoint75 = new Vector2((pointB.x - pointA.x) * v + pointA.x, yInt75);
|
|
|
|
|
|
// Gets the four control points of bezier curve
|
|
|
- let controlPoints = this.interpolateControlPoints(pointA, intermediatePoint25, u, intermediatePoint75, v, pointB);
|
|
|
+ let controlPoints = this.interpolateControlPoints(
|
|
|
+ pointA,
|
|
|
+ intermediatePoint25,
|
|
|
+ u,
|
|
|
+ intermediatePoint75,
|
|
|
+ v,
|
|
|
+ pointB
|
|
|
+ );
|
|
|
|
|
|
if (controlPoints !== undefined) {
|
|
|
this.setKeyframePoint(controlPoints, i, keyframes.length);
|
|
@@ -1769,7 +1875,14 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
* @param v distance between p0 and p3 as percentage to affect p2
|
|
|
* @param p3 finish point of curve
|
|
|
*/
|
|
|
- interpolateControlPoints(p0: Vector2, p1: Vector2, u: number, p2: Vector2, v: number, p3: Vector2): Vector2[] | undefined {
|
|
|
+ interpolateControlPoints(
|
|
|
+ p0: Vector2,
|
|
|
+ p1: Vector2,
|
|
|
+ u: number,
|
|
|
+ p2: Vector2,
|
|
|
+ v: number,
|
|
|
+ p3: Vector2
|
|
|
+ ): Vector2[] | undefined {
|
|
|
let a = 0.0;
|
|
|
let b = 0.0;
|
|
|
let c = 0.0;
|
|
@@ -1921,7 +2034,12 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
if (keys.length !== 0) {
|
|
|
const firstFrame = keys[0].frame;
|
|
|
const LastFrame = this.state.selected.getHighestFrame();
|
|
|
- this._mainAnimatable = this.props.scene.beginAnimation(target, firstFrame, LastFrame, this.state.isLooping);
|
|
|
+ this._mainAnimatable = this.props.scene.beginAnimation(
|
|
|
+ target,
|
|
|
+ firstFrame,
|
|
|
+ LastFrame,
|
|
|
+ this.state.isLooping
|
|
|
+ );
|
|
|
this._mainAnimatable.stop();
|
|
|
}
|
|
|
}
|
|
@@ -1995,7 +2113,9 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
if (animation) {
|
|
|
const hasKeyframe = animation.getKeys().find((x) => x.frame === frame);
|
|
|
const currentValue = this.calculateCurrentPointInCurve(frame);
|
|
|
- const value = hasKeyframe ? this.getValueAsArray(animation.dataType, hasKeyframe.value)[this.state.selectedCoordinate] : currentValue ?? 0;
|
|
|
+ const value = hasKeyframe
|
|
|
+ ? this.getValueAsArray(animation.dataType, hasKeyframe.value)[this.state.selectedCoordinate]
|
|
|
+ : currentValue ?? 0;
|
|
|
const keyframe: IAnimationKey = { frame, value };
|
|
|
this.setState(
|
|
|
{
|
|
@@ -2018,7 +2138,10 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
* @param frame the frame to calculate its current value on the curve
|
|
|
*/
|
|
|
calculateCurrentPointInCurve = (frame: number): number | undefined => {
|
|
|
- if (this.state.selectedPathData !== undefined && this.state.selectedPathData[this.state.selectedCoordinate] !== undefined) {
|
|
|
+ if (
|
|
|
+ this.state.selectedPathData !== undefined &&
|
|
|
+ this.state.selectedPathData[this.state.selectedCoordinate] !== undefined
|
|
|
+ ) {
|
|
|
const selectedCurve = this.state.selectedPathData[this.state.selectedCoordinate].domCurve.current;
|
|
|
if (selectedCurve !== null) {
|
|
|
const curveLength = selectedCurve.getTotalLength();
|
|
@@ -2027,7 +2150,10 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
const currentPointInCurve = selectedCurve.getPointAtLength(frameValue);
|
|
|
const middle = this._heightScale / 2;
|
|
|
|
|
|
- const offset = (currentPointInCurve?.y * this._heightScale - this._heightScale ** 2 / 2) / middle / this._heightScale;
|
|
|
+ const offset =
|
|
|
+ (currentPointInCurve?.y * this._heightScale - this._heightScale ** 2 / 2) /
|
|
|
+ middle /
|
|
|
+ this._heightScale;
|
|
|
|
|
|
const unit = Math.sign(offset);
|
|
|
const currentValue = unit === -1 ? Math.abs(offset + unit) : unit - offset;
|
|
@@ -2060,7 +2186,9 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
if (keyframe.value === null) {
|
|
|
value = this.state.panningY;
|
|
|
} else {
|
|
|
- value = this.getValueAsArray(this.state.selected.dataType, keyframe.value)[this.state.selectedCoordinate];
|
|
|
+ value = this.getValueAsArray(this.state.selected.dataType, keyframe.value)[
|
|
|
+ this.state.selectedCoordinate
|
|
|
+ ];
|
|
|
}
|
|
|
|
|
|
const valueScale = this._heightScale / this._scaleFactor;
|
|
@@ -2141,10 +2269,20 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
let firstFrame = keys[0].frame;
|
|
|
let LastFrame = this.state.selected.getHighestFrame();
|
|
|
if (direction === 1) {
|
|
|
- this._mainAnimatable = this.props.scene.beginAnimation(target, firstFrame, LastFrame, this.state.isLooping);
|
|
|
+ this._mainAnimatable = this.props.scene.beginAnimation(
|
|
|
+ target,
|
|
|
+ firstFrame,
|
|
|
+ LastFrame,
|
|
|
+ this.state.isLooping
|
|
|
+ );
|
|
|
}
|
|
|
if (direction === -1) {
|
|
|
- this._mainAnimatable = this.props.scene.beginAnimation(target, LastFrame, firstFrame, this.state.isLooping);
|
|
|
+ this._mainAnimatable = this.props.scene.beginAnimation(
|
|
|
+ target,
|
|
|
+ LastFrame,
|
|
|
+ firstFrame,
|
|
|
+ this.state.isLooping
|
|
|
+ );
|
|
|
}
|
|
|
if (!this.state.isLooping && this._mainAnimatable) {
|
|
|
this._mainAnimatable.onAnimationEnd = () => this.playPause(0);
|
|
@@ -2268,7 +2406,11 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
firstFrame = keysCopy[0].frame;
|
|
|
lastFrame = keysCopy[keysCopy.length - 1].frame;
|
|
|
// If not selected get all keyframes
|
|
|
- keysCopy.sort((a, b) => this.getValueAsArray(animation.dataType, a.value)[coordinate] - this.getValueAsArray(animation.dataType, b.value)[coordinate]);
|
|
|
+ keysCopy.sort(
|
|
|
+ (a, b) =>
|
|
|
+ this.getValueAsArray(animation.dataType, a.value)[coordinate] -
|
|
|
+ this.getValueAsArray(animation.dataType, b.value)[coordinate]
|
|
|
+ );
|
|
|
lowest = keysCopy[0];
|
|
|
highest = keysCopy[keysCopy.length - 1];
|
|
|
keysCopy.sort((a, b) => a.frame - b.frame);
|
|
@@ -2302,7 +2444,11 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
}
|
|
|
|
|
|
// Sort to get lowest and highest values for scale
|
|
|
- keysInRange.sort((a, b) => this.getValueAsArray(animation.dataType, a.value)[coordinate] - this.getValueAsArray(animation.dataType, b.value)[coordinate]);
|
|
|
+ keysInRange.sort(
|
|
|
+ (a, b) =>
|
|
|
+ this.getValueAsArray(animation.dataType, a.value)[coordinate] -
|
|
|
+ this.getValueAsArray(animation.dataType, b.value)[coordinate]
|
|
|
+ );
|
|
|
|
|
|
lowest = keysInRange[0];
|
|
|
highest = keysInRange[keysInRange.length - 1];
|
|
@@ -2311,7 +2457,9 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
}
|
|
|
|
|
|
// calculate scale...
|
|
|
- const scale = this.getValueAsArray(animation.dataType, highest?.value)[coordinate] - this.getValueAsArray(animation.dataType, lowest?.value)[coordinate];
|
|
|
+ const scale =
|
|
|
+ this.getValueAsArray(animation.dataType, highest?.value)[coordinate] -
|
|
|
+ this.getValueAsArray(animation.dataType, lowest?.value)[coordinate];
|
|
|
|
|
|
// Scale Frames to fit width of canvas
|
|
|
// reposition canvas to middle value of scale
|
|
@@ -2404,7 +2552,11 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
render() {
|
|
|
return (
|
|
|
<div ref={this._editor} id="animation-curve-editor">
|
|
|
- <Notification message={this.state.notification} open={this.state.notification !== "" ? true : false} close={this.clearNotification} />
|
|
|
+ <Notification
|
|
|
+ message={this.state.notification}
|
|
|
+ open={this.state.notification !== "" ? true : false}
|
|
|
+ close={this.clearNotification}
|
|
|
+ />
|
|
|
<GraphActionsBar
|
|
|
setKeyframeValue={this.setKeyframeValueFromInput}
|
|
|
enabled={this.state.selected === null || this.state.selected === undefined ? false : true}
|
|
@@ -2481,7 +2633,15 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
})}
|
|
|
|
|
|
{this.setValueLines().map((line, i) => {
|
|
|
- return <line key={i} x1={-((this.state.frameAxisLength.length * 10) / 2)} y1={line.value} x2={this.state.frameAxisLength.length * 10} y2={line.value}></line>;
|
|
|
+ return (
|
|
|
+ <line
|
|
|
+ key={i}
|
|
|
+ x1={-((this.state.frameAxisLength.length * 10) / 2)}
|
|
|
+ y1={line.value}
|
|
|
+ x2={this.state.frameAxisLength.length * 10}
|
|
|
+ y2={line.value}
|
|
|
+ ></line>
|
|
|
+ );
|
|
|
})}
|
|
|
|
|
|
{/* Multiple Curves */}
|
|
@@ -2516,16 +2676,36 @@ export class AnimationCurveEditorComponent extends React.Component<IAnimationCur
|
|
|
/>
|
|
|
))}
|
|
|
|
|
|
- <rect onClick={(e) => this.moveFrameTo(e)} x={-((this.state.frameAxisLength.length * 10) / 2)} y={91 + this.state.panningY + "%"} width={this.state.frameAxisLength.length * 10} height="9%" fill="#222" style={{ cursor: "pointer" }}></rect>
|
|
|
+ <rect
|
|
|
+ onClick={(e) => this.moveFrameTo(e)}
|
|
|
+ x={-((this.state.frameAxisLength.length * 10) / 2)}
|
|
|
+ y={91 + this.state.panningY + "%"}
|
|
|
+ width={this.state.frameAxisLength.length * 10}
|
|
|
+ height="9%"
|
|
|
+ fill="#222"
|
|
|
+ style={{ cursor: "pointer" }}
|
|
|
+ ></rect>
|
|
|
|
|
|
{this.state.frameAxisLength.map((f, i) => (
|
|
|
<svg key={i} x="0" y={96 + this.state.panningY + "%"} className="frame-contain">
|
|
|
- <text x={f.value} y="1px" dx="2px" style={{ fontSize: `${0.2 * this.state.scale}em` }}>
|
|
|
+ <text
|
|
|
+ x={f.value}
|
|
|
+ y="1px"
|
|
|
+ dx="2px"
|
|
|
+ style={{ fontSize: `${0.2 * this.state.scale}em` }}
|
|
|
+ >
|
|
|
{Math.round((f.label * 10) / this._pixelFrameUnit)}
|
|
|
</text>
|
|
|
<line x1={f.value} y1="0" x2={f.value} y2="5%"></line>
|
|
|
|
|
|
- {f.value % this.state.fps === 0 && f.value !== 0 ? <line x1={f.value * this._pixelFrameUnit} y1="-100%" x2={f.value * this._pixelFrameUnit} y2="5%"></line> : null}
|
|
|
+ {f.value % this.state.fps === 0 && f.value !== 0 ? (
|
|
|
+ <line
|
|
|
+ x1={f.value * this._pixelFrameUnit}
|
|
|
+ y1="-100%"
|
|
|
+ x2={f.value * this._pixelFrameUnit}
|
|
|
+ y2="5%"
|
|
|
+ ></line>
|
|
|
+ ) : null}
|
|
|
</svg>
|
|
|
))}
|
|
|
|