@luma.gl/engine 8.6.0-alpha.5 → 9.0.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/animation/key-frames.d.ts +1 -0
- package/dist/animation/key-frames.d.ts.map +1 -1
- package/dist/animation/key-frames.js.map +1 -1
- package/dist/animation/timeline.d.ts +2 -2
- package/dist/animation/timeline.d.ts.map +1 -1
- package/dist/animation/timeline.js.map +1 -1
- package/dist/geometries/cone-geometry.d.ts.map +1 -1
- package/dist/geometries/cone-geometry.js +1 -1
- package/dist/geometries/cone-geometry.js.map +1 -1
- package/dist/geometries/cube-geometry.d.ts +4 -0
- package/dist/geometries/cube-geometry.d.ts.map +1 -1
- package/dist/geometries/cube-geometry.js +31 -7
- package/dist/geometries/cube-geometry.js.map +1 -1
- package/dist/geometries/cylinder-geometry.d.ts.map +1 -1
- package/dist/geometries/cylinder-geometry.js +1 -1
- package/dist/geometries/cylinder-geometry.js.map +1 -1
- package/dist/geometries/ico-sphere-geometry.d.ts.map +1 -1
- package/dist/geometries/ico-sphere-geometry.js +1 -1
- package/dist/geometries/ico-sphere-geometry.js.map +1 -1
- package/dist/geometries/plane-geometry.d.ts.map +1 -1
- package/dist/geometries/plane-geometry.js +1 -1
- package/dist/geometries/plane-geometry.js.map +1 -1
- package/dist/geometries/sphere-geometry.d.ts.map +1 -1
- package/dist/geometries/sphere-geometry.js +1 -1
- package/dist/geometries/sphere-geometry.js.map +1 -1
- package/dist/geometries/truncated-cone-geometry.d.ts +15 -3
- package/dist/geometries/truncated-cone-geometry.d.ts.map +1 -1
- package/dist/geometries/truncated-cone-geometry.js +29 -15
- package/dist/geometries/truncated-cone-geometry.js.map +1 -1
- package/dist/geometry/geometry-table.d.ts +15 -0
- package/dist/geometry/geometry-table.d.ts.map +1 -0
- package/dist/geometry/geometry-table.js +2 -0
- package/dist/{transform/transform-types.js.map → geometry/geometry-table.js.map} +1 -1
- package/dist/geometry/geometry-utils.js.map +1 -1
- package/dist/geometry/geometry.d.ts +32 -14
- package/dist/geometry/geometry.d.ts.map +1 -1
- package/dist/geometry/geometry.js +57 -34
- package/dist/geometry/geometry.js.map +1 -1
- package/dist/geometry/primitive-utils.d.ts +1 -0
- package/dist/geometry/primitive-utils.d.ts.map +1 -0
- package/dist/geometry/primitive-utils.js +2 -0
- package/dist/geometry/primitive-utils.js.map +1 -0
- package/dist/index.d.ts +6 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -6
- package/dist/index.js.map +1 -1
- package/dist/lib/animation-loop.d.ts +25 -87
- package/dist/lib/animation-loop.d.ts.map +1 -1
- package/dist/lib/animation-loop.js +111 -197
- package/dist/lib/animation-loop.js.map +1 -1
- package/dist/lib/animation-props.d.ts +24 -0
- package/dist/lib/animation-props.d.ts.map +1 -0
- package/dist/lib/animation-props.js +2 -0
- package/dist/lib/animation-props.js.map +1 -0
- package/dist/lib/clip-space.d.ts +1 -0
- package/dist/lib/clip-space.d.ts.map +1 -0
- package/dist/lib/clip-space.js +2 -0
- package/dist/lib/clip-space.js.map +1 -0
- package/dist/lib/model-utils.d.ts +4 -3
- package/dist/lib/model-utils.d.ts.map +1 -1
- package/dist/lib/model-utils.js +24 -70
- package/dist/lib/model-utils.js.map +1 -1
- package/dist/lib/model.d.ts +34 -104
- package/dist/lib/model.d.ts.map +1 -1
- package/dist/lib/model.js +111 -502
- package/dist/lib/model.js.map +1 -1
- package/dist/lib/pipeline-factory.d.ts +60 -0
- package/dist/lib/pipeline-factory.d.ts.map +1 -0
- package/dist/lib/pipeline-factory.js +219 -0
- package/dist/lib/pipeline-factory.js.map +1 -0
- package/dist/lib/render-loop.d.ts +10 -18
- package/dist/lib/render-loop.d.ts.map +1 -1
- package/dist/lib/render-loop.js +32 -35
- package/dist/lib/render-loop.js.map +1 -1
- package/package.json +6 -6
- package/src/animation/key-frames.ts +1 -0
- package/src/animation/timeline.ts +2 -2
- package/src/geometries/cone-geometry.ts +1 -1
- package/src/geometries/cube-geometry.ts +160 -8
- package/src/geometries/cylinder-geometry.ts +1 -1
- package/src/geometries/ico-sphere-geometry.ts +2 -2
- package/src/geometries/plane-geometry.ts +1 -1
- package/src/geometries/sphere-geometry.ts +2 -2
- package/src/geometries/truncated-cone-geometry.ts +30 -12
- package/src/geometry/geometry-table.ts +16 -0
- package/src/geometry/geometry-utils.ts +1 -1
- package/src/geometry/geometry.ts +97 -47
- package/src/geometry/primitive-utils.ts +30 -0
- package/src/index.ts +13 -12
- package/src/lib/animation-loop.ts +141 -319
- package/src/lib/animation-props.ts +31 -0
- package/src/{utils → lib}/clip-space.ts +5 -2
- package/src/lib/model-utils.ts +60 -32
- package/src/lib/model.ts +127 -639
- package/src/lib/pipeline-factory.ts +234 -0
- package/src/lib/render-loop.ts +44 -40
- package/dist/lib/program-manager.d.ts +0 -39
- package/dist/lib/program-manager.d.ts.map +0 -1
- package/dist/lib/program-manager.js +0 -175
- package/dist/lib/program-manager.js.map +0 -1
- package/dist/transform/buffer-transform.d.ts +0 -36
- package/dist/transform/buffer-transform.d.ts.map +0 -1
- package/dist/transform/buffer-transform.js +0 -255
- package/dist/transform/buffer-transform.js.map +0 -1
- package/dist/transform/texture-transform.d.ts +0 -57
- package/dist/transform/texture-transform.d.ts.map +0 -1
- package/dist/transform/texture-transform.js +0 -412
- package/dist/transform/texture-transform.js.map +0 -1
- package/dist/transform/transform-shader-utils.d.ts +0 -26
- package/dist/transform/transform-shader-utils.d.ts.map +0 -1
- package/dist/transform/transform-shader-utils.js +0 -149
- package/dist/transform/transform-shader-utils.js.map +0 -1
- package/dist/transform/transform-types.d.ts +0 -44
- package/dist/transform/transform-types.d.ts.map +0 -1
- package/dist/transform/transform-types.js +0 -2
- package/dist/transform/transform.d.ts +0 -47
- package/dist/transform/transform.d.ts.map +0 -1
- package/dist/transform/transform.js +0 -198
- package/dist/transform/transform.js.map +0 -1
- package/dist/utils/clip-space.d.ts +0 -5
- package/dist/utils/clip-space.d.ts.map +0 -1
- package/dist/utils/clip-space.js +0 -34
- package/dist/utils/clip-space.js.map +0 -1
- package/src/lib/program-manager.ts +0 -187
- package/src/transform/buffer-transform.ts +0 -214
- package/src/transform/texture-transform.ts +0 -344
- package/src/transform/transform-shader-utils.ts +0 -169
- package/src/transform/transform-types.ts +0 -42
- package/src/transform/transform.ts +0 -189
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import type {RenderPipelineProps, RenderPipelineParameters, PrimitiveTopology, ShaderLayout} from '@luma.gl/api';
|
|
2
|
+
import {Device, RenderPipeline, ComputePipeline} from '@luma.gl/api/';
|
|
3
|
+
import type { ShaderModule } from '@luma.gl/shadertools';
|
|
4
|
+
import {assembleShaders} from '@luma.gl/shadertools';
|
|
5
|
+
|
|
6
|
+
export type GetRenderPipelineOptions = {
|
|
7
|
+
vs: string;
|
|
8
|
+
fs: string | null;
|
|
9
|
+
topology: PrimitiveTopology;
|
|
10
|
+
layout?: ShaderLayout | null;
|
|
11
|
+
parameters?: RenderPipelineParameters;
|
|
12
|
+
|
|
13
|
+
modules?: ShaderModule[];
|
|
14
|
+
defines?: Record<string, string | number | boolean>;
|
|
15
|
+
inject?: Record<string, string>;
|
|
16
|
+
transpileToGLSL100?: boolean;
|
|
17
|
+
|
|
18
|
+
varyings?: string[];
|
|
19
|
+
bufferMode?: number,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type GetComputePipelineOptions = {
|
|
23
|
+
cs: string;
|
|
24
|
+
parameters?: RenderPipelineParameters;
|
|
25
|
+
|
|
26
|
+
modules?: ShaderModule[];
|
|
27
|
+
defines?: Record<string, string>;
|
|
28
|
+
inject?: Record<string, string>;
|
|
29
|
+
transpileToGLSL100?: boolean;
|
|
30
|
+
|
|
31
|
+
varyings?: string[];
|
|
32
|
+
bufferMode?: number;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const DEFAULT_RENDER_PIPELINE_OPTIONS: Required<GetRenderPipelineOptions> = {
|
|
36
|
+
vs: '',
|
|
37
|
+
fs: '',
|
|
38
|
+
modules: [],
|
|
39
|
+
defines: {},
|
|
40
|
+
inject: {},
|
|
41
|
+
transpileToGLSL100: false,
|
|
42
|
+
layout: null,
|
|
43
|
+
|
|
44
|
+
varyings: [],
|
|
45
|
+
bufferMode: 0x8c8d, // // varyings/bufferMode for xform feedback, 0x8c8d: SEPARATE_ATTRIBS
|
|
46
|
+
topology: 'triangle-list',
|
|
47
|
+
parameters: {}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
type GetUniformsFunc = (props?: Record<string, any>) => Record<string, any>;
|
|
51
|
+
|
|
52
|
+
/** Efficiently create shared pipelines with varying parameters */
|
|
53
|
+
export class PipelineFactory {
|
|
54
|
+
readonly device: Device;
|
|
55
|
+
|
|
56
|
+
stateHash: number = 0; // Used to change hashing if hooks are modified
|
|
57
|
+
private _hashCounter: number = 0;
|
|
58
|
+
private readonly _hashes: Record<string, number> = {};
|
|
59
|
+
private readonly _useCounts: Record<string, number> = {};
|
|
60
|
+
|
|
61
|
+
private readonly _pipelineCache: Record<string, RenderPipeline> = {};
|
|
62
|
+
|
|
63
|
+
private readonly _getUniforms: Record<string, GetUniformsFunc> = {};
|
|
64
|
+
private readonly _hookFunctions: any[] = [];
|
|
65
|
+
private _defaultModules: any[] = [];
|
|
66
|
+
// private readonly _registeredModules = {}; // TODO: Remove? This isn't used anywhere in luma.gl
|
|
67
|
+
|
|
68
|
+
static getDefaultPipelineFactory(device: Device): PipelineFactory {
|
|
69
|
+
// @ts-expect-error Add to device
|
|
70
|
+
device.defaultPipelineFactory = device.defaultPipelineFactory || new PipelineFactory(device);
|
|
71
|
+
// @ts-expect-error Add to device
|
|
72
|
+
return device.defaultPipelineFactory;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
constructor(device: Device) {
|
|
76
|
+
this.device = device;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
addDefaultModule(module: ShaderModule): void {
|
|
80
|
+
if (!this._defaultModules.find((m) => m.name === (typeof module === 'string' ? module : module.name))) {
|
|
81
|
+
this._defaultModules.push(module);
|
|
82
|
+
}
|
|
83
|
+
this.stateHash++;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
removeDefaultModule(module: ShaderModule): void {
|
|
87
|
+
const moduleName = typeof module === 'string' ? module : module.name;
|
|
88
|
+
this._defaultModules = this._defaultModules.filter((m) => m.name !== moduleName);
|
|
89
|
+
this.stateHash++;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
addShaderHook(hook: string, opts?): void {
|
|
93
|
+
if (opts) {
|
|
94
|
+
hook = Object.assign(opts, {hook});
|
|
95
|
+
}
|
|
96
|
+
this._hookFunctions.push(hook);
|
|
97
|
+
this.stateHash++;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
createRenderPipeline(options: GetRenderPipelineOptions): {
|
|
101
|
+
pipeline: RenderPipeline;
|
|
102
|
+
getUniforms: GetUniformsFunc;
|
|
103
|
+
} {
|
|
104
|
+
const props: Required<GetRenderPipelineOptions> = {...DEFAULT_RENDER_PIPELINE_OPTIONS, ...options};
|
|
105
|
+
|
|
106
|
+
const modules = this._getModuleList(props.modules); // Combine with default modules
|
|
107
|
+
|
|
108
|
+
const hash = this._hashRenderPipeline({...props, modules});
|
|
109
|
+
|
|
110
|
+
if (!this._pipelineCache[hash]) {
|
|
111
|
+
const {pipeline, getUniforms} = this._createRenderPipeline({...props, modules});
|
|
112
|
+
pipeline.hash = hash;
|
|
113
|
+
this._pipelineCache[hash] = pipeline;
|
|
114
|
+
this._getUniforms[hash] = getUniforms || ((x?: unknown) => ({}));
|
|
115
|
+
this._useCounts[hash] = 0;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
this._useCounts[hash]++;
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
pipeline: this._pipelineCache[hash],
|
|
122
|
+
getUniforms: this._getUniforms[hash]
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
release(pipeline: RenderPipeline): void {
|
|
127
|
+
const hash = pipeline.hash;
|
|
128
|
+
this._useCounts[hash]--;
|
|
129
|
+
if (this._useCounts[hash] === 0) {
|
|
130
|
+
this._pipelineCache[hash].destroy();
|
|
131
|
+
delete this._pipelineCache[hash];
|
|
132
|
+
delete this._getUniforms[hash];
|
|
133
|
+
delete this._useCounts[hash];
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
getUniforms(pipeline: RenderPipeline) {
|
|
138
|
+
return this._getUniforms[pipeline.hash] || null;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// PRIVATE
|
|
142
|
+
|
|
143
|
+
_createRenderPipeline(props: GetRenderPipelineOptions): {
|
|
144
|
+
pipeline: RenderPipeline,
|
|
145
|
+
getUniforms: GetUniformsFunc
|
|
146
|
+
} {
|
|
147
|
+
const platformInfo = {
|
|
148
|
+
gpu: this.device.info.gpu,
|
|
149
|
+
features: this.device.features
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
if (!props.fs) {
|
|
153
|
+
throw new Error('fs');
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const assembled = assembleShaders(platformInfo, {...props, fs: props.fs, hookFunctions: this._hookFunctions});
|
|
157
|
+
|
|
158
|
+
const pipeline = this.device.createRenderPipeline({
|
|
159
|
+
...props,
|
|
160
|
+
vs: this.device.createShader({stage: 'vertex', source: assembled.vs}),
|
|
161
|
+
fs: assembled.fs ? this.device.createShader({stage: 'fragment', source: assembled.fs}) : null,
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
return {pipeline, getUniforms: assembled.getUniforms};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Calculate a hash based on all the inputs for a render pipeline */
|
|
168
|
+
_hashRenderPipeline(props: GetRenderPipelineOptions): string {
|
|
169
|
+
const {modules = [], varyings = [], defines = {}, inject = {}, parameters = {}} = props;
|
|
170
|
+
const vsHash = this._getHash(props.vs);
|
|
171
|
+
const fsHash = props.fs ? this._getHash(props.fs) : 0;
|
|
172
|
+
|
|
173
|
+
const moduleHashes = modules.map((m) => this._getHash(typeof m === 'string' ? m : m.name)).sort();
|
|
174
|
+
const varyingHashes = varyings.map((v) => this._getHash(v));
|
|
175
|
+
|
|
176
|
+
const defineKeys = Object.keys(defines).sort();
|
|
177
|
+
const injectKeys = Object.keys(inject).sort();
|
|
178
|
+
const defineHashes: number[] = [];
|
|
179
|
+
const injectHashes: number[] = [];
|
|
180
|
+
|
|
181
|
+
for (const key of defineKeys) {
|
|
182
|
+
defineHashes.push(this._getHash(key));
|
|
183
|
+
defineHashes.push(this._getHash(String(defines[key])));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
for (const key of injectKeys) {
|
|
187
|
+
injectHashes.push(this._getHash(key));
|
|
188
|
+
injectHashes.push(this._getHash(inject[key]));
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// TODO - hash parameters!
|
|
192
|
+
const parameterHash = JSON.stringify(parameters);
|
|
193
|
+
|
|
194
|
+
return `${vsHash}/${fsHash}D${defineHashes.join('/')}M${moduleHashes.join(
|
|
195
|
+
'/'
|
|
196
|
+
)}I${injectHashes.join('/')}V${varyingHashes.join('/')}H${this.stateHash}B${props.bufferMode}${
|
|
197
|
+
props.transpileToGLSL100 ? 'T' : ''
|
|
198
|
+
}P${parameterHash}`;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
_getHash(key: string): number {
|
|
202
|
+
if (this._hashes[key] === undefined) {
|
|
203
|
+
this._hashes[key] = this._hashCounter++;
|
|
204
|
+
}
|
|
205
|
+
return this._hashes[key];
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Dedupe and combine with default modules
|
|
209
|
+
_getModuleList(appModules: ShaderModule[] = []): ShaderModule[] {
|
|
210
|
+
const modules = new Array(this._defaultModules.length + appModules.length);
|
|
211
|
+
const seen: Record<string, boolean> = {};
|
|
212
|
+
let count = 0;
|
|
213
|
+
|
|
214
|
+
for (let i = 0, len = this._defaultModules.length; i < len; ++i) {
|
|
215
|
+
const module = this._defaultModules[i];
|
|
216
|
+
const name = module.name;
|
|
217
|
+
modules[count++] = module;
|
|
218
|
+
seen[name] = true;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
for (let i = 0, len = appModules.length; i < len; ++i) {
|
|
222
|
+
const module = appModules[i];
|
|
223
|
+
const name = module.name;
|
|
224
|
+
if (!seen[name]) {
|
|
225
|
+
modules[count++] = module;
|
|
226
|
+
seen[name] = true;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
modules.length = count;
|
|
231
|
+
|
|
232
|
+
return modules;
|
|
233
|
+
}
|
|
234
|
+
}
|
package/src/lib/render-loop.ts
CHANGED
|
@@ -1,56 +1,60 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {AnimationProps} from '
|
|
3
|
-
import AnimationLoop from './animation-loop';
|
|
4
|
-
import {Timeline} from '../animation/timeline'
|
|
1
|
+
import type {DeviceProps} from '@luma.gl/api';
|
|
2
|
+
import type {AnimationProps} from '../lib/animation-props';
|
|
3
|
+
import {AnimationLoop} from './animation-loop';
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Minimal animation loop that initializes models in constructor
|
|
8
7
|
* Simplifying type management
|
|
8
|
+
* v9 API
|
|
9
9
|
*/
|
|
10
10
|
export abstract class RenderLoop {
|
|
11
|
-
constructor(animationProps?: AnimationProps) {}
|
|
12
|
-
onRender(animationProps: AnimationProps) {}
|
|
13
|
-
onFinalize(animationProps: AnimationProps) {}
|
|
14
|
-
|
|
15
|
-
static getAnimationLoop(RenderLoopConstructor: typeof RenderLoop) {
|
|
16
|
-
return new WrappedAnimationLoop(RenderLoopConstructor);
|
|
17
|
-
}
|
|
18
11
|
|
|
19
|
-
|
|
20
|
-
static run(RenderLoopConstructor: typeof RenderLoop, options?: {start?: boolean}): WrappedAnimationLoop {
|
|
21
|
-
const animationLoop = RenderLoop.getAnimationLoop(RenderLoopConstructor);
|
|
22
|
-
if (options?.start !== false) {
|
|
23
|
-
animationLoop.start();
|
|
24
|
-
}
|
|
25
|
-
return animationLoop;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
12
|
+
animationLoop?: AnimationLoop;
|
|
28
13
|
|
|
29
|
-
|
|
30
|
-
RenderLoopConstructor: typeof RenderLoop;
|
|
31
|
-
renderLoop: RenderLoop;
|
|
14
|
+
constructor(animationProps?: AnimationProps) {}
|
|
32
15
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return this.RenderLoopConstructor.info;
|
|
16
|
+
destroy(): void {
|
|
17
|
+
this.animationLoop?.destroy();
|
|
36
18
|
}
|
|
37
19
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
20
|
+
async onInitialize(animationProps: AnimationProps): Promise<unknown> { return null; }
|
|
21
|
+
abstract onRender(animationProps: AnimationProps): unknown;
|
|
22
|
+
abstract onFinalize(animationProps: AnimationProps): void;
|
|
42
23
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
24
|
+
/** Instantiates and runs the render loop */
|
|
25
|
+
static run(RenderLoopConstructor: typeof RenderLoop, deviceProps?: DeviceProps): AnimationLoop {
|
|
26
|
+
let renderLoop: RenderLoop | null = null;
|
|
27
|
+
|
|
28
|
+
// Create an animation loop;
|
|
29
|
+
const animationLoop = new AnimationLoop({
|
|
30
|
+
deviceProps,
|
|
31
|
+
|
|
32
|
+
async onInitialize(animationProps: AnimationProps): Promise<unknown> {
|
|
33
|
+
// @ts-expect-error abstract to prevent instantiation
|
|
34
|
+
renderLoop = new RenderLoopConstructor(animationProps);
|
|
35
|
+
renderLoop!.animationLoop = animationLoop;
|
|
36
|
+
// Any async loading can be handled here
|
|
37
|
+
return await renderLoop?.onInitialize(animationProps);
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
onRender(animationProps: AnimationProps) {
|
|
41
|
+
renderLoop?.onRender(animationProps);
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
onFinalize(animationProps: AnimationProps) {
|
|
45
|
+
renderLoop?.onFinalize(animationProps);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// @ts-expect-error Hack: adds info for the website to find
|
|
50
|
+
animationLoop.getInfo = () => {
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
return this.RenderLoopConstructor.info;
|
|
53
|
+
}
|
|
47
54
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
55
|
+
// Start the loop automatically
|
|
56
|
+
// animationLoop.start();
|
|
51
57
|
|
|
52
|
-
|
|
53
|
-
this.renderLoop?.onFinalize?.(animationProps);
|
|
58
|
+
return animationLoop;
|
|
54
59
|
}
|
|
55
60
|
}
|
|
56
|
-
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Device } from '@luma.gl/api/';
|
|
2
|
-
import { Program } from '@luma.gl/webgl';
|
|
3
|
-
declare type Module = 'string' | {
|
|
4
|
-
name: string;
|
|
5
|
-
};
|
|
6
|
-
declare type GetProgramOptions = {
|
|
7
|
-
vs?: string;
|
|
8
|
-
fs?: string;
|
|
9
|
-
defines?: {};
|
|
10
|
-
inject?: {};
|
|
11
|
-
varyings?: string[];
|
|
12
|
-
bufferMode?: number;
|
|
13
|
-
modules?: Module[];
|
|
14
|
-
transpileToGLSL100?: boolean;
|
|
15
|
-
};
|
|
16
|
-
export default class ProgramManager {
|
|
17
|
-
readonly device: Device;
|
|
18
|
-
stateHash: number;
|
|
19
|
-
private _hashCounter;
|
|
20
|
-
private readonly _hashes;
|
|
21
|
-
private readonly _useCounts;
|
|
22
|
-
private readonly _programCache;
|
|
23
|
-
private readonly _getUniforms;
|
|
24
|
-
private readonly _registeredModules;
|
|
25
|
-
private readonly _hookFunctions;
|
|
26
|
-
private _defaultModules;
|
|
27
|
-
static getDefaultProgramManager(device: Device): ProgramManager;
|
|
28
|
-
constructor(device: Device);
|
|
29
|
-
addDefaultModule(module: Module): void;
|
|
30
|
-
removeDefaultModule(module: Module): void;
|
|
31
|
-
addShaderHook(hook: any, opts?: any): void;
|
|
32
|
-
get(props?: GetProgramOptions): Program;
|
|
33
|
-
getUniforms(program: Program): any;
|
|
34
|
-
release(program: Program): void;
|
|
35
|
-
_getHash(key: string): string;
|
|
36
|
-
_getModuleList(appModules?: Module[]): Module[];
|
|
37
|
-
}
|
|
38
|
-
export {};
|
|
39
|
-
//# sourceMappingURL=program-manager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"program-manager.d.ts","sourceRoot":"","sources":["../../src/lib/program-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AAErC,OAAO,EAAC,OAAO,EAAC,MAAM,gBAAgB,CAAC;AAEvC,aAAK,MAAM,GAAG,QAAQ,GAAG;IAAC,IAAI,EAAE,MAAM,CAAA;CAAC,CAAC;AAExC,aAAK,iBAAiB,GAAG;IACvB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,EAAE,CAAC;IACb,MAAM,CAAC,EAAE,EAAE,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,cAAc;IACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,SAAS,SAAK;IACd,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAM;IAC9B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAM;IAEjC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAM;IACpC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAM;IACnC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAM;IACzC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAM;IACrC,OAAO,CAAC,eAAe,CAAM;IAE7B,MAAM,CAAC,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc;gBAOnD,MAAM,EAAE,MAAM;IAI1B,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAStC,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAMzC,aAAa,CAAC,IAAI,KAAA,EAAE,IAAI,CAAC,KAAA,GAAG,IAAI;IAShC,GAAG,CAAC,KAAK,GAAE,iBAAsB,GAAG,OAAO;IAqE3C,WAAW,CAAC,OAAO,EAAE,OAAO;IAI5B,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAY/B,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAS7B,cAAc,CAAC,UAAU,GAAE,MAAM,EAAO,GAAG,MAAM,EAAE;CA0BpD"}
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
-
import { assembleShaders } from '@luma.gl/shadertools';
|
|
3
|
-
import { Program } from '@luma.gl/webgl';
|
|
4
|
-
export default class ProgramManager {
|
|
5
|
-
static getDefaultProgramManager(device) {
|
|
6
|
-
device.defaultProgramManager = device.defaultProgramManager || new ProgramManager(device);
|
|
7
|
-
return device.defaultProgramManager;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
constructor(device) {
|
|
11
|
-
_defineProperty(this, "device", void 0);
|
|
12
|
-
|
|
13
|
-
_defineProperty(this, "stateHash", 0);
|
|
14
|
-
|
|
15
|
-
_defineProperty(this, "_hashCounter", 0);
|
|
16
|
-
|
|
17
|
-
_defineProperty(this, "_hashes", {});
|
|
18
|
-
|
|
19
|
-
_defineProperty(this, "_useCounts", {});
|
|
20
|
-
|
|
21
|
-
_defineProperty(this, "_programCache", {});
|
|
22
|
-
|
|
23
|
-
_defineProperty(this, "_getUniforms", {});
|
|
24
|
-
|
|
25
|
-
_defineProperty(this, "_registeredModules", {});
|
|
26
|
-
|
|
27
|
-
_defineProperty(this, "_hookFunctions", []);
|
|
28
|
-
|
|
29
|
-
_defineProperty(this, "_defaultModules", []);
|
|
30
|
-
|
|
31
|
-
this.device = device;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
addDefaultModule(module) {
|
|
35
|
-
if (!this._defaultModules.find(m => m.name === module.name)) {
|
|
36
|
-
this._defaultModules.push(module);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
this.stateHash++;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
removeDefaultModule(module) {
|
|
43
|
-
const moduleName = typeof module === 'string' ? module : module.name;
|
|
44
|
-
this._defaultModules = this._defaultModules.filter(m => m.name !== moduleName);
|
|
45
|
-
this.stateHash++;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
addShaderHook(hook, opts) {
|
|
49
|
-
if (opts) {
|
|
50
|
-
hook = Object.assign(opts, {
|
|
51
|
-
hook
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
this._hookFunctions.push(hook);
|
|
56
|
-
|
|
57
|
-
this.stateHash++;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
get(props = {}) {
|
|
61
|
-
const {
|
|
62
|
-
vs = '',
|
|
63
|
-
fs = '',
|
|
64
|
-
defines = {},
|
|
65
|
-
inject = {},
|
|
66
|
-
varyings = [],
|
|
67
|
-
bufferMode = 0x8c8d,
|
|
68
|
-
transpileToGLSL100 = false
|
|
69
|
-
} = props;
|
|
70
|
-
|
|
71
|
-
const modules = this._getModuleList(props.modules);
|
|
72
|
-
|
|
73
|
-
const vsHash = this._getHash(vs);
|
|
74
|
-
|
|
75
|
-
const fsHash = this._getHash(fs);
|
|
76
|
-
|
|
77
|
-
const moduleHashes = modules.map(m => this._getHash(m.name)).sort();
|
|
78
|
-
const varyingHashes = varyings.map(v => this._getHash(v));
|
|
79
|
-
const defineKeys = Object.keys(defines).sort();
|
|
80
|
-
const injectKeys = Object.keys(inject).sort();
|
|
81
|
-
const defineHashes = [];
|
|
82
|
-
const injectHashes = [];
|
|
83
|
-
|
|
84
|
-
for (const key of defineKeys) {
|
|
85
|
-
defineHashes.push(this._getHash(key));
|
|
86
|
-
defineHashes.push(this._getHash(defines[key]));
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
for (const key of injectKeys) {
|
|
90
|
-
injectHashes.push(this._getHash(key));
|
|
91
|
-
injectHashes.push(this._getHash(inject[key]));
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const hash = "".concat(vsHash, "/").concat(fsHash, "D").concat(defineHashes.join('/'), "M").concat(moduleHashes.join('/'), "I").concat(injectHashes.join('/'), "V").concat(varyingHashes.join('/'), "H").concat(this.stateHash, "B").concat(bufferMode).concat(transpileToGLSL100 ? 'T' : '');
|
|
95
|
-
|
|
96
|
-
if (!this._programCache[hash]) {
|
|
97
|
-
const assembled = assembleShaders(this.device, {
|
|
98
|
-
vs,
|
|
99
|
-
fs,
|
|
100
|
-
modules,
|
|
101
|
-
inject,
|
|
102
|
-
defines,
|
|
103
|
-
hookFunctions: this._hookFunctions,
|
|
104
|
-
transpileToGLSL100
|
|
105
|
-
});
|
|
106
|
-
this._programCache[hash] = new Program(this.device.gl, {
|
|
107
|
-
hash,
|
|
108
|
-
vs: assembled.vs,
|
|
109
|
-
fs: assembled.fs,
|
|
110
|
-
varyings,
|
|
111
|
-
bufferMode
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
this._getUniforms[hash] = assembled.getUniforms || (x => {});
|
|
115
|
-
|
|
116
|
-
this._useCounts[hash] = 0;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
this._useCounts[hash]++;
|
|
120
|
-
return this._programCache[hash];
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
getUniforms(program) {
|
|
124
|
-
return this._getUniforms[program.hash] || null;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
release(program) {
|
|
128
|
-
const hash = program.hash;
|
|
129
|
-
this._useCounts[hash]--;
|
|
130
|
-
|
|
131
|
-
if (this._useCounts[hash] === 0) {
|
|
132
|
-
this._programCache[hash].delete();
|
|
133
|
-
|
|
134
|
-
delete this._programCache[hash];
|
|
135
|
-
delete this._getUniforms[hash];
|
|
136
|
-
delete this._useCounts[hash];
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
_getHash(key) {
|
|
141
|
-
if (this._hashes[key] === undefined) {
|
|
142
|
-
this._hashes[key] = this._hashCounter++;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return this._hashes[key];
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
_getModuleList(appModules = []) {
|
|
149
|
-
const modules = new Array(this._defaultModules.length + appModules.length);
|
|
150
|
-
const seen = {};
|
|
151
|
-
let count = 0;
|
|
152
|
-
|
|
153
|
-
for (let i = 0, len = this._defaultModules.length; i < len; ++i) {
|
|
154
|
-
const module = this._defaultModules[i];
|
|
155
|
-
const name = module.name;
|
|
156
|
-
modules[count++] = module;
|
|
157
|
-
seen[name] = true;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
for (let i = 0, len = appModules.length; i < len; ++i) {
|
|
161
|
-
const module = appModules[i];
|
|
162
|
-
const name = module.name;
|
|
163
|
-
|
|
164
|
-
if (!seen[name]) {
|
|
165
|
-
modules[count++] = module;
|
|
166
|
-
seen[name] = true;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
modules.length = count;
|
|
171
|
-
return modules;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
//# sourceMappingURL=program-manager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/program-manager.ts"],"names":["assembleShaders","Program","ProgramManager","getDefaultProgramManager","device","defaultProgramManager","constructor","addDefaultModule","module","_defaultModules","find","m","name","push","stateHash","removeDefaultModule","moduleName","filter","addShaderHook","hook","opts","Object","assign","_hookFunctions","get","props","vs","fs","defines","inject","varyings","bufferMode","transpileToGLSL100","modules","_getModuleList","vsHash","_getHash","fsHash","moduleHashes","map","sort","varyingHashes","v","defineKeys","keys","injectKeys","defineHashes","injectHashes","key","hash","join","_programCache","assembled","hookFunctions","gl","_getUniforms","getUniforms","x","_useCounts","program","release","delete","_hashes","undefined","_hashCounter","appModules","Array","length","seen","count","i","len"],"mappings":";AACA,SAAQA,eAAR,QAA8B,sBAA9B;AACA,SAAQC,OAAR,QAAsB,gBAAtB;AAeA,eAAe,MAAMC,cAAN,CAAqB;AAcH,SAAxBC,wBAAwB,CAACC,MAAD,EAAiC;AAE9DA,IAAAA,MAAM,CAACC,qBAAP,GAA+BD,MAAM,CAACC,qBAAP,IAAgC,IAAIH,cAAJ,CAAmBE,MAAnB,CAA/D;AAEA,WAAOA,MAAM,CAACC,qBAAd;AACD;;AAEDC,EAAAA,WAAW,CAACF,MAAD,EAAiB;AAAA;;AAAA,uCAlBhB,CAkBgB;;AAAA,0CAjBL,CAiBK;;AAAA,qCAhBD,EAgBC;;AAAA,wCAfE,EAeF;;AAAA,2CAbK,EAaL;;AAAA,0CAZI,EAYJ;;AAAA,gDAXU,EAWV;;AAAA,4CAVM,EAUN;;AAAA,6CATF,EASE;;AAC1B,SAAKA,MAAL,GAAcA,MAAd;AACD;;AAEDG,EAAAA,gBAAgB,CAACC,MAAD,EAAuB;AAErC,QAAI,CAAC,KAAKC,eAAL,CAAqBC,IAArB,CAA2BC,CAAD,IAAOA,CAAC,CAACC,IAAF,KAAWJ,MAAM,CAACI,IAAnD,CAAL,EAA+D;AAC7D,WAAKH,eAAL,CAAqBI,IAArB,CAA0BL,MAA1B;AACD;;AAED,SAAKM,SAAL;AACD;;AAEDC,EAAAA,mBAAmB,CAACP,MAAD,EAAuB;AACxC,UAAMQ,UAAU,GAAG,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/shadertools';\nimport {Program} from '@luma.gl/webgl';\n\ntype Module = 'string' | {name: string}; // TODO\n\ntype GetProgramOptions = {\n vs?: string,\n fs?: string,\n defines?: {},\n inject?: {},\n varyings?: string[],\n bufferMode?: number,\n modules?: Module[];\n transpileToGLSL100?: boolean\n};\n\nexport default class ProgramManager {\n readonly device: Device;\n\n stateHash = 0; // Used change hashing if hooks are modified\n private _hashCounter = 0;\n private readonly _hashes = {};\n private readonly _useCounts = {};\n\n private readonly _programCache = {};\n private readonly _getUniforms = {};\n private readonly _registeredModules = {}; // TODO: Remove? This isn't used anywhere in luma.gl\n private readonly _hookFunctions = [];\n private _defaultModules = [];\n\n static getDefaultProgramManager(device: Device): ProgramManager {\n // @ts-expect-error\n device.defaultProgramManager = device.defaultProgramManager || new ProgramManager(device);\n // @ts-expect-error\n return device.defaultProgramManager;\n }\n\n constructor(device: Device) {\n this.device = device;\n }\n\n addDefaultModule(module: Module): void {\n // @ts-expect-error\n if (!this._defaultModules.find((m) => m.name === module.name)) {\n this._defaultModules.push(module);\n }\n\n this.stateHash++;\n }\n\n removeDefaultModule(module: Module): void {\n const moduleName = typeof module === 'string' ? module : module.name;\n this._defaultModules = this._defaultModules.filter((m) => m.name !== moduleName);\n this.stateHash++;\n }\n\n addShaderHook(hook, opts?): void {\n if (opts) {\n hook = Object.assign(opts, {hook});\n }\n\n this._hookFunctions.push(hook);\n this.stateHash++;\n }\n\n get(props: GetProgramOptions = {}): Program {\n const {\n vs = '',\n fs = '',\n defines = {},\n inject = {},\n varyings = [],\n bufferMode = 0x8c8d,\n transpileToGLSL100 = false\n } = props; // varyings/bufferMode for xform feedback, 0x8c8d = SEPARATE_ATTRIBS\n\n const modules = this._getModuleList(props.modules); // Combine with default modules\n\n const vsHash = this._getHash(vs);\n const fsHash = this._getHash(fs);\n // @ts-expect-error\n const moduleHashes = modules.map((m) => this._getHash(m.name)).sort();\n const varyingHashes = varyings.map((v) => this._getHash(v));\n\n const defineKeys = Object.keys(defines).sort();\n const injectKeys = Object.keys(inject).sort();\n const defineHashes = [];\n const injectHashes = [];\n\n for (const key of defineKeys) {\n defineHashes.push(this._getHash(key));\n defineHashes.push(this._getHash(defines[key]));\n }\n\n for (const key of injectKeys) {\n injectHashes.push(this._getHash(key));\n injectHashes.push(this._getHash(inject[key]));\n }\n\n const hash = `${vsHash}/${fsHash}D${defineHashes.join('/')}M${moduleHashes.join(\n '/'\n )}I${injectHashes.join('/')}V${varyingHashes.join('/')}H${this.stateHash}B${bufferMode}${\n transpileToGLSL100 ? 'T' : ''\n }`;\n\n if (!this._programCache[hash]) {\n const assembled = assembleShaders(this.device, {\n vs,\n fs,\n modules,\n inject,\n defines,\n hookFunctions: this._hookFunctions,\n transpileToGLSL100\n });\n\n // @ts-expect-error TODO - program should be created from device\n this._programCache[hash] = new Program(this.device.gl, {\n hash,\n vs: assembled.vs,\n fs: assembled.fs,\n varyings,\n bufferMode\n });\n\n this._getUniforms[hash] = assembled.getUniforms || ((x) => {});\n this._useCounts[hash] = 0;\n }\n\n this._useCounts[hash]++;\n\n return this._programCache[hash];\n }\n\n getUniforms(program: Program) {\n return this._getUniforms[program.hash] || null;\n }\n\n release(program: Program): void {\n const hash = program.hash;\n this._useCounts[hash]--;\n\n if (this._useCounts[hash] === 0) {\n this._programCache[hash].delete();\n delete this._programCache[hash];\n delete this._getUniforms[hash];\n delete this._useCounts[hash];\n }\n }\n\n _getHash(key: string): string {\n if (this._hashes[key] === undefined) {\n this._hashes[key] = this._hashCounter++;\n }\n\n return this._hashes[key];\n }\n\n // Dedup and combine with default modules\n _getModuleList(appModules: Module[] = []): Module[] {\n const modules = new Array(this._defaultModules.length + appModules.length);\n const seen = {};\n let count = 0;\n\n for (let i = 0, len = this._defaultModules.length; i < len; ++i) {\n const module = this._defaultModules[i];\n const name = module.name;\n modules[count++] = module;\n seen[name] = true;\n }\n\n for (let i = 0, len = appModules.length; i < len; ++i) {\n const module = appModules[i];\n // @ts-expect-error\n const name = module.name;\n if (!seen[name]) {\n modules[count++] = module;\n seen[name] = true;\n }\n }\n\n modules.length = count;\n\n return modules;\n }\n}\n"],"file":"program-manager.js"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { Buffer } from '@luma.gl/webgl';
|
|
2
|
-
import type { TransformProps, TransformDrawOptions, TransformRunOptions, TransformBinding } from './transform-types';
|
|
3
|
-
export default class BufferTransform {
|
|
4
|
-
gl: WebGL2RenderingContext;
|
|
5
|
-
currentIndex: number;
|
|
6
|
-
feedbackMap: {};
|
|
7
|
-
varyings: string[] | null;
|
|
8
|
-
bindings: TransformBinding[];
|
|
9
|
-
resources: {};
|
|
10
|
-
constructor(gl: WebGL2RenderingContext, props?: TransformProps);
|
|
11
|
-
setupResources(opts: any): void;
|
|
12
|
-
updateModelProps(props?: TransformProps): TransformProps;
|
|
13
|
-
getDrawOptions(opts?: TransformRunOptions): TransformDrawOptions;
|
|
14
|
-
swap(): boolean;
|
|
15
|
-
update(opts?: {}): void;
|
|
16
|
-
getBuffer(varyingName: string | null): Buffer | null;
|
|
17
|
-
getData(options?: {
|
|
18
|
-
varyingName?: string;
|
|
19
|
-
}): any;
|
|
20
|
-
delete(): void;
|
|
21
|
-
_initialize(props?: TransformProps): void;
|
|
22
|
-
_getFeedbackBuffers(props: any): {};
|
|
23
|
-
_setupBuffers(props?: {}): void;
|
|
24
|
-
_setupTransformFeedback(binding: any, { model }: {
|
|
25
|
-
model: any;
|
|
26
|
-
}): void;
|
|
27
|
-
_updateBindings(opts: any): void;
|
|
28
|
-
_updateBinding(binding: any, opts: any): any;
|
|
29
|
-
_swapBuffers(opts: any): {
|
|
30
|
-
sourceBuffers: any;
|
|
31
|
-
feedbackBuffers: any;
|
|
32
|
-
};
|
|
33
|
-
_createNewBuffer(name: any, opts: any): Buffer;
|
|
34
|
-
_getNextIndex(): number;
|
|
35
|
-
}
|
|
36
|
-
//# sourceMappingURL=buffer-transform.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bu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