@luma.gl/engine 9.0.0-alpha.21 → 9.0.0-alpha.23

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 (46) hide show
  1. package/dist/animation-loop/animation-loop.d.ts.map +1 -1
  2. package/dist/animation-loop/animation-loop.js +3 -1
  3. package/dist/animation-loop/animation-loop.js.map +1 -1
  4. package/dist/animation-loop/animation-props.d.ts +2 -1
  5. package/dist/animation-loop/animation-props.d.ts.map +1 -1
  6. package/dist/animation-loop/animation-props.js.map +1 -1
  7. package/dist/dist.dev.js +1321 -633
  8. package/dist/index.cjs +110 -29
  9. package/dist/index.d.ts +3 -2
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +2 -1
  12. package/dist/index.js.map +1 -1
  13. package/dist/lib/clip-space.d.ts +1 -1
  14. package/dist/lib/clip-space.d.ts.map +1 -1
  15. package/dist/lib/clip-space.js +1 -1
  16. package/dist/lib/clip-space.js.map +1 -1
  17. package/dist/lib/pipeline-factory.d.ts +1 -1
  18. package/dist/lib/pipeline-factory.d.ts.map +1 -1
  19. package/dist/lib/pipeline-factory.js.map +1 -1
  20. package/dist/model/model-utils.d.ts.map +1 -0
  21. package/dist/model/model-utils.js.map +1 -0
  22. package/dist/{lib → model}/model.d.ts +7 -2
  23. package/dist/model/model.d.ts.map +1 -0
  24. package/dist/{lib → model}/model.js +10 -6
  25. package/dist/model/model.js.map +1 -0
  26. package/dist/transform/transform.d.ts +98 -0
  27. package/dist/transform/transform.d.ts.map +1 -0
  28. package/dist/transform/transform.js +67 -0
  29. package/dist/transform/transform.js.map +1 -0
  30. package/dist.min.js +83 -65
  31. package/package.json +6 -6
  32. package/src/animation-loop/animation-loop.ts +5 -1
  33. package/src/animation-loop/animation-props.ts +2 -1
  34. package/src/index.ts +4 -2
  35. package/src/lib/clip-space.ts +1 -1
  36. package/src/lib/pipeline-factory.ts +1 -1
  37. package/src/{lib → model}/model.ts +16 -7
  38. package/src/transform/transform.ts +246 -0
  39. package/dist/lib/model-utils.d.ts.map +0 -1
  40. package/dist/lib/model-utils.js.map +0 -1
  41. package/dist/lib/model.d.ts.map +0 -1
  42. package/dist/lib/model.js.map +0 -1
  43. package/src/.DS_Store +0 -0
  44. /package/dist/{lib → model}/model-utils.d.ts +0 -0
  45. /package/dist/{lib → model}/model-utils.js +0 -0
  46. /package/src/{lib → model}/model-utils.ts +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luma.gl/engine",
3
- "version": "9.0.0-alpha.21",
3
+ "version": "9.0.0-alpha.23",
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/api": "9.0.0-alpha.21",
44
- "@luma.gl/constants": "9.0.0-alpha.21",
45
- "@luma.gl/shadertools": "9.0.0-alpha.21",
46
- "@luma.gl/webgl": "9.0.0-alpha.21",
43
+ "@luma.gl/api": "9.0.0-alpha.23",
44
+ "@luma.gl/constants": "9.0.0-alpha.23",
45
+ "@luma.gl/shadertools": "9.0.0-alpha.23",
46
+ "@luma.gl/webgl": "9.0.0-alpha.23",
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": "7ee95470a6a2f62753201beb0c36b00e37c70455"
51
+ "gitHead": "5e4a30497333bea4be8f2b3f3db33c0b67931b9c"
52
52
  }
