@luma.gl/engine 9.0.0-beta.1 → 9.0.0-beta.10

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 (154) hide show
  1. package/dist/animation/key-frames.js +54 -54
  2. package/dist/animation/timeline.d.ts.map +1 -1
  3. package/dist/animation/timeline.js +95 -100
  4. package/dist/animation-loop/animation-loop-template.d.ts +1 -1
  5. package/dist/animation-loop/animation-loop-template.d.ts.map +1 -1
  6. package/dist/animation-loop/animation-loop-template.js +19 -5
  7. package/dist/animation-loop/animation-loop.d.ts +2 -2
  8. package/dist/animation-loop/animation-loop.d.ts.map +1 -1
  9. package/dist/animation-loop/animation-loop.js +433 -356
  10. package/dist/animation-loop/animation-props.d.ts +2 -2
  11. package/dist/animation-loop/animation-props.d.ts.map +1 -1
  12. package/dist/animation-loop/animation-props.js +0 -1
  13. package/dist/animation-loop/make-animation-loop.d.ts +2 -2
  14. package/dist/animation-loop/make-animation-loop.d.ts.map +1 -1
  15. package/dist/animation-loop/make-animation-loop.js +28 -24
  16. package/dist/computation.d.ts +95 -0
  17. package/dist/computation.d.ts.map +1 -0
  18. package/dist/computation.js +248 -0
  19. package/dist/debug/copy-texture-to-image.d.ts.map +1 -1
  20. package/dist/debug/copy-texture-to-image.js +39 -42
  21. package/dist/debug/debug-framebuffer.d.ts.map +1 -1
  22. package/dist/debug/debug-framebuffer.js +43 -40
  23. package/dist/debug/debug-shader-layout.js +24 -25
  24. package/dist/debug/pixel-data-utils.d.ts.map +1 -1
  25. package/dist/debug/pixel-data-utils.js +34 -36
  26. package/dist/dist.dev.js +2538 -3027
  27. package/dist/dist.min.js +102 -0
  28. package/dist/geometries/cone-geometry.d.ts +1 -1
  29. package/dist/geometries/cone-geometry.d.ts.map +1 -1
  30. package/dist/geometries/cone-geometry.js +11 -17
  31. package/dist/geometries/cube-geometry.d.ts +1 -1
  32. package/dist/geometries/cube-geometry.d.ts.map +1 -1
  33. package/dist/geometries/cube-geometry.js +190 -61
  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 +9 -14
  37. package/dist/geometries/ico-sphere-geometry.d.ts +1 -1
  38. package/dist/geometries/ico-sphere-geometry.d.ts.map +1 -1
  39. package/dist/geometries/ico-sphere-geometry.js +141 -160
  40. package/dist/geometries/plane-geometry.d.ts +1 -1
  41. package/dist/geometries/plane-geometry.d.ts.map +1 -1
  42. package/dist/geometries/plane-geometry.js +92 -110
  43. package/dist/geometries/sphere-geometry.d.ts +1 -1
  44. package/dist/geometries/sphere-geometry.d.ts.map +1 -1
  45. package/dist/geometries/sphere-geometry.js +76 -95
  46. package/dist/geometries/truncated-cone-geometry.d.ts +1 -1
  47. package/dist/geometries/truncated-cone-geometry.d.ts.map +1 -1
  48. package/dist/geometries/truncated-cone-geometry.js +99 -117
  49. package/dist/geometry/geometry-table.d.ts.map +1 -1
  50. package/dist/geometry/geometry-table.js +3 -1
  51. package/dist/geometry/geometry-utils.js +35 -32
  52. package/dist/geometry/geometry.d.ts.map +1 -1
  53. package/dist/geometry/geometry.js +80 -71
  54. package/dist/geometry/gpu-geometry.d.ts +1 -1
  55. package/dist/geometry/gpu-geometry.d.ts.map +1 -1
  56. package/dist/geometry/gpu-geometry.js +79 -99
  57. package/dist/geometry/gpu-table.js +41 -1
  58. package/dist/index.cjs +725 -409
  59. package/dist/index.cjs.map +7 -0
  60. package/dist/index.d.ts +43 -40
  61. package/dist/index.d.ts.map +1 -1
  62. package/dist/index.js +6 -1
  63. package/dist/lib/clip-space.d.ts +2 -2
  64. package/dist/lib/clip-space.d.ts.map +1 -1
  65. package/dist/lib/clip-space.js +28 -34
  66. package/dist/lib/pipeline-factory.d.ts +13 -14
  67. package/dist/lib/pipeline-factory.d.ts.map +1 -1
  68. package/dist/lib/pipeline-factory.js +86 -85
  69. package/dist/lib/shader-factory.d.ts +17 -0
  70. package/dist/lib/shader-factory.d.ts.map +1 -0
  71. package/dist/lib/shader-factory.js +46 -0
  72. package/dist/model/model.d.ts +59 -46
  73. package/dist/model/model.d.ts.map +1 -1
  74. package/dist/model/model.js +635 -411
  75. package/dist/scenegraph/group-node.d.ts +1 -1
  76. package/dist/scenegraph/group-node.d.ts.map +1 -1
  77. package/dist/scenegraph/group-node.js +73 -83
  78. package/dist/scenegraph/model-node.d.ts +3 -3
  79. package/dist/scenegraph/model-node.d.ts.map +1 -1
  80. package/dist/scenegraph/model-node.js +31 -24
  81. package/dist/scenegraph/scenegraph-node.d.ts.map +1 -1
  82. package/dist/scenegraph/scenegraph-node.js +136 -124
  83. package/dist/shader-inputs.d.ts.map +1 -1
  84. package/dist/shader-inputs.js +99 -58
  85. package/dist/transform/buffer-transform.d.ts +1 -1
  86. package/dist/transform/buffer-transform.d.ts.map +1 -1
  87. package/dist/transform/buffer-transform.js +65 -57
  88. package/dist/transform/texture-transform.d.ts +1 -1
  89. package/dist/transform/texture-transform.d.ts.map +1 -1
  90. package/dist/transform/texture-transform.js +109 -114
  91. package/dist.min.js +3 -271
  92. package/package.json +10 -9
  93. package/src/animation/timeline.ts +20 -20
  94. package/src/animation-loop/animation-loop-template.ts +10 -8
  95. package/src/animation-loop/animation-loop.ts +20 -10
  96. package/src/animation-loop/animation-props.ts +1 -1
  97. package/src/animation-loop/make-animation-loop.ts +17 -8
  98. package/src/computation.ts +346 -0
  99. package/src/debug/copy-texture-to-image.ts +9 -11
  100. package/src/debug/debug-framebuffer.ts +16 -3
  101. package/src/debug/debug-shader-layout.ts +1 -1
  102. package/src/debug/pixel-data-utils.ts +3 -6
  103. package/src/geometries/cube-geometry.ts +17 -13
  104. package/src/geometries/ico-sphere-geometry.ts +1 -1
  105. package/src/geometries/plane-geometry.ts +1 -1
  106. package/src/geometries/sphere-geometry.ts +1 -1
  107. package/src/geometries/truncated-cone-geometry.ts +2 -1
  108. package/src/geometry/geometry-table.ts +9 -6
  109. package/src/geometry/geometry-utils.ts +16 -0
  110. package/src/geometry/geometry.ts +9 -6
  111. package/src/geometry/gpu-geometry.ts +18 -11
  112. package/src/index.ts +4 -1
  113. package/src/lib/clip-space.ts +16 -19
  114. package/src/lib/pipeline-factory.ts +71 -64
  115. package/src/lib/shader-factory.ts +57 -0
  116. package/src/model/model.ts +255 -146
  117. package/src/scenegraph/group-node.ts +14 -10
  118. package/src/scenegraph/model-node.ts +2 -2
  119. package/src/scenegraph/scenegraph-node.ts +2 -2
  120. package/src/shader-inputs.ts +19 -12
  121. package/src/transform/buffer-transform.ts +16 -8
  122. package/src/transform/texture-transform.ts +14 -15
  123. package/dist/animation/key-frames.js.map +0 -1
  124. package/dist/animation/timeline.js.map +0 -1
  125. package/dist/animation-loop/animation-loop-template.js.map +0 -1
  126. package/dist/animation-loop/animation-loop.js.map +0 -1
  127. package/dist/animation-loop/animation-props.js.map +0 -1
  128. package/dist/animation-loop/make-animation-loop.js.map +0 -1
  129. package/dist/debug/copy-texture-to-image.js.map +0 -1
  130. package/dist/debug/debug-framebuffer.js.map +0 -1
  131. package/dist/debug/debug-shader-layout.js.map +0 -1
  132. package/dist/debug/pixel-data-utils.js.map +0 -1
  133. package/dist/geometries/cone-geometry.js.map +0 -1
  134. package/dist/geometries/cube-geometry.js.map +0 -1
  135. package/dist/geometries/cylinder-geometry.js.map +0 -1
  136. package/dist/geometries/ico-sphere-geometry.js.map +0 -1
  137. package/dist/geometries/plane-geometry.js.map +0 -1
  138. package/dist/geometries/sphere-geometry.js.map +0 -1
  139. package/dist/geometries/truncated-cone-geometry.js.map +0 -1
  140. package/dist/geometry/geometry-table.js.map +0 -1
  141. package/dist/geometry/geometry-utils.js.map +0 -1
  142. package/dist/geometry/geometry.js.map +0 -1
  143. package/dist/geometry/gpu-geometry.js.map +0 -1
  144. package/dist/geometry/gpu-table.js.map +0 -1
  145. package/dist/index.js.map +0 -1
  146. package/dist/lib/clip-space.js.map +0 -1
  147. package/dist/lib/pipeline-factory.js.map +0 -1
  148. package/dist/model/model.js.map +0 -1
  149. package/dist/scenegraph/group-node.js.map +0 -1
  150. package/dist/scenegraph/model-node.js.map +0 -1
  151. package/dist/scenegraph/scenegraph-node.js.map +0 -1
  152. package/dist/shader-inputs.js.map +0 -1
  153. package/dist/transform/buffer-transform.js.map +0 -1
  154. package/dist/transform/texture-transform.js.map +0 -1
