@luma.gl/engine 9.0.0-alpha.23 → 9.0.0-alpha.25

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.
Files changed (76) hide show
  1. package/dist/animation/key-frames.d.ts +1 -1
  2. package/dist/animation/key-frames.d.ts.map +1 -1
  3. package/dist/animation/timeline.d.ts +4 -4
  4. package/dist/animation/timeline.d.ts.map +1 -1
  5. package/dist/animation/timeline.js.map +1 -1
  6. package/dist/animation-loop/animation-loop.d.ts +2 -4
  7. package/dist/animation-loop/animation-loop.d.ts.map +1 -1
  8. package/dist/animation-loop/animation-loop.js +7 -7
  9. package/dist/animation-loop/animation-loop.js.map +1 -1
  10. package/dist/animation-loop/animation-props.d.ts +1 -3
  11. package/dist/animation-loop/animation-props.d.ts.map +1 -1
  12. package/dist/animation-loop/make-animation-loop.d.ts +1 -1
  13. package/dist/animation-loop/make-animation-loop.d.ts.map +1 -1
  14. package/dist/animation-loop/make-animation-loop.js.map +1 -1
  15. package/dist/dist.dev.js +1539 -105
  16. package/dist/geometries/cone-geometry.d.ts +1 -1
  17. package/dist/geometries/cone-geometry.d.ts.map +1 -1
  18. package/dist/geometries/cube-geometry.d.ts +1 -1
  19. package/dist/geometries/cube-geometry.d.ts.map +1 -1
  20. package/dist/geometries/cylinder-geometry.d.ts +1 -1
  21. package/dist/geometries/cylinder-geometry.d.ts.map +1 -1
  22. package/dist/geometries/ico-sphere-geometry.d.ts +1 -1
  23. package/dist/geometries/ico-sphere-geometry.d.ts.map +1 -1
  24. package/dist/geometries/ico-sphere-geometry.js.map +1 -1
  25. package/dist/geometries/plane-geometry.d.ts +1 -1
  26. package/dist/geometries/plane-geometry.d.ts.map +1 -1
  27. package/dist/geometries/plane-geometry.js.map +1 -1
  28. package/dist/geometries/sphere-geometry.d.ts +1 -1
  29. package/dist/geometries/sphere-geometry.d.ts.map +1 -1
  30. package/dist/geometries/truncated-cone-geometry.d.ts +1 -1
  31. package/dist/geometries/truncated-cone-geometry.d.ts.map +1 -1
  32. package/dist/geometry/geometry-table.d.ts +1 -1
  33. package/dist/geometry/geometry-table.d.ts.map +1 -1
  34. package/dist/geometry/geometry.d.ts +5 -5
  35. package/dist/geometry/geometry.d.ts.map +1 -1
  36. package/dist/geometry/geometry.js +1 -1
  37. package/dist/geometry/geometry.js.map +1 -1
  38. package/dist/index.cjs +305 -47
  39. package/dist/index.d.ts +3 -0
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +3 -0
  42. package/dist/index.js.map +1 -1
  43. package/dist/lib/clip-space.js +1 -1
  44. package/dist/lib/clip-space.js.map +1 -1
  45. package/dist/lib/pipeline-factory.d.ts +3 -3
  46. package/dist/lib/pipeline-factory.d.ts.map +1 -1
  47. package/dist/lib/pipeline-factory.js.map +1 -1
  48. package/dist/model/model-utils.js.map +1 -1
  49. package/dist/model/model.d.ts +1 -1
  50. package/dist/model/model.d.ts.map +1 -1
  51. package/dist/model/model.js.map +1 -1
  52. package/dist/scenegraph/group-node.d.ts +21 -0
  53. package/dist/scenegraph/group-node.d.ts.map +1 -0
  54. package/dist/scenegraph/group-node.js +95 -0
  55. package/dist/scenegraph/group-node.js.map +1 -0
  56. package/dist/scenegraph/model-node.d.ts +18 -0
  57. package/dist/scenegraph/model-node.d.ts.map +1 -0
  58. package/dist/scenegraph/model-node.js +29 -0
  59. package/dist/scenegraph/model-node.js.map +1 -0
  60. package/dist/scenegraph/scenegraph-node.d.ts +56 -0
  61. package/dist/scenegraph/scenegraph-node.d.ts.map +1 -0
  62. package/dist/scenegraph/scenegraph-node.js +142 -0
  63. package/dist/scenegraph/scenegraph-node.js.map +1 -0
  64. package/dist/transform/transform.d.ts +5 -5
  65. package/dist/transform/transform.d.ts.map +1 -1
  66. package/dist/transform/transform.js +1 -1
  67. package/dist/transform/transform.js.map +1 -1
  68. package/dist.min.js +77 -76
  69. package/package.json +6 -6
  70. package/src/geometry/geometry.ts +1 -1
  71. package/src/index.ts +5 -0
  72. package/src/lib/clip-space.ts +1 -1
  73. package/src/scenegraph/group-node.ts +103 -0
  74. package/src/scenegraph/model-node.ts +50 -0
  75. package/src/scenegraph/scenegraph-node.ts +204 -0
  76. package/src/transform/transform.ts +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luma.gl/engine",