@@ -276,7 +276,7 @@ export class AnimationLoop {
276
276
 
277
277
  _setDisplay(display: any) {
278
278
  if (this.display) {
279
- this.display.delete();
279
+ this.display.destroy();
280
280
  this.display.animationLoop = null;
281
281
  }
282
282
 
@@ -355,8 +355,10 @@ export class AnimationLoop {
355
355
  }
356
356
  this.animationProps = {
357
357
  animationLoop: this,
358
+
358
359
  device: this.device,
359
360
  canvas: this.device?.canvasContext?.canvas,
361
+ renderPass: this.device.getDefaultRenderPass(),
360
362
  timeline: this.timeline,
361
363
 
362
364
  // Initial values
@@ -393,6 +395,8 @@ export class AnimationLoop {
393
395
  return;
394
396
  }
395
397
 
398
+ this.animationProps.renderPass = this.device.getDefaultRenderPass();
399
+
396
400
  const {width, height, aspect} = this._getSizeAndAspect();
397
401
  if (width !== this.animationProps.width || height !== this.animationProps.height) {
398
402
  this.setNeedsRedraw('drawing buffer resized');
@@ -1,10 +1,11 @@
1
- import {Device} from '@luma.gl/api';
1
+ import {Device, RenderPass} from '@luma.gl/api';
2
2
  import {Timeline} from '../animation/timeline'
3
3
  import type {AnimationLoop} from './animation-loop';
4
4
 
5
5
  /** Properties passed to every render frame */
6
6
  export type AnimationProps = {
7
7
  device: Device;
8
+ renderPass: RenderPass;
8
9
  animationLoop: AnimationLoop;
9
10
 
10
11
  /** @todo Should be canvasContext */
package/src/index.ts CHANGED
@@ -13,8 +13,10 @@ export {AnimationLoop} from './animation-loop/animation-loop';
13
13
  export type {MakeAnimationLoopProps} from './animation-loop/make-animation-loop';
14
14
  export {makeAnimationLoop} from './animation-loop/make-animation-loop';
15
15
 
16
- export type {ModelProps} from './lib/model';
17
- export {Model} from './lib/model';
16
+ export type {ModelProps} from './model/model';
17
+ export {Model} from './model/model';
18
+
19
+ export {Transform} from './transform/transform';
18
20
 
19
21
  export {PipelineFactory} from './lib/pipeline-factory';
20
22
 
@@ -3,7 +3,7 @@
3
3
  import GL from '@luma.gl/constants';
4
4
  import {Device, glsl} from '@luma.gl/api';
5
5
  import {WebGLDevice} from '@luma.gl/webgl';
6
- import {Model, ModelProps} from './model';
6
+ import {Model, ModelProps} from '../model/model';
7
7
  import {Geometry} from '../geometry/geometry';
8
8
 
9
9
  const CLIPSPACE_VERTEX_SHADER = glsl`\
@@ -1,5 +1,5 @@
1
1
  import type {RenderPipelineParameters, PrimitiveTopology, ShaderLayout} from '@luma.gl/api';
2
- import {Device, RenderPipeline} from '@luma.gl/api/';
2
+ import {Device, RenderPipeline} from '@luma.gl/api';
3
3
  import type { ShaderModule } from '@luma.gl/shadertools';
4
4
  import {assembleShaders} from '@luma.gl/shadertools';
5
5
 
@@ -5,15 +5,18 @@ import {RenderPipeline} from '@luma.gl/api';
5
5
  import type { ShaderModule } from '@luma.gl/shadertools';
6
6
  import type {Geometry} from '../geometry/geometry';
7
7
  import {getAttributeBuffersFromGeometry, getIndexBufferFromGeometry} from './model-utils';
8
- import {PipelineFactory} from './pipeline-factory';
8
+ import {PipelineFactory} from '../lib/pipeline-factory';
9
9
 
10
10
  export type ModelProps = Omit<RenderPipelineProps, 'vs' | 'fs'> & {
11
11
  // Model also accepts a string
12
12
  vs?: {glsl?: string; wgsl?: string} | string | null;
13
13
  fs?: {glsl?: string; wgsl?: string} | string | null;
14
+ defines?: Record<string, string | number | boolean>;
14
15
  modules?: ShaderModule[];
15
16
  moduleSettings?: Record<string, Record<string, any>>;
16
17
  geometry?: Geometry | null;
18
+ /** deprecated pipeline factory to use to create renderpipelines */
19
+ pipelineFactory?: PipelineFactory;
17
20
  };
18
21
 
19
22
  const DEFAULT_MODEL_PROPS: Required<ModelProps> = {
@@ -23,20 +26,25 @@ const DEFAULT_MODEL_PROPS: Required<ModelProps> = {
23
26
  id: 'unnamed',
24
27
  handle: undefined,
25
28
  userData: {},
29
+ defines: {},
26
30
  modules: [],
27
31
  moduleSettings: {},
28
- geometry: null
32
+ geometry: null,
33
+ pipelineFactory: undefined
29
34
  };
30
35
 
31
36
  /** v9 API */
32
37
  export class Model {
33
38
  readonly device: Device;
34
- readonly pipeline: RenderPipeline;
35
39
  readonly id: string;
36
40
  readonly vs: string;
37
41
  readonly fs: string | null = null;
38
42
  readonly topology: PrimitiveTopology;
39
43
  readonly vertexCount;
44
+
45
+ readonly pipelineFactory: PipelineFactory;
46
+ pipeline: RenderPipeline;
47
+
40
48
  props: Required<ModelProps>;
41
49
 
42
50
  private _getModuleUniforms: (props?: Record<string, Record<string, any>>) => Record<string, any>;
@@ -64,12 +72,13 @@ export class Model {
64
72
  this.topology = this.props.geometry.topology || 'triangle-list';
65
73
  }
66
74
 
67
- const pipelineFactory = PipelineFactory.getDefaultPipelineFactory(this.device);
68
- const {pipeline, getUniforms} = pipelineFactory.createRenderPipeline({
75
+ this.pipelineFactory = this.props.pipelineFactory || PipelineFactory.getDefaultPipelineFactory(this.device);
76
+ const {pipeline, getUniforms} = this.pipelineFactory.createRenderPipeline({
69
77
  ...this.props,
70
78
  vs: this.vs,
71
79
  fs: this.fs,
72
80
  topology: this.topology,
81
+ defines: props.defines,
73
82
  parameters: props.parameters,
74
83
  layout: props.layout
75
84
  });
@@ -85,10 +94,10 @@ export class Model {
85
94
  }
86
95
 
87
96
  destroy(): void {
88
- this.pipeline.destroy();
97
+ this.pipelineFactory.release(this.pipeline);
89
98
  }
90
99
 
91
- draw(renderPass?: RenderPass): this {
100
+ draw(renderPass: RenderPass): this {
92
101
  this.pipeline.draw({
93
102
  renderPass,
94
103
  vertexCount: this.vertexCount,
@@ -0,0 +1,246 @@
1
+ // luma.gl, MIT license
2
+
3
+ import {Device, Buffer, Texture, Framebuffer} from '@luma.gl/api';
4
+ import {getShaderInfo, getPassthroughFS} from '@luma.gl/shadertools';
5
+ import GL from '@luma.gl/constants';
6
+ import {WebGLDevice, GLParameters} from '@luma.gl/webgl';
7
+ import {Model} from '../model/model';
8
+
9
+ // import {AccessorObject} from '@luma.gl/webgl';
10
+ // import {default as TransformFeedback} from '../classic/transform-feedback';
11
+ // import BufferTransform from './buffer-transform';
12
+ // import TextureTransform from './texture-transform';
13
+
14
+ type TransformFeedback = any;
15
+
16
+ /** Properties for creating Transforms */
17
+ export type TransformProps = {
18
+ id?: string;
19
+ vs?: string;
20
+ elementCount?: number;
21
+ sourceBuffers?: Record<string, Buffer>;
22
+ feedbackBuffers?: Record<string, string | Buffer | {buffer: Buffer; byteOffset?: number}>;
23
+ varyings?: string[];
24
+ feedbackMap?: Record<string, string>;
25
+ modules?: object[]; // TODO use ShaderModule type
26
+ attributes?: Record<string, any>;
27
+ uniforms?: Record<string, any>;
28
+ defines?: Record<string, any>
29
+ parameters?: GLParameters;
30
+ discard?: boolean;
31
+ isIndexed?: boolean;
32
+ inject?: Record<string, string>;
33
+ drawMode?: number;
34
+ framebuffer?: Framebuffer;
35
+ _sourceTextures?: Record<string, Texture>;
36
+ _targetTexture?: string | Texture;
37
+ _targetTextureVarying?: string;
38
+ _swapTexture?: string | null;
39
+ _fs?: string;
40
+ fs?: string;
41
+ };
42
+
43
+ /** Options that can be provided when running a Transform */
44
+ export type TransformRunOptions = {
45
+ framebuffer?: Framebuffer;
46
+ clearRenderTarget?: boolean;
47
+ uniforms?: Record<string, any>;
48
+ parameters?: Record<string, any>;
49
+ discard?: boolean;
50
+ };
51
+
52
+ /** Options that control drawing a Transform. Used by subclasses to return draw parameters */
53
+ export type TransformDrawOptions = {
54
+ attributes?: Record<string, any>;
55
+ framebuffer?: any;
56
+ uniforms?: object;
57
+ discard?: boolean;
58
+ parameters?: object;
59
+ transformFeedback?: any;
60
+ };
61
+
62
+ export type TransformBinding = {
63
+ sourceBuffers: Record<string, Buffer>;
64
+ sourceTextures: Record<string, Texture>;
65
+ feedbackBuffers?: Record<string, Buffer | {buffer: Buffer}>;
66
+ transformFeedback?: TransformFeedback;
67
+ framebuffer?: Framebuffer;
68
+ targetTexture?: Texture;
69
+ };
70
+
71
+ /**
72
+ * Takes source and target buffers/textures and sets up the pipeline
73
+ */
74
+ export class Transform {
75
+ /**
76
+ * Check if Transforms are supported (they are not under WebGL1)
77
+ * @todo differentiate writing to buffer vs not
78
+ */
79
+ static isSupported(device: Device | WebGLRenderingContext): boolean {
80
+ // try {
81
+ // const webglDevice = WebGLDevice.attach(device);
82
+ // return webglDevice.isWebGL2;
83
+ // } catch {
84
+ // return false;
85
+ // }
86
+ return false;
87
+ }
88
+
89
+ readonly device: WebGLDevice;
90
+ readonly gl: WebGL2RenderingContext;
91
+ // model: Model;
92
+ elementCount = 0;
93
+ // bufferTransform: BufferTransform | null = null;
94
+ // textureTransform: TextureTransform | null = null;
95
+ elementIDBuffer: Buffer | null = null;
96
+
97
+ constructor(device: Device | WebGLRenderingContext, props: TransformProps = {}) {
98
+ this.device = WebGLDevice.attach(device);
99
+ // TODO assert webgl2?
100
+ this.gl = this.device.gl2;
101
+ this._buildResourceTransforms(props);
102
+
103
+ props = this._updateModelProps(props);
104
+ // @ts-expect-error TODO this is valid type error for params
105
+ this.model = new Model(this.device, {
106
+ ...props,
107
+ fs: props.fs || getPassthroughFS({version: getShaderInfo(props.vs).version}),
108
+ id: props.id || 'transform-model',
109
+ // @ts-expect-error
110
+ drawMode: props.drawMode || GL.POINTS,
111
+ vertexCount: props.elementCount
112
+ });
113
+
114
+ // if (this.bufferTransform) {
115
+ // this.bufferTransform.setupResources({model: this.model});
116
+ // }
117
+ Object.seal(this);
118
+ }
119
+
120
+ /** Delete owned resources. */
121
+ destroy(): void {
122
+ // if (this.model) {
123
+ // this.model.destroy();
124
+ // }
125
+ // if (this.bufferTransform) {
126
+ // this.bufferTransform.destroy();
127
+ // }
128
+ // if (this.textureTransform) {
129
+ // this.textureTransform.destroy();
130
+ // }
131
+ }
132
+
133
+ /** @deprecated Use destroy*() */
134
+ delete(): void {
135
+ this.destroy();
136
+ }
137
+
138
+ /** Run one transform loop. */
139
+ run(options?: TransformRunOptions): void {
140
+ const {clearRenderTarget = true} = options || {};
141
+
142
+ const updatedOpts = this._updateDrawOptions(options);
143
+
144
+ if (clearRenderTarget && updatedOpts.framebuffer) {
145
+ // clear(this.device, {framebuffer: updatedOpts.framebuffer, color: true});
146
+ }
147
+
148
+ // this.model.transform(updatedOpts);
149
+ }
150
+
151
+ /** swap resources if a map is provided */
152
+ swap(): void {
153
+ // let swapped = false;
154
+ // const resourceTransforms = [this.bufferTransform, this.textureTransform].filter(Boolean);
155
+ // for (const resourceTransform of resourceTransforms) {
156
+ // swapped = swapped || Boolean(resourceTransform?.swap());
157
+ // }
158
+ // assert(swapped, 'Nothing to swap');
159
+ }
160
+
161
+ /** Return Buffer object for given varying name. */
162
+ getBuffer(varyingName: string): Buffer | null {
163
+ // return this.bufferTransform && this.bufferTransform.getBuffer(varyingName);
164
+ return null;
165
+ }
166
+
167
+ /** Return data either from Buffer or from Texture */
168
+ getData(options: {packed?: boolean; varyingName?: string} = {}) {
169
+ // const resourceTransforms = [this.bufferTransform, this.textureTransform].filter(Boolean);
170
+ // for (const resourceTransform of resourceTransforms) {
171
+ // const data = resourceTransform?.getData(options);
172
+ // if (data) {
173
+ // return data;
174
+ // }
175
+ // }
176
+ // return null;
177
+ }
178
+
179
+ /** Return framebuffer object if rendering to textures */
180
+ getFramebuffer(): Framebuffer | null {
181
+ // return this.textureTransform?.getFramebuffer() || null;
182
+ return null;
183
+ }
184
+
185
+ /** Update some or all buffer/texture bindings. */
186
+ update(props: TransformProps): void {
187
+ // if (props.elementCount !== undefined) {
188
+ // this.model.setVertexCount(props.elementCount);
189
+ // }
190
+ // const resourceTransforms = [this.bufferTransform, this.textureTransform].filter(Boolean);
191
+ // for (const resourceTransform of resourceTransforms) {
192
+ // resourceTransform?.update(props);
193
+ // }
194
+ }
195
+
196
+ // Private
197
+
198
+ _updateModelProps(props: TransformProps): TransformProps {
199
+ const updatedProps: TransformProps = {...props};
200
+ // const resourceTransforms = [this.bufferTransform, this.textureTransform].filter(Boolean) ;
201
+ // for (const resourceTransform of resourceTransforms) {
202
+ // updatedProps = resourceTransform.updateModelProps(updatedProps);
203
+ // }
204
+ return updatedProps;
205
+ }
206
+
207
+ _buildResourceTransforms(props: TransformProps) {
208
+ // if (canCreateBufferTransform(props)) {
209
+ // this.bufferTransform = new BufferTransform(this.device, props);
210
+ // }
211
+ // if (canCreateTextureTransform(props)) {
212
+ // this.textureTransform = new TextureTransform(this.device, props);
213
+ // }
214
+ // assert(
215
+ // this.bufferTransform || this.textureTransform,
216
+ // 'must provide source/feedback buffers or source/target textures'
217
+ // );
218
+ }
219
+
220
+ _updateDrawOptions(options: TransformRunOptions): TransformDrawOptions {
221
+ const updatedOpts = {...options};
222
+ // const resourceTransforms = [this.bufferTransform, this.textureTransform].filter(Boolean) ;
223
+ // for (const resourceTransform of resourceTransforms) {
224
+ // updatedOpts = Object.assign(updatedOpts, resourceTransform.getDrawOptions(updatedOpts));
225
+ // }
226
+ return updatedOpts;
227
+ }
228
+ }
229
+
230
+ // Helper Methods
231
+
232
+ // function canCreateBufferTransform(props: TransformProps): boolean {
233
+ // const canCreate =
234
+ // (props.feedbackBuffers && !isObjectEmpty(props.feedbackBuffers)) ||
235
+ // (props.feedbackMap && !isObjectEmpty(props.feedbackMap)) ||
236
+ // (props.varyings && props.varyings.length > 0);
237
+ // return Boolean(canCreate);
238
+ // }
239
+
240
+ // function canCreateTextureTransform(props: TransformProps): boolean {
241
+ // const canCreate =
242
+ // (props._sourceTextures && !isObjectEmpty(props._sourceTextures)) ||
243
+ // props._targetTexture ||
244
+ // props._targetTextureVarying;
245
+ // return Boolean(canCreate);
246
+ // }
@@ -1 +0,0 @@
1
- {"version":3,"file":"model-utils.d.ts","sourceRoot":"","sources":["../../src/lib/model-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,MAAM,EAAS,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAsDnD,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,MAAM,GAAG,SAAS,CAYjG;AAED,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAc1G"}
@@ -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","undefined","data","value","Uint16Array","Uint32Array","createBuffer","usage","INDEX","getAttributeBuffersFromGeometry","buffers","name","attribute","Object","entries","attributes","remappedName","mapAttributeName","constant","Error","typedArray","id","concat"],"sources":["../../src/lib/model-utils.ts"],"sourcesContent":["import {Device, Buffer, assert} from '@luma.gl/api';\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 | undefined {\n if (!geometry.indices) {\n return undefined;\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,cAAc;AAInD,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,EAAsB;EACjG,IAAI,CAACA,QAAQ,CAACC,OAAO,EAAE;IACrB,OAAOC,SAAS;EAClB;EAGA,MAAMC,IAAI,GAAGH,QAAQ,CAACC,OAAO,CAACG,KAAK,IAAIJ,QAAQ,CAACC,OAAO;EACvDX,MAAM,CACJa,IAAI,YAAYE,WAAW,IAAIF,IAAI,Y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AC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI;IAMtD,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAMrC,aAAa,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI;IAMvD,uBAAuB;IACvB,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAMpD,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI;IAMhD,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;CAWvC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"model.js","names":["RenderPipeline","getAttributeBuffersFromGeometry","getIndexBufferFromGeometry","PipelineFactory","DEFAULT_MODEL_PROPS","_DEFAULT_PROPS","vs","fs","id","handle","undefined","userData","modules","moduleSettings","geometry","Model","constructor","device","props","_defineProperty","Error","getShaderSource","vertexCount","topology","pipelineFactory","getDefaultPipelineFactory","pipeline","getUniforms","createRenderPipeline","parameters","layout","_getModuleUniforms","_setGeometry","setUniforms","setProps","destroy","draw","renderPass","instanceCount","indices","setIndexBuffer","attributes","setAttributes","bindings","setBindings","uniforms","updateModuleSettings","Object","assign","geometryBuffers","indexBuffer","shader","info","type","wgsl","glsl"],"sources":["../../src/lib/model.ts"],"sourcesContent":["// luma.gl, MIT license\n\nimport type {Device, Buffer, RenderPipelineProps, RenderPass, Binding, PrimitiveTopology} from '@luma.gl/api';\nimport {RenderPipeline} from '@luma.gl/api';\nimport type { ShaderModule } from '@luma.gl/shadertools';\nimport type {Geometry} from '../geometry/geometry';\nimport {getAttributeBuffersFromGeometry, getIndexBufferFromGeometry} from './model-utils';\nimport {PipelineFactory} from './pipeline-factory';\n\nexport type ModelProps = Omit<RenderPipelineProps, 'vs' | 'fs'> & {\n // Model also accepts a string\n vs?: {glsl?: string; wgsl?: string} | string | null;\n fs?: {glsl?: string; wgsl?: string} | string | null;\n modules?: ShaderModule[];\n moduleSettings?: Record<string, Record<string, any>>;\n geometry?: Geometry | null;\n};\n\nconst DEFAULT_MODEL_PROPS: Required<ModelProps> = {\n ...RenderPipeline._DEFAULT_PROPS,\n vs: null,\n fs: null,\n id: 'unnamed',\n handle: undefined,\n userData: {},\n modules: [],\n moduleSettings: {},\n geometry: null\n};\n\n/** v9 API */\nexport class Model {\n readonly device: Device;\n readonly pipeline: RenderPipeline;\n readonly id: string;\n readonly vs: string;\n readonly fs: string | null = null;\n readonly topology: PrimitiveTopology;\n readonly vertexCount;\n props: Required<ModelProps>;\n\n private _getModuleUniforms: (props?: Record<string, Record<string, any>>) => Record<string, any>;\n\n constructor(device: Device, props: ModelProps) {\n this.props = {...DEFAULT_MODEL_PROPS, ...props};\n props = this.props;\n this.id = this.props.id;\n this.device = device;\n\n // Create the pipeline\n if (!props.vs) {\n throw new Error('no vertex shader');\n }\n this.vs = getShaderSource(this.device, props.vs);\n if (props.fs) {\n this.fs = getShaderSource(this.device, props.fs);\n }\n\n this.vertexCount = this.props.vertexCount;\n this.topology = this.props.topology;\n\n if (this.props.geometry) {\n this.vertexCount = this.props.geometry.vertexCount;\n this.topology = this.props.geometry.topology || 'triangle-list';\n }\n\n const pipelineFactory = PipelineFactory.getDefaultPipelineFactory(this.device);\n const {pipeline, getUniforms} = pipelineFactory.createRenderPipeline({\n ...this.props,\n vs: this.vs,\n fs: this.fs,\n topology: this.topology,\n parameters: props.parameters,\n layout: props.layout\n });\n\n this.pipeline = pipeline;\n this._getModuleUniforms = getUniforms;\n\n if (this.props.geometry) {\n this._setGeometry(this.props.geometry);\n }\n this.setUniforms(this._getModuleUniforms()) // Get all default module uniforms\n this.setProps(this.props);\n }\n\n destroy(): void {\n this.pipeline.destroy();\n }\n\n draw(renderPass?: RenderPass): this {\n this.pipeline.draw({\n renderPass,\n vertexCount: this.vertexCount,\n instanceCount: this.props.instanceCount\n });\n return this;\n }\n\n setProps(props: ModelProps): this {\n if (props.indices) {\n this.setIndexBuffer(props.indices);\n }\n if (props.attributes) {\n this.setAttributes(props.attributes);\n }\n if (props.bindings) {\n this.setBindings(props.bindings);\n }\n if (props.uniforms) {\n this.setUniforms(props.uniforms);\n }\n if (props.moduleSettings) {\n this.updateModuleSettings(props.moduleSettings);\n }\n return this;\n }\n\n updateModuleSettings(props: Record<string, any>): this {\n const uniforms = this._getModuleUniforms(props);\n this.setUniforms(uniforms);\n return this;\n }\n\n setIndexBuffer(indices: Buffer): this {\n this.pipeline.setIndexBuffer(indices);\n // this._indices = indices;\n return this;\n }\n\n setAttributes(attributes: Record<string, Buffer>): this {\n this.pipeline.setAttributes(attributes);\n Object.assign(this.props.attributes, attributes);\n return this;\n }\n\n /** Set the bindings */\n setBindings(bindings: Record<string, Binding>): this {\n this.pipeline.setBindings(bindings);\n Object.assign(this.props.bindings, bindings);\n return this;\n }\n\n setUniforms(uniforms: Record<string, any>): this {\n this.pipeline.setUniforms(uniforms);\n Object.assign(this.props.uniforms, uniforms);\n return this;\n }\n\n _setGeometry(geometry: Geometry): void {\n // this._deleteGeometryBuffers();\n\n const geometryBuffers = getAttributeBuffersFromGeometry(this.device, geometry);\n this.setAttributes(geometryBuffers);\n\n const indexBuffer = getIndexBufferFromGeometry(this.device, geometry);\n if (indexBuffer) {\n this.setIndexBuffer(indexBuffer);\n }\n }\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":";AAGA,SAAQA,cAAc,QAAO,cAAc;AAAC,SAGpCC,+BAA+B,EAAEC,0BAA0B;AAAA,SAC3DC,eAA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