@luma.gl/engine 9.0.0-alpha.32 → 9.0.0-alpha.33

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luma.gl/engine",
3
- "version": "9.0.0-alpha.32",
3
+ "version": "9.0.0-alpha.33",
4
4
  "description": "WebGL2 Components for High Performance Rendering and Computation",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -40,13 +40,13 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "@babel/runtime": "^7.0.0",
43
- "@luma.gl/constants": "9.0.0-alpha.32",
44
- "@luma.gl/core": "9.0.0-alpha.32",
45
- "@luma.gl/shadertools": "9.0.0-alpha.32",
46
- "@luma.gl/webgl": "9.0.0-alpha.32",
43
+ "@luma.gl/constants": "9.0.0-alpha.33",
44
+ "@luma.gl/core": "9.0.0-alpha.33",
45
+ "@luma.gl/shadertools": "9.0.0-alpha.33",
46
+ "@luma.gl/webgl": "9.0.0-alpha.33",
47
47
  "@math.gl/core": "4.0.0-alpha.4",
48
48
  "@probe.gl/log": "^4.0.2",
49
49
  "@probe.gl/stats": "^4.0.2"
50
50
  },
51
- "gitHead": "08b30dcae4aee321738cf05b509cef6b3b24c880"
51
+ "gitHead": "65a38ac7ed371767303b5ded6cc3d34373e904e3"
52
52
  }
@@ -24,7 +24,7 @@ export type GeometryAttributes = {
24
24
  NORMAL: GeometryAttribute;
25
25
  TEXCOORD_0: GeometryAttribute;
26
26
  COLOR_0?: GeometryAttribute;
27
- indices?: {size?: number; value: Uint32Array | Uint16Array};
27
+ indices?: GeometryAttribute & {size: 1; value: Uint32Array | Uint16Array};
28
28
  };
29
29
 
