@visactor/vrender-animate
Version:
This module provides a graph-based animation system for VRender.
41 lines (37 loc) • 2.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: !0
}), exports.RotateBySphereAnimate = void 0;
const vutils_1 = require("@visactor/vutils"), custom_animate_1 = require("./custom-animate"), transient_1 = require("./transient");
class RotateBySphereAnimate extends custom_animate_1.ACustomAnimate {
onBind() {
super.onBind(), this.propKeys = [ "x", "y", "z", "alpha", "zIndex" ];
}
onFirstRun() {
super.onFirstRun(), this.target.applyFinalAttributeToAttribute();
}
onStart() {
var _a, _b;
super.onStart();
const {center: center, r: r} = "function" == typeof this.params ? this.params() : this.params, source = null !== (_a = this.target.getFinalAttribute()) && void 0 !== _a ? _a : this.target.attribute, startX = source.x, startY = source.y, startZ = null !== (_b = source.z) && void 0 !== _b ? _b : 0, phi = Math.acos((startY - center.y) / r);
let theta = Math.acos((startX - center.x) / r / Math.sin(phi));
startZ - center.z < 0 && (theta = vutils_1.pi2 - theta), this.theta = theta, this.phi = phi;
}
onEnd() {}
onUpdate(end, ratio, out) {
if (null == this.phi || null == this.theta) return;
const {center: center, r: r, cb: cb} = "function" == typeof this.params ? this.params() : this.params, deltaAngle = 2 * Math.PI * ratio, theta = this.theta + deltaAngle, phi = this.phi, x = r * Math.sin(phi) * Math.cos(theta) + center.x, y = r * Math.cos(phi) + center.y, z = r * Math.sin(phi) * Math.sin(theta) + center.z;
let alpha = theta + vutils_1.pi / 2;
for (;alpha > vutils_1.pi2; ) alpha -= vutils_1.pi2;
alpha = vutils_1.pi2 - alpha, (0, transient_1.applyAnimationFrameAttributes)(this.target, {
x: x,
y: y,
z: z,
alpha: alpha,
zIndex: -1e4 * z
}), this.target.addUpdatePositionTag(), this.target.addUpdateShapeAndBoundsTag(),
cb && cb(out);
}
}
exports.RotateBySphereAnimate = RotateBySphereAnimate;
//# sourceMappingURL=sphere.js.map