@@ -1,2 +1,4 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
1
4
  export {};
2
- //# sourceMappingURL=geometry-table.js.map
@@ -1,37 +1,40 @@
1
+ // import type {Geometry} from './geometry';
1
2
  export function unpackIndexedGeometry(geometry) {
2
- const {
3
- indices,
4
- attributes
5
- } = geometry;
6
- if (!indices) {
7
- return geometry;
8
- }
9
- const vertexCount = indices.value.length;
10
- const unpackedAttributes = {};
11
- for (const attributeName in attributes) {
12
- const attribute = attributes[attributeName];
13
- const {
14
- constant,
15
- value,
16
- size
17
- } = attribute;
18
- if (constant || !size) {
19
- continue;
3
+ const { indices, attributes } = geometry;
4
+ if (!indices) {
5
+ return geometry;
20
6
  }
21
- const unpackedValue = new value.constructor(vertexCount * size);
22
- for (let x = 0; x < vertexCount; ++x) {
23
- const index = indices.value[x];
24
- for (let i = 0; i < size; i++) {
25
- unpackedValue[x * size + i] = value[index * size + i];
26
- }
7
+ const vertexCount = indices.value.length;
8
+ const unpackedAttributes = {};
9
+ for (const attributeName in attributes) {
10
+ const attribute = attributes[attributeName];
11
+ const { constant, value, size } = attribute;
12
+ if (constant || !size) {
13
+ continue; // eslint-disable-line
14
+ }
15
+ const unpackedValue = new value.constructor(vertexCount * size);
16
+ for (let x = 0; x < vertexCount; ++x) {
17
+ const index = indices.value[x];
18
+ for (let i = 0; i < size; i++) {
19
+ unpackedValue[x * size + i] = value[index * size + i];
20
+ }
21
+ }
22
+ unpackedAttributes[attributeName] = { size, value: unpackedValue };
27
23
  }
28
- unpackedAttributes[attributeName] = {
29
- size,
30
- value: unpackedValue
24
+ return {
25
+ attributes: Object.assign({}, attributes, unpackedAttributes)
31
26
  };
32
- }
33
- return {
34
- attributes: Object.assign({}, attributes, unpackedAttributes)
35
- };
36
27
  }
37
- //# sourceMappingURL=geometry-utils.js.map
28
+ // export function calculateVertexNormals(positions: Float32Array): Uint8Array {
29
+ // let normals = new Uint8Array(positions.length / 3);
30
+ // for (let i = 0; i < positions.length; i++) {
31
+ // const vec1 = new Vector3(positions.subarray(i * 3, i + 0, i + 3));
32
+ // const vec2 = new Vector3(positions.subarray(i + 3, i + 6));
33
+ // const vec3 = new Vector3(positions.subarray(i + 6, i + 9));
34
+ // const normal = new Vector3(vec1).cross(vec2).normalize();
35
+ // normals.set(normal[0], i + 4);
36
+ // normals.set(normal[1], i + 4 + 1);
37
+ // normals.set(normal[2], i + 2);
38
+ // }
39
+ // const normal = new Vector3(vec1).cross(vec2).normalize();
40
+ // }
@@ -1 +1 @@
1
- {"version":3,"file":"geometry.d.ts","sourceRoot":"","sources":["../../src/geometry/geometry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,iBAAiB,EAAE,UAAU,EAAC,MAAM,eAAe,CAAC;AAGjE,MAAM,MAAM,aAAa,GAAG;IAC1B,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,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,GAAG,UAAU,CAAC,CAAC;IAC5D,OAAO,CAAC,EAAE,iBAAiB,GAAG,UAAU,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,MAAM,EAAE,iBAAiB,CAAC;IAC1B,UAAU,EAAE,iBAAiB,CAAC;IAC9B,OAAO,CAAC,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UAAU,EAAE;QACnB,QAAQ,EAAE,iBAAiB,CAAC;QAC5B,MAAM,EAAE,iBAAiB,CAAC;QAC1B,UAAU,EAAE,iBAAiB,CAAC;QAC9B,OAAO,CAAC,EAAE,iBAAiB,CAAC;QAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS,CAAC;KAC9C,CAAC;IAEF,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAM;gBAE3B,KAAK,EAAE,aAAa;IA6ChC,cAAc,IAAI,MAAM;IAIxB;;;OAGG;IACH,aAAa,IAAI,kBAAkB;IAMnC,MAAM,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM;IAIrC;;;;;;;;;;OAUG;IACH,cAAc,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,EAAE,OAAO,EAAE,GAAG,GAAG,IAAI;IAIjF,qBAAqB,CAAC,UAAU,EAAE,kBAAkB,EAAE,OAAO,EAAE,iBAAiB,GAAG,MAAM;CAe1F"}
@@ -1,79 +1,88 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
1
4
  import { uid, assert } from '@luma.gl/core';
2
5
  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 = {};
10
- const {
11
- attributes = {},
12
- indices = null,
13
- vertexCount = null
14
- } = props;
15
- this.id = props.id || uid('geometry');
16
- this.topology = props.topology;
17
- if (indices) {
18
- this.indices = ArrayBuffer.isView(indices) ? {
19
- value: indices,
20
- size: 1
21
- } : indices;
6
+ id;
7
+ /** Determines how vertices are read from the 'vertex' attributes */
8
+ topology;
9
+ vertexCount;
10
+ indices;
11
+ attributes;
12
+ userData = {};
13
+ constructor(props) {
14
+ const { attributes = {}, indices = null, vertexCount = null } = props;
15
+ this.id = props.id || uid('geometry');
16
+ this.topology = props.topology;
17
+ if (indices) {
18
+ this.indices = ArrayBuffer.isView(indices) ? { value: indices, size: 1 } : indices;
19
+ }
20
+ // @ts-expect-error
21
+ this.attributes = {};
22
+ for (const [attributeName, attributeValue] of Object.entries(attributes)) {
23
+ // Wrap "unwrapped" arrays and try to autodetect their type
24
+ const attribute = ArrayBuffer.isView(attributeValue)
25
+ ? { value: attributeValue }
26
+ : attributeValue;
27
+ assert(ArrayBuffer.isView(attribute.value), `${this._print(attributeName)}: must be typed array or object with value as typed array`);
28
+ if ((attributeName === 'POSITION' || attributeName === 'positions') && !attribute.size) {
29
+ attribute.size = 3;
30
+ }
31
+ // Move indices to separate field
32
+ if (attributeName === 'indices') {
33
+ assert(!this.indices);
34
+ this.indices = attribute;
35
+ }
36
+ else {
37
+ this.attributes[attributeName] = attribute;
38
+ }
39
+ }
40
+ if (this.indices && this.indices.isIndexed !== undefined) {
41
+ this.indices = Object.assign({}, this.indices);
42
+ delete this.indices.isIndexed;
43
+ }
44
+ this.vertexCount = vertexCount || this._calculateVertexCount(this.attributes, this.indices);
22
45
  }
23
- this.attributes = {};
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`);
29
- if ((attributeName === 'POSITION' || attributeName === 'positions') && !attribute.size) {
30
- attribute.size = 3;
31
- }
32
- if (attributeName === 'indices') {
33
- assert(!this.indices);
34
- this.indices = attribute;
35
- } else {
36
- this.attributes[attributeName] = attribute;
37
- }
46
+ getVertexCount() {
47
+ return this.vertexCount;
38
48
  }
39
- if (this.indices && this.indices.isIndexed !== undefined) {
40
- this.indices = Object.assign({}, this.indices);
41
- delete this.indices.isIndexed;
49
+ /**
50
+ * Return an object with all attributes plus indices added as a field.
51
+ * TODO Geometry types are a mess
52
+ */
53
+ getAttributes() {
54
+ return this.indices ? { indices: this.indices, ...this.attributes } : this.attributes;
42
55
  }
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) {
58
- return this;
59
- }
60
- _calculateVertexCount(attributes, indices) {
61
- if (indices) {
62
- return indices.value.length;
56
+ // PRIVATE
57
+ _print(attributeName) {
58
+ return `Geometry ${this.id} attribute ${attributeName}`;
63
59
  }
64
- let vertexCount = Infinity;
65
- for (const attribute of Object.values(attributes)) {
66
- const {
67
- value,
68
- size,
69
- constant
70
- } = attribute;
71
- if (!constant && value && size >= 1) {
72
- vertexCount = Math.min(vertexCount, value.length / size);
73
- }
60
+ /**
61
+ * GeometryAttribute
62
+ * value: typed array
63
+ * type: indices, vertices, uvs
64
+ * size: elements per vertex
65
+ * target: WebGL buffer type (string or constant)
66
+ *
67
+ * @param attributes
68
+ * @param indices
69
+ * @returns
70
+ */
71
+ _setAttributes(attributes, indices) {
72
+ return this;
73
+ }
74
+ _calculateVertexCount(attributes, indices) {
75
+ if (indices) {
76
+ return indices.value.length;
77
+ }
78
+ let vertexCount = Infinity;
79
+ for (const attribute of Object.values(attributes)) {
80
+ const { value, size, constant } = attribute;
81
+ if (!constant && value && size >= 1) {
82
+ vertexCount = Math.min(vertexCount, value.length / size);
83
+ }
84
+ }
85
+ assert(Number.isFinite(vertexCount));
86
+ return vertexCount;
74
87
  }
75
- assert(Number.isFinite(vertexCount));
76
- return vertexCount;
77
- }
78
88
  }
79
- //# sourceMappingURL=geometry.js.map
@@ -1,6 +1,6 @@
1
1
  import type { PrimitiveTopology, BufferLayout } from '@luma.gl/core';
2
2
  import { Device, Buffer } from '@luma.gl/core';
3
- import type { Geometry } from '../geometry/geometry';
3
+ import type { Geometry } from "../geometry/geometry.js";
4
4
  export type GPUGeometryProps = {
5
5
  id?: string;
6
6
  /** Determines how vertices are read from the 'vertex' attributes */
@@ -1 +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;IA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- 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);
3
+ id;
4
+ userData = {};
5
+ /** Determines how vertices are read from the 'vertex' attributes */
6
+ topology;
7
+ bufferLayout = [];
8
+ vertexCount;
9
+ indices;
10
+ attributes;
11
+ constructor(props) {
12
+ this.id = props.id || uid('geometry');
13
+ this.topology = props.topology;
14
+ this.indices = props.indices || null;
15
+ this.attributes = props.attributes;
16
+ this.vertexCount = props.vertexCount;
17
+ this.bufferLayout = props.bufferLayout || [];
18
+ if (this.indices) {
19
+ assert(this.indices.usage === Buffer.INDEX);
20
+ }
21
+ }
22
+ destroy() {
23
+ this.indices?.destroy();
24
+ for (const attribute of Object.values(this.attributes)) {
25
+ attribute.destroy();
26
+ }
27
+ }
28
+ getVertexCount() {
29
+ return this.vertexCount;
30
+ }
31
+ getAttributes() {
32
+ return this.attributes;
33
+ }
34
+ getIndexes() {
35
+ return this.indices;
36
+ }
37
+ _calculateVertexCount(positions) {
38
+ // Assume that positions is a fully packed float32x3 buffer
39
+ const vertexCount = positions.byteLength / 12;
40
+ return vertexCount;
19
41
  }
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
42
  }
43
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
- });
44
+ if (geometry instanceof GPUGeometry) {
45
+ return geometry;
46
+ }
47
+ const indices = getIndexBufferFromGeometry(device, geometry);
48
+ const { attributes, bufferLayout } = getAttributeBuffersFromGeometry(device, geometry);
49
+ return new GPUGeometry({
50
+ topology: geometry.topology || 'triangle-list',
51
+ bufferLayout,
52
+ vertexCount: geometry.vertexCount,
53
+ indices,
54
+ attributes
55
+ });
59
56
  }
60
57
  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
- });
58
+ if (!geometry.indices) {
59
+ return undefined;
60
+ }
61
+ const data = geometry.indices.value;
62
+ return device.createBuffer({ usage: Buffer.INDEX, data });
69
63
  }
70
64
  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
- case 'COLOR_0':
86
- name = 'colors';
87
- break;
65
+ const bufferLayout = [];
66
+ const attributes = {};
67
+ for (const [attributeName, attribute] of Object.entries(geometry.attributes)) {
68
+ let name = attributeName;
69
+ // TODO Map some GLTF attribute names (is this still needed?)
70
+ switch (attributeName) {
71
+ case 'POSITION':
72
+ name = 'positions';
73
+ break;
74
+ case 'NORMAL':
75
+ name = 'normals';
76
+ break;
77
+ case 'TEXCOORD_0':
78
+ name = 'texCoords';
79
+ break;
80
+ case 'COLOR_0':
81
+ name = 'colors';
82
+ break;
83
+ }
84
+ attributes[name] = device.createBuffer({ data: attribute.value, id: `${attributeName}-buffer` });
85
+ const { value, size, normalized } = attribute;
86
+ bufferLayout.push({ name, format: getVertexFormatFromAttribute(value, size, normalized) });
88
87
  }
89
- attributes[name] = device.createBuffer({
90
- data: attribute.value,
91
- id: `${attributeName}-buffer`
92
- });
93
- const {
94
- value,
95
- size,
96
- normalized
97
- } = attribute;
98
- bufferLayout.push({
99
- name,
100
- format: getVertexFormatFromAttribute(value, size, normalized)
101
- });
102
- }
103
- const vertexCount = geometry._calculateVertexCount(geometry.attributes, geometry.indices);
104
- return {
105
- attributes,
106
- bufferLayout,
107
- vertexCount
108
- };
88
+ const vertexCount = geometry._calculateVertexCount(geometry.attributes, geometry.indices);
89
+ return { attributes, bufferLayout, vertexCount };
109
90
  }
110
- //# sourceMappingURL=gpu-geometry.js.map
@@ -1,2 +1,42 @@
1
+ "use strict";
2
+ /*
3
+ export function getAttributeLayoutsFromGeometry(geometry: Geometry) {
4
+ const layouts: Record<string, {}> = {};
5
+ let indices = geometry.indices;
1
6
 
2
- //# sourceMappingURL=gpu-table.js.map
7
+ for (const [name, attribute] of Object.entries(geometry.attributes)) {
8
+ const remappedName = mapAttributeName(name);
9
+
10
+ if (attribute.constant) {
11
+ throw new Error('constant attributes not supported');
12
+ } else {
13
+ const typedArray = attribute.value;
14
+ // Create accessor by copying the attribute and removing `value``
15
+ const accessor = {...attribute};
16
+ delete accessor.value;
17
+ buffers[remappedName] = [device.createBuffer(typedArray), accessor];
18
+
19
+ inferAttributeAccessor(name, accessor);
20
+ }
21
+ }
22
+ }
23
+
24
+ export class Table {
25
+ length: number;
26
+ // columns: Record<string, TypedArray> = {};
27
+ }
28
+
29
+ export class GPUTable {
30
+ length: number;
31
+ columns: Record<string, Buffer> = {};
32
+ }
33
+
34
+ export function convertTableToGPUTable(table: Table) {
35
+ // for (const ) {}
36
+ }
37
+
38
+ export function renameTableColumns(table: Table, map: (name: string) => string) {
39
+ const newColumns = table.columns.reduce()
40
+ table.clone();
41
+ }
42
+ */