30
30
  export type GeometryAttribute = {
@@ -38,7 +38,7 @@ export class Geometry {
38
38
  /** Determines how vertices are read from the 'vertex' attributes */
39
39
  readonly topology?: PrimitiveTopology;
40
40
  readonly vertexCount: number;
41
- readonly indices?: Uint16Array | Uint32Array;
41
+ readonly indices?: GeometryAttribute;
42
42
  readonly attributes: {
43
43
  POSITION: GeometryAttribute;
44
44
  NORMAL: GeometryAttribute;
@@ -56,7 +56,6 @@ export class Geometry {
56
56
  this.topology = props.topology;
57
57
 
58
58
  if (indices) {
59
- // @ts-expect-error
60
59
  this.indices = ArrayBuffer.isView(indices) ? {value: indices, size: 1} : indices;
61
60
  }
62
61
 
@@ -81,17 +80,14 @@ export class Geometry {
81
80
  // Move indices to separate field
82
81
  if (attributeName === 'indices') {
83
82
  assert(!this.indices);
84
- // @ts-expect-error
85
83
  this.indices = attribute;
86
84
  } else {
87
85
  this.attributes[attributeName] = attribute;
88
86
  }
89
87
  }
90
88
 
91
- // @ts-expect-error
92
89
  if (this.indices && this.indices.isIndexed !== undefined) {
93
90
  this.indices = Object.assign({}, this.indices);
94
- // @ts-expect-error
95
91
  delete this.indices.isIndexed;
96
92
  }
97
93
 
@@ -102,9 +98,11 @@ export class Geometry {
102
98
  return this.vertexCount;
103
99
  }
104
100
 
105
- // Return an object with all attributes plus indices added as a field.
101
+ /**
102
+ * Return an object with all attributes plus indices added as a field.
103
+ * TODO Geometry types are a mess
104
+ */
106
105
  getAttributes(): GeometryAttributes {
107
- // @ts-expect-error Geometry types are a mess
108
106
  return this.indices ? {indices: this.indices, ...this.attributes} : this.attributes;
109
107
  }
110
108
 
@@ -114,22 +112,27 @@ export class Geometry {
114
112
  return `Geometry ${this.id} attribute ${attributeName}`;
115
113
  }
116
114
 
117
- // GeometryAttribute
118
- // value: typed array
119
- // type: indices, vertices, uvs
120
- // size: elements per vertex
121
- // target: WebGL buffer type (string or constant)
115
+ /**
116
+ * GeometryAttribute
117
+ * value: typed array
118
+ * type: indices, vertices, uvs
119
+ * size: elements per vertex
120
+ * target: WebGL buffer type (string or constant)
121
+ *
122
+ * @param attributes
123
+ * @param indices
124
+ * @returns
125
+ */
122
126
  _setAttributes(attributes: Record<string, GeometryAttribute>, indices: any): this {
123
127
  return this;
124
128
  }
125
129
 
126
- _calculateVertexCount(attributes: any, indices: any): number {
130
+ _calculateVertexCount(attributes: GeometryAttributes, indices: GeometryAttribute): number {
127
131
  if (indices) {
128
132
  return indices.value.length;
129
133
  }
130
134
  let vertexCount = Infinity;
131
- for (const attributeName in attributes) {
132
- const attribute = attributes[attributeName];
135
+ for (const attribute of Object.values(attributes)) {
133
136
  const {value, size, constant} = attribute;
134
137
  if (!constant && value && size >= 1) {
135
138
  vertexCount = Math.min(vertexCount, value.length / size);
@@ -14,16 +14,16 @@ export type GPUGeometryProps = {
14
14
  | 'triangle-strip'
15
15
  | 'triangle-fan-webgl';
16
16
  /** Auto calculated from attributes if not provided */
17
- vertexCount?: number;
18
- bufferLayout?: BufferLayout[];
17
+ vertexCount: number;
18
+ bufferLayout: BufferLayout[];
19
19
  indices?: Buffer | null;
20
20
  attributes: GPUGeometryAttributes;
21
21
  };
22
22
 
23
23
  export type GPUGeometryAttributes = {
24
24
  positions: Buffer;
25
- normals: Buffer;
26
- texCoords: Buffer;
25
+ normals?: Buffer;
26
+ texCoords?: Buffer;
27
27
  colors?: Buffer;
28
28
  };
29
29
 
@@ -39,8 +39,8 @@ export class GPUGeometry {
39
39
  readonly indices?: Buffer | null;
40
40
  readonly attributes: {
41
41
  positions: Buffer;
42
- normals: Buffer;
43
- texCoords: Buffer;
42
+ normals?: Buffer;
43
+ texCoords?: Buffer;
44
44
  colors?: Buffer;
45
45
  };
46
46
 
@@ -50,21 +50,21 @@ export class GPUGeometry {
50
50
  this.indices = props.indices || null;
51
51
  this.attributes = props.attributes;
52
52
 
53
- //
54
- this.vertexCount = props.vertexCount || this._calculateVertexCount(this.attributes.positions);
53
+ //
54
+ this.vertexCount = props.vertexCount;
55
55
 
56
56
  // Populate default bufferLayout
57
57
  this.bufferLayout = props.bufferLayout || [];
58
58
  if (!this.bufferLayout.find(layout => layout.name === 'positions')) {
59
59
  this.bufferLayout.push({name: 'positions', format: 'float32x3'});
60
60
  }
61
- if (!this.bufferLayout.find(layout => layout.name === 'normals')) {
61
+ if (this.attributes.normals && !this.bufferLayout.find(layout => layout.name === 'normals')) {
62
62
  this.bufferLayout.push({name: 'normals', format: 'float32x3'});
63
63
  }
64
- if (!this.bufferLayout.find(layout => layout.name === 'texCoords')) {
64
+ if (this.attributes.texCoords && !this.bufferLayout.find(layout => layout.name === 'texCoords')) {
65
65
  this.bufferLayout.push({name: 'texCoords', format: 'float32x2'});
66
66
  }
67
- if (!this.bufferLayout.find(layout => layout.name === 'colors')) {
67
+ if (this.attributes.colors && !this.bufferLayout.find(layout => layout.name === 'colors')) {
68
68
  this.bufferLayout.push({name: 'colors', format: 'float32x3'});
69
69
  }
70
70
 
@@ -106,11 +106,12 @@ export function makeGPUGeometry(device: Device, geometry: Geometry | GPUGeometry
106
106
  }
107
107
 
108
108
  const indices = getIndexBufferFromGeometry(device, geometry);
109
- const attributes = getAttributeBuffersFromGeometry(device, geometry);
109
+ const {attributes, bufferLayout} = getAttributeBuffersFromGeometry(device, geometry);
110
110
  return new GPUGeometry({
111
- topology: geometry.topology,
112
- vertexCount: geometry.vertexCount,
113
- indices,
111
+ topology: geometry.topology || 'triangle-list',
112
+ bufferLayout,
113
+ vertexCount: geometry.vertexCount,
114
+ indices,
114
115
  attributes
115
116
  });
116
117
  }
@@ -120,8 +121,7 @@ export function getIndexBufferFromGeometry(device: Device, geometry: Geometry):
120
121
  return undefined;
121
122
  }
122
123
 
123
- // @ts-expect-error
124
- const data = geometry.indices.value || geometry.indices;
124
+ const data = geometry.indices.value;
125
125
  assert(
126
126
  data instanceof Uint16Array || data instanceof Uint32Array,
127
127
  'attribute array for "indices" must be of integer type'
@@ -129,31 +129,30 @@ export function getIndexBufferFromGeometry(device: Device, geometry: Geometry):
129
129
  return device.createBuffer({usage: Buffer.INDEX, data});
130
130
  }
131
131
 
132
- export function getAttributeBuffersFromGeometry(device: Device, geometry: Geometry): GPUGeometryAttributes {
132
+ export function getAttributeBuffersFromGeometry(
133
+ device: Device,
134
+ geometry: Geometry
135
+ ): {attributes: GPUGeometryAttributes, bufferLayout: BufferLayout[], vertexCount: number} {
133
136
  const positions = geometry.attributes.positions || geometry.attributes.POSITION;
134
137
  const normals = geometry.attributes.normals || geometry.attributes.NORMAL;
135
138
  const texCoords = geometry.attributes.texCoords || geometry.attributes.TEXCOORD_0;
136
139
 
137
- const buffers: GPUGeometryAttributes = {
138
- positions: device.createBuffer({data: positions.value, id: 'positions-buffer'}),
139
- normals: device.createBuffer({data: normals.value, id: 'normals-buffer'}),
140
- texCoords: device.createBuffer({data: texCoords.value, id: 'texCoords-buffer'})
140
+ const attributes: GPUGeometryAttributes = {
141
+ positions: device.createBuffer({data: positions.value, id: 'positions-buffer'})
141
142
  };
143
+ const bufferLayout: BufferLayout[] = [
144
+ {name: 'positions', format: `float32x${positions.size as 2 | 3 | 4}`}
145
+ ];
146
+ if (normals) {
147
+ attributes.normals = device.createBuffer({data: normals.value, id: 'normals-buffer'});
148
+ bufferLayout.push({name: 'normals', format: `float32x${normals.size as 2 | 3 | 4}`});
149
+ }
150
+ if (texCoords) {
151
+ attributes.texCoords = device.createBuffer({data: texCoords.value, id: 'texCoords-buffer'});
152
+ bufferLayout.push({name: 'texCoords', format: `float32x${texCoords.size as 2 | 3 | 4}`});
153
+ }
142
154
 
143
- return buffers;
144
- }
145
-
146
- // Support for mapping new geometries with glTF attribute names to "classic" luma.gl shader names
147
- const GLTF_TO_LUMA_ATTRIBUTE_MAP = {
148
- POSITION: 'positions',
149
- NORMAL: 'normals',
150
- COLOR_0: 'colors',
151
- TEXCOORD_0: 'texCoords',
152
- TEXCOORD_1: 'texCoords1',
153
- TEXCOORD_2: 'texCoords2'
154
- };
155
+ const vertexCount = geometry._calculateVertexCount(geometry.attributes, geometry.indices)
155
156
 
156
- export function mapAttributeName(name: string): string {
157
- // @ts-ignore-error
158
- return GLTF_TO_LUMA_ATTRIBUTE_MAP[name] || name;
157
+ return {attributes, bufferLayout, vertexCount};
159
158
  }
@@ -3,12 +3,11 @@
3
3
  import type {TypedArray, RenderPipelineProps, RenderPipelineParameters, BufferLayout} from '@luma.gl/core';
4
4
  import type {Binding, UniformValue, PrimitiveTopology} from '@luma.gl/core';
5
5
  import {Device, Buffer, RenderPipeline, RenderPass, log, uid, deepEqual} from '@luma.gl/core';
6
- import type {ShaderModule} from '@luma.gl/shadertools';
6
+ import type {ShaderModule, PlatformInfo} from '@luma.gl/shadertools';
7
7
  import {ShaderAssembler} from '@luma.gl/shadertools';
8
8
  import type {Geometry} from '../geometry/geometry';
9
9
  import {GPUGeometry, makeGPUGeometry} from '../geometry/gpu-geometry';
10
10
  import {PipelineFactory} from '../lib/pipeline-factory';
11
- import {buildShaders} from './model-shaders';
12
11
 
13
12
  export type ModelProps = Omit<RenderPipelineProps, 'vs' | 'fs'> & {
14
13
  // Model also accepts a string shaders
@@ -112,7 +111,15 @@ export class Model {
112
111
 
113
112
  Object.assign(this.userData, props.userData);
114
113
 
115
- const {vs, fs, getUniforms} = buildShaders(device, this.props);
114
+ /** Create a shadertools platform info from the Device */
115
+ const platformInfo: PlatformInfo = {
116
+ type: device.info.type,
117
+ shaderLanguage: device.info.shadingLanguages[0],
118
+ gpu: device.info.gpu,
119
+ features: device.features
120
+ };
121
+
122
+ const {vs, fs, getUniforms} = this.props.shaderAssembler.assembleShaders(platformInfo, this.props);
116
123
  this.vs = vs;
117
124
  this.fs = fs;
118
125
  this._getModuleUniforms = getUniforms;
@@ -125,9 +132,8 @@ export class Model {
125
132
  this.parameters = this.props.parameters;
126
133
 
127
134
  // Geometry, if provided, sets several attributes, indices, and also vertex count and topology
128
- const gpuGeometry = props.geometry && makeGPUGeometry(device, props.geometry);
129
- if (gpuGeometry) {
130
- this.setGeometry(gpuGeometry);
135
+ if (props.geometry) {
136
+ this.setGeometry(props.geometry);
131
137
  }
132
138
 
133
139
  this.pipelineFactory =
@@ -198,16 +204,18 @@ export class Model {
198
204
 
199
205
  /**
200
206
  * Updates the optional geometry
207
+ * Geometry, sets several attributes, indices, and also vertex count and topology
201
208
  * @note Can trigger a pipeline rebuild / pipeline cache fetch on WebGPU
202
209
  */
203
- setGeometry(geometry: GPUGeometry): void {
204
- this.setTopology(geometry.topology || 'triangle-list');
205
- this.bufferLayout = mergeBufferLayouts(this.bufferLayout, geometry.bufferLayout);
210
+ setGeometry(geometry: GPUGeometry | Geometry): void {
211
+ const gpuGeometry = geometry && makeGPUGeometry(this.device, geometry);
212
+ this.setTopology(gpuGeometry.topology || 'triangle-list');
213
+ this.bufferLayout = mergeBufferLayouts(this.bufferLayout, gpuGeometry.bufferLayout);
206
214
 
207
215
  // TODO - delete previous geometry?
208
- this.vertexCount = geometry.vertexCount;
209
- this.setAttributes(geometry.attributes);
210
- this.setIndexBuffer(geometry.indices);
216
+ this.vertexCount = gpuGeometry.vertexCount;
217
+ this.setAttributes(gpuGeometry.attributes);
218
+ this.setIndexBuffer(gpuGeometry.indices);
211
219
  }
212
220
 
213
221
  /**
@@ -1,35 +0,0 @@
1
- import type { Device } from '@luma.gl/core';
2
- import type { ShaderModule, HookFunction } from '@luma.gl/shadertools';
3
- import { ShaderAssembler } from '@luma.gl/shadertools';
4
- export type ModelShaderProps = {
5
- vs?: {
6
- glsl?: string;
7
- wgsl?: string;
8
- } | string | null;
9
- fs?: {
10
- glsl?: string;
11
- wgsl?: string;
12
- } | string | null;
13
- /** shadertool shader modules (added to shader code) */
14
- modules?: ShaderModule[];
15
- /** Shadertool module defines (configures shader code)*/
16
- defines?: Record<string, string | number | boolean>;
17
- inject?: Record<string, string>;
18
- hooks?: Record<string, HookFunction>;
19
- transpileToGLSL100?: boolean;
20
- shaderAssembler: ShaderAssembler;
21
- };
22
- type GetUniformsFunc = (props?: Record<string, any>) => Record<string, any>;
23
- /**
24
- * TODO - should this functionality move into shadertools / assembleShaders ?
25
- * @param device
26
- * @param props
27
- * @returns
28
- */
29
- export declare function buildShaders(device: Device, props: ModelShaderProps): {
30
- vs: string;
31
- fs: string | undefined;
32
- getUniforms: GetUniformsFunc;
33
- };
34
- export {};
35
- //# sourceMappingURL=model-shaders.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"model-shaders.d.ts","sourceRoot":"","sources":["../../src/model/model-shaders.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,EAAC,YAAY,EAAE,YAAY,EAAC,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAC,eAAe,EAAC,MAAM,sBAAsB,CAAC;AAErD,MAAM,MAAM,gBAAgB,GAAG;IAE7B,EAAE,CAAC,EAAE;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAC,GAAG,MAAM,GAAG,IAAI,CAAC;IACpD,EAAE,CAAC,EAAE;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAC,GAAG,MAAM,GAAG,IAAI,CAAC;IACpD,uDAAuD;IACvD,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;IACzB,wDAAwD;IACxD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;IACpD,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACrC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B,eAAe,EAAE,eAAe,CAAC;CAClC,CAAC;AAEF,KAAK,eAAe,GAAG,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAE5E;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,gBAAgB,GACtB;IACD,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,GAAG,SAAS,CAAC;IACvB,WAAW,EAAE,eAAe,CAAA;CAC7B,CAmBA"}
@@ -1,38 +0,0 @@
1
- export function buildShaders(device, props) {
2
- if (!props.vs) {
3
- throw new Error('no vertex shader');
4
- }
5
- const vs = getShaderSource(device, props.vs);
6
- let fs;
7
- if (props.fs) {
8
- fs = getShaderSource(device, props.fs);
9
- }
10
- const platformInfo = {
11
- type: device.info.type,
12
- gpu: device.info.gpu,
13
- features: device.features
14
- };
15
- return props.shaderAssembler.assembleShaders(platformInfo, {
16
- ...props,
17
- fs,
18
- vs
19
- });
20
- }
21
- function getShaderSource(device, shader) {
22
- if (typeof shader === 'string') {
23
- return shader;
24
- }
25
- switch (device.info.type) {
26
- case 'webgpu':
27
- if (shader !== null && shader !== void 0 && shader.wgsl) {
28
- return shader.wgsl;
29
- }
30
- throw new Error('WebGPU does not support GLSL shaders');
31
- default:
32
- if (shader !== null && shader !== void 0 && shader.glsl) {
33
- return shader.glsl;
34
- }
35
- throw new Error('WebGL does not support WGSL shaders');
36
- }
37
- }
38
- //# sourceMappingURL=model-shaders.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"model-shaders.js","names":["buildShaders","device","props","vs","Error","getShaderSource","fs","platformInfo","type","info","gpu","features","shaderAssembler","assembleShaders","shader","wgsl","glsl"],"sources":["../../src/model/model-shaders.ts"],"sourcesContent":["import type {Device} from '@luma.gl/core';\nimport type {ShaderModule, HookFunction} from '@luma.gl/shadertools';\nimport {ShaderAssembler} from '@luma.gl/shadertools';\n\nexport type ModelShaderProps = {\n // Model also accepts a string shaders\n vs?: {glsl?: string; wgsl?: string} | string | null;\n fs?: {glsl?: string; wgsl?: string} | string | null;\n /** shadertool shader modules (added to shader code) */\n modules?: ShaderModule[];\n /** Shadertool module defines (configures shader code)*/\n defines?: Record<string, string | number | boolean>;\n inject?: Record<string, string>;\n hooks?: Record<string, HookFunction>;\n transpileToGLSL100?: boolean;\n\n shaderAssembler: ShaderAssembler;\n};\n\ntype GetUniformsFunc = (props?: Record<string, any>) => Record<string, any>;\n\n/**\n * TODO - should this functionality move into shadertools / assembleShaders ?\n * @param device\n * @param props\n * @returns\n */\nexport function buildShaders(\n device: Device,\n props: ModelShaderProps\n): {\n vs: string; \n fs: string | undefined; \n getUniforms: GetUniformsFunc\n} {\n if (!props.vs) {\n throw new Error('no vertex shader');\n }\n\n // Resolve WGSL vs GLSL\n const vs = getShaderSource(device, props.vs);\n let fs;\n if (props.fs) {\n fs = getShaderSource(device, props.fs);\n }\n\n const platformInfo = {\n type: device.info.type,\n gpu: device.info.gpu,\n features: device.features\n };\n\n return props.shaderAssembler.assembleShaders(platformInfo, {...props, fs, vs});\n}\n\n/** Create a shader from the different overloads */\nfunction getShaderSource(device: Device, shader: string | {glsl?: string; wgsl?: string}): string {\n // TODO - detect WGSL/GLSL and throw an error if not supported\n if (typeof shader === 'string') {\n return shader;\n }\n\n switch (device.info.type) {\n case 'webgpu':\n if (shader?.wgsl) {\n return shader.wgsl;\n }\n throw new Error('WebGPU does not support GLSL shaders');\n\n default:\n if (shader?.glsl) {\n return shader.glsl;\n }\n throw new Error('WebGL does not support WGSL shaders');\n }\n}\n"],"mappings":"AA2BA,OAAO,SAASA,YAAYA,CAC1BC,MAAc,EACdC,KAAuB,EAKvB;EACA,IAAI,CAACA,KAAK,CAACC,EAAE,EAAE;IACb,MAAM,IAAIC,KAAK,CAAC,kBAAkB,CAAC;EACrC;EAGA,MAAMD,EAAE,GAAGE,eAAe,CAACJ,MAAM,EAAEC,KAAK,CAACC,EAAE,CAAC;EAC5C,IAAIG,EAAE;EACN,IAAIJ,KAAK,CAACI,EAAE,EAAE;IACZA,EAAE,GAAGD,eAAe,CAACJ,MAAM,EAAEC,KAAK,CAACI,EAAE,CAAC;EACxC;EAEA,MAAMC,YAAY,GAAG;IACnBC,IAAI,EAAEP,MAAM,CAACQ,IAAI,CAACD,IAAI;IACtBE,GAAG,EAAET,MAAM,CAACQ,IAAI,CAACC,GAAG;IACpBC,QAAQ,EAAEV,MAAM,CAACU;EACnB,CAAC;EAED,OAAOT,KAAK,CAACU,eAAe,CAACC,eAAe,CAACN,YAAY,EAAE;IAAC,GAAGL,KAAK;IAAEI,EAAE;IAAEH;EAAE,CAAC,CAAC;AAChF;AAGA,SAASE,eAAeA,CAACJ,MAAc,EAAEa,MAA+C,EAAU;EAEhG,IAAI,OAAOA,MAAM,KAAK,QAAQ,EAAE;IAC9B,OAAOA,MAAM;EACf;EAEA,QAAQb,MAAM,CAACQ,IAAI,CAACD,IAAI;IACtB,KAAK,QAAQ;MACX,IAAIM,MAAM,aAANA,MAAM,eAANA,MAAM,CAAEC,IAAI,EAAE;QAChB,OAAOD,MAAM,CAACC,IAAI;MACpB;MACA,MAAM,IAAIX,KAAK,CAAC,sCAAsC,CAAC;IAEzD;MACE,IAAIU,MAAM,aAANA,MAAM,eAANA,MAAM,CAAEE,IAAI,EAAE;QAChB,OAAOF,MAAM,CAACE,IAAI;MACpB;MACA,MAAM,IAAIZ,KAAK,CAAC,qCAAqC,CAAC;EAC1D;AACF"}
@@ -1,5 +0,0 @@
1
- import { Device, Buffer } from '@luma.gl/core';
2
- import type { Geometry } from '../geometry/geometry';
3
- export declare function getIndexBufferFromGeometry(device: Device, geometry: Geometry): Buffer | null;
4
- export declare function getAttributeBuffersFromGeometry(device: Device, geometry: Geometry): Record<string, Buffer>;
5
- //# sourceMappingURL=model-utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"model-utils.d.ts","sourceRoot":"","sources":["../../src/model/model-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,MAAM,EAAS,MAAM,eAAe,CAAC;AACrD,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAsDnD,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,MAAM,GAAG,IAAI,CAY5F;AAED,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAc1G"}
@@ -1,40 +0,0 @@
1
- import { Buffer, assert } from '@luma.gl/core';
2
- const GLTF_TO_LUMA_ATTRIBUTE_MAP = {
3
- POSITION: 'positions',
4
- NORMAL: 'normals',
5
- COLOR_0: 'colors',
6
- TEXCOORD_0: 'texCoords',
7
- TEXCOORD_1: 'texCoords1',
8
- TEXCOORD_2: 'texCoords2'
9
- };
10
- export function getIndexBufferFromGeometry(device, geometry) {
11
- if (!geometry.indices) {
12
- return null;
13
- }
14
- const data = geometry.indices.value || geometry.indices;
15
- assert(data instanceof Uint16Array || data instanceof Uint32Array, 'attribute array for "indices" must be of integer type');
16
- return device.createBuffer({
17
- usage: Buffer.INDEX,
18
- data
19
- });
20
- }
21
- export function getAttributeBuffersFromGeometry(device, geometry) {
22
- const buffers = {};
23
- for (const [name, attribute] of Object.entries(geometry.attributes)) {
24
- const remappedName = mapAttributeName(name);
25
- if (attribute !== null && attribute !== void 0 && attribute.constant) {
26
- throw new Error('constant attributes not supported');
27
- } else {
28
- const typedArray = attribute === null || attribute === void 0 ? void 0 : attribute.value;
29
- buffers[remappedName] = device.createBuffer({
30
- data: typedArray,
31
- id: "".concat(remappedName, "-buffer")
32
- });
33
- }
34
- }
35
- return buffers;
36
- }
37
- function mapAttributeName(name) {
38
- return GLTF_TO_LUMA_ATTRIBUTE_MAP[name] || name;
39
- }
40
- //# sourceMappingURL=model-utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"model-utils.js","names":["Buffer","assert","GLTF_TO_LUMA_ATTRIBUTE_MAP","POSITION","NORMAL","COLOR_0","TEXCOORD_0","TEXCOORD_1","TEXCOORD_2","getIndexBufferFromGeometry","device","geometry","indices","data","value","Uint16Array","Uint32Array","createBuffer","usage","INDEX","getAttributeBuffersFromGeometry","buffers","name","attribute","Object","entries","attributes","remappedName","mapAttributeName","constant","Error","typedArray","id","concat"],"sources":["../../src/model/model-utils.ts"],"sourcesContent":["import {Device, Buffer, assert} from '@luma.gl/core';\nimport type {Geometry} from '../geometry/geometry';\n\n// Support for mapping new geometries with glTF attribute names to \"classic\" luma.gl shader names\nconst GLTF_TO_LUMA_ATTRIBUTE_MAP = {\n POSITION: 'positions',\n NORMAL: 'normals',\n COLOR_0: 'colors',\n TEXCOORD_0: 'texCoords',\n TEXCOORD_1: 'texCoords1',\n TEXCOORD_2: 'texCoords2'\n};\n\n/*\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\nexport function getIndexBufferFromGeometry(device: Device, geometry: Geometry): Buffer | null {\n if (!geometry.indices) {\n return null;\n }\n\n // @ts-expect-error\n const data = geometry.indices.value || geometry.indices;\n assert(\n data instanceof Uint16Array || data instanceof Uint32Array,\n 'attribute array for \"indices\" must be of integer type'\n );\n return device.createBuffer({usage: Buffer.INDEX, data});\n}\n\nexport function getAttributeBuffersFromGeometry(device: Device, geometry: Geometry): Record<string, Buffer> {\n const buffers: Record<string, Buffer> = {};\n\n for (const [name, attribute] of Object.entries(geometry.attributes)) {\n const remappedName = mapAttributeName(name);\n if (attribute?.constant) {\n throw new Error('constant attributes not supported');\n } else {\n const typedArray = attribute?.value;\n buffers[remappedName] = device.createBuffer({data: typedArray, id: `${remappedName}-buffer`});\n }\n }\n\n return buffers;\n}\n\nfunction mapAttributeName(name: string): string {\n // @ts-ignore-error\n return GLTF_TO_LUMA_ATTRIBUTE_MAP[name] || name;\n}\n\n/*\n// Check for well known attribute names\n// eslint-disable-next-line complexity\nexport function inferAttributeAccessor(attributeName, attribute) {\n let category;\n switch (attributeName) {\n case 'texCoords':\n case 'texCoord1':\n case 'texCoord2':\n case 'texCoord3':\n category = 'uvs';\n break;\n case 'vertices':\n case 'positions':\n case 'normals':\n case 'pickingColors':\n category = 'vectors';\n break;\n default:\n }\n\n // Check for categorys\n switch (category) {\n case 'vectors':\n attribute.size = attribute.size || 3;\n break;\n case 'uvs':\n attribute.size = attribute.size || 2;\n break;\n default:\n }\n\n assert(Number.isFinite(attribute.size), `attribute ${attributeName} needs size`);\n}\n*/\n"],"mappings":"AAAA,SAAgBA,MAAM,EAAEC,MAAM,QAAO,eAAe;AAIpD,MAAMC,0BAA0B,GAAG;EACjCC,QAAQ,EAAE,WAAW;EACrBC,MAAM,EAAE,SAAS;EACjBC,OAAO,EAAE,QAAQ;EACjBC,UAAU,EAAE,WAAW;EACvBC,UAAU,EAAE,YAAY;EACxBC,UAAU,EAAE;AACd,CAAC;AA4CD,OAAO,SAASC,0BAA0BA,CAACC,MAAc,EAAEC,QAAkB,EAAiB;EAC5F,IAAI,CAACA,QAAQ,CAACC,OAAO,EAAE;IACrB,OAAO,IAAI;EACb;EAGA,MAAMC,IAAI,GAAGF,QAAQ,CAACC,OAAO,CAACE,KAAK,IAAIH,QAAQ,CAACC,OAAO;EACvDX,MAAM,CACJY,IAAI,YAAYE,WAAW,IAAIF,IAAI,YAAYG,WAAW,EAC1D,uDACF,CAAC;EACD,OAAON,MAAM,CAACO,YAAY,CAAC;IAACC,KAAK,EAAElB,MAAM,CAACmB,KAAK;IAAEN;EAAI,CAAC,CAAC;AACzD;AAEA,OAAO,SAASO,+BAA+BA,CAACV,MAAc,EAAEC,QAAkB,EAA0B;EAC1G,MAAMU,OAA+B,GAAG,CAAC,CAAC;EAE1C,KAAK,MAAM,CAACC,IAAI,EAAEC,SAAS,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACd,QAAQ,CAACe,UAAU,CAAC,EAAE;IACnE,MAAMC,YAAY,GAAGC,gBAAgB,CAACN,IAAI,CAAC;IAC3C,IAAIC,SAAS,aAATA,SAAS,eAATA,SAAS,CAAEM,QAAQ,EAAE;MACvB,MAAM,IAAIC,KAAK,CAAC,mCAAmC,CAAC;IACtD,CAAC,MAAM;MACL,MAAMC,UAAU,GAAGR,SAAS,aAATA,SAAS,uBAATA,SAAS,CAAET,KAAK;MACnCO,OAAO,CAACM,YAAY,CAAC,GAAGjB,MAAM,CAACO,YAAY,CAAC;QAACJ,IAAI,EAAEkB,UAAU;QAAEC,EAAE,KAAAC,MAAA,CAAKN,YAAY;MAAS,CAAC,CAAC;IAC/F;EACF;EAEA,OAAON,OAAO;AAChB;AAEA,SAASO,gBAAgBA,CAACN,IAAY,EAAU;EAE9C,OAAOpB,0BAA0B,CAACoB,IAAI,CAAC,IAAIA,IAAI;AACjD"}
@@ -1,76 +0,0 @@
1
- import type {Device} from '@luma.gl/core';
2
- import type {ShaderModule, HookFunction} from '@luma.gl/shadertools';
3
- import {ShaderAssembler} from '@luma.gl/shadertools';
4
-
5
- export type ModelShaderProps = {
6
- // Model also accepts a string shaders
7
- vs?: {glsl?: string; wgsl?: string} | string | null;
8
- fs?: {glsl?: string; wgsl?: string} | string | null;
9
- /** shadertool shader modules (added to shader code) */
10
- modules?: ShaderModule[];
11
- /** Shadertool module defines (configures shader code)*/
12
- defines?: Record<string, string | number | boolean>;
13
- inject?: Record<string, string>;
14
- hooks?: Record<string, HookFunction>;
15
- transpileToGLSL100?: boolean;
16
-
17
- shaderAssembler: ShaderAssembler;
18
- };
19
-
20
- type GetUniformsFunc = (props?: Record<string, any>) => Record<string, any>;
21
-
22
- /**
23
- * TODO - should this functionality move into shadertools / assembleShaders ?
24
- * @param device
25
- * @param props
26
- * @returns
27
- */
28
- export function buildShaders(
29
- device: Device,
30
- props: ModelShaderProps
31
- ): {
32
- vs: string;
33
- fs: string | undefined;
34
- getUniforms: GetUniformsFunc
35
- } {
36
- if (!props.vs) {
37
- throw new Error('no vertex shader');
38
- }
39
-
40
- // Resolve WGSL vs GLSL
41
- const vs = getShaderSource(device, props.vs);
42
- let fs;
43
- if (props.fs) {
44
- fs = getShaderSource(device, props.fs);
45
- }
46
-
47
- const platformInfo = {
48
- type: device.info.type,
49
- gpu: device.info.gpu,
50
- features: device.features
51
- };
52
-
53
- return props.shaderAssembler.assembleShaders(platformInfo, {...props, fs, vs});
54
- }
55
-
56
- /** Create a shader from the different overloads */
57
- function getShaderSource(device: Device, shader: string | {glsl?: string; wgsl?: string}): string {
58
- // TODO - detect WGSL/GLSL and throw an error if not supported
59
- if (typeof shader === 'string') {
60
- return shader;
61
- }
62
-
63
- switch (device.info.type) {
64
- case 'webgpu':
65
- if (shader?.wgsl) {
66
- return shader.wgsl;
67
- }
68
- throw new Error('WebGPU does not support GLSL shaders');
69
-
70
- default:
71
- if (shader?.glsl) {
72
- return shader.glsl;
73
- }
74
- throw new Error('WebGL does not support WGSL shaders');
75
- }
76
- }