3
- "version": "9.0.0-alpha.23",
3
+ "version": "9.0.0-alpha.25",
4
4
  "description": "WebGL2 Components for High Performance Rendering and Computation",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -40,13 +40,13 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "@babel/runtime": "^7.0.0",
43
- "@luma.gl/api": "9.0.0-alpha.23",
44
- "@luma.gl/constants": "9.0.0-alpha.23",
45
- "@luma.gl/shadertools": "9.0.0-alpha.23",
46
- "@luma.gl/webgl": "9.0.0-alpha.23",
43
+ "@luma.gl/api": "9.0.0-alpha.25",
44
+ "@luma.gl/constants": "9.0.0-alpha.25",
45
+ "@luma.gl/shadertools": "9.0.0-alpha.25",
46
+ "@luma.gl/webgl": "9.0.0-alpha.25",
47
47
  "@math.gl/core": "4.0.0-alpha.4",
48
48
  "@probe.gl/log": "^4.0.2",
49
49
  "@probe.gl/stats": "^4.0.2"
50
50
  },
51
- "gitHead": "5e4a30497333bea4be8f2b3f3db33c0b67931b9c"
51
+ "gitHead": "a91e00399e59c1b5310bdfd842648238c5abf908"
52
52
  }
@@ -1,7 +1,7 @@
1
1
  // luma.gl, MIT license
2
2
  import type {PrimitiveTopology, TypedArray} from '@luma.gl/api';
3
3
  import {uid, assert} from '@luma.gl/api';
4
- import GL from '@luma.gl/constants';
4
+ import {GL} from '@luma.gl/constants';
5
5
 
