@luma.gl/engine 9.0.10 → 9.1.0-alpha.1
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.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 +1194 -474
- package/dist/dist.min.js +27 -25
- 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 +492 -245
- 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 +66 -9
- 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 +0 -1
- package/dist/shader-inputs.d.ts.map +1 -1
- package/dist/shader-inputs.js +5 -3
- 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 +72 -18
- 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 +5 -3
- 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
- package/src/.DS_Store +0 -0
package/dist/index.cjs
CHANGED
|
@@ -27,6 +27,7 @@ var dist_exports = {};
|
|
|
27
27
|
__export(dist_exports, {
|
|
28
28
|
AnimationLoop: () => AnimationLoop,
|
|
29
29
|
AnimationLoopTemplate: () => AnimationLoopTemplate,
|
|
30
|
+
AsyncTexture: () => AsyncTexture,
|
|
30
31
|
BufferTransform: () => BufferTransform,
|
|
31
32
|
ClipSpace: () => ClipSpace,
|
|
32
33
|
Computation: () => Computation,
|
|
@@ -49,7 +50,13 @@ __export(dist_exports, {
|
|
|
49
50
|
Timeline: () => Timeline,
|
|
50
51
|
TruncatedConeGeometry: () => TruncatedConeGeometry,
|
|
51
52
|
_ShaderInputs: () => ShaderInputs,
|
|
52
|
-
|
|
53
|
+
cancelAnimationFrame: () => cancelAnimationFrame,
|
|
54
|
+
loadImage: () => loadImage,
|
|
55
|
+
loadImageBitmap: () => loadImageBitmap,
|
|
56
|
+
makeAnimationLoop: () => makeAnimationLoop,
|
|
57
|
+
makeRandomGenerator: () => makeRandomGenerator,
|
|
58
|
+
requestAnimationFrame: () => requestAnimationFrame,
|
|
59
|
+
setPathPrefix: () => setPathPrefix
|
|
53
60
|
});
|
|
54
61
|
module.exports = __toCommonJS(dist_exports);
|
|
55
62
|
|
|
@@ -226,7 +233,16 @@ var AnimationLoopTemplate = class {
|
|
|
226
233
|
|
|
227
234
|
// dist/animation-loop/animation-loop.js
|
|
228
235
|
var import_core = require("@luma.gl/core");
|
|
229
|
-
|
|
236
|
+
|
|
237
|
+
// dist/animation-loop/request-animation-frame.js
|
|
238
|
+
function requestAnimationFrame(callback) {
|
|
239
|
+
return typeof window !== "undefined" && window.requestAnimationFrame ? window.requestAnimationFrame(callback) : setTimeout(callback, 1e3 / 60);
|
|
240
|
+
}
|
|
241
|
+
function cancelAnimationFrame(timerId) {
|
|
242
|
+
return typeof window !== "undefined" && window.cancelAnimationFrame ? window.cancelAnimationFrame(timerId) : clearTimeout(timerId);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// dist/animation-loop/animation-loop.js
|
|
230
246
|
var import_stats = require("@probe.gl/stats");
|
|
231
247
|
var statIdCounter = 0;
|
|
232
248
|
var DEFAULT_ANIMATION_LOOP_PROPS = {
|
|
@@ -426,13 +442,13 @@ var AnimationLoop = class {
|
|
|
426
442
|
if (!this._running) {
|
|
427
443
|
return;
|
|
428
444
|
}
|
|
429
|
-
this._animationFrameId =
|
|
445
|
+
this._animationFrameId = requestAnimationFrame(this._animationFrame.bind(this));
|
|
430
446
|
}
|
|
431
447
|
_cancelAnimationFrame() {
|
|
432
448
|
if (this._animationFrameId === null) {
|
|
433
449
|
return;
|
|
434
450
|
}
|
|
435
|
-
|
|
451
|
+
cancelAnimationFrame(this._animationFrameId);
|
|
436
452
|
this._animationFrameId = null;
|
|
437
453
|
}
|
|
438
454
|
_animationFrame() {
|
|
@@ -445,12 +461,13 @@ var AnimationLoop = class {
|
|
|
445
461
|
// Called on each frame, can be overridden to call onRender multiple times
|
|
446
462
|
// to support e.g. stereoscopic rendering
|
|
447
463
|
_renderFrame(animationProps) {
|
|
464
|
+
var _a;
|
|
448
465
|
if (this.display) {
|
|
449
466
|
this.display._renderFrame(animationProps);
|
|
450
467
|
return;
|
|
451
468
|
}
|
|
452
469
|
this.props.onRender(this._getAnimationProps());
|
|
453
|
-
this.device.submit();
|
|
470
|
+
(_a = this.device) == null ? void 0 : _a.submit();
|
|
454
471
|
}
|
|
455
472
|
_clearNeedsRedraw() {
|
|
456
473
|
this.needsRedraw = false;
|
|
@@ -462,13 +479,14 @@ var AnimationLoop = class {
|
|
|
462
479
|
// Initialize the object that will be passed to app callbacks
|
|
463
480
|
_initializeAnimationProps() {
|
|
464
481
|
var _a, _b;
|
|
465
|
-
|
|
482
|
+
const canvas2 = (_b = (_a = this.device) == null ? void 0 : _a.canvasContext) == null ? void 0 : _b.canvas;
|
|
483
|
+
if (!this.device || !canvas2) {
|
|
466
484
|
throw new Error("loop");
|
|
467
485
|
}
|
|
468
486
|
this.animationProps = {
|
|
469
487
|
animationLoop: this,
|
|
470
488
|
device: this.device,
|
|
471
|
-
canvas:
|
|
489
|
+
canvas: canvas2,
|
|
472
490
|
timeline: this.timeline,
|
|
473
491
|
// Initial values
|
|
474
492
|
useDevicePixels: this.props.useDevicePixels,
|
|
@@ -612,10 +630,10 @@ var AnimationLoop = class {
|
|
|
612
630
|
};
|
|
613
631
|
|
|
614
632
|
// dist/animation-loop/make-animation-loop.js
|
|
615
|
-
var
|
|
633
|
+
var import_core2 = require("@luma.gl/core");
|
|
616
634
|
function makeAnimationLoop(AnimationLoopTemplateCtor, props) {
|
|
617
635
|
let renderLoop = null;
|
|
618
|
-
const device = (props == null ? void 0 : props.device) ||
|
|
636
|
+
const device = (props == null ? void 0 : props.device) || import_core2.luma.createDevice();
|
|
619
637
|
const animationLoop = new AnimationLoop({
|
|
620
638
|
...props,
|
|
621
639
|
device,
|
|
@@ -633,14 +651,24 @@ function makeAnimationLoop(AnimationLoopTemplateCtor, props) {
|
|
|
633
651
|
}
|
|
634
652
|
|
|
635
653
|
// dist/model/model.js
|
|
654
|
+
var import_core7 = require("@luma.gl/core");
|
|
636
655
|
var import_core8 = require("@luma.gl/core");
|
|
637
656
|
var import_core9 = require("@luma.gl/core");
|
|
638
657
|
var import_core10 = require("@luma.gl/core");
|
|
639
|
-
var import_core11 = require("@luma.gl/core");
|
|
640
658
|
var import_shadertools2 = require("@luma.gl/shadertools");
|
|
641
659
|
|
|
642
660
|
// dist/geometry/gpu-geometry.js
|
|
643
|
-
var
|
|
661
|
+
var import_core3 = require("@luma.gl/core");
|
|
662
|
+
|
|
663
|
+
// dist/utils/uid.js
|
|
664
|
+
var uidCounters = {};
|
|
665
|
+
function uid(id = "id") {
|
|
666
|
+
uidCounters[id] = uidCounters[id] || 1;
|
|
667
|
+
const count = uidCounters[id]++;
|
|
668
|
+
return `${id}-${count}`;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
// dist/geometry/gpu-geometry.js
|
|
644
672
|
var GPUGeometry = class {
|
|
645
673
|
id;
|
|
646
674
|
userData = {};
|
|
@@ -651,14 +679,16 @@ var GPUGeometry = class {
|
|
|
651
679
|
indices;
|
|
652
680
|
attributes;
|
|
653
681
|
constructor(props) {
|
|
654
|
-
this.id = props.id ||
|
|
682
|
+
this.id = props.id || uid("geometry");
|
|
655
683
|
this.topology = props.topology;
|
|
656
684
|
this.indices = props.indices || null;
|
|
657
685
|
this.attributes = props.attributes;
|
|
658
686
|
this.vertexCount = props.vertexCount;
|
|
659
687
|
this.bufferLayout = props.bufferLayout || [];
|
|
660
688
|
if (this.indices) {
|
|
661
|
-
|
|
689
|
+
if (!(this.indices.usage & import_core3.Buffer.INDEX)) {
|
|
690
|
+
throw new Error("Index buffer must have INDEX usage");
|
|
691
|
+
}
|
|
662
692
|
}
|
|
663
693
|
}
|
|
664
694
|
destroy() {
|
|
@@ -675,7 +705,7 @@ var GPUGeometry = class {
|
|
|
675
705
|
return this.attributes;
|
|
676
706
|
}
|
|
677
707
|
getIndexes() {
|
|
678
|
-
return this.indices;
|
|
708
|
+
return this.indices || null;
|
|
679
709
|
}
|
|
680
710
|
_calculateVertexCount(positions) {
|
|
681
711
|
const vertexCount = positions.byteLength / 12;
|
|
@@ -701,7 +731,7 @@ function getIndexBufferFromGeometry(device, geometry) {
|
|
|
701
731
|
return void 0;
|
|
702
732
|
}
|
|
703
733
|
const data = geometry.indices.value;
|
|
704
|
-
return device.createBuffer({ usage:
|
|
734
|
+
return device.createBuffer({ usage: import_core3.Buffer.INDEX, data });
|
|
705
735
|
}
|
|
706
736
|
function getAttributeBuffersFromGeometry(device, geometry) {
|
|
707
737
|
const bufferLayout = [];
|
|
@@ -722,123 +752,40 @@ function getAttributeBuffersFromGeometry(device, geometry) {
|
|
|
722
752
|
name = "colors";
|
|
723
753
|
break;
|
|
724
754
|
}
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
755
|
+
if (attribute) {
|
|
756
|
+
attributes[name] = device.createBuffer({
|
|
757
|
+
data: attribute.value,
|
|
758
|
+
id: `${attributeName}-buffer`
|
|
759
|
+
});
|
|
760
|
+
const { value, size, normalized } = attribute;
|
|
761
|
+
bufferLayout.push({ name, format: (0, import_core3.getVertexFormatFromAttribute)(value, size, normalized) });
|
|
762
|
+
}
|
|
728
763
|
}
|
|
729
764
|
const vertexCount = geometry._calculateVertexCount(geometry.attributes, geometry.indices);
|
|
730
765
|
return { attributes, bufferLayout, vertexCount };
|
|
731
766
|
}
|
|
732
767
|
|
|
733
|
-
// dist/shader-inputs.js
|
|
734
|
-
var import_core5 = require("@luma.gl/core");
|
|
735
|
-
var import_shadertools = require("@luma.gl/shadertools");
|
|
736
|
-
var ShaderInputs = class {
|
|
737
|
-
/**
|
|
738
|
-
* The map of modules
|
|
739
|
-
* @todo should should this include the resolved dependencies?
|
|
740
|
-
*/
|
|
741
|
-
modules;
|
|
742
|
-
/** Stores the uniform values for each module */
|
|
743
|
-
moduleUniforms;
|
|
744
|
-
/** Stores the uniform bindings for each module */
|
|
745
|
-
moduleBindings;
|
|
746
|
-
/** Tracks if uniforms have changed */
|
|
747
|
-
moduleUniformsChanged;
|
|
748
|
-
/**
|
|
749
|
-
* Create a new UniformStore instance
|
|
750
|
-
* @param modules
|
|
751
|
-
*/
|
|
752
|
-
constructor(modules) {
|
|
753
|
-
const allModules = (0, import_shadertools._resolveModules)(Object.values(modules));
|
|
754
|
-
import_core5.log.log(1, "Creating ShaderInputs with modules", allModules.map((m) => m.name))();
|
|
755
|
-
this.modules = modules;
|
|
756
|
-
this.moduleUniforms = {};
|
|
757
|
-
this.moduleBindings = {};
|
|
758
|
-
for (const [name, module2] of Object.entries(modules)) {
|
|
759
|
-
const moduleName = name;
|
|
760
|
-
this.moduleUniforms[moduleName] = module2.defaultUniforms || {};
|
|
761
|
-
this.moduleBindings[moduleName] = {};
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
/** Destroy */
|
|
765
|
-
destroy() {
|
|
766
|
-
}
|
|
767
|
-
/**
|
|
768
|
-
* Set module props
|
|
769
|
-
*/
|
|
770
|
-
setProps(props) {
|
|
771
|
-
var _a;
|
|
772
|
-
for (const name of Object.keys(props)) {
|
|
773
|
-
const moduleName = name;
|
|
774
|
-
const moduleProps = props[moduleName];
|
|
775
|
-
const module2 = this.modules[moduleName];
|
|
776
|
-
if (!module2) {
|
|
777
|
-
import_core5.log.warn(`Module ${name} not found`)();
|
|
778
|
-
continue;
|
|
779
|
-
}
|
|
780
|
-
const oldUniforms = this.moduleUniforms[moduleName];
|
|
781
|
-
const uniforms = ((_a = module2.getUniforms) == null ? void 0 : _a.call(module2, moduleProps, this.moduleUniforms[moduleName])) || moduleProps;
|
|
782
|
-
this.moduleUniforms[moduleName] = { ...oldUniforms, ...uniforms };
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
/** Merges all bindings for the shader (from the various modules) */
|
|
786
|
-
// getUniformBlocks(): Record<string, Texture | Sampler> {
|
|
787
|
-
// return this.moduleUniforms;
|
|
788
|
-
// }
|
|
789
|
-
/**
|
|
790
|
-
* Return the map of modules
|
|
791
|
-
* @todo should should this include the resolved dependencies?
|
|
792
|
-
*/
|
|
793
|
-
getModules() {
|
|
794
|
-
return Object.values(this.modules);
|
|
795
|
-
}
|
|
796
|
-
/** Get all uniform values for all modules */
|
|
797
|
-
getUniformValues() {
|
|
798
|
-
return this.moduleUniforms;
|
|
799
|
-
}
|
|
800
|
-
/** Merges all bindings for the shader (from the various modules) */
|
|
801
|
-
getBindings() {
|
|
802
|
-
const bindings = {};
|
|
803
|
-
for (const moduleBindings of Object.values(this.moduleBindings)) {
|
|
804
|
-
Object.assign(bindings, moduleBindings);
|
|
805
|
-
}
|
|
806
|
-
return bindings;
|
|
807
|
-
}
|
|
808
|
-
getDebugTable() {
|
|
809
|
-
var _a;
|
|
810
|
-
const table = {};
|
|
811
|
-
for (const [moduleName, module2] of Object.entries(this.moduleUniforms)) {
|
|
812
|
-
for (const [key, value] of Object.entries(module2)) {
|
|
813
|
-
table[`${moduleName}.${key}`] = {
|
|
814
|
-
type: (_a = this.modules[moduleName].uniformTypes) == null ? void 0 : _a[key],
|
|
815
|
-
value: String(value)
|
|
816
|
-
};
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
return table;
|
|
820
|
-
}
|
|
821
|
-
};
|
|
822
|
-
|
|
823
768
|
// dist/lib/pipeline-factory.js
|
|
824
|
-
var
|
|
769
|
+
var import_core4 = require("@luma.gl/core");
|
|
825
770
|
var _PipelineFactory = class {
|
|
826
|
-
device;
|
|
827
|
-
_hashCounter = 0;
|
|
828
|
-
_hashes = {};
|
|
829
|
-
_renderPipelineCache = {};
|
|
830
|
-
_computePipelineCache = {};
|
|
831
771
|
/** Get the singleton default pipeline factory for the specified device */
|
|
832
772
|
static getDefaultPipelineFactory(device) {
|
|
833
773
|
device._lumaData.defaultPipelineFactory = device._lumaData.defaultPipelineFactory || new _PipelineFactory(device);
|
|
834
774
|
return device._lumaData.defaultPipelineFactory;
|
|
835
775
|
}
|
|
776
|
+
device;
|
|
777
|
+
destroyPolicy;
|
|
778
|
+
_hashCounter = 0;
|
|
779
|
+
_hashes = {};
|
|
780
|
+
_renderPipelineCache = {};
|
|
781
|
+
_computePipelineCache = {};
|
|
836
782
|
constructor(device) {
|
|
837
783
|
this.device = device;
|
|
784
|
+
this.destroyPolicy = device.props._factoryDestroyPolicy;
|
|
838
785
|
}
|
|
839
786
|
/** Return a RenderPipeline matching props. Reuses a similar pipeline if already created. */
|
|
840
787
|
createRenderPipeline(props) {
|
|
841
|
-
const allProps = { ...
|
|
788
|
+
const allProps = { ...import_core4.RenderPipeline.defaultProps, ...props };
|
|
842
789
|
const hash = this._hashRenderPipeline(allProps);
|
|
843
790
|
if (!this._renderPipelineCache[hash]) {
|
|
844
791
|
const pipeline = this.device.createRenderPipeline({
|
|
@@ -852,7 +799,7 @@ var _PipelineFactory = class {
|
|
|
852
799
|
return this._renderPipelineCache[hash].pipeline;
|
|
853
800
|
}
|
|
854
801
|
createComputePipeline(props) {
|
|
855
|
-
const allProps = { ...
|
|
802
|
+
const allProps = { ...import_core4.ComputePipeline.defaultProps, ...props };
|
|
856
803
|
const hash = this._hashComputePipeline(allProps);
|
|
857
804
|
if (!this._computePipelineCache[hash]) {
|
|
858
805
|
const pipeline = this.device.createComputePipeline({
|
|
@@ -867,11 +814,13 @@ var _PipelineFactory = class {
|
|
|
867
814
|
}
|
|
868
815
|
release(pipeline) {
|
|
869
816
|
const hash = pipeline.hash;
|
|
870
|
-
const cache = pipeline instanceof
|
|
817
|
+
const cache = pipeline instanceof import_core4.ComputePipeline ? this._computePipelineCache : this._renderPipelineCache;
|
|
871
818
|
cache[hash].useCount--;
|
|
872
819
|
if (cache[hash].useCount === 0) {
|
|
873
|
-
|
|
874
|
-
|
|
820
|
+
if (this.destroyPolicy === "unused") {
|
|
821
|
+
cache[hash].pipeline.destroy();
|
|
822
|
+
delete cache[hash];
|
|
823
|
+
}
|
|
875
824
|
}
|
|
876
825
|
}
|
|
877
826
|
// PRIVATE
|
|
@@ -881,7 +830,7 @@ var _PipelineFactory = class {
|
|
|
881
830
|
}
|
|
882
831
|
/** Calculate a hash based on all the inputs for a render pipeline */
|
|
883
832
|
_hashRenderPipeline(props) {
|
|
884
|
-
const vsHash = this._getHash(props.vs.source);
|
|
833
|
+
const vsHash = props.vs ? this._getHash(props.vs.source) : 0;
|
|
885
834
|
const fsHash = props.fs ? this._getHash(props.fs.source) : 0;
|
|
886
835
|
const varyingHash = "-";
|
|
887
836
|
const bufferLayoutHash = this._getHash(JSON.stringify(props.bufferLayout));
|
|
@@ -901,21 +850,23 @@ var _PipelineFactory = class {
|
|
|
901
850
|
}
|
|
902
851
|
};
|
|
903
852
|
var PipelineFactory = _PipelineFactory;
|
|
904
|
-
__publicField(PipelineFactory, "defaultProps", { ...
|
|
853
|
+
__publicField(PipelineFactory, "defaultProps", { ...import_core4.RenderPipeline.defaultProps });
|
|
905
854
|
|
|
906
855
|
// dist/lib/shader-factory.js
|
|
907
|
-
var
|
|
856
|
+
var import_core5 = require("@luma.gl/core");
|
|
908
857
|
var _ShaderFactory = class {
|
|
909
|
-
device;
|
|
910
|
-
_cache = {};
|
|
911
858
|
/** Returns the default ShaderFactory for the given {@link Device}, creating one if necessary. */
|
|
912
859
|
static getDefaultShaderFactory(device) {
|
|
913
860
|
device._lumaData.defaultShaderFactory ||= new _ShaderFactory(device);
|
|
914
861
|
return device._lumaData.defaultShaderFactory;
|
|
915
862
|
}
|
|
863
|
+
device;
|
|
864
|
+
destroyPolicy;
|
|
865
|
+
_cache = {};
|
|
916
866
|
/** @internal */
|
|
917
867
|
constructor(device) {
|
|
918
868
|
this.device = device;
|
|
869
|
+
this.destroyPolicy = device.props._factoryDestroyPolicy;
|
|
919
870
|
}
|
|
920
871
|
/** Requests a {@link Shader} from the cache, creating a new Shader only if necessary. */
|
|
921
872
|
createShader(props) {
|
|
@@ -938,8 +889,10 @@ var _ShaderFactory = class {
|
|
|
938
889
|
if (cacheEntry) {
|
|
939
890
|
cacheEntry.useCount--;
|
|
940
891
|
if (cacheEntry.useCount === 0) {
|
|
941
|
-
|
|
942
|
-
|
|
892
|
+
if (this.destroyPolicy === "unused") {
|
|
893
|
+
delete this._cache[key];
|
|
894
|
+
cacheEntry.shader.destroy();
|
|
895
|
+
}
|
|
943
896
|
}
|
|
944
897
|
}
|
|
945
898
|
}
|
|
@@ -949,7 +902,7 @@ var _ShaderFactory = class {
|
|
|
949
902
|
}
|
|
950
903
|
};
|
|
951
904
|
var ShaderFactory = _ShaderFactory;
|
|
952
|
-
__publicField(ShaderFactory, "defaultProps", { ...
|
|
905
|
+
__publicField(ShaderFactory, "defaultProps", { ...import_core5.Shader.defaultProps });
|
|
953
906
|
|
|
954
907
|
// dist/debug/debug-shader-layout.js
|
|
955
908
|
function getDebugTableForShaderLayout(layout, name) {
|
|
@@ -996,15 +949,259 @@ function debugFramebuffer(fbo, { id, minimap, opaque, top = "0", left = "0", rgb
|
|
|
996
949
|
canvas.style.height = "400px";
|
|
997
950
|
}
|
|
998
951
|
const color = fbo.device.readPixelsToArrayWebGL(fbo);
|
|
999
|
-
const imageData = ctx.createImageData(fbo.width, fbo.height);
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
952
|
+
const imageData = ctx == null ? void 0 : ctx.createImageData(fbo.width, fbo.height);
|
|
953
|
+
if (imageData) {
|
|
954
|
+
const offset = 0;
|
|
955
|
+
for (let i = 0; i < color.length; i += 4) {
|
|
956
|
+
imageData.data[offset + i + 0] = color[i + 0] * rgbaScale;
|
|
957
|
+
imageData.data[offset + i + 1] = color[i + 1] * rgbaScale;
|
|
958
|
+
imageData.data[offset + i + 2] = color[i + 2] * rgbaScale;
|
|
959
|
+
imageData.data[offset + i + 3] = opaque ? 255 : color[i + 3] * rgbaScale;
|
|
960
|
+
}
|
|
961
|
+
ctx == null ? void 0 : ctx.putImageData(imageData, 0, 0);
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
// dist/utils/deep-equal.js
|
|
966
|
+
function deepEqual(a, b, depth) {
|
|
967
|
+
if (a === b) {
|
|
968
|
+
return true;
|
|
969
|
+
}
|
|
970
|
+
if (!depth || !a || !b) {
|
|
971
|
+
return false;
|
|
972
|
+
}
|
|
973
|
+
if (Array.isArray(a)) {
|
|
974
|
+
if (!Array.isArray(b) || a.length !== b.length) {
|
|
975
|
+
return false;
|
|
976
|
+
}
|
|
977
|
+
for (let i = 0; i < a.length; i++) {
|
|
978
|
+
if (!deepEqual(a[i], b[i], depth - 1)) {
|
|
979
|
+
return false;
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
return true;
|
|
983
|
+
}
|
|
984
|
+
if (Array.isArray(b)) {
|
|
985
|
+
return false;
|
|
986
|
+
}
|
|
987
|
+
if (typeof a === "object" && typeof b === "object") {
|
|
988
|
+
const aKeys = Object.keys(a);
|
|
989
|
+
const bKeys = Object.keys(b);
|
|
990
|
+
if (aKeys.length !== bKeys.length) {
|
|
991
|
+
return false;
|
|
992
|
+
}
|
|
993
|
+
for (const key of aKeys) {
|
|
994
|
+
if (!b.hasOwnProperty(key)) {
|
|
995
|
+
return false;
|
|
996
|
+
}
|
|
997
|
+
if (!deepEqual(a[key], b[key], depth - 1)) {
|
|
998
|
+
return false;
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
return true;
|
|
1002
|
+
}
|
|
1003
|
+
return false;
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
// dist/model/split-uniforms-and-bindings.js
|
|
1007
|
+
var import_types = require("@math.gl/types");
|
|
1008
|
+
function isUniformValue(value) {
|
|
1009
|
+
return (0, import_types.isNumericArray)(value) !== null || typeof value === "number" || typeof value === "boolean";
|
|
1010
|
+
}
|
|
1011
|
+
function splitUniformsAndBindings(uniforms) {
|
|
1012
|
+
const result = { bindings: {}, uniforms: {} };
|
|
1013
|
+
Object.keys(uniforms).forEach((name) => {
|
|
1014
|
+
const uniform = uniforms[name];
|
|
1015
|
+
if (isUniformValue(uniform)) {
|
|
1016
|
+
result.uniforms[name] = uniform;
|
|
1017
|
+
} else {
|
|
1018
|
+
result.bindings[name] = uniform;
|
|
1019
|
+
}
|
|
1020
|
+
});
|
|
1021
|
+
return result;
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
// dist/shader-inputs.js
|
|
1025
|
+
var import_core6 = require("@luma.gl/core");
|
|
1026
|
+
var import_shadertools = require("@luma.gl/shadertools");
|
|
1027
|
+
var ShaderInputs = class {
|
|
1028
|
+
/**
|
|
1029
|
+
* The map of modules
|
|
1030
|
+
* @todo should should this include the resolved dependencies?
|
|
1031
|
+
*/
|
|
1032
|
+
// @ts-expect-error Fix typings
|
|
1033
|
+
modules;
|
|
1034
|
+
/** Stores the uniform values for each module */
|
|
1035
|
+
moduleUniforms;
|
|
1036
|
+
/** Stores the uniform bindings for each module */
|
|
1037
|
+
moduleBindings;
|
|
1038
|
+
/** Tracks if uniforms have changed */
|
|
1039
|
+
// moduleUniformsChanged: Record<keyof ShaderPropsT, false | string>;
|
|
1040
|
+
/**
|
|
1041
|
+
* Create a new UniformStore instance
|
|
1042
|
+
* @param modules
|
|
1043
|
+
*/
|
|
1044
|
+
// @ts-expect-error Fix typings
|
|
1045
|
+
constructor(modules) {
|
|
1046
|
+
const allModules = (0, import_shadertools._resolveModules)(Object.values(modules));
|
|
1047
|
+
import_core6.log.log(1, "Creating ShaderInputs with modules", allModules.map((m) => m.name))();
|
|
1048
|
+
this.modules = modules;
|
|
1049
|
+
this.moduleUniforms = {};
|
|
1050
|
+
this.moduleBindings = {};
|
|
1051
|
+
for (const [name, module2] of Object.entries(modules)) {
|
|
1052
|
+
const moduleName = name;
|
|
1053
|
+
this.moduleUniforms[moduleName] = module2.defaultUniforms || {};
|
|
1054
|
+
this.moduleBindings[moduleName] = {};
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
/** Destroy */
|
|
1058
|
+
destroy() {
|
|
1059
|
+
}
|
|
1060
|
+
/**
|
|
1061
|
+
* Set module props
|
|
1062
|
+
*/
|
|
1063
|
+
setProps(props) {
|
|
1064
|
+
var _a;
|
|
1065
|
+
for (const name of Object.keys(props)) {
|
|
1066
|
+
const moduleName = name;
|
|
1067
|
+
const moduleProps = props[moduleName] || {};
|
|
1068
|
+
const module2 = this.modules[moduleName];
|
|
1069
|
+
if (!module2) {
|
|
1070
|
+
import_core6.log.warn(`Module ${name} not found`)();
|
|
1071
|
+
continue;
|
|
1072
|
+
}
|
|
1073
|
+
const oldUniforms = this.moduleUniforms[moduleName];
|
|
1074
|
+
const uniforms = ((_a = module2.getUniforms) == null ? void 0 : _a.call(module2, moduleProps, this.moduleUniforms[moduleName])) || moduleProps;
|
|
1075
|
+
this.moduleUniforms[moduleName] = { ...oldUniforms, ...uniforms };
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
/** Merges all bindings for the shader (from the various modules) */
|
|
1079
|
+
// getUniformBlocks(): Record<string, Texture | Sampler> {
|
|
1080
|
+
// return this.moduleUniforms;
|
|
1081
|
+
// }
|
|
1082
|
+
/**
|
|
1083
|
+
* Return the map of modules
|
|
1084
|
+
* @todo should should this include the resolved dependencies?
|
|
1085
|
+
*/
|
|
1086
|
+
getModules() {
|
|
1087
|
+
return Object.values(this.modules);
|
|
1088
|
+
}
|
|
1089
|
+
/** Get all uniform values for all modules */
|
|
1090
|
+
getUniformValues() {
|
|
1091
|
+
return this.moduleUniforms;
|
|
1092
|
+
}
|
|
1093
|
+
/** Merges all bindings for the shader (from the various modules) */
|
|
1094
|
+
getBindings() {
|
|
1095
|
+
const bindings = {};
|
|
1096
|
+
for (const moduleBindings of Object.values(this.moduleBindings)) {
|
|
1097
|
+
Object.assign(bindings, moduleBindings);
|
|
1098
|
+
}
|
|
1099
|
+
return bindings;
|
|
1100
|
+
}
|
|
1101
|
+
getDebugTable() {
|
|
1102
|
+
var _a;
|
|
1103
|
+
const table = {};
|
|
1104
|
+
for (const [moduleName, module2] of Object.entries(this.moduleUniforms)) {
|
|
1105
|
+
for (const [key, value] of Object.entries(module2)) {
|
|
1106
|
+
table[`${moduleName}.${key}`] = {
|
|
1107
|
+
type: (_a = this.modules[moduleName].uniformTypes) == null ? void 0 : _a[key],
|
|
1108
|
+
value: String(value)
|
|
1109
|
+
};
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
return table;
|
|
1113
|
+
}
|
|
1114
|
+
};
|
|
1115
|
+
|
|
1116
|
+
// dist/application-utils/load-file.js
|
|
1117
|
+
var pathPrefix = "";
|
|
1118
|
+
function setPathPrefix(prefix) {
|
|
1119
|
+
pathPrefix = prefix;
|
|
1120
|
+
}
|
|
1121
|
+
async function loadImageBitmap(url, opts) {
|
|
1122
|
+
const image = new Image();
|
|
1123
|
+
image.crossOrigin = (opts == null ? void 0 : opts.crossOrigin) || "anonymous";
|
|
1124
|
+
image.src = url.startsWith("http") ? url : pathPrefix + url;
|
|
1125
|
+
await image.decode();
|
|
1126
|
+
return await createImageBitmap(image);
|
|
1127
|
+
}
|
|
1128
|
+
async function loadImage(url, opts) {
|
|
1129
|
+
return await new Promise((resolve, reject) => {
|
|
1130
|
+
try {
|
|
1131
|
+
const image = new Image();
|
|
1132
|
+
image.onload = () => resolve(image);
|
|
1133
|
+
image.onerror = () => reject(new Error(`Could not load image ${url}.`));
|
|
1134
|
+
image.crossOrigin = (opts == null ? void 0 : opts.crossOrigin) || "anonymous";
|
|
1135
|
+
image.src = url.startsWith("http") ? url : pathPrefix + url;
|
|
1136
|
+
} catch (error) {
|
|
1137
|
+
reject(error);
|
|
1138
|
+
}
|
|
1139
|
+
});
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
// dist/async-texture/async-texture.js
|
|
1143
|
+
var AsyncTexture = class {
|
|
1144
|
+
device;
|
|
1145
|
+
// TODO - should we type these as possibly `null`? It will make usage harder?
|
|
1146
|
+
// @ts-expect-error
|
|
1147
|
+
texture;
|
|
1148
|
+
// @ts-expect-error
|
|
1149
|
+
sampler;
|
|
1150
|
+
// @ts-expect-error
|
|
1151
|
+
view;
|
|
1152
|
+
ready;
|
|
1153
|
+
isReady = false;
|
|
1154
|
+
destroyed = false;
|
|
1155
|
+
resolveReady = () => {
|
|
1156
|
+
};
|
|
1157
|
+
rejectReady = () => {
|
|
1158
|
+
};
|
|
1159
|
+
constructor(device, props) {
|
|
1160
|
+
this.device = device;
|
|
1161
|
+
if (typeof (props == null ? void 0 : props.data) === "string" && props.dimension === "2d") {
|
|
1162
|
+
props = { ...props, data: loadImageBitmap(props.data) };
|
|
1163
|
+
}
|
|
1164
|
+
this.ready = new Promise((resolve, reject) => {
|
|
1165
|
+
this.resolveReady = () => {
|
|
1166
|
+
this.isReady = true;
|
|
1167
|
+
resolve();
|
|
1168
|
+
};
|
|
1169
|
+
this.rejectReady = reject;
|
|
1170
|
+
});
|
|
1171
|
+
this.initAsync(props);
|
|
1172
|
+
}
|
|
1173
|
+
async initAsync(props) {
|
|
1174
|
+
let resolveReady;
|
|
1175
|
+
let rejectReady;
|
|
1176
|
+
const asyncData = props.data;
|
|
1177
|
+
const data = await awaitAllPromises(asyncData).then(resolveReady, rejectReady);
|
|
1178
|
+
if (this.destroyed) {
|
|
1179
|
+
return;
|
|
1180
|
+
}
|
|
1181
|
+
const syncProps = { ...props, data };
|
|
1182
|
+
this.texture = this.device.createTexture(syncProps);
|
|
1183
|
+
this.sampler = this.texture.sampler;
|
|
1184
|
+
this.view = this.texture.view;
|
|
1185
|
+
this.isReady = true;
|
|
1186
|
+
}
|
|
1187
|
+
destroy() {
|
|
1188
|
+
if (this.texture) {
|
|
1189
|
+
this.texture.destroy();
|
|
1190
|
+
this.texture = null;
|
|
1191
|
+
}
|
|
1192
|
+
this.destroyed = true;
|
|
1193
|
+
}
|
|
1194
|
+
};
|
|
1195
|
+
async function awaitAllPromises(x) {
|
|
1196
|
+
x = await x;
|
|
1197
|
+
if (Array.isArray(x)) {
|
|
1198
|
+
return x.map(awaitAllPromises);
|
|
1199
|
+
}
|
|
1200
|
+
if (x && typeof x === "object" && x.constructor === Object) {
|
|
1201
|
+
const entries = Object.entries(x).map(([key, value]) => [key, awaitAllPromises(value)]);
|
|
1202
|
+
return Object.fromEntries(entries);
|
|
1203
|
+
}
|
|
1204
|
+
return x;
|
|
1008
1205
|
}
|
|
1009
1206
|
|
|
1010
1207
|
// dist/model/model.js
|
|
@@ -1013,8 +1210,11 @@ var LOG_DRAW_TIMEOUT = 1e4;
|
|
|
1013
1210
|
var _Model = class {
|
|
1014
1211
|
device;
|
|
1015
1212
|
id;
|
|
1213
|
+
// @ts-expect-error assigned in function called from constructor
|
|
1016
1214
|
source;
|
|
1215
|
+
// @ts-expect-error assigned in function called from constructor
|
|
1017
1216
|
vs;
|
|
1217
|
+
// @ts-expect-error assigned in function called from constructor
|
|
1018
1218
|
fs;
|
|
1019
1219
|
pipelineFactory;
|
|
1020
1220
|
shaderFactory;
|
|
@@ -1054,7 +1254,9 @@ var _Model = class {
|
|
|
1054
1254
|
/** The underlying GPU "program". @note May be recreated if parameters change */
|
|
1055
1255
|
pipeline;
|
|
1056
1256
|
/** ShaderInputs instance */
|
|
1257
|
+
// @ts-expect-error Assigned in function called by constructor
|
|
1057
1258
|
shaderInputs;
|
|
1259
|
+
// @ts-expect-error Assigned in function called by constructor
|
|
1058
1260
|
_uniformStore;
|
|
1059
1261
|
_attributeInfos = {};
|
|
1060
1262
|
_gpuGeometry = null;
|
|
@@ -1069,17 +1271,20 @@ var _Model = class {
|
|
|
1069
1271
|
var _a, _b, _c;
|
|
1070
1272
|
this.props = { ..._Model.defaultProps, ...props };
|
|
1071
1273
|
props = this.props;
|
|
1072
|
-
this.id = props.id ||
|
|
1274
|
+
this.id = props.id || uid("model");
|
|
1073
1275
|
this.device = device;
|
|
1074
1276
|
Object.assign(this.userData, props.userData);
|
|
1075
1277
|
const moduleMap = Object.fromEntries(((_a = this.props.modules) == null ? void 0 : _a.map((module2) => [module2.name, module2])) || []);
|
|
1076
1278
|
this.setShaderInputs(props.shaderInputs || new ShaderInputs(moduleMap));
|
|
1077
1279
|
const platformInfo = getPlatformInfo(device);
|
|
1078
|
-
const modules = (
|
|
1280
|
+
const modules = (
|
|
1281
|
+
// @ts-expect-error shaderInputs is assigned in setShaderInputs above.
|
|
1282
|
+
(((_b = this.props.modules) == null ? void 0 : _b.length) > 0 ? this.props.modules : (_c = this.shaderInputs) == null ? void 0 : _c.getModules()) || []
|
|
1283
|
+
);
|
|
1079
1284
|
const isWebGPU = this.device.type === "webgpu";
|
|
1080
1285
|
if (isWebGPU && this.props.source) {
|
|
1081
1286
|
this.props.shaderLayout ||= (0, import_shadertools2.getShaderLayoutFromWGSL)(this.props.source);
|
|
1082
|
-
const { source, getUniforms } = this.props.shaderAssembler.
|
|
1287
|
+
const { source, getUniforms } = this.props.shaderAssembler.assembleWGSLShader({
|
|
1083
1288
|
platformInfo,
|
|
1084
1289
|
...this.props,
|
|
1085
1290
|
modules
|
|
@@ -1087,7 +1292,7 @@ var _Model = class {
|
|
|
1087
1292
|
this.source = source;
|
|
1088
1293
|
this._getModuleUniforms = getUniforms;
|
|
1089
1294
|
} else {
|
|
1090
|
-
const { vs, fs, getUniforms } = this.props.shaderAssembler.
|
|
1295
|
+
const { vs, fs, getUniforms } = this.props.shaderAssembler.assembleGLSLShaderPair({
|
|
1091
1296
|
platformInfo,
|
|
1092
1297
|
...this.props,
|
|
1093
1298
|
modules
|
|
@@ -1113,7 +1318,7 @@ var _Model = class {
|
|
|
1113
1318
|
if (this._gpuGeometry) {
|
|
1114
1319
|
this._setGeometryAttributes(this._gpuGeometry);
|
|
1115
1320
|
}
|
|
1116
|
-
if (props
|
|
1321
|
+
if ("isInstanced" in props) {
|
|
1117
1322
|
this.isInstanced = props.isInstanced;
|
|
1118
1323
|
}
|
|
1119
1324
|
if (props.instanceCount) {
|
|
@@ -1182,8 +1387,11 @@ var _Model = class {
|
|
|
1182
1387
|
try {
|
|
1183
1388
|
this._logDrawCallStart();
|
|
1184
1389
|
this.pipeline = this._updatePipeline();
|
|
1185
|
-
|
|
1186
|
-
|
|
1390
|
+
const syncBindings = this._getBindings();
|
|
1391
|
+
this.pipeline.setBindings(syncBindings, {
|
|
1392
|
+
disableWarnings: this.props.disableWarnings
|
|
1393
|
+
});
|
|
1394
|
+
if (!isObjectEmpty(this.uniforms)) {
|
|
1187
1395
|
this.pipeline.setUniformsWebGL(this.uniforms);
|
|
1188
1396
|
}
|
|
1189
1397
|
const { indexBuffer } = this.vertexArray;
|
|
@@ -1264,7 +1472,7 @@ var _Model = class {
|
|
|
1264
1472
|
* @param parameters
|
|
1265
1473
|
*/
|
|
1266
1474
|
setParameters(parameters) {
|
|
1267
|
-
if (!
|
|
1475
|
+
if (!deepEqual(parameters, this.parameters, 2)) {
|
|
1268
1476
|
this.parameters = parameters;
|
|
1269
1477
|
this._setPipelineNeedsUpdate("parameters");
|
|
1270
1478
|
}
|
|
@@ -1292,7 +1500,7 @@ var _Model = class {
|
|
|
1292
1500
|
/** Set the shader inputs */
|
|
1293
1501
|
setShaderInputs(shaderInputs) {
|
|
1294
1502
|
this.shaderInputs = shaderInputs;
|
|
1295
|
-
this._uniformStore = new
|
|
1503
|
+
this._uniformStore = new import_core8.UniformStore(this.shaderInputs.modules);
|
|
1296
1504
|
for (const moduleName of Object.keys(this.shaderInputs.modules)) {
|
|
1297
1505
|
const uniformBuffer = this._uniformStore.getManagedUniformBuffer(this.device, moduleName);
|
|
1298
1506
|
this.bindings[`${moduleName}Uniforms`] = uniformBuffer;
|
|
@@ -1332,12 +1540,12 @@ var _Model = class {
|
|
|
1332
1540
|
*/
|
|
1333
1541
|
setAttributes(buffers, options) {
|
|
1334
1542
|
if (buffers.indices) {
|
|
1335
|
-
|
|
1543
|
+
import_core9.log.warn(`Model:${this.id} setAttributes() - indexBuffer should be set using setIndexBuffer()`)();
|
|
1336
1544
|
}
|
|
1337
1545
|
for (const [bufferName, buffer] of Object.entries(buffers)) {
|
|
1338
1546
|
const bufferLayout = this.bufferLayout.find((layout) => getAttributeNames(layout).includes(bufferName));
|
|
1339
1547
|
if (!bufferLayout) {
|
|
1340
|
-
|
|
1548
|
+
import_core9.log.warn(`Model(${this.id}): Missing layout for buffer "${bufferName}".`)();
|
|
1341
1549
|
continue;
|
|
1342
1550
|
}
|
|
1343
1551
|
const attributeNames = getAttributeNames(bufferLayout);
|
|
@@ -1350,7 +1558,7 @@ var _Model = class {
|
|
|
1350
1558
|
}
|
|
1351
1559
|
}
|
|
1352
1560
|
if (!set && !((options == null ? void 0 : options.disableWarnings) ?? this.props.disableWarnings)) {
|
|
1353
|
-
|
|
1561
|
+
import_core9.log.warn(`Model(${this.id}): Ignoring buffer "${buffer.id}" for unknown attribute "${bufferName}"`)();
|
|
1354
1562
|
}
|
|
1355
1563
|
}
|
|
1356
1564
|
this.setNeedsRedraw("attributes");
|
|
@@ -1369,7 +1577,7 @@ var _Model = class {
|
|
|
1369
1577
|
if (attributeInfo) {
|
|
1370
1578
|
this.vertexArray.setConstantWebGL(attributeInfo.location, value);
|
|
1371
1579
|
} else if (!((options == null ? void 0 : options.disableWarnings) ?? this.props.disableWarnings)) {
|
|
1372
|
-
|
|
1580
|
+
import_core9.log.warn(`Model "${this.id}: Ignoring constant supplied for unknown attribute "${attributeName}"`)();
|
|
1373
1581
|
}
|
|
1374
1582
|
}
|
|
1375
1583
|
this.setNeedsRedraw("constants");
|
|
@@ -1381,7 +1589,7 @@ var _Model = class {
|
|
|
1381
1589
|
* @param uniforms
|
|
1382
1590
|
*/
|
|
1383
1591
|
setUniforms(uniforms) {
|
|
1384
|
-
if (!
|
|
1592
|
+
if (!isObjectEmpty(uniforms)) {
|
|
1385
1593
|
this.pipeline.setUniformsWebGL(uniforms);
|
|
1386
1594
|
Object.assign(this.uniforms, uniforms);
|
|
1387
1595
|
}
|
|
@@ -1391,21 +1599,39 @@ var _Model = class {
|
|
|
1391
1599
|
* @deprecated Updates shader module settings (which results in uniforms being set)
|
|
1392
1600
|
*/
|
|
1393
1601
|
updateModuleSettings(props) {
|
|
1394
|
-
const { bindings, uniforms } =
|
|
1602
|
+
const { bindings, uniforms } = splitUniformsAndBindings(this._getModuleUniforms(props));
|
|
1395
1603
|
Object.assign(this.bindings, bindings);
|
|
1396
1604
|
Object.assign(this.uniforms, uniforms);
|
|
1397
1605
|
this.setNeedsRedraw("moduleSettings");
|
|
1398
1606
|
}
|
|
1399
1607
|
// Internal methods
|
|
1608
|
+
/** Get texture / texture view from any async textures */
|
|
1609
|
+
_getBindings() {
|
|
1610
|
+
return Object.entries(this.bindings).reduce((acc, [name, binding]) => {
|
|
1611
|
+
if (binding instanceof AsyncTexture) {
|
|
1612
|
+
if (binding.isReady) {
|
|
1613
|
+
acc[name] = binding.texture;
|
|
1614
|
+
}
|
|
1615
|
+
} else {
|
|
1616
|
+
acc[name] = binding;
|
|
1617
|
+
}
|
|
1618
|
+
return acc;
|
|
1619
|
+
}, {});
|
|
1620
|
+
}
|
|
1400
1621
|
/** Get the timestamp of the latest updated bound GPU memory resource (buffer/texture). */
|
|
1401
1622
|
_getBindingsUpdateTimestamp() {
|
|
1402
1623
|
let timestamp = 0;
|
|
1403
1624
|
for (const binding of Object.values(this.bindings)) {
|
|
1404
|
-
if (binding instanceof
|
|
1625
|
+
if (binding instanceof import_core7.TextureView) {
|
|
1405
1626
|
timestamp = Math.max(timestamp, binding.texture.updateTimestamp);
|
|
1406
|
-
} else if (binding instanceof
|
|
1627
|
+
} else if (binding instanceof import_core7.Buffer || binding instanceof import_core7.Texture) {
|
|
1407
1628
|
timestamp = Math.max(timestamp, binding.updateTimestamp);
|
|
1408
|
-
} else if (
|
|
1629
|
+
} else if (binding instanceof AsyncTexture) {
|
|
1630
|
+
timestamp = binding.texture ? Math.max(timestamp, binding.texture.updateTimestamp) : (
|
|
1631
|
+
// The texture will become available in the future
|
|
1632
|
+
Infinity
|
|
1633
|
+
);
|
|
1634
|
+
} else if (!(binding instanceof import_core7.Sampler)) {
|
|
1409
1635
|
timestamp = Math.max(timestamp, binding.buffer.updateTimestamp);
|
|
1410
1636
|
}
|
|
1411
1637
|
}
|
|
@@ -1440,7 +1666,7 @@ var _Model = class {
|
|
|
1440
1666
|
let prevShaderVs = null;
|
|
1441
1667
|
let prevShaderFs = null;
|
|
1442
1668
|
if (this.pipeline) {
|
|
1443
|
-
|
|
1669
|
+
import_core9.log.log(1, `Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)();
|
|
1444
1670
|
prevShaderVs = this.pipeline.vs;
|
|
1445
1671
|
prevShaderFs = this.pipeline.fs;
|
|
1446
1672
|
}
|
|
@@ -1467,10 +1693,13 @@ var _Model = class {
|
|
|
1467
1693
|
bufferLayout: this.bufferLayout,
|
|
1468
1694
|
topology: this.topology,
|
|
1469
1695
|
parameters: this.parameters,
|
|
1696
|
+
// TODO - why set bindings here when we reset them every frame?
|
|
1697
|
+
// Should we expose a BindGroup abstraction?
|
|
1698
|
+
bindings: this._getBindings(),
|
|
1470
1699
|
vs,
|
|
1471
1700
|
fs
|
|
1472
1701
|
});
|
|
1473
|
-
this._attributeInfos = (0,
|
|
1702
|
+
this._attributeInfos = (0, import_core10.getAttributeInfosFromLayouts)(this.pipeline.shaderLayout, this.bufferLayout);
|
|
1474
1703
|
if (prevShaderVs)
|
|
1475
1704
|
this.shaderFactory.release(prevShaderVs);
|
|
1476
1705
|
if (prevShaderFs)
|
|
@@ -1482,33 +1711,33 @@ var _Model = class {
|
|
|
1482
1711
|
_lastLogTime = 0;
|
|
1483
1712
|
_logOpen = false;
|
|
1484
1713
|
_logDrawCallStart() {
|
|
1485
|
-
const logDrawTimeout =
|
|
1486
|
-
if (
|
|
1714
|
+
const logDrawTimeout = import_core9.log.level > 3 ? 0 : LOG_DRAW_TIMEOUT;
|
|
1715
|
+
if (import_core9.log.level < 2 || Date.now() - this._lastLogTime < logDrawTimeout) {
|
|
1487
1716
|
return;
|
|
1488
1717
|
}
|
|
1489
1718
|
this._lastLogTime = Date.now();
|
|
1490
1719
|
this._logOpen = true;
|
|
1491
|
-
|
|
1720
|
+
import_core9.log.group(LOG_DRAW_PRIORITY, `>>> DRAWING MODEL ${this.id}`, { collapsed: import_core9.log.level <= 2 })();
|
|
1492
1721
|
}
|
|
1493
1722
|
_logDrawCallEnd() {
|
|
1494
1723
|
if (this._logOpen) {
|
|
1495
1724
|
const shaderLayoutTable = getDebugTableForShaderLayout(this.pipeline.shaderLayout, this.id);
|
|
1496
|
-
|
|
1725
|
+
import_core9.log.table(LOG_DRAW_PRIORITY, shaderLayoutTable)();
|
|
1497
1726
|
const uniformTable = this.shaderInputs.getDebugTable();
|
|
1498
1727
|
for (const [name, value] of Object.entries(this.uniforms)) {
|
|
1499
1728
|
uniformTable[name] = { value };
|
|
1500
1729
|
}
|
|
1501
|
-
|
|
1730
|
+
import_core9.log.table(LOG_DRAW_PRIORITY, uniformTable)();
|
|
1502
1731
|
const attributeTable = this._getAttributeDebugTable();
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1732
|
+
import_core9.log.table(LOG_DRAW_PRIORITY, this._attributeInfos)();
|
|
1733
|
+
import_core9.log.table(LOG_DRAW_PRIORITY, attributeTable)();
|
|
1734
|
+
import_core9.log.groupEnd(LOG_DRAW_PRIORITY)();
|
|
1506
1735
|
this._logOpen = false;
|
|
1507
1736
|
}
|
|
1508
1737
|
}
|
|
1509
1738
|
_drawCount = 0;
|
|
1510
1739
|
_logFramebuffer(renderPass) {
|
|
1511
|
-
const debugFramebuffers =
|
|
1740
|
+
const debugFramebuffers = import_core9.log.get("framebuffer");
|
|
1512
1741
|
this._drawCount++;
|
|
1513
1742
|
if (!debugFramebuffers || this._drawCount++ > 3 && this._drawCount % 60) {
|
|
1514
1743
|
return;
|
|
@@ -1521,10 +1750,11 @@ var _Model = class {
|
|
|
1521
1750
|
_getAttributeDebugTable() {
|
|
1522
1751
|
const table = {};
|
|
1523
1752
|
for (const [name, attributeInfo] of Object.entries(this._attributeInfos)) {
|
|
1753
|
+
const values = this.vertexArray.attributes[attributeInfo.location];
|
|
1524
1754
|
table[attributeInfo.location] = {
|
|
1525
1755
|
name,
|
|
1526
1756
|
type: attributeInfo.shaderType,
|
|
1527
|
-
values: this._getBufferOrConstantValues(
|
|
1757
|
+
values: values ? this._getBufferOrConstantValues(values, attributeInfo.bufferDataType) : "null"
|
|
1528
1758
|
};
|
|
1529
1759
|
}
|
|
1530
1760
|
if (this.vertexArray.indexBuffer) {
|
|
@@ -1540,15 +1770,15 @@ var _Model = class {
|
|
|
1540
1770
|
}
|
|
1541
1771
|
// TODO - fix typing of luma data types
|
|
1542
1772
|
_getBufferOrConstantValues(attribute, dataType) {
|
|
1543
|
-
const TypedArrayConstructor = (0,
|
|
1544
|
-
const typedArray = attribute instanceof
|
|
1773
|
+
const TypedArrayConstructor = (0, import_core10.getTypedArrayFromDataType)(dataType);
|
|
1774
|
+
const typedArray = attribute instanceof import_core7.Buffer ? new TypedArrayConstructor(attribute.debugData) : attribute;
|
|
1545
1775
|
return typedArray.toString();
|
|
1546
1776
|
}
|
|
1547
1777
|
};
|
|
1548
1778
|
var Model = _Model;
|
|
1549
1779
|
__publicField(Model, "defaultProps", {
|
|
1550
|
-
...
|
|
1551
|
-
source:
|
|
1780
|
+
...import_core8.RenderPipeline.defaultProps,
|
|
1781
|
+
source: void 0,
|
|
1552
1782
|
vs: null,
|
|
1553
1783
|
fs: null,
|
|
1554
1784
|
id: "unnamed",
|
|
@@ -1599,9 +1829,17 @@ function getAttributeNames(bufferLayout) {
|
|
|
1599
1829
|
var _a;
|
|
1600
1830
|
return bufferLayout.attributes ? (_a = bufferLayout.attributes) == null ? void 0 : _a.map((layout) => layout.attribute) : [bufferLayout.name];
|
|
1601
1831
|
}
|
|
1832
|
+
function isObjectEmpty(obj) {
|
|
1833
|
+
let isEmpty = true;
|
|
1834
|
+
for (const key in obj) {
|
|
1835
|
+
isEmpty = false;
|
|
1836
|
+
break;
|
|
1837
|
+
}
|
|
1838
|
+
return isEmpty;
|
|
1839
|
+
}
|
|
1602
1840
|
|
|
1603
1841
|
// dist/transform/buffer-transform.js
|
|
1604
|
-
var
|
|
1842
|
+
var import_core11 = require("@luma.gl/core");
|
|
1605
1843
|
var import_shadertools3 = require("@luma.gl/shadertools");
|
|
1606
1844
|
var BufferTransform = class {
|
|
1607
1845
|
device;
|
|
@@ -1613,7 +1851,9 @@ var BufferTransform = class {
|
|
|
1613
1851
|
return ((_a = device == null ? void 0 : device.info) == null ? void 0 : _a.type) === "webgl";
|
|
1614
1852
|
}
|
|
1615
1853
|
constructor(device, props = Model.defaultProps) {
|
|
1616
|
-
|
|
1854
|
+
if (!BufferTransform.isSupported(device)) {
|
|
1855
|
+
throw new Error("BufferTransform not yet implemented on WebGPU");
|
|
1856
|
+
}
|
|
1617
1857
|
this.device = device;
|
|
1618
1858
|
this.model = new Model(this.device, {
|
|
1619
1859
|
id: props.id || "buffer-transform-model",
|
|
@@ -1623,6 +1863,7 @@ var BufferTransform = class {
|
|
|
1623
1863
|
});
|
|
1624
1864
|
this.transformFeedback = this.device.createTransformFeedback({
|
|
1625
1865
|
layout: this.model.pipeline.shaderLayout,
|
|
1866
|
+
// @ts-expect-error TODO
|
|
1626
1867
|
buffers: props.feedbackBuffers
|
|
1627
1868
|
});
|
|
1628
1869
|
this.model.setTransformFeedback(this.transformFeedback);
|
|
@@ -1654,7 +1895,10 @@ var BufferTransform = class {
|
|
|
1654
1895
|
}
|
|
1655
1896
|
readAsync(varyingName) {
|
|
1656
1897
|
const result = this.getBuffer(varyingName);
|
|
1657
|
-
if (result
|
|
1898
|
+
if (!result) {
|
|
1899
|
+
throw new Error("BufferTransform#getBuffer");
|
|
1900
|
+
}
|
|
1901
|
+
if (result instanceof import_core11.Buffer) {
|
|
1658
1902
|
return result.readAsync();
|
|
1659
1903
|
}
|
|
1660
1904
|
const { buffer, byteOffset = 0, byteLength = buffer.byteLength } = result;
|
|
@@ -1738,6 +1982,7 @@ var TextureTransform = class {
|
|
|
1738
1982
|
binding = {
|
|
1739
1983
|
sourceBuffers: {},
|
|
1740
1984
|
sourceTextures: {},
|
|
1985
|
+
// @ts-expect-error
|
|
1741
1986
|
targetTexture: null
|
|
1742
1987
|
};
|
|
1743
1988
|
}
|
|
@@ -1770,10 +2015,9 @@ var TextureTransform = class {
|
|
|
1770
2015
|
};
|
|
1771
2016
|
|
|
1772
2017
|
// dist/lib/clip-space.js
|
|
1773
|
-
var
|
|
2018
|
+
var import_core12 = require("@luma.gl/core");
|
|
1774
2019
|
|
|
1775
2020
|
// dist/geometry/geometry.js
|
|
1776
|
-
var import_core13 = require("@luma.gl/core");
|
|
1777
2021
|
var Geometry = class {
|
|
1778
2022
|
id;
|
|
1779
2023
|
/** Determines how vertices are read from the 'vertex' attributes */
|
|
@@ -1784,7 +2028,7 @@ var Geometry = class {
|
|
|
1784
2028
|
userData = {};
|
|
1785
2029
|
constructor(props) {
|
|
1786
2030
|
const { attributes = {}, indices = null, vertexCount = null } = props;
|
|
1787
|
-
this.id = props.id ||
|
|
2031
|
+
this.id = props.id || uid("geometry");
|
|
1788
2032
|
this.topology = props.topology;
|
|
1789
2033
|
if (indices) {
|
|
1790
2034
|
this.indices = ArrayBuffer.isView(indices) ? { value: indices, size: 1 } : indices;
|
|
@@ -1792,12 +2036,16 @@ var Geometry = class {
|
|
|
1792
2036
|
this.attributes = {};
|
|
1793
2037
|
for (const [attributeName, attributeValue] of Object.entries(attributes)) {
|
|
1794
2038
|
const attribute = ArrayBuffer.isView(attributeValue) ? { value: attributeValue } : attributeValue;
|
|
1795
|
-
|
|
2039
|
+
if (!ArrayBuffer.isView(attribute.value)) {
|
|
2040
|
+
throw new Error(`${this._print(attributeName)}: must be typed array or object with value as typed array`);
|
|
2041
|
+
}
|
|
1796
2042
|
if ((attributeName === "POSITION" || attributeName === "positions") && !attribute.size) {
|
|
1797
2043
|
attribute.size = 3;
|
|
1798
2044
|
}
|
|
1799
2045
|
if (attributeName === "indices") {
|
|
1800
|
-
|
|
2046
|
+
if (this.indices) {
|
|
2047
|
+
throw new Error("Multiple indices detected");
|
|
2048
|
+
}
|
|
1801
2049
|
this.indices = attribute;
|
|
1802
2050
|
} else {
|
|
1803
2051
|
this.attributes[attributeName] = attribute;
|
|
@@ -1844,11 +2092,10 @@ var Geometry = class {
|
|
|
1844
2092
|
let vertexCount = Infinity;
|
|
1845
2093
|
for (const attribute of Object.values(attributes)) {
|
|
1846
2094
|
const { value, size, constant } = attribute;
|
|
1847
|
-
if (!constant && value && size >= 1) {
|
|
2095
|
+
if (!constant && value && size !== void 0 && size >= 1) {
|
|
1848
2096
|
vertexCount = Math.min(vertexCount, value.length / size);
|
|
1849
2097
|
}
|
|
1850
2098
|
}
|
|
1851
|
-
(0, import_core13.assert)(Number.isFinite(vertexCount));
|
|
1852
2099
|
return vertexCount;
|
|
1853
2100
|
}
|
|
1854
2101
|
};
|
|
@@ -1890,20 +2137,19 @@ var ClipSpace = class extends Model {
|
|
|
1890
2137
|
};
|
|
1891
2138
|
|
|
1892
2139
|
// dist/scenegraph/scenegraph-node.js
|
|
1893
|
-
var
|
|
1894
|
-
var import_core16 = require("@math.gl/core");
|
|
2140
|
+
var import_core13 = require("@math.gl/core");
|
|
1895
2141
|
var ScenegraphNode = class {
|
|
1896
2142
|
id;
|
|
1897
|
-
matrix = new
|
|
2143
|
+
matrix = new import_core13.Matrix4();
|
|
1898
2144
|
display = true;
|
|
1899
|
-
position = new
|
|
1900
|
-
rotation = new
|
|
1901
|
-
scale = new
|
|
2145
|
+
position = new import_core13.Vector3();
|
|
2146
|
+
rotation = new import_core13.Vector3();
|
|
2147
|
+
scale = new import_core13.Vector3(1, 1, 1);
|
|
1902
2148
|
userData = {};
|
|
1903
2149
|
props = {};
|
|
1904
2150
|
constructor(props = {}) {
|
|
1905
2151
|
const { id } = props;
|
|
1906
|
-
this.id = id ||
|
|
2152
|
+
this.id = id || uid(this.constructor.name);
|
|
1907
2153
|
this._setScenegraphNodeProps(props);
|
|
1908
2154
|
}
|
|
1909
2155
|
getBounds() {
|
|
@@ -1923,17 +2169,14 @@ var ScenegraphNode = class {
|
|
|
1923
2169
|
return `{type: ScenegraphNode, id: ${this.id})}`;
|
|
1924
2170
|
}
|
|
1925
2171
|
setPosition(position) {
|
|
1926
|
-
(0, import_core15.assert)(position.length === 3, "setPosition requires vector argument");
|
|
1927
2172
|
this.position = position;
|
|
1928
2173
|
return this;
|
|
1929
2174
|
}
|
|
1930
2175
|
setRotation(rotation) {
|
|
1931
|
-
(0, import_core15.assert)(rotation.length === 3, "setRotation requires vector argument");
|
|
1932
2176
|
this.rotation = rotation;
|
|
1933
2177
|
return this;
|
|
1934
2178
|
}
|
|
1935
2179
|
setScale(scale) {
|
|
1936
|
-
(0, import_core15.assert)(scale.length === 3, "setScale requires vector argument");
|
|
1937
2180
|
this.scale = scale;
|
|
1938
2181
|
return this;
|
|
1939
2182
|
}
|
|
@@ -1985,9 +2228,8 @@ var ScenegraphNode = class {
|
|
|
1985
2228
|
return this;
|
|
1986
2229
|
}
|
|
1987
2230
|
getCoordinateUniforms(viewMatrix, modelMatrix) {
|
|
1988
|
-
(0, import_core15.assert)(viewMatrix);
|
|
1989
2231
|
modelMatrix = modelMatrix || this.matrix;
|
|
1990
|
-
const worldMatrix = new
|
|
2232
|
+
const worldMatrix = new import_core13.Matrix4(viewMatrix).multiplyRight(modelMatrix);
|
|
1991
2233
|
const worldInverse = worldMatrix.invert();
|
|
1992
2234
|
const worldInverseTranspose = worldInverse.transpose();
|
|
1993
2235
|
return {
|
|
@@ -2022,9 +2264,6 @@ var ScenegraphNode = class {
|
|
|
2022
2264
|
}
|
|
2023
2265
|
*/
|
|
2024
2266
|
_setScenegraphNodeProps(props) {
|
|
2025
|
-
if ("display" in props) {
|
|
2026
|
-
this.display = props.display;
|
|
2027
|
-
}
|
|
2028
2267
|
if ("position" in props) {
|
|
2029
2268
|
this.setPosition(props.position);
|
|
2030
2269
|
}
|
|
@@ -2042,14 +2281,14 @@ var ScenegraphNode = class {
|
|
|
2042
2281
|
};
|
|
2043
2282
|
|
|
2044
2283
|
// dist/scenegraph/group-node.js
|
|
2045
|
-
var
|
|
2046
|
-
var
|
|
2284
|
+
var import_core14 = require("@math.gl/core");
|
|
2285
|
+
var import_core15 = require("@luma.gl/core");
|
|
2047
2286
|
var GroupNode = class extends ScenegraphNode {
|
|
2048
2287
|
children;
|
|
2049
2288
|
constructor(props = {}) {
|
|
2050
2289
|
props = Array.isArray(props) ? { children: props } : props;
|
|
2051
2290
|
const { children = [] } = props;
|
|
2052
|
-
|
|
2291
|
+
import_core15.log.assert(children.every((child) => child instanceof ScenegraphNode), "every child must an instance of ScenegraphNode");
|
|
2053
2292
|
super(props);
|
|
2054
2293
|
this.children = children;
|
|
2055
2294
|
}
|
|
@@ -2064,12 +2303,12 @@ var GroupNode = class extends ScenegraphNode {
|
|
|
2064
2303
|
return;
|
|
2065
2304
|
}
|
|
2066
2305
|
const [min, max] = bounds;
|
|
2067
|
-
const center = new
|
|
2306
|
+
const center = new import_core14.Vector3(min).add(max).divide([2, 2, 2]);
|
|
2068
2307
|
worldMatrix.transformAsPoint(center, center);
|
|
2069
|
-
const halfSize = new
|
|
2308
|
+
const halfSize = new import_core14.Vector3(max).subtract(min).divide([2, 2, 2]);
|
|
2070
2309
|
worldMatrix.transformAsVector(halfSize, halfSize);
|
|
2071
2310
|
for (let v = 0; v < 8; v++) {
|
|
2072
|
-
const position = new
|
|
2311
|
+
const position = new import_core14.Vector3(v & 1 ? -1 : 1, v & 2 ? -1 : 1, v & 4 ? -1 : 1).multiply(halfSize).add(center);
|
|
2073
2312
|
for (let i = 0; i < 3; i++) {
|
|
2074
2313
|
result[0][i] = Math.min(result[0][i], position[i]);
|
|
2075
2314
|
result[1][i] = Math.max(result[1][i], position[i]);
|
|
@@ -2109,8 +2348,8 @@ var GroupNode = class extends ScenegraphNode {
|
|
|
2109
2348
|
this.children = [];
|
|
2110
2349
|
return this;
|
|
2111
2350
|
}
|
|
2112
|
-
traverse(visitor, { worldMatrix = new
|
|
2113
|
-
const modelMatrix = new
|
|
2351
|
+
traverse(visitor, { worldMatrix = new import_core14.Matrix4() } = {}) {
|
|
2352
|
+
const modelMatrix = new import_core14.Matrix4(worldMatrix).multiplyRight(this.matrix);
|
|
2114
2353
|
for (const child of this.children) {
|
|
2115
2354
|
if (child instanceof GroupNode) {
|
|
2116
2355
|
child.traverse(visitor, { worldMatrix: modelMatrix });
|
|
@@ -2137,9 +2376,6 @@ var ModelNode = class extends ScenegraphNode {
|
|
|
2137
2376
|
this.bounds = props.bounds || null;
|
|
2138
2377
|
this.setProps(props);
|
|
2139
2378
|
}
|
|
2140
|
-
getBounds() {
|
|
2141
|
-
return this.bounds;
|
|
2142
|
-
}
|
|
2143
2379
|
destroy() {
|
|
2144
2380
|
if (this.model) {
|
|
2145
2381
|
this.model.destroy();
|
|
@@ -2148,17 +2384,16 @@ var ModelNode = class extends ScenegraphNode {
|
|
|
2148
2384
|
this.managedResources.forEach((resource) => resource.destroy());
|
|
2149
2385
|
this.managedResources = [];
|
|
2150
2386
|
}
|
|
2387
|
+
getBounds() {
|
|
2388
|
+
return this.bounds;
|
|
2389
|
+
}
|
|
2151
2390
|
// Expose model methods
|
|
2152
2391
|
draw(renderPass) {
|
|
2153
2392
|
return this.model.draw(renderPass);
|
|
2154
2393
|
}
|
|
2155
2394
|
};
|
|
2156
2395
|
|
|
2157
|
-
// dist/geometries/cone-geometry.js
|
|
2158
|
-
var import_core20 = require("@luma.gl/core");
|
|
2159
|
-
|
|
2160
2396
|
// dist/geometries/truncated-cone-geometry.js
|
|
2161
|
-
var import_core19 = require("@luma.gl/core");
|
|
2162
2397
|
var INDEX_OFFSETS = {
|
|
2163
2398
|
x: [2, 0, 1],
|
|
2164
2399
|
y: [0, 1, 2],
|
|
@@ -2166,7 +2401,7 @@ var INDEX_OFFSETS = {
|
|
|
2166
2401
|
};
|
|
2167
2402
|
var TruncatedConeGeometry = class extends Geometry {
|
|
2168
2403
|
constructor(props = {}) {
|
|
2169
|
-
const { id =
|
|
2404
|
+
const { id = uid("truncated-code-geometry") } = props;
|
|
2170
2405
|
const { indices, attributes } = tesselateTruncatedCone(props);
|
|
2171
2406
|
super({
|
|
2172
2407
|
...props,
|
|
@@ -2261,7 +2496,7 @@ function tesselateTruncatedCone(props = {}) {
|
|
|
2261
2496
|
// dist/geometries/cone-geometry.js
|
|
2262
2497
|
var ConeGeometry = class extends TruncatedConeGeometry {
|
|
2263
2498
|
constructor(props = {}) {
|
|
2264
|
-
const { id =
|
|
2499
|
+
const { id = uid("cone-geometry"), radius = 1, cap = true } = props;
|
|
2265
2500
|
super({
|
|
2266
2501
|
...props,
|
|
2267
2502
|
id,
|
|
@@ -2274,10 +2509,9 @@ var ConeGeometry = class extends TruncatedConeGeometry {
|
|
|
2274
2509
|
};
|
|
2275
2510
|
|
|
2276
2511
|
// dist/geometries/cube-geometry.js
|
|
2277
|
-
var import_core21 = require("@luma.gl/core");
|
|
2278
2512
|
var CubeGeometry = class extends Geometry {
|
|
2279
2513
|
constructor(props = {}) {
|
|
2280
|
-
const { id =
|
|
2514
|
+
const { id = uid("cube-geometry"), indices = true } = props;
|
|
2281
2515
|
super(indices ? {
|
|
2282
2516
|
...props,
|
|
2283
2517
|
id,
|
|
@@ -2884,10 +3118,9 @@ var NON_INDEXED_ATTRIBUTES = {
|
|
|
2884
3118
|
};
|
|
2885
3119
|
|
|
2886
3120
|
// dist/geometries/cylinder-geometry.js
|
|
2887
|
-
var import_core22 = require("@luma.gl/core");
|
|
2888
3121
|
var CylinderGeometry = class extends TruncatedConeGeometry {
|
|
2889
3122
|
constructor(props = {}) {
|
|
2890
|
-
const { id =
|
|
3123
|
+
const { id = uid("cylinder-geometry"), radius = 1 } = props;
|
|
2891
3124
|
super({
|
|
2892
3125
|
...props,
|
|
2893
3126
|
id,
|
|
@@ -2898,13 +3131,12 @@ var CylinderGeometry = class extends TruncatedConeGeometry {
|
|
|
2898
3131
|
};
|
|
2899
3132
|
|
|
2900
3133
|
// dist/geometries/ico-sphere-geometry.js
|
|
2901
|
-
var
|
|
2902
|
-
var import_core24 = require("@math.gl/core");
|
|
3134
|
+
var import_core16 = require("@math.gl/core");
|
|
2903
3135
|
var ICO_POSITIONS = [-1, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 1, 0, -1, 0, 1, 0, 0];
|
|
2904
3136
|
var ICO_INDICES = [3, 4, 5, 3, 5, 1, 3, 1, 0, 3, 0, 4, 4, 0, 2, 4, 2, 5, 2, 0, 1, 5, 2, 1];
|
|
2905
3137
|
var IcoSphereGeometry = class extends Geometry {
|
|
2906
3138
|
constructor(props = {}) {
|
|
2907
|
-
const { id =
|
|
3139
|
+
const { id = uid("ico-sphere-geometry") } = props;
|
|
2908
3140
|
const { indices, attributes } = tesselateIcosaHedron(props);
|
|
2909
3141
|
super({
|
|
2910
3142
|
...props,
|
|
@@ -2997,7 +3229,7 @@ function tesselateIcosaHedron(props) {
|
|
|
2997
3229
|
const u3 = 1 - phi3 / PI2;
|
|
2998
3230
|
const vec1 = [x3 - x2, y3 - y2, z3 - z2];
|
|
2999
3231
|
const vec2 = [x1 - x2, y1 - y2, z1 - z2];
|
|
3000
|
-
const normal = new
|
|
3232
|
+
const normal = new import_core16.Vector3(vec1).cross(vec2).normalize();
|
|
3001
3233
|
let newIndex;
|
|
3002
3234
|
if ((u1 === 0 || u2 === 0 || u3 === 0) && (u1 === 0 || u1 > 0.5) && (u2 === 0 || u2 > 0.5) && (u3 === 0 || u3 > 0.5)) {
|
|
3003
3235
|
positions.push(positions[in1 + 0], positions[in1 + 1], positions[in1 + 2]);
|
|
@@ -3045,9 +3277,6 @@ function tesselateIcosaHedron(props) {
|
|
|
3045
3277
|
};
|
|
3046
3278
|
}
|
|
3047
3279
|
|
|
3048
|
-
// dist/geometries/plane-geometry.js
|
|
3049
|
-
var import_core25 = require("@luma.gl/core");
|
|
3050
|
-
|
|
3051
3280
|
// dist/geometry/geometry-utils.js
|
|
3052
3281
|
function unpackIndexedGeometry(geometry) {
|
|
3053
3282
|
const { indices, attributes } = geometry;
|
|
@@ -3079,7 +3308,7 @@ function unpackIndexedGeometry(geometry) {
|
|
|
3079
3308
|
// dist/geometries/plane-geometry.js
|
|
3080
3309
|
var PlaneGeometry = class extends Geometry {
|
|
3081
3310
|
constructor(props = {}) {
|
|
3082
|
-
const { id =
|
|
3311
|
+
const { id = uid("plane-geometry") } = props;
|
|
3083
3312
|
const { indices, attributes } = tesselatePlane(props);
|
|
3084
3313
|
super({
|
|
3085
3314
|
...props,
|
|
@@ -3169,10 +3398,9 @@ function tesselatePlane(props) {
|
|
|
3169
3398
|
}
|
|
3170
3399
|
|
|
3171
3400
|
// dist/geometries/sphere-geometry.js
|
|
3172
|
-
var import_core26 = require("@luma.gl/core");
|
|
3173
3401
|
var SphereGeometry = class extends Geometry {
|
|
3174
3402
|
constructor(props = {}) {
|
|
3175
|
-
const { id =
|
|
3403
|
+
const { id = uid("sphere-geometry") } = props;
|
|
3176
3404
|
const { indices, attributes } = tesselateSphere(props);
|
|
3177
3405
|
super({
|
|
3178
3406
|
...props,
|
|
@@ -3247,11 +3475,26 @@ function tesselateSphere(props) {
|
|
|
3247
3475
|
};
|
|
3248
3476
|
}
|
|
3249
3477
|
|
|
3478
|
+
// dist/application-utils/random.js
|
|
3479
|
+
function makeRandomGenerator() {
|
|
3480
|
+
let s = 1;
|
|
3481
|
+
let c = 1;
|
|
3482
|
+
return () => {
|
|
3483
|
+
s = Math.sin(c * 17.23);
|
|
3484
|
+
c = Math.cos(s * 27.92);
|
|
3485
|
+
return fract(Math.abs(s * c) * 1432.71);
|
|
3486
|
+
};
|
|
3487
|
+
}
|
|
3488
|
+
function fract(n) {
|
|
3489
|
+
return n - Math.floor(n);
|
|
3490
|
+
}
|
|
3491
|
+
|
|
3250
3492
|
// dist/computation.js
|
|
3251
|
-
var
|
|
3252
|
-
var
|
|
3253
|
-
var
|
|
3493
|
+
var import_core17 = require("@luma.gl/core");
|
|
3494
|
+
var import_core18 = require("@luma.gl/core");
|
|
3495
|
+
var import_core19 = require("@luma.gl/core");
|
|
3254
3496
|
var import_shadertools5 = require("@luma.gl/shadertools");
|
|
3497
|
+
var import_types2 = require("@math.gl/types");
|
|
3255
3498
|
var LOG_DRAW_PRIORITY2 = 2;
|
|
3256
3499
|
var LOG_DRAW_TIMEOUT2 = 1e4;
|
|
3257
3500
|
var _Computation = class {
|
|
@@ -3262,13 +3505,16 @@ var _Computation = class {
|
|
|
3262
3505
|
userData = {};
|
|
3263
3506
|
/** Bindings (textures, samplers, uniform buffers) */
|
|
3264
3507
|
bindings = {};
|
|
3265
|
-
/** The underlying GPU
|
|
3508
|
+
/** The underlying GPU pipeline. */
|
|
3266
3509
|
pipeline;
|
|
3510
|
+
/** Assembled compute shader source */
|
|
3511
|
+
source;
|
|
3267
3512
|
/** the underlying compiled compute shader */
|
|
3513
|
+
// @ts-ignore Set in function called from constructor
|
|
3268
3514
|
shader;
|
|
3269
|
-
source;
|
|
3270
3515
|
/** ShaderInputs instance */
|
|
3271
3516
|
shaderInputs;
|
|
3517
|
+
// @ts-ignore Set in function called from constructor
|
|
3272
3518
|
_uniformStore;
|
|
3273
3519
|
_pipelineNeedsUpdate = "newly created";
|
|
3274
3520
|
_getModuleUniforms;
|
|
@@ -3281,17 +3527,18 @@ var _Computation = class {
|
|
|
3281
3527
|
}
|
|
3282
3528
|
this.props = { ..._Computation.defaultProps, ...props };
|
|
3283
3529
|
props = this.props;
|
|
3284
|
-
this.id = props.id ||
|
|
3530
|
+
this.id = props.id || uid("model");
|
|
3285
3531
|
this.device = device;
|
|
3286
3532
|
Object.assign(this.userData, props.userData);
|
|
3287
3533
|
const moduleMap = Object.fromEntries(((_a = this.props.modules) == null ? void 0 : _a.map((module2) => [module2.name, module2])) || []);
|
|
3288
|
-
this.
|
|
3534
|
+
this.shaderInputs = props.shaderInputs || new ShaderInputs(moduleMap);
|
|
3535
|
+
this.setShaderInputs(this.shaderInputs);
|
|
3289
3536
|
this.props.shaderLayout ||= (0, import_shadertools5.getShaderLayoutFromWGSL)(this.props.source);
|
|
3290
3537
|
const platformInfo = getPlatformInfo2(device);
|
|
3291
3538
|
const modules = (((_b = this.props.modules) == null ? void 0 : _b.length) > 0 ? this.props.modules : (_c = this.shaderInputs) == null ? void 0 : _c.getModules()) || [];
|
|
3292
3539
|
this.pipelineFactory = props.pipelineFactory || PipelineFactory.getDefaultPipelineFactory(this.device);
|
|
3293
3540
|
this.shaderFactory = props.shaderFactory || ShaderFactory.getDefaultShaderFactory(this.device);
|
|
3294
|
-
const { source, getUniforms } = this.props.shaderAssembler.
|
|
3541
|
+
const { source, getUniforms } = this.props.shaderAssembler.assembleWGSLShader({
|
|
3295
3542
|
platformInfo,
|
|
3296
3543
|
...this.props,
|
|
3297
3544
|
modules
|
|
@@ -3344,7 +3591,7 @@ var _Computation = class {
|
|
|
3344
3591
|
}
|
|
3345
3592
|
setShaderInputs(shaderInputs) {
|
|
3346
3593
|
this.shaderInputs = shaderInputs;
|
|
3347
|
-
this._uniformStore = new
|
|
3594
|
+
this._uniformStore = new import_core17.UniformStore(this.shaderInputs.modules);
|
|
3348
3595
|
for (const moduleName of Object.keys(this.shaderInputs.modules)) {
|
|
3349
3596
|
const uniformBuffer = this._uniformStore.getManagedUniformBuffer(this.device, moduleName);
|
|
3350
3597
|
this.bindings[`${moduleName}Uniforms`] = uniformBuffer;
|
|
@@ -3357,7 +3604,7 @@ var _Computation = class {
|
|
|
3357
3604
|
const uniforms = this._getModuleUniforms(props);
|
|
3358
3605
|
const keys = Object.keys(uniforms).filter((k) => {
|
|
3359
3606
|
const uniform = uniforms[k];
|
|
3360
|
-
return !(0,
|
|
3607
|
+
return !(0, import_types2.isNumericArray)(uniform) && typeof uniform !== "number" && typeof uniform !== "boolean";
|
|
3361
3608
|
});
|
|
3362
3609
|
const bindings = {};
|
|
3363
3610
|
for (const k of keys) {
|
|
@@ -3381,7 +3628,7 @@ var _Computation = class {
|
|
|
3381
3628
|
if (this._pipelineNeedsUpdate) {
|
|
3382
3629
|
let prevShader = null;
|
|
3383
3630
|
if (this.pipeline) {
|
|
3384
|
-
|
|
3631
|
+
import_core18.log.log(1, `Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)();
|
|
3385
3632
|
prevShader = this.shader;
|
|
3386
3633
|
}
|
|
3387
3634
|
this._pipelineNeedsUpdate = false;
|
|
@@ -3405,33 +3652,33 @@ var _Computation = class {
|
|
|
3405
3652
|
_lastLogTime = 0;
|
|
3406
3653
|
_logOpen = false;
|
|
3407
3654
|
_logDrawCallStart() {
|
|
3408
|
-
const logDrawTimeout =
|
|
3409
|
-
if (
|
|
3655
|
+
const logDrawTimeout = import_core18.log.level > 3 ? 0 : LOG_DRAW_TIMEOUT2;
|
|
3656
|
+
if (import_core18.log.level < 2 || Date.now() - this._lastLogTime < logDrawTimeout) {
|
|
3410
3657
|
return;
|
|
3411
3658
|
}
|
|
3412
3659
|
this._lastLogTime = Date.now();
|
|
3413
3660
|
this._logOpen = true;
|
|
3414
|
-
|
|
3661
|
+
import_core18.log.group(LOG_DRAW_PRIORITY2, `>>> DRAWING MODEL ${this.id}`, { collapsed: import_core18.log.level <= 2 })();
|
|
3415
3662
|
}
|
|
3416
3663
|
_logDrawCallEnd() {
|
|
3417
3664
|
if (this._logOpen) {
|
|
3418
3665
|
const uniformTable = this.shaderInputs.getDebugTable();
|
|
3419
|
-
|
|
3420
|
-
|
|
3666
|
+
import_core18.log.table(LOG_DRAW_PRIORITY2, uniformTable)();
|
|
3667
|
+
import_core18.log.groupEnd(LOG_DRAW_PRIORITY2)();
|
|
3421
3668
|
this._logOpen = false;
|
|
3422
3669
|
}
|
|
3423
3670
|
}
|
|
3424
3671
|
_drawCount = 0;
|
|
3425
3672
|
// TODO - fix typing of luma data types
|
|
3426
3673
|
_getBufferOrConstantValues(attribute, dataType) {
|
|
3427
|
-
const TypedArrayConstructor = (0,
|
|
3428
|
-
const typedArray = attribute instanceof
|
|
3674
|
+
const TypedArrayConstructor = (0, import_core19.getTypedArrayFromDataType)(dataType);
|
|
3675
|
+
const typedArray = attribute instanceof import_core17.Buffer ? new TypedArrayConstructor(attribute.debugData) : attribute;
|
|
3429
3676
|
return typedArray.toString();
|
|
3430
3677
|
}
|
|
3431
3678
|
};
|
|
3432
3679
|
var Computation = _Computation;
|
|
3433
3680
|
__publicField(Computation, "defaultProps", {
|
|
3434
|
-
...
|
|
3681
|
+
...import_core17.ComputePipeline.defaultProps,
|
|
3435
3682
|
id: "unnamed",
|
|
3436
3683
|
handle: void 0,
|
|
3437
3684
|
userData: {},
|