@@ -24,7 +24,6 @@ export class WindParticlesComputing {
2424 updatePosition : CustomPrimitive ;
2525 postProcessingPosition : CustomPrimitive ;
2626 } ;
27- private bounds : WindData [ 'bounds' ] ;
2827 windData : Required < WindData > ;
2928 private frameRateMonitor : FrameRateMonitor ;
3029 private frameRate : number = 60 ;
@@ -34,7 +33,6 @@ export class WindParticlesComputing {
3433 this . context = context ;
3534 this . options = options ;
3635 this . viewerParameters = viewerParameters ;
37- this . bounds = windData . bounds ;
3836 this . windData = windData ;
3937
4038 this . frameRateMonitor = new FrameRateMonitor ( {
@@ -49,27 +47,20 @@ export class WindParticlesComputing {
4947 }
5048
5149 private initFrameRate ( ) {
52- let lastUpdate = performance . now ( ) ;
53- const updateInterval = 1000 ; // Update every 1000ms (1 second)
54-
5550 const updateFrameRate = ( ) => {
56- const currentTime = performance . now ( ) ;
57- const deltaTime = currentTime - lastUpdate ;
58-
59- // Only update frame rate once per second
60- if ( deltaTime >= updateInterval ) {
61- if ( this . frameRateMonitor . lastFramesPerSecond ) {
62- this . frameRate = this . frameRateMonitor . lastFramesPerSecond ;
63- this . frameRateAdjustment = 60 / Math . max ( this . frameRate , 1 ) ;
64- }
65- lastUpdate = currentTime ;
51+ // avoid update frame rate when frame rate is too low
52+ if ( this . frameRateMonitor . lastFramesPerSecond > 50 ) {
53+ this . frameRate = this . frameRateMonitor . lastFramesPerSecond ;
54+ this . frameRateAdjustment = 60 / Math . max ( this . frameRate , 1 ) ;
6655 }
56+ }
6757
68- requestAnimationFrame ( updateFrameRate ) ;
69- } ;
70-
58+ // Initial frame rate calculation
7159 updateFrameRate ( ) ;
7260
61+ // Use setInterval instead of requestAnimationFrame
62+ const intervalId = setInterval ( updateFrameRate , 1000 ) ;
63+
7364 // Monitor frame rate changes
7465 this . frameRateMonitor . lowFrameRate . addEventListener ( ( scene , frameRate ) => {
7566 console . warn ( `Low frame rate detected: ${ frameRate } FPS` ) ;
@@ -78,6 +69,13 @@ export class WindParticlesComputing {
7869 this . frameRateMonitor . nominalFrameRate . addEventListener ( ( scene , frameRate ) => {
7970 console . log ( `Frame rate returned to normal: ${ frameRate } FPS` ) ;
8071 } ) ;
72+
73+ // Add cleanup method to destroy
74+ const originalDestroy = this . destroy . bind ( this ) ;
75+ this . destroy = ( ) => {
76+ clearInterval ( intervalId ) ;
77+ originalDestroy ( ) ;
78+ } ;
8179 }
8280
8381 createWindTextures ( ) {
@@ -141,14 +139,6 @@ export class WindParticlesComputing {
141139 }
142140
143141 createComputingPrimitives ( ) {
144- const dimension = new Cartesian2 ( this . windData . width , this . windData . height ) ;
145- const minimum = new Cartesian2 ( this . bounds . west , this . bounds . south ) ;
146- const maximum = new Cartesian2 ( this . bounds . east , this . bounds . north ) ;
147- const interval = new Cartesian2 (
148- ( maximum . x - minimum . x ) / ( dimension . x - 1 ) ,
149- ( maximum . y - minimum . y ) / ( dimension . y - 1 )
150- ) ;
151-
152142 this . primitives = {
153143 calculateSpeed : new CustomPrimitive ( {
154144 commandType : 'Compute' ,
@@ -162,10 +152,9 @@ export class WindParticlesComputing {
162152 speedScaleFactor : ( ) => {
163153 return ( this . viewerParameters . pixelSize + 50 ) * this . options . speedFactor * this . frameRateAdjustment ;
164154 } ,
165- dimension : ( ) => dimension ,
166- minimum : ( ) => minimum ,
167- maximum : ( ) => maximum ,
168- interval : ( ) => interval ,
155+ dimension : ( ) => new Cartesian2 ( this . windData . width , this . windData . height ) ,
156+ minimum : ( ) => new Cartesian2 ( this . windData . bounds . west , this . windData . bounds . south ) ,
157+ maximum : ( ) => new Cartesian2 ( this . windData . bounds . east , this . windData . bounds . north ) ,
169158 } ,
170159 fragmentShaderSource : ShaderManager . getCalculateSpeedShader ( ) ,
171160 outputTexture : this . particlesTextures . particlesSpeed ,
0 commit comments