@luma.gl/engine 9.0.0-alpha.8 → 9.0.0-beta.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.
Files changed (191) hide show
  1. package/LICENSE +3 -1
  2. package/dist/animation/key-frames.d.ts +1 -1
  3. package/dist/animation/key-frames.d.ts.map +1 -1
  4. package/dist/animation/key-frames.js +6 -27
  5. package/dist/animation/key-frames.js.map +1 -1
  6. package/dist/animation/timeline.d.ts +8 -8
  7. package/dist/animation/timeline.d.ts.map +1 -1
  8. package/dist/animation/timeline.js +18 -49
  9. package/dist/animation/timeline.js.map +1 -1
  10. package/dist/animation-loop/animation-loop-template.d.ts +23 -0
  11. package/dist/animation-loop/animation-loop-template.d.ts.map +1 -0
  12. package/dist/animation-loop/animation-loop-template.js +7 -0
  13. package/dist/animation-loop/animation-loop-template.js.map +1 -0
  14. package/dist/{lib → animation-loop}/animation-loop.d.ts +30 -22
  15. package/dist/animation-loop/animation-loop.d.ts.map +1 -0
  16. package/dist/{lib → animation-loop}/animation-loop.js +77 -192
  17. package/dist/animation-loop/animation-loop.js.map +1 -0
  18. package/dist/{lib → animation-loop}/animation-props.d.ts +2 -3
  19. package/dist/animation-loop/animation-props.d.ts.map +1 -0
  20. package/dist/animation-loop/animation-props.js.map +1 -0
  21. package/dist/animation-loop/make-animation-loop.d.ts +6 -0
  22. package/dist/animation-loop/make-animation-loop.d.ts.map +1 -0
  23. package/dist/animation-loop/make-animation-loop.js +28 -0
  24. package/dist/animation-loop/make-animation-loop.js.map +1 -0
  25. package/dist/debug/copy-texture-to-image.d.ts +26 -0
  26. package/dist/debug/copy-texture-to-image.d.ts.map +1 -0
  27. package/dist/debug/copy-texture-to-image.js +46 -0
  28. package/dist/debug/copy-texture-to-image.js.map +1 -0
  29. package/dist/debug/debug-framebuffer.d.ts +11 -0
  30. package/dist/debug/debug-framebuffer.d.ts.map +1 -0
  31. package/dist/debug/debug-framebuffer.js +43 -0
  32. package/dist/debug/debug-framebuffer.js.map +1 -0
  33. package/dist/debug/debug-shader-layout.d.ts +9 -0
  34. package/dist/debug/debug-shader-layout.d.ts.map +1 -0
  35. package/dist/debug/debug-shader-layout.js +28 -0
  36. package/dist/debug/debug-shader-layout.js.map +1 -0
  37. package/dist/debug/pixel-data-utils.d.ts +24 -0
  38. package/dist/debug/pixel-data-utils.d.ts.map +1 -0
  39. package/dist/debug/pixel-data-utils.js +41 -0
  40. package/dist/debug/pixel-data-utils.js.map +1 -0
  41. package/dist/dist.dev.js +10081 -0
  42. package/dist/geometries/cone-geometry.d.ts +1 -1
  43. package/dist/geometries/cone-geometry.d.ts.map +1 -1
  44. package/dist/geometries/cone-geometry.js +6 -5
  45. package/dist/geometries/cone-geometry.js.map +1 -1
  46. package/dist/geometries/cube-geometry.d.ts +2 -2
  47. package/dist/geometries/cube-geometry.d.ts.map +1 -1
  48. package/dist/geometries/cube-geometry.js +16 -10
  49. package/dist/geometries/cube-geometry.js.map +1 -1
  50. package/dist/geometries/cylinder-geometry.d.ts +1 -1
  51. package/dist/geometries/cylinder-geometry.d.ts.map +1 -1
  52. package/dist/geometries/cylinder-geometry.js +6 -5
  53. package/dist/geometries/cylinder-geometry.js.map +1 -1
  54. package/dist/geometries/ico-sphere-geometry.d.ts +2 -2
  55. package/dist/geometries/ico-sphere-geometry.d.ts.map +1 -1
  56. package/dist/geometries/ico-sphere-geometry.js +10 -19
  57. package/dist/geometries/ico-sphere-geometry.js.map +1 -1
  58. package/dist/geometries/plane-geometry.d.ts +2 -2
  59. package/dist/geometries/plane-geometry.d.ts.map +1 -1
  60. package/dist/geometries/plane-geometry.js +14 -23
  61. package/dist/geometries/plane-geometry.js.map +1 -1
  62. package/dist/geometries/sphere-geometry.d.ts +2 -2
  63. package/dist/geometries/sphere-geometry.d.ts.map +1 -1
  64. package/dist/geometries/sphere-geometry.js +9 -13
  65. package/dist/geometries/sphere-geometry.js.map +1 -1
  66. package/dist/geometries/truncated-cone-geometry.d.ts +2 -4
  67. package/dist/geometries/truncated-cone-geometry.d.ts.map +1 -1
  68. package/dist/geometries/truncated-cone-geometry.js +9 -25
  69. package/dist/geometries/truncated-cone-geometry.js.map +1 -1
  70. package/dist/geometry/geometry-table.d.ts +2 -2
  71. package/dist/geometry/geometry-table.d.ts.map +1 -1
  72. package/dist/geometry/geometry-table.js.map +1 -1
  73. package/dist/geometry/geometry-utils.d.ts.map +1 -1
  74. package/dist/geometry/geometry-utils.js +0 -9
  75. package/dist/geometry/geometry-utils.js.map +1 -1
  76. package/dist/geometry/geometry.d.ts +43 -43
  77. package/dist/geometry/geometry.d.ts.map +1 -1
  78. package/dist/geometry/geometry.js +20 -82
  79. package/dist/geometry/geometry.js.map +1 -1
  80. package/dist/geometry/gpu-geometry.d.ts +37 -0
  81. package/dist/geometry/gpu-geometry.d.ts.map +1 -0
  82. package/dist/geometry/gpu-geometry.js +110 -0
  83. package/dist/geometry/gpu-geometry.js.map +1 -0
  84. package/dist/geometry/gpu-table.d.ts +1 -0
  85. package/dist/geometry/gpu-table.d.ts.map +1 -0
  86. package/dist/geometry/gpu-table.js +2 -0
  87. package/dist/geometry/gpu-table.js.map +1 -0
  88. package/dist/index.cjs +3128 -0
  89. package/dist/index.d.ts +24 -8
  90. package/dist/index.d.ts.map +1 -1
  91. package/dist/index.js +23 -14
  92. package/dist/index.js.map +1 -1
  93. package/dist/lib/clip-space.d.ts +8 -0
  94. package/dist/lib/clip-space.d.ts.map +1 -1
  95. package/dist/lib/clip-space.js +47 -0
  96. package/dist/lib/clip-space.js.map +1 -1
  97. package/dist/lib/pipeline-factory.d.ts +12 -45
  98. package/dist/lib/pipeline-factory.d.ts.map +1 -1
  99. package/dist/lib/pipeline-factory.js +42 -168
  100. package/dist/lib/pipeline-factory.js.map +1 -1
  101. package/dist/model/model.d.ts +206 -0
  102. package/dist/model/model.d.ts.map +1 -0
  103. package/dist/model/model.js +435 -0
  104. package/dist/model/model.js.map +1 -0
  105. package/dist/scenegraph/group-node.d.ts +21 -0
  106. package/dist/scenegraph/group-node.d.ts.map +1 -0
  107. package/dist/scenegraph/group-node.js +94 -0
  108. package/dist/scenegraph/group-node.js.map +1 -0
  109. package/dist/scenegraph/model-node.d.ts +18 -0
  110. package/dist/scenegraph/model-node.d.ts.map +1 -0
  111. package/dist/scenegraph/model-node.js +28 -0
  112. package/dist/scenegraph/model-node.js.map +1 -0
  113. package/dist/scenegraph/scenegraph-node.d.ts +56 -0
  114. package/dist/scenegraph/scenegraph-node.d.ts.map +1 -0
  115. package/dist/scenegraph/scenegraph-node.js +141 -0
  116. package/dist/scenegraph/scenegraph-node.js.map +1 -0
  117. package/dist/shader-inputs.d.ts +63 -0
  118. package/dist/shader-inputs.d.ts.map +1 -0
  119. package/dist/shader-inputs.js +66 -0
  120. package/dist/shader-inputs.js.map +1 -0
  121. package/dist/transform/buffer-transform.d.ts +35 -0
  122. package/dist/transform/buffer-transform.d.ts.map +1 -0
  123. package/dist/transform/buffer-transform.js +62 -0
  124. package/dist/transform/buffer-transform.js.map +1 -0
  125. package/dist/transform/texture-transform.d.ts +57 -0
  126. package/dist/transform/texture-transform.d.ts.map +1 -0
  127. package/dist/transform/texture-transform.js +122 -0
  128. package/dist/transform/texture-transform.js.map +1 -0
  129. package/dist.min.js +293 -0
  130. package/package.json +21 -12
  131. package/src/animation/timeline.ts +15 -14
  132. package/src/animation-loop/animation-loop-template.ts +23 -0
  133. package/src/{lib → animation-loop}/animation-loop.ts +99 -88
  134. package/src/{lib → animation-loop}/animation-props.ts +1 -1
  135. package/src/animation-loop/make-animation-loop.ts +44 -0
  136. package/src/debug/copy-texture-to-image.ts +72 -0
  137. package/src/debug/debug-framebuffer.ts +57 -0
  138. package/src/debug/debug-shader-layout.ts +38 -0
  139. package/src/debug/pixel-data-utils.ts +57 -0
  140. package/src/geometries/cone-geometry.ts +1 -1
  141. package/src/geometries/cube-geometry.ts +47 -45
  142. package/src/geometries/cylinder-geometry.ts +2 -2
  143. package/src/geometries/ico-sphere-geometry.ts +6 -5
  144. package/src/geometries/plane-geometry.ts +5 -4
  145. package/src/geometries/sphere-geometry.ts +4 -3
  146. package/src/geometries/truncated-cone-geometry.ts +4 -13
  147. package/src/geometry/geometry-table.ts +1 -1
  148. package/src/geometry/geometry-utils.ts +3 -3
  149. package/src/geometry/geometry.ts +65 -110
  150. package/src/geometry/gpu-geometry.ts +125 -0
  151. package/src/geometry/gpu-table.ts +41 -0
  152. package/src/index.ts +34 -10
  153. package/src/lib/clip-space.ts +22 -21
  154. package/src/lib/pipeline-factory.ts +51 -168
  155. package/src/model/model.ts +726 -0
  156. package/src/scenegraph/group-node.ts +103 -0
  157. package/src/scenegraph/model-node.ts +50 -0
  158. package/src/scenegraph/scenegraph-node.ts +204 -0
  159. package/src/shader-inputs.ts +150 -0
  160. package/src/transform/buffer-transform.ts +94 -0
  161. package/src/transform/texture-transform.ts +169 -0
  162. package/dist/bundle.d.ts +0 -2
  163. package/dist/bundle.d.ts.map +0 -1
  164. package/dist/bundle.js +0 -5
  165. package/dist/bundle.js.map +0 -1
  166. package/dist/geometry/primitive-utils.d.ts +0 -1
  167. package/dist/geometry/primitive-utils.d.ts.map +0 -1
  168. package/dist/geometry/primitive-utils.js +0 -2
  169. package/dist/geometry/primitive-utils.js.map +0 -1
  170. package/dist/lib/animation-loop.d.ts.map +0 -1
  171. package/dist/lib/animation-loop.js.map +0 -1
  172. package/dist/lib/animation-props.d.ts.map +0 -1
  173. package/dist/lib/animation-props.js.map +0 -1
  174. package/dist/lib/model-utils.d.ts +0 -5
  175. package/dist/lib/model-utils.d.ts.map +0 -1
  176. package/dist/lib/model-utils.js +0 -45
  177. package/dist/lib/model-utils.js.map +0 -1
  178. package/dist/lib/model.d.ts +0 -41
  179. package/dist/lib/model.d.ts.map +0 -1
  180. package/dist/lib/model.js +0 -182
  181. package/dist/lib/model.js.map +0 -1
  182. package/dist/lib/render-loop.d.ts +0 -14
  183. package/dist/lib/render-loop.d.ts.map +0 -1
  184. package/dist/lib/render-loop.js +0 -49
  185. package/dist/lib/render-loop.js.map +0 -1
  186. package/src/bundle.ts +0 -4
  187. package/src/geometry/primitive-utils.ts +0 -30
  188. package/src/lib/model-utils.ts +0 -124
  189. package/src/lib/model.ts +0 -183
  190. package/src/lib/render-loop.ts +0 -58
  191. /package/dist/{lib → animation-loop}/animation-props.js +0 -0
