@@ -24,7 +24,6 @@ export class WindParticlesComputing {
24
24
updatePosition : CustomPrimitive ;
25
25
postProcessingPosition : CustomPrimitive ;
26
26
} ;
27
- private bounds : WindData [ 'bounds' ] ;
28
27
windData : Required < WindData > ;
29
28
private frameRateMonitor : FrameRateMonitor ;
30
29
private frameRate : number = 60 ;
@@ -34,7 +33,6 @@ export class WindParticlesComputing {
34
33
this . context = context ;
35
34
this . options = options ;
36
35
this . viewerParameters = viewerParameters ;
37
- this . bounds = windData . bounds ;
38
36
this . windData = windData ;
39
37
40
38
this . frameRateMonitor = new FrameRateMonitor ( {
@@ -49,27 +47,20 @@ export class WindParticlesComputing {
49
47
}
50
48
51
49
private initFrameRate ( ) {
52
- let lastUpdate = performance . now ( ) ;
53
- const updateInterval = 1000 ; // Update every 1000ms (1 second)
54
-
55
50
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 ) ;
66
55
}
56
+ }
67
57
68
- requestAnimationFrame ( updateFrameRate ) ;
69
- } ;
70
-
58
+ // Initial frame rate calculation
71
59
updateFrameRate ( ) ;
72
60
61
+ // Use setInterval instead of requestAnimationFrame
62
+ const intervalId = setInterval ( updateFrameRate , 1000 ) ;
63
+
73
64
// Monitor frame rate changes
74
65
this . frameRateMonitor . lowFrameRate . addEventListener ( ( scene , frameRate ) => {
75
66
console . warn ( `Low frame rate detected: ${ frameRate } FPS` ) ;
@@ -78,6 +69,13 @@ export class WindParticlesComputing {
78
69
this . frameRateMonitor . nominalFrameRate . addEventListener ( ( scene , frameRate ) => {
79
70
console . log ( `Frame rate returned to normal: ${ frameRate } FPS` ) ;
80
71
} ) ;
72
+
73
+ // Add cleanup method to destroy
74
+ const originalDestroy = this . destroy . bind ( this ) ;
75
+ this . destroy = ( ) => {
76
+ clearInterval ( intervalId ) ;
77
+ originalDestroy ( ) ;
78
+ } ;
81
79
}
82
80
83
81
createWindTextures ( ) {
@@ -141,14 +139,6 @@ export class WindParticlesComputing {
141
139
}
142
140
143
141
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
-
152
142
this . primitives = {
153
143
calculateSpeed : new CustomPrimitive ( {
154
144
commandType : 'Compute' ,
@@ -162,10 +152,9 @@ export class WindParticlesComputing {
162
152
speedScaleFactor : ( ) => {
163
153
return ( this . viewerParameters . pixelSize + 50 ) * this . options . speedFactor * this . frameRateAdjustment ;
164
154
} ,
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 ) ,
169
158
} ,
170
159
fragmentShaderSource : ShaderManager . getCalculateSpeedShader ( ) ,
171
160
outputTexture : this . particlesTextures . particlesSpeed ,
0 commit comments