@luma.gl/engine 9.0.0-alpha.5 → 9.0.0-alpha.51

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 (171) 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 +9 -9
  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/{lib → animation-loop}/animation-loop.d.ts +30 -31
  11. package/dist/animation-loop/animation-loop.d.ts.map +1 -0
  12. package/dist/{lib → animation-loop}/animation-loop.js +115 -199
  13. package/dist/animation-loop/animation-loop.js.map +1 -0
  14. package/dist/{lib → animation-loop}/animation-props.d.ts +6 -7
  15. package/dist/animation-loop/animation-props.d.ts.map +1 -0
  16. package/dist/animation-loop/animation-props.js.map +1 -0
  17. package/dist/animation-loop/make-animation-loop.d.ts +6 -0
  18. package/dist/animation-loop/make-animation-loop.d.ts.map +1 -0
  19. package/dist/animation-loop/make-animation-loop.js +28 -0
  20. package/dist/animation-loop/make-animation-loop.js.map +1 -0
  21. package/dist/animation-loop/render-loop.d.ts +23 -0
  22. package/dist/animation-loop/render-loop.d.ts.map +1 -0
  23. package/dist/animation-loop/render-loop.js +7 -0
  24. package/dist/animation-loop/render-loop.js.map +1 -0
  25. package/dist/dist.dev.js +7064 -0
  26. package/dist/geometries/cone-geometry.d.ts +1 -1
  27. package/dist/geometries/cone-geometry.d.ts.map +1 -1
  28. package/dist/geometries/cone-geometry.js +6 -5
  29. package/dist/geometries/cone-geometry.js.map +1 -1
  30. package/dist/geometries/cube-geometry.d.ts +2 -2
  31. package/dist/geometries/cube-geometry.d.ts.map +1 -1
  32. package/dist/geometries/cube-geometry.js +15 -8
  33. package/dist/geometries/cube-geometry.js.map +1 -1
  34. package/dist/geometries/cylinder-geometry.d.ts +1 -1
  35. package/dist/geometries/cylinder-geometry.d.ts.map +1 -1
  36. package/dist/geometries/cylinder-geometry.js +6 -5
  37. package/dist/geometries/cylinder-geometry.js.map +1 -1
  38. package/dist/geometries/ico-sphere-geometry.d.ts +2 -2
  39. package/dist/geometries/ico-sphere-geometry.d.ts.map +1 -1
  40. package/dist/geometries/ico-sphere-geometry.js +10 -19
  41. package/dist/geometries/ico-sphere-geometry.js.map +1 -1
  42. package/dist/geometries/plane-geometry.d.ts +2 -2
  43. package/dist/geometries/plane-geometry.d.ts.map +1 -1
  44. package/dist/geometries/plane-geometry.js +14 -23
  45. package/dist/geometries/plane-geometry.js.map +1 -1
  46. package/dist/geometries/sphere-geometry.d.ts +2 -2
  47. package/dist/geometries/sphere-geometry.d.ts.map +1 -1
  48. package/dist/geometries/sphere-geometry.js +9 -13
  49. package/dist/geometries/sphere-geometry.js.map +1 -1
  50. package/dist/geometries/truncated-cone-geometry.d.ts +2 -4
  51. package/dist/geometries/truncated-cone-geometry.d.ts.map +1 -1
  52. package/dist/geometries/truncated-cone-geometry.js +9 -25
  53. package/dist/geometries/truncated-cone-geometry.js.map +1 -1
  54. package/dist/geometry/geometry-table.d.ts +2 -2
  55. package/dist/geometry/geometry-table.d.ts.map +1 -1
  56. package/dist/geometry/geometry-table.js.map +1 -1
  57. package/dist/geometry/geometry-utils.d.ts.map +1 -1
  58. package/dist/geometry/geometry-utils.js +0 -9
  59. package/dist/geometry/geometry-utils.js.map +1 -1
  60. package/dist/geometry/geometry.d.ts +50 -59
  61. package/dist/geometry/geometry.d.ts.map +1 -1
  62. package/dist/geometry/geometry.js +32 -97
  63. package/dist/geometry/geometry.js.map +1 -1
  64. package/dist/geometry/gpu-geometry.d.ts +37 -0
  65. package/dist/geometry/gpu-geometry.d.ts.map +1 -0
  66. package/dist/geometry/gpu-geometry.js +107 -0
  67. package/dist/geometry/gpu-geometry.js.map +1 -0
  68. package/dist/geometry/gpu-table.d.ts +1 -0
  69. package/dist/geometry/gpu-table.d.ts.map +1 -0
  70. package/dist/geometry/gpu-table.js +2 -0
  71. package/dist/geometry/gpu-table.js.map +1 -0
  72. package/dist/index.cjs +2959 -0
  73. package/dist/index.d.ts +26 -9
  74. package/dist/index.d.ts.map +1 -1
  75. package/dist/index.js +23 -13
  76. package/dist/index.js.map +1 -1
  77. package/dist/lib/clip-space.d.ts +8 -0
  78. package/dist/lib/clip-space.d.ts.map +1 -1
  79. package/dist/lib/clip-space.js +47 -0
  80. package/dist/lib/clip-space.js.map +1 -1
  81. package/dist/lib/pipeline-factory.d.ts +12 -40
  82. package/dist/lib/pipeline-factory.d.ts.map +1 -1
  83. package/dist/lib/pipeline-factory.js +50 -148
  84. package/dist/lib/pipeline-factory.js.map +1 -1
  85. package/dist/model/model.d.ts +192 -0
  86. package/dist/model/model.d.ts.map +1 -0
  87. package/dist/model/model.js +312 -0
  88. package/dist/model/model.js.map +1 -0
  89. package/dist/scenegraph/group-node.d.ts +21 -0
  90. package/dist/scenegraph/group-node.d.ts.map +1 -0
  91. package/dist/scenegraph/group-node.js +94 -0
  92. package/dist/scenegraph/group-node.js.map +1 -0
  93. package/dist/scenegraph/model-node.d.ts +18 -0
  94. package/dist/scenegraph/model-node.d.ts.map +1 -0
  95. package/dist/scenegraph/model-node.js +28 -0
  96. package/dist/scenegraph/model-node.js.map +1 -0
  97. package/dist/scenegraph/scenegraph-node.d.ts +56 -0
  98. package/dist/scenegraph/scenegraph-node.d.ts.map +1 -0
  99. package/dist/scenegraph/scenegraph-node.js +141 -0
  100. package/dist/scenegraph/scenegraph-node.js.map +1 -0
  101. package/dist/shader-inputs.d.ts +62 -0
  102. package/dist/shader-inputs.d.ts.map +1 -0
  103. package/dist/shader-inputs.js +49 -0
  104. package/dist/shader-inputs.js.map +1 -0
  105. package/dist/transform/buffer-transform.d.ts +35 -0
  106. package/dist/transform/buffer-transform.d.ts.map +1 -0
  107. package/dist/transform/buffer-transform.js +62 -0
  108. package/dist/transform/buffer-transform.js.map +1 -0
  109. package/dist/transform/texture-transform.d.ts +57 -0
  110. package/dist/transform/texture-transform.d.ts.map +1 -0
  111. package/dist/transform/texture-transform.js +122 -0
  112. package/dist/transform/texture-transform.js.map +1 -0
  113. package/dist.min.js +286 -0
  114. package/package.json +21 -12
  115. package/src/animation/timeline.ts +16 -15
  116. package/src/{lib → animation-loop}/animation-loop.ts +120 -107
  117. package/src/{lib → animation-loop}/animation-props.ts +5 -5
  118. package/src/animation-loop/make-animation-loop.ts +44 -0
  119. package/src/animation-loop/render-loop.ts +23 -0
  120. package/src/geometries/cone-geometry.ts +1 -1
  121. package/src/geometries/cube-geometry.ts +6 -3
  122. package/src/geometries/cylinder-geometry.ts +2 -2
  123. package/src/geometries/ico-sphere-geometry.ts +7 -6
  124. package/src/geometries/plane-geometry.ts +5 -4
  125. package/src/geometries/sphere-geometry.ts +4 -3
  126. package/src/geometries/truncated-cone-geometry.ts +4 -13
  127. package/src/geometry/geometry-table.ts +1 -1
  128. package/src/geometry/geometry-utils.ts +3 -3
  129. package/src/geometry/geometry.ts +79 -119
  130. package/src/geometry/gpu-geometry.ts +124 -0
  131. package/src/geometry/gpu-table.ts +41 -0
  132. package/src/index.ts +38 -12
  133. package/src/lib/clip-space.ts +22 -21
  134. package/src/lib/pipeline-factory.ts +60 -168
  135. package/src/model/model.ts +549 -0
  136. package/src/scenegraph/group-node.ts +103 -0
  137. package/src/scenegraph/model-node.ts +50 -0
  138. package/src/scenegraph/scenegraph-node.ts +204 -0
  139. package/src/shader-inputs.ts +132 -0
  140. package/src/transform/buffer-transform.ts +94 -0
  141. package/src/transform/texture-transform.ts +169 -0
  142. package/dist/bundle.d.ts +0 -2
  143. package/dist/bundle.d.ts.map +0 -1
  144. package/dist/bundle.js +0 -5
  145. package/dist/bundle.js.map +0 -1
  146. package/dist/geometry/primitive-utils.d.ts +0 -1
  147. package/dist/geometry/primitive-utils.d.ts.map +0 -1
  148. package/dist/geometry/primitive-utils.js +0 -2
  149. package/dist/geometry/primitive-utils.js.map +0 -1
  150. package/dist/lib/animation-loop.d.ts.map +0 -1
  151. package/dist/lib/animation-loop.js.map +0 -1
  152. package/dist/lib/animation-props.d.ts.map +0 -1
  153. package/dist/lib/animation-props.js.map +0 -1
  154. package/dist/lib/model-utils.d.ts +0 -5
  155. package/dist/lib/model-utils.d.ts.map +0 -1
  156. package/dist/lib/model-utils.js +0 -45
  157. package/dist/lib/model-utils.js.map +0 -1
  158. package/dist/lib/model.d.ts +0 -41
  159. package/dist/lib/model.d.ts.map +0 -1
  160. package/dist/lib/model.js +0 -176
  161. package/dist/lib/model.js.map +0 -1
  162. package/dist/lib/render-loop.d.ts +0 -14
  163. package/dist/lib/render-loop.d.ts.map +0 -1
  164. package/dist/lib/render-loop.js +0 -49
  165. package/dist/lib/render-loop.js.map +0 -1
  166. package/src/bundle.ts +0 -4
  167. package/src/geometry/primitive-utils.ts +0 -30
  168. package/src/lib/model-utils.ts +0 -124
  169. package/src/lib/model.ts +0 -179
  170. package/src/lib/render-loop.ts +0 -58
  171. /package/dist/{lib → animation-loop}/animation-props.js +0 -0