@@ -1,91 +1,61 @@
1
1
  // luma.gl, MIT license
2
- import type {TypedArray} from '@luma.gl/api';
3
- import {uid, assert} from '@luma.gl/api';
4
- import GL from '@luma.gl/constants';
5
-
6
- /**
7
- * Rendering primitives - "topology" specifies how to extract primitives from vertices.
8
- * @deprecated - use string constants instead
9
- */
10
- export type GLTopology =
11
- GL.POINTS | // draw single points.
12
- GL.LINES | // draw lines. Each vertex connects to the one after it.
13
- GL.LINE_LOOP | // draw lines. Each set of two vertices is treated as a separate line segment.
14
- GL.LINE_STRIP | // draw a connected group of line segments from the first vertex to the last
15
- GL.TRIANGLES | // draw triangles. Each set of three vertices creates a separate triangle.
16
- GL.TRIANGLE_STRIP | // draw a connected group of triangles.
17
- GL.TRIANGLE_FAN // draw a connected group of triangles.
18
- ;
19
-
20
- export type GeometryAttribute = {
21
- size?: number;
22
- value: TypedArray;
23
- [key: string]: any
24
- }
2
+ import type {PrimitiveTopology, TypedArray} from '@luma.gl/core';
3
+ import {uid, assert} from '@luma.gl/core';
25
4
 
