@@ -237,7 +237,7 @@ export class ParticleGenerator {
237
237
/**
238
238
* @internal
239
239
*/
240
- _emit ( time : number , count : number ) : void {
240
+ _emit ( playTime : number , count : number ) : void {
241
241
if ( this . emission . enabled ) {
242
242
// Wait the existing particles to be retired
243
243
const notRetireParticleCount = this . _getNotRetiredParticleCount ( ) ;
@@ -250,15 +250,15 @@ export class ParticleGenerator {
250
250
const shape = this . emission . shape ;
251
251
for ( let i = 0 ; i < count ; i ++ ) {
252
252
if ( shape ?. enabled ) {
253
- shape . _generatePositionAndDirection ( this . emission . _shapeRand , time , position , direction ) ;
253
+ shape . _generatePositionAndDirection ( this . emission . _shapeRand , playTime , position , direction ) ;
254
254
const positionScale = this . main . _getPositionScale ( ) ;
255
255
position . multiply ( positionScale ) ;
256
256
direction . normalize ( ) . multiply ( positionScale ) ;
257
257
} else {
258
258
position . set ( 0 , 0 , 0 ) ;
259
259
direction . set ( 0 , 0 , - 1 ) ;
260
260
}
261
- this . _addNewParticle ( position , direction , transform , time ) ;
261
+ this . _addNewParticle ( position , direction , transform , playTime ) ;
262
262
}
263
263
}
264
264
}
@@ -669,7 +669,7 @@ export class ParticleGenerator {
669
669
}
670
670
}
671
671
672
- private _addNewParticle ( position : Vector3 , direction : Vector3 , transform : Transform , time : number ) : void {
672
+ private _addNewParticle ( position : Vector3 , direction : Vector3 , transform : Transform , playTime : number ) : void {
673
673
const firstFreeElement = this . _firstFreeElement ;
674
674
let nextFreeElement = firstFreeElement + 1 ;
675
675
if ( nextFreeElement >= this . _currentParticleCount ) {
@@ -711,9 +711,7 @@ export class ParticleGenerator {
711
711
const offset = firstFreeElement * ParticleBufferUtils . instanceVertexFloatStride ;
712
712
713
713
// Position
714
- instanceVertices [ offset ] = position . x ;
715
- instanceVertices [ offset + 1 ] = position . y ;
716
- instanceVertices [ offset + 2 ] = position . z ;
714
+ position . copyToArray ( instanceVertices , offset ) ;
717
715
718
716
// Start life time
719
717
instanceVertices [ offset + ParticleBufferUtils . startLifeTimeOffset ] = main . startLifetime . evaluate (
@@ -722,12 +720,10 @@ export class ParticleGenerator {
722
720
) ;
723
721
724
722
// Direction
725
- instanceVertices [ offset + 4 ] = direction . x ;
726
- instanceVertices [ offset + 5 ] = direction . y ;
727
- instanceVertices [ offset + 6 ] = direction . z ;
723
+ direction . copyToArray ( instanceVertices , offset + 4 ) ;
728
724
729
725
// Time
730
- instanceVertices [ offset + ParticleBufferUtils . timeOffset ] = time ;
726
+ instanceVertices [ offset + ParticleBufferUtils . timeOffset ] = playTime ;
731
727
732
728
// Color
733
729
const startColor = ParticleGenerator . _tempColor0 ;
@@ -736,19 +732,19 @@ export class ParticleGenerator {
736
732
startColor . toLinear ( startColor ) ;
737
733
}
738
734
739
- instanceVertices [ offset + 8 ] = startColor . r ;
740
- instanceVertices [ offset + 9 ] = startColor . g ;
741
- instanceVertices [ offset + 10 ] = startColor . b ;
742
- instanceVertices [ offset + 11 ] = startColor . a ;
735
+ startColor . copyToArray ( instanceVertices , offset + 8 ) ;
736
+
737
+ const duration = this . main . duration ;
738
+ const normalizedEmitAge = ( playTime % duration ) / duration ;
743
739
744
740
// Start size
745
741
const startSizeRand = main . _startSizeRand ;
746
742
if ( main . startSize3D ) {
747
- instanceVertices [ offset + 12 ] = main . startSizeX . evaluate ( undefined , startSizeRand . random ( ) ) ;
748
- instanceVertices [ offset + 13 ] = main . startSizeY . evaluate ( undefined , startSizeRand . random ( ) ) ;
749
- instanceVertices [ offset + 14 ] = main . startSizeZ . evaluate ( undefined , startSizeRand . random ( ) ) ;
743
+ instanceVertices [ offset + 12 ] = main . startSizeX . evaluate ( normalizedEmitAge , startSizeRand . random ( ) ) ;
744
+ instanceVertices [ offset + 13 ] = main . startSizeY . evaluate ( normalizedEmitAge , startSizeRand . random ( ) ) ;
745
+ instanceVertices [ offset + 14 ] = main . startSizeZ . evaluate ( normalizedEmitAge , startSizeRand . random ( ) ) ;
750
746
} else {
751
- const size = main . startSize . evaluate ( undefined , startSizeRand . random ( ) ) ;
747
+ const size = main . startSize . evaluate ( normalizedEmitAge , startSizeRand . random ( ) ) ;
752
748
instanceVertices [ offset + 12 ] = size ;
753
749
instanceVertices [ offset + 13 ] = size ;
754
750
instanceVertices [ offset + 14 ] = size ;
@@ -815,15 +811,10 @@ export class ParticleGenerator {
815
811
816
812
if ( this . main . simulationSpace === ParticleSimulationSpace . World ) {
817
813
// Simulation world position
818
- instanceVertices [ offset + 27 ] = pos . x ;
819
- instanceVertices [ offset + 28 ] = pos . y ;
820
- instanceVertices [ offset + 29 ] = pos . z ;
814
+ pos . copyToArray ( instanceVertices , offset + 27 ) ;
821
815
822
816
// Simulation world position
823
- instanceVertices [ offset + 30 ] = rot . x ;
824
- instanceVertices [ offset + 31 ] = rot . y ;
825
- instanceVertices [ offset + 32 ] = rot . z ;
826
- instanceVertices [ offset + 33 ] = rot . w ;
817
+ rot . copyToArray ( instanceVertices , offset + 30 ) ;
827
818
}
828
819
829
820
// Simulation UV
0 commit comments