Skip to content

Commit 7df1de4

Browse files
committed
Clean up animation layers related types
1 parent a3d01af commit 7df1de4

File tree

4 files changed

+31
-76
lines changed

4 files changed

+31
-76
lines changed
Lines changed: 14 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
1-
import {
2-
CompositeLayer,
3-
Layer,
4-
LayersList,
5-
LayerContext,
6-
GetPickingInfoParams,
7-
} from "deck.gl";
1+
import { CompositeLayer, Layer, LayersList } from "deck.gl";
82
import type { CompositeLayerProps, UpdateParameters } from "deck.gl";
9-
import type { BitmapLayerPickingInfo } from "@deck.gl/layers";
103
import type { Texture } from "@luma.gl/core";
114

125
import { NumericDataAnimationPaintLayer } from "../NumericDataAnimationPaintLayer";
@@ -27,53 +20,19 @@ const textureSamplerDefaultOption = {
2720

2821
export default class NumericDataAnimationLayer extends CompositeLayer<NumericDataAnimationLayerProps> {
2922
static layerName: string = "numeric-data-animation-layer";
30-
31-
// initializeState(context: LayerContext): void {
32-
// const { tileSize, textureParameters } = this.props;
33-
// const dataTextureStart = context.device.createTexture({
34-
// data: this.props.imageDataStart,
35-
// width: tileSize,
36-
// height: tileSize,
37-
// ...textureDefaultOption,
38-
// sampler: {
39-
// ...textureSamplerDefaultOption,
40-
// ...textureParameters,
41-
// },
42-
// });
43-
// const dataTextureEnd = context.device.createTexture({
44-
// data: this.props.imageDataEnd,
45-
// width: tileSize,
46-
// height: tileSize,
47-
// ...textureDefaultOption,
48-
// sampler: {
49-
// ...textureSamplerDefaultOption,
50-
// ...textureParameters,
51-
// },
52-
// });
53-
// this.setState({
54-
// dataTextureStart,
55-
// dataTextureEnd,
56-
// });
57-
// }
5823
updateState(
5924
params: UpdateParameters<
60-
Layer<NumericDataLayerProps & Required<CompositeLayerProps>>
25+
Layer<NumericDataAnimationLayerProps & Required<CompositeLayerProps>>
6126
>
6227
): void {
6328
const { props, oldProps, context } = params;
64-
const { imageDataStart, imageDataEnd, timestamp } = props;
65-
const {
66-
imageDataStart: oldImageDataStart,
67-
imageDataEnd: oldImageDataEnd,
68-
timestamp: oldTimestamp,
69-
} = oldProps;
70-
if (
71-
imageDataStart !== oldImageDataStart &&
72-
imageDataEnd !== oldImageDataEnd
73-
) {
29+
const { imageDataFrom, imageDataTo } = props;
30+
const { imageDataFrom: oldImageDataFrom, imageDataTo: oldImageDataTo } =
31+
oldProps;
32+
if (imageDataFrom !== oldImageDataFrom && imageDataTo !== oldImageDataTo) {
7433
const { tileSize, textureParameters } = props;
75-
const dataTextureStart = context.device.createTexture({
76-
data: this.props.imageDataStart,
34+
const dataTextureFrom = context.device.createTexture({
35+
data: this.props.imageDataFrom,
7736
width: tileSize,
7837
height: tileSize,
7938
...textureDefaultOption,
@@ -82,8 +41,8 @@ export default class NumericDataAnimationLayer extends CompositeLayer<NumericDat
8241
...textureParameters,
8342
},
8443
});
85-
const dataTextureEnd = context.device.createTexture({
86-
data: this.props.imageDataEnd,
44+
const dataTextureTo = context.device.createTexture({
45+
data: this.props.imageDataTo,
8746
width: tileSize,
8847
height: tileSize,
8948
...textureDefaultOption,
@@ -93,17 +52,17 @@ export default class NumericDataAnimationLayer extends CompositeLayer<NumericDat
9352
},
9453
});
9554
this.setState({
96-
dataTextureStart,
97-
dataTextureEnd,
55+
dataTextureFrom,
56+
dataTextureTo,
9857
});
9958
}
10059
}
10160

10261
renderLayers(): Layer | null | LayersList {
10362
return new NumericDataAnimationPaintLayer(this.props, {
10463
id: `${this.props.id}-data`,
105-
image: this.state.dataTextureStart as Texture,
106-
imageEnd: this.state.dataTextureEnd as Texture,
64+
image: this.state.dataTextureFrom as Texture,
65+
imageTo: this.state.dataTextureTo as Texture,
10766
});
10867
}
10968
}
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
import type { NumericDataPaintLayerProps } from "../NumericDataPaintLayer/types";
2-
import type { BitmapLayerPickingInfo } from "@deck.gl/layers";
1+
import type { NumericDataAnimationPaintLayerProps } from "../NumericDataAnimationPaintLayer/types";
32
import type { TypedArray, NumberDataType } from "zarrita";
43

54
export interface NumericDataAnimationLayerProps
6-
extends NumericDataPaintLayerProps {
7-
imageDataStart: TypedArray<NumberDataType>;
8-
imageDataEnd: TypedArray<NumberDataType>;
9-
}
10-
11-
export interface NumericDataPickingInfo extends BitmapLayerPickingInfo {
12-
dataValue: NumberDataType | null;
5+
extends NumericDataAnimationPaintLayerProps {
6+
imageDataFrom: TypedArray<NumberDataType>;
7+
imageDataTo: TypedArray<NumberDataType>;
138
}

src/layers/NumericDataAnimationPaintLayer/index.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { BitmapLayer } from "deck.gl";
33
import type { Texture } from "@luma.gl/core";
44
import type { ShaderModule } from "@luma.gl/shadertools";
55

6-
import type { NumericDataPaintLayerProps } from "./types";
6+
import type { NumericDataAnimationPaintLayerProps } from "./types";
77

88
const uniformBlock = `\
99
uniform ndUniforms {
@@ -18,7 +18,7 @@ export type NDProps = {
1818
max: number;
1919
step: number;
2020
colormap_texture: Texture;
21-
image_end: Texture;
21+
image_to: Texture;
2222
};
2323

2424
const numericDataAnimationUniforms = {
@@ -38,16 +38,17 @@ const defaultProps = {
3838
min: 0,
3939
max: 0,
4040
tileSize: 256,
41-
timestamp: 0.0,
41+
step: 0.0,
4242
imageData: [],
43+
imageTo: [],
4344
colormap_image: {
4445
type: "image",
4546
value: null,
4647
async: true,
4748
},
4849
};
4950

50-
export class NumericDataAnimationPaintLayer extends BitmapLayer<NumericDataPaintLayerProps> {
51+
export class NumericDataAnimationPaintLayer extends BitmapLayer<NumericDataAnimationPaintLayerProps> {
5152
static layerName = "numeric-paint-animation-layer";
5253
static defaultProps = defaultProps;
5354

@@ -57,12 +58,11 @@ export class NumericDataAnimationPaintLayer extends BitmapLayer<NumericDataPaint
5758
inject: {
5859
"fs:#decl": `
5960
uniform sampler2D colormap_texture; // texture is not included in ubo
60-
uniform sampler2D image_end;
61+
uniform sampler2D image_to;
6162
`,
6263
"fs:DECKGL_FILTER_COLOR": `
63-
6464
float start_value = color.r;
65-
vec4 end_image = texture(image_end, geometry.uv);
65+
vec4 end_image = texture(image_to, geometry.uv);
6666
float end_value = end_image.r;
6767
float value = mix(start_value, end_value, nd.step);
6868
if (isnan(value)) {
@@ -80,16 +80,16 @@ export class NumericDataAnimationPaintLayer extends BitmapLayer<NumericDataPaint
8080

8181
// @ts-expect-error no opts type available
8282
draw(opts) {
83-
const { colormap_image, imageEnd, timestamp, min, max } = this.props;
83+
const { colormap_image, imageTo, step, min, max } = this.props;
8484

8585
const sModels = super.getModels();
8686
if (colormap_image)
8787
for (const m of sModels) {
8888
m.shaderInputs.setProps({
8989
nd: {
9090
colormap_texture: colormap_image,
91-
image_end: imageEnd,
92-
step: timestamp,
91+
image_to: imageTo,
92+
step,
9393
min,
9494
max,
9595
},
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import type { BitmapLayerProps } from "deck.gl";
22

3-
export interface NumericDataPaintLayerProps extends BitmapLayerProps {
3+
export interface NumericDataAnimationPaintLayerProps extends BitmapLayerProps {
44
colormap_image: string | Texture;
55
min: number;
66
max: number;
7-
timestamp: number;
7+
step: number;
88
tileSize: number;
9+
imageTo: Texture;
910
}

0 commit comments

Comments
 (0)