import * as THREE from 'three' ; import { SimulatorBase } from './SimulatorBase' ; import { SimulationFrameVector } from './SimulationFrameVector' ; import { springV } from '../../core/FunctionLibrary' ; export class VectorSpringSimulator extends SimulatorBase { public position : THREE . Vector3 ; public velocity : THREE . Vector3 ; public target : THREE . Vector3 ; public cache : SimulationFrameVector [ ] ; constructor ( fps , mass , damping ) { super ( fps , mass , damping ) ; this . init ( ) ; } public init ( ) { this . position = new THREE . Vector3 ( ) ; this . velocity = new THREE . Vector3 ( ) ; this . target = new THREE . Vector3 ( ) ; this . cache = [ ] ; for ( let i = 0 ; i < 2 ; i ++ ) { this . cache . push ( new SimulationFrameVector ( new THREE . Vector3 ( ) , new THREE . Vector3 ( ) ) ) ; } } param { number } timeStep public simulate ( timeStep ) { this . generateFrames ( timeStep ) ; this . position . lerpVectors ( this . cache [ 0 ] . position , this . cache [ 1 ] . position , this . offset / this . frameTime ) ; this . velocity . lerpVectors ( this . cache [ 0 ] . velocity , this . cache [ 1 ] . velocity , this . offset / this . frameTime ) ; } /**
     * Gets another simulation frame
     */ public getFrame ( isLastFrame ) { let newSpring = new SimulationFrameVector ( this . lastFrame ( ) . position . clone ( ) , this . lastFrame ( ) . velocity . clone ( ) ) ; springV ( newSpring . position , this . target , newSpring . velocity , this . mass , this . damping ) ; return newSpring ; } }