26
5
  export type GeometryProps = {
27
6
  id?: string;
28
- attributes?: Record<string, GeometryAttribute | TypedArray>,
29
- indices?: GeometryAttribute | TypedArray;
30
- vertexCount?: number;
31
7
  /** Determines how vertices are read from the 'vertex' attributes */
32
- topology?: 'point-list' | 'line-list' | 'line-strip' | 'triangle-list' | 'triangle-strip';
33
- /** @deprecated */
34
- drawMode?: GLTopology;
8
+ topology:
9
+ | 'point-list'
10
+ | 'line-list'
11
+ | 'line-strip'
12
+ | 'line-loop-webgl'
13
+ | 'triangle-list'
14
+ | 'triangle-strip'
15
+ | 'triangle-fan-webgl';
16
+ /** Auto calculated from attributes if not provided */
17
+ vertexCount?: number;
18
+ attributes?: Record<string, GeometryAttribute | TypedArray>;
19
+ indices?: GeometryAttribute | TypedArray;
35
20
  };
36
21
 
37
- type GeometryAttributes = {
38
- POSITION: GeometryAttribute,
39
- NORMAL: GeometryAttribute,
40
- TEXCOORD_0: GeometryAttribute,
41
- COLOR_0?: GeometryAttribute,
42
- indices?: {size?: number, value: Uint32Array | Uint16Array};
22
+ export type GeometryAttributes = {
23
+ POSITION: GeometryAttribute;
24
+ NORMAL: GeometryAttribute;
25
+ TEXCOORD_0: GeometryAttribute;
26
+ COLOR_0?: GeometryAttribute;
27
+ indices?: GeometryAttribute & {size: 1; value: Uint32Array | Uint16Array};
43
28
  };
44
29
 
45
- export default class Geometry {
46
- /** @deprecated */
47
- static DRAW_MODE = {
48
- POINTS: GL.POINTS, // draw single points.
49
- LINES: GL.LINES, // draw lines. Each vertex connects to the one after it.
50
- LINE_LOOP: GL.LINE_LOOP, // draw lines. Each set of two vertices is treated as a separate line segment.
51
- LINE_STRIP: GL.LINE_STRIP, // draw a connected group of line segments from the first vertex to the last
52
- TRIANGLES: GL.TRIANGLES, // draw triangles. Each set of three vertices creates a separate triangle.
53
- TRIANGLE_STRIP: GL.TRIANGLE_STRIP, // draw a connected group of triangles.
54
- TRIANGLE_FAN: GL.TRIANGLE_FAN // draw a connected group of triangles.
55
- };
30
+ export type GeometryAttribute = {
31
+ size?: number;
32
+ value: TypedArray;
33
+ [key: string]: any;
34
+ };
56
35
 
36
+ export class Geometry {
57
37
  readonly id: string;
58
- userData: Record<string, unknown> = {};
59
-
60
38
  /** Determines how vertices are read from the 'vertex' attributes */
61
- topology?: 'point-list' | 'line-list' | 'line-strip' | 'triangle-list' | 'triangle-strip';
62
- /** @deprecated */
63
- readonly drawMode: GLTopology = GL.TRIANGLES;
64
-
39
+ readonly topology?: PrimitiveTopology;
65
40
  readonly vertexCount: number;
41
+ readonly indices?: GeometryAttribute;
66
42
  readonly attributes: {
67
- POSITION: GeometryAttribute,
68
- NORMAL: GeometryAttribute,
69
- TEXCOORD_0: GeometryAttribute,
70
- COLOR_0?: GeometryAttribute,
43
+ POSITION: GeometryAttribute;
44
+ NORMAL: GeometryAttribute;
45
+ TEXCOORD_0: GeometryAttribute;
46
+ COLOR_0?: GeometryAttribute;
47
+ [key: string]: GeometryAttribute | undefined;
71
48
  };
72
- readonly indices?: Uint16Array | Uint32Array;
73
49
 
74
- constructor(props: GeometryProps = {}) {
75
- const {
76
- id = uid('geometry'),
77
- drawMode = GL.TRIANGLES,
78
- attributes = {},
79
- indices = null,
80
- vertexCount = null
81
- } = props;
50
+ userData: Record<string, unknown> = {};
82
51
 
83
- this.id = id;
84
- this.drawMode = drawMode;
85
- this.topology = props.topology || convertToTopology(drawMode);
52
+ constructor(props: GeometryProps) {
53
+ const {attributes = {}, indices = null, vertexCount = null} = props;
54
+
55
+ this.id = props.id || uid('geometry');
56
+ this.topology = props.topology;
86
57
 
87
58
  if (indices) {
88
- // @ts-expect-error
89
59
  this.indices = ArrayBuffer.isView(indices) ? {value: indices, size: 1} : indices;
90
60
  }
91
61
 
@@ -93,9 +63,10 @@ export default class Geometry {
93
63
  this.attributes = {};
94
64
 
95
65
  for (const [attributeName, attributeValue] of Object.entries(attributes)) {
96
-
97
66
  // Wrap "unwrapped" arrays and try to autodetect their type
98
- const attribute: GeometryAttribute = ArrayBuffer.isView(attributeValue) ? {value: attributeValue} : attributeValue;
67
+ const attribute: GeometryAttribute = ArrayBuffer.isView(attributeValue)
68
+ ? {value: attributeValue}
69
+ : attributeValue;
99
70
 
100
71
  assert(
101
72
  ArrayBuffer.isView(attribute.value),
@@ -109,36 +80,31 @@ export default class Geometry {
109
80
  // Move indices to separate field
110
81
  if (attributeName === 'indices') {
111
82
  assert(!this.indices);
112
- // @ts-expect-error
113
- this.indices = attribute;
83
+ this.indices = attribute;
114
84
  } else {
115
85
  this.attributes[attributeName] = attribute;
116
86
  }
117
87
  }
118
88
 
119
- // @ts-expect-error
120
- if (this.indices && this.indices.isIndexed !== undefined) {
89
+ if (this.indices && this.indices.isIndexed !== undefined) {
121
90
  this.indices = Object.assign({}, this.indices);
122
- // @ts-expect-error
123
91
  delete this.indices.isIndexed;
124
92
  }
125
93
 
126
94
  this.vertexCount = vertexCount || this._calculateVertexCount(this.attributes, this.indices);
127
95
  }
128
96
 
129
- /** @deprecated Use string topology constants instead */
130
- get mode() {
131
- return this.drawMode;
132
- }
133
-
134
97
  getVertexCount(): number {
135
98
  return this.vertexCount;
136
99
  }
137
100
 
138
- // Return an object with all attributes plus indices added as a field.
139
- // getAttributes(): GeometryAttributes {
140
- // return this.indices ? {indices: this.indices, ...this.attributes} : this.attributes;
141
- // }
101
+ /**
102
+ * Return an object with all attributes plus indices added as a field.
103
+ * TODO Geometry types are a mess
104
+ */
105
+ getAttributes(): GeometryAttributes {
106
+ return this.indices ? {indices: this.indices, ...this.attributes} : this.attributes;
107
+ }
142
108
 
143
109
  // PRIVATE
144
110
 
@@ -146,23 +112,27 @@ export default class Geometry {
146
112
  return `Geometry ${this.id} attribute ${attributeName}`;
147
113
  }
148
114
 
149
- // GeometryAttribute
150
- // value: typed array
151
- // type: indices, vertices, uvs
152
- // size: elements per vertex
153
- // target: WebGL buffer type (string or constant)
154
- _setAttributes(attributes: Record<string, GeometryAttribute>, indices): this {
155
-
115
+ /**
116
+ * GeometryAttribute
117
+ * value: typed array
118
+ * type: indices, vertices, uvs
119
+ * size: elements per vertex
120
+ * target: WebGL buffer type (string or constant)
121
+ *
122
+ * @param attributes
123
+ * @param indices
124
+ * @returns
125
+ */
126
+ _setAttributes(attributes: Record<string, GeometryAttribute>, indices: any): this {
156
127
  return this;
157
128
  }
158
129
 
159
- _calculateVertexCount(attributes, indices): number {
130
+ _calculateVertexCount(attributes: GeometryAttributes, indices: GeometryAttribute): number {
160
131
  if (indices) {
161
132
  return indices.value.length;
162
133
  }
163
134
  let vertexCount = Infinity;
164
- for (const attributeName in attributes) {
165
- const attribute = attributes[attributeName];
135
+ for (const attribute of Object.values(attributes)) {
166
136
  const {value, size, constant} = attribute;
167
137
  if (!constant && value && size >= 1) {
168
138
  vertexCount = Math.min(vertexCount, value.length / size);
@@ -173,18 +143,3 @@ export default class Geometry {
173
143
  return vertexCount;
174
144
  }
175
145
  }
176
-
177
- function convertToTopology(drawMode: GLTopology): 'point-list' | 'line-list' | 'line-strip' | 'triangle-list' | 'triangle-strip' {
178
- switch (drawMode) {
179
- case GL.POINTS: return 'point-list'; // draw single points.
180
- case GL.LINES: return 'line-list'; // draw lines. Each vertex connects to the one after it.
181
- case GL.LINE_STRIP: return 'line-strip'; // draw a connected group of line segments from the first vertex to the last
182
- case GL.TRIANGLES: return 'triangle-list'; // draw triangles. Each set of three vertices creates a separate triangle.
183
- case GL.TRIANGLE_STRIP: return 'triangle-strip'; // draw a connected group of triangles.
184
-
185
- case GL.TRIANGLE_FAN: // draw a connected group of triangles.
186
- case GL.LINE_LOOP: // draw lines. Each set of two vertices is treated as a separate line segment.
187
- default:
188
- throw new Error(String(drawMode));
189
- }
190
- }
@@ -0,0 +1,125 @@
1
+ import type {PrimitiveTopology, BufferLayout} from '@luma.gl/core';
2
+ import {Device, Buffer, uid, assert, getVertexFormatFromAttribute} from '@luma.gl/core';
3
+ import type {Geometry} from '../geometry/geometry';
4
+
5
+ export type GPUGeometryProps = {
6
+ id?: string;
7
+ /** Determines how vertices are read from the 'vertex' attributes */
8
+ topology:
9
+ | 'point-list'
10
+ | 'line-list'
11
+ | 'line-strip'
12
+ | 'line-loop-webgl'
13
+ | 'triangle-list'
14
+ | 'triangle-strip'
15
+ | 'triangle-fan-webgl';
16
+ /** Auto calculated from attributes if not provided */
17
+ vertexCount: number;
18
+ bufferLayout: BufferLayout[];
19
+ indices?: Buffer | null;
20
+ attributes: Record<string, Buffer>;
21
+ };
22
+
23
+ export class GPUGeometry {
24
+ readonly id: string;
25
+ userData: Record<string, unknown> = {};
26
+
27
+ /** Determines how vertices are read from the 'vertex' attributes */
28
+ readonly topology?: PrimitiveTopology;
29
+ readonly bufferLayout: BufferLayout[] = [];
30
+
31
+ readonly vertexCount: number;
32
+ readonly indices?: Buffer | null;
33
+ readonly attributes: Record<string, Buffer>;
34
+
35
+ constructor(props: GPUGeometryProps) {
36
+ this.id = props.id || uid('geometry');
37
+ this.topology = props.topology;
38
+ this.indices = props.indices || null;
39
+ this.attributes = props.attributes;
40
+
41
+ this.vertexCount = props.vertexCount;
42
+
43
+ this.bufferLayout = props.bufferLayout || [];
44
+
45
+ if (this.indices) {
46
+ assert(this.indices.usage === Buffer.INDEX);
47
+ }
48
+ }
49
+
50
+ destroy(): void {
51
+ this.indices.destroy();
52
+ this.attributes.positions.destroy();
53
+ this.attributes.normals.destroy();
54
+ this.attributes.texCoords.destroy();
55
+ this.attributes.colors?.destroy();
56
+ }
57
+
58
+ getVertexCount(): number {
59
+ return this.vertexCount;
60
+ }
61
+
62
+ getAttributes(): Record<string, Buffer> {
63
+ return this.attributes;
64
+ }
65
+
66
+ getIndexes(): Buffer | null {
67
+ return this.indices;
68
+ }
69
+
70
+ _calculateVertexCount(positions: Buffer): number {
71
+ // Assume that positions is a fully packed float32x3 buffer
72
+ const vertexCount = positions.byteLength / 12;
73
+ return vertexCount;
74
+ }
75
+ }
76
+
77
+ export function makeGPUGeometry(device: Device, geometry: Geometry | GPUGeometry): GPUGeometry {
78
+ if (geometry instanceof GPUGeometry) {
79
+ return geometry;
80
+ }
81
+
82
+ const indices = getIndexBufferFromGeometry(device, geometry);
83
+ const {attributes, bufferLayout} = getAttributeBuffersFromGeometry(device, geometry);
84
+ return new GPUGeometry({
85
+ topology: geometry.topology || 'triangle-list',
86
+ bufferLayout,
87
+ vertexCount: geometry.vertexCount,
88
+ indices,
89
+ attributes
90
+ });
91
+ }
92
+
93
+ export function getIndexBufferFromGeometry(device: Device, geometry: Geometry): Buffer | undefined {
94
+ if (!geometry.indices) {
95
+ return undefined;
96
+ }
97
+ const data = geometry.indices.value;
98
+ return device.createBuffer({usage: Buffer.INDEX, data});
99
+ }
100
+
101
+ export function getAttributeBuffersFromGeometry(
102
+ device: Device,
103
+ geometry: Geometry
104
+ ): {attributes: Record<string, Buffer>, bufferLayout: BufferLayout[], vertexCount: number} {
105
+ const bufferLayout: BufferLayout[] = [];
106
+
107
+ const attributes: Record<string, Buffer> = {};
108
+ for (const [attributeName, attribute] of Object.entries(geometry.attributes)) {
109
+ let name: string = attributeName;
110
+ // TODO Map some GLTF attribute names (is this still needed?)
111
+ switch (attributeName) {
112
+ case 'POSITION': name = 'positions'; break;
113
+ case 'NORMAL': name = 'normals'; break;
114
+ case 'TEXCOORD_0': name = 'texCoords'; break;
115
+ case 'COLOR_0': name = 'colors'; break;
116
+ }
117
+ attributes[name] = device.createBuffer({data: attribute.value, id: `${attributeName}-buffer`});
118
+ const {value, size, normalized} = attribute;
119
+ bufferLayout.push({name, format: getVertexFormatFromAttribute(value, size, normalized)});
120
+ }
121
+
122
+ const vertexCount = geometry._calculateVertexCount(geometry.attributes, geometry.indices)
123
+
124
+ return {attributes, bufferLayout, vertexCount};
125
+ }
@@ -0,0 +1,41 @@
1
+ /*
2
+ export function getAttributeLayoutsFromGeometry(geometry: Geometry) {
3
+ const layouts: Record<string, {}> = {};
4
+ let indices = geometry.indices;
5
+
6
+ for (const [name, attribute] of Object.entries(geometry.attributes)) {
7
+ const remappedName = mapAttributeName(name);
8
+
9
+ if (attribute.constant) {
10
+ throw new Error('constant attributes not supported');
11
+ } else {
12
+ const typedArray = attribute.value;
13
+ // Create accessor by copying the attribute and removing `value``
14
+ const accessor = {...attribute};
15
+ delete accessor.value;
16
+ buffers[remappedName] = [device.createBuffer(typedArray), accessor];
17
+
18
+ inferAttributeAccessor(name, accessor);
19
+ }
20
+ }
21
+ }
22
+
23
+ export class Table {
24
+ length: number;
25
+ // columns: Record<string, TypedArray> = {};
26
+ }
27
+
28
+ export class GPUTable {
29
+ length: number;
30
+ columns: Record<string, Buffer> = {};
31
+ }
32
+
33
+ export function convertTableToGPUTable(table: Table) {
34
+ // for (const ) {}
35
+ }
36
+
37
+ export function renameTableColumns(table: Table, map: (name: string) => string) {
38
+ const newColumns = table.columns.reduce()
39
+ table.clone();
40
+ }
41
+ */
package/src/index.ts CHANGED
@@ -1,22 +1,43 @@
1
1
  // luma.gl Engine API
2
- export type {AnimationProps} from './lib/animation-props';
3
- export type {AnimationLoopProps} from './lib/animation-loop';
4
- export {AnimationLoop} from './lib/animation-loop';
5
- export {RenderLoop} from './lib/render-loop';
6
- export type {ModelProps} from './lib/model';
7
- export {default as Model} from './lib/model';
8
-
9
- export {PipelineFactory} from './lib/pipeline-factory';
10
2
 
11
3
  // Animation
12
4
  export {Timeline} from './animation/timeline';
13
5
  export {KeyFrames} from './animation/key-frames';
6
+ export type {AnimationProps} from './animation-loop/animation-props';
7
+
8
+ export {AnimationLoopTemplate} from './animation-loop/animation-loop-template';
9
+
10
+ export type {AnimationLoopProps} from './animation-loop/animation-loop';
11
+ export {AnimationLoop} from './animation-loop/animation-loop';
12
+
13
+ export type {MakeAnimationLoopProps} from './animation-loop/make-animation-loop';
14
+ export {makeAnimationLoop} from './animation-loop/make-animation-loop';
15
+
16
+ export type {ModelProps} from './model/model';
17
+ export {Model} from './model/model';
18
+
19
+ // Transforms
20
+ export type {BufferTransformProps} from './transform/buffer-transform';
21
+ export {BufferTransform} from './transform/buffer-transform';
22
+ export type {TextureTransformProps} from './transform/texture-transform';
23
+ export {TextureTransform} from './transform/texture-transform';
24
+
25
+ export {PipelineFactory} from './lib/pipeline-factory';
14
26
 
15
27
  // Utils
16
- // export {default as ClipSpace} from './lib/clip-space';
28
+ export {ClipSpace} from './lib/clip-space';
29
+
30
+ // Scenegraph Core nodes
31
+ export {ScenegraphNode} from './scenegraph/scenegraph-node';
32
+ export {GroupNode} from './scenegraph/group-node';
33
+ export type {ModelNodeProps} from './scenegraph/model-node';
34
+ export {ModelNode} from './scenegraph/model-node';
17
35
 
18
36
  // Geometries
19
- export {default as Geometry} from './geometry/geometry';
37
+ export type {GeometryProps} from './geometry/geometry';
38
+ export {Geometry} from './geometry/geometry';
39
+ export type {GPUGeometryProps} from './geometry/gpu-geometry';
40
+ export {GPUGeometry} from './geometry/gpu-geometry';
20
41
 
21
42
  // Primitives
22
43
  export type {ConeGeometryProps} from './geometries/cone-geometry';
@@ -34,3 +55,6 @@ export {SphereGeometry} from './geometries/sphere-geometry';
34
55
  export type {TruncatedConeGeometryProps} from './geometries/truncated-cone-geometry';
35
56
  export {TruncatedConeGeometry} from './geometries/truncated-cone-geometry';
36
57
 
58
+ // EXPERIMENTAL
59
+ export type {ShaderModuleInputs} from './shader-inputs';
60
+ export {ShaderInputs as _ShaderInputs} from './shader-inputs';
@@ -1,18 +1,17 @@
1
1
 
2
2
  // ClipSpace
3
- /*
4
- import GL from '@luma.gl/constants';
5
- import Model, {ModelProps} from './model';
6
- import Geometry from '../geometry/geometry';
3
+ import {Device, glsl} from '@luma.gl/core';
4
+ import {Model, ModelProps} from '../model/model';
5
+ import {Geometry} from '../geometry/geometry';
7
6
 
8
- const CLIPSPACE_VERTEX_SHADER = `\
9
- attribute vec2 aClipSpacePosition;
10
- attribute vec2 aTexCoord;
11
- attribute vec2 aCoordinate;
7
+ const CLIPSPACE_VERTEX_SHADER = glsl`\
8
+ in vec2 aClipSpacePosition;
9
+ in vec2 aTexCoord;
10
+ in vec2 aCoordinate;
12
11
 
13
- varying vec2 position;
14
- varying vec2 coordinate;
15
- varying vec2 uv;
12
+ out vec2 position;
13
+ out vec2 coordinate;
14
+ out vec2 uv;
16
15
 
17
16
  void main(void) {
18
17
  gl_Position = vec4(aClipSpacePosition, 0., 1.);
@@ -22,20 +21,24 @@ void main(void) {
22
21
  }
23
22
  `;
24
23
 
25
- /* eslint-disable indent, no-multi-spaces *
24
+ /* eslint-disable indent, no-multi-spaces */
26
25
  const POSITIONS = [-1, -1, 1, -1, -1, 1, 1, 1];
27
26
 
28
-
29
- export default class ClipSpace extends Model {
30
- constructor(gl: WebGLRenderingContext, opts?: ModelProps) {
27
+ /**
28
+ * A flat geometry that covers the "visible area" that the GPU renders.
29
+ */
30
+ export class ClipSpace extends Model {
31
+ constructor(device: Device, opts?: ModelProps) {
31
32
  const TEX_COORDS = POSITIONS.map((coord) => (coord === -1 ? 0 : coord));
32
33
 
33
34
  super(
34
- gl,
35
- Object.assign({}, opts, {
35
+ device,
36
+ {
37
+ ...opts,
36
38
  vs: CLIPSPACE_VERTEX_SHADER,
39
+ vertexCount: 4,
37
40
  geometry: new Geometry({
38
- drawMode: GL.TRIANGLE_STRIP,
41
+ topology: 'triangle-strip',
39
42
  vertexCount: 4,
40
43
  attributes: {
41
44
  aClipSpacePosition: {size: 2, value: new Float32Array(POSITIONS)},
@@ -43,9 +46,7 @@ export default class ClipSpace extends Model {
43
46
  aCoordinate: {size: 2, value: new Float32Array(TEX_COORDS)}
44
47
  }
45
48
  })
46
- })
49
+ }
47
50
  );
48
- this.setVertexCount(4);
49
51
  }
50
52
  }
51
- */