@luma.gl/engine 9.0.0-alpha.16 → 9.0.0-alpha.19

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 (188) hide show
  1. package/dist/animation/key-frames.d.ts +1 -1
  2. package/dist/animation/key-frames.d.ts.map +1 -1
  3. package/dist/animation/key-frames.js +55 -54
  4. package/dist/animation/key-frames.js.map +1 -0
  5. package/dist/animation/timeline.d.ts +4 -4
  6. package/dist/animation/timeline.d.ts.map +1 -1
  7. package/dist/animation/timeline.js +101 -94
  8. package/dist/animation/timeline.js.map +1 -0
  9. package/dist/animation-loop/animation-loop.d.ts +4 -2
  10. package/dist/animation-loop/animation-loop.d.ts.map +1 -1
  11. package/dist/animation-loop/animation-loop.js +358 -414
  12. package/dist/animation-loop/animation-loop.js.map +1 -0
  13. package/dist/animation-loop/animation-props.d.ts +3 -1
  14. package/dist/animation-loop/animation-props.d.ts.map +1 -1
  15. package/dist/animation-loop/animation-props.js +1 -0
  16. package/dist/animation-loop/animation-props.js.map +1 -0
  17. package/dist/animation-loop/make-animation-loop.d.ts +1 -1
  18. package/dist/animation-loop/make-animation-loop.d.ts.map +1 -1
  19. package/dist/animation-loop/make-animation-loop.js +25 -26
  20. package/dist/animation-loop/make-animation-loop.js.map +1 -0
  21. package/dist/animation-loop/render-loop.js +5 -17
  22. package/dist/animation-loop/render-loop.js.map +1 -0
  23. package/dist/dist.dev.js +12517 -0
  24. package/dist/geometries/cone-geometry.d.ts +1 -1
  25. package/dist/geometries/cone-geometry.d.ts.map +1 -1
  26. package/dist/geometries/cone-geometry.js +18 -12
  27. package/dist/geometries/cone-geometry.js.map +1 -0
  28. package/dist/geometries/cube-geometry.d.ts +1 -1
  29. package/dist/geometries/cube-geometry.d.ts.map +1 -1
  30. package/dist/geometries/cube-geometry.js +60 -187
  31. package/dist/geometries/cube-geometry.js.map +1 -0
  32. package/dist/geometries/cylinder-geometry.d.ts +1 -1
  33. package/dist/geometries/cylinder-geometry.d.ts.map +1 -1
  34. package/dist/geometries/cylinder-geometry.js +15 -10
  35. package/dist/geometries/cylinder-geometry.js.map +1 -0
  36. package/dist/geometries/ico-sphere-geometry.d.ts +1 -1
  37. package/dist/geometries/ico-sphere-geometry.d.ts.map +1 -1
  38. package/dist/geometries/ico-sphere-geometry.js +160 -141
  39. package/dist/geometries/ico-sphere-geometry.js.map +1 -0
  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 +111 -93
  43. package/dist/geometries/plane-geometry.js.map +1 -0
  44. package/dist/geometries/sphere-geometry.d.ts +1 -1
  45. package/dist/geometries/sphere-geometry.d.ts.map +1 -1
  46. package/dist/geometries/sphere-geometry.js +95 -76
  47. package/dist/geometries/sphere-geometry.js.map +1 -0
  48. package/dist/geometries/truncated-cone-geometry.d.ts +1 -1
  49. package/dist/geometries/truncated-cone-geometry.d.ts.map +1 -1
  50. package/dist/geometries/truncated-cone-geometry.js +126 -105
  51. package/dist/geometries/truncated-cone-geometry.js.map +1 -0
  52. package/dist/geometry/geometry-table.d.ts +1 -1
  53. package/dist/geometry/geometry-table.d.ts.map +1 -1
  54. package/dist/geometry/geometry-table.js +1 -0
  55. package/dist/geometry/geometry-table.js.map +1 -0
  56. package/dist/geometry/geometry-utils.js +32 -22
  57. package/dist/geometry/geometry-utils.js.map +1 -0
  58. package/dist/geometry/geometry.d.ts +4 -4
  59. package/dist/geometry/geometry.d.ts.map +1 -1
  60. package/dist/geometry/geometry.js +109 -96
  61. package/dist/geometry/geometry.js.map +1 -0
  62. package/dist/geometry/primitive-utils.js +1 -30
  63. package/dist/geometry/primitive-utils.js.map +1 -0
  64. package/dist/index.cjs +2268 -0
  65. package/dist/index.d.ts +1 -0
  66. package/dist/index.d.ts.map +1 -1
  67. package/dist/index.js +17 -20
  68. package/dist/index.js.map +1 -0
  69. package/dist/lib/clip-space.d.ts +8 -0
  70. package/dist/lib/clip-space.d.ts.map +1 -1
  71. package/dist/lib/clip-space.js +32 -45
  72. package/dist/lib/clip-space.js.map +1 -0
  73. package/dist/lib/model-utils.js +28 -101
  74. package/dist/lib/model-utils.js.map +1 -0
  75. package/dist/lib/model.d.ts +1 -1
  76. package/dist/lib/model.d.ts.map +1 -1
  77. package/dist/lib/model.js +129 -121
  78. package/dist/lib/model.js.map +1 -0
  79. package/dist/lib/pipeline-factory.d.ts +3 -3
  80. package/dist/lib/pipeline-factory.d.ts.map +1 -1
  81. package/dist/lib/pipeline-factory.js +165 -136
  82. package/dist/lib/pipeline-factory.js.map +1 -0
  83. package/dist.min.js +295 -0
  84. package/package.json +22 -13
  85. package/src/animation/timeline.ts +1 -1
  86. package/src/animation-loop/animation-loop.ts +5 -5
  87. package/src/animation-loop/make-animation-loop.ts +2 -1
  88. package/src/geometry/geometry.ts +2 -2
  89. package/src/index.ts +1 -1
  90. package/src/lib/clip-space.ts +14 -11
  91. package/src/lib/pipeline-factory.ts +1 -1
  92. package/dist/bundle.d.ts +0 -2
  93. package/dist/bundle.d.ts.map +0 -1
  94. package/dist/bundle.js +0 -5
  95. package/dist/dist.min.js +0 -31
  96. package/dist/es5/animation/key-frames.js +0 -84
  97. package/dist/es5/animation/key-frames.js.map +0 -1
  98. package/dist/es5/animation/timeline.js +0 -183
  99. package/dist/es5/animation/timeline.js.map +0 -1
  100. package/dist/es5/animation-loop/animation-loop.js +0 -534
  101. package/dist/es5/animation-loop/animation-loop.js.map +0 -1
  102. package/dist/es5/animation-loop/animation-props.js +0 -2
  103. package/dist/es5/animation-loop/animation-props.js.map +0 -1
  104. package/dist/es5/animation-loop/make-animation-loop.js +0 -53
  105. package/dist/es5/animation-loop/make-animation-loop.js.map +0 -1
  106. package/dist/es5/animation-loop/render-loop.js +0 -39
  107. package/dist/es5/animation-loop/render-loop.js.map +0 -1
  108. package/dist/es5/bundle.js +0 -6
  109. package/dist/es5/bundle.js.map +0 -1
  110. package/dist/es5/geometries/cone-geometry.js +0 -43
  111. package/dist/es5/geometries/cone-geometry.js.map +0 -1
  112. package/dist/es5/geometries/cube-geometry.js +0 -84
  113. package/dist/es5/geometries/cube-geometry.js.map +0 -1
  114. package/dist/es5/geometries/cylinder-geometry.js +0 -39
  115. package/dist/es5/geometries/cylinder-geometry.js.map +0 -1
  116. package/dist/es5/geometries/ico-sphere-geometry.js +0 -185
  117. package/dist/es5/geometries/ico-sphere-geometry.js.map +0 -1
  118. package/dist/es5/geometries/plane-geometry.js +0 -137
  119. package/dist/es5/geometries/plane-geometry.js.map +0 -1
  120. package/dist/es5/geometries/sphere-geometry.js +0 -120
  121. package/dist/es5/geometries/sphere-geometry.js.map +0 -1
  122. package/dist/es5/geometries/truncated-cone-geometry.js +0 -160
  123. package/dist/es5/geometries/truncated-cone-geometry.js.map +0 -1
  124. package/dist/es5/geometry/geometry-table.js +0 -2
  125. package/dist/es5/geometry/geometry-table.js.map +0 -1
  126. package/dist/es5/geometry/geometry-utils.js +0 -39
  127. package/dist/es5/geometry/geometry-utils.js.map +0 -1
  128. package/dist/es5/geometry/geometry.js +0 -150
  129. package/dist/es5/geometry/geometry.js.map +0 -1
  130. package/dist/es5/geometry/primitive-utils.js +0 -2
  131. package/dist/es5/geometry/primitive-utils.js.map +0 -1
  132. package/dist/es5/index.js +0 -112
  133. package/dist/es5/index.js.map +0 -1
  134. package/dist/es5/lib/clip-space.js +0 -2
  135. package/dist/es5/lib/clip-space.js.map +0 -1
  136. package/dist/es5/lib/model-utils.js +0 -52
  137. package/dist/es5/lib/model-utils.js.map +0 -1
  138. package/dist/es5/lib/model.js +0 -173
  139. package/dist/es5/lib/model.js.map +0 -1
  140. package/dist/es5/lib/pipeline-factory.js +0 -244
  141. package/dist/es5/lib/pipeline-factory.js.map +0 -1
  142. package/dist/esm/animation/key-frames.js +0 -57
  143. package/dist/esm/animation/key-frames.js.map +0 -1
  144. package/dist/esm/animation/timeline.js +0 -113
  145. package/dist/esm/animation/timeline.js.map +0 -1
  146. package/dist/esm/animation-loop/animation-loop.js +0 -367
  147. package/dist/esm/animation-loop/animation-loop.js.map +0 -1
  148. package/dist/esm/animation-loop/animation-props.js +0 -2
  149. package/dist/esm/animation-loop/animation-props.js.map +0 -1
  150. package/dist/esm/animation-loop/make-animation-loop.js +0 -28
  151. package/dist/esm/animation-loop/make-animation-loop.js.map +0 -1
  152. package/dist/esm/animation-loop/render-loop.js +0 -7
  153. package/dist/esm/animation-loop/render-loop.js.map +0 -1
  154. package/dist/esm/bundle.js +0 -4
  155. package/dist/esm/bundle.js.map +0 -1
  156. package/dist/esm/geometries/cone-geometry.js +0 -21
  157. package/dist/esm/geometries/cone-geometry.js.map +0 -1
  158. package/dist/esm/geometries/cube-geometry.js +0 -67
  159. package/dist/esm/geometries/cube-geometry.js.map +0 -1
  160. package/dist/esm/geometries/cylinder-geometry.js +0 -18
  161. package/dist/esm/geometries/cylinder-geometry.js.map +0 -1
  162. package/dist/esm/geometries/ico-sphere-geometry.js +0 -170
  163. package/dist/esm/geometries/ico-sphere-geometry.js.map +0 -1
  164. package/dist/esm/geometries/plane-geometry.js +0 -119
  165. package/dist/esm/geometries/plane-geometry.js.map +0 -1
  166. package/dist/esm/geometries/sphere-geometry.js +0 -102
  167. package/dist/esm/geometries/sphere-geometry.js.map +0 -1
  168. package/dist/esm/geometries/truncated-cone-geometry.js +0 -136
  169. package/dist/esm/geometries/truncated-cone-geometry.js.map +0 -1
  170. package/dist/esm/geometry/geometry-table.js +0 -2
  171. package/dist/esm/geometry/geometry-table.js.map +0 -1
  172. package/dist/esm/geometry/geometry-utils.js +0 -37
  173. package/dist/esm/geometry/geometry-utils.js.map +0 -1
  174. package/dist/esm/geometry/geometry.js +0 -119
  175. package/dist/esm/geometry/geometry.js.map +0 -1
  176. package/dist/esm/geometry/primitive-utils.js +0 -2
  177. package/dist/esm/geometry/primitive-utils.js.map +0 -1
  178. package/dist/esm/index.js +0 -16
  179. package/dist/esm/index.js.map +0 -1
  180. package/dist/esm/lib/clip-space.js +0 -2
  181. package/dist/esm/lib/clip-space.js.map +0 -1
  182. package/dist/esm/lib/model-utils.js +0 -40
  183. package/dist/esm/lib/model-utils.js.map +0 -1
  184. package/dist/esm/lib/model.js +0 -146
  185. package/dist/esm/lib/model.js.map +0 -1
  186. package/dist/esm/lib/pipeline-factory.js +0 -180
  187. package/dist/esm/lib/pipeline-factory.js.map +0 -1
  188. package/src/bundle.ts +0 -4
