@luma.gl/engine 9.0.0-alpha.3 → 9.0.0-alpha.31

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 (148) hide show
  1. package/LICENSE +2 -1
  2. package/dist/animation/key-frames.d.ts +1 -1
  3. package/dist/animation/key-frames.d.ts.map +1 -1
  4. package/dist/animation/key-frames.js +0 -20
  5. package/dist/animation/key-frames.js.map +1 -1
  6. package/dist/animation/timeline.d.ts +5 -5
  7. package/dist/animation/timeline.d.ts.map +1 -1
  8. package/dist/animation/timeline.js +0 -30
  9. package/dist/animation/timeline.js.map +1 -1
  10. package/dist/{lib → animation-loop}/animation-loop.d.ts +28 -29
  11. package/dist/animation-loop/animation-loop.d.ts.map +1 -0
  12. package/dist/{lib → animation-loop}/animation-loop.js +96 -175
  13. package/dist/animation-loop/animation-loop.js.map +1 -0
  14. package/dist/{lib → animation-loop}/animation-props.d.ts +7 -7
  15. package/dist/animation-loop/animation-props.d.ts.map +1 -0
  16. package/dist/animation-loop/animation-props.js.map +1 -0
  17. package/dist/animation-loop/make-animation-loop.d.ts +6 -0
  18. package/dist/animation-loop/make-animation-loop.d.ts.map +1 -0
  19. package/dist/animation-loop/make-animation-loop.js +28 -0
  20. package/dist/animation-loop/make-animation-loop.js.map +1 -0
  21. package/dist/animation-loop/render-loop.d.ts +23 -0
  22. package/dist/animation-loop/render-loop.d.ts.map +1 -0
  23. package/dist/animation-loop/render-loop.js +7 -0
  24. package/dist/animation-loop/render-loop.js.map +1 -0
  25. package/dist/dist.dev.js +14977 -0
  26. package/dist/geometries/cone-geometry.d.ts +1 -1
  27. package/dist/geometries/cone-geometry.d.ts.map +1 -1
  28. package/dist/geometries/cone-geometry.js +6 -5
  29. package/dist/geometries/cone-geometry.js.map +1 -1
  30. package/dist/geometries/cube-geometry.d.ts +2 -2
  31. package/dist/geometries/cube-geometry.d.ts.map +1 -1
  32. package/dist/geometries/cube-geometry.js +15 -8
  33. package/dist/geometries/cube-geometry.js.map +1 -1
  34. package/dist/geometries/cylinder-geometry.d.ts +1 -1
  35. package/dist/geometries/cylinder-geometry.d.ts.map +1 -1
  36. package/dist/geometries/cylinder-geometry.js +6 -5
  37. package/dist/geometries/cylinder-geometry.js.map +1 -1
  38. package/dist/geometries/ico-sphere-geometry.d.ts +2 -2
  39. package/dist/geometries/ico-sphere-geometry.d.ts.map +1 -1
  40. package/dist/geometries/ico-sphere-geometry.js +9 -18
  41. package/dist/geometries/ico-sphere-geometry.js.map +1 -1
  42. package/dist/geometries/plane-geometry.d.ts +2 -2
  43. package/dist/geometries/plane-geometry.d.ts.map +1 -1
  44. package/dist/geometries/plane-geometry.js +10 -19
  45. package/dist/geometries/plane-geometry.js.map +1 -1
  46. package/dist/geometries/sphere-geometry.d.ts +2 -2
  47. package/dist/geometries/sphere-geometry.d.ts.map +1 -1
  48. package/dist/geometries/sphere-geometry.js +9 -13
  49. package/dist/geometries/sphere-geometry.js.map +1 -1
  50. package/dist/geometries/truncated-cone-geometry.d.ts +2 -2
  51. package/dist/geometries/truncated-cone-geometry.d.ts.map +1 -1
  52. package/dist/geometries/truncated-cone-geometry.js +9 -14
  53. package/dist/geometries/truncated-cone-geometry.js.map +1 -1
  54. package/dist/geometry/geometry-table.d.ts +2 -2
  55. package/dist/geometry/geometry-table.d.ts.map +1 -1
  56. package/dist/geometry/geometry-table.js.map +1 -1
  57. package/dist/geometry/geometry-utils.d.ts.map +1 -1
  58. package/dist/geometry/geometry-utils.js +0 -9
  59. package/dist/geometry/geometry-utils.js.map +1 -1
  60. package/dist/geometry/geometry.d.ts +35 -58
  61. package/dist/geometry/geometry.d.ts.map +1 -1
  62. package/dist/geometry/geometry.js +26 -89
  63. package/dist/geometry/geometry.js.map +1 -1
  64. package/dist/geometry/primitive-utils.js.map +1 -1
  65. package/dist/index.cjs +2576 -0
  66. package/dist/index.d.ts +18 -9
  67. package/dist/index.d.ts.map +1 -1
  68. package/dist/index.js +20 -13
  69. package/dist/index.js.map +1 -1
  70. package/dist/lib/clip-space.d.ts +8 -0
  71. package/dist/lib/clip-space.d.ts.map +1 -1
  72. package/dist/lib/clip-space.js +36 -1
  73. package/dist/lib/clip-space.js.map +1 -1
  74. package/dist/lib/pipeline-factory.d.ts +19 -14
  75. package/dist/lib/pipeline-factory.d.ts.map +1 -1
  76. package/dist/lib/pipeline-factory.js +52 -63
  77. package/dist/lib/pipeline-factory.js.map +1 -1
  78. package/dist/{lib → model}/model-utils.d.ts +2 -2
  79. package/dist/model/model-utils.d.ts.map +1 -0
  80. package/dist/{lib → model}/model-utils.js +3 -8
  81. package/dist/model/model-utils.js.map +1 -0
  82. package/dist/model/model.d.ts +67 -0
  83. package/dist/model/model.d.ts.map +1 -0
  84. package/dist/{lib → model}/model.js +59 -76
  85. package/dist/model/model.js.map +1 -0
  86. package/dist/scenegraph/group-node.d.ts +21 -0
  87. package/dist/scenegraph/group-node.d.ts.map +1 -0
  88. package/dist/scenegraph/group-node.js +95 -0
  89. package/dist/scenegraph/group-node.js.map +1 -0
  90. package/dist/scenegraph/model-node.d.ts +18 -0
  91. package/dist/scenegraph/model-node.d.ts.map +1 -0
  92. package/dist/scenegraph/model-node.js +29 -0
  93. package/dist/scenegraph/model-node.js.map +1 -0
  94. package/dist/scenegraph/scenegraph-node.d.ts +56 -0
  95. package/dist/scenegraph/scenegraph-node.d.ts.map +1 -0
  96. package/dist/scenegraph/scenegraph-node.js +142 -0
  97. package/dist/scenegraph/scenegraph-node.js.map +1 -0
  98. package/dist/transform/transform.d.ts +98 -0
  99. package/dist/transform/transform.d.ts.map +1 -0
  100. package/dist/transform/transform.js +67 -0
  101. package/dist/transform/transform.js.map +1 -0
  102. package/dist.min.js +314 -0
  103. package/package.json +22 -12
  104. package/src/animation/timeline.ts +2 -2
  105. package/src/{lib → animation-loop}/animation-loop.ts +115 -97
  106. package/src/{lib → animation-loop}/animation-props.ts +6 -5
  107. package/src/animation-loop/make-animation-loop.ts +44 -0
  108. package/src/animation-loop/render-loop.ts +23 -0
  109. package/src/geometries/cone-geometry.ts +1 -1
  110. package/src/geometries/cube-geometry.ts +6 -3
  111. package/src/geometries/cylinder-geometry.ts +2 -2
  112. package/src/geometries/ico-sphere-geometry.ts +7 -6
  113. package/src/geometries/plane-geometry.ts +5 -4
  114. package/src/geometries/sphere-geometry.ts +4 -3
  115. package/src/geometries/truncated-cone-geometry.ts +4 -3
  116. package/src/geometry/geometry-table.ts +1 -1
  117. package/src/geometry/geometry-utils.ts +3 -3
  118. package/src/geometry/geometry.ts +72 -115
  119. package/src/index.ts +28 -12
  120. package/src/lib/clip-space.ts +17 -15
  121. package/src/lib/pipeline-factory.ts +60 -50
  122. package/src/{lib → model}/model-utils.ts +5 -4
  123. package/src/model/model.ts +230 -0
  124. package/src/scenegraph/group-node.ts +103 -0
  125. package/src/scenegraph/model-node.ts +50 -0
  126. package/src/scenegraph/scenegraph-node.ts +204 -0
  127. package/src/transform/transform.ts +246 -0
  128. package/dist/bundle.d.ts +0 -2
  129. package/dist/bundle.d.ts.map +0 -1
  130. package/dist/bundle.js +0 -5
  131. package/dist/bundle.js.map +0 -1
  132. package/dist/lib/animation-loop.d.ts.map +0 -1
  133. package/dist/lib/animation-loop.js.map +0 -1
  134. package/dist/lib/animation-props.d.ts.map +0 -1
  135. package/dist/lib/animation-props.js.map +0 -1
  136. package/dist/lib/model-utils.d.ts.map +0 -1
  137. package/dist/lib/model-utils.js.map +0 -1
  138. package/dist/lib/model.d.ts +0 -41
  139. package/dist/lib/model.d.ts.map +0 -1
  140. package/dist/lib/model.js.map +0 -1
  141. package/dist/lib/render-loop.d.ts +0 -14
  142. package/dist/lib/render-loop.d.ts.map +0 -1
  143. package/dist/lib/render-loop.js +0 -49
  144. package/dist/lib/render-loop.js.map +0 -1
  145. package/src/bundle.ts +0 -4
  146. package/src/lib/model.ts +0 -179
  147. package/src/lib/render-loop.ts +0 -58
  148. /package/dist/{lib → animation-loop}/animation-props.js +0 -0
