UNPKG

@visactor/vrender-animate

Version:

This module provides a graph-based animation system for VRender.

37 lines (34 loc) 1.85 kB
import { pi, pi2 } from "@visactor/vutils"; import { ACustomAnimate } from "./custom-animate"; import { applyAnimationFrameAttributes } from "./transient"; export class RotateBySphereAnimate extends 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 = 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 + pi / 2; for (;alpha > pi2; ) alpha -= pi2; alpha = pi2 - alpha, applyAnimationFrameAttributes(this.target, { x: x, y: y, z: z, alpha: alpha, zIndex: -1e4 * z }), this.target.addUpdatePositionTag(), this.target.addUpdateShapeAndBoundsTag(), cb && cb(out); } } //# sourceMappingURL=sphere.js.map