@luma.gl/engine 9.0.0-beta.4 → 9.0.0-beta.5
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.js +54 -54
- package/dist/animation/timeline.js +95 -100
- package/dist/animation-loop/animation-loop-template.js +17 -5
- package/dist/animation-loop/animation-loop.js +425 -356
- package/dist/animation-loop/animation-props.js +0 -1
- package/dist/animation-loop/make-animation-loop.js +27 -25
- package/dist/debug/copy-texture-to-image.js +39 -43
- package/dist/debug/debug-framebuffer.js +43 -39
- package/dist/debug/debug-shader-layout.js +24 -25
- package/dist/debug/pixel-data-utils.js +33 -36
- package/dist/dist.dev.js +3784 -8643
- package/dist/geometries/cone-geometry.js +12 -18
- package/dist/geometries/cube-geometry.js +189 -62
- package/dist/geometries/cylinder-geometry.js +10 -15
- package/dist/geometries/ico-sphere-geometry.js +142 -161
- package/dist/geometries/plane-geometry.js +94 -112
- package/dist/geometries/sphere-geometry.js +77 -96
- package/dist/geometries/truncated-cone-geometry.js +100 -118
- package/dist/geometry/geometry-table.js +0 -1
- package/dist/geometry/geometry-utils.js +35 -32
- package/dist/geometry/geometry.js +77 -71
- package/dist/geometry/gpu-geometry.js +80 -99
- package/dist/geometry/gpu-table.js +41 -1
- package/dist/index.cjs +80 -127
- package/dist/index.cjs.map +7 -0
- package/dist/index.js +27 -24
- package/dist/lib/clip-space.js +25 -30
- package/dist/lib/pipeline-factory.d.ts +1 -5
- package/dist/lib/pipeline-factory.d.ts.map +1 -1
- package/dist/lib/pipeline-factory.js +61 -68
- package/dist/model/model.d.ts +2 -2
- package/dist/model/model.d.ts.map +1 -1
- package/dist/model/model.js +539 -413
- package/dist/scenegraph/group-node.js +69 -84
- package/dist/scenegraph/model-node.js +32 -25
- package/dist/scenegraph/scenegraph-node.js +136 -124
- package/dist/shader-inputs.js +96 -58
- package/dist/transform/buffer-transform.js +65 -58
- package/dist/transform/texture-transform.d.ts.map +1 -1
- package/dist/transform/texture-transform.js +108 -115
- package/dist.min.js +2 -272
- package/package.json +10 -9
- package/src/lib/pipeline-factory.ts +8 -21
- package/src/model/model.ts +5 -5
- package/src/transform/buffer-transform.ts +3 -3
- package/src/transform/texture-transform.ts +0 -2
- package/dist/animation/key-frames.js.map +0 -1
- package/dist/animation/timeline.js.map +0 -1
- package/dist/animation-loop/animation-loop-template.js.map +0 -1
- package/dist/animation-loop/animation-loop.js.map +0 -1
- package/dist/animation-loop/animation-props.js.map +0 -1
- package/dist/animation-loop/make-animation-loop.js.map +0 -1
- package/dist/debug/copy-texture-to-image.js.map +0 -1
- package/dist/debug/debug-framebuffer.js.map +0 -1
- package/dist/debug/debug-shader-layout.js.map +0 -1
- package/dist/debug/pixel-data-utils.js.map +0 -1
- package/dist/geometries/cone-geometry.js.map +0 -1
- package/dist/geometries/cube-geometry.js.map +0 -1
- package/dist/geometries/cylinder-geometry.js.map +0 -1
- package/dist/geometries/ico-sphere-geometry.js.map +0 -1
- package/dist/geometries/plane-geometry.js.map +0 -1
- package/dist/geometries/sphere-geometry.js.map +0 -1
- package/dist/geometries/truncated-cone-geometry.js.map +0 -1
- package/dist/geometry/geometry-table.js.map +0 -1
- package/dist/geometry/geometry-utils.js.map +0 -1
- package/dist/geometry/geometry.js.map +0 -1
- package/dist/geometry/gpu-geometry.js.map +0 -1
- package/dist/geometry/gpu-table.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/clip-space.js.map +0 -1
- package/dist/lib/pipeline-factory.js.map +0 -1
- package/dist/model/model.js.map +0 -1
- package/dist/scenegraph/group-node.js.map +0 -1
- package/dist/scenegraph/model-node.js.map +0 -1
- package/dist/scenegraph/scenegraph-node.js.map +0 -1
- package/dist/shader-inputs.js.map +0 -1
- package/dist/transform/buffer-transform.js.map +0 -1
- package/dist/transform/texture-transform.js.map +0 -1
|
@@ -1,94 +1,79 @@
|
|
|
1
1
|
import { Matrix4, Vector3 } from '@math.gl/core';
|
|
2
2
|
import { log } from '@luma.gl/core';
|
|
3
|
-
import { ScenegraphNode } from
|
|
3
|
+
import { ScenegraphNode } from './scenegraph-node';
|
|
4
4
|
export class GroupNode extends ScenegraphNode {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
result[0][i] = Math.min(result[0][i], position[i]);
|
|
37
|
-
result[1][i] = Math.max(result[1][i], position[i]);
|
|
5
|
+
children;
|
|
6
|
+
constructor(props = {}) {
|
|
7
|
+
props = Array.isArray(props) ? { children: props } : props;
|
|
8
|
+
const { children = [] } = props;
|
|
9
|
+
log.assert(children.every((child) => child instanceof ScenegraphNode), 'every child must an instance of ScenegraphNode');
|
|
10
|
+
super(props);
|
|
11
|
+
this.children = children;
|
|
12
|
+
}
|
|
13
|
+
getBounds() {
|
|
14
|
+
const result = [[Infinity, Infinity, Infinity], [-Infinity, -Infinity, -Infinity]];
|
|
15
|
+
this.traverse((node, { worldMatrix }) => {
|
|
16
|
+
const bounds = node.getBounds();
|
|
17
|
+
if (!bounds) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const [min, max] = bounds;
|
|
21
|
+
const center = new Vector3(min).add(max).divide([2, 2, 2]);
|
|
22
|
+
worldMatrix.transformAsPoint(center, center);
|
|
23
|
+
const halfSize = new Vector3(max).subtract(min).divide([2, 2, 2]);
|
|
24
|
+
worldMatrix.transformAsVector(halfSize, halfSize);
|
|
25
|
+
for (let v = 0; v < 8; v++) {
|
|
26
|
+
// Test all 8 corners of the box
|
|
27
|
+
const position = new Vector3(v & 0b001 ? -1 : 1, v & 0b010 ? -1 : 1, v & 0b100 ? -1 : 1).multiply(halfSize).add(center);
|
|
28
|
+
for (let i = 0; i < 3; i++) {
|
|
29
|
+
result[0][i] = Math.min(result[0][i], position[i]);
|
|
30
|
+
result[1][i] = Math.max(result[1][i], position[i]);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
if (!Number.isFinite(result[0][0])) {
|
|
35
|
+
return null;
|
|
38
36
|
}
|
|
39
|
-
|
|
40
|
-
});
|
|
41
|
-
if (!Number.isFinite(result[0][0])) {
|
|
42
|
-
return null;
|
|
37
|
+
return result;
|
|
43
38
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
39
|
+
destroy() {
|
|
40
|
+
this.children.forEach((child) => child.destroy());
|
|
41
|
+
this.removeAll();
|
|
42
|
+
super.destroy();
|
|
43
|
+
}
|
|
44
|
+
// Unpacks arrays and nested arrays of children
|
|
45
|
+
add(...children) {
|
|
46
|
+
for (const child of children) {
|
|
47
|
+
if (Array.isArray(child)) {
|
|
48
|
+
this.add(...child);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
this.children.push(child);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return this;
|
|
54
55
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
remove(child) {
|
|
57
|
+
const children = this.children;
|
|
58
|
+
const indexOf = children.indexOf(child);
|
|
59
|
+
if (indexOf > -1) {
|
|
60
|
+
children.splice(indexOf, 1);
|
|
61
|
+
}
|
|
62
|
+
return this;
|
|
61
63
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const children = this.children;
|
|
66
|
-
const indexOf = children.indexOf(child);
|
|
67
|
-
if (indexOf > -1) {
|
|
68
|
-
children.splice(indexOf, 1);
|
|
64
|
+
removeAll() {
|
|
65
|
+
this.children = [];
|
|
66
|
+
return this;
|
|
69
67
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const modelMatrix = new Matrix4(worldMatrix).multiplyRight(this.matrix);
|
|
81
|
-
for (const child of this.children) {
|
|
82
|
-
if (child instanceof GroupNode) {
|
|
83
|
-
child.traverse(visitor, {
|
|
84
|
-
worldMatrix: modelMatrix
|
|
85
|
-
});
|
|
86
|
-
} else {
|
|
87
|
-
visitor(child, {
|
|
88
|
-
worldMatrix: modelMatrix
|
|
89
|
-
});
|
|
90
|
-
}
|
|
68
|
+
traverse(visitor, { worldMatrix = new Matrix4() } = {}) {
|
|
69
|
+
const modelMatrix = new Matrix4(worldMatrix).multiplyRight(this.matrix);
|
|
70
|
+
for (const child of this.children) {
|
|
71
|
+
if (child instanceof GroupNode) {
|
|
72
|
+
child.traverse(visitor, { worldMatrix: modelMatrix });
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
visitor(child, { worldMatrix: modelMatrix });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
91
78
|
}
|
|
92
|
-
}
|
|
93
79
|
}
|
|
94
|
-
//# sourceMappingURL=group-node.js.map
|
|
@@ -1,28 +1,35 @@
|
|
|
1
|
-
import { ScenegraphNode } from
|
|
1
|
+
import { ScenegraphNode } from './scenegraph-node';
|
|
2
2
|
export class ModelNode extends ScenegraphNode {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
this
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
3
|
+
model;
|
|
4
|
+
bounds = null;
|
|
5
|
+
managedResources;
|
|
6
|
+
// TODO - is this used? override callbacks to make sure we call them with this
|
|
7
|
+
// onBeforeRender = null;
|
|
8
|
+
// onAfterRender = null;
|
|
9
|
+
// AfterRender = null;
|
|
10
|
+
constructor(props) {
|
|
11
|
+
super(props);
|
|
12
|
+
// Create new Model or used supplied Model
|
|
13
|
+
this.model = props.model;
|
|
14
|
+
this.managedResources = props.managedResources || [];
|
|
15
|
+
this.bounds = props.bounds || null;
|
|
16
|
+
this.setProps(props);
|
|
17
|
+
}
|
|
18
|
+
getBounds() {
|
|
19
|
+
return this.bounds;
|
|
20
|
+
}
|
|
21
|
+
destroy() {
|
|
22
|
+
if (this.model) {
|
|
23
|
+
this.model.destroy();
|
|
24
|
+
// @ts-expect-error
|
|
25
|
+
this.model = null;
|
|
26
|
+
}
|
|
27
|
+
this.managedResources.forEach((resource) => resource.destroy());
|
|
28
|
+
this.managedResources = [];
|
|
29
|
+
}
|
|
30
|
+
// Expose model methods
|
|
31
|
+
draw(renderPass) {
|
|
32
|
+
// Return value indicates if something was actually drawn
|
|
33
|
+
return this.model.draw(renderPass);
|
|
20
34
|
}
|
|
21
|
-
this.managedResources.forEach(resource => resource.destroy());
|
|
22
|
-
this.managedResources = [];
|
|
23
|
-
}
|
|
24
|
-
draw(renderPass) {
|
|
25
|
-
return this.model.draw(renderPass);
|
|
26
|
-
}
|
|
27
35
|
}
|
|
28
|
-
//# sourceMappingURL=model-node.js.map
|
|
@@ -1,141 +1,153 @@
|
|
|
1
1
|
import { assert, uid } from '@luma.gl/core';
|
|
2
2
|
import { Vector3, Matrix4 } from '@math.gl/core';
|
|
3
3
|
export class ScenegraphNode {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} = props;
|
|
17
|
-
this.id = id || uid(this.constructor.name);
|
|
18
|
-
this._setScenegraphNodeProps(props);
|
|
19
|
-
}
|
|
20
|
-
getBounds() {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
destroy() {}
|
|
24
|
-
delete() {
|
|
25
|
-
this.destroy();
|
|
26
|
-
}
|
|
27
|
-
setProps(props) {
|
|
28
|
-
this._setScenegraphNodeProps(props);
|
|
29
|
-
return this;
|
|
30
|
-
}
|
|
31
|
-
toString() {
|
|
32
|
-
return `{type: ScenegraphNode, id: ${this.id})}`;
|
|
33
|
-
}
|
|
34
|
-
setPosition(position) {
|
|
35
|
-
assert(position.length === 3, 'setPosition requires vector argument');
|
|
36
|
-
this.position = position;
|
|
37
|
-
return this;
|
|
38
|
-
}
|
|
39
|
-
setRotation(rotation) {
|
|
40
|
-
assert(rotation.length === 3, 'setRotation requires vector argument');
|
|
41
|
-
this.rotation = rotation;
|
|
42
|
-
return this;
|
|
43
|
-
}
|
|
44
|
-
setScale(scale) {
|
|
45
|
-
assert(scale.length === 3, 'setScale requires vector argument');
|
|
46
|
-
this.scale = scale;
|
|
47
|
-
return this;
|
|
48
|
-
}
|
|
49
|
-
setMatrix(matrix) {
|
|
50
|
-
let copyMatrix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
51
|
-
if (copyMatrix) {
|
|
52
|
-
this.matrix.copy(matrix);
|
|
53
|
-
} else {
|
|
54
|
-
this.matrix = matrix;
|
|
4
|
+
id;
|
|
5
|
+
matrix = new Matrix4();
|
|
6
|
+
display = true;
|
|
7
|
+
position = new Vector3();
|
|
8
|
+
rotation = new Vector3();
|
|
9
|
+
scale = new Vector3(1, 1, 1);
|
|
10
|
+
userData = {};
|
|
11
|
+
props = {};
|
|
12
|
+
constructor(props = {}) {
|
|
13
|
+
const { id } = props;
|
|
14
|
+
this.id = id || uid(this.constructor.name);
|
|
15
|
+
this._setScenegraphNodeProps(props);
|
|
55
16
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const {
|
|
59
|
-
position,
|
|
60
|
-
rotation,
|
|
61
|
-
scale,
|
|
62
|
-
update = true
|
|
63
|
-
} = components;
|
|
64
|
-
if (position) {
|
|
65
|
-
this.setPosition(position);
|
|
17
|
+
getBounds() {
|
|
18
|
+
return null;
|
|
66
19
|
}
|
|
67
|
-
|
|
68
|
-
|
|
20
|
+
destroy() { }
|
|
21
|
+
/** @deprecated use .destroy() */
|
|
22
|
+
delete() {
|
|
23
|
+
this.destroy();
|
|
69
24
|
}
|
|
70
|
-
|
|
71
|
-
|
|
25
|
+
setProps(props) {
|
|
26
|
+
this._setScenegraphNodeProps(props);
|
|
27
|
+
return this;
|
|
72
28
|
}
|
|
73
|
-
|
|
74
|
-
|
|
29
|
+
toString() {
|
|
30
|
+
return `{type: ScenegraphNode, id: ${this.id})}`;
|
|
75
31
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const rot = this.rotation;
|
|
81
|
-
const scale = this.scale;
|
|
82
|
-
this.matrix.identity();
|
|
83
|
-
this.matrix.translate(pos);
|
|
84
|
-
this.matrix.rotateXYZ(rot);
|
|
85
|
-
this.matrix.scale(scale);
|
|
86
|
-
return this;
|
|
87
|
-
}
|
|
88
|
-
update() {
|
|
89
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
90
|
-
const {
|
|
91
|
-
position,
|
|
92
|
-
rotation,
|
|
93
|
-
scale
|
|
94
|
-
} = options;
|
|
95
|
-
if (position) {
|
|
96
|
-
this.setPosition(position);
|
|
32
|
+
setPosition(position) {
|
|
33
|
+
assert(position.length === 3, 'setPosition requires vector argument');
|
|
34
|
+
this.position = position;
|
|
35
|
+
return this;
|
|
97
36
|
}
|
|
98
|
-
|
|
99
|
-
|
|
37
|
+
setRotation(rotation) {
|
|
38
|
+
assert(rotation.length === 3, 'setRotation requires vector argument');
|
|
39
|
+
this.rotation = rotation;
|
|
40
|
+
return this;
|
|
100
41
|
}
|
|
101
|
-
|
|
102
|
-
|
|
42
|
+
setScale(scale) {
|
|
43
|
+
assert(scale.length === 3, 'setScale requires vector argument');
|
|
44
|
+
this.scale = scale;
|
|
45
|
+
return this;
|
|
103
46
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const worldInverse = worldMatrix.invert();
|
|
112
|
-
const worldInverseTranspose = worldInverse.transpose();
|
|
113
|
-
return {
|
|
114
|
-
viewMatrix,
|
|
115
|
-
modelMatrix,
|
|
116
|
-
objectMatrix: modelMatrix,
|
|
117
|
-
worldMatrix,
|
|
118
|
-
worldInverseMatrix: worldInverse,
|
|
119
|
-
worldInverseTransposeMatrix: worldInverseTranspose
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
_setScenegraphNodeProps(props) {
|
|
123
|
-
if ('display' in props) {
|
|
124
|
-
this.display = props.display;
|
|
47
|
+
setMatrix(matrix, copyMatrix = true) {
|
|
48
|
+
if (copyMatrix) {
|
|
49
|
+
this.matrix.copy(matrix);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
this.matrix = matrix;
|
|
53
|
+
}
|
|
125
54
|
}
|
|
126
|
-
|
|
127
|
-
|
|
55
|
+
setMatrixComponents(components) {
|
|
56
|
+
const { position, rotation, scale, update = true } = components;
|
|
57
|
+
if (position) {
|
|
58
|
+
this.setPosition(position);
|
|
59
|
+
}
|
|
60
|
+
if (rotation) {
|
|
61
|
+
this.setRotation(rotation);
|
|
62
|
+
}
|
|
63
|
+
if (scale) {
|
|
64
|
+
this.setScale(scale);
|
|
65
|
+
}
|
|
66
|
+
if (update) {
|
|
67
|
+
this.updateMatrix();
|
|
68
|
+
}
|
|
69
|
+
return this;
|
|
128
70
|
}
|
|
129
|
-
|
|
130
|
-
|
|
71
|
+
updateMatrix() {
|
|
72
|
+
const pos = this.position;
|
|
73
|
+
const rot = this.rotation;
|
|
74
|
+
const scale = this.scale;
|
|
75
|
+
this.matrix.identity();
|
|
76
|
+
this.matrix.translate(pos);
|
|
77
|
+
this.matrix.rotateXYZ(rot);
|
|
78
|
+
this.matrix.scale(scale);
|
|
79
|
+
return this;
|
|
131
80
|
}
|
|
132
|
-
|
|
133
|
-
|
|
81
|
+
update(options = {}) {
|
|
82
|
+
const { position, rotation, scale } = options;
|
|
83
|
+
if (position) {
|
|
84
|
+
this.setPosition(position);
|
|
85
|
+
}
|
|
86
|
+
if (rotation) {
|
|
87
|
+
this.setRotation(rotation);
|
|
88
|
+
}
|
|
89
|
+
if (scale) {
|
|
90
|
+
this.setScale(scale);
|
|
91
|
+
}
|
|
92
|
+
this.updateMatrix();
|
|
93
|
+
return this;
|
|
134
94
|
}
|
|
135
|
-
|
|
136
|
-
|
|
95
|
+
getCoordinateUniforms(viewMatrix, modelMatrix) {
|
|
96
|
+
// TODO - solve multiple class problem
|
|
97
|
+
// assert(viewMatrix instanceof Matrix4);
|
|
98
|
+
assert(viewMatrix);
|
|
99
|
+
modelMatrix = modelMatrix || this.matrix;
|
|
100
|
+
const worldMatrix = new Matrix4(viewMatrix).multiplyRight(modelMatrix);
|
|
101
|
+
const worldInverse = worldMatrix.invert();
|
|
102
|
+
const worldInverseTranspose = worldInverse.transpose();
|
|
103
|
+
return {
|
|
104
|
+
viewMatrix,
|
|
105
|
+
modelMatrix,
|
|
106
|
+
objectMatrix: modelMatrix,
|
|
107
|
+
worldMatrix,
|
|
108
|
+
worldInverseMatrix: worldInverse,
|
|
109
|
+
worldInverseTransposeMatrix: worldInverseTranspose
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
// TODO - copied code, not yet vetted
|
|
113
|
+
/*
|
|
114
|
+
transform() {
|
|
115
|
+
if (!this.parent) {
|
|
116
|
+
this.endPosition.set(this.position);
|
|
117
|
+
this.endRotation.set(this.rotation);
|
|
118
|
+
this.endScale.set(this.scale);
|
|
119
|
+
} else {
|
|
120
|
+
const parent = this.parent;
|
|
121
|
+
this.endPosition.set(this.position.add(parent.endPosition));
|
|
122
|
+
this.endRotation.set(this.rotation.add(parent.endRotation));
|
|
123
|
+
this.endScale.set(this.scale.add(parent.endScale));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const ch = this.children;
|
|
127
|
+
for (let i = 0; i < ch.length; ++i) {
|
|
128
|
+
ch[i].transform();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
*/
|
|
134
|
+
_setScenegraphNodeProps(props) {
|
|
135
|
+
if ('display' in props) {
|
|
136
|
+
this.display = props.display;
|
|
137
|
+
}
|
|
138
|
+
if ('position' in props) {
|
|
139
|
+
this.setPosition(props.position);
|
|
140
|
+
}
|
|
141
|
+
if ('rotation' in props) {
|
|
142
|
+
this.setRotation(props.rotation);
|
|
143
|
+
}
|
|
144
|
+
if ('scale' in props) {
|
|
145
|
+
this.setScale(props.scale);
|
|
146
|
+
}
|
|
147
|
+
// Matrix overwrites other props
|
|
148
|
+
if ('matrix' in props) {
|
|
149
|
+
this.setMatrix(props.matrix);
|
|
150
|
+
}
|
|
151
|
+
Object.assign(this.props, props);
|
|
137
152
|
}
|
|
138
|
-
Object.assign(this.props, props);
|
|
139
|
-
}
|
|
140
153
|
}
|
|
141
|
-
//# sourceMappingURL=scenegraph-node.js.map
|
package/dist/shader-inputs.js
CHANGED
|
@@ -1,66 +1,104 @@
|
|
|
1
1
|
import { log } from '@luma.gl/core';
|
|
2
|
+
// import type {ShaderUniformType, UniformValue, UniformFormat, UniformInfoDevice, Texture, Sampler} from '@luma.gl/core';
|
|
2
3
|
import { _resolveModules } from '@luma.gl/shadertools';
|
|
4
|
+
/**
|
|
5
|
+
* ShaderInputs holds uniform and binding values for one or more shader modules,
|
|
6
|
+
* - It can generate binary data for any uniform buffer
|
|
7
|
+
* - It can manage a uniform buffer for each block
|
|
8
|
+
* - It can update managed uniform buffers with a single call
|
|
9
|
+
* - It performs some book keeping on what has changed to minimize unnecessary writes to uniform buffers.
|
|
10
|
+
*/
|
|
3
11
|
export class ShaderInputs {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
/**
|
|
13
|
+
* The map of modules
|
|
14
|
+
* @todo should should this include the resolved dependencies?
|
|
15
|
+
*/
|
|
16
|
+
modules;
|
|
17
|
+
/** Stores the uniform values for each module */
|
|
18
|
+
moduleUniforms;
|
|
19
|
+
/** Stores the uniform bindings for each module */
|
|
20
|
+
moduleBindings;
|
|
21
|
+
/** Tracks if uniforms have changed */
|
|
22
|
+
moduleUniformsChanged;
|
|
23
|
+
/**
|
|
24
|
+
* Create a new UniformStore instance
|
|
25
|
+
* @param modules
|
|
26
|
+
*/
|
|
27
|
+
constructor(modules) {
|
|
28
|
+
// TODO - get all dependencies from modules
|
|
29
|
+
const allModules = _resolveModules(Object.values(modules));
|
|
30
|
+
log.log(1, 'Creating ShaderInputs with modules', allModules.map(m => m.name))();
|
|
31
|
+
// Store the module definitions and create storage for uniform values and binding values, per module
|
|
32
|
+
this.modules = modules;
|
|
33
|
+
this.moduleUniforms = {};
|
|
34
|
+
this.moduleBindings = {};
|
|
35
|
+
// Initialize the modules
|
|
36
|
+
for (const [name, module] of Object.entries(modules)) {
|
|
37
|
+
const moduleName = name;
|
|
38
|
+
// Get default uniforms from module
|
|
39
|
+
this.moduleUniforms[moduleName] = module.defaultUniforms || {};
|
|
40
|
+
this.moduleBindings[moduleName] = {};
|
|
41
|
+
}
|
|
18
42
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
43
|
+
/** Destroy */
|
|
44
|
+
destroy() { }
|
|
45
|
+
/**
|
|
46
|
+
* Set module props
|
|
47
|
+
*/
|
|
48
|
+
setProps(props) {
|
|
49
|
+
for (const name of Object.keys(props)) {
|
|
50
|
+
const moduleName = name;
|
|
51
|
+
const moduleProps = props[moduleName];
|
|
52
|
+
const module = this.modules[moduleName];
|
|
53
|
+
if (!module) {
|
|
54
|
+
// Ignore props for unregistered modules
|
|
55
|
+
log.warn(`Module ${name} not found`)();
|
|
56
|
+
continue; // eslint-disable-line no-continue
|
|
57
|
+
}
|
|
58
|
+
const oldUniforms = this.moduleUniforms[moduleName];
|
|
59
|
+
const uniforms = module.getUniforms?.(moduleProps, this.moduleUniforms[moduleName]) || moduleProps;
|
|
60
|
+
// console.error(uniforms)
|
|
61
|
+
this.moduleUniforms[moduleName] = { ...oldUniforms, ...uniforms };
|
|
62
|
+
// this.moduleUniformsChanged ||= moduleName;
|
|
63
|
+
// console.log(`setProps(${String(moduleName)}`, moduleName, this.moduleUniforms[moduleName])
|
|
64
|
+
// TODO - Get Module bindings
|
|
65
|
+
// const bindings = module.getBindings?.(moduleProps);
|
|
66
|
+
// this.moduleUniforms[moduleName] = bindings;
|
|
67
|
+
}
|
|
37
68
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
Object.assign(bindings, moduleBindings);
|
|
69
|
+
/** Merges all bindings for the shader (from the various modules) */
|
|
70
|
+
// getUniformBlocks(): Record<string, Texture | Sampler> {
|
|
71
|
+
// return this.moduleUniforms;
|
|
72
|
+
// }
|
|
73
|
+
/**
|
|
74
|
+
* Return the map of modules
|
|
75
|
+
* @todo should should this include the resolved dependencies?
|
|
76
|
+
*/
|
|
77
|
+
getModules() {
|
|
78
|
+
return Object.values(this.modules);
|
|
49
79
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
for (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
80
|
+
/** Get all uniform values for all modules */
|
|
81
|
+
getUniformValues() {
|
|
82
|
+
return this.moduleUniforms;
|
|
83
|
+
}
|
|
84
|
+
/** Merges all bindings for the shader (from the various modules) */
|
|
85
|
+
getBindings() {
|
|
86
|
+
const bindings = {};
|
|
87
|
+
for (const moduleBindings of Object.values(this.moduleBindings)) {
|
|
88
|
+
Object.assign(bindings, moduleBindings);
|
|
89
|
+
}
|
|
90
|
+
return bindings;
|
|
91
|
+
}
|
|
92
|
+
getDebugTable() {
|
|
93
|
+
const table = {};
|
|
94
|
+
for (const [moduleName, module] of Object.entries(this.moduleUniforms)) {
|
|
95
|
+
for (const [key, value] of Object.entries(module)) {
|
|
96
|
+
table[`${moduleName}.${key}`] = {
|
|
97
|
+
type: this.modules[moduleName].uniformTypes?.[key],
|
|
98
|
+
value: String(value)
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return table;
|
|
62
103
|
}
|
|
63
|
-
return table;
|
|
64
|
-
}
|
|
65
104
|
}
|
|
66
|
-
//# sourceMappingURL=shader-inputs.js.map
|