6
6
  /**
7
7
  * Rendering primitives - "topology" specifies how to extract primitives from vertices.
package/src/index.ts CHANGED
@@ -23,6 +23,11 @@ export {PipelineFactory} from './lib/pipeline-factory';
23
23
  // Utils
24
24
  export {ClipSpace} from './lib/clip-space';
25
25
 
26
+ // Scenegraph Core nodes
27
+ export {ScenegraphNode} from './scenegraph/scenegraph-node';
28
+ export {GroupNode} from './scenegraph/group-node';
29
+ export {ModelNode} from './scenegraph/model-node';
30
+
26
31
  // Geometries
27
32
  export {Geometry} from './geometry/geometry';
28
33
 
@@ -1,6 +1,6 @@
1
1
 
2
2
  // ClipSpace
3
- import GL from '@luma.gl/constants';
3
+ import {GL} from '@luma.gl/constants';
4
4
  import {Device, glsl} from '@luma.gl/api';
5
5
  import {WebGLDevice} from '@luma.gl/webgl';
6
6
  import {Model, ModelProps} from '../model/model';
@@ -0,0 +1,103 @@
1
+ import {Matrix4, Vector3} from '@math.gl/core';
2
+ import {log} from '@luma.gl/api';
3
+ import {ScenegraphNode, ScenegraphNodeProps} from './scenegraph-node';
4
+
5
+ export type GroupNodeProps = ScenegraphNodeProps & {
6
+ children?: ScenegraphNode[];
7
+ }
8
+
9
+ export class GroupNode extends ScenegraphNode {
10
+ children: ScenegraphNode[];
11
+
12
+ constructor(children: ScenegraphNode[]);
13
+ constructor(props?: GroupNodeProps);
14
+
15
+ constructor(props: ScenegraphNode[] | GroupNodeProps = {}) {
16
+ props = Array.isArray(props) ? {children: props} : props;
17
+ const {children = []} = props;
18
+ log.assert(
19
+ children.every((child) => child instanceof ScenegraphNode),
20
+ 'every child must an instance of ScenegraphNode'
21
+ );
22
+ super(props);
23
+ this.children = children;
24
+ }
25
+
26
+ override getBounds(): [number[], number[]] | null {
27
+ const result: [number[], number[]] = [[Infinity, Infinity, Infinity], [-Infinity, -Infinity, -Infinity]];
28
+
29
+ this.traverse((node, {worldMatrix}) => {
30
+ const bounds = node.getBounds();
31
+ if (!bounds) {
32
+ return;
33
+ }
34
+ const [min, max] = bounds;
35
+ const center = new Vector3(min).add(max).divide([2, 2, 2]);
36
+ worldMatrix.transformAsPoint(center, center);
37
+ const halfSize = new Vector3(max).subtract(min).divide([2, 2, 2]);
38
+ worldMatrix.transformAsVector(halfSize, halfSize);
39
+
40
+ for (let v = 0; v < 8; v++) {
41
+ // Test all 8 corners of the box
42
+ const position = new Vector3(
43
+ v & 0b001 ? -1 : 1,
44
+ v & 0b010 ? -1 : 1,
45
+ v & 0b100 ? -1 : 1
46
+ ).multiply(halfSize).add(center);
47
+
48
+ for (let i = 0; i < 3; i++) {
49
+ result[0][i] = Math.min(result[0][i], position[i]);
50
+ result[1][i] = Math.max(result[1][i], position[i]);
51
+ }
52
+ }
53
+ });
54
+ if (!Number.isFinite(result[0][0])) {
55
+ return null;
56
+ }
57
+ return result;
58
+ }
59
+
60
+ override destroy(): void {
61
+ this.children.forEach((child) => child.destroy());
62
+ this.removeAll();
63
+ super.destroy();
64
+ }
65
+
66
+ // Unpacks arrays and nested arrays of children
67
+ add(...children: (ScenegraphNode | ScenegraphNode[])[]): this {
68
+ for (const child of children) {
69
+ if (Array.isArray(child)) {
70
+ this.add(...child);
71
+ } else {
72
+ this.children.push(child);
73
+ }
74
+ }
75
+ return this;
76
+ }
77
+
78
+ remove(child: ScenegraphNode): this {
79
+ const children = this.children;
80
+ const indexOf = children.indexOf(child);
81
+ if (indexOf > -1) {
82
+ children.splice(indexOf, 1);
83
+ }
84
+ return this;
85
+ }
86
+
87
+ removeAll(): this {
88
+ this.children = [];
89
+ return this;
90
+ }
91
+
92
+ traverse(visitor: (node: ScenegraphNode, context: {worldMatrix: Matrix4}) => void, {worldMatrix = new Matrix4()} = {}) {
93
+ const modelMatrix = new Matrix4(worldMatrix).multiplyRight(this.matrix);
94
+
95
+ for (const child of this.children) {
96
+ if (child instanceof GroupNode) {
97
+ child.traverse(visitor, {worldMatrix: modelMatrix});
98
+ } else {
99
+ visitor(child, {worldMatrix: modelMatrix});
100
+ }
101
+ }
102
+ }
103
+ }
@@ -0,0 +1,50 @@
1
+ import {RenderPass} from '@luma.gl/api';
2
+ import {ScenegraphNode, ScenegraphNodeProps} from './scenegraph-node';
3
+ import {Model} from '../model/model';
4
+
5
+ export type ModelNodeProps = ScenegraphNodeProps & {
6
+ model: Model;
7
+ managedResources?: any[];
8
+ bounds?: [number[], number[]];
9
+ }
10
+
11
+ export class ModelNode extends ScenegraphNode {
12
+ readonly model: Model;
13
+ bounds: [number[], number[]] | null = null;
14
+ managedResources: any[];
15
+
16
+ // TODO - is this used? override callbacks to make sure we call them with this
17
+ // onBeforeRender = null;
18
+ // onAfterRender = null;
19
+ // AfterRender = null;
20
+
21
+ constructor(props: ModelNodeProps) {
22
+ super(props);
23
+
24
+ // Create new Model or used supplied Model
25
+ this.model = props.model;
26
+ this.managedResources = props.managedResources || [];
27
+ this.bounds = props.bounds || null;
28
+ this.setProps(props);
29
+ }
30
+
31
+ override getBounds(): [number[], number[]] | null {
32
+ return this.bounds;
33
+ }
34
+
35
+ override destroy(): void {
36
+ if (this.model) {
37
+ this.model.destroy();
38
+ // @ts-expect-error
39
+ this.model = null;
40
+ }
41
+ this.managedResources.forEach((resource) => resource.destroy());
42
+ this.managedResources = [];
43
+ }
44
+
45
+ // Expose model methods
46
+ draw(renderPass?: RenderPass) {
47
+ // Return value indicates if something was actually drawn
48
+ return this.model.draw(renderPass);
49
+ }
50
+ }
@@ -0,0 +1,204 @@
1
+ import {assert, uid, NumericArray} from '@luma.gl/api';
2
+ import {Vector3, Matrix4} from '@math.gl/core';
3
+
4
+ /** Properties for creating a new Scenegraph */
5
+ export type ScenegraphNodeProps = {
6
+ id?: string;
7
+ /** whether to display the object at all */
8
+ display?: boolean;
9
+ matrix?: NumericArray;
10
+ position?: NumericArray;
11
+ rotation?: NumericArray;
12
+ scale?: NumericArray;
13
+ update?: boolean
14
+ };
15
+
16
+ export class ScenegraphNode {
17
+ readonly id: string;
18
+ matrix: Matrix4 = new Matrix4();
19
+
20
+ display = true;
21
+ position = new Vector3();
22
+ rotation = new Vector3();
23
+ scale = new Vector3(1, 1, 1);
24
+ userData: Record<string, unknown> = {};
25
+
26
+ props: ScenegraphNodeProps = {};
27
+
28
+ constructor(props: ScenegraphNodeProps = {}) {
29
+ const {id} = props;
30
+
31
+ this.id = id || uid(this.constructor.name);
32
+
33
+ this._setScenegraphNodeProps(props);
34
+ }
35
+
36
+ getBounds(): [number[], number[]] | null {
37
+ return null;
38
+ }
39
+
40
+ destroy(): void {}
41
+
42
+ /** @deprecated use .destroy() */
43
+ delete(): void {
44
+ this.destroy();
45
+ }
46
+ setProps(props: ScenegraphNodeProps): this {
47
+ this._setScenegraphNodeProps(props);
48
+ return this;
49
+ }
50
+
51
+ toString(): string {
52
+ return `{type: ScenegraphNode, id: ${this.id})}`;
53
+ }
54
+
55
+ setPosition(position: any): this {
56
+ assert(position.length === 3, 'setPosition requires vector argument');
57
+ this.position = position;
58
+ return this;
59
+ }
60
+
61
+ setRotation(rotation: any): this {
62
+ assert(rotation.length === 3, 'setRotation requires vector argument');
63
+ this.rotation = rotation;
64
+ return this;
65
+ }
66
+
67
+ setScale(scale: any): this {
68
+ assert(scale.length === 3, 'setScale requires vector argument');
69
+ this.scale = scale;
70
+ return this;
71
+ }
72
+
73
+ setMatrix(matrix: any, copyMatrix: boolean = true): void {
74
+ if (copyMatrix) {
75
+ this.matrix.copy(matrix);
76
+ } else {
77
+ this.matrix = matrix;
78
+ }
79
+ }
80
+
81
+ setMatrixComponents(components: {
82
+ position?: any;
83
+ rotation?: any;
84
+ scale?: any;
85
+ update?: boolean;
86
+ }): this {
87
+ const {position, rotation, scale, update = true} = components;
88
+ if (position) {
89
+ this.setPosition(position);
90
+ }
91
+ if (rotation) {
92
+ this.setRotation(rotation);
93
+ }
94
+ if (scale) {
95
+ this.setScale(scale);
96
+ }
97
+ if (update) {
98
+ this.updateMatrix();
99
+ }
100
+ return this;
101
+ }
102
+
103
+ updateMatrix(): this {
104
+ const pos = this.position;
105
+ const rot = this.rotation;
106
+ const scale = this.scale;
107
+
108
+ this.matrix.identity();
109
+ this.matrix.translate(pos);
110
+ this.matrix.rotateXYZ(rot);
111
+ this.matrix.scale(scale);
112
+ return this;
113
+ }
114
+
115
+ update(options: {position?: any; rotation?: any; scale?: any} = {}): this {
116
+ const {position, rotation, scale} = options;
117
+ if (position) {
118
+ this.setPosition(position);
119
+ }
120
+ if (rotation) {
121
+ this.setRotation(rotation);
122
+ }
123
+ if (scale) {
124
+ this.setScale(scale);
125
+ }
126
+ this.updateMatrix();
127
+ return this;
128
+ }
129
+
130
+ getCoordinateUniforms(
131
+ viewMatrix: any,
132
+ modelMatrix?: any
133
+ ): {
134
+ viewMatrix: any;
135
+ modelMatrix: any;
136
+ objectMatrix: any;
137
+ worldMatrix: any;
138
+ worldInverseMatrix: any;
139
+ worldInverseTransposeMatrix: any;
140
+ } {
141
+ // TODO - solve multiple class problem
142
+ // assert(viewMatrix instanceof Matrix4);
143
+ assert(viewMatrix);
144
+ modelMatrix = modelMatrix || this.matrix;
145
+ const worldMatrix = new Matrix4(viewMatrix).multiplyRight(modelMatrix);
146
+ const worldInverse = worldMatrix.invert();
147
+ const worldInverseTranspose = worldInverse.transpose();
148
+
149
+ return {
150
+ viewMatrix,
151
+ modelMatrix,
152
+ objectMatrix: modelMatrix,
153
+ worldMatrix,
154
+ worldInverseMatrix: worldInverse,
155
+ worldInverseTransposeMatrix: worldInverseTranspose
156
+ };
157
+ }
158
+
159
+ // TODO - copied code, not yet vetted
160
+ /*
161
+ transform() {
162
+ if (!this.parent) {
163
+ this.endPosition.set(this.position);
164
+ this.endRotation.set(this.rotation);
165
+ this.endScale.set(this.scale);
166
+ } else {
167
+ const parent = this.parent;
168
+ this.endPosition.set(this.position.add(parent.endPosition));
169
+ this.endRotation.set(this.rotation.add(parent.endRotation));
170
+ this.endScale.set(this.scale.add(parent.endScale));
171
+ }
172
+
173
+ const ch = this.children;
174
+ for (let i = 0; i < ch.length; ++i) {
175
+ ch[i].transform();
176
+ }
177
+
178
+ return this;
179
+ }
180
+ */
181
+
182
+ _setScenegraphNodeProps(props: ScenegraphNodeProps): void {
183
+ if ('display' in props) {
184
+ this.display = props.display;
185
+ }
186
+
187
+ if ('position' in props) {
188
+ this.setPosition(props.position);
189
+ }
190
+ if ('rotation' in props) {
191
+ this.setRotation(props.rotation);
192
+ }
193
+ if ('scale' in props) {
194
+ this.setScale(props.scale);
195
+ }
196
+
197
+ // Matrix overwrites other props
198
+ if ('matrix' in props) {
199
+ this.setMatrix(props.matrix);
200
+ }
201
+
202
+ Object.assign(this.props, props);
203
+ }
204
+ }
@@ -2,7 +2,7 @@
2
2
 
3
3
  import {Device, Buffer, Texture, Framebuffer} from '@luma.gl/api';
4
4
  import {getShaderInfo, getPassthroughFS} from '@luma.gl/shadertools';
5
- import GL from '@luma.gl/constants';
5
+ import {GL} from '@luma.gl/constants';
6
6
  import {WebGLDevice, GLParameters} from '@luma.gl/webgl';
7
7
  import {Model} from '../model/model';
8
8