import { vec3 } from 'gl-matrix' ; import EmittedObject from '../../emittedobject' ; import RibbonEmitterObject from './ribbonemitterobject' ; import MdxModelInstance from './modelinstance' ; import RibbonEmitter from './ribbonemitter' ; const belowHeap = vec3 . create ( ) ; const aboveHeap = vec3 . create ( ) ; const colorHeap = new Float32Array ( 3 ) ; const alphaHeap = new Float32Array ( 1 ) ; const slotHeap = new Uint32Array ( 1 ) ; /**
 * A ribbon.
 */ export default class Ribbon extends EmittedObject { vertices = new Float32Array ( 6 ) ; color = new Uint8Array ( 4 ) ; slot = 0 ; prev : Ribbon | null = null ; next : Ribbon | null = null ; bind ( ) { const emitter = < RibbonEmitter > this . emitter ; const instance = < MdxModelInstance > emitter . instance ; const sequence = instance . sequence ; const frame = instance . frame ; const counter = instance . counter ; const emitterObject = < RibbonEmitterObject > emitter . emitterObject ; const node = instance . nodes [ emitterObject . index ] ; const [ x , y , z ] = node . pivot ; const worldMatrix = node . worldMatrix ; const vertices = this . vertices ; this . health = emitter . emitterObject . lifeSpan ; emitterObject . getHeightBelow ( < Float32Array > belowHeap , sequence , frame , counter ) ; emitterObject . getHeightAbove ( < Float32Array > aboveHeap , sequence , frame , counter ) ; belowHeap [ 1 ] = y - belowHeap [ 0 ] ; belowHeap [ 0 ] = x ; belowHeap [ 2 ] = z ; aboveHeap [ 1 ] = y + aboveHeap [ 0 ] ; aboveHeap [ 0 ] = x ; aboveHeap [ 2 ] = z ; vec3 . transformMat4 ( belowHeap , belowHeap , worldMatrix ) ; vec3 . transformMat4 ( aboveHeap , aboveHeap , worldMatrix ) ; vertices [ 0 ] = aboveHeap [ 0 ] ; vertices [ 1 ] = aboveHeap [ 1 ] ; vertices [ 2 ] = aboveHeap [ 2 ] ; vertices [ 3 ] = belowHeap [ 0 ] ; vertices [ 4 ] = belowHeap [ 1 ] ; vertices [ 5 ] = belowHeap [ 2 ] ; } update ( dt ) { this . health -= dt ; if ( this . health > 0 ) { const emitter = < RibbonEmitter > this . emitter ; const instance = < MdxModelInstance > emitter . instance ; const sequence = instance . sequence ; const frame = instance . frame ; const counter = instance . counter ; const emitterObject = < RibbonEmitterObject > emitter . emitterObject ; const color = this . color ; const vertices = this . vertices ; const gravity = emitterObject . gravity * dt * dt ; emitterObject . getColor ( colorHeap , sequence , frame , counter ) ; emitterObject . getAlpha ( alphaHeap , sequence , frame , counter ) ; emitterObject . getTextureSlot ( slotHeap , sequence , frame , counter ) ; vertices [ 1 ] -= gravity ; vertices [ 4 ] -= gravity ; color [ 0 ] = colorHeap [ 0 ] * 255 ; color [ 1 ] = colorHeap [ 1 ] * 255 ; color [ 2 ] = colorHeap [ 2 ] * 255 ; color [ 3 ] = alphaHeap [ 0 ] * 255 ; this . slot = slotHeap [ 0 ] ; } } }