import { Interpolator, Vector3 } from '@zephyr3d/base';
import { AnimationTrack } from './animationtrack.js';

/**
 * Scale animation track
 * @public
 */ class NodeScaleTrack extends AnimationTrack {
    _state;
    _interpolator;
    constructor(modeOrInterpolator, keyFramesOrEmbedded, embedded){
        if (modeOrInterpolator === undefined) {
            super(false);
        } else if (modeOrInterpolator instanceof Interpolator) {
            if (modeOrInterpolator.target !== 'vec3') {
                throw new Error(`ScaleTrack(): interpolator target must be 'vec3'`);
            }
            super(keyFramesOrEmbedded ?? false);
            this._interpolator = modeOrInterpolator;
        } else {
            const keyFrames = keyFramesOrEmbedded;
            const inputs = new Float32Array(keyFrames.map((val)=>val.time));
            const outputs = new Float32Array(keyFrames.length * 3);
            for(let i = 0; i < keyFrames.length; i++){
                outputs[i * 3 + 0] = keyFrames[i].value.x;
                outputs[i * 3 + 1] = keyFrames[i].value.y;
                outputs[i * 3 + 2] = keyFrames[i].value.z;
            }
            super(embedded ?? false);
            this._interpolator = new Interpolator(modeOrInterpolator, 'vec3', inputs, outputs);
        }
        this._state = new Vector3();
    }
    get interpolator() {
        return this._interpolator;
    }
    set interpolator(interp) {
        if (interp && interp.target !== 'vec3') {
            throw new Error(`ScaleTrack(): interpolator target must be 'vec3'`);
        }
        this._interpolator = interp ?? null;
    }
    /** {@inheritDoc AnimationTrack.calculateState} */ calculateState(target, currentTime) {
        this._interpolator.interpolate(currentTime, this._state);
        return this._state;
    }
    /** {@inheritDoc AnimationTrack.applyState} */ applyState(node, state) {
        node.scale.set(state);
    }
    /** {@inheritDoc AnimationTrack.mixState} */ mixState(a, b, t) {
        return new Vector3(a.x + t * (b.x - a.x), a.y + t * (b.y - a.y), a.z + t * (b.z - a.z));
    }
    /** {@inheritDoc AnimationTrack.getBlendId} */ getBlendId() {
        return 'node-scale';
    }
    /** {@inheritDoc AnimationTrack.getDuration} */ getDuration() {
        return this._interpolator.maxTime;
    }
}

export { NodeScaleTrack };
//# sourceMappingURL=scaletrack.js.map
