Skip to content

Commit 6f15c38

Browse files
committed
fix: reduce unnecessary texture recreation
1 parent 7486fb6 commit 6f15c38

File tree

8 files changed

+100
-11
lines changed

8 files changed

+100
-11
lines changed

example/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# example
22

3+
## 0.4.6
4+
5+
### Patch Changes
6+
7+
- fix: reduce unnecessary texture recreation
8+
- Updated dependencies
9+
- cesium-wind-layer@0.7.5
10+
311
## 0.4.5
412

513
### Patch Changes

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "example",
33
"private": true,
4-
"version": "0.4.5",
4+
"version": "0.4.6",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",

example/src/components/ControlPanel.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import ColorTableInput from './ColorTableInput';
66
import styled from 'styled-components';
77
import { ZoomInOutlined } from '@ant-design/icons';
88
import { EyeOutlined, EyeInvisibleOutlined } from '@ant-design/icons';
9+
import NumberInput from './NumberInput';
910

1011
const { Text } = Typography;
1112

@@ -301,7 +302,7 @@ export const ControlPanel: React.FC<ControlPanelProps> = ({
301302
</Text>
302303
}
303304
>
304-
<InputNumber />
305+
<NumberInput min={1} max={2000} step={10} />
305306
</CompactFormItem>
306307

307308
<CompactFormItem
@@ -311,7 +312,7 @@ export const ControlPanel: React.FC<ControlPanelProps> = ({
311312
'Height of particles above the ground in meters.'
312313
)}
313314
>
314-
<InputNumber min={-1000} max={10000} step={100} />
315+
<NumberInput min={-1000} max={10000} step={100} />
315316
</CompactFormItem>
316317

317318
<CompactFormItem
@@ -321,7 +322,7 @@ export const ControlPanel: React.FC<ControlPanelProps> = ({
321322
'Width of particle trails in pixels. Controls the width of the particles.'
322323
)}
323324
>
324-
<InputNumber min={0.1} max={100} step={0.1} />
325+
<NumberInput min={0.1} max={100} step={0.1} precision={1} />
325326
</CompactFormItem>
326327

327328
<CompactFormItem
@@ -331,7 +332,7 @@ export const ControlPanel: React.FC<ControlPanelProps> = ({
331332
'Factor to adjust the speed of particles. Controls the movement speed of particles.'
332333
)}
333334
>
334-
<InputNumber min={0.1} max={10} step={0.1} />
335+
<NumberInput min={0.1} max={10} step={0.1} precision={1} />
335336
</CompactFormItem>
336337

337338
<CompactFormItem
@@ -341,7 +342,7 @@ export const ControlPanel: React.FC<ControlPanelProps> = ({
341342
'Rate at which particles are dropped (reset). Controls the lifecycle of particles.'
342343
)}
343344
>
344-
<InputNumber min={0.001} max={0.01} step={0.001} />
345+
<NumberInput min={0.001} max={0.01} step={0.001} precision={3} />
345346
</CompactFormItem>
346347

347348
<CompactFormItem
@@ -351,7 +352,7 @@ export const ControlPanel: React.FC<ControlPanelProps> = ({
351352
'Additional drop rate for slow-moving particles. Increases the probability of dropping particles when they move slowly.'
352353
)}
353354
>
354-
<InputNumber min={0} max={0.2} step={0.001} />
355+
<NumberInput min={0} max={0.2} step={0.001} precision={3} />
355356
</CompactFormItem>
356357

357358
<CompactFormItem
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import React from 'react';
2+
import { InputNumber, Slider } from 'antd';
3+
import styled from 'styled-components';
4+
5+
const Container = styled.div`
6+
display: flex;
7+
gap: 12px;
8+
align-items: center;
9+
`;
10+
11+
const StyledSlider = styled(Slider)`
12+
flex: 1;
13+
margin: 0;
14+
15+
@media (max-width: 767px) {
16+
padding: 8px 0;
17+
18+
.ant-slider-handle {
19+
width: 20px;
20+
height: 20px;
21+
margin-top: -9px;
22+
}
23+
}
24+
`;
25+
26+
const StyledInputNumber = styled(InputNumber<number>)`
27+
width: 80px !important;
28+
`;
29+
30+
interface NumberInputProps {
31+
value?: number;
32+
onChange?: (value: number) => void;
33+
min?: number;
34+
max?: number;
35+
step?: number;
36+
precision?: number;
37+
}
38+
39+
const NumberInput: React.FC<NumberInputProps> = ({
40+
value,
41+
onChange,
42+
min,
43+
max,
44+
step = 1,
45+
precision = 0,
46+
}) => {
47+
const handleInputNumberChange = (val: number | null) => {
48+
if (val !== null && onChange) {
49+
onChange(val);
50+
}
51+
};
52+
53+
return (
54+
<Container>
55+
<StyledSlider
56+
value={value}
57+
onChange={onChange}
58+
min={min}
59+
max={max}
60+
step={step}
61+
/>
62+
<StyledInputNumber
63+
value={value}
64+
onChange={handleInputNumberChange}
65+
min={min}
66+
max={max}
67+
step={step}
68+
precision={precision}
69+
/>
70+
</Container>
71+
);
72+
};
73+
74+
export default NumberInput;

packages/cesium-wind-layer/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# cesium-wind-layer
22

3+
## 0.7.5
4+
5+
### Patch Changes
6+
7+
- fix: reduce unnecessary texture recreation
8+
39
## 0.7.4
410

511
### Patch Changes

packages/cesium-wind-layer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cesium-wind-layer",
3-
"version": "0.7.4",
3+
"version": "0.7.5",
44
"publishConfig": {
55
"access": "public"
66
},

packages/cesium-wind-layer/src/windParticleSystem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class WindParticleSystem {
4747

4848
changeOptions(options: Partial<WindLayerOptions>) {
4949
let maxParticlesChanged = false;
50-
if (this.options.particlesTextureSize && this.options.particlesTextureSize !== options.particlesTextureSize) {
50+
if (options.particlesTextureSize && this.options.particlesTextureSize !== options.particlesTextureSize) {
5151
maxParticlesChanged = true;
5252
}
5353

packages/cesium-wind-layer/src/windParticlesComputing.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class WindParticlesComputing {
4949
private initFrameRate() {
5050
const updateFrameRate = () => {
5151
// avoid update frame rate when frame rate is too low
52-
if (this.frameRateMonitor.lastFramesPerSecond > 50) {
52+
if (this.frameRateMonitor.lastFramesPerSecond > 20) {
5353
this.frameRate = this.frameRateMonitor.lastFramesPerSecond;
5454
this.frameRateAdjustment = 60 / Math.max(this.frameRate, 1);
5555
}
@@ -223,7 +223,7 @@ export class WindParticlesComputing {
223223
}
224224

225225
updateOptions(options: Partial<WindLayerOptions>) {
226-
const needUpdateWindTextures = options.flipY !== this.options.flipY;
226+
const needUpdateWindTextures = options.flipY !== undefined && options.flipY !== this.options.flipY;
227227
this.options = deepMerge(options, this.options);
228228
if (needUpdateWindTextures) {
229229
this.reCreateWindTextures();

0 commit comments

Comments
 (0)