@luma.gl/engine 10.0.0-alpha.3 → 10.0.0-alpha.4

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 (86) hide show
  1. package/dist/dist.dev.js +695 -1317
  2. package/dist/dist.min.js +31 -31
  3. package/dist/geometry/edge-geometry.d.ts +3 -2
  4. package/dist/geometry/edge-geometry.d.ts.map +1 -1
  5. package/dist/geometry/edge-geometry.js.map +1 -1
  6. package/dist/geometry/geometry-primitives.d.ts +54 -0
  7. package/dist/geometry/geometry-primitives.d.ts.map +1 -0
  8. package/dist/geometry/geometry-primitives.js +153 -0
  9. package/dist/geometry/geometry-primitives.js.map +1 -0
  10. package/dist/geometry/geometry-utils.d.ts +7 -15
  11. package/dist/geometry/geometry-utils.d.ts.map +1 -1
  12. package/dist/geometry/geometry-utils.js +9 -55
  13. package/dist/geometry/geometry-utils.js.map +1 -1
  14. package/dist/geometry/geometry.d.ts +9 -69
  15. package/dist/geometry/geometry.d.ts.map +1 -1
  16. package/dist/geometry/geometry.js +27 -93
  17. package/dist/geometry/geometry.js.map +1 -1
  18. package/dist/geometry/gpu-geometry.d.ts +4 -2
  19. package/dist/geometry/gpu-geometry.d.ts.map +1 -1
  20. package/dist/geometry/gpu-geometry.js +3 -3
  21. package/dist/geometry/gpu-geometry.js.map +1 -1
  22. package/dist/index.cjs +241 -1301
  23. package/dist/index.cjs.map +3 -3
  24. package/dist/index.d.ts +14 -14
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +7 -7
  27. package/dist/index.js.map +1 -1
  28. package/dist/model/model.d.ts +1 -1
  29. package/dist/model/model.d.ts.map +1 -1
  30. package/dist/models/clip-space.d.ts +4 -1
  31. package/dist/models/clip-space.d.ts.map +1 -1
  32. package/dist/models/clip-space.js +16 -13
  33. package/dist/models/clip-space.js.map +1 -1
  34. package/dist/models/directional-light-model.js +1 -1
  35. package/dist/models/directional-light-model.js.map +1 -1
  36. package/dist/models/point-light-model.js +1 -1
  37. package/dist/models/point-light-model.js.map +1 -1
  38. package/dist/models/spot-light-model.js +1 -1
  39. package/dist/models/spot-light-model.js.map +1 -1
  40. package/package.json +7 -6
  41. package/src/geometry/edge-geometry.ts +7 -3
  42. package/src/geometry/geometry-primitives.ts +215 -0
  43. package/src/geometry/geometry-utils.ts +16 -71
  44. package/src/geometry/geometry.ts +36 -163
  45. package/src/geometry/gpu-geometry.ts +9 -4
  46. package/src/index.ts +14 -14
  47. package/src/model/model.ts +1 -1
  48. package/src/models/clip-space.ts +21 -14
  49. package/src/models/directional-light-model.ts +1 -1
  50. package/src/models/point-light-model.ts +1 -1
  51. package/src/models/spot-light-model.ts +1 -1
  52. package/dist/geometries/cone-geometry.d.ts +0 -12
  53. package/dist/geometries/cone-geometry.d.ts.map +0 -1
  54. package/dist/geometries/cone-geometry.js +0 -19
  55. package/dist/geometries/cone-geometry.js.map +0 -1
  56. package/dist/geometries/cube-geometry.d.ts +0 -14
  57. package/dist/geometries/cube-geometry.d.ts.map +0 -1
  58. package/dist/geometries/cube-geometry.js +0 -222
  59. package/dist/geometries/cube-geometry.js.map +0 -1
  60. package/dist/geometries/cylinder-geometry.d.ts +0 -11
  61. package/dist/geometries/cylinder-geometry.d.ts.map +0 -1
  62. package/dist/geometries/cylinder-geometry.js +0 -17
  63. package/dist/geometries/cylinder-geometry.js.map +0 -1
  64. package/dist/geometries/ico-sphere-geometry.d.ts +0 -11
  65. package/dist/geometries/ico-sphere-geometry.d.ts.map +0 -1
  66. package/dist/geometries/ico-sphere-geometry.js +0 -158
  67. package/dist/geometries/ico-sphere-geometry.js.map +0 -1
  68. package/dist/geometries/plane-geometry.d.ts +0 -20
  69. package/dist/geometries/plane-geometry.d.ts.map +0 -1
  70. package/dist/geometries/plane-geometry.js +0 -106
  71. package/dist/geometries/plane-geometry.js.map +0 -1
  72. package/dist/geometries/sphere-geometry.d.ts +0 -12
  73. package/dist/geometries/sphere-geometry.d.ts.map +0 -1
  74. package/dist/geometries/sphere-geometry.js +0 -88
  75. package/dist/geometries/sphere-geometry.js.map +0 -1
  76. package/dist/geometries/truncated-cone-geometry.d.ts +0 -23
  77. package/dist/geometries/truncated-cone-geometry.d.ts.map +0 -1
  78. package/dist/geometries/truncated-cone-geometry.js +0 -112
  79. package/dist/geometries/truncated-cone-geometry.js.map +0 -1
  80. package/src/geometries/cone-geometry.ts +0 -31
  81. package/src/geometries/cube-geometry.ts +0 -258
  82. package/src/geometries/cylinder-geometry.ts +0 -28
  83. package/src/geometries/ico-sphere-geometry.ts +0 -193
  84. package/src/geometries/plane-geometry.ts +0 -142
  85. package/src/geometries/sphere-geometry.ts +0 -113
  86. package/src/geometries/truncated-cone-geometry.ts +0 -145
