Skip to content

Commit

Permalink
feat: add dynamic option to control particle animation
Browse files Browse the repository at this point in the history
- Add new `dynamic` option to WindLayerOptions to control particle animation state
- Add dynamic switch control in ControlPanel component
- Set default value of dynamic option to true
- Update types and documentation

This change allows users to toggle between animated and static particle states.
  • Loading branch information
hongfaqiu committed Nov 6, 2024
1 parent 3fdaa14 commit 770381e
Show file tree
Hide file tree
Showing 10 changed files with 2,729 additions and 3,354 deletions.
13 changes: 13 additions & 0 deletions .changeset/strong-dryers-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
'cesium-wind-layer': minor
'example': minor
---

feat: add dynamic option to control particle animation

- Add new `dynamic` option to WindLayerOptions to control particle animation state
- Add dynamic switch control in ControlPanel component
- Set default value of dynamic option to true
- Update types and documentation

This change allows users to toggle between animated and static particle states.
15 changes: 15 additions & 0 deletions example/src/components/ControlPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,21 @@ export const ControlPanel: React.FC<ControlPanelProps> = ({
/>
</CompactFormItem>

<CompactFormItem
name="dynamic"
label={renderLabel(
'Dynamic Animation',
'Enable or disable particle animation. When disabled, particles will remain static.'
)}
valuePropName="checked"
>
<Switch
size="small"
checkedChildren="Animated"
unCheckedChildren="Static"
/>
</CompactFormItem>

<CompactFormItem
label={renderLabel(
'Speed Range',
Expand Down
1 change: 1 addition & 0 deletions example/src/pages/earth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const defaultOptions: Partial<WindLayerOptions> = {
colors: colorSchemes[3].colors,
flipY: true,
useViewerBounds: true,
dynamic: true,
// Remove domain and speedFactor from here since they will be set dynamically
};

Expand Down
2 changes: 2 additions & 0 deletions packages/cesium-wind-layer/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const windLayer = new WindLayer(viewer, windData, {
flipY: false, // Flip Y coordinates if needed
domain: undefined, // Optional: domain for speed
displayRange: undefined, // Optional: display range for speed
dynamic: true, // Whether to enable dynamic particle animation
});
```

Expand Down Expand Up @@ -107,6 +108,7 @@ interface WindLayerOptions {
min?: number; // Minimum speed value for display
max?: number; // Maximum speed value for display
};
dynamic: boolean; // Whether to enable dynamic particle animation. Default is true.
}
```

Expand Down
6 changes: 4 additions & 2 deletions packages/cesium-wind-layer/readme.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ const windLayer = new WindLayer(viewer, windData, {
colors: ['white'], // 粒子颜色
flipY: false, // 是否翻转 Y 坐标
domain: undefined, // 速度渲染范围
displayRange: undefined // 速度显示范围
displayRange: undefined, // 速度显示范围
dynamic: true // 是否启用动态粒子动画
});
```

Expand Down Expand Up @@ -106,7 +107,8 @@ interface WindLayerOptions {
displayRange?: { // 速度显示范围(默认:undefined)
min?: number; // 最小速度值
max?: number; // 最大速度值
};
};
dynamic: boolean; // 是否启用动态粒子动画(默认:true)
}
```

Expand Down
9 changes: 8 additions & 1 deletion packages/cesium-wind-layer/src/customPrimitive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from 'cesium';

interface CustomPrimitiveOptions {
isDynamic?: () => boolean;
commandType: 'Draw' | 'Compute';
geometry?: Geometry;
attributeLocations?: { [key: string]: number };
Expand Down Expand Up @@ -48,6 +49,7 @@ export default class CustomPrimitive {
show: boolean;
commandToExecute?: DrawCommand | ComputeCommand;
clearCommand?: ClearCommand;
isDynamic: () => boolean;

constructor(options: CustomPrimitiveOptions) {
this.commandType = options.commandType;
Expand All @@ -66,7 +68,8 @@ export default class CustomPrimitive {
this.show = true;
this.commandToExecute = undefined;
this.clearCommand = undefined;

this.isDynamic = options.isDynamic ?? (() => true);

if (this.autoClear) {
this.clearCommand = new ClearCommand({
color: new Color(0.0, 0.0, 0.0, 0.0),
Expand Down Expand Up @@ -131,6 +134,10 @@ export default class CustomPrimitive {
}

update(frameState: any) {
if (!this.isDynamic()) {
return;
}

if (!this.show || !defined(frameState)) {
return;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/cesium-wind-layer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export class WindLayer {
flipY: false,
useViewerBounds: false,
domain: undefined,
displayRange: undefined
displayRange: undefined,
dynamic: true
}

viewer: Viewer;
Expand Down
5 changes: 5 additions & 0 deletions packages/cesium-wind-layer/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ export interface WindLayerOptions {
min?: number;
max?: number;
};
/**
* Whether to enable dynamic particle animation. Default is true.
* When set to false, particles will remain static.
*/
dynamic: boolean;
}

export interface WindDataDemention {
Expand Down
9 changes: 6 additions & 3 deletions packages/cesium-wind-layer/src/windParticlesComputing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ export class WindParticlesComputing {
if (this.primitives.calculateSpeed.commandToExecute) {
this.primitives.calculateSpeed.commandToExecute.outputTexture = this.particlesTextures.particlesSpeed;
}
}
},
isDynamic: () =>this.options.dynamic
}),

updatePosition: new CustomPrimitive({
Expand All @@ -182,7 +183,8 @@ export class WindParticlesComputing {
if (this.primitives.updatePosition.commandToExecute) {
this.primitives.updatePosition.commandToExecute.outputTexture = this.particlesTextures.nextParticlesPosition;
}
}
},
isDynamic: () => this.options.dynamic
}),

postProcessingPosition: new CustomPrimitive({
Expand All @@ -207,7 +209,8 @@ export class WindParticlesComputing {
if (this.primitives.postProcessingPosition.commandToExecute) {
this.primitives.postProcessingPosition.commandToExecute.outputTexture = this.particlesTextures.postProcessingPosition;
}
}
},
isDynamic: () => this.options.dynamic
})
};
}
Expand Down
Loading

0 comments on commit 770381e

Please sign in to comment.