@@ -1,71 +1,34 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import { uid, assert } from '@luma.gl/api';
3
- import GL from '@luma.gl/constants';
4
- export default class Geometry {
5
- constructor(props = {}) {
6
- _defineProperty(this, "id", void 0);
7
-
8
- _defineProperty(this, "userData", {});
9
-
10
- _defineProperty(this, "topology", void 0);
11
-
12
- _defineProperty(this, "drawMode", GL.TRIANGLES);
13
-
14
- _defineProperty(this, "vertexCount", void 0);
15
-
16
- _defineProperty(this, "attributes", void 0);
17
-
18
- _defineProperty(this, "indices", void 0);
19
-
1
+ import { uid, assert } from '@luma.gl/core';
2
+ export class Geometry {
3
+ constructor(props) {
4
+ this.id = void 0;
5
+ this.topology = void 0;
6
+ this.vertexCount = void 0;
7
+ this.indices = void 0;
8
+ this.attributes = void 0;
9
+ this.userData = {};
20
10
  const {
21
- id = uid('geometry'),
22
- drawMode = GL.TRIANGLES,
23
11
  attributes = {},
24
12
  indices = null,
25
13
  vertexCount = null
26
14
  } = props;
27
- this.id = id;
28
- this.drawMode = drawMode;
29
- this.topology = props.topology || convertToTopology(drawMode);
30
-
31
- this._setAttributes(attributes, indices);
32
-
33
- this.vertexCount = vertexCount || this._calculateVertexCount(this.attributes, this.indices);
34
- }
35
-
36
- get mode() {
37
- return this.drawMode;
38
- }
39
-
40
- getVertexCount() {
41
- return this.vertexCount;
42
- }
43
-
44
- _print(attributeName) {
45
- return "Geometry ".concat(this.id, " attribute ").concat(attributeName);
46
- }
47
-
48
- _setAttributes(attributes, indices) {
15
+ this.id = props.id || uid('geometry');
16
+ this.topology = props.topology;
49
17
  if (indices) {
50
18
  this.indices = ArrayBuffer.isView(indices) ? {
51
19
  value: indices,
52
20
  size: 1
53
21
  } : indices;
54
22
  }
55
-
56
23
  this.attributes = {};
57
-
58
- for (const attributeName in attributes) {
59
- let attribute = attributes[attributeName];
60
- attribute = ArrayBuffer.isView(attribute) ? {
61
- value: attribute
62
- } : attribute;
63
- assert(ArrayBuffer.isView(attribute.value), "".concat(this._print(attributeName), ": must be typed array or object with value as typed array"));
64
-
24
+ for (const [attributeName, attributeValue] of Object.entries(attributes)) {
25
+ const attribute = ArrayBuffer.isView(attributeValue) ? {
26
+ value: attributeValue
27
+ } : attributeValue;
28
+ assert(ArrayBuffer.isView(attribute.value), `${this._print(attributeName)}: must be typed array or object with value as typed array`);
65
29
  if ((attributeName === 'POSITION' || attributeName === 'positions') && !attribute.size) {
66
30
  attribute.size = 3;
67
31
  }
68
-
69
32
  if (attributeName === 'indices') {
70
33
  assert(!this.indices);
71
34
  this.indices = attribute;
@@ -73,72 +36,44 @@ export default class Geometry {
73
36
  this.attributes[attributeName] = attribute;
74
37
  }
75
38
  }
76
-
77
39
  if (this.indices && this.indices.isIndexed !== undefined) {
78
40
  this.indices = Object.assign({}, this.indices);
79
41
  delete this.indices.isIndexed;
80
42
  }
81
-
43
+ this.vertexCount = vertexCount || this._calculateVertexCount(this.attributes, this.indices);
44
+ }
45
+ getVertexCount() {
46
+ return this.vertexCount;
47
+ }
48
+ getAttributes() {
49
+ return this.indices ? {
50
+ indices: this.indices,
51
+ ...this.attributes
52
+ } : this.attributes;
53
+ }
54
+ _print(attributeName) {
55
+ return `Geometry ${this.id} attribute ${attributeName}`;
56
+ }
57
+ _setAttributes(attributes, indices) {
82
58
  return this;
83
59
  }
84
-
85
60
  _calculateVertexCount(attributes, indices) {
86
61
  if (indices) {
87
62
  return indices.value.length;
88
63
  }
89
-
90
64
  let vertexCount = Infinity;
91
-
92
- for (const attributeName in attributes) {
93
- const attribute = attributes[attributeName];
65
+ for (const attribute of Object.values(attributes)) {
94
66
  const {
95
67
  value,
96
68
  size,
97
69
  constant
98
70
  } = attribute;
99
-
100
71
  if (!constant && value && size >= 1) {
101
72
  vertexCount = Math.min(vertexCount, value.length / size);
102
73
  }
103
74
  }
104
-
105
75
  assert(Number.isFinite(vertexCount));
106
76
  return vertexCount;
107
77
  }
108
-
109
- }
110
-
111
- _defineProperty(Geometry, "DRAW_MODE", {
112
- POINTS: GL.POINTS,
113
- LINES: GL.LINES,
114
- LINE_LOOP: GL.LINE_LOOP,
115
- LINE_STRIP: GL.LINE_STRIP,
116
- TRIANGLES: GL.TRIANGLES,
117
- TRIANGLE_STRIP: GL.TRIANGLE_STRIP,
118
- TRIANGLE_FAN: GL.TRIANGLE_FAN
119
- });
120
-
121
- function convertToTopology(drawMode) {
122
- switch (drawMode) {
123
- case GL.POINTS:
124
- return 'point-list';
125
-
126
- case GL.LINES:
127
- return 'line-list';
128
-
129
- case GL.LINE_STRIP:
130
- return 'line-strip';
131
-
132
- case GL.TRIANGLES:
133
- return 'triangle-list';
134
-
135
- case GL.TRIANGLE_STRIP:
136
- return 'triangle-strip';
137
-
138
- case GL.TRIANGLE_FAN:
139
- case GL.LINE_LOOP:
140
- default:
141
- throw new Error(String(drawMode));
142
- }
143
78
  }
144
79
  //# sourceMappingURL=geometry.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/geometry/geometry.ts"],"names":["uid","assert","GL","Geometry","constructor","props","TRIANGLES","id","drawMode","attributes","indices","vertexCount","topology","convertToTopology","_setAttributes","_calculateVertexCount","mode","getVertexCount","_print","attributeName","ArrayBuffer","isView","value","size","attribute","isIndexed","undefined","Object","assign","length","Infinity","constant","Math","min","Number","isFinite","POINTS","LINES","LINE_LOOP","LINE_STRIP","TRIANGLE_STRIP","TRIANGLE_FAN","Error","String"],"mappings":";AAEA,SAAQA,GAAR,EAAaC,MAAb,QAA0B,cAA1B;AACA,OAAOC,EAAP,MAAe,oBAAf;AAkCA,eAAe,MAAMC,QAAN,CAAe;AA6B5BC,EAAAA,WAAW,CAACC,KAAoB,GAAG,EAAxB,EAA4B;AAAA;;AAAA,sCAhBP,EAgBO;;AAAA;;AAAA,sCAXTH,EAAE,CAACI,SAWM;;AAAA;;AAAA;;AAAA;;AACrC,UAAM;AACJC,MAAAA,EAAE,GAAGP,GAAG,CAAC,UAAD,CADJ;AAEJQ,MAAAA,QAAQ,GAAGN,EAAE,CAACI,SAFV;AAGJG,MAAAA,UAAU,GAAG,EAHT;AAIJC,MAAAA,OAAO,GAAG,IAJN;AAKJC,MAAAA,WAAW,GAAG;AALV,QAMFN,KANJ;AAQA,SAAKE,EAAL,GAAUA,EAAV;AACA,SAAKC,QAAL,GAAgBA,QAAhB;AACA,SAAKI,QAAL,GAAgBP,KAAK,CAACO,QAAN,IAAkBC,iBAAiB,CAACL,QAAD,CAAnD;;AAEA,SAAKM,cAAL,CAAoBL,UAApB,EAAgCC,OAAhC;;AAEA,SAAKC,WAAL,GAAmBA,WAAW,IAAI,KAAKI,qBAAL,CAA2B,KAAKN,UAAhC,EAA4C,KAAKC,OAAjD,CAAlC;AACD;;AAEO,MAAJM,IAAI,GAAG;AACT,WAAO,KAAKR,QAAZ;AACD;;AAEDS,EAAAA,cAAc,GAAW;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AR;AAAgB,aAAO,YAAP;;AAChB,SAAKlC,EAAE,CAACmC,KAAR;AAAe,aAAO,WAAP;;AACf,SAAKnC,EAAE,CAACqC,UAAR;AAAoB,aAAO,YAAP;;AACpB,SAAKrC,EAAE,CAACI,SAAR;AAAmB,aAAO,eAAP;;AACnB,SAAKJ,EAAE,CAACsC,cAAR;AAAwB,aAAO,gBAAP;;AAExB,SAAKtC,EAAE,CAACuC,YAAR;AACA,SAAKvC,EAAE,CAACoC,SAAR;AACA;AACE,YAAM,IAAII,KAAJ,CAAUC,MAAM,CAACnC,QAAD,CAAhB,CAAN;AAVJ;AAYD","sourcesContent":["// luma.gl, MIT license\nimport type {TypedArray} from '@luma.gl/api';\nimport {uid, assert} from '@luma.gl/api';\nimport GL from '@luma.gl/constants';\n\n/**\n * Rendering primitives - \"topology\" specifies how to extract primitives from vertices.\n */\nexport type Topology =\n GL.POINTS | // draw single points.\n GL.LINES | // draw lines. Each vertex connects to the one after it.\n GL.LINE_LOOP | // draw lines. Each set of two vertices is treated as a separate line segment.\n GL.LINE_STRIP | // draw a connected group of line segments from the first vertex to the last\n GL.TRIANGLES | // draw triangles. Each set of three vertices creates a separate triangle.\n GL.TRIANGLE_STRIP | // draw a connected group of triangles.\n GL.TRIANGLE_FAN // draw a connected group of triangles.\n ;\n\nexport type GeometryProps = {\n id?: string;\n attributes?: {},\n indices?;\n vertexCount?: number;\n /** Determines how vertices are read from the 'vertex' attributes */\n topology?: 'point-list' | 'line-list' | 'line-strip' | 'triangle-list' | 'triangle-strip';\n /** @deprecated */\n drawMode?: Topology;\n};\n\ntype GeometryAttributes = {\n POSITION: {size: number, value: TypedArray, [key: string]: any},\n NORMAL: {size: number, value: TypedArray, [key: string]: any},\n TEXCOORD_0: {size: number, value: TypedArray, [key: string]: any},\n COLOR_0?: {size: number, value: TypedArray, [key: string]: any},\n indices?: {size?: number, value: Uint32Array | Uint16Array};\n};\n\nexport default class Geometry {\n /** @deprecated */\n static DRAW_MODE = {\n POINTS: GL.POINTS, // draw single points.\n LINES: GL.LINES, // draw lines. Each vertex connects to the one after it.\n LINE_LOOP: GL.LINE_LOOP, // draw lines. Each set of two vertices is treated as a separate line segment.\n LINE_STRIP: GL.LINE_STRIP, // draw a connected group of line segments from the first vertex to the last\n TRIANGLES: GL.TRIANGLES, // draw triangles. Each set of three vertices creates a separate triangle.\n TRIANGLE_STRIP: GL.TRIANGLE_STRIP, // draw a connected group of triangles.\n TRIANGLE_FAN: GL.TRIANGLE_FAN // draw a connected group of triangles.\n };\n\n readonly id: string;\n userData: Record<string, any> = {};\n\n /** Determines how vertices are read from the 'vertex' attributes */\n topology?: 'point-list' | 'line-list' | 'line-strip' | 'triangle-list' | 'triangle-strip';\n /** @deprecated */\n readonly drawMode: Topology = GL.TRIANGLES;\n\n readonly vertexCount: number;\n readonly attributes: {\n POSITION: {size: number, value: TypedArray, [key: string]: any},\n NORMAL: {size: number, value: TypedArray, [key: string]: any},\n TEXCOORD_0: {size: number, value: TypedArray, [key: string]: any},\n COLOR_0?: {size: number, value: TypedArray, [key: string]: any},\n };\n readonly indices?: Uint16Array | Uint32Array;\n\n constructor(props: GeometryProps = {}) {\n const {\n id = uid('geometry'),\n drawMode = GL.TRIANGLES,\n attributes = {},\n indices = null,\n vertexCount = null\n } = props;\n\n this.id = id;\n this.drawMode = drawMode;\n this.topology = props.topology || convertToTopology(drawMode);\n\n this._setAttributes(attributes, indices);\n\n this.vertexCount = vertexCount || this._calculateVertexCount(this.attributes, this.indices);\n }\n\n get mode() {\n return this.drawMode;\n }\n\n getVertexCount(): number {\n return this.vertexCount;\n }\n\n // Return an object with all attributes plus indices added as a field.\n // getAttributes(): GeometryAttributes {\n // return this.indices ? {indices: this.indices, ...this.attributes} : this.attributes;\n // }\n\n // PRIVATE\n\n _print(attributeName): string {\n return `Geometry ${this.id} attribute ${attributeName}`;\n }\n\n // Attribute\n // value: typed array\n // type: indices, vertices, uvs\n // size: elements per vertex\n // target: WebGL buffer type (string or constant)\n _setAttributes(attributes, indices): this {\n if (indices) {\n // @ts-expect-error\n this.indices = ArrayBuffer.isView(indices) ? {value: indices, size: 1} : indices;\n }\n\n // @ts-expect-error\n this.attributes = {};\n\n for (const attributeName in attributes) {\n let attribute = attributes[attributeName];\n\n // Wrap \"unwrapped\" arrays and try to autodetect their type\n attribute = ArrayBuffer.isView(attribute) ? {value: attribute} : attribute;\n\n assert(\n ArrayBuffer.isView(attribute.value),\n `${this._print(attributeName)}: must be typed array or object with value as typed array`\n );\n\n if ((attributeName === 'POSITION' || attributeName === 'positions') && !attribute.size) {\n attribute.size = 3;\n }\n\n // Move indices to separate field\n if (attributeName === 'indices') {\n assert(!this.indices);\n // @ts-expect-error\n this.indices = attribute;\n } else {\n this.attributes[attributeName] = attribute;\n }\n }\n\n // @ts-expect-error\n if (this.indices && this.indices.isIndexed !== undefined) {\n // @ts-expect-error\n this.indices = Object.assign({}, this.indices);\n // @ts-expect-error\n delete this.indices.isIndexed;\n }\n\n return this;\n }\n\n _calculateVertexCount(attributes, indices): number {\n if (indices) {\n return indices.value.length;\n }\n let vertexCount = Infinity;\n for (const attributeName in attributes) {\n const attribute = attributes[attributeName];\n const {value, size, constant} = attribute;\n if (!constant && value && size >= 1) {\n vertexCount = Math.min(vertexCount, value.length / size);\n }\n }\n\n assert(Number.isFinite(vertexCount));\n return vertexCount;\n }\n}\n\nfunction convertToTopology(drawMode: GL): 'point-list' | 'line-list' | 'line-strip' | 'triangle-list' | 'triangle-strip' {\n switch (drawMode) {\n case GL.POINTS: return 'point-list'; // draw single points.\n case GL.LINES: return 'line-list'; // draw lines. Each vertex connects to the one after it.\n case GL.LINE_STRIP: return 'line-strip'; // draw a connected group of line segments from the first vertex to the last\n case GL.TRIANGLES: return 'triangle-list'; // draw triangles. Each set of three vertices creates a separate triangle.\n case GL.TRIANGLE_STRIP: return 'triangle-strip'; // draw a connected group of triangles.\n\n case GL.TRIANGLE_FAN: // draw a connected group of triangles.\n case GL.LINE_LOOP: // draw lines. Each set of two vertices is treated as a separate line segment.\n default:\n throw new Error(String(drawMode));\n }\n}\n"],"file":"geometry.js"}
1
+ {"version":3,"file":"geometry.js","names":["uid","assert","Geometry","constructor","props","id","topology","vertexCount","indices","attributes","userData","ArrayBuffer","isView","value","size","attributeName","attributeValue","Object","entries","attribute","_print","isIndexed","undefined","assign","_calculateVertexCount","getVertexCount","getAttributes","_setAttributes","length","Infinity","values","constant","Math","min","Number","isFinite"],"sources":["../../src/geometry/geometry.ts"],"sourcesContent":["// luma.gl, MIT license\nimport type {PrimitiveTopology, TypedArray} from '@luma.gl/core';\nimport {uid, assert} from '@luma.gl/core';\n\nexport type GeometryProps = {\n id?: string;\n /** Determines how vertices are read from the 'vertex' attributes */\n topology:\n | 'point-list'\n | 'line-list'\n | 'line-strip'\n | 'line-loop-webgl'\n | 'triangle-list'\n | 'triangle-strip'\n | 'triangle-fan-webgl';\n /** Auto calculated from attributes if not provided */\n vertexCount?: number;\n attributes?: Record<string, GeometryAttribute | TypedArray>;\n indices?: GeometryAttribute | TypedArray;\n};\n\nexport type GeometryAttributes = {\n POSITION: GeometryAttribute;\n NORMAL: GeometryAttribute;\n TEXCOORD_0: GeometryAttribute;\n COLOR_0?: GeometryAttribute;\n indices?: GeometryAttribute & {size: 1; value: Uint32Array | Uint16Array};\n};\n\nexport type GeometryAttribute = {\n size?: number;\n value: TypedArray;\n [key: string]: any;\n};\n\nexport class Geometry {\n readonly id: string;\n /** Determines how vertices are read from the 'vertex' attributes */\n readonly topology?: PrimitiveTopology;\n readonly vertexCount: number;\n readonly indices?: GeometryAttribute;\n readonly attributes: {\n POSITION: GeometryAttribute;\n NORMAL: GeometryAttribute;\n TEXCOORD_0: GeometryAttribute;\n COLOR_0?: GeometryAttribute;\n [key: string]: GeometryAttribute | undefined;\n };\n\n userData: Record<string, unknown> = {};\n\n constructor(props: GeometryProps) {\n const {attributes = {}, indices = null, vertexCount = null} = props;\n\n this.id = props.id || uid('geometry');\n this.topology = props.topology;\n\n if (indices) {\n this.indices = ArrayBuffer.isView(indices) ? {value: indices, size: 1} : indices;\n }\n\n // @ts-expect-error\n this.attributes = {};\n\n for (const [attributeName, attributeValue] of Object.entries(attributes)) {\n // Wrap \"unwrapped\" arrays and try to autodetect their type\n const attribute: GeometryAttribute = ArrayBuffer.isView(attributeValue)\n ? {value: attributeValue}\n : attributeValue;\n\n assert(\n ArrayBuffer.isView(attribute.value),\n `${this._print(attributeName)}: must be typed array or object with value as typed array`\n );\n\n if ((attributeName === 'POSITION' || attributeName === 'positions') && !attribute.size) {\n attribute.size = 3;\n }\n\n // Move indices to separate field\n if (attributeName === 'indices') {\n assert(!this.indices);\n this.indices = attribute;\n } else {\n this.attributes[attributeName] = attribute;\n }\n }\n\n if (this.indices && this.indices.isIndexed !== undefined) {\n this.indices = Object.assign({}, this.indices);\n delete this.indices.isIndexed;\n }\n\n this.vertexCount = vertexCount || this._calculateVertexCount(this.attributes, this.indices);\n }\n\n getVertexCount(): number {\n return this.vertexCount;\n }\n\n /** \n * Return an object with all attributes plus indices added as a field.\n * TODO Geometry types are a mess\n */\n getAttributes(): GeometryAttributes {\n return this.indices ? {indices: this.indices, ...this.attributes} : this.attributes;\n }\n\n // PRIVATE\n\n _print(attributeName: string): string {\n return `Geometry ${this.id} attribute ${attributeName}`;\n }\n\n /**\n * GeometryAttribute\n * value: typed array\n * type: indices, vertices, uvs\n * size: elements per vertex\n * target: WebGL buffer type (string or constant)\n * \n * @param attributes \n * @param indices \n * @returns \n */\n _setAttributes(attributes: Record<string, GeometryAttribute>, indices: any): this {\n return this;\n }\n\n _calculateVertexCount(attributes: GeometryAttributes, indices: GeometryAttribute): number {\n if (indices) {\n return indices.value.length;\n }\n let vertexCount = Infinity;\n for (const attribute of Object.values(attributes)) {\n const {value, size, constant} = attribute;\n if (!constant && value && size >= 1) {\n vertexCount = Math.min(vertexCount, value.length / size);\n }\n }\n\n assert(Number.isFinite(vertexCount));\n return vertexCount;\n }\n}\n"],"mappings":"AAEA,SAAQA,GAAG,EAAEC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,CAACY,QAAQ,IAAIlB,KAAK,IAAIC,IAAI,IAAI,CAAC,EAAE;QACnCP,WAAW,GAAGyB,IAAI,CAACC,GAAG,CAAC1B,WAAW,EAAEM,KAAK,CAACe,MAAM,GAAGd,IAAI,CAAC;MAC1D;IACF;IAEAb,MAAM,CAACiC,MAAM,CAACC,QAAQ,CAAC5B,WAAW,CAAC,CAAC;IACpC,OAAOA,WAAW;EACpB;AACF"}
@@ -0,0 +1,37 @@
1
+ import type { PrimitiveTopology, BufferLayout } from '@luma.gl/core';
2
+ import { Device, Buffer } from '@luma.gl/core';
3
+ import type { Geometry } from '../geometry/geometry';
4
+ export type GPUGeometryProps = {
5
+ id?: string;
6
+ /** Determines how vertices are read from the 'vertex' attributes */
7
+ topology: 'point-list' | 'line-list' | 'line-strip' | 'line-loop-webgl' | 'triangle-list' | 'triangle-strip' | 'triangle-fan-webgl';
8
+ /** Auto calculated from attributes if not provided */
9
+ vertexCount: number;
10
+ bufferLayout: BufferLayout[];
11
+ indices?: Buffer | null;
12
+ attributes: Record<string, Buffer>;
13
+ };
14
+ export declare class GPUGeometry {
15
+ readonly id: string;
16
+ userData: Record<string, unknown>;
17
+ /** Determines how vertices are read from the 'vertex' attributes */
18
+ readonly topology?: PrimitiveTopology;
19
+ readonly bufferLayout: BufferLayout[];
20
+ readonly vertexCount: number;
21
+ readonly indices?: Buffer | null;
22
+ readonly attributes: Record<string, Buffer>;
23
+ constructor(props: GPUGeometryProps);
24
+ destroy(): void;
25
+ getVertexCount(): number;
26
+ getAttributes(): Record<string, Buffer>;
27
+ getIndexes(): Buffer | null;
28
+ _calculateVertexCount(positions: Buffer): number;
29
+ }
30
+ export declare function makeGPUGeometry(device: Device, geometry: Geometry | GPUGeometry): GPUGeometry;
31
+ export declare function getIndexBufferFromGeometry(device: Device, geometry: Geometry): Buffer | undefined;
32
+ export declare function getAttributeBuffersFromGeometry(device: Device, geometry: Geometry): {
33
+ attributes: Record<string, Buffer>;
34
+ bufferLayout: BufferLayout[];
35
+ vertexCount: number;
36
+ };
37
+ //# sourceMappingURL=gpu-geometry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gpu-geometry.d.ts","sourceRoot":"","sources":["../../src/geometry/gpu-geometry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,iBAAiB,EAAE,YAAY,EAAC,MAAM,eAAe,CAAC;AACnE,OAAO,EAAC,MAAM,EAAE,MAAM,EAA4C,MAAM,eAAe,CAAC;AACxF,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAEnD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,oEAAoE;IACpE,QAAQ,EACJ,YAAY,GACZ,WAAW,GACX,YAAY,GACZ,iBAAiB,GACjB,eAAe,GACf,gBAAgB,GAChB,oBAAoB,CAAC;IACzB,sDAAsD;IACtD,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,YAAY,EAAE,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACpC,CAAC;AAEF,qBAAa,WAAW;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAM;IAEvC,oEAAoE;IACpE,QAAQ,CAAC,QAAQ,CAAC,EAAE,iBAAiB,CAAC;IACtC,QAAQ,CAAC,YAAY,EAAE,YAAY,EAAE,CAAM;IAE3C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBAEhC,KAAK,EAAE,gBAAgB;IAenC,OAAO,IAAI,IAAI;IAQf,cAAc,IAAI,MAAM;IAIxB,aAAa,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAIvC,UAAU,IAAI,MAAM,GAAG,IAAI;IAI3B,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;CAKjD;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,WAAW,GAAG,WAAW,CAc7F;AAED,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,MAAM,GAAG,SAAS,CAMjG;AAED,wBAAgB,+BAA+B,CAC7C,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,QAAQ,GACjB;IAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,YAAY,EAAE,YAAY,EAAE,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAC,CAoBzF"}
@@ -0,0 +1,107 @@
1
+ import { Buffer, uid, assert, getVertexFormatFromAttribute } from '@luma.gl/core';
2
+ export class GPUGeometry {
3
+ constructor(props) {
4
+ this.id = void 0;
5
+ this.userData = {};
6
+ this.topology = void 0;
7
+ this.bufferLayout = [];
8
+ this.vertexCount = void 0;
9
+ this.indices = void 0;
10
+ this.attributes = void 0;
11
+ this.id = props.id || uid('geometry');
12
+ this.topology = props.topology;
13
+ this.indices = props.indices || null;
14
+ this.attributes = props.attributes;
15
+ this.vertexCount = props.vertexCount;
16
+ this.bufferLayout = props.bufferLayout || [];
17
+ if (this.indices) {
18
+ assert(this.indices.usage === Buffer.INDEX);
19
+ }
20
+ }
21
+ destroy() {
22
+ var _this$attributes$colo;
23
+ this.indices.destroy();
24
+ this.attributes.positions.destroy();
25
+ this.attributes.normals.destroy();
26
+ this.attributes.texCoords.destroy();
27
+ (_this$attributes$colo = this.attributes.colors) === null || _this$attributes$colo === void 0 ? void 0 : _this$attributes$colo.destroy();
28
+ }
29
+ getVertexCount() {
30
+ return this.vertexCount;
31
+ }
32
+ getAttributes() {
33
+ return this.attributes;
34
+ }
35
+ getIndexes() {
36
+ return this.indices;
37
+ }
38
+ _calculateVertexCount(positions) {
39
+ const vertexCount = positions.byteLength / 12;
40
+ return vertexCount;
41
+ }
42
+ }
43
+ export function makeGPUGeometry(device, geometry) {
44
+ if (geometry instanceof GPUGeometry) {
45
+ return geometry;
46
+ }
47
+ const indices = getIndexBufferFromGeometry(device, geometry);
48
+ const {
49
+ attributes,
50
+ bufferLayout
51
+ } = getAttributeBuffersFromGeometry(device, geometry);
52
+ return new GPUGeometry({
53
+ topology: geometry.topology || 'triangle-list',
54
+ bufferLayout,
55
+ vertexCount: geometry.vertexCount,
56
+ indices,
57
+ attributes
58
+ });
59
+ }
60
+ export function getIndexBufferFromGeometry(device, geometry) {
61
+ if (!geometry.indices) {
62
+ return undefined;
63
+ }
64
+ const data = geometry.indices.value;
65
+ return device.createBuffer({
66
+ usage: Buffer.INDEX,
67
+ data
68
+ });
69
+ }
70
+ export function getAttributeBuffersFromGeometry(device, geometry) {
71
+ const bufferLayout = [];
72
+ const attributes = {};
73
+ for (const [attributeName, attribute] of Object.entries(geometry.attributes)) {
74
+ let name = attributeName;
75
+ switch (attributeName) {
76
+ case 'POSITION':
77
+ name = 'positions';
78
+ break;
79
+ case 'NORMAL':
80
+ name = 'normals';
81
+ break;
82
+ case 'TEXCOORD_0':
83
+ name = 'texCoords';
84
+ break;
85
+ }
86
+ attributes[name] = device.createBuffer({
87
+ data: attribute.value,
88
+ id: `${attributeName}-buffer`
89
+ });
90
+ const {
91
+ value,
92
+ size,
93
+ normalized
94
+ } = attribute;
95
+ bufferLayout.push({
96
+ name,
97
+ format: getVertexFormatFromAttribute(value, size, normalized)
98
+ });
99
+ }
100
+ const vertexCount = geometry._calculateVertexCount(geometry.attributes, geometry.indices);
101
+ return {
102
+ attributes,
103
+ bufferLayout,
104
+ vertexCount
105
+ };
106
+ }
107
+ //# sourceMappingURL=gpu-geometry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gpu-geometry.js","names":["Buffer","uid","assert","getVertexFormatFromAttribute","GPUGeometry","constructor","props","id","userData","topology","bufferLayout","vertexCount","indices","attributes","usage","INDEX","destroy","_this$attributes$colo","positions","normals","texCoords","colors","getVertexCount","getAttributes","getIndexes","_calculateVertexCount","byteLength","makeGPUGeometry","device","geometry","getIndexBufferFromGeometry","getAttributeBuffersFromGeometry","undefined","data","value","createBuffer","attributeName","attribute","Object","entries","name","size","normalized","push","format"],"sources":["../../src/geometry/gpu-geometry.ts"],"sourcesContent":["import type {PrimitiveTopology, BufferLayout} from '@luma.gl/core';\nimport {Device, Buffer, uid, assert, getVertexFormatFromAttribute} from '@luma.gl/core';\nimport type {Geometry} from '../geometry/geometry';\n\nexport type GPUGeometryProps = {\n id?: string;\n /** Determines how vertices are read from the 'vertex' attributes */\n topology:\n | 'point-list'\n | 'line-list'\n | 'line-strip'\n | 'line-loop-webgl'\n | 'triangle-list'\n | 'triangle-strip'\n | 'triangle-fan-webgl';\n /** Auto calculated from attributes if not provided */\n vertexCount: number;\n bufferLayout: BufferLayout[];\n indices?: Buffer | null;\n attributes: Record<string, Buffer>;\n};\n\nexport class GPUGeometry {\n readonly id: string;\n userData: Record<string, unknown> = {};\n\n /** Determines how vertices are read from the 'vertex' attributes */\n readonly topology?: PrimitiveTopology;\n readonly bufferLayout: BufferLayout[] = [];\n\n readonly vertexCount: number;\n readonly indices?: Buffer | null;\n readonly attributes: Record<string, Buffer>;\n\n constructor(props: GPUGeometryProps) {\n this.id = props.id || uid('geometry');\n this.topology = props.topology;\n this.indices = props.indices || null;\n this.attributes = props.attributes;\n\n this.vertexCount = props.vertexCount;\n\n this.bufferLayout = props.bufferLayout || [];\n\n if (this.indices) {\n assert(this.indices.usage === Buffer.INDEX);\n }\n }\n\n destroy(): void {\n this.indices.destroy();\n this.attributes.positions.destroy();\n this.attributes.normals.destroy();\n this.attributes.texCoords.destroy();\n this.attributes.colors?.destroy();\n }\n\n getVertexCount(): number {\n return this.vertexCount;\n }\n\n getAttributes(): Record<string, Buffer> {\n return this.attributes;\n }\n\n getIndexes(): Buffer | null {\n return this.indices;\n }\n\n _calculateVertexCount(positions: Buffer): number {\n // Assume that positions is a fully packed float32x3 buffer\n const vertexCount = positions.byteLength / 12;\n return vertexCount;\n }\n}\n\nexport function makeGPUGeometry(device: Device, geometry: Geometry | GPUGeometry): GPUGeometry {\n if (geometry instanceof GPUGeometry) {\n return geometry;\n }\n\n const indices = getIndexBufferFromGeometry(device, geometry);\n const {attributes, bufferLayout} = getAttributeBuffersFromGeometry(device, geometry);\n return new GPUGeometry({\n topology: geometry.topology || 'triangle-list',\n bufferLayout,\n vertexCount: geometry.vertexCount,\n indices,\n attributes\n });\n}\n\nexport function getIndexBufferFromGeometry(device: Device, geometry: Geometry): Buffer | undefined {\n if (!geometry.indices) {\n return undefined;\n }\n const data = geometry.indices.value;\n return device.createBuffer({usage: Buffer.INDEX, data});\n}\n\nexport function getAttributeBuffersFromGeometry(\n device: Device,\n geometry: Geometry\n): {attributes: Record<string, Buffer>, bufferLayout: BufferLayout[], vertexCount: number} {\n const bufferLayout: BufferLayout[] = [];\n\n const attributes: Record<string, Buffer> = {};\n for (const [attributeName, attribute] of Object.entries(geometry.attributes)) {\n let name: string = attributeName;\n // TODO Map some GLTF attribute names (is this still needed?)\n switch (attributeName) {\n case 'POSITION': name = 'positions'; break;\n case 'NORMAL': name = 'normals'; break;\n case 'TEXCOORD_0': name = 'texCoords'; break;\n }\n attributes[name] = device.createBuffer({data: attribute.value, id: `${attributeName}-buffer`});\n const {value, size, normalized} = attribute;\n bufferLayout.push({name, format: getVertexFormatFromAttribute(value, size, normalized)});\n }\n\n const vertexCount = geometry._calculateVertexCount(geometry.attributes, geometry.indices)\n\n return {attributes, bufferLayout, vertexCount};\n}\n"],"mappings":"AACA,SAAgBA,MAAM,EAAEC,GAAG,EAAEC,MAAM,EAAEC,4BAA4B,QAAO,eAAe;AAqBvF,OAAO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IAAI2B,IAAY,GAAGJ,aAAa;IAEhC,QAAQA,aAAa;MACnB,KAAK,UAAU;QAAEI,IAAI,GAAG,WAAW;QAAE;MACrC,KAAK,QAAQ;QAAEA,IAAI,GAAG,SAAS;QAAE;MACjC,KAAK,YAAY;QAAEA,IAAI,GAAG,WAAW;QAAE;IACzC;IACA3B,UAAU,CAAC2B,IAAI,CAAC,GAAGZ,MAAM,CAACO,YAAY,CAAC;MAACF,IAAI,EAAEI,SAAS,CAACH,KAAK;MAAE3B,EAAE,EAAG,GAAE6B,aAAc;IAAQ,CAAC,CAAC;IAC9F,MAAM;MAACF,KAAK;MAAEO,IAAI;MAAEC;IAAU,CAAC,GAAGL,SAAS;IAC3C3B,YAAY,CAACiC,IAAI,CAAC;MAACH,IAAI;MAAEI,MAAM,EAAEzC,4BAA4B,CAAC+B,KAAK,EAAEO,IAAI,EAAEC,UAAU;IAAC,CAAC,CAAC;EAC1F;EAEA,MAAM/B,WAAW,GAAGkB,QAAQ,CAACJ,qBAAqB,CAACI,QAAQ,CAAChB,UAAU,EAAEgB,QAAQ,CAACjB,OAAO,CAAC;EAEzF,OAAO;IAACC,UAAU;IAAEH,YAAY;IAAEC;EAAW,CAAC;AAChD"}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=gpu-table.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gpu-table.d.ts","sourceRoot":"","sources":["../../src/geometry/gpu-table.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=gpu-table.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gpu-table.js","names":[],"sources":["../../src/geometry/gpu-table.ts"],"sourcesContent":["/*\nexport function getAttributeLayoutsFromGeometry(geometry: Geometry) {\n const layouts: Record<string, {}> = {};\n let indices = geometry.indices;\n\n for (const [name, attribute] of Object.entries(geometry.attributes)) {\n const remappedName = mapAttributeName(name);\n\n if (attribute.constant) {\n throw new Error('constant attributes not supported');\n } else {\n const typedArray = attribute.value;\n // Create accessor by copying the attribute and removing `value``\n const accessor = {...attribute};\n delete accessor.value;\n buffers[remappedName] = [device.createBuffer(typedArray), accessor];\n\n inferAttributeAccessor(name, accessor);\n }\n }\n}\n\nexport class Table {\n length: number;\n // columns: Record<string, TypedArray> = {};\n}\n\nexport class GPUTable {\n length: number;\n columns: Record<string, Buffer> = {};\n}\n\nexport function convertTableToGPUTable(table: Table) {\n // for (const ) {}\n}\n\nexport function renameTableColumns(table: Table, map: (name: string) => string) {\n const newColumns = table.columns.reduce()\n table.clone();\n}\n*/\n"],"mappings":""}