@@ -2,9 +2,11 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
- import type {VertexFormat} from '@luma.gl/core';
5
+ import type {BufferLayout, VertexFormat} from '@luma.gl/core';
6
6
  import {vertexFormatDecoder} from '@luma.gl/core';
7
7
  import type {TypedArray} from '@math.gl/core';
8
+ import type {Geometry as MathGeometry} from '@math.gl/geometry';
9
+ export {unpackIndexedGeometry} from '@math.gl/geometry';
8
10
  import {Geometry, getGeometryShaderAttributeName, type GeometryAttribute} from './geometry';
9
11
 
10
12
  type TypedArrayConstructor = {
@@ -13,11 +15,6 @@ type TypedArrayConstructor = {
13
15
  readonly BYTES_PER_ELEMENT: number;
14
16
  };
15
17
 
16
- type GeometryLike = {
17
- indices?: GeometryAttribute;
18
- attributes: Record<string, GeometryAttribute | undefined>;
19
- };
20
-
21
18
  /** Options for {@link makeInterleavedGeometry}. */
22
19
  export type MakeInterleavedGeometryOptions = {
23
20
  /** Name of the packed geometry buffer. Defaults to `geometry`. */
@@ -44,48 +41,6 @@ type InterleavedAttribute = {
44
41
  byteLength: number;
45
42
  };
46
43
 
47
- /**
48
- * Expands indexed geometry attributes into non-indexed attributes.
49
- *
50
- * The returned object keeps the original attribute keys and replaces each non-constant attribute
51
- * with data expanded through the index buffer. The `indices` field is intentionally omitted from
52
- * the returned geometry-like object.
53
- */
54
- export function unpackIndexedGeometry<T extends GeometryLike>(geometry: T): GeometryLike {
55
- const {indices, attributes} = geometry;
56
- if (!indices) {
57
- return geometry;
58
- }
59
-
60
- const vertexCount = indices.value.length;
61
- const unpackedAttributes: Record<string, GeometryAttribute> = {};
62
-
63
- for (const attributeName in attributes) {
64
- const attribute = attributes[attributeName];
65
- if (!attribute) {
66
- continue; // eslint-disable-line
67
- }
68
- const {value, size} = attribute;
69
- const constant = attribute['constant'];
70
- if (constant || !size) {
71
- continue; // eslint-disable-line
72
- }
73
- const ArrayType = value.constructor as TypedArrayConstructor;
74
- const unpackedValue = new ArrayType(vertexCount * size);
75
- for (let x = 0; x < vertexCount; ++x) {
76
- const index = indices.value[x];
77
- for (let i = 0; i < size; i++) {
78
- unpackedValue[x * size + i] = value[index * size + i];
79
- }
80
- }
81
- unpackedAttributes[attributeName] = {size, value: unpackedValue};
82
- }
83
-
84
- return {
85
- attributes: Object.assign({}, attributes, unpackedAttributes)
86
- };
87
- }
88
-
89
44
  /**
90
45
  * Packs a CPU {@link Geometry} into one interleaved vertex buffer.
91
46
  *
@@ -95,7 +50,7 @@ export function unpackIndexedGeometry<T extends GeometryLike>(geometry: T): Geom
95
50
  * idempotent and returns the original instance.
96
51
  */
97
52
  export function makeInterleavedGeometry(
98
- geometry: Geometry,
53
+ geometry: MathGeometry & {bufferLayout?: BufferLayout[]},
99
54
  options: MakeInterleavedGeometryOptions = {}
100
55
  ): Geometry {
101
56
  const bufferName = options.bufferName || 'geometry';
@@ -183,8 +138,11 @@ export function makeInterleavedGeometry(
183
138
  });
184
139
  }
185
140
 
186
- function isInterleavedGeometry(geometry: Geometry, bufferName: string): boolean {
187
- if (geometry.bufferLayout.length !== 1) {
141
+ function isInterleavedGeometry(
142
+ geometry: MathGeometry & {bufferLayout?: BufferLayout[]},
143
+ bufferName: string
144
+ ): geometry is Geometry {
145
+ if (geometry.bufferLayout?.length !== 1) {
188
146
  return false;
189
147
  }
190
148
 
@@ -197,13 +155,16 @@ function isInterleavedGeometry(geometry: Geometry, bufferName: string): boolean
197
155
  }
198
156
 
199
157
  function getInterleavedSourceAttributes(
200
- geometry: Geometry,
158
+ geometry: MathGeometry,
201
159
  attributeNames?: string[]
202
160
  ): Array<[string, GeometryAttribute | undefined]> {
203
- if (attributeNames) {
204
- return attributeNames.map(attributeName => [attributeName, geometry.attributes[attributeName]]);
161
+ const attributes = new Map<string, [string, GeometryAttribute]>();
162
+ const sourceNames = attributeNames || Object.keys(geometry.attributes);
163
+ for (const name of sourceNames) {
164
+ const attribute = geometry.attributes[name];
165
+ if (attribute) attributes.set(getGeometryShaderAttributeName(name), [name, attribute]);
205
166
  }
206
- return Object.entries(geometry.attributes);
167
+ return Array.from(attributes.values());
207
168
  }
208
169
 
209
170
  function writeInterleavedAttribute(
@@ -236,19 +197,3 @@ function writeInterleavedAttribute(
236
197
  function alignTo(byteOffset: number, alignment: number): number {
237
198
  return Math.ceil(byteOffset / alignment) * alignment;
238
199
  }
239
-
240
- // export function calculateVertexNormals(positions: Float32Array): Uint8Array {
241
- // let normals = new Uint8Array(positions.length / 3);
242
-
243
- // for (let i = 0; i < positions.length; i++) {
244
- // const vec1 = new Vector3(positions.subarray(i * 3, i + 0, i + 3));
245
- // const vec2 = new Vector3(positions.subarray(i + 3, i + 6));
246
- // const vec3 = new Vector3(positions.subarray(i + 6, i + 9));
247
-
248
- // const normal = new Vector3(vec1).cross(vec2).normalize();
249
- // normals.set(normal[0], i + 4);
250
- // normals.set(normal[1], i + 4 + 1);
251
- // normals.set(normal[2], i + 2);
252
- // }
253
- // const normal = new Vector3(vec1).cross(vec2).normalize();
254
- // }
@@ -2,181 +2,54 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
- import type {TypedArray} from '@math.gl/core';
6
- import type {BufferLayout, PrimitiveTopology} from '@luma.gl/core';
5
+ import {Geometry as MathGeometry, type GeometryProps as MathGeometryProps} from '@math.gl/geometry';
6
+ import type {BufferLayout} from '@luma.gl/core';
7
7
  import {vertexFormatDecoder} from '@luma.gl/core';
8
- import {uid} from '../utils/uid';
8
+ import type {GeometryAttribute} from '@math.gl/geometry';
9
9
 
10
- /** CPU-side attribute data accepted by {@link Geometry}. */
11
- export type GeometryAttributeInput = GeometryAttribute | TypedArray;
10
+ export type {
11
+ GeometryAttribute,
12
+ GeometryAttributeInput,
13
+ GeometryAttributes
14
+ } from '@math.gl/geometry';
12
15
 
13
- /** Properties used to create a {@link Geometry}. */
14
- export type GeometryProps = {
15
- /** Application-provided identifier. */
16
- id?: string;
17
- /** Determines how vertices are assembled into primitives. */
18
- topology: 'point-list' | 'line-list' | 'line-strip' | 'triangle-list' | 'triangle-strip';
19
- /** Draw vertex count. Auto-calculated from attributes or indices when omitted. */
20
- vertexCount?: number;
21
- /** CPU attributes, keyed by caller-provided names such as glTF mesh attribute semantics. */
22
- attributes: Record<string, GeometryAttributeInput>;
23
- /**
24
- * Maps geometry buffers to shader attributes.
25
- *
26
- * If omitted, the constructor creates one shader-facing buffer layout entry for each attribute.
27
- * Explicit buffer layouts are preserved unchanged.
28
- */
29
- bufferLayout?: BufferLayout[];
30
- /** Optional index data. Indices are always stored separately from vertex attributes. */
31
- indices?: GeometryAttribute | TypedArray;
32
- };
16
+ /** Legacy engine geometry properties, including caller-owned shader layout metadata. */
17
+ export type GeometryProps = MathGeometryProps & {bufferLayout?: BufferLayout[]};
33
18
 
34
- /** Attributes returned by {@link Geometry.getAttributes}. */
35
- export type GeometryAttributes = Record<string, GeometryAttribute | undefined> & {
36
- /** Optional index attribute, included when the geometry is indexed. */
37
- indices?: GeometryAttribute & {size: 1; value: Uint32Array | Uint16Array};
38
- };
39
-
40
- /** Typed-array backed CPU geometry attribute. */
41
- export type GeometryAttribute = {
42
- /** Number of typed-array elements per vertex. */
43
- size?: number;
44
- /** Attribute data. */
45
- value: TypedArray;
46
- /** Additional attribute metadata consumed by geometry utilities. */
47
- [key: string]: any;
48
- };
49
-
50
- /**
51
- * CPU-side geometry container.
52
- *
53
- * `Geometry` stores typed-array vertex data, optional index data, and an always-populated
54
- * `bufferLayout` that describes how its attributes map to shader inputs. CPU attribute names are
55
- * preserved as supplied; synthesized buffer layouts map supported glTF-style names such as
56
- * `POSITION` and `TEXCOORD_0` to default shader names such as `positions` and `texCoords`.
57
- */
58
- export class Geometry {
59
- /** Application-provided or generated identifier. */
60
- readonly id: string;
61
-
62
- /** Determines how vertices are assembled into primitives. */
63
- readonly topology?: PrimitiveTopology;
64
-
65
- /** Resolved draw vertex count. */
66
- readonly vertexCount: number;
67
-
68
- /** Optional index attribute. */
69
- readonly indices?: GeometryAttribute;
70
-
71
- /** CPU attributes, keyed by caller-provided source attribute name. */
72
- readonly attributes: Record<string, GeometryAttribute | undefined>;
73
-
74
- /** Buffer layout matching the geometry attributes. Always populated. */
19
+ /** Compatibility adapter for math.gl CPU geometry with engine shader layout metadata. */
20
+ export class Geometry extends MathGeometry {
75
21
  readonly bufferLayout: BufferLayout[];
76
22
 
77
- /** Application-owned metadata. */
78
- userData: Record<string, unknown> = {};
79
-
80
- /** Creates a CPU geometry and wraps raw typed arrays into attribute records. */
81
23
  constructor(props: GeometryProps) {
82
- const {attributes = {}, indices = null, vertexCount = null} = props;
83
-
84
- this.id = props.id || uid('geometry');
85
- this.topology = props.topology;
86
-
87
- if (indices) {
88
- this.indices = ArrayBuffer.isView(indices) ? {value: indices, size: 1} : indices;
24
+ const attributes: MathGeometryProps['attributes'] = {};
25
+ const sourceNames = new Map<string, string>();
26
+ for (const [name, attribute] of Object.entries(props.attributes)) {
27
+ const shaderName = getGeometryShaderAttributeName(name);
28
+ const previousName = sourceNames.get(shaderName);
29
+ if (previousName) delete attributes[previousName];
30
+ sourceNames.set(shaderName, name);
31
+ attributes[name] = attribute;
89
32
  }
90
-
91
- this.attributes = {};
92
-
93
- for (const [attributeName, attributeValue] of Object.entries(attributes)) {
94
- // Wrap "unwrapped" arrays and try to autodetect their type
95
- const attribute: GeometryAttribute = ArrayBuffer.isView(attributeValue)
96
- ? {value: attributeValue}
97
- : attributeValue;
98
-
99
- if (!ArrayBuffer.isView(attribute.value)) {
100
- throw new Error(
101
- `${this._print(attributeName)}: must be typed array or object with value as typed array`
102
- );
103
- }
104
-
105
- if ((attributeName === 'POSITION' || attributeName === 'positions') && !attribute.size) {
106
- attribute.size = 3;
107
- }
108
-
109
- // Move indices to separate field
110
- if (attributeName === 'indices') {
111
- if (this.indices) {
112
- throw new Error('Multiple indices detected');
113
- }
114
- this.indices = attribute;
115
- } else {
116
- const shaderAttributeName = getGeometryShaderAttributeName(attributeName);
117
- const storedAttributeName = Object.keys(this.attributes).find(
118
- name => getGeometryShaderAttributeName(name) === shaderAttributeName
119
- );
120
- if (storedAttributeName) {
121
- delete this.attributes[storedAttributeName];
122
- }
123
- this.attributes[attributeName] = attribute;
33
+ const sourceIndices = props.indices;
34
+ const indices =
35
+ sourceIndices instanceof Uint8Array
36
+ ? new Uint16Array(sourceIndices)
37
+ : sourceIndices &&
38
+ !ArrayBuffer.isView(sourceIndices) &&
39
+ sourceIndices.value instanceof Uint8Array
40
+ ? {...sourceIndices, value: new Uint16Array(sourceIndices.value)}
41
+ : sourceIndices;
42
+ super({...props, attributes, indices});
43
+ // Preserve legacy descriptor identity while math.gl owns normalization and validation.
44
+ for (const [name, input] of Object.entries(attributes)) {
45
+ if (!ArrayBuffer.isView(input) && Object.isExtensible(input) && name !== 'indices') {
46
+ Object.assign(input, this.attributes[name]);
47
+ this.attributes[name] = input;
124
48
  }
125
49
  }
126
-
127
- if (this.indices && this.indices['isIndexed'] !== undefined) {
128
- this.indices = Object.assign({}, this.indices);
129
- delete this.indices['isIndexed'];
130
- }
131
-
132
- this.vertexCount = vertexCount || this._calculateVertexCount(this.attributes, this.indices);
133
50
  this.bufferLayout =
134
51
  props.bufferLayout || getBufferLayoutFromGeometryAttributes(this.attributes);
135
52
  }
136
-
137
- /** Returns the resolved draw vertex count. */
138
- getVertexCount(): number {
139
- return this.vertexCount;
140
- }
141
-
142
- /** Returns all attributes, including `indices` when index data is present. */
143
- getAttributes(): GeometryAttributes {
144
- return (
145
- this.indices ? {indices: this.indices, ...this.attributes} : this.attributes
146
- ) as GeometryAttributes;
147
- }
148
-
149
- // PRIVATE
150
-
151
- _print(attributeName: string): string {
152
- return `Geometry ${this.id} attribute ${attributeName}`;
153
- }
154
-
155
- _setAttributes(attributes: Record<string, GeometryAttribute>, indices: any): this {
156
- return this;
157
- }
158
-
159
- _calculateVertexCount(
160
- attributes: Record<string, GeometryAttribute | undefined>,
161
- indices?: GeometryAttribute
162
- ): number {
163
- if (indices) {
164
- return indices.value.length;
165
- }
166
- let vertexCount = Infinity;
167
- for (const attribute of Object.values(attributes)) {
168
- if (!attribute) {
169
- continue; // eslint-disable-line no-continue
170
- }
171
- const {value, size, constant} = attribute;
172
- if (!constant && value && size !== undefined && size >= 1) {
173
- vertexCount = Math.min(vertexCount, value.length / size);
174
- }
175
- }
176
-
177
- // assert(Number.isFinite(vertexCount));
178
- return vertexCount;
179
- }
180
53
  }
181
54
 
182
55
  /**
@@ -202,7 +75,7 @@ export function getGeometryShaderAttributeName(attributeName: string): string {
202
75
  }
203
76
  }
204
77
 
205
- function getBufferLayoutFromGeometryAttributes(
78
+ export function getBufferLayoutFromGeometryAttributes(
206
79
  attributes: Record<string, GeometryAttribute | undefined>
207
80
  ): BufferLayout[] {
208
81
  const bufferLayout: BufferLayout[] = [];
@@ -4,7 +4,11 @@
4
4
 
5
5
  import type {PrimitiveTopology, BufferLayout} from '@luma.gl/core';
6
6
  import {Device, Buffer} from '@luma.gl/core';
7
- import {type Geometry, getGeometryShaderAttributeName} from '../geometry/geometry';
7
+ import type {Geometry} from '@math.gl/geometry';
8
+ import {
9
+ getBufferLayoutFromGeometryAttributes,
10
+ getGeometryShaderAttributeName
11
+ } from '../geometry/geometry';
8
12
  import {makeInterleavedGeometry} from './geometry-utils';
9
13
  import {uid} from '../utils/uid';
10
14
 
@@ -143,12 +147,12 @@ export function getIndexBufferFromGeometry(device: Device, geometry: Geometry):
143
147
  */
144
148
  export function getAttributeBuffersFromGeometry(
145
149
  device: Device,
146
- geometry: Geometry
150
+ geometry: Geometry & {bufferLayout?: BufferLayout[]}
147
151
  ): {attributes: Record<string, Buffer>; bufferLayout: BufferLayout[]; vertexCount: number} {
148
152
  const attributes: Record<string, Buffer> = {};
149
153
  for (const [attributeName, attribute] of Object.entries(geometry.attributes)) {
150
154
  const name =
151
- geometry.bufferLayout.find(bufferLayout => bufferLayout.name === attributeName)?.name ||
155
+ geometry.bufferLayout?.find(bufferLayout => bufferLayout.name === attributeName)?.name ||
152
156
  getGeometryShaderAttributeName(attributeName);
153
157
  if (attribute) {
154
158
  attributes[name] = device.createBuffer({
@@ -160,7 +164,8 @@ export function getAttributeBuffersFromGeometry(
160
164
 
161
165
  return {
162
166
  attributes,
163
- bufferLayout: geometry.bufferLayout,
167
+ bufferLayout:
168
+ geometry.bufferLayout || getBufferLayoutFromGeometryAttributes(geometry.attributes),
164
169
  vertexCount: geometry.vertexCount
165
170
  };
166
171
  }
package/src/index.ts CHANGED
@@ -110,20 +110,20 @@ export type {GPUGeometryProps} from './geometry/gpu-geometry';
110
110
  export {GPUGeometry} from './geometry/gpu-geometry';
111
111
 
112
112
  // Primitives
113
- export type {ConeGeometryProps} from './geometries/cone-geometry';
114
- export {ConeGeometry} from './geometries/cone-geometry';
115
- export type {CubeGeometryProps} from './geometries/cube-geometry';
116
- export {CubeGeometry} from './geometries/cube-geometry';
117
- export type {CylinderGeometryProps} from './geometries/cylinder-geometry';
118
- export {CylinderGeometry} from './geometries/cylinder-geometry';
119
- export type {IcoSphereGeometryProps} from './geometries/ico-sphere-geometry';
120
- export {IcoSphereGeometry} from './geometries/ico-sphere-geometry';
121
- export type {PlaneGeometryProps} from './geometries/plane-geometry';
122
- export {PlaneGeometry} from './geometries/plane-geometry';
123
- export type {SphereGeometryProps} from './geometries/sphere-geometry';
124
- export {SphereGeometry} from './geometries/sphere-geometry';
125
- export type {TruncatedConeGeometryProps} from './geometries/truncated-cone-geometry';
126
- export {TruncatedConeGeometry} from './geometries/truncated-cone-geometry';
113
+ export type {ConeGeometryProps} from './geometry/geometry-primitives';
114
+ export {ConeGeometry} from './geometry/geometry-primitives';
115
+ export type {CubeGeometryProps} from './geometry/geometry-primitives';
116
+ export {CubeGeometry} from './geometry/geometry-primitives';
117
+ export type {CylinderGeometryProps} from './geometry/geometry-primitives';
118
+ export {CylinderGeometry} from './geometry/geometry-primitives';
119
+ export type {IcoSphereGeometryProps} from './geometry/geometry-primitives';
120
+ export {IcoSphereGeometry} from './geometry/geometry-primitives';
121
+ export type {PlaneGeometryProps} from './geometry/geometry-primitives';
122
+ export {PlaneGeometry} from './geometry/geometry-primitives';
123
+ export type {SphereGeometryProps} from './geometry/geometry-primitives';
124
+ export {SphereGeometry} from './geometry/geometry-primitives';
125
+ export type {TruncatedConeGeometryProps} from './geometry/geometry-primitives';
126
+ export {TruncatedConeGeometry} from './geometry/geometry-primitives';
127
127
 
128
128
  export {ShaderInputs} from './shader-inputs';
129
129
  export type {ShaderInputBinding, ShaderInputsProps} from './shader-inputs';
@@ -53,7 +53,7 @@ import {
53
53
  ShaderAssembler
54
54
  } from '@luma.gl/shadertools';
55
55
 
56
- import type {Geometry} from '../geometry/geometry';
56
+ import type {Geometry} from '@math.gl/geometry';
57
57
  import {GPUGeometry, makeGPUGeometry} from '../geometry/gpu-geometry';
58
58
  import {getDebugTableForShaderLayout} from '../debug/debug-shader-layout';
59
59
  import {debugFramebuffer} from '../debug/debug-framebuffer';
@@ -51,36 +51,43 @@ void main(void) {
51
51
  }
52
52
  `;
53
53
 
54
- /* eslint-disable indent, no-multi-spaces */
55
- const POSITIONS = [-1, -1, 1, -1, -1, 1, 1, 1];
54
+ const QUAD_POSITIONS = [-1, -1, 1, -1, -1, 1, 1, 1];
55
+
56
+ const TRIANGLE_POSITIONS = [-1, -1, 3, -1, -1, 3];
56
57
 
57
58
  /** Props for ClipSpace */
58
- export type ClipSpaceProps = Omit<ModelProps, 'vs' | 'vertexCount' | 'geometry'>;
59
+ export type ClipSpaceProps = Omit<ModelProps, 'vs' | 'vertexCount' | 'geometry'> & {
60
+ /** Fullscreen geometry. Defaults to the two-triangle quad. */
61
+ geometryType?: 'quad' | 'triangle';
62
+ };
59
63
 
60
64
  /**
61
65
  * A flat geometry that covers the "visible area" that the GPU renders.
62
66
  */
63
67
  export class ClipSpace extends Model {
64
68
  constructor(device: Device, props: ClipSpaceProps) {
65
- const TEX_COORDS = POSITIONS.map(coord => (coord === -1 ? 0 : coord));
69
+ const {geometryType = 'quad', ...modelProps} = props;
70
+ const positions = geometryType === 'triangle' ? TRIANGLE_POSITIONS : QUAD_POSITIONS;
71
+ const textureCoordinates = positions.map(position => (position + 1) / 2);
72
+ const vertexCount = positions.length / 2;
66
73
 
67
74
  // For WGSL we need to append the supplied fragment shader to the default vertex shader source
68
- if (props.source) {
69
- props = {...props, source: `${CLIPSPACE_VERTEX_SHADER_WGSL}\n${props.source}`};
75
+ if (modelProps.source) {
76
+ modelProps.source = `${CLIPSPACE_VERTEX_SHADER_WGSL}\n${modelProps.source}`;
70
77
  }
71
78
 
72
79
  super(device, {
73
- id: props.id || uid('clip-space'),
74
- ...props,
80
+ id: modelProps.id || uid('clip-space'),
81
+ ...modelProps,
75
82
  vs: CLIPSPACE_VERTEX_SHADER,
76
- vertexCount: 4,
83
+ vertexCount,
77
84
  geometry: new Geometry({
78
- topology: 'triangle-strip',
79
- vertexCount: 4,
85
+ topology: geometryType === 'triangle' ? 'triangle-list' : 'triangle-strip',
86
+ vertexCount,
80
87
  attributes: {
81
- clipSpacePositions: {size: 2, value: new Float32Array(POSITIONS)},
82
- texCoords: {size: 2, value: new Float32Array(TEX_COORDS)},
83
- coordinates: {size: 2, value: new Float32Array(TEX_COORDS)}
88
+ clipSpacePositions: {size: 2, value: new Float32Array(positions)},
89
+ texCoords: {size: 2, value: new Float32Array(textureCoordinates)},
90
+ coordinates: {size: 2, value: new Float32Array(textureCoordinates)}
84
91
  }
85
92
  })
86
93
  });
@@ -3,7 +3,7 @@
3
3
  // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  import {Device} from '@luma.gl/core';
6
- import {ConeGeometry} from '../geometries/cone-geometry';
6
+ import {ConeGeometry} from '../geometry/geometry-primitives';
7
7
  import {
8
8
  BaseLightModel,
9
9
  buildDirectionalLightInstanceData,
@@ -3,7 +3,7 @@
3
3
  // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  import {Device} from '@luma.gl/core';
6
- import {SphereGeometry} from '../geometries/sphere-geometry';
6
+ import {SphereGeometry} from '../geometry/geometry-primitives';
7
7
  import {
8
8
  BaseLightModel,
9
9
  buildPointLightInstanceData,
@@ -3,7 +3,7 @@
3
3
  // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  import {Device} from '@luma.gl/core';
6
- import {ConeGeometry} from '../geometries/cone-geometry';
6
+ import {ConeGeometry} from '../geometry/geometry-primitives';
7
7
  import {
8
8
  BaseLightModel,
9
9
  buildSpotLightInstanceData,
@@ -1,12 +0,0 @@
1
- import type { TruncatedConeGeometryProps } from "./truncated-cone-geometry.js";
2
- import { TruncatedConeGeometry } from "./truncated-cone-geometry.js";
3
- export type ConeGeometryProps = Omit<TruncatedConeGeometryProps, 'topRadius' | 'bottomRadius' | 'topCap' | 'bottomCap'> & {
4
- id?: string;
5
- radius?: number;
6
- cap?: boolean;
7
- attributes?: any;
8
- };
9
- export declare class ConeGeometry extends TruncatedConeGeometry {
10
- constructor(props?: ConeGeometryProps);
11
- }
12
- //# sourceMappingURL=cone-geometry.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cone-geometry.d.ts","sourceRoot":"","sources":["../../src/geometries/cone-geometry.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,0BAA0B,EAAC,qCAAkC;AAC1E,OAAO,EAAC,qBAAqB,EAAC,qCAAkC;AAGhE,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAClC,0BAA0B,EAC1B,WAAW,GAAG,cAAc,GAAG,QAAQ,GAAG,WAAW,CACtD,GAAG;IACF,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,UAAU,CAAC,EAAE,GAAG,CAAC;CAClB,CAAC;AAEF,qBAAa,YAAa,SAAQ,qBAAqB;gBACzC,KAAK,GAAE,iBAAsB;CAW1C"}
@@ -1,19 +0,0 @@
1
- // luma.gl
2
- // SPDX-License-Identifier: MIT
3
- // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
- import { TruncatedConeGeometry } from "./truncated-cone-geometry.js";
5
- import { uid } from "../utils/uid.js";
6
- export class ConeGeometry extends TruncatedConeGeometry {
7
- constructor(props = {}) {
8
- const { id = uid('cone-geometry'), radius = 1, cap = true } = props;
9
- super({
10
- ...props,
11
- id,
12
- topRadius: 0,
13
- topCap: Boolean(cap),
14
- bottomCap: Boolean(cap),
15
- bottomRadius: radius
16
- });
17
- }
18
- }
19
- //# sourceMappingURL=cone-geometry.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cone-geometry.js","sourceRoot":"","sources":["../../src/geometries/cone-geometry.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,4DAA4D;AAG5D,OAAO,EAAC,qBAAqB,EAAC,qCAAkC;AAChE,OAAO,EAAC,GAAG,EAAC,wBAAqB;AAYjC,MAAM,OAAO,YAAa,SAAQ,qBAAqB;IACrD,YAAY,QAA2B,EAAE;QACvC,MAAM,EAAC,EAAE,GAAG,GAAG,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,GAAG,GAAG,IAAI,EAAC,GAAG,KAAK,CAAC;QAClE,KAAK,CAAC;YACJ,GAAG,KAAK;YACR,EAAE;YACF,SAAS,EAAE,CAAC;YACZ,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC;YACpB,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC;YACvB,YAAY,EAAE,MAAM;SACrB,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -1,14 +0,0 @@
1
- import { Geometry } from "../geometry/geometry.js";
2
- export type CubeGeometryProps = {
3
- id?: string;
4
- indices?: boolean;
5
- attributes?: any;
6
- };
7
- export declare class CubeGeometry extends Geometry {
8
- constructor(props?: CubeGeometryProps);
9
- }
10
- export declare const CUBE_NON_INDEXED_POSITIONS: Float32Array<ArrayBuffer>;
11
- export declare const CUBE_NON_INDEXED_TEX_COORDS: Float32Array<ArrayBuffer>;
12
- export declare const CUBE_NON_INDEXED_COLORS: Float32Array<ArrayBuffer>;
13
- export declare const CUBE_NON_INDEXED_FACE_INDICES: Uint32Array<ArrayBuffer>;
14
- //# sourceMappingURL=cube-geometry.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cube-geometry.d.ts","sourceRoot":"","sources":["../../src/geometries/cube-geometry.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,QAAQ,EAAC,gCAA6B;AAI9C,MAAM,MAAM,iBAAiB,GAAG;IAC9B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,GAAG,CAAC;CAClB,CAAC;AAEF,qBAAa,YAAa,SAAQ,QAAQ;gBAC5B,KAAK,GAAE,iBAAsB;CAoB1C;AA+DD,eAAO,MAAM,0BAA0B,2BA0CrC,CAAC;AAIH,eAAO,MAAM,2BAA2B,2BA0CtC,CAAC;AAIH,eAAO,MAAM,uBAAuB,2BA0ClC,CAAC;AAGH,eAAO,MAAM,6BAA6B,0BAOxC,CAAC"}