@@ -1,106 +1,119 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
1
2
  import { uid, assert } from '@luma.gl/api';
2
3
  import GL from '@luma.gl/constants';
3
- class Geometry {
4
- constructor(props = {}) {
5
- this.userData = {};
6
- /** @deprecated */
7
- this.drawMode = GL.TRIANGLES;
8
- const { id = uid('geometry'), drawMode = GL.TRIANGLES, attributes = {}, indices = null, vertexCount = null } = props;
9
- this.id = id;
10
- this.drawMode = drawMode;
11
- this.topology = props.topology || convertToTopology(drawMode);
12
- if (indices) {
13
- // @ts-expect-error
14
- this.indices = ArrayBuffer.isView(indices) ? { value: indices, size: 1 } : indices;
15
- }
16
- // @ts-expect-error
17
- this.attributes = {};
18
- for (const [attributeName, attributeValue] of Object.entries(attributes)) {
19
- // Wrap "unwrapped" arrays and try to autodetect their type
20
- const attribute = ArrayBuffer.isView(attributeValue) ? { value: attributeValue } : attributeValue;
21
- assert(ArrayBuffer.isView(attribute.value), `${this._print(attributeName)}: must be typed array or object with value as typed array`);
22
- if ((attributeName === 'POSITION' || attributeName === 'positions') && !attribute.size) {
23
- attribute.size = 3;
24
- }
25
- // Move indices to separate field
26
- if (attributeName === 'indices') {
27
- assert(!this.indices);
28
- // @ts-expect-error
29
- this.indices = attribute;
30
- }
31
- else {
32
- this.attributes[attributeName] = attribute;
33
- }
34
- }
35
- // @ts-expect-error
36
- if (this.indices && this.indices.isIndexed !== undefined) {
37
- this.indices = Object.assign({}, this.indices);
38
- // @ts-expect-error
39
- delete this.indices.isIndexed;
40
- }
41
- this.vertexCount = vertexCount || this._calculateVertexCount(this.attributes, this.indices);
4
+ export default class Geometry {
5
+ constructor() {
6
+ let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7
+ _defineProperty(this, "id", void 0);
8
+ _defineProperty(this, "userData", {});
9
+ _defineProperty(this, "topology", void 0);
10
+ _defineProperty(this, "drawMode", GL.TRIANGLES);
11
+ _defineProperty(this, "vertexCount", void 0);
12
+ _defineProperty(this, "attributes", void 0);
13
+ _defineProperty(this, "indices", void 0);
14
+ const {
15
+ id = uid('geometry'),
16
+ drawMode = GL.TRIANGLES,
17
+ attributes = {},
18
+ indices = null,
19
+ vertexCount = null
20
+ } = props;
21
+ this.id = id;
22
+ this.drawMode = drawMode;
23
+ this.topology = props.topology || convertToTopology(drawMode);
24
+ if (indices) {
25
+ this.indices = ArrayBuffer.isView(indices) ? {
26
+ value: indices,
27
+ size: 1
28
+ } : indices;
42
29
  }
43
- /** @deprecated Use string topology constants instead */
44
- get mode() {
45
- return this.drawMode;
30
+ this.attributes = {};
31
+ for (const [attributeName, attributeValue] of Object.entries(attributes)) {
32
+ const attribute = ArrayBuffer.isView(attributeValue) ? {
33
+ value: attributeValue
34
+ } : attributeValue;
35
+ assert(ArrayBuffer.isView(attribute.value), "".concat(this._print(attributeName), ": must be typed array or object with value as typed array"));
36
+ if ((attributeName === 'POSITION' || attributeName === 'positions') && !attribute.size) {
37
+ attribute.size = 3;
38
+ }
39
+ if (attributeName === 'indices') {
40
+ assert(!this.indices);
41
+ this.indices = attribute;
42
+ } else {
43
+ this.attributes[attributeName] = attribute;
44
+ }
46
45
  }
47
- getVertexCount() {
48
- return this.vertexCount;
46
+ if (this.indices && this.indices.isIndexed !== undefined) {
47
+ this.indices = Object.assign({}, this.indices);
48
+ delete this.indices.isIndexed;
49
49
  }
50
- // Return an object with all attributes plus indices added as a field.
51
- getAttributes() {
52
- // @ts-expect-error Geometry types are a mess
53
- return this.indices ? { indices: this.indices, ...this.attributes } : this.attributes;
50
+ this.vertexCount = vertexCount || this._calculateVertexCount(this.attributes, this.indices);
51
+ }
52
+ get mode() {
53
+ return this.drawMode;
54
+ }
55
+ getVertexCount() {
56
+ return this.vertexCount;
57
+ }
58
+ getAttributes() {
59
+ return this.indices ? {
60
+ indices: this.indices,
61
+ ...this.attributes
62
+ } : this.attributes;
63
+ }
64
+ _print(attributeName) {
65
+ return "Geometry ".concat(this.id, " attribute ").concat(attributeName);
66
+ }
67
+ _setAttributes(attributes, indices) {
68
+ return this;
69
+ }
70
+ _calculateVertexCount(attributes, indices) {
71
+ if (indices) {
72
+ return indices.value.length;
54
73
  }
55
- // PRIVATE
56
- _print(attributeName) {
57
- return `Geometry ${this.id} attribute ${attributeName}`;
58
- }
59
- // GeometryAttribute
60
- // value: typed array
61
- // type: indices, vertices, uvs
62
- // size: elements per vertex
63
- // target: WebGL buffer type (string or constant)
64
- _setAttributes(attributes, indices) {
65
- return this;
66
- }
67
- _calculateVertexCount(attributes, indices) {
68
- if (indices) {
69
- return indices.value.length;
70
- }
71
- let vertexCount = Infinity;
72
- for (const attributeName in attributes) {
73
- const attribute = attributes[attributeName];
74
- const { value, size, constant } = attribute;
75
- if (!constant && value && size >= 1) {
76
- vertexCount = Math.min(vertexCount, value.length / size);
77
- }
78
- }
79
- assert(Number.isFinite(vertexCount));
80
- return vertexCount;
74
+ let vertexCount = Infinity;
75
+ for (const attributeName in attributes) {
76
+ const attribute = attributes[attributeName];
77
+ const {
78
+ value,
79
+ size,
80
+ constant
81
+ } = attribute;
82
+ if (!constant && value && size >= 1) {
83
+ vertexCount = Math.min(vertexCount, value.length / size);
84
+ }
81
85
  }
86
+ assert(Number.isFinite(vertexCount));
87
+ return vertexCount;
88
+ }
82
89
  }
83
- /** @deprecated */
84
- Geometry.DRAW_MODE = {
85
- POINTS: GL.POINTS,
86
- LINES: GL.LINES,
87
- LINE_LOOP: GL.LINE_LOOP,
88
- LINE_STRIP: GL.LINE_STRIP,
89
- TRIANGLES: GL.TRIANGLES,
90
- TRIANGLE_STRIP: GL.TRIANGLE_STRIP,
91
- TRIANGLE_FAN: GL.TRIANGLE_FAN // draw a connected group of triangles.
92
- };
93
- export default Geometry;
90
+ _defineProperty(Geometry, "DRAW_MODE", {
91
+ POINTS: GL.POINTS,
92
+ LINES: GL.LINES,
93
+ LINE_LOOP: GL.LINE_LOOP,
94
+ LINE_STRIP: GL.LINE_STRIP,
95
+ TRIANGLES: GL.TRIANGLES,
96
+ TRIANGLE_STRIP: GL.TRIANGLE_STRIP,
97
+ TRIANGLE_FAN: GL.TRIANGLE_FAN
98
+ });
94
99
  function convertToTopology(drawMode) {
95
- switch (drawMode) {
96
- case GL.POINTS: return 'point-list'; // draw single points.
97
- case GL.LINES: return 'line-list'; // draw lines. Each vertex connects to the one after it.
98
- case GL.LINE_STRIP: return 'line-strip'; // draw a connected group of line segments from the first vertex to the last
99
- case GL.TRIANGLES: return 'triangle-list'; // draw triangles. Each set of three vertices creates a separate triangle.
100
- case GL.TRIANGLE_STRIP: return 'triangle-strip'; // draw a connected group of triangles.
101
- case GL.TRIANGLE_FAN: return 'triangle-fan'; // draw a connected group of triangles.
102
- case GL.LINE_LOOP: return 'line-loop'; // draw lines. Each set of two vertices is treated as a separate line segment.
103
- default:
104
- throw new Error(String(drawMode));
105
- }
100
+ switch (drawMode) {
101
+ case GL.POINTS:
102
+ return 'point-list';
103
+ case GL.LINES:
104
+ return 'line-list';
105
+ case GL.LINE_STRIP:
106
+ return 'line-strip';
107
+ case GL.TRIANGLES:
108
+ return 'triangle-list';
109
+ case GL.TRIANGLE_STRIP:
110
+ return 'triangle-strip';
111
+ case GL.TRIANGLE_FAN:
112
+ return 'triangle-fan';
113
+ case GL.LINE_LOOP:
114
+ return 'line-loop';
115
+ default:
116
+ throw new Error(String(drawMode));
117
+ }
106
118
  }
119
+ //# sourceMappingURL=geometry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geometry.js","names":["uid","assert","GL","Geometry","constructor","props","arguments","length","undefined","_defineProperty","TRIANGLES","id","drawMode","attributes","indices","vertexCount","topology","convertToTopology","ArrayBuffer","isView","value","size","attributeName","attributeValue","Object","entries","attribute","concat","_print","isIndexed","assign","_calculateVertexCount","mode","getVertexCount","getAttributes","_setAttributes","Infinity","constant","Math","min","Number","isFinite","POINTS","LINES","LINE_LOOP","LINE_STRIP","TRIANGLE_STRIP","TRIANGLE_FAN","Error","String"],"sources":["../../src/geometry/geometry.ts"],"sourcesContent":["// luma.gl, MIT license\nimport type {PrimitiveTopology, 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 * @deprecated - use string constants instead\n */\nexport type GLTopology =\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 GeometryAttribute = {\n size?: number;\n value: TypedArray;\n [key: string]: any\n}\n\nexport type GeometryProps = {\n id?: string;\n attributes?: Record<string, GeometryAttribute | TypedArray>,\n indices?: GeometryAttribute | TypedArray;\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?: GLTopology;\n};\n\ntype GeometryAttributes = {\n POSITION: GeometryAttribute,\n NORMAL: GeometryAttribute,\n TEXCOORD_0: GeometryAttribute,\n COLOR_0?: GeometryAttribute,\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, unknown> = {};\n\n /** Determines how vertices are read from the 'vertex' attributes */\n topology?: PrimitiveTopology;\n /** @deprecated */\n readonly drawMode: GLTopology = GL.TRIANGLES;\n\n readonly vertexCount: number;\n readonly attributes: {\n POSITION: GeometryAttribute,\n NORMAL: GeometryAttribute,\n TEXCOORD_0: GeometryAttribute,\n COLOR_0?: GeometryAttribute,\n [key: string]: GeometryAttribute | undefined\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 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, attributeValue] of Object.entries(attributes)) {\n\n // Wrap \"unwrapped\" arrays and try to autodetect their type\n const attribute: GeometryAttribute = ArrayBuffer.isView(attributeValue) ? {value: attributeValue} : 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 // @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 this.indices = Object.assign({}, this.indices);\n // @ts-expect-error\n delete this.indices.isIndexed;\n }\n\n this.vertexCount = vertexCount || this._calculateVertexCount(this.attributes, this.indices);\n }\n\n /** @deprecated Use string topology constants instead */\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 // @ts-expect-error Geometry types are a mess\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 // GeometryAttribute\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: Record<string, GeometryAttribute>, indices: any): this {\n\n return this;\n }\n\n _calculateVertexCount(attributes: any, indices: any): 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: GLTopology): PrimitiveTopology {\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: return 'triangle-fan'; // draw a connected group of triangles.\n case GL.LINE_LOOP: return '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"],"mappings":";AAEA,SAAQA,GAAG,EAAEC,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AAO,eAAe;IACzC,KAAKR,EAAE,CAAC4C,cAAc;MAAE,OAAO,gBAAgB;IAE/C,KAAK5C,EAAE,CAAC6C,YAAY;MAAE,OAAO,cAAc;IAC3C,KAAK7C,EAAE,CAAC0C,SAAS;MAAE,OAAO,WAAW;IACrC;MACE,MAAM,IAAII,KAAK,CAACC,MAAM,CAACrC,QAAQ,CAAC,CAAC;EAAC;AAExC"}
@@ -1,31 +1,2 @@
1
- "use strict";
2
- /*
3
- import type {GeometryTable} from './geometry-table.js';
4
1
 
5
- export function unpackIndexedGeometry(geometry: GeometryTable): GeometryTable {
6
- const {indices, attributes} = geometry;
7
- if (!indices) {
8
- return geometry;
9
- }
10
-
11
- const vertexCount = indices.length;
12
- const unpackedAttributes = {};
13
-
14
- for (const [name, values] of Object.entries(attributes)) {
15
- const size = {POSITION: 3, NORMAL: 3, TEX_COORD0: 2}[name];
16
- const unpackedValues = new values.constructor(length * size);
17
- for (let x = 0; x < vertexCount; ++x) {
18
- const index = indices[x];
19
- for (let i = 0; i < size; i++) {
20
- unpackedValues[x * size + i] = values[index * size + i];
21
- }
22
- }
23
- unpackedAttributes[name] = unpackedValues;
24
- }
25
-
26
- return {
27
- length,
28
- attributes: unpackedAttributes
29
- };
30
- }
31
- */
2
+ //# sourceMappingURL=primitive-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"primitive-utils.js","names":[],"sources":["../../src/geometry/primitive-utils.ts"],"sourcesContent":["/*\nimport type {GeometryTable} from './geometry-table';\n\nexport function unpackIndexedGeometry(geometry: GeometryTable): GeometryTable {\n const {indices, attributes} = geometry;\n if (!indices) {\n return geometry;\n }\n\n const vertexCount = indices.length;\n const unpackedAttributes = {};\n\n for (const [name, values] of Object.entries(attributes)) {\n const size = {POSITION: 3, NORMAL: 3, TEX_COORD0: 2}[name];\n const unpackedValues = new values.constructor(length * size);\n for (let x = 0; x < vertexCount; ++x) {\n const index = indices[x];\n for (let i = 0; i < size; i++) {\n unpackedValues[x * size + i] = values[index * size + i];\n }\n }\n unpackedAttributes[name] = unpackedValues;\n }\n\n return {\n length,\n attributes: unpackedAttributes\n };\n}\n*/"],"mappings":""}