UNPKG

@pmndrs/handle

Version:

framework agnostic expandable handle implementation for threejs

82 lines (81 loc) 2.1 kB
import { Euler } from 'three'; class SubtractedHandleTransformStateImpl { t1; t2; _position; _quaternion; _rotation; _scale; constructor(t1, t2) { this.t1 = t1; this.t2 = t2; } get time() { return this.t1.time - this.t2.time; } get position() { return (this._position ??= this.t1.position.clone().sub(this.t2.position)); } get quaternion() { return (this._quaternion ??= this.t2.quaternion.clone().invert().premultiply(this.t1.quaternion)); } get rotation() { return (this._rotation ??= new Euler().setFromQuaternion(this.quaternion)); } get scale() { return (this._scale ??= this.t1.scale.clone().sub(this.t2.scale)); } } export class HandleStateImpl { cancel; previous; memo; event; //will be set by start before the first read initial; current; first; last; //cache _delta; _offset; constructor(cancel) { this.cancel = cancel; } start(event, current) { this.event = event; this.previous = undefined; this.current = current; this.initial = current; this.first = true; this.last = false; this.memo = undefined; this._delta = undefined; this._offset = undefined; } update(event, current) { this.event = event; this.previous = this.current; this.current = current; this.first = false; this.last = false; this._delta = undefined; this._offset = undefined; } end(event) { this.event = event; this.first = false; this.last = true; this._delta = undefined; this._offset = undefined; } get delta() { if (this.previous == null) { return undefined; } return (this._delta ??= new SubtractedHandleTransformStateImpl(this.current, this.previous)); } get offset() { return (this._offset ??= new SubtractedHandleTransformStateImpl(this.current, this.initial)); } }