@@ -0,0 +1,204 @@
1
+ import {assert, uid, NumericArray} from '@luma.gl/core';
2
+ import {Vector3, Matrix4} from '@math.gl/core';
3
+
4
+ /** Properties for creating a new Scenegraph */
5
+ export type ScenegraphNodeProps = {
6
+ id?: string;
7
+ /** whether to display the object at all */
8
+ display?: boolean;
9
+ matrix?: NumericArray;
10
+ position?: NumericArray;
11
+ rotation?: NumericArray;
12
+ scale?: NumericArray;
13
+ update?: boolean
14
+ };
15
+
16
+ export class ScenegraphNode {
17
+ readonly id: string;
18
+ matrix: Matrix4 = new Matrix4();
19
+
20
+ display = true;
21
+ position = new Vector3();
22
+ rotation = new Vector3();
23
+ scale = new Vector3(1, 1, 1);
24
+ userData: Record<string, unknown> = {};
25
+
26
+ props: ScenegraphNodeProps = {};
27
+
28
+ constructor(props: ScenegraphNodeProps = {}) {
29
+ const {id} = props;
30
+
31
+ this.id = id || uid(this.constructor.name);
32
+
33
+ this._setScenegraphNodeProps(props);
34
+ }
35
+
36
+ getBounds(): [number[], number[]] | null {
37
+ return null;
38
+ }
39
+
40
+ destroy(): void {}
41
+
42
+ /** @deprecated use .destroy() */
43
+ delete(): void {
44
+ this.destroy();
45
+ }
46
+ setProps(props: ScenegraphNodeProps): this {
47
+ this._setScenegraphNodeProps(props);
48
+ return this;
49
+ }
50
+
51
+ toString(): string {
52
+ return `{type: ScenegraphNode, id: ${this.id})}`;
53
+ }
54
+
55
+ setPosition(position: any): this {
56
+ assert(position.length === 3, 'setPosition requires vector argument');
57
+ this.position = position;
58
+ return this;
59
+ }
60
+
61
+ setRotation(rotation: any): this {
62
+ assert(rotation.length === 3, 'setRotation requires vector argument');
63
+ this.rotation = rotation;
64
+ return this;
65
+ }
66
+
67
+ setScale(scale: any): this {
68
+ assert(scale.length === 3, 'setScale requires vector argument');
69
+ this.scale = scale;
70
+ return this;
71
+ }
72
+
73
+ setMatrix(matrix: any, copyMatrix: boolean = true): void {
74
+ if (copyMatrix) {
75
+ this.matrix.copy(matrix);
76
+ } else {
77
+ this.matrix = matrix;
78
+ }
79
+ }
80
+
81
+ setMatrixComponents(components: {
82
+ position?: any;
83
+ rotation?: any;
84
+ scale?: any;
85
+ update?: boolean;
86
+ }): this {
87
+ const {position, rotation, scale, update = true} = components;
88
+ if (position) {
89
+ this.setPosition(position);
90
+ }
91
+ if (rotation) {
92
+ this.setRotation(rotation);
93
+ }
94
+ if (scale) {
95
+ this.setScale(scale);
96
+ }
97
+ if (update) {
98
+ this.updateMatrix();
99
+ }
100
+ return this;
101
+ }
102
+
103
+ updateMatrix(): this {
104
+ const pos = this.position;
105
+ const rot = this.rotation;
106
+ const scale = this.scale;
107
+
108
+ this.matrix.identity();
109
+ this.matrix.translate(pos);
110
+ this.matrix.rotateXYZ(rot);
111
+ this.matrix.scale(scale);
112
+ return this;
113
+ }
114
+
115
+ update(options: {position?: any; rotation?: any; scale?: any} = {}): this {
116
+ const {position, rotation, scale} = options;
117
+ if (position) {
118
+ this.setPosition(position);
119
+ }
120
+ if (rotation) {
121
+ this.setRotation(rotation);
122
+ }
123
+ if (scale) {
124
+ this.setScale(scale);
125
+ }
126
+ this.updateMatrix();
127
+ return this;
128
+ }
129
+
130
+ getCoordinateUniforms(
131
+ viewMatrix: any,
132
+ modelMatrix?: any
133
+ ): {
134
+ viewMatrix: any;
135
+ modelMatrix: any;
136
+ objectMatrix: any;
137
+ worldMatrix: any;
138
+ worldInverseMatrix: any;
139
+ worldInverseTransposeMatrix: any;
140
+ } {
141
+ // TODO - solve multiple class problem
142
+ // assert(viewMatrix instanceof Matrix4);
143
+ assert(viewMatrix);
144
+ modelMatrix = modelMatrix || this.matrix;
145
+ const worldMatrix = new Matrix4(viewMatrix).multiplyRight(modelMatrix);
146
+ const worldInverse = worldMatrix.invert();
147
+ const worldInverseTranspose = worldInverse.transpose();
148
+
149
+ return {
150
+ viewMatrix,
151
+ modelMatrix,
152
+ objectMatrix: modelMatrix,
153
+ worldMatrix,
154
+ worldInverseMatrix: worldInverse,
155
+ worldInverseTransposeMatrix: worldInverseTranspose
156
+ };
157
+ }
158
+
159
+ // TODO - copied code, not yet vetted
160
+ /*
161
+ transform() {
162
+ if (!this.parent) {
163
+ this.endPosition.set(this.position);
164
+ this.endRotation.set(this.rotation);
165
+ this.endScale.set(this.scale);
166
+ } else {
167
+ const parent = this.parent;
168
+ this.endPosition.set(this.position.add(parent.endPosition));
169
+ this.endRotation.set(this.rotation.add(parent.endRotation));
170
+ this.endScale.set(this.scale.add(parent.endScale));
171
+ }
172
+
173
+ const ch = this.children;
174
+ for (let i = 0; i < ch.length; ++i) {
175
+ ch[i].transform();
176
+ }
177
+
178
+ return this;
179
+ }
180
+ */
181
+
182
+ _setScenegraphNodeProps(props: ScenegraphNodeProps): void {
183
+ if ('display' in props) {
184
+ this.display = props.display;
185
+ }
186
+
187
+ if ('position' in props) {
188
+ this.setPosition(props.position);
189
+ }
190
+ if ('rotation' in props) {
191
+ this.setRotation(props.rotation);
192
+ }
193
+ if ('scale' in props) {
194
+ this.setScale(props.scale);
195
+ }
196
+
197
+ // Matrix overwrites other props
198
+ if ('matrix' in props) {
199
+ this.setMatrix(props.matrix);
200
+ }
201
+
202
+ Object.assign(this.props, props);
203
+ }
204
+ }
@@ -0,0 +1,246 @@
1
+ // luma.gl, MIT license
2
+
3
+ import {Device, Buffer, Texture, Framebuffer} from '@luma.gl/core';
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
+ // }
package/dist/bundle.d.ts DELETED
@@ -1,2 +0,0 @@
1
- declare const moduleExports: any;
2
- //# sourceMappingURL=bundle.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AACA,QAAA,MAAM,aAAa,KAAqB,CAAC"}
package/dist/bundle.js DELETED
@@ -1,5 +0,0 @@
1
- const moduleExports = require('./index');
2
-
3
- globalThis.luma = globalThis.luma || {};
4
- module.exports = Object.assign(globalThis.luma, moduleExports);
5
- //# sourceMappingURL=bundle.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/bundle.ts"],"names":["moduleExports","require","globalThis","luma","module","exports","Object","assign"],"mappings":"AACA,MAAMA,aAAa,GAAGC,OAAO,CAAC,SAAD,CAA7B;;AACAC,UAAU,CAACC,IAAX,GAAkBD,UAAU,CAACC,IAAX,IAAmB,EAArC;AACAC,MAAM,CAACC,OAAP,GAAiBC,MAAM,CAACC,MAAP,CAAcL,UAAU,CAACC,IAAzB,EAA+BH,aAA/B,CAAjB","sourcesContent":["// @ts-nocheck\nconst moduleExports = require('./index');\nglobalThis.luma = globalThis.luma || {};\nmodule.exports = Object.assign(globalThis.luma, moduleExports);\n"],"file":"bundle.js"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"animation-loop.d.ts","sourceRoot":"","sources":["../../src/lib/animation-loop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,MAAM,EAAE,WAAW,EAAC,MAAM,cAAc,CAAC;AAEvD,OAAO,EAAC,QAAQ,EAAC,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAC,cAAc,EAAC,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAC,KAAK,EAAE,IAAI,EAAC,MAAM,iBAAiB,CAAC;AAS5C,+BAA+B;AAC/B,oBAAY,kBAAkB,GAAG;IAC/B,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACzD,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,cAAc,KAAK,MAAM,CAAC;IAC5C,YAAY,CAAC,EAAE,CAAC,cAAc,EAAE,cAAc,KAAK,IAAI,CAAC;IACxD,QAAQ,CAAC,EAAE,CAAC,cAAc,EAAE,cAAc,KAAK,IAAI,CAAC;IACpD,UAAU,CAAC,EAAE,CAAC,cAAc,EAAE,cAAc,KAAK,IAAI,CAAC;IACtD,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,KAAK,IAAI,CAAC;IAElC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,KAAK,CAAC,EAAE,KAAK,CAAC;IAGd,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC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G,OAAO,CAAC,MAAM,CAAC;IAIzD,YAAY,CAAC,cAAc,EAAE,cAAc,GAAG,EAAE,GAAG,IAAI;IAIvD,QAAQ,CAAC,cAAc,EAAE,cAAc;IAIvC,UAAU,CAAC,cAAc,EAAE,cAAc;IAMzC,WAAW;IAcX,WAAW,CAAC,OAAO,KAAA;IAcnB,sBAAsB;IActB,qBAAqB;IAerB,eAAe;IAUf,YAAY,CAAC,KAAK,EAAE,cAAc;IAYlC,iBAAiB;IAIjB,WAAW;IAMX,uBAAuB;IA6BvB,mBAAmB;IA+BnB,yFAAyF;IACnF,aAAa;IAQnB,cAAc;IAoBd,iBAAiB;;;;;IAmBjB,6BAA6B;IAC7B,eAAe;IAQf;;;OAGG;IACH,0BAA0B;IAM1B,YAAY;IAuBZ,UAAU;IAWV,mBAAmB;IAOnB,YAAY,CAAC,CAAC,KAAA;IAGd,aAAa,CAAC,CAAC,KAAA;CAGhB"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/lib/animation-loop.ts"],"names":["luma","requestAnimationFrame","cancelAnimationFrame","isBrowser","isPage","document","statIdCounter","DEFAULT_ANIMATION_LOOP_PROPS","onCreateDevice","props","createDevice","onAddHTML","undefined","onInitialize","onRender","onFinalize","onError","error","console","device","deviceProps","debug","stats","get","useDevicePixels","autoResizeViewport","autoResizeDrawingBuffer","AnimationLoop","constructor","gl","cpuTime","gpuTime","frameRate","setProps","start","bind","stop","_onMousemove","_onMouseleave","destroy","_setDisplay","delete","setNeedsRedraw","reason","needsRedraw","_running","appContext","_initialized","_createDevice","_initialize","animationProps","_cancelAnimationFrame","_requestAnimationFrame","err","Error","redraw","isLost","_beginTimers","_setupFrame","_updateCallbackData","_renderFrame","_clearNeedsRedraw","_resolveNextFrame","_nextFramePromise","_endTimers","attachTimeline","timeline","detachTimeline","waitForRender","Promise","resolve","toDataURL","canvas","_startEventHandling","_initializeCallbackData","_resizeCanvasDrawingBuffer","_resizeViewport","display","animationLoop","_animationFrameId","_animationFrame","canvasContext","width","height","aspect","time","startTime","Date","now","engineTime","tick","tock","_mousePosition","_getSizeAndAspect","update","Math","floor","getTime","_createInfoDiv","wrapperDiv","createElement","body","appendChild","style","position","div","left","bottom","background","html","innerHTML","getPixelSize","clientHeight","clientWidth","viewport","drawingBufferWidth","drawingBufferHeight","resize","timeEnd","timeStart","addEventListener","e","offsetX","offsetY"],"mappings":";AAAA,SAAQA,IAAR,QAAwC,cAAxC;AACA,SAAQC,qBAAR,EAA+BC,oBAA/B,QAA0D,cAA1D;AAIA,SAAQC,SAAR,QAAwB,eAAxB;AAEA,MAAMC,MAAM,GAAGD,SAAS,MAAM,OAAOE,QAAP,KAAoB,WAAlD;AAEA,IAAIC,aAAa,GAAG,CAApB;AAwBA,MAAMC,4BAA0D,GAAG;AACjEC,EAAAA,cAAc,EAAGC,KAAD,IAAyCT,IAAI,CAACU,YAAL,CAAkBD,KAAlB,CADQ;AAEjEE,EAAAA,SAAS,EAAEC,SAFsD;AAGjEC,EAAAA,YAAY,EAAE,OAAO,EAAP,CAHmD;AAIjEC,EAAAA,QAAQ,EAAE,MAAM,CAAE,CAJ+C;AAKjEC,EAAAA,UAAU,EAAE,MAAM,CAAE,CAL6C;AAMjEC,EAAAA,OAAO,EAAGC,KAAD,IAAWC,OAAO,CAACD,KAAR,CAAcA,KAAd,CAN6C;AAQjEE,EAAAA,MAAM,EAAEP,SARyD;AASjEQ,EAAAA,WAAW,EAAE,EAToD;AAUjEC,EAAAA,KAAK,EAAE,KAV0D;AAWjEC,EAAAA,KAAK,EAAEtB,IAAI,CAACsB,KAAL,CAAWC,GAAX,0BAAiCjB,aAAa,EAA9C,EAX0D;AAcjEkB,EAAAA,eAAe,EAAE,IAdgD;AAejEC,EAAAA,kBAAkB,EAAE,IAf6C;AAgBjEC,EAAAA,uBAAuB,EAAE;AAhBwC,CAAnE;AAoBA,eAAe,MAAMC,aAAN,CAAoB;AA4BjCC,EAAAA,WAAW,CAACnB,KAAyB,GAAG,EAA7B,EAAiC;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GAAG;AACX,SAAKlC,OAAL,CAAawF,OAAb;AAMD;;AAID7C,EAAAA,mBAAmB,GAAG;AACpB,QAAI,KAAKD,MAAT,EAAiB;AACf,WAAKA,MAAL,CAAYgD,gBAAZ,CAA6B,WAA7B,EAA0C,KAAKnF,YAA/C;AACA,WAAKmC,MAAL,CAAYgD,gBAAZ,CAA6B,YAA7B,EAA2C,KAAKlF,aAAhD;AACD;AACF;;AAEDD,EAAAA,YAAY,CAACoF,CAAD,EAAI;AACd,SAAKvE,cAAL,CAAoB0C,cAApB,GAAqC,CAAC6B,CAAC,CAACC,OAAH,EAAYD,CAAC,CAACE,OAAd,CAArC;AACD;;AACDrF,EAAAA,aAAa,CAACmF,CAAD,EAAI;AACf,SAAKvE,cAAL,CAAoB0C,cAApB,GAAqC,IAArC;AACD;;AAhegC","sourcesContent":["import {luma, Device, DeviceProps} from '@luma.gl/api';\nimport {requestAnimationFrame, cancelAnimationFrame} from '@luma.gl/api';\nimport {Timeline} from '../animation/timeline';\nimport {AnimationProps} from '../lib/animation-props';\nimport {Stats, Stat} from '@probe.gl/stats';\nimport {isBrowser} from '@probe.gl/env';\n\nconst isPage = isBrowser() && typeof document !== 'undefined';\n\nlet statIdCounter = 0;\n\ntype ContextProps = DeviceProps;\n\n/** AnimationLoop properties */\nexport type AnimationLoopProps = {\n onCreateDevice?: (props: DeviceProps) => Promise<Device>;\n onAddHTML?: (div: HTMLDivElement) => string; // innerHTML\n onInitialize?: (animationProps: AnimationProps) => void;\n onRender?: (animationProps: AnimationProps) => void;\n onFinalize?: (animationProps: AnimationProps) => void;\n onError?: (reason: Error) => void;\n\n device?: Device;\n deviceProps?: DeviceProps;\n stats?: Stats;\n\n // view parameters\n debug?: boolean;\n autoResizeViewport?: boolean;\n autoResizeDrawingBuffer?: boolean;\n useDevicePixels?: number | boolean;\n};\n\nconst DEFAULT_ANIMATION_LOOP_PROPS: Required<AnimationLoopProps> = {\n onCreateDevice: (props: DeviceProps): Promise<Device> => luma.createDevice(props),\n onAddHTML: undefined,\n onInitialize: () => ({}),\n onRender: () => {},\n onFinalize: () => {},\n onError: (error) => console.error(error), // eslint-disable-line no-console\n\n device: undefined,\n deviceProps: {},\n debug: false,\n stats: luma.stats.get(`animation-loop-${statIdCounter++}`),\n\n // view parameters\n useDevicePixels: true,\n autoResizeViewport: true,\n autoResizeDrawingBuffer: true,\n};\n\n/** Convenient animation loop */\nexport default class AnimationLoop {\n device: Device;\n canvas: HTMLCanvasElement; // | OffscreenCanvas;\n\n props: Required<AnimationLoopProps>;\n animationProps: AnimationProps;\n timeline: Timeline = null;\n stats: Stats;\n cpuTime: Stat;\n gpuTime: Stat;\n frameRate: Stat;\n\n display: any;\n\n needsRedraw: string | null = 'initialized';\n\n _initialized: boolean = false;\n _running: boolean = false;\n _animationFrameId = null;\n _nextFramePromise: Promise<AnimationLoop> | null = null;\n _resolveNextFrame: ((AnimationLoop) => void) | null = null;\n _cpuStartTime: number = 0;\n\n // _gpuTimeQuery: Query | null = null;\n\n /*\n * @param {HTMLCanvasElement} canvas - if provided, width and height will be passed to context\n */\n constructor(props: AnimationLoopProps = {}) {\n this.props = {...DEFAULT_ANIMATION_LOOP_PROPS, ...props};\n props = this.props;\n\n let {useDevicePixels = true} = this.props;\n\n // state\n this.device = props.device;\n // @ts-expect-error\n this.gl = (this.device && this.device.gl) || props.gl;\n\n this.stats = props.stats;\n this.cpuTime = this.stats.get('CPU Time');\n this.gpuTime = this.stats.get('GPU Time');\n this.frameRate = this.stats.get('Frame Rate');\n\n this.setProps({\n autoResizeViewport: props.autoResizeViewport,\n autoResizeDrawingBuffer: props.autoResizeDrawingBuffer,\n useDevicePixels\n });\n\n // Bind methods\n this.start = this.start.bind(this);\n this.stop = this.stop.bind(this);\n\n this._onMousemove = this._onMousemove.bind(this);\n this._onMouseleave = this._onMouseleave.bind(this);\n }\n\n destroy(): void {\n this.stop();\n this._setDisplay(null);\n }\n\n /** @deprecated Use .destroy() */\n delete(): void {\n this.destroy();\n }\n\n setNeedsRedraw(reason: string): this {\n this.needsRedraw = this.needsRedraw || reason;\n return this;\n }\n\n // TODO - move to CanvasContext\n setProps(props: AnimationLoopProps): this {\n if ('autoResizeViewport' in props) {\n this.props.autoResizeViewport = props.autoResizeViewport;\n }\n if ('autoResizeDrawingBuffer' in props) {\n this.props.autoResizeDrawingBuffer = props.autoResizeDrawingBuffer;\n }\n if ('useDevicePixels' in props) {\n this.props.useDevicePixels = props.useDevicePixels;\n }\n return this;\n }\n\n /** Starts a render loop if not already running */\n async start() {\n if (this._running) {\n return this;\n }\n this._running = true;\n\n try {\n // check that we haven't been stopped\n if (!this._running) {\n return null;\n }\n\n let appContext;\n if (!this._initialized) {\n this._initialized = true;\n // Create the WebGL context\n await this._createDevice();\n this._initialize();\n\n // Note: onIntialize can return a promise (e.g. in case app needs to load resources)\n await this.onInitialize(this.animationProps);\n }\n\n // check that we haven't been stopped\n if (!this._running) {\n return null;\n }\n\n // Start the loop\n if (appContext !== false) {\n // cancel any pending renders to ensure only one loop can ever run\n this._cancelAnimationFrame();\n this._requestAnimationFrame();\n }\n\n return this;\n } catch (err: unknown) {\n const error = err instanceof Error ? err : new Error('Unknown error')\n this.props.onError(error);\n // this._running = false; // TODO\n throw error;\n }\n }\n\n /** Explicitly draw a frame */\n redraw(): this {\n if (this.device.isLost) {\n return this;\n }\n\n this._beginTimers();\n\n this._setupFrame();\n this._updateCallbackData();\n\n this._renderFrame(this.animationProps);\n\n // clear needsRedraw flag\n this._clearNeedsRedraw();\n\n if (this._resolveNextFrame) {\n this._resolveNextFrame(this);\n this._nextFramePromise = null;\n this._resolveNextFrame = null;\n }\n\n this._endTimers();\n\n return this;\n }\n\n // Stops a render loop if already running, finalizing\n stop() {\n // console.debug(`Stopping ${this.constructor.name}`);\n if (this._running) {\n // call callback\n this.onFinalize(this.animationProps);\n\n this._cancelAnimationFrame();\n this._nextFramePromise = null;\n this._resolveNextFrame = null;\n this._running = false;\n }\n return this;\n }\n\n attachTimeline(timeline: Timeline): Timeline {\n this.timeline = timeline;\n return this.timeline;\n }\n\n detachTimeline(): void {\n this.timeline = null;\n }\n\n waitForRender(): Promise<AnimationLoop> {\n this.setNeedsRedraw('waitForRender');\n\n if (!this._nextFramePromise) {\n this._nextFramePromise = new Promise((resolve) => {\n this._resolveNextFrame = resolve;\n });\n }\n return this._nextFramePromise;\n }\n\n async toDataURL() {\n this.setNeedsRedraw('toDataURL');\n await this.waitForRender();\n return this.canvas.toDataURL();\n }\n\n onCreateDevice(deviceProps: DeviceProps): Promise<Device> {\n return this.props.onCreateDevice(deviceProps);\n }\n\n onInitialize(animationProps: AnimationProps): {} | void {\n return this.props.onInitialize(animationProps);\n }\n\n onRender(animationProps: AnimationProps) {\n return this.props.onRender(animationProps);\n }\n\n onFinalize(animationProps: AnimationProps) {\n return this.props.onFinalize(animationProps);\n }\n\n // PRIVATE METHODS\n\n _initialize() {\n this._startEventHandling();\n\n // Initialize the callback data\n this._initializeCallbackData();\n this._updateCallbackData();\n\n // Default viewport setup, in case onInitialize wants to render\n this._resizeCanvasDrawingBuffer();\n this._resizeViewport();\n\n // this._gpuTimeQuery = Query.isSupported(this.gl, ['timers']) ? new Query(this.gl) : null;\n }\n\n _setDisplay(display) {\n if (this.display) {\n this.display.delete();\n this.display.animationLoop = null;\n }\n\n // store animation loop on the display\n if (display) {\n display.animationLoop = this;\n }\n\n this.display = display;\n }\n\n _requestAnimationFrame() {\n if (!this._running) {\n return;\n }\n\n // VR display has a separate animation frame to sync with headset\n // TODO WebVR API discontinued, replaced by WebXR: https://immersive-web.github.io/webxr/\n // See https://developer.mozilla.org/en-US/docs/Web/API/VRDisplay/requestAnimationFrame\n // if (this.display && this.display.requestAnimationFrame) {\n // this._animationFrameId = this.display.requestAnimationFrame(this._animationFrame.bind(this));\n // }\n this._animationFrameId = requestAnimationFrame(this._animationFrame.bind(this));\n }\n\n _cancelAnimationFrame() {\n if (this._animationFrameId !== null) {\n return;\n }\n\n // VR display has a separate animation frame to sync with headset\n // TODO WebVR API discontinued, replaced by WebXR: https://immersive-web.github.io/webxr/\n // See https://developer.mozilla.org/en-US/docs/Web/API/VRDisplay/requestAnimationFrame\n // if (this.display && this.display.cancelAnimationFrame) {\n // this.display.cancelAnimationFrame(this._animationFrameId);\n // }\n cancelAnimationFrame(this._animationFrameId);\n this._animationFrameId = null;\n }\n\n _animationFrame() {\n if (!this._running) {\n return;\n }\n this.redraw();\n this._requestAnimationFrame();\n }\n\n // Called on each frame, can be overridden to call onRender multiple times\n // to support e.g. stereoscopic rendering\n _renderFrame(props: AnimationProps) {\n // Allow e.g. VR display to render multiple frames.\n if (this.display) {\n this.display._renderFrame(props);\n return;\n }\n\n // call callback\n this.onRender(props);\n // end callback\n }\n\n _clearNeedsRedraw() {\n this.needsRedraw = null;\n }\n\n _setupFrame() {\n this._resizeCanvasDrawingBuffer();\n this._resizeViewport();\n }\n\n // Initialize the object that will be passed to app callbacks\n _initializeCallbackData() {\n this.animationProps = {\n animationLoop: this,\n device: this.device,\n canvas: this.device.canvasContext.canvas,\n timeline: this.timeline,\n\n // Initial values\n useDevicePixels: this.props.useDevicePixels,\n needsRedraw: null,\n\n // Placeholders\n width: 1,\n height: 1,\n aspect: 1,\n\n // Animation props\n time: 0,\n startTime: Date.now(),\n engineTime: 0,\n tick: 0,\n tock: 0,\n\n // Experimental\n _mousePosition: null // Event props\n };\n }\n\n // Update the context object that will be passed to app callbacks\n _updateCallbackData() {\n const {width, height, aspect} = this._getSizeAndAspect();\n if (width !== this.animationProps.width || height !== this.animationProps.height) {\n this.setNeedsRedraw('drawing buffer resized');\n }\n if (aspect !== this.animationProps.aspect) {\n this.setNeedsRedraw('drawing buffer aspect changed');\n }\n\n this.animationProps.width = width;\n this.animationProps.height = height;\n this.animationProps.aspect = aspect;\n\n this.animationProps.needsRedraw = this.needsRedraw;\n\n // Update time properties\n this.animationProps.engineTime = Date.now() - this.animationProps.startTime;\n\n if (this.timeline) {\n this.timeline.update(this.animationProps.engineTime);\n }\n\n this.animationProps.tick = Math.floor((this.animationProps.time / 1000) * 60);\n this.animationProps.tock++;\n\n // For back compatibility\n this.animationProps.time = this.timeline\n ? this.timeline.getTime()\n : this.animationProps.engineTime;\n }\n\n /** Either uses supplied or existing context, or calls provided callback to create one */\n async _createDevice() {\n const deviceProps = {...this.props, ...this.props.deviceProps};\n this.device = await this.onCreateDevice(deviceProps);\n // @ts-expect-error\n this.canvas = this.device.canvasContext.canvas;\n this._createInfoDiv();\n }\n\n _createInfoDiv() {\n if (this.canvas && this.props.onAddHTML) {\n const wrapperDiv = document.createElement('div');\n document.body.appendChild(wrapperDiv);\n wrapperDiv.style.position = 'relative';\n const div = document.createElement('div');\n div.style.position = 'absolute';\n div.style.left = '10px';\n div.style.bottom = '10px';\n div.style.width = '300px';\n div.style.background = 'white';\n wrapperDiv.appendChild(this.canvas);\n wrapperDiv.appendChild(div);\n const html = this.props.onAddHTML(div);\n if (html) {\n div.innerHTML = html;\n }\n }\n }\n\n _getSizeAndAspect() {\n // https://webglfundamentals.org/webgl/lessons/webgl-resizing-the-canvas.html\n const [width, height] = this.device.canvasContext.getPixelSize();\n\n // https://webglfundamentals.org/webgl/lessons/webgl-anti-patterns.html\n let aspect = 1;\n const canvas = this.device.canvasContext.canvas;\n\n // @ts-expect-error\n if (canvas && canvas.clientHeight) {\n // @ts-expect-error\n aspect = canvas.clientWidth / canvas.clientHeight;\n } else if (width > 0 && height > 0) {\n aspect = width / height;\n }\n\n return {width, height, aspect};\n }\n\n /** Default viewport setup */\n _resizeViewport() {\n // @ts-expect-error Expose on canvasContext\n if (this.props.autoResizeViewport && this.device.gl) {\n // @ts-expect-error Expose canvasContext\n this.device.gl.viewport(0, 0, this.device.gl.drawingBufferWidth, this.device.gl.drawingBufferHeight);\n }\n }\n\n /**\n * Resize the render buffer of the canvas to match canvas client size\n * Optionally multiplying with devicePixel ratio\n */\n _resizeCanvasDrawingBuffer() {\n if (this.props.autoResizeDrawingBuffer) {\n this.device.canvasContext.resize({useDevicePixels: this.props.useDevicePixels});\n }\n }\n\n _beginTimers() {\n this.frameRate.timeEnd();\n this.frameRate.timeStart();\n\n // Check if timer for last frame has completed.\n // GPU timer results are never available in the same\n // frame they are captured.\n // if (\n // this._gpuTimeQuery &&\n // this._gpuTimeQuery.isResultAvailable() &&\n // !this._gpuTimeQuery.isTimerDisjoint()\n // ) {\n // this.stats.get('GPU Time').addTime(this._gpuTimeQuery.getTimerMilliseconds());\n // }\n\n // if (this._gpuTimeQuery) {\n // // GPU time query start\n // this._gpuTimeQuery.beginTimeElapsedQuery();\n // }\n\n // this.cpuTime.timeStart();\n }\n\n _endTimers() {\n this.cpuTime.timeEnd();\n\n // if (this._gpuTimeQuery) {\n // // GPU time query end. Results will be available on next frame.\n // this._gpuTimeQuery.end();\n // }\n }\n\n // Event handling\n\n _startEventHandling() {\n if (this.canvas) {\n this.canvas.addEventListener('mousemove', this._onMousemove);\n this.canvas.addEventListener('mouseleave', this._onMouseleave);\n }\n }\n\n _onMousemove(e) {\n this.animationProps._mousePosition = [e.offsetX, e.offsetY];\n }\n _onMouseleave(e) {\n this.animationProps._mousePosition = null;\n }\n}\n"],"file":"animation-loop.js"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"animation-props.d.ts","sourceRoot":"","sources":["../../src/lib/animation-props.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAC;AACpC,OAAO,EAAC,QAAQ,EAAC,MAAM,uBAAuB,CAAA;AAC9C,OAAO,KAAK,aAAa,MAAM,kBAAkB,CAAC;AAElD,+CAA+C;AAC/C,oBAAY,cAAc,GAAG;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,aAAa,CAAC;IAE7B,oCAAoC;IACpC,MAAM,EAAE,iBAAiB,GAAG,eAAe,CAAC;IAC5C,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IAGf,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IAGb,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,QAAQ,EAAE,QAAQ,CAAC;IAGnB,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"animation-props.js"}
@@ -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,QAAQ,MAAM,sBAAsB,CAAC;AAsDjD,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,"sources":["../../src/lib/model-utils.ts"],"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"],"mappings":"AAAA,SAAgBA,MAAhB,EAAwBC,MAAxB,QAAqC,cAArC;AAIA,MAAMC,0BAA0B,GAAG;AACjCC,EAAAA,QAAQ,EAAE,WADuB;AA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;AAED,SAASO,gBAAT,CAA0BN,IAA1B,EAAgD;AAC9C,SAAOrB,0BAA0B,CAACqB,IAAD,CAA1B,IAAoCA,IAA3C;AACD","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 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"],"file":"model-utils.js"}
@@ -1,41 +0,0 @@
1
- import type { Device, Buffer, RenderPipelineProps, RenderPass, Binding } from '@luma.gl/api';
2
- import { RenderPipeline } from '@luma.gl/api';
3
- import type { ShaderModule } from '@luma.gl/shadertools';
4
- import type Geometry from '../geometry/geometry';
5
- export declare type ModelProps = Omit<RenderPipelineProps, 'vs' | 'fs'> & {
6
- vs?: {
7
- glsl?: string;
8
- wgsl?: string;
9
- } | string;
10
- fs?: {
11
- glsl?: string;
12
- wgsl?: string;
13
- } | string;
14
- modules?: ShaderModule[];
15
- moduleSettings?: Record<string, Record<string, any>>;
16
- geometry?: Geometry;
17
- };
18
- /** v9 API */
19
- export default class Model {
20
- readonly device: Device;
21
- readonly pipeline: RenderPipeline;
22
- readonly id: string;
23
- readonly vs: string;
24
- readonly fs: string | undefined;
25
- readonly topology: string;
26
- readonly vertexCount: any;
27
- props: Required<ModelProps>;
28
- private _getModuleUniforms;
29
- constructor(device: Device, props: ModelProps);
30
- destroy(): void;
31
- draw(renderPass?: RenderPass): this;
32
- setProps(props: ModelProps): this;
33
- updateModuleSettings(props: Record<string, any>): this;
34
- setIndexBuffer(indices: Buffer): this;
35
- setAttributes(attributes: Record<string, Buffer>): this;
36
- /** Set the bindings */
37
- setBindings(bindings: Record<string, Binding>): this;
38
- setUniforms(uniforms: Record<string, any>): this;
39
- _setGeometry(geometry: Geometry): void;
40
- }
41
- //# sourceMappingURL=model.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/lib/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAE,MAAM,EAAE,mBAAmB,EAAE,UAAU,EAAE,OAAO,EAAC,MAAM,cAAc,CAAC;AAC3F,OAAO,EAAC,cAAc,EAAe,MAAM,cAAc,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAC;AAIjD,oBAAY,UAAU,GAAG,IAAI,CAAC,mBAAmB,EAAE,IAAI,GAAG,IAAI,CAAC,GAAG;IAEhE,EAAE,CAAC,EAAE;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAC,GAAG,MAAM,CAAC;IAC7C,EAAE,CAAC,EAAE;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAC,GAAG,MAAM,CAAC;IAC7C,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;IACrD,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB,CAAC;AAcF,aAAa;AACb,MAAM,CAAC,OAAO,OAAO,KAAK;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,MAAC;IACrB,KAAK,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;IAE5B,OAAO,CAAC,kBAAkB,CAAuE;gBAErF,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU;IAyC7C,OAAO,IAAI,IAAI;IAIf,IAAI,CAAC,UAAU,CAAC,EAAE,UAAU,GAAG,IAAI;IASnC,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAmBjC,oBAAoB,CAAC,KAAK,EAAE,MAAM,CAAC,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,"sources":["../../src/lib/model.ts"],"names":["RenderPipeline","getAttributeBuffersFromGeometry","getIndexBufferFromGeometry","PipelineFactory","DEFAULT_MODEL_PROPS","_DEFAULT_PROPS","vs","undefined","fs","id","handle","userData","modules","moduleSettings","geometry","Model","constructor","device","props","getShaderSource","vertexCount","topology","renderPipeline","getUniforms","getDefaultPipelineFactory","createRenderPipeline","parameters","layout","pipeline","_getModuleUniforms","_setGeometry","setUniforms","setProps","destroy","draw","renderPass","instanceCount","indices","setIndexBuffer","attributes","setAttributes","bindings","setBindings","uniforms","updateModuleSettings","Object","assign","geometryBuffers","indexBuffer","shader","info","type","wgsl","Error","glsl"],"mappings":";AACA,SAAQA,cAAR,QAA2C,cAA3C;AAGA,SAAQC,+BAAR,EAAyCC,0BAAzC,QAA0E,eAA1E;AACA,OAAOC,eAAP,MAA4B,oBAA5B;AAWA,MAAMC,mBAAyC,GAAG,EAChD,GAAGJ,cAAc,CAACK,cAD8B;AAEhDC,EAAAA,EAAE,EAAEC,SAF4C;AAGhDC,EAAAA,EAAE,EAAED,SAH4C;AAIhDE,EAAAA,EAAE,EAAE,SAJ4C;AAKhDC,EAAAA,MAAM,EAAEH,SALwC;AAMhDI,EAAAA,QAAQ,EAAE,EANsC;AAOhDC,EAAAA,OAAO,EAAE,EAPuC;AAQhDC,EAAAA,cAAc,EAAE,EARgC;AAShDC,EAAAA,QAAQ,EAAEP;AATsC,CAAlD;AAaA,eAAe,MAAMQ,KAAN,CAAY;AAYzBC,EAAAA,WAAW,CAACC,MAAD,EAAiBC,KAAjB,EAAoC;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAC7C,SAAKA,KAAL,GAAa,EAAC,GAAGd,mBAAJ;AAAyB,SAAGc;AAA5B,KAAb;AACAA,IAAAA,KAAK,GAAG,KAAKA,KAAb;AACA,SAAKT,EAAL,GAAUS,KAAK,CAACT,EAAhB;AACA,SAAKQ,MAAL,GAAcA,MAAd;AAGA,SAAKX,EAAL,GAAUa,eAAe,CAAC,KAAKF,MAAN,EAAcC,KAAK,CAACZ,EAApB,CAAzB;;AACA,QAAIY,KAAK,CAACV,EAAV,EAAc;AACZ,WAAKA,EAAL,GAAUW,eAAe,CAAC,KAAKF,MAAN,EAAcC,KAAK,CAACV,EAApB,CAAzB;AACD;;AAED,SAA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AAA,WAAW,CAACY,QAAD,EAAsC;AAC/C,SAAKf,QAAL,CAAcG,WAAd,CAA0BY,QAA1B;AACAE,IAAAA,MAAM,CAACC,MAAP,CAAc,KAAK5B,KAAL,CAAWyB,QAAzB,EAAmCA,QAAnC;AACA,WAAO,IAAP;AACD;;AAEDb,EAAAA,YAAY,CAAChB,QAAD,EAA2B;AAGrC,UAAMiC,eAAe,GAAG9C,+BAA+B,CAAC,KAAKgB,MAAN,EAAcH,QAAd,CAAvD;AACA,SAAK0B,aAAL,CAAmBO,eAAnB;AAEA,UAAMC,WAAW,GAAG9C,0BAA0B,CAAC,KAAKe,MAAN,EAAcH,QAAd,CAA9C;;AACA,QAAIkC,WAAJ,EAAiB;AACf,WAAKV,cAAL,CAAoBU,WAApB;AACD;AACF;;AA9HwB;;AAkI3B,SAAS7B,eAAT,CAAyBF,MAAzB,EAAyCgC,MAAzC,EAAkG;AAEhG,MAAI,OAAOA,MAAP,KAAkB,QAAtB,EAAgC;AAC9B,WAAOA,MAAP;AACD;;AAED,UAAQhC,MAAM,CAACiC,IAAP,CAAYC,IAApB;AACE,SAAK,QAAL;AACE,UAAIF,MAAJ,aAAIA,MAAJ,eAAIA,MAAM,CAAEG,IAAZ,EAAkB;AAChB,eAAOH,MAAM,CAACG,IAAd;AACD;;AACD,YAAM,IAAIC,KAAJ,CAAU,sCAAV,CAAN;;AAEF;AACE,UAAIJ,MAAJ,aAAIA,MAAJ,eAAIA,MAAM,CAAEK,IAAZ,EAAkB;AAChB,eAAOL,MAAM,CAACK,IAAd;AACD;;AACD,YAAM,IAAID,KAAJ,CAAU,qCAAV,CAAN;AAXJ;AAaD","sourcesContent":["import type {Device, Buffer, RenderPipelineProps, RenderPass, Binding} from '@luma.gl/api';\nimport {RenderPipeline, Shader, cast} 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;\n fs?: {glsl?: string; wgsl?: string} | string;\n modules?: ShaderModule[];\n moduleSettings?: Record<string, Record<string, any>>;\n geometry?: Geometry;\n};\n\nconst DEFAULT_MODEL_PROPS: Required<ModelProps> = {\n ...RenderPipeline._DEFAULT_PROPS,\n vs: undefined,\n fs: undefined,\n id: 'unnamed',\n handle: undefined,\n userData: {},\n modules: [],\n moduleSettings: {},\n geometry: undefined\n};\n\n/** v9 API */\nexport default class Model {\n readonly device: Device;\n readonly pipeline: RenderPipeline;\n readonly id: string;\n readonly vs: string;\n readonly fs: string | undefined;\n readonly topology: string;\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 = props.id;\n this.device = device;\n\n // Create the pipeline\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;\n }\n\n const {renderPipeline, getUniforms} = PipelineFactory.getDefaultPipelineFactory(this.device).createRenderPipeline({\n ...this.props,\n vs: this.vs,\n fs: this.fs,\n topology: this.topology,\n parameters: props.parameters,\n // Geometry in the vertex shader!\n // @ts-expect-error\n layout: props.layout\n });\n\n this.pipeline = renderPipeline;\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"],"file":"model.js"}
@@ -1,14 +0,0 @@
1
- import type { DeviceProps } from '@luma.gl/api';
2
- import type { AnimationProps } from '../lib/animation-props';
3
- import AnimationLoop from './animation-loop';
4
- /**
5
- * Minimal animation loop that initializes models in constructor
6
- * Simplifying type management
7
- * v9 API
8
- */
9
- export declare abstract class RenderLoop {
10
- constructor(animationProps?: AnimationProps);
11
- /** Instantiates and runs the render loop */
12
- static run(RenderLoopConstructor: typeof RenderLoop, deviceProps?: DeviceProps): AnimationLoop;
13
- }
14
- //# sourceMappingURL=render-loop.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"render-loop.d.ts","sourceRoot":"","sources":["../../src/lib/render-loop.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,wBAAwB,CAAC;AAC3D,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAE7C;;;;GAIG;AACH,8BAAsB,UAAU;gBAClB,cAAc,CAAC,EAAE,cAAc;IAE3C,4CAA4C;IAC5C,MAAM,CAAC,GAAG,CAAC,qBAAqB,EAAE,OAAO,UAAU,EAAE,WAAW,CAAC,EAAE,WAAW,GAAG,aAAa;CAS/F"}