@luma.gl/engine 9.0.11 → 9.1.0-alpha.2
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/LICENSE +34 -0
- package/dist/animation/key-frames.d.ts.map +1 -1
- package/dist/animation/key-frames.js +3 -0
- package/dist/animation-loop/animation-loop-template.d.ts.map +1 -1
- package/dist/animation-loop/animation-loop-template.js +3 -0
- package/dist/animation-loop/animation-loop.d.ts +1 -1
- package/dist/animation-loop/animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/animation-loop.js +5 -4
- package/dist/animation-loop/animation-props.d.ts.map +1 -1
- package/dist/animation-loop/animation-props.js +3 -0
- package/dist/animation-loop/request-animation-frame.d.ts +3 -0
- package/dist/animation-loop/request-animation-frame.d.ts.map +1 -0
- package/dist/animation-loop/request-animation-frame.js +16 -0
- package/dist/application-utils/load-file.d.ts +22 -0
- package/dist/application-utils/load-file.d.ts.map +1 -0
- package/dist/application-utils/load-file.js +43 -0
- package/dist/application-utils/random.d.ts +3 -0
- package/dist/application-utils/random.d.ts.map +1 -0
- package/dist/application-utils/random.js +16 -0
- package/dist/async-texture/async-texture.d.ts +50 -0
- package/dist/async-texture/async-texture.d.ts.map +1 -0
- package/dist/async-texture/async-texture.js +77 -0
- package/dist/computation.d.ts +4 -3
- package/dist/computation.d.ts.map +1 -1
- package/dist/computation.js +14 -6
- package/dist/debug/copy-texture-to-image.d.ts.map +1 -1
- package/dist/debug/copy-texture-to-image.js +4 -1
- package/dist/debug/debug-framebuffer.d.ts.map +1 -1
- package/dist/debug/debug-framebuffer.js +17 -12
- package/dist/debug/pixel-data-utils.d.ts +1 -1
- package/dist/dist.dev.js +1291 -648
- package/dist/dist.min.js +30 -28
- package/dist/geometries/cone-geometry.d.ts.map +1 -1
- package/dist/geometries/cone-geometry.js +4 -1
- package/dist/geometries/cube-geometry.d.ts.map +1 -1
- package/dist/geometries/cube-geometry.js +4 -1
- package/dist/geometries/cylinder-geometry.d.ts.map +1 -1
- package/dist/geometries/cylinder-geometry.js +4 -1
- package/dist/geometries/ico-sphere-geometry.d.ts.map +1 -1
- package/dist/geometries/ico-sphere-geometry.js +4 -1
- package/dist/geometries/plane-geometry.d.ts.map +1 -1
- package/dist/geometries/plane-geometry.js +4 -1
- package/dist/geometries/sphere-geometry.d.ts.map +1 -1
- package/dist/geometries/sphere-geometry.js +4 -1
- package/dist/geometries/truncated-cone-geometry.d.ts.map +1 -1
- package/dist/geometries/truncated-cone-geometry.js +4 -1
- package/dist/geometry/geometry-table.d.ts +2 -1
- package/dist/geometry/geometry-table.d.ts.map +1 -1
- package/dist/geometry/geometry-utils.d.ts.map +1 -1
- package/dist/geometry/geometry-utils.js +3 -1
- package/dist/geometry/geometry.d.ts +5 -4
- package/dist/geometry/geometry.d.ts.map +1 -1
- package/dist/geometry/geometry.js +9 -5
- package/dist/geometry/gpu-geometry.d.ts +1 -1
- package/dist/geometry/gpu-geometry.d.ts.map +1 -1
- package/dist/geometry/gpu-geometry.js +18 -6
- package/dist/geometry/gpu-table.js +3 -0
- package/dist/index.cjs +491 -244
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/lib/clip-space.d.ts.map +1 -1
- package/dist/lib/clip-space.js +3 -0
- package/dist/lib/pipeline-factory.d.ts +3 -2
- package/dist/lib/pipeline-factory.d.ts.map +1 -1
- package/dist/lib/pipeline-factory.js +12 -8
- package/dist/lib/shader-factory.d.ts +3 -2
- package/dist/lib/shader-factory.d.ts.map +1 -1
- package/dist/lib/shader-factory.js +11 -4
- package/dist/model/model.d.ts +10 -6
- package/dist/model/model.d.ts.map +1 -1
- package/dist/model/model.js +65 -8
- package/dist/model/split-uniforms-and-bindings.d.ts +9 -0
- package/dist/model/split-uniforms-and-bindings.d.ts.map +1 -0
- package/dist/model/split-uniforms-and-bindings.js +20 -0
- package/dist/scenegraph/group-node.d.ts +1 -1
- package/dist/scenegraph/group-node.d.ts.map +1 -1
- package/dist/scenegraph/group-node.js +3 -0
- package/dist/scenegraph/model-node.d.ts +2 -2
- package/dist/scenegraph/model-node.d.ts.map +1 -1
- package/dist/scenegraph/model-node.js +6 -3
- package/dist/scenegraph/scenegraph-node.d.ts +5 -6
- package/dist/scenegraph/scenegraph-node.d.ts.map +1 -1
- package/dist/scenegraph/scenegraph-node.js +11 -8
- package/dist/shader-inputs.d.ts +2 -3
- package/dist/shader-inputs.d.ts.map +1 -1
- package/dist/shader-inputs.js +7 -5
- package/dist/transform/buffer-transform.d.ts.map +1 -1
- package/dist/transform/buffer-transform.js +8 -2
- package/dist/transform/texture-transform.d.ts +2 -2
- package/dist/transform/texture-transform.d.ts.map +1 -1
- package/dist/transform/texture-transform.js +1 -0
- package/dist/utils/deep-equal.d.ts +9 -0
- package/dist/utils/deep-equal.d.ts.map +1 -0
- package/dist/utils/deep-equal.js +50 -0
- package/dist/utils/uid.d.ts +7 -0
- package/dist/utils/uid.d.ts.map +1 -0
- package/dist/utils/uid.js +14 -0
- package/package.json +7 -6
- package/src/animation/key-frames.ts +4 -0
- package/src/animation-loop/animation-loop-template.ts +4 -0
- package/src/animation-loop/animation-loop.ts +6 -4
- package/src/animation-loop/animation-props.ts +4 -0
- package/src/animation-loop/request-animation-frame.ts +19 -0
- package/src/application-utils/load-file.ts +53 -0
- package/src/application-utils/random.ts +18 -0
- package/src/async-texture/async-texture.ts +140 -0
- package/src/computation.ts +17 -9
- package/src/debug/copy-texture-to-image.ts +4 -1
- package/src/debug/debug-framebuffer.ts +18 -12
- package/src/debug/pixel-data-utils.ts +1 -1
- package/src/geometries/cone-geometry.ts +5 -1
- package/src/geometries/cube-geometry.ts +5 -1
- package/src/geometries/cylinder-geometry.ts +5 -1
- package/src/geometries/ico-sphere-geometry.ts +5 -1
- package/src/geometries/plane-geometry.ts +5 -1
- package/src/geometries/sphere-geometry.ts +5 -1
- package/src/geometries/truncated-cone-geometry.ts +5 -1
- package/src/geometry/geometry-table.ts +2 -1
- package/src/geometry/geometry-utils.ts +3 -1
- package/src/geometry/geometry.ts +16 -19
- package/src/geometry/gpu-geometry.ts +20 -14
- package/src/geometry/gpu-table.ts +4 -0
- package/src/index.ts +15 -0
- package/src/lib/clip-space.ts +4 -0
- package/src/lib/pipeline-factory.ts +17 -16
- package/src/lib/shader-factory.ts +13 -6
- package/src/model/model.ts +71 -17
- package/src/model/split-uniforms-and-bindings.ts +31 -0
- package/src/scenegraph/group-node.ts +4 -0
- package/src/scenegraph/model-node.ts +9 -5
- package/src/scenegraph/scenegraph-node.ts +17 -13
- package/src/shader-inputs.ts +8 -6
- package/src/transform/buffer-transform.ts +8 -9
- package/src/transform/texture-transform.ts +2 -1
- package/src/utils/deep-equal.ts +51 -0
- package/src/utils/uid.ts +16 -0
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
2
4
|
import { Vector3, Matrix4 } from '@math.gl/core';
|
|
5
|
+
import { uid } from "../utils/uid.js";
|
|
3
6
|
export class ScenegraphNode {
|
|
4
7
|
id;
|
|
5
8
|
matrix = new Matrix4();
|
|
@@ -30,17 +33,17 @@ export class ScenegraphNode {
|
|
|
30
33
|
return `{type: ScenegraphNode, id: ${this.id})}`;
|
|
31
34
|
}
|
|
32
35
|
setPosition(position) {
|
|
33
|
-
assert(position.length === 3, 'setPosition requires vector argument');
|
|
36
|
+
// assert(position.length === 3, 'setPosition requires vector argument');
|
|
34
37
|
this.position = position;
|
|
35
38
|
return this;
|
|
36
39
|
}
|
|
37
40
|
setRotation(rotation) {
|
|
38
|
-
assert(rotation.length === 3, 'setRotation requires vector argument');
|
|
41
|
+
// assert(rotation.length === 3, 'setRotation requires vector argument');
|
|
39
42
|
this.rotation = rotation;
|
|
40
43
|
return this;
|
|
41
44
|
}
|
|
42
45
|
setScale(scale) {
|
|
43
|
-
assert(scale.length === 3, 'setScale requires vector argument');
|
|
46
|
+
// assert(scale.length === 3, 'setScale requires vector argument');
|
|
44
47
|
this.scale = scale;
|
|
45
48
|
return this;
|
|
46
49
|
}
|
|
@@ -95,7 +98,7 @@ export class ScenegraphNode {
|
|
|
95
98
|
getCoordinateUniforms(viewMatrix, modelMatrix) {
|
|
96
99
|
// TODO - solve multiple class problem
|
|
97
100
|
// assert(viewMatrix instanceof Matrix4);
|
|
98
|
-
assert(viewMatrix);
|
|
101
|
+
// assert(viewMatrix);
|
|
99
102
|
modelMatrix = modelMatrix || this.matrix;
|
|
100
103
|
const worldMatrix = new Matrix4(viewMatrix).multiplyRight(modelMatrix);
|
|
101
104
|
const worldInverse = worldMatrix.invert();
|
|
@@ -132,9 +135,9 @@ export class ScenegraphNode {
|
|
|
132
135
|
}
|
|
133
136
|
*/
|
|
134
137
|
_setScenegraphNodeProps(props) {
|
|
135
|
-
if ('display' in props) {
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
+
// if ('display' in props) {
|
|
139
|
+
// this.display = props.display;
|
|
140
|
+
// }
|
|
138
141
|
if ('position' in props) {
|
|
139
142
|
this.setPosition(props.position);
|
|
140
143
|
}
|
package/dist/shader-inputs.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { UniformValue, Texture, Sampler } from '@luma.gl/core';
|
|
2
|
-
import {
|
|
2
|
+
import { ShaderModule } from '@luma.gl/shadertools';
|
|
3
3
|
/** Minimal ShaderModule subset, we don't need shader code etc */
|
|
4
4
|
export type ShaderModuleInputs<PropsT extends Record<string, unknown> = Record<string, unknown>, UniformsT extends Record<string, UniformValue> = Record<string, UniformValue>, BindingsT extends Record<string, Texture | Sampler> = Record<string, Texture | Sampler>> = {
|
|
5
5
|
defaultUniforms?: UniformsT;
|
|
@@ -32,7 +32,6 @@ export declare class ShaderInputs<ShaderPropsT extends Partial<Record<string, Re
|
|
|
32
32
|
/** Stores the uniform bindings for each module */
|
|
33
33
|
moduleBindings: Record<keyof ShaderPropsT, Record<string, Texture | Sampler>>;
|
|
34
34
|
/** Tracks if uniforms have changed */
|
|
35
|
-
moduleUniformsChanged: Record<keyof ShaderPropsT, false | string>;
|
|
36
35
|
/**
|
|
37
36
|
* Create a new UniformStore instance
|
|
38
37
|
* @param modules
|
|
@@ -53,7 +52,7 @@ export declare class ShaderInputs<ShaderPropsT extends Partial<Record<string, Re
|
|
|
53
52
|
* Return the map of modules
|
|
54
53
|
* @todo should should this include the resolved dependencies?
|
|
55
54
|
*/
|
|
56
|
-
getModules():
|
|
55
|
+
getModules(): ShaderModule[];
|
|
57
56
|
/** Get all uniform values for all modules */
|
|
58
57
|
getUniformValues(): Record<keyof ShaderPropsT, Record<string, UniformValue>>;
|
|
59
58
|
/** Merges all bindings for the shader (from the various modules) */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shader-inputs.d.ts","sourceRoot":"","sources":["../src/shader-inputs.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,YAAY,EAAE,OAAO,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAGlE,OAAO,
|
|
1
|
+
{"version":3,"file":"shader-inputs.d.ts","sourceRoot":"","sources":["../src/shader-inputs.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,YAAY,EAAE,OAAO,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAGlE,OAAO,EAA8B,YAAY,EAAC,MAAM,sBAAsB,CAAC;AAE/E,iEAAiE;AACjE,MAAM,MAAM,kBAAkB,CAC5B,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChE,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,EAC7E,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,E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AEG;IACH,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;SAAE,CAAC,IAAI,MAAM,YAAY,CAAC,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;KAAC,CAAC,GAAG,IAAI;IA0BtF,oEAAoE;IAKpE;;;OAGG;IACH,UAAU,IAAI,YAAY,EAAE;IAI5B,6CAA6C;IAC7C,gBAAgB,IAAI,MAAM,CAAC,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAI5E,oEAAoE;IACpE,WAAW,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC;IAQhD,aAAa,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAYzD"}
|
package/dist/shader-inputs.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
import { log } from '@luma.gl/core';
|
|
5
5
|
// import type {ShaderUniformType, UniformValue, UniformFormat, UniformInfoDevice, Texture, Sampler} from '@luma.gl/core';
|
|
6
|
-
import {
|
|
6
|
+
import { getShaderModuleDependencies } from '@luma.gl/shadertools';
|
|
7
7
|
/**
|
|
8
8
|
* ShaderInputs holds uniform and binding values for one or more shader modules,
|
|
9
9
|
* - It can generate binary data for any uniform buffer
|
|
@@ -16,20 +16,22 @@ export class ShaderInputs {
|
|
|
16
16
|
* The map of modules
|
|
17
17
|
* @todo should should this include the resolved dependencies?
|
|
18
18
|
*/
|
|
19
|
+
// @ts-expect-error Fix typings
|
|
19
20
|
modules;
|
|
20
21
|
/** Stores the uniform values for each module */
|
|
21
22
|
moduleUniforms;
|
|
22
23
|
/** Stores the uniform bindings for each module */
|
|
23
24
|
moduleBindings;
|
|
24
25
|
/** Tracks if uniforms have changed */
|
|
25
|
-
moduleUniformsChanged
|
|
26
|
+
// moduleUniformsChanged: Record<keyof ShaderPropsT, false | string>;
|
|
26
27
|
/**
|
|
27
28
|
* Create a new UniformStore instance
|
|
28
29
|
* @param modules
|
|
29
30
|
*/
|
|
31
|
+
// @ts-expect-error Fix typings
|
|
30
32
|
constructor(modules) {
|
|
31
33
|
// TODO - get all dependencies from modules
|
|
32
|
-
const allModules =
|
|
34
|
+
const allModules = getShaderModuleDependencies(Object.values(modules));
|
|
33
35
|
log.log(1, 'Creating ShaderInputs with modules', allModules.map(m => m.name))();
|
|
34
36
|
// Store the module definitions and create storage for uniform values and binding values, per module
|
|
35
37
|
this.modules = modules;
|
|
@@ -51,7 +53,7 @@ export class ShaderInputs {
|
|
|
51
53
|
setProps(props) {
|
|
52
54
|
for (const name of Object.keys(props)) {
|
|
53
55
|
const moduleName = name;
|
|
54
|
-
const moduleProps = props[moduleName];
|
|
56
|
+
const moduleProps = props[moduleName] || {};
|
|
55
57
|
const module = this.modules[moduleName];
|
|
56
58
|
if (!module) {
|
|
57
59
|
// Ignore props for unregistered modules
|
|
@@ -62,7 +64,7 @@ export class ShaderInputs {
|
|
|
62
64
|
const uniforms = module.getUniforms?.(moduleProps, this.moduleUniforms[moduleName]) || moduleProps;
|
|
63
65
|
// console.error(uniforms)
|
|
64
66
|
this.moduleUniforms[moduleName] = { ...oldUniforms, ...uniforms };
|
|
65
|
-
// this.moduleUniformsChanged ||= moduleName;
|
|
67
|
+
// // this.moduleUniformsChanged ||= moduleName;
|
|
66
68
|
// console.log(`setProps(${String(moduleName)}`, moduleName, this.moduleUniforms[moduleName])
|
|
67
69
|
// TODO - Get Module bindings
|
|
68
70
|
// const bindings = module.getBindings?.(moduleProps);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffer-transform.d.ts","sourceRoot":"","sources":["../../src/transform/buffer-transform.ts"],"names":[],"mappings":"AAIA,OAAO,
|
|
1
|
+
{"version":3,"file":"buffer-transform.d.ts","sourceRoot":"","sources":["../../src/transform/buffer-transform.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,MAAM,E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} from '@luma.gl/core';
|
|
5
5
|
import { getPassthroughFS } from '@luma.gl/shadertools';
|
|
6
6
|
import { Model } from "../model/model.js";
|
|
7
7
|
/**
|
|
@@ -17,7 +17,9 @@ export class BufferTransform {
|
|
|
17
17
|
return device?.info?.type === 'webgl';
|
|
18
18
|
}
|
|
19
19
|
constructor(device, props = Model.defaultProps) {
|
|
20
|
-
|
|
20
|
+
if (!BufferTransform.isSupported(device)) {
|
|
21
|
+
throw new Error('BufferTransform not yet implemented on WebGPU');
|
|
22
|
+
}
|
|
21
23
|
this.device = device;
|
|
22
24
|
this.model = new Model(this.device, {
|
|
23
25
|
id: props.id || 'buffer-transform-model',
|
|
@@ -27,6 +29,7 @@ export class BufferTransform {
|
|
|
27
29
|
});
|
|
28
30
|
this.transformFeedback = this.device.createTransformFeedback({
|
|
29
31
|
layout: this.model.pipeline.shaderLayout,
|
|
32
|
+
// @ts-expect-error TODO
|
|
30
33
|
buffers: props.feedbackBuffers
|
|
31
34
|
});
|
|
32
35
|
this.model.setTransformFeedback(this.transformFeedback);
|
|
@@ -61,6 +64,9 @@ export class BufferTransform {
|
|
|
61
64
|
}
|
|
62
65
|
readAsync(varyingName) {
|
|
63
66
|
const result = this.getBuffer(varyingName);
|
|
67
|
+
if (!result) {
|
|
68
|
+
throw new Error('BufferTransform#getBuffer');
|
|
69
|
+
}
|
|
64
70
|
if (result instanceof Buffer) {
|
|
65
71
|
return result.readAsync();
|
|
66
72
|
}
|
|
@@ -44,10 +44,10 @@ export declare class TextureTransform {
|
|
|
44
44
|
/** @deprecated */
|
|
45
45
|
update(...args: any[]): void;
|
|
46
46
|
getData({ packed }?: {
|
|
47
|
-
packed?: boolean;
|
|
47
|
+
packed?: boolean | undefined;
|
|
48
48
|
}): void;
|
|
49
49
|
getTargetTexture(): Texture;
|
|
50
|
-
getFramebuffer(): Framebuffer;
|
|
50
|
+
getFramebuffer(): Framebuffer | undefined;
|
|
51
51
|
_initialize(props: TextureTransformProps): void;
|
|
52
52
|
_updateBindings(props: TextureTransformProps): void;
|
|
53
53
|
_updateBinding(binding: TextureBinding, { sourceBuffers, sourceTextures, targetTexture }: TextureTransformProps): TextureBinding;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"texture-transform.d.ts","sourceRoot":"","sources":["../../src/transform/texture-transform.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,eAAe,EAAE,OAAO,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAC7F,OAAO,EAAC,KAAK,EAAE,UAAU,EAAC,0BAAuB;AAGjD;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAAG,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,GAAG;IAC3D,EAAE,CAAC,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;IACtB,4CAA4C;IAC5C,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,4CAA4C;IAC5C,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,gEAAgE;IAChE,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,gEAAgE;IAChE,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,aAAa,EAAE,OAAO,CAAC;IACvB,qBAAqB,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACrC,oBAAoB,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF,KAAK,cAAc,GAAG;IACpB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,aAAa,EAAE,OAAO,CAAC;IACvB,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B,CAAC;AAIF;;;GAGG;AACH,qBAAa,gBAAgB;IAC3B,QAAQ,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AG,IAAI;IAI/C,eAAe,CAAC,KAAK,EAAE,qBAAqB;IAI5C,cAAc,CACZ,OAAO,EAAE,cAAc,EACvB,EAAC,aAAa,EAAE,cAAc,EAAE,aAAa,EAAC,EAAE,qBAAqB,GACpE,cAAc;IA8BjB,2BAA2B,IAAI,IAAI;CAOpC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fast partial deep equal for prop.
|
|
3
|
+
*
|
|
4
|
+
* @param a Prop
|
|
5
|
+
* @param b Prop to compare against `a`
|
|
6
|
+
* @param depth Depth to which to recurse in nested Objects/Arrays. Use 0 (default) for shallow comparison, -1 for infinite depth
|
|
7
|
+
*/
|
|
8
|
+
export declare function deepEqual(a: any, b: any, depth: number): boolean;
|
|
9
|
+
//# sourceMappingURL=deep-equal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deep-equal.d.ts","sourceRoot":"","sources":["../../src/utils/deep-equal.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AAEH,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAsChE"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
/**
|
|
5
|
+
* Fast partial deep equal for prop.
|
|
6
|
+
*
|
|
7
|
+
* @param a Prop
|
|
8
|
+
* @param b Prop to compare against `a`
|
|
9
|
+
* @param depth Depth to which to recurse in nested Objects/Arrays. Use 0 (default) for shallow comparison, -1 for infinite depth
|
|
10
|
+
*/
|
|
11
|
+
/* eslint-disable complexity */
|
|
12
|
+
export function deepEqual(a, b, depth) {
|
|
13
|
+
if (a === b) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
if (!depth || !a || !b) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
if (Array.isArray(a)) {
|
|
20
|
+
if (!Array.isArray(b) || a.length !== b.length) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
for (let i = 0; i < a.length; i++) {
|
|
24
|
+
if (!deepEqual(a[i], b[i], depth - 1)) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
if (Array.isArray(b)) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
if (typeof a === 'object' && typeof b === 'object') {
|
|
34
|
+
const aKeys = Object.keys(a);
|
|
35
|
+
const bKeys = Object.keys(b);
|
|
36
|
+
if (aKeys.length !== bKeys.length) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
for (const key of aKeys) {
|
|
40
|
+
if (!b.hasOwnProperty(key)) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
if (!deepEqual(a[key], b[key], depth - 1)) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uid.d.ts","sourceRoot":"","sources":["../../src/utils/uid.ts"],"names":[],"mappings":"AAMA;;;;IAII;AACJ,wBAAgB,GAAG,CAAC,EAAE,GAAE,MAAa,GAAG,MAAM,CAI7C"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
const uidCounters = {};
|
|
5
|
+
/**
|
|
6
|
+
* Returns a UID.
|
|
7
|
+
* @param id= - Identifier base name
|
|
8
|
+
* @return uid
|
|
9
|
+
**/
|
|
10
|
+
export function uid(id = 'id') {
|
|
11
|
+
uidCounters[id] = uidCounters[id] || 1;
|
|
12
|
+
const count = uidCounters[id]++;
|
|
13
|
+
return `${id}-${count}`;
|
|
14
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luma.gl/engine",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.1.0-alpha.2",
|
|
4
4
|
"description": "3D Engine Components for luma.gl",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,13 +40,14 @@
|
|
|
40
40
|
"prepublishOnly": "npm run build-minified-bundle && npm run build-dev-bundle"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@luma.gl/core": "^9.0.0"
|
|
43
|
+
"@luma.gl/core": "^9.0.0-beta"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@luma.gl/shadertools": "9.0.
|
|
46
|
+
"@luma.gl/shadertools": "9.1.0-alpha.2",
|
|
47
47
|
"@math.gl/core": "^4.0.0",
|
|
48
|
-
"@
|
|
49
|
-
"@probe.gl/
|
|
48
|
+
"@math.gl/types": "^4.0.0",
|
|
49
|
+
"@probe.gl/log": "^4.0.8",
|
|
50
|
+
"@probe.gl/stats": "^4.0.8"
|
|
50
51
|
},
|
|
51
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "cb258afdefd2d5712d2decca35c746dd9d77a03e"
|
|
52
53
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import {luma, Device} from '@luma.gl/core';
|
|
6
|
-
import {requestAnimationFrame, cancelAnimationFrame} from '
|
|
6
|
+
import {requestAnimationFrame, cancelAnimationFrame} from './request-animation-frame';
|
|
7
7
|
import {Timeline} from '../animation/timeline';
|
|
8
8
|
import {AnimationProps} from './animation-props';
|
|
9
9
|
import {Stats, Stat} from '@probe.gl/stats';
|
|
@@ -342,7 +342,7 @@ export class AnimationLoop {
|
|
|
342
342
|
// end callback
|
|
343
343
|
|
|
344
344
|
// Submit commands (necessary on WebGPU)
|
|
345
|
-
this.device
|
|
345
|
+
this.device?.submit();
|
|
346
346
|
}
|
|
347
347
|
|
|
348
348
|
_clearNeedsRedraw(): void {
|
|
@@ -356,14 +356,16 @@ export class AnimationLoop {
|
|
|
356
356
|
|
|
357
357
|
// Initialize the object that will be passed to app callbacks
|
|
358
358
|
_initializeAnimationProps(): void {
|
|
359
|
-
|
|
359
|
+
const canvas = this.device?.canvasContext?.canvas;
|
|
360
|
+
|
|
361
|
+
if (!this.device || !canvas) {
|
|
360
362
|
throw new Error('loop');
|
|
361
363
|
}
|
|
362
364
|
this.animationProps = {
|
|
363
365
|
animationLoop: this,
|
|
364
366
|
|
|
365
367
|
device: this.device,
|
|
366
|
-
canvas
|
|
368
|
+
canvas,
|
|
367
369
|
timeline: this.timeline,
|
|
368
370
|
|
|
369
371
|
// Initial values
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
// Node.js polyfills for requestAnimationFrame and cancelAnimationFrame
|
|
6
|
+
/* global window, setTimeout, clearTimeout */
|
|
7
|
+
|
|
8
|
+
// / <reference types="@types/node" />
|
|
9
|
+
export function requestAnimationFrame(callback: (time?: any) => void): any {
|
|
10
|
+
return typeof window !== 'undefined' && window.requestAnimationFrame
|
|
11
|
+
? window.requestAnimationFrame(callback)
|
|
12
|
+
: setTimeout(callback, 1000 / 60);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function cancelAnimationFrame(timerId: any): void {
|
|
16
|
+
return typeof window !== 'undefined' && window.cancelAnimationFrame
|
|
17
|
+
? window.cancelAnimationFrame(timerId)
|
|
18
|
+
: clearTimeout(timerId);
|
|
19
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
let pathPrefix = '';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Set a relative path prefix
|
|
9
|
+
*/
|
|
10
|
+
export function setPathPrefix(prefix: string) {
|
|
11
|
+
pathPrefix = prefix;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// TODO - keep only loadImageBitmap
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Loads ImageBitmap asynchronously. Respects setPathPrefix.
|
|
18
|
+
* image.crossOrigin can be set via opts.crossOrigin, default to 'anonymous'
|
|
19
|
+
* @returns a promise tracking the load
|
|
20
|
+
*/
|
|
21
|
+
export async function loadImageBitmap(
|
|
22
|
+
url: string,
|
|
23
|
+
opts?: {crossOrigin?: string}
|
|
24
|
+
): Promise<ImageBitmap> {
|
|
25
|
+
const image = new Image();
|
|
26
|
+
image.crossOrigin = opts?.crossOrigin || 'anonymous';
|
|
27
|
+
image.src = url.startsWith('http') ? url : pathPrefix + url;
|
|
28
|
+
await image.decode();
|
|
29
|
+
return await createImageBitmap(image);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Loads image asynchronously. Respects setPathPrefix.
|
|
34
|
+
* image.crossOrigin can be set via opts.crossOrigin, default to 'anonymous'
|
|
35
|
+
* @returns a promise tracking the load
|
|
36
|
+
* @deprecated Use `loadImageBitmap()` unless you are supporting old versions of Safari.
|
|
37
|
+
*/
|
|
38
|
+
export async function loadImage(
|
|
39
|
+
url: string,
|
|
40
|
+
opts?: {crossOrigin?: string}
|
|
41
|
+
): Promise<HTMLImageElement> {
|
|
42
|
+
return await new Promise((resolve, reject) => {
|
|
43
|
+
try {
|
|
44
|
+
const image = new Image();
|
|
45
|
+
image.onload = () => resolve(image);
|
|
46
|
+
image.onerror = () => reject(new Error(`Could not load image ${url}.`));
|
|
47
|
+
image.crossOrigin = opts?.crossOrigin || 'anonymous';
|
|
48
|
+
image.src = url.startsWith('http') ? url : pathPrefix + url;
|
|
49
|
+
} catch (error) {
|
|
50
|
+
reject(error);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
/** Creates a deterministic pseudorandom number generator */
|
|
6
|
+
export function makeRandomGenerator(): () => number {
|
|
7
|
+
let s = 1;
|
|
8
|
+
let c = 1;
|
|
9
|
+
return () => {
|
|
10
|
+
s = Math.sin(c * 17.23);
|
|
11
|
+
c = Math.cos(s * 27.92);
|
|
12
|
+
return fract(Math.abs(s * c) * 1432.71);
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function fract(n: number): number {
|
|
17
|
+
return n - Math.floor(n);
|
|
18
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// luma.gl, MIT license
|
|
2
|
+
// Copyright (c) vis.gl contributors
|
|
3
|
+
|
|
4
|
+
import type {Texture, TextureProps, Sampler, TextureView, Device} from '@luma.gl/core';
|
|
5
|
+
|
|
6
|
+
import type {
|
|
7
|
+
Texture1DData,
|
|
8
|
+
Texture2DData,
|
|
9
|
+
Texture3DData,
|
|
10
|
+
TextureArrayData,
|
|
11
|
+
TextureCubeData,
|
|
12
|
+
TextureCubeArrayData
|
|
13
|
+
} from '@luma.gl/core';
|
|
14
|
+
|
|
15
|
+
import {loadImageBitmap} from '../application-utils/load-file';
|
|
16
|
+
|
|
17
|
+
export type AsyncTextureProps = Omit<TextureProps, 'data'> & AsyncTextureDataProps;
|
|
18
|
+
|
|
19
|
+
type AsyncTextureDataProps =
|
|
20
|
+
| AsyncTexture1DProps
|
|
21
|
+
| AsyncTexture2DProps
|
|
22
|
+
| AsyncTexture3DProps
|
|
23
|
+
| AsyncTextureArrayProps
|
|
24
|
+
| AsyncTextureCubeProps
|
|
25
|
+
| AsyncTextureCubeArrayProps;
|
|
26
|
+
|
|
27
|
+
type AsyncTexture1DProps = {dimension: '1d'; data: Promise<Texture1DData> | Texture1DData | null};
|
|
28
|
+
type AsyncTexture2DProps = {dimension?: '2d'; data: Promise<Texture2DData> | Texture2DData | null};
|
|
29
|
+
type AsyncTexture3DProps = {dimension: '3d'; data: Promise<Texture3DData> | Texture3DData | null};
|
|
30
|
+
type AsyncTextureArrayProps = {
|
|
31
|
+
dimension: '2d-array';
|
|
32
|
+
data: Promise<TextureArrayData> | TextureArrayData | null;
|
|
33
|
+
};
|
|
34
|
+
type AsyncTextureCubeProps = {
|
|
35
|
+
dimension: 'cube';
|
|
36
|
+
data: Promise<TextureCubeData> | TextureCubeData | null;
|
|
37
|
+
};
|
|
38
|
+
type AsyncTextureCubeArrayProps = {
|
|
39
|
+
dimension: 'cube-array';
|
|
40
|
+
data: Promise<TextureCubeArrayData> | TextureCubeArrayData | null;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
type TextureData = TextureProps['data'];
|
|
44
|
+
type AsyncTextureData = AsyncTextureProps['data'];
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* It is very convenient to be able to initialize textures with promises
|
|
48
|
+
* This can add considerable complexity to the Texture class, and doesn't
|
|
49
|
+
* fit with the immutable nature of WebGPU resources.
|
|
50
|
+
* Instead, luma.gl offers async textures as a separate class.
|
|
51
|
+
*/
|
|
52
|
+
export class AsyncTexture {
|
|
53
|
+
readonly device: Device;
|
|
54
|
+
|
|
55
|
+
// TODO - should we type these as possibly `null`? It will make usage harder?
|
|
56
|
+
// @ts-expect-error
|
|
57
|
+
texture: Texture;
|
|
58
|
+
// @ts-expect-error
|
|
59
|
+
sampler: Sampler;
|
|
60
|
+
// @ts-expect-error
|
|
61
|
+
view: TextureView;
|
|
62
|
+
|
|
63
|
+
readonly ready: Promise<void>;
|
|
64
|
+
isReady: boolean = false;
|
|
65
|
+
destroyed: boolean = false;
|
|
66
|
+
|
|
67
|
+
protected resolveReady: () => void = () => {};
|
|
68
|
+
protected rejectReady: (error: Error) => void = () => {};
|
|
69
|
+
|
|
70
|
+
constructor(device: Device, props: AsyncTextureProps) {
|
|
71
|
+
this.device = device;
|
|
72
|
+
|
|
73
|
+
// Signature: new AsyncTexture(device, {data: url})
|
|
74
|
+
if (typeof props?.data === 'string' && props.dimension === '2d') {
|
|
75
|
+
props = {...props, data: loadImageBitmap(props.data)};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
this.ready = new Promise<void>((resolve, reject) => {
|
|
79
|
+
this.resolveReady = () => {
|
|
80
|
+
this.isReady = true;
|
|
81
|
+
resolve();
|
|
82
|
+
};
|
|
83
|
+
this.rejectReady = reject;
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
this.initAsync(props);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async initAsync(props: AsyncTextureProps): Promise<void> {
|
|
90
|
+
let resolveReady;
|
|
91
|
+
let rejectReady;
|
|
92
|
+
|
|
93
|
+
const asyncData: AsyncTextureData = props.data;
|
|
94
|
+
const data: TextureData = await awaitAllPromises(asyncData).then(resolveReady, rejectReady);
|
|
95
|
+
|
|
96
|
+
// Check that we haven't been destroyed while waiting for texture data to load
|
|
97
|
+
if (this.destroyed) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Now we can actually create the texture
|
|
102
|
+
// @ts-expect-error Discriminated union
|
|
103
|
+
const syncProps: TextureProps = {...props, data};
|
|
104
|
+
|
|
105
|
+
this.texture = this.device.createTexture(syncProps);
|
|
106
|
+
this.sampler = this.texture.sampler;
|
|
107
|
+
this.view = this.texture.view;
|
|
108
|
+
this.isReady = true;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
destroy(): void {
|
|
112
|
+
if (this.texture) {
|
|
113
|
+
this.texture.destroy();
|
|
114
|
+
// @ts-expect-error
|
|
115
|
+
this.texture = null;
|
|
116
|
+
}
|
|
117
|
+
this.destroyed = true;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// We could implement resize by replacing the texture
|
|
121
|
+
// resize(width: number, height: number): boolean {
|
|
122
|
+
// throw new Error('Not implemented');
|
|
123
|
+
// // return false;
|
|
124
|
+
// }
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// HELPERS
|
|
128
|
+
|
|
129
|
+
/** Resolve all promises in a nested data structure */
|
|
130
|
+
async function awaitAllPromises(x: any): Promise<any> {
|
|
131
|
+
x = await x;
|
|
132
|
+
if (Array.isArray(x)) {
|
|
133
|
+
return x.map(awaitAllPromises);
|
|
134
|
+
}
|
|
135
|
+
if (x && typeof x === 'object' && x.constructor === Object) {
|
|
136
|
+
const entries = Object.entries(x).map(([key, value]) => [key, awaitAllPromises(value)]);
|
|
137
|
+
return Object.fromEntries(entries);
|
|
138
|
+
}
|
|
139
|
+
return x;
|
|
140
|
+
}
|