@luma.gl/engine 9.0.0-alpha.8 → 9.0.0-beta.1

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 (191) hide show
  1. package/LICENSE +3 -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 +6 -27
  5. package/dist/animation/key-frames.js.map +1 -1
  6. package/dist/animation/timeline.d.ts +8 -8
  7. package/dist/animation/timeline.d.ts.map +1 -1
  8. package/dist/animation/timeline.js +18 -49
  9. package/dist/animation/timeline.js.map +1 -1
  10. package/dist/animation-loop/animation-loop-template.d.ts +23 -0
  11. package/dist/animation-loop/animation-loop-template.d.ts.map +1 -0
  12. package/dist/animation-loop/animation-loop-template.js +7 -0
  13. package/dist/animation-loop/animation-loop-template.js.map +1 -0
  14. package/dist/{lib → animation-loop}/animation-loop.d.ts +30 -22
  15. package/dist/animation-loop/animation-loop.d.ts.map +1 -0
  16. package/dist/{lib → animation-loop}/animation-loop.js +77 -192
  17. package/dist/animation-loop/animation-loop.js.map +1 -0
  18. package/dist/{lib → animation-loop}/animation-props.d.ts +2 -3
  19. package/dist/animation-loop/animation-props.d.ts.map +1 -0
  20. package/dist/animation-loop/animation-props.js.map +1 -0
  21. package/dist/animation-loop/make-animation-loop.d.ts +6 -0
  22. package/dist/animation-loop/make-animation-loop.d.ts.map +1 -0
  23. package/dist/animation-loop/make-animation-loop.js +28 -0
  24. package/dist/animation-loop/make-animation-loop.js.map +1 -0
  25. package/dist/debug/copy-texture-to-image.d.ts +26 -0
  26. package/dist/debug/copy-texture-to-image.d.ts.map +1 -0
  27. package/dist/debug/copy-texture-to-image.js +46 -0
  28. package/dist/debug/copy-texture-to-image.js.map +1 -0
  29. package/dist/debug/debug-framebuffer.d.ts +11 -0
  30. package/dist/debug/debug-framebuffer.d.ts.map +1 -0
  31. package/dist/debug/debug-framebuffer.js +43 -0
  32. package/dist/debug/debug-framebuffer.js.map +1 -0
  33. package/dist/debug/debug-shader-layout.d.ts +9 -0
  34. package/dist/debug/debug-shader-layout.d.ts.map +1 -0
  35. package/dist/debug/debug-shader-layout.js +28 -0
  36. package/dist/debug/debug-shader-layout.js.map +1 -0
  37. package/dist/debug/pixel-data-utils.d.ts +24 -0
  38. package/dist/debug/pixel-data-utils.d.ts.map +1 -0
  39. package/dist/debug/pixel-data-utils.js +41 -0
  40. package/dist/debug/pixel-data-utils.js.map +1 -0
  41. package/dist/dist.dev.js +10081 -0
  42. package/dist/geometries/cone-geometry.d.ts +1 -1
  43. package/dist/geometries/cone-geometry.d.ts.map +1 -1
  44. package/dist/geometries/cone-geometry.js +6 -5
  45. package/dist/geometries/cone-geometry.js.map +1 -1
  46. package/dist/geometries/cube-geometry.d.ts +2 -2
  47. package/dist/geometries/cube-geometry.d.ts.map +1 -1
  48. package/dist/geometries/cube-geometry.js +16 -10
  49. package/dist/geometries/cube-geometry.js.map +1 -1
  50. package/dist/geometries/cylinder-geometry.d.ts +1 -1
  51. package/dist/geometries/cylinder-geometry.d.ts.map +1 -1
  52. package/dist/geometries/cylinder-geometry.js +6 -5
  53. package/dist/geometries/cylinder-geometry.js.map +1 -1
  54. package/dist/geometries/ico-sphere-geometry.d.ts +2 -2
  55. package/dist/geometries/ico-sphere-geometry.d.ts.map +1 -1
  56. package/dist/geometries/ico-sphere-geometry.js +10 -19
  57. package/dist/geometries/ico-sphere-geometry.js.map +1 -1
  58. package/dist/geometries/plane-geometry.d.ts +2 -2
  59. package/dist/geometries/plane-geometry.d.ts.map +1 -1
  60. package/dist/geometries/plane-geometry.js +14 -23
  61. package/dist/geometries/plane-geometry.js.map +1 -1
  62. package/dist/geometries/sphere-geometry.d.ts +2 -2
  63. package/dist/geometries/sphere-geometry.d.ts.map +1 -1
  64. package/dist/geometries/sphere-geometry.js +9 -13
  65. package/dist/geometries/sphere-geometry.js.map +1 -1
  66. package/dist/geometries/truncated-cone-geometry.d.ts +2 -4
  67. package/dist/geometries/truncated-cone-geometry.d.ts.map +1 -1
  68. package/dist/geometries/truncated-cone-geometry.js +9 -25
  69. package/dist/geometries/truncated-cone-geometry.js.map +1 -1
  70. package/dist/geometry/geometry-table.d.ts +2 -2
  71. package/dist/geometry/geometry-table.d.ts.map +1 -1
  72. package/dist/geometry/geometry-table.js.map +1 -1
  73. package/dist/geometry/geometry-utils.d.ts.map +1 -1
  74. package/dist/geometry/geometry-utils.js +0 -9
  75. package/dist/geometry/geometry-utils.js.map +1 -1
  76. package/dist/geometry/geometry.d.ts +43 -43
  77. package/dist/geometry/geometry.d.ts.map +1 -1
  78. package/dist/geometry/geometry.js +20 -82
  79. package/dist/geometry/geometry.js.map +1 -1
  80. package/dist/geometry/gpu-geometry.d.ts +37 -0
  81. package/dist/geometry/gpu-geometry.d.ts.map +1 -0
  82. package/dist/geometry/gpu-geometry.js +110 -0
  83. package/dist/geometry/gpu-geometry.js.map +1 -0
  84. package/dist/geometry/gpu-table.d.ts +1 -0
  85. package/dist/geometry/gpu-table.d.ts.map +1 -0
  86. package/dist/geometry/gpu-table.js +2 -0
  87. package/dist/geometry/gpu-table.js.map +1 -0
  88. package/dist/index.cjs +3128 -0
  89. package/dist/index.d.ts +24 -8
  90. package/dist/index.d.ts.map +1 -1
  91. package/dist/index.js +23 -14
  92. package/dist/index.js.map +1 -1
  93. package/dist/lib/clip-space.d.ts +8 -0
  94. package/dist/lib/clip-space.d.ts.map +1 -1
  95. package/dist/lib/clip-space.js +47 -0
  96. package/dist/lib/clip-space.js.map +1 -1
  97. package/dist/lib/pipeline-factory.d.ts +12 -45
  98. package/dist/lib/pipeline-factory.d.ts.map +1 -1
  99. package/dist/lib/pipeline-factory.js +42 -168
  100. package/dist/lib/pipeline-factory.js.map +1 -1
  101. package/dist/model/model.d.ts +206 -0
  102. package/dist/model/model.d.ts.map +1 -0
  103. package/dist/model/model.js +435 -0
  104. package/dist/model/model.js.map +1 -0
  105. package/dist/scenegraph/group-node.d.ts +21 -0
  106. package/dist/scenegraph/group-node.d.ts.map +1 -0
  107. package/dist/scenegraph/group-node.js +94 -0
  108. package/dist/scenegraph/group-node.js.map +1 -0
  109. package/dist/scenegraph/model-node.d.ts +18 -0
  110. package/dist/scenegraph/model-node.d.ts.map +1 -0
  111. package/dist/scenegraph/model-node.js +28 -0
  112. package/dist/scenegraph/model-node.js.map +1 -0
  113. package/dist/scenegraph/scenegraph-node.d.ts +56 -0
  114. package/dist/scenegraph/scenegraph-node.d.ts.map +1 -0
  115. package/dist/scenegraph/scenegraph-node.js +141 -0
  116. package/dist/scenegraph/scenegraph-node.js.map +1 -0
  117. package/dist/shader-inputs.d.ts +63 -0
  118. package/dist/shader-inputs.d.ts.map +1 -0
  119. package/dist/shader-inputs.js +66 -0
  120. package/dist/shader-inputs.js.map +1 -0
  121. package/dist/transform/buffer-transform.d.ts +35 -0
  122. package/dist/transform/buffer-transform.d.ts.map +1 -0
  123. package/dist/transform/buffer-transform.js +62 -0
  124. package/dist/transform/buffer-transform.js.map +1 -0
  125. package/dist/transform/texture-transform.d.ts +57 -0
  126. package/dist/transform/texture-transform.d.ts.map +1 -0
  127. package/dist/transform/texture-transform.js +122 -0
  128. package/dist/transform/texture-transform.js.map +1 -0
  129. package/dist.min.js +293 -0
  130. package/package.json +21 -12
  131. package/src/animation/timeline.ts +15 -14
  132. package/src/animation-loop/animation-loop-template.ts +23 -0
  133. package/src/{lib → animation-loop}/animation-loop.ts +99 -88
  134. package/src/{lib → animation-loop}/animation-props.ts +1 -1
  135. package/src/animation-loop/make-animation-loop.ts +44 -0
  136. package/src/debug/copy-texture-to-image.ts +72 -0
  137. package/src/debug/debug-framebuffer.ts +57 -0
  138. package/src/debug/debug-shader-layout.ts +38 -0
  139. package/src/debug/pixel-data-utils.ts +57 -0
  140. package/src/geometries/cone-geometry.ts +1 -1
  141. package/src/geometries/cube-geometry.ts +47 -45
  142. package/src/geometries/cylinder-geometry.ts +2 -2
  143. package/src/geometries/ico-sphere-geometry.ts +6 -5
  144. package/src/geometries/plane-geometry.ts +5 -4
  145. package/src/geometries/sphere-geometry.ts +4 -3
  146. package/src/geometries/truncated-cone-geometry.ts +4 -13
  147. package/src/geometry/geometry-table.ts +1 -1
  148. package/src/geometry/geometry-utils.ts +3 -3
  149. package/src/geometry/geometry.ts +65 -110
  150. package/src/geometry/gpu-geometry.ts +125 -0
  151. package/src/geometry/gpu-table.ts +41 -0
  152. package/src/index.ts +34 -10
  153. package/src/lib/clip-space.ts +22 -21
  154. package/src/lib/pipeline-factory.ts +51 -168
  155. package/src/model/model.ts +726 -0
  156. package/src/scenegraph/group-node.ts +103 -0
  157. package/src/scenegraph/model-node.ts +50 -0
  158. package/src/scenegraph/scenegraph-node.ts +204 -0
  159. package/src/shader-inputs.ts +150 -0
  160. package/src/transform/buffer-transform.ts +94 -0
  161. package/src/transform/texture-transform.ts +169 -0
  162. package/dist/bundle.d.ts +0 -2
  163. package/dist/bundle.d.ts.map +0 -1
  164. package/dist/bundle.js +0 -5
  165. package/dist/bundle.js.map +0 -1
  166. package/dist/geometry/primitive-utils.d.ts +0 -1
  167. package/dist/geometry/primitive-utils.d.ts.map +0 -1
  168. package/dist/geometry/primitive-utils.js +0 -2
  169. package/dist/geometry/primitive-utils.js.map +0 -1
  170. package/dist/lib/animation-loop.d.ts.map +0 -1
  171. package/dist/lib/animation-loop.js.map +0 -1
  172. package/dist/lib/animation-props.d.ts.map +0 -1
  173. package/dist/lib/animation-props.js.map +0 -1
  174. package/dist/lib/model-utils.d.ts +0 -5
  175. package/dist/lib/model-utils.d.ts.map +0 -1
  176. package/dist/lib/model-utils.js +0 -45
  177. package/dist/lib/model-utils.js.map +0 -1
  178. package/dist/lib/model.d.ts +0 -41
  179. package/dist/lib/model.d.ts.map +0 -1
  180. package/dist/lib/model.js +0 -182
  181. package/dist/lib/model.js.map +0 -1
  182. package/dist/lib/render-loop.d.ts +0 -14
  183. package/dist/lib/render-loop.d.ts.map +0 -1
  184. package/dist/lib/render-loop.js +0 -49
  185. package/dist/lib/render-loop.js.map +0 -1
  186. package/src/bundle.ts +0 -4
  187. package/src/geometry/primitive-utils.ts +0 -30
  188. package/src/lib/model-utils.ts +0 -124
  189. package/src/lib/model.ts +0 -183
  190. package/src/lib/render-loop.ts +0 -58
  191. /package/dist/{lib → animation-loop}/animation-props.js +0 -0
package/dist/index.cjs ADDED
@@ -0,0 +1,3128 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var __publicField = (obj, key, value) => {
21
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
+ return value;
23
+ };
24
+
25
+ // src/index.ts
26
+ var src_exports = {};
27
+ __export(src_exports, {
28
+ AnimationLoop: () => AnimationLoop,
29
+ AnimationLoopTemplate: () => AnimationLoopTemplate,
30
+ BufferTransform: () => BufferTransform,
31
+ ClipSpace: () => ClipSpace,
32
+ ConeGeometry: () => ConeGeometry,
33
+ CubeGeometry: () => CubeGeometry,
34
+ CylinderGeometry: () => CylinderGeometry,
35
+ GPUGeometry: () => GPUGeometry,
36
+ Geometry: () => Geometry,
37
+ GroupNode: () => GroupNode,
38
+ IcoSphereGeometry: () => IcoSphereGeometry,
39
+ KeyFrames: () => KeyFrames,
40
+ Model: () => Model,
41
+ ModelNode: () => ModelNode,
42
+ PipelineFactory: () => PipelineFactory,
43
+ PlaneGeometry: () => PlaneGeometry,
44
+ ScenegraphNode: () => ScenegraphNode,
45
+ SphereGeometry: () => SphereGeometry,
46
+ TextureTransform: () => TextureTransform,
47
+ Timeline: () => Timeline,
48
+ TruncatedConeGeometry: () => TruncatedConeGeometry,
49
+ _ShaderInputs: () => ShaderInputs,
50
+ makeAnimationLoop: () => makeAnimationLoop
51
+ });
52
+ module.exports = __toCommonJS(src_exports);
53
+
54
+ // src/animation/timeline.ts
55
+ var channelHandles = 1;
56
+ var animationHandles = 1;
57
+ var Timeline = class {
58
+ time = 0;
59
+ channels = /* @__PURE__ */ new Map();
60
+ animations = /* @__PURE__ */ new Map();
61
+ playing = false;
62
+ lastEngineTime = -1;
63
+ constructor() {
64
+ }
65
+ addChannel(props) {
66
+ const { delay = 0, duration = Number.POSITIVE_INFINITY, rate = 1, repeat = 1 } = props;
67
+ const channelId = channelHandles++;
68
+ const channel = {
69
+ time: 0,
70
+ delay,
71
+ duration,
72
+ rate,
73
+ repeat
74
+ };
75
+ this._setChannelTime(channel, this.time);
76
+ this.channels.set(channelId, channel);
77
+ return channelId;
78
+ }
79
+ removeChannel(channelId) {
80
+ this.channels.delete(channelId);
81
+ for (const [animationHandle, animation] of this.animations) {
82
+ if (animation.channel === channelId) {
83
+ this.detachAnimation(animationHandle);
84
+ }
85
+ }
86
+ }
87
+ isFinished(channelId) {
88
+ const channel = this.channels.get(channelId);
89
+ if (channel === void 0) {
90
+ return false;
91
+ }
92
+ return this.time >= channel.delay + channel.duration * channel.repeat;
93
+ }
94
+ getTime(channelId) {
95
+ if (channelId === void 0) {
96
+ return this.time;
97
+ }
98
+ const channel = this.channels.get(channelId);
99
+ if (channel === void 0) {
100
+ return -1;
101
+ }
102
+ return channel.time;
103
+ }
104
+ setTime(time) {
105
+ this.time = Math.max(0, time);
106
+ const channels = this.channels.values();
107
+ for (const channel of channels) {
108
+ this._setChannelTime(channel, this.time);
109
+ }
110
+ const animations = this.animations.values();
111
+ for (const animationData of animations) {
112
+ const { animation, channel } = animationData;
113
+ animation.setTime(this.getTime(channel));
114
+ }
115
+ }
116
+ play() {
117
+ this.playing = true;
118
+ }
119
+ pause() {
120
+ this.playing = false;
121
+ this.lastEngineTime = -1;
122
+ }
123
+ reset() {
124
+ this.setTime(0);
125
+ }
126
+ attachAnimation(animation, channelHandle) {
127
+ const animationHandle = animationHandles++;
128
+ this.animations.set(animationHandle, {
129
+ animation,
130
+ channel: channelHandle
131
+ });
132
+ animation.setTime(this.getTime(channelHandle));
133
+ return animationHandle;
134
+ }
135
+ detachAnimation(channelId) {
136
+ this.animations.delete(channelId);
137
+ }
138
+ update(engineTime) {
139
+ if (this.playing) {
140
+ if (this.lastEngineTime === -1) {
141
+ this.lastEngineTime = engineTime;
142
+ }
143
+ this.setTime(this.time + (engineTime - this.lastEngineTime));
144
+ this.lastEngineTime = engineTime;
145
+ }
146
+ }
147
+ _setChannelTime(channel, time) {
148
+ const offsetTime = time - channel.delay;
149
+ const totalDuration = channel.duration * channel.repeat;
150
+ if (offsetTime >= totalDuration) {
151
+ channel.time = channel.duration * channel.rate;
152
+ } else {
153
+ channel.time = Math.max(0, offsetTime) % channel.duration;
154
+ channel.time *= channel.rate;
155
+ }
156
+ }
157
+ };
158
+
159
+ // src/animation/key-frames.ts
160
+ var KeyFrames = class {
161
+ startIndex = -1;
162
+ endIndex = -1;
163
+ factor = 0;
164
+ times = [];
165
+ values = [];
166
+ _lastTime = -1;
167
+ constructor(keyFrames) {
168
+ this.setKeyFrames(keyFrames);
169
+ this.setTime(0);
170
+ }
171
+ setKeyFrames(keyFrames) {
172
+ const numKeys = keyFrames.length;
173
+ this.times.length = numKeys;
174
+ this.values.length = numKeys;
175
+ for (let i = 0; i < numKeys; ++i) {
176
+ this.times[i] = keyFrames[i][0];
177
+ this.values[i] = keyFrames[i][1];
178
+ }
179
+ this._calculateKeys(this._lastTime);
180
+ }
181
+ setTime(time) {
182
+ time = Math.max(0, time);
183
+ if (time !== this._lastTime) {
184
+ this._calculateKeys(time);
185
+ this._lastTime = time;
186
+ }
187
+ }
188
+ getStartTime() {
189
+ return this.times[this.startIndex];
190
+ }
191
+ getEndTime() {
192
+ return this.times[this.endIndex];
193
+ }
194
+ getStartData() {
195
+ return this.values[this.startIndex];
196
+ }
197
+ getEndData() {
198
+ return this.values[this.endIndex];
199
+ }
200
+ _calculateKeys(time) {
201
+ let index = 0;
202
+ const numKeys = this.times.length;
203
+ for (index = 0; index < numKeys - 2; ++index) {
204
+ if (this.times[index + 1] > time) {
205
+ break;
206
+ }
207
+ }
208
+ this.startIndex = index;
209
+ this.endIndex = index + 1;
210
+ const startTime = this.times[this.startIndex];
211
+ const endTime = this.times[this.endIndex];
212
+ this.factor = Math.min(Math.max(0, (time - startTime) / (endTime - startTime)), 1);
213
+ }
214
+ };
215
+
216
+ // src/animation-loop/animation-loop-template.ts
217
+ var AnimationLoopTemplate = class {
218
+ constructor(animationProps) {
219
+ }
220
+ async onInitialize(animationProps) {
221
+ return null;
222
+ }
223
+ };
224
+
225
+ // src/animation-loop/animation-loop.ts
226
+ var import_core = require("@luma.gl/core");
227
+ var import_core2 = require("@luma.gl/core");
228
+ var import_stats = require("@probe.gl/stats");
229
+ var statIdCounter = 0;
230
+ var DEFAULT_ANIMATION_LOOP_PROPS = {
231
+ device: null,
232
+ onAddHTML: () => "",
233
+ onInitialize: async () => {
234
+ return null;
235
+ },
236
+ onRender: () => {
237
+ },
238
+ onFinalize: () => {
239
+ },
240
+ onError: (error) => console.error(error),
241
+ // eslint-disable-line no-console
242
+ stats: import_core.luma.stats.get(`animation-loop-${statIdCounter++}`),
243
+ // view parameters
244
+ useDevicePixels: true,
245
+ autoResizeViewport: false,
246
+ autoResizeDrawingBuffer: false
247
+ };
248
+ var AnimationLoop = class {
249
+ device = null;
250
+ canvas = null;
251
+ props;
252
+ animationProps = null;
253
+ timeline = null;
254
+ stats;
255
+ cpuTime;
256
+ gpuTime;
257
+ frameRate;
258
+ display;
259
+ needsRedraw = "initialized";
260
+ _initialized = false;
261
+ _running = false;
262
+ _animationFrameId = null;
263
+ _nextFramePromise = null;
264
+ _resolveNextFrame = null;
265
+ _cpuStartTime = 0;
266
+ // _gpuTimeQuery: Query | null = null;
267
+ /*
268
+ * @param {HTMLCanvasElement} canvas - if provided, width and height will be passed to context
269
+ */
270
+ constructor(props) {
271
+ this.props = { ...DEFAULT_ANIMATION_LOOP_PROPS, ...props };
272
+ props = this.props;
273
+ if (!props.device) {
274
+ throw new Error("No device provided");
275
+ }
276
+ const { useDevicePixels = true } = this.props;
277
+ this.stats = props.stats || new import_stats.Stats({ id: "animation-loop-stats" });
278
+ this.cpuTime = this.stats.get("CPU Time");
279
+ this.gpuTime = this.stats.get("GPU Time");
280
+ this.frameRate = this.stats.get("Frame Rate");
281
+ this.setProps({
282
+ autoResizeViewport: props.autoResizeViewport,
283
+ autoResizeDrawingBuffer: props.autoResizeDrawingBuffer,
284
+ useDevicePixels
285
+ });
286
+ this.start = this.start.bind(this);
287
+ this.stop = this.stop.bind(this);
288
+ this._onMousemove = this._onMousemove.bind(this);
289
+ this._onMouseleave = this._onMouseleave.bind(this);
290
+ }
291
+ destroy() {
292
+ this.stop();
293
+ this._setDisplay(null);
294
+ }
295
+ /** @deprecated Use .destroy() */
296
+ delete() {
297
+ this.destroy();
298
+ }
299
+ /** Flags this animation loop as needing redraw */
300
+ setNeedsRedraw(reason) {
301
+ this.needsRedraw = this.needsRedraw || reason;
302
+ return this;
303
+ }
304
+ /** TODO - move these props to CanvasContext? */
305
+ setProps(props) {
306
+ if ("autoResizeViewport" in props) {
307
+ this.props.autoResizeViewport = props.autoResizeViewport || false;
308
+ }
309
+ if ("autoResizeDrawingBuffer" in props) {
310
+ this.props.autoResizeDrawingBuffer = props.autoResizeDrawingBuffer || false;
311
+ }
312
+ if ("useDevicePixels" in props) {
313
+ this.props.useDevicePixels = props.useDevicePixels || false;
314
+ }
315
+ return this;
316
+ }
317
+ /** Starts a render loop if not already running */
318
+ async start() {
319
+ if (this._running) {
320
+ return this;
321
+ }
322
+ this._running = true;
323
+ try {
324
+ let appContext;
325
+ if (!this._initialized) {
326
+ this._initialized = true;
327
+ await this._initDevice();
328
+ this._initialize();
329
+ await this.props.onInitialize(this._getAnimationProps());
330
+ }
331
+ if (!this._running) {
332
+ return null;
333
+ }
334
+ if (appContext !== false) {
335
+ this._cancelAnimationFrame();
336
+ this._requestAnimationFrame();
337
+ }
338
+ return this;
339
+ } catch (err) {
340
+ const error = err instanceof Error ? err : new Error("Unknown error");
341
+ this.props.onError(error);
342
+ throw error;
343
+ }
344
+ }
345
+ /** Stops a render loop if already running, finalizing */
346
+ stop() {
347
+ if (this._running) {
348
+ if (this.animationProps) {
349
+ this.props.onFinalize(this.animationProps);
350
+ }
351
+ this._cancelAnimationFrame();
352
+ this._nextFramePromise = null;
353
+ this._resolveNextFrame = null;
354
+ this._running = false;
355
+ }
356
+ return this;
357
+ }
358
+ /** Explicitly draw a frame */
359
+ redraw() {
360
+ var _a;
361
+ if ((_a = this.device) == null ? void 0 : _a.isLost) {
362
+ return this;
363
+ }
364
+ this._beginFrameTimers();
365
+ this._setupFrame();
366
+ this._updateAnimationProps();
367
+ this._renderFrame(this._getAnimationProps());
368
+ this._clearNeedsRedraw();
369
+ if (this._resolveNextFrame) {
370
+ this._resolveNextFrame(this);
371
+ this._nextFramePromise = null;
372
+ this._resolveNextFrame = null;
373
+ }
374
+ this._endFrameTimers();
375
+ return this;
376
+ }
377
+ /** Add a timeline, it will be automatically updated by the animation loop. */
378
+ attachTimeline(timeline) {
379
+ this.timeline = timeline;
380
+ return this.timeline;
381
+ }
382
+ /** Remove a timeline */
383
+ detachTimeline() {
384
+ this.timeline = null;
385
+ }
386
+ /** Wait until a render completes */
387
+ waitForRender() {
388
+ this.setNeedsRedraw("waitForRender");
389
+ if (!this._nextFramePromise) {
390
+ this._nextFramePromise = new Promise((resolve) => {
391
+ this._resolveNextFrame = resolve;
392
+ });
393
+ }
394
+ return this._nextFramePromise;
395
+ }
396
+ /** TODO - should use device.deviceContext */
397
+ async toDataURL() {
398
+ this.setNeedsRedraw("toDataURL");
399
+ await this.waitForRender();
400
+ if (this.canvas instanceof HTMLCanvasElement) {
401
+ return this.canvas.toDataURL();
402
+ }
403
+ throw new Error("OffscreenCanvas");
404
+ }
405
+ // PRIVATE METHODS
406
+ _initialize() {
407
+ this._startEventHandling();
408
+ this._initializeAnimationProps();
409
+ this._updateAnimationProps();
410
+ this._resizeCanvasDrawingBuffer();
411
+ this._resizeViewport();
412
+ }
413
+ _setDisplay(display) {
414
+ if (this.display) {
415
+ this.display.destroy();
416
+ this.display.animationLoop = null;
417
+ }
418
+ if (display) {
419
+ display.animationLoop = this;
420
+ }
421
+ this.display = display;
422
+ }
423
+ _requestAnimationFrame() {
424
+ if (!this._running) {
425
+ return;
426
+ }
427
+ this._animationFrameId = (0, import_core2.requestAnimationFrame)(this._animationFrame.bind(this));
428
+ }
429
+ _cancelAnimationFrame() {
430
+ if (this._animationFrameId === null) {
431
+ return;
432
+ }
433
+ (0, import_core2.cancelAnimationFrame)(this._animationFrameId);
434
+ this._animationFrameId = null;
435
+ }
436
+ _animationFrame() {
437
+ if (!this._running) {
438
+ return;
439
+ }
440
+ this.redraw();
441
+ this._requestAnimationFrame();
442
+ }
443
+ // Called on each frame, can be overridden to call onRender multiple times
444
+ // to support e.g. stereoscopic rendering
445
+ _renderFrame(animationProps) {
446
+ if (this.display) {
447
+ this.display._renderFrame(animationProps);
448
+ return;
449
+ }
450
+ this.props.onRender(this._getAnimationProps());
451
+ this.device.submit();
452
+ }
453
+ _clearNeedsRedraw() {
454
+ this.needsRedraw = false;
455
+ }
456
+ _setupFrame() {
457
+ this._resizeCanvasDrawingBuffer();
458
+ this._resizeViewport();
459
+ }
460
+ // Initialize the object that will be passed to app callbacks
461
+ _initializeAnimationProps() {
462
+ var _a, _b;
463
+ if (!this.device) {
464
+ throw new Error("loop");
465
+ }
466
+ this.animationProps = {
467
+ animationLoop: this,
468
+ device: this.device,
469
+ canvas: (_b = (_a = this.device) == null ? void 0 : _a.canvasContext) == null ? void 0 : _b.canvas,
470
+ timeline: this.timeline,
471
+ // Initial values
472
+ useDevicePixels: this.props.useDevicePixels,
473
+ needsRedraw: false,
474
+ // Placeholders
475
+ width: 1,
476
+ height: 1,
477
+ aspect: 1,
478
+ // Animation props
479
+ time: 0,
480
+ startTime: Date.now(),
481
+ engineTime: 0,
482
+ tick: 0,
483
+ tock: 0,
484
+ // Experimental
485
+ _mousePosition: null
486
+ // Event props
487
+ };
488
+ }
489
+ _getAnimationProps() {
490
+ if (!this.animationProps) {
491
+ throw new Error("animationProps");
492
+ }
493
+ return this.animationProps;
494
+ }
495
+ // Update the context object that will be passed to app callbacks
496
+ _updateAnimationProps() {
497
+ if (!this.animationProps) {
498
+ return;
499
+ }
500
+ const { width, height, aspect } = this._getSizeAndAspect();
501
+ if (width !== this.animationProps.width || height !== this.animationProps.height) {
502
+ this.setNeedsRedraw("drawing buffer resized");
503
+ }
504
+ if (aspect !== this.animationProps.aspect) {
505
+ this.setNeedsRedraw("drawing buffer aspect changed");
506
+ }
507
+ this.animationProps.width = width;
508
+ this.animationProps.height = height;
509
+ this.animationProps.aspect = aspect;
510
+ this.animationProps.needsRedraw = this.needsRedraw;
511
+ this.animationProps.engineTime = Date.now() - this.animationProps.startTime;
512
+ if (this.timeline) {
513
+ this.timeline.update(this.animationProps.engineTime);
514
+ }
515
+ this.animationProps.tick = Math.floor(this.animationProps.time / 1e3 * 60);
516
+ this.animationProps.tock++;
517
+ this.animationProps.time = this.timeline ? this.timeline.getTime() : this.animationProps.engineTime;
518
+ }
519
+ /** Wait for supplied device */
520
+ async _initDevice() {
521
+ var _a;
522
+ this.device = await this.props.device;
523
+ if (!this.device) {
524
+ throw new Error("No device provided");
525
+ }
526
+ this.canvas = ((_a = this.device.canvasContext) == null ? void 0 : _a.canvas) || null;
527
+ }
528
+ _createInfoDiv() {
529
+ if (this.canvas && this.props.onAddHTML) {
530
+ const wrapperDiv = document.createElement("div");
531
+ document.body.appendChild(wrapperDiv);
532
+ wrapperDiv.style.position = "relative";
533
+ const div = document.createElement("div");
534
+ div.style.position = "absolute";
535
+ div.style.left = "10px";
536
+ div.style.bottom = "10px";
537
+ div.style.width = "300px";
538
+ div.style.background = "white";
539
+ if (this.canvas instanceof HTMLCanvasElement) {
540
+ wrapperDiv.appendChild(this.canvas);
541
+ }
542
+ wrapperDiv.appendChild(div);
543
+ const html = this.props.onAddHTML(div);
544
+ if (html) {
545
+ div.innerHTML = html;
546
+ }
547
+ }
548
+ }
549
+ _getSizeAndAspect() {
550
+ var _a, _b, _c, _d;
551
+ if (!this.device) {
552
+ return { width: 1, height: 1, aspect: 1 };
553
+ }
554
+ const [width, height] = ((_b = (_a = this.device) == null ? void 0 : _a.canvasContext) == null ? void 0 : _b.getPixelSize()) || [1, 1];
555
+ let aspect = 1;
556
+ const canvas2 = (_d = (_c = this.device) == null ? void 0 : _c.canvasContext) == null ? void 0 : _d.canvas;
557
+ if (canvas2 && canvas2.clientHeight) {
558
+ aspect = canvas2.clientWidth / canvas2.clientHeight;
559
+ } else if (width > 0 && height > 0) {
560
+ aspect = width / height;
561
+ }
562
+ return { width, height, aspect };
563
+ }
564
+ /** Default viewport setup */
565
+ _resizeViewport() {
566
+ if (this.props.autoResizeViewport && this.device.gl) {
567
+ this.device.gl.viewport(0, 0, this.device.gl.drawingBufferWidth, this.device.gl.drawingBufferHeight);
568
+ }
569
+ }
570
+ /**
571
+ * Resize the render buffer of the canvas to match canvas client size
572
+ * Optionally multiplying with devicePixel ratio
573
+ */
574
+ _resizeCanvasDrawingBuffer() {
575
+ var _a, _b;
576
+ if (this.props.autoResizeDrawingBuffer) {
577
+ (_b = (_a = this.device) == null ? void 0 : _a.canvasContext) == null ? void 0 : _b.resize({ useDevicePixels: this.props.useDevicePixels });
578
+ }
579
+ }
580
+ _beginFrameTimers() {
581
+ this.frameRate.timeEnd();
582
+ this.frameRate.timeStart();
583
+ this.cpuTime.timeStart();
584
+ }
585
+ _endFrameTimers() {
586
+ this.cpuTime.timeEnd();
587
+ }
588
+ // Event handling
589
+ _startEventHandling() {
590
+ if (this.canvas) {
591
+ this.canvas.addEventListener("mousemove", this._onMousemove.bind(this));
592
+ this.canvas.addEventListener("mouseleave", this._onMouseleave.bind(this));
593
+ }
594
+ }
595
+ _onMousemove(event) {
596
+ if (event instanceof MouseEvent) {
597
+ this._getAnimationProps()._mousePosition = [event.offsetX, event.offsetY];
598
+ }
599
+ }
600
+ _onMouseleave(event) {
601
+ this._getAnimationProps()._mousePosition = null;
602
+ }
603
+ };
604
+
605
+ // src/animation-loop/make-animation-loop.ts
606
+ var import_core3 = require("@luma.gl/core");
607
+ function makeAnimationLoop(AnimationLoopTemplateCtor, props) {
608
+ let renderLoop = null;
609
+ const device = (props == null ? void 0 : props.device) || import_core3.luma.createDevice();
610
+ const animationLoop = new AnimationLoop({
611
+ ...props,
612
+ device,
613
+ async onInitialize(animationProps) {
614
+ renderLoop = new AnimationLoopTemplateCtor(animationProps);
615
+ return await (renderLoop == null ? void 0 : renderLoop.onInitialize(animationProps));
616
+ },
617
+ onRender: (animationProps) => renderLoop == null ? void 0 : renderLoop.onRender(animationProps),
618
+ onFinalize: (animationProps) => renderLoop == null ? void 0 : renderLoop.onFinalize(animationProps)
619
+ });
620
+ animationLoop.getInfo = () => {
621
+ return this.AnimationLoopTemplateCtor.info;
622
+ };
623
+ return animationLoop;
624
+ }
625
+
626
+ // src/model/model.ts
627
+ var import_core7 = require("@luma.gl/core");
628
+ var import_core8 = require("@luma.gl/core");
629
+ var import_core9 = require("@luma.gl/core");
630
+ var import_shadertools2 = require("@luma.gl/shadertools");
631
+
632
+ // src/shader-inputs.ts
633
+ var import_core4 = require("@luma.gl/core");
634
+ var import_shadertools = require("@luma.gl/shadertools");
635
+ var ShaderInputs = class {
636
+ /**
637
+ * The map of modules
638
+ * @todo should should this include the resolved dependencies?
639
+ */
640
+ modules;
641
+ /** Stores the uniform values for each module */
642
+ moduleUniforms;
643
+ /** Stores the uniform bindings for each module */
644
+ moduleBindings;
645
+ /** Tracks if uniforms have changed */
646
+ moduleUniformsChanged;
647
+ /**
648
+ * Create a new UniformStore instance
649
+ * @param modules
650
+ */
651
+ constructor(modules) {
652
+ const allModules = (0, import_shadertools._resolveModules)(Object.values(modules));
653
+ import_core4.log.log(1, "Creating ShaderInputs with modules", allModules.map((m) => m.name))();
654
+ this.modules = modules;
655
+ this.moduleUniforms = {};
656
+ this.moduleBindings = {};
657
+ for (const [name, module2] of Object.entries(modules)) {
658
+ const moduleName = name;
659
+ this.moduleUniforms[moduleName] = module2.defaultUniforms || {};
660
+ this.moduleBindings[moduleName] = {};
661
+ }
662
+ }
663
+ /** Destroy */
664
+ destroy() {
665
+ }
666
+ /**
667
+ * Set module props
668
+ */
669
+ setProps(props) {
670
+ var _a;
671
+ for (const name of Object.keys(props)) {
672
+ const moduleName = name;
673
+ const moduleProps = props[moduleName];
674
+ const module2 = this.modules[moduleName];
675
+ if (!module2) {
676
+ import_core4.log.warn(`Module ${name} not found`)();
677
+ continue;
678
+ }
679
+ const oldUniforms = this.moduleUniforms[moduleName];
680
+ const uniforms = ((_a = module2.getUniforms) == null ? void 0 : _a.call(module2, moduleProps, this.moduleUniforms[moduleName])) || moduleProps;
681
+ this.moduleUniforms[moduleName] = { ...oldUniforms, ...uniforms };
682
+ }
683
+ }
684
+ /** Merges all bindings for the shader (from the various modules) */
685
+ // getUniformBlocks(): Record<string, Texture | Sampler> {
686
+ // return this.moduleUniforms;
687
+ // }
688
+ /**
689
+ * Return the map of modules
690
+ * @todo should should this include the resolved dependencies?
691
+ */
692
+ getModules() {
693
+ return Object.values(this.modules);
694
+ }
695
+ /** Get all uniform values for all modules */
696
+ getUniformValues() {
697
+ return this.moduleUniforms;
698
+ }
699
+ /** Merges all bindings for the shader (from the various modules) */
700
+ getBindings() {
701
+ const bindings = {};
702
+ for (const moduleBindings of Object.values(this.moduleBindings)) {
703
+ Object.assign(bindings, moduleBindings);
704
+ }
705
+ return bindings;
706
+ }
707
+ getDebugTable() {
708
+ var _a;
709
+ const table = {};
710
+ for (const [moduleName, module2] of Object.entries(this.moduleUniforms)) {
711
+ for (const [key, value] of Object.entries(module2)) {
712
+ table[`${moduleName}.${key}`] = {
713
+ type: (_a = this.modules[moduleName].uniformTypes) == null ? void 0 : _a[key],
714
+ value: String(value)
715
+ };
716
+ }
717
+ }
718
+ return table;
719
+ }
720
+ };
721
+
722
+ // src/geometry/gpu-geometry.ts
723
+ var import_core5 = require("@luma.gl/core");
724
+ var GPUGeometry = class {
725
+ id;
726
+ userData = {};
727
+ /** Determines how vertices are read from the 'vertex' attributes */
728
+ topology;
729
+ bufferLayout = [];
730
+ vertexCount;
731
+ indices;
732
+ attributes;
733
+ constructor(props) {
734
+ this.id = props.id || (0, import_core5.uid)("geometry");
735
+ this.topology = props.topology;
736
+ this.indices = props.indices || null;
737
+ this.attributes = props.attributes;
738
+ this.vertexCount = props.vertexCount;
739
+ this.bufferLayout = props.bufferLayout || [];
740
+ if (this.indices) {
741
+ (0, import_core5.assert)(this.indices.usage === import_core5.Buffer.INDEX);
742
+ }
743
+ }
744
+ destroy() {
745
+ var _a;
746
+ this.indices.destroy();
747
+ this.attributes.positions.destroy();
748
+ this.attributes.normals.destroy();
749
+ this.attributes.texCoords.destroy();
750
+ (_a = this.attributes.colors) == null ? void 0 : _a.destroy();
751
+ }
752
+ getVertexCount() {
753
+ return this.vertexCount;
754
+ }
755
+ getAttributes() {
756
+ return this.attributes;
757
+ }
758
+ getIndexes() {
759
+ return this.indices;
760
+ }
761
+ _calculateVertexCount(positions) {
762
+ const vertexCount = positions.byteLength / 12;
763
+ return vertexCount;
764
+ }
765
+ };
766
+ function makeGPUGeometry(device, geometry) {
767
+ if (geometry instanceof GPUGeometry) {
768
+ return geometry;
769
+ }
770
+ const indices = getIndexBufferFromGeometry(device, geometry);
771
+ const { attributes, bufferLayout } = getAttributeBuffersFromGeometry(device, geometry);
772
+ return new GPUGeometry({
773
+ topology: geometry.topology || "triangle-list",
774
+ bufferLayout,
775
+ vertexCount: geometry.vertexCount,
776
+ indices,
777
+ attributes
778
+ });
779
+ }
780
+ function getIndexBufferFromGeometry(device, geometry) {
781
+ if (!geometry.indices) {
782
+ return void 0;
783
+ }
784
+ const data = geometry.indices.value;
785
+ return device.createBuffer({ usage: import_core5.Buffer.INDEX, data });
786
+ }
787
+ function getAttributeBuffersFromGeometry(device, geometry) {
788
+ const bufferLayout = [];
789
+ const attributes = {};
790
+ for (const [attributeName, attribute] of Object.entries(geometry.attributes)) {
791
+ let name = attributeName;
792
+ switch (attributeName) {
793
+ case "POSITION":
794
+ name = "positions";
795
+ break;
796
+ case "NORMAL":
797
+ name = "normals";
798
+ break;
799
+ case "TEXCOORD_0":
800
+ name = "texCoords";
801
+ break;
802
+ case "COLOR_0":
803
+ name = "colors";
804
+ break;
805
+ }
806
+ attributes[name] = device.createBuffer({ data: attribute.value, id: `${attributeName}-buffer` });
807
+ const { value, size, normalized } = attribute;
808
+ bufferLayout.push({ name, format: (0, import_core5.getVertexFormatFromAttribute)(value, size, normalized) });
809
+ }
810
+ const vertexCount = geometry._calculateVertexCount(geometry.attributes, geometry.indices);
811
+ return { attributes, bufferLayout, vertexCount };
812
+ }
813
+
814
+ // src/lib/pipeline-factory.ts
815
+ var import_core6 = require("@luma.gl/core");
816
+ var _PipelineFactory = class {
817
+ device;
818
+ _hashCounter = 0;
819
+ _hashes = {};
820
+ _useCounts = {};
821
+ _pipelineCache = {};
822
+ static getDefaultPipelineFactory(device) {
823
+ device._lumaData.defaultPipelineFactory = device._lumaData.defaultPipelineFactory || new _PipelineFactory(device);
824
+ return device._lumaData.defaultPipelineFactory;
825
+ }
826
+ constructor(device) {
827
+ this.device = device;
828
+ }
829
+ createRenderPipeline(options) {
830
+ const props = { ..._PipelineFactory.defaultProps, ...options };
831
+ const hash = this._hashRenderPipeline({ ...props });
832
+ if (!this._pipelineCache[hash]) {
833
+ const pipeline = this.device.createRenderPipeline({
834
+ ...props,
835
+ vs: this.device.createShader({ stage: "vertex", source: props.vs }),
836
+ fs: props.fs ? this.device.createShader({ stage: "fragment", source: props.fs }) : null
837
+ });
838
+ pipeline.hash = hash;
839
+ this._pipelineCache[hash] = pipeline;
840
+ this._useCounts[hash] = 0;
841
+ }
842
+ this._useCounts[hash]++;
843
+ return this._pipelineCache[hash];
844
+ }
845
+ release(pipeline) {
846
+ const hash = pipeline.hash;
847
+ this._useCounts[hash]--;
848
+ if (this._useCounts[hash] === 0) {
849
+ this._pipelineCache[hash].destroy();
850
+ delete this._pipelineCache[hash];
851
+ delete this._useCounts[hash];
852
+ }
853
+ }
854
+ // PRIVATE
855
+ _createRenderPipeline(props) {
856
+ if (!props.fs) {
857
+ throw new Error("fs");
858
+ }
859
+ const pipeline = this.device.createRenderPipeline({
860
+ ...props,
861
+ vs: this.device.createShader({ stage: "vertex", source: props.vs }),
862
+ fs: props.fs ? this.device.createShader({ stage: "fragment", source: props.fs }) : null
863
+ });
864
+ return pipeline;
865
+ }
866
+ /** Calculate a hash based on all the inputs for a render pipeline */
867
+ _hashRenderPipeline(props) {
868
+ const vsHash = this._getHash(props.vs);
869
+ const fsHash = props.fs ? this._getHash(props.fs) : 0;
870
+ const varyingHash = "-";
871
+ switch (this.device.info.type) {
872
+ case "webgpu":
873
+ const parameterHash = this._getHash(JSON.stringify(props.parameters));
874
+ const bufferLayoutHash = this._getHash(JSON.stringify(props.bufferLayout));
875
+ return `${vsHash}/${fsHash}V${varyingHash}T${props.topology}P${parameterHash}BL${bufferLayoutHash}}`;
876
+ default:
877
+ return `${vsHash}/${fsHash}V${varyingHash}`;
878
+ }
879
+ }
880
+ _getHash(key) {
881
+ if (this._hashes[key] === void 0) {
882
+ this._hashes[key] = this._hashCounter++;
883
+ }
884
+ return this._hashes[key];
885
+ }
886
+ };
887
+ var PipelineFactory = _PipelineFactory;
888
+ __publicField(PipelineFactory, "defaultProps", {
889
+ ...import_core6.RenderPipeline.defaultProps,
890
+ vs: void 0,
891
+ fs: void 0
892
+ });
893
+
894
+ // src/debug/debug-shader-layout.ts
895
+ function getDebugTableForShaderLayout(layout, name) {
896
+ var _a;
897
+ const table = {};
898
+ const header = "Values";
899
+ if (layout.attributes.length === 0 && !((_a = layout.varyings) == null ? void 0 : _a.length)) {
900
+ return { "No attributes or varyings": { [header]: "N/A" } };
901
+ }
902
+ for (const attributeDeclaration of layout.attributes) {
903
+ if (attributeDeclaration) {
904
+ const glslDeclaration = `${attributeDeclaration.location} ${attributeDeclaration.name}: ${attributeDeclaration.type}`;
905
+ table[`in ${glslDeclaration}`] = { [header]: attributeDeclaration.stepMode || "vertex" };
906
+ }
907
+ }
908
+ for (const varyingDeclaration of layout.varyings || []) {
909
+ const glslDeclaration = `${varyingDeclaration.location} ${varyingDeclaration.name}`;
910
+ table[`out ${glslDeclaration}`] = { [header]: JSON.stringify(varyingDeclaration.accessor) };
911
+ }
912
+ return table;
913
+ }
914
+
915
+ // src/debug/debug-framebuffer.ts
916
+ var canvas = null;
917
+ var ctx = null;
918
+ function debugFramebuffer(fbo, { id, minimap, opaque, top = "0", left = "0", rgbaScale = 1 }) {
919
+ if (!canvas) {
920
+ canvas = document.createElement("canvas");
921
+ canvas.id = id;
922
+ canvas.title = id;
923
+ canvas.style.zIndex = "100";
924
+ canvas.style.position = "absolute";
925
+ canvas.style.top = top;
926
+ canvas.style.left = left;
927
+ canvas.style.border = "blue 1px solid";
928
+ canvas.style.transform = "scaleY(-1)";
929
+ document.body.appendChild(canvas);
930
+ ctx = canvas.getContext("2d");
931
+ }
932
+ if (canvas.width !== fbo.width || canvas.height !== fbo.height) {
933
+ canvas.width = fbo.width / 2;
934
+ canvas.height = fbo.height / 2;
935
+ canvas.style.width = "400px";
936
+ canvas.style.height = "400px";
937
+ }
938
+ const color = fbo.device.readPixelsToArrayWebGL(fbo);
939
+ const imageData = ctx.createImageData(fbo.width, fbo.height);
940
+ const offset = 0;
941
+ for (let i = 0; i < color.length; i += 4) {
942
+ imageData.data[offset + i + 0] = color[i + 0] * rgbaScale;
943
+ imageData.data[offset + i + 1] = color[i + 1] * rgbaScale;
944
+ imageData.data[offset + i + 2] = color[i + 2] * rgbaScale;
945
+ imageData.data[offset + i + 3] = opaque ? 255 : color[i + 3] * rgbaScale;
946
+ }
947
+ ctx.putImageData(imageData, 0, 0);
948
+ }
949
+
950
+ // src/model/model.ts
951
+ var LOG_DRAW_PRIORITY = 2;
952
+ var LOG_DRAW_TIMEOUT = 1e4;
953
+ var _Model = class {
954
+ device;
955
+ id;
956
+ vs;
957
+ fs;
958
+ pipelineFactory;
959
+ userData = {};
960
+ // Fixed properties (change can trigger pipeline rebuild)
961
+ /** The render pipeline GPU parameters, depth testing etc */
962
+ parameters;
963
+ /** The primitive topology */
964
+ topology;
965
+ /** Buffer layout */
966
+ bufferLayout;
967
+ // Dynamic properties
968
+ /** Vertex count */
969
+ vertexCount;
970
+ /** instance count */
971
+ instanceCount = 0;
972
+ /** Index buffer */
973
+ indexBuffer = null;
974
+ /** Buffer-valued attributes */
975
+ bufferAttributes = {};
976
+ /** Constant-valued attributes */
977
+ constantAttributes = {};
978
+ /** Bindings (textures, samplers, uniform buffers) */
979
+ bindings = {};
980
+ /** Sets uniforms @deprecated Use uniform buffers and setBindings() for portability*/
981
+ uniforms = {};
982
+ /**
983
+ * VertexArray
984
+ * @note not implemented: if bufferLayout is updated, vertex array has to be rebuilt!
985
+ * @todo - allow application to define multiple vertex arrays?
986
+ * */
987
+ vertexArray;
988
+ /** TransformFeedback, WebGL 2 only. */
989
+ transformFeedback = null;
990
+ /** The underlying GPU "program". @note May be recreated if parameters change */
991
+ pipeline;
992
+ /** ShaderInputs instance */
993
+ shaderInputs;
994
+ _uniformStore;
995
+ _pipelineNeedsUpdate = "newly created";
996
+ _attributeInfos = {};
997
+ _gpuGeometry = null;
998
+ _getModuleUniforms;
999
+ props;
1000
+ constructor(device, props) {
1001
+ var _a, _b, _c;
1002
+ this.props = { ..._Model.defaultProps, ...props };
1003
+ props = this.props;
1004
+ this.id = props.id || (0, import_core8.uid)("model");
1005
+ this.device = device;
1006
+ Object.assign(this.userData, props.userData);
1007
+ const moduleMap = Object.fromEntries(
1008
+ ((_a = this.props.modules) == null ? void 0 : _a.map((module2) => [module2.name, module2])) || []
1009
+ );
1010
+ this.setShaderInputs(props.shaderInputs || new ShaderInputs(moduleMap));
1011
+ const isWebGPU = this.device.info.type === "webgpu";
1012
+ if (this.props.source) {
1013
+ if (isWebGPU) {
1014
+ this.props.shaderLayout ||= (0, import_shadertools2.getShaderLayoutFromWGSL)(this.props.source);
1015
+ }
1016
+ this.props.fs = this.props.source;
1017
+ this.props.vs = this.props.source;
1018
+ }
1019
+ if (isWebGPU && typeof this.props.vs !== "string") {
1020
+ this.props.shaderLayout ||= (0, import_shadertools2.getShaderLayoutFromWGSL)(this.props.vs.wgsl);
1021
+ }
1022
+ const platformInfo = getPlatformInfo(device);
1023
+ const modules = (((_b = this.props.modules) == null ? void 0 : _b.length) > 0 ? this.props.modules : (_c = this.shaderInputs) == null ? void 0 : _c.getModules()) || [];
1024
+ const { vs, fs, getUniforms } = this.props.shaderAssembler.assembleShaders({
1025
+ platformInfo,
1026
+ ...this.props,
1027
+ modules
1028
+ });
1029
+ this.vs = vs;
1030
+ this.fs = fs;
1031
+ this._getModuleUniforms = getUniforms;
1032
+ this.vertexCount = this.props.vertexCount;
1033
+ this.instanceCount = this.props.instanceCount;
1034
+ this.topology = this.props.topology;
1035
+ this.bufferLayout = this.props.bufferLayout;
1036
+ this.parameters = this.props.parameters;
1037
+ if (props.geometry) {
1038
+ this._gpuGeometry = this.setGeometry(props.geometry);
1039
+ }
1040
+ this.pipelineFactory = props.pipelineFactory || PipelineFactory.getDefaultPipelineFactory(this.device);
1041
+ this.pipeline = this._updatePipeline();
1042
+ this.vertexArray = device.createVertexArray({
1043
+ renderPipeline: this.pipeline
1044
+ });
1045
+ if (this._gpuGeometry) {
1046
+ this._setGeometryAttributes(this._gpuGeometry);
1047
+ }
1048
+ if (props.vertexCount) {
1049
+ this.setVertexCount(props.vertexCount);
1050
+ }
1051
+ if (props.instanceCount) {
1052
+ this.setInstanceCount(props.instanceCount);
1053
+ }
1054
+ if (props.indices) {
1055
+ throw new Error("Model.props.indices removed. Use props.indexBuffer");
1056
+ }
1057
+ if (props.indexBuffer) {
1058
+ this.setIndexBuffer(props.indexBuffer);
1059
+ }
1060
+ if (props.attributes) {
1061
+ this.setAttributes(props.attributes);
1062
+ }
1063
+ if (props.constantAttributes) {
1064
+ this.setConstantAttributes(props.constantAttributes);
1065
+ }
1066
+ if (props.bindings) {
1067
+ this.setBindings(props.bindings);
1068
+ }
1069
+ if (props.uniforms) {
1070
+ this.setUniforms(props.uniforms);
1071
+ }
1072
+ if (props.moduleSettings) {
1073
+ import_core8.log.warn("Model.props.moduleSettings is deprecated. Use Model.shaderInputs.setProps()")();
1074
+ this.updateModuleSettings(props.moduleSettings);
1075
+ }
1076
+ if (props.transformFeedback) {
1077
+ this.transformFeedback = props.transformFeedback;
1078
+ }
1079
+ Object.seal(this);
1080
+ }
1081
+ destroy() {
1082
+ this.pipelineFactory.release(this.pipeline);
1083
+ this._uniformStore.destroy();
1084
+ }
1085
+ // Draw call
1086
+ predraw() {
1087
+ this.updateShaderInputs();
1088
+ }
1089
+ draw(renderPass) {
1090
+ this.predraw();
1091
+ try {
1092
+ this._logDrawCallStart();
1093
+ this.pipeline = this._updatePipeline();
1094
+ this.pipeline.setBindings(this.bindings);
1095
+ this.pipeline.setUniforms(this.uniforms);
1096
+ this.pipeline.draw({
1097
+ renderPass,
1098
+ vertexArray: this.vertexArray,
1099
+ vertexCount: this.vertexCount,
1100
+ instanceCount: this.instanceCount,
1101
+ transformFeedback: this.transformFeedback
1102
+ });
1103
+ } finally {
1104
+ this._logDrawCallEnd();
1105
+ }
1106
+ this._logFramebuffer(renderPass);
1107
+ }
1108
+ // Update fixed fields (can trigger pipeline rebuild)
1109
+ /**
1110
+ * Updates the optional geometry
1111
+ * Geometry, set topology and bufferLayout
1112
+ * @note Can trigger a pipeline rebuild / pipeline cache fetch on WebGPU
1113
+ */
1114
+ setGeometry(geometry) {
1115
+ const gpuGeometry = geometry && makeGPUGeometry(this.device, geometry);
1116
+ this.setTopology(gpuGeometry.topology || "triangle-list");
1117
+ this.bufferLayout = mergeBufferLayouts(this.bufferLayout, gpuGeometry.bufferLayout);
1118
+ if (this.vertexArray) {
1119
+ this._setGeometryAttributes(gpuGeometry);
1120
+ }
1121
+ return gpuGeometry;
1122
+ }
1123
+ /**
1124
+ * Updates the optional geometry attributes
1125
+ * Geometry, sets several attributes, indexBuffer, and also vertex count
1126
+ * @note Can trigger a pipeline rebuild / pipeline cache fetch on WebGPU
1127
+ */
1128
+ _setGeometryAttributes(gpuGeometry) {
1129
+ const attributes = { ...gpuGeometry.attributes };
1130
+ for (const [attributeName] of Object.entries(attributes)) {
1131
+ if (!this.pipeline.shaderLayout.attributes.find((layout) => layout.name === attributeName) && attributeName !== "positions") {
1132
+ delete attributes[attributeName];
1133
+ }
1134
+ }
1135
+ this.vertexCount = gpuGeometry.vertexCount;
1136
+ this.setIndexBuffer(gpuGeometry.indices);
1137
+ this.setAttributes(gpuGeometry.attributes, "ignore-unknown");
1138
+ this.setAttributes(attributes);
1139
+ }
1140
+ /**
1141
+ * Updates the primitive topology ('triangle-list', 'triangle-strip' etc).
1142
+ * @note Triggers a pipeline rebuild / pipeline cache fetch on WebGPU
1143
+ */
1144
+ setTopology(topology) {
1145
+ if (topology !== this.topology) {
1146
+ this.topology = topology;
1147
+ this._setPipelineNeedsUpdate("topology");
1148
+ }
1149
+ }
1150
+ /**
1151
+ * Updates the buffer layout.
1152
+ * @note Triggers a pipeline rebuild / pipeline cache fetch on WebGPU
1153
+ */
1154
+ setBufferLayout(bufferLayout) {
1155
+ this.bufferLayout = this._gpuGeometry ? mergeBufferLayouts(bufferLayout, this._gpuGeometry.bufferLayout) : bufferLayout;
1156
+ this._setPipelineNeedsUpdate("bufferLayout");
1157
+ this.pipeline = this._updatePipeline();
1158
+ this.vertexArray = this.device.createVertexArray({
1159
+ renderPipeline: this.pipeline
1160
+ });
1161
+ if (this._gpuGeometry) {
1162
+ this._setGeometryAttributes(this._gpuGeometry);
1163
+ }
1164
+ }
1165
+ /**
1166
+ * Set GPU parameters.
1167
+ * @note Can trigger a pipeline rebuild / pipeline cache fetch.
1168
+ * @param parameters
1169
+ */
1170
+ setParameters(parameters) {
1171
+ if (!(0, import_core8.deepEqual)(parameters, this.parameters, 2)) {
1172
+ this.parameters = parameters;
1173
+ this._setPipelineNeedsUpdate("parameters");
1174
+ }
1175
+ }
1176
+ // Update dynamic fields
1177
+ /**
1178
+ * Updates the vertex count (used in draw calls)
1179
+ * @note Any attributes with stepMode=vertex need to be at least this big
1180
+ */
1181
+ setVertexCount(vertexCount) {
1182
+ this.vertexCount = vertexCount;
1183
+ }
1184
+ /**
1185
+ * Updates the instance count (used in draw calls)
1186
+ * @note Any attributes with stepMode=instance need to be at least this big
1187
+ */
1188
+ setInstanceCount(instanceCount) {
1189
+ this.instanceCount = instanceCount;
1190
+ }
1191
+ setShaderInputs(shaderInputs) {
1192
+ this.shaderInputs = shaderInputs;
1193
+ this._uniformStore = new import_core7.UniformStore(this.shaderInputs.modules);
1194
+ for (const moduleName of Object.keys(this.shaderInputs.modules)) {
1195
+ const uniformBuffer = this._uniformStore.getManagedUniformBuffer(this.device, moduleName);
1196
+ this.bindings[`${moduleName}Uniforms`] = uniformBuffer;
1197
+ }
1198
+ }
1199
+ /**
1200
+ * Updates shader module settings (which results in uniforms being set)
1201
+ */
1202
+ setShaderModuleProps(props) {
1203
+ const uniforms = this._getModuleUniforms(props);
1204
+ const keys = Object.keys(uniforms).filter((k) => {
1205
+ const uniform = uniforms[k];
1206
+ return !(0, import_core8.isNumberArray)(uniform) && typeof uniform !== "number" && typeof uniform !== "boolean";
1207
+ });
1208
+ const bindings = {};
1209
+ for (const k of keys) {
1210
+ bindings[k] = uniforms[k];
1211
+ delete uniforms[k];
1212
+ }
1213
+ }
1214
+ updateShaderInputs() {
1215
+ this._uniformStore.setUniforms(this.shaderInputs.getUniformValues());
1216
+ }
1217
+ /**
1218
+ * @deprecated Updates shader module settings (which results in uniforms being set)
1219
+ */
1220
+ updateModuleSettings(props) {
1221
+ import_core8.log.warn("Model.updateModuleSettings is deprecated. Use Model.shaderInputs.setProps()")();
1222
+ const { bindings, uniforms } = (0, import_core8.splitUniformsAndBindings)(this._getModuleUniforms(props));
1223
+ Object.assign(this.bindings, bindings);
1224
+ Object.assign(this.uniforms, uniforms);
1225
+ }
1226
+ /**
1227
+ * Sets bindings (textures, samplers, uniform buffers)
1228
+ */
1229
+ setBindings(bindings) {
1230
+ Object.assign(this.bindings, bindings);
1231
+ }
1232
+ /**
1233
+ * Sets individual uniforms
1234
+ * @deprecated WebGL only, use uniform buffers for portability
1235
+ * @param uniforms
1236
+ * @returns self for chaining
1237
+ */
1238
+ setUniforms(uniforms) {
1239
+ this.pipeline.setUniforms(uniforms);
1240
+ Object.assign(this.uniforms, uniforms);
1241
+ }
1242
+ /**
1243
+ * Sets the index buffer
1244
+ * @todo - how to unset it if we change geometry?
1245
+ */
1246
+ setIndexBuffer(indexBuffer) {
1247
+ this.vertexArray.setIndexBuffer(indexBuffer);
1248
+ }
1249
+ /**
1250
+ * Updates optional transform feedback. WebGL 2 only.
1251
+ */
1252
+ setTransformFeedback(transformFeedback) {
1253
+ this.transformFeedback = transformFeedback;
1254
+ }
1255
+ /**
1256
+ * Sets attributes (buffers)
1257
+ * @note Overrides any attributes previously set with the same name
1258
+ */
1259
+ setAttributes(buffers, _option) {
1260
+ if (buffers.indices) {
1261
+ import_core8.log.warn(
1262
+ `Model:${this.id} setAttributes() - indexBuffer should be set using setIndexBuffer()`
1263
+ )();
1264
+ }
1265
+ for (const [bufferName, buffer] of Object.entries(buffers)) {
1266
+ const bufferLayout = this.bufferLayout.find((layout) => getAttributeNames(layout).includes(bufferName));
1267
+ if (!bufferLayout) {
1268
+ import_core8.log.warn(`Model(${this.id}): Missing layout for buffer "${bufferName}".`)();
1269
+ continue;
1270
+ }
1271
+ const attributeNames = getAttributeNames(bufferLayout);
1272
+ let set = false;
1273
+ for (const attributeName of attributeNames) {
1274
+ const attributeInfo = this._attributeInfos[attributeName];
1275
+ if (attributeInfo) {
1276
+ this.vertexArray.setBuffer(attributeInfo.location, buffer);
1277
+ set = true;
1278
+ }
1279
+ }
1280
+ if (!set && _option !== "ignore-unknown") {
1281
+ import_core8.log.warn(
1282
+ `Model(${this.id}): Ignoring buffer "${buffer.id}" for unknown attribute "${bufferName}"`
1283
+ )();
1284
+ }
1285
+ }
1286
+ }
1287
+ /**
1288
+ * Sets constant attributes
1289
+ * @note Overrides any attributes previously set with the same name
1290
+ * Constant attributes are only supported in WebGL, not in WebGPU
1291
+ * Any attribute that is disabled in the current vertex array object
1292
+ * is read from the context's global constant value for that attribute location.
1293
+ * @param constantAttributes
1294
+ */
1295
+ setConstantAttributes(attributes) {
1296
+ for (const [attributeName, value] of Object.entries(attributes)) {
1297
+ const attributeInfo = this._attributeInfos[attributeName];
1298
+ if (attributeInfo) {
1299
+ this.vertexArray.setConstant(attributeInfo.location, value);
1300
+ } else {
1301
+ import_core8.log.warn(
1302
+ `Model "${this.id}: Ignoring constant supplied for unknown attribute "${attributeName}"`
1303
+ )();
1304
+ }
1305
+ }
1306
+ }
1307
+ _setPipelineNeedsUpdate(reason) {
1308
+ this._pipelineNeedsUpdate = this._pipelineNeedsUpdate || reason;
1309
+ }
1310
+ _updatePipeline() {
1311
+ if (this._pipelineNeedsUpdate) {
1312
+ if (this.pipeline) {
1313
+ import_core8.log.log(
1314
+ 1,
1315
+ `Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`
1316
+ )();
1317
+ }
1318
+ this._pipelineNeedsUpdate = false;
1319
+ const vs = this.device.createShader({
1320
+ id: `${this.id}-vertex`,
1321
+ stage: "vertex",
1322
+ source: this.vs
1323
+ });
1324
+ const fs = this.fs ? this.device.createShader({
1325
+ id: `${this.id}-fragment`,
1326
+ stage: "fragment",
1327
+ source: this.fs
1328
+ }) : null;
1329
+ this.pipeline = this.device.createRenderPipeline({
1330
+ ...this.props,
1331
+ bufferLayout: this.bufferLayout,
1332
+ topology: this.topology,
1333
+ parameters: this.parameters,
1334
+ vs,
1335
+ fs
1336
+ });
1337
+ this._attributeInfos = (0, import_core9.getAttributeInfosFromLayouts)(
1338
+ this.pipeline.shaderLayout,
1339
+ this.bufferLayout
1340
+ );
1341
+ }
1342
+ return this.pipeline;
1343
+ }
1344
+ /** Throttle draw call logging */
1345
+ _lastLogTime = 0;
1346
+ _logOpen = false;
1347
+ _logDrawCallStart() {
1348
+ const logDrawTimeout = import_core8.log.level > 3 ? 0 : LOG_DRAW_TIMEOUT;
1349
+ if (import_core8.log.level < 2 || Date.now() - this._lastLogTime < logDrawTimeout) {
1350
+ return;
1351
+ }
1352
+ this._lastLogTime = Date.now();
1353
+ this._logOpen = true;
1354
+ import_core8.log.group(LOG_DRAW_PRIORITY, `>>> DRAWING MODEL ${this.id}`, { collapsed: import_core8.log.level <= 2 })();
1355
+ }
1356
+ _logDrawCallEnd() {
1357
+ if (this._logOpen) {
1358
+ const shaderLayoutTable = getDebugTableForShaderLayout(this.pipeline.shaderLayout, this.id);
1359
+ import_core8.log.table(LOG_DRAW_PRIORITY, shaderLayoutTable)();
1360
+ const uniformTable = this.shaderInputs.getDebugTable();
1361
+ for (const [name, value] of Object.entries(this.uniforms)) {
1362
+ uniformTable[name] = { value };
1363
+ }
1364
+ import_core8.log.table(LOG_DRAW_PRIORITY, uniformTable)();
1365
+ const attributeTable = this._getAttributeDebugTable();
1366
+ import_core8.log.table(LOG_DRAW_PRIORITY, this._attributeInfos)();
1367
+ import_core8.log.table(LOG_DRAW_PRIORITY, attributeTable)();
1368
+ import_core8.log.groupEnd(LOG_DRAW_PRIORITY)();
1369
+ this._logOpen = false;
1370
+ }
1371
+ }
1372
+ _drawCount = 0;
1373
+ _logFramebuffer(renderPass) {
1374
+ const debugFramebuffers = import_core8.log.get("framebuffer");
1375
+ this._drawCount++;
1376
+ if (!debugFramebuffers || this._drawCount++ > 3 && this._drawCount % 60) {
1377
+ return;
1378
+ }
1379
+ const framebuffer = renderPass.props.framebuffer;
1380
+ if (framebuffer) {
1381
+ debugFramebuffer(framebuffer, { id: framebuffer.id, minimap: true });
1382
+ }
1383
+ }
1384
+ _getAttributeDebugTable() {
1385
+ const table = {};
1386
+ for (const [name, attributeInfo] of Object.entries(this._attributeInfos)) {
1387
+ table[attributeInfo.location] = {
1388
+ name,
1389
+ type: attributeInfo.shaderType,
1390
+ values: this._getBufferOrConstantValues(
1391
+ this.vertexArray.attributes[attributeInfo.location],
1392
+ attributeInfo.bufferDataType
1393
+ )
1394
+ };
1395
+ }
1396
+ if (this.vertexArray.indexBuffer) {
1397
+ const { indexBuffer } = this.vertexArray;
1398
+ const values = indexBuffer.indexType === "uint32" ? new Uint32Array(indexBuffer.debugData) : new Uint16Array(indexBuffer.debugData);
1399
+ table.indices = {
1400
+ name: "indices",
1401
+ type: indexBuffer.indexType,
1402
+ values: values.toString()
1403
+ };
1404
+ }
1405
+ return table;
1406
+ }
1407
+ // TODO - fix typing of luma data types
1408
+ _getBufferOrConstantValues(attribute, dataType) {
1409
+ const TypedArrayConstructor = (0, import_core7.getTypedArrayFromDataType)(dataType);
1410
+ const typedArray = attribute instanceof import_core7.Buffer ? new TypedArrayConstructor(attribute.debugData) : attribute;
1411
+ return typedArray.toString();
1412
+ }
1413
+ };
1414
+ var Model = _Model;
1415
+ __publicField(Model, "defaultProps", {
1416
+ ...import_core7.RenderPipeline.defaultProps,
1417
+ source: null,
1418
+ vs: null,
1419
+ fs: null,
1420
+ id: "unnamed",
1421
+ handle: void 0,
1422
+ userData: {},
1423
+ defines: {},
1424
+ modules: [],
1425
+ moduleSettings: void 0,
1426
+ geometry: null,
1427
+ indexBuffer: null,
1428
+ attributes: {},
1429
+ constantAttributes: {},
1430
+ varyings: [],
1431
+ shaderInputs: void 0,
1432
+ pipelineFactory: void 0,
1433
+ transformFeedback: void 0,
1434
+ shaderAssembler: import_shadertools2.ShaderAssembler.getDefaultShaderAssembler()
1435
+ });
1436
+ function mergeBufferLayouts(layouts1, layouts2) {
1437
+ const layouts = [...layouts1];
1438
+ for (const attribute of layouts2) {
1439
+ const index = layouts.findIndex((attribute2) => attribute2.name === attribute.name);
1440
+ if (index < 0) {
1441
+ layouts.push(attribute);
1442
+ } else {
1443
+ layouts[index] = attribute;
1444
+ }
1445
+ }
1446
+ return layouts;
1447
+ }
1448
+ function getPlatformInfo(device) {
1449
+ return {
1450
+ type: device.info.type,
1451
+ shaderLanguage: device.info.shadingLanguage,
1452
+ shaderLanguageVersion: device.info.shadingLanguageVersion,
1453
+ gpu: device.info.gpu,
1454
+ features: device.features
1455
+ };
1456
+ }
1457
+ function getAttributeNames(bufferLayout) {
1458
+ var _a;
1459
+ return bufferLayout.attributes ? (_a = bufferLayout.attributes) == null ? void 0 : _a.map((layout) => layout.attribute) : [bufferLayout.name];
1460
+ }
1461
+
1462
+ // src/transform/buffer-transform.ts
1463
+ var import_core10 = require("@luma.gl/core");
1464
+ var import_shadertools3 = require("@luma.gl/shadertools");
1465
+ var BufferTransform = class {
1466
+ device;
1467
+ model;
1468
+ transformFeedback;
1469
+ /** @deprecated Use device feature test. */
1470
+ static isSupported(device) {
1471
+ return device.features.has("transform-feedback-webgl2");
1472
+ }
1473
+ constructor(device, props = Model.defaultProps) {
1474
+ (0, import_core10.assert)(device.features.has("transform-feedback-webgl2"), "Device must support transform feedback");
1475
+ this.device = device;
1476
+ this.model = new Model(this.device, {
1477
+ id: props.id || "buffer-transform-model",
1478
+ fs: props.fs || (0, import_shadertools3.getPassthroughFS)({ version: 300 }),
1479
+ topology: props.topology || "point-list",
1480
+ ...props
1481
+ });
1482
+ this.transformFeedback = this.device.createTransformFeedback({
1483
+ layout: this.model.pipeline.shaderLayout,
1484
+ buffers: props.feedbackBuffers
1485
+ });
1486
+ this.model.setTransformFeedback(this.transformFeedback);
1487
+ Object.seal(this);
1488
+ }
1489
+ /** Destroy owned resources. */
1490
+ destroy() {
1491
+ if (this.model) {
1492
+ this.model.destroy();
1493
+ }
1494
+ }
1495
+ /** @deprecated Use {@link destroy}. */
1496
+ delete() {
1497
+ this.destroy();
1498
+ }
1499
+ /** Run one transform loop. */
1500
+ run(options) {
1501
+ const renderPass = this.device.beginRenderPass(options);
1502
+ this.model.draw(renderPass);
1503
+ renderPass.end();
1504
+ }
1505
+ /** @deprecated */
1506
+ update(...args) {
1507
+ console.warn("TextureTransform#update() not implemented");
1508
+ }
1509
+ /** Returns the {@link Buffer} or {@link BufferRange} for given varying name. */
1510
+ getBuffer(varyingName) {
1511
+ return this.transformFeedback.getBuffer(varyingName);
1512
+ }
1513
+ readAsync(varyingName) {
1514
+ const result = this.getBuffer(varyingName);
1515
+ if (result instanceof import_core10.Buffer) {
1516
+ return result.readAsync();
1517
+ }
1518
+ const { buffer, byteOffset = 0, byteLength = buffer.byteLength } = result;
1519
+ return buffer.readAsync(byteOffset, byteLength);
1520
+ }
1521
+ };
1522
+
1523
+ // src/transform/texture-transform.ts
1524
+ var import_shadertools4 = require("@luma.gl/shadertools");
1525
+ var FS_OUTPUT_VARIABLE = "transform_output";
1526
+ var TextureTransform = class {
1527
+ device;
1528
+ model;
1529
+ sampler;
1530
+ currentIndex = 0;
1531
+ samplerTextureMap = null;
1532
+ bindings = [];
1533
+ // each element is an object : {sourceTextures, targetTexture, framebuffer}
1534
+ resources = {};
1535
+ // resources to be deleted
1536
+ constructor(device, props) {
1537
+ this.device = device;
1538
+ this.sampler = device.createSampler({
1539
+ addressModeU: "clamp-to-edge",
1540
+ addressModeV: "clamp-to-edge",
1541
+ minFilter: "nearest",
1542
+ magFilter: "nearest",
1543
+ mipmapFilter: "nearest"
1544
+ });
1545
+ this.model = new Model(this.device, {
1546
+ id: props.id || "texture-transform-model",
1547
+ fs: props.fs || (0, import_shadertools4.getPassthroughFS)({
1548
+ version: 300,
1549
+ input: props.targetTextureVarying,
1550
+ inputChannels: props.targetTextureChannels,
1551
+ output: FS_OUTPUT_VARIABLE
1552
+ }),
1553
+ vertexCount: props.vertexCount,
1554
+ // TODO(donmccurdy): Naming?
1555
+ ...props
1556
+ });
1557
+ this._initialize(props);
1558
+ Object.seal(this);
1559
+ }
1560
+ // Delete owned resources.
1561
+ destroy() {
1562
+ }
1563
+ /** @deprecated Use {@link destroy}. */
1564
+ delete() {
1565
+ this.destroy();
1566
+ }
1567
+ run(options) {
1568
+ const { framebuffer } = this.bindings[this.currentIndex];
1569
+ const renderPass = this.device.beginRenderPass({ framebuffer, ...options });
1570
+ this.model.draw(renderPass);
1571
+ renderPass.end();
1572
+ }
1573
+ /** @deprecated */
1574
+ update(...args) {
1575
+ console.warn("TextureTransform#update() not implemented");
1576
+ }
1577
+ getData({ packed = false } = {}) {
1578
+ throw new Error("getData() not implemented");
1579
+ }
1580
+ getTargetTexture() {
1581
+ const { targetTexture } = this.bindings[this.currentIndex];
1582
+ return targetTexture;
1583
+ }
1584
+ getFramebuffer() {
1585
+ const currentResources = this.bindings[this.currentIndex];
1586
+ return currentResources.framebuffer;
1587
+ }
1588
+ // Private
1589
+ _initialize(props) {
1590
+ this._updateBindings(props);
1591
+ }
1592
+ _updateBindings(props) {
1593
+ this.bindings[this.currentIndex] = this._updateBinding(this.bindings[this.currentIndex], props);
1594
+ }
1595
+ _updateBinding(binding, { sourceBuffers, sourceTextures, targetTexture }) {
1596
+ if (!binding) {
1597
+ binding = {
1598
+ sourceBuffers: {},
1599
+ sourceTextures: {},
1600
+ targetTexture: null
1601
+ };
1602
+ }
1603
+ Object.assign(binding.sourceTextures, sourceTextures);
1604
+ Object.assign(binding.sourceBuffers, sourceBuffers);
1605
+ if (targetTexture) {
1606
+ binding.targetTexture = targetTexture;
1607
+ const { width, height } = targetTexture;
1608
+ if (binding.framebuffer) {
1609
+ binding.framebuffer.destroy();
1610
+ }
1611
+ binding.framebuffer = this.device.createFramebuffer({
1612
+ id: "transform-framebuffer",
1613
+ width,
1614
+ height,
1615
+ colorAttachments: [targetTexture]
1616
+ });
1617
+ binding.framebuffer.resize({ width, height });
1618
+ }
1619
+ return binding;
1620
+ }
1621
+ // set texture filtering parameters on source textures.
1622
+ _setSourceTextureParameters() {
1623
+ const index = this.currentIndex;
1624
+ const { sourceTextures } = this.bindings[index];
1625
+ for (const name in sourceTextures) {
1626
+ sourceTextures[name].sampler = this.sampler;
1627
+ }
1628
+ }
1629
+ };
1630
+
1631
+ // src/lib/clip-space.ts
1632
+ var import_core12 = require("@luma.gl/core");
1633
+
1634
+ // src/geometry/geometry.ts
1635
+ var import_core11 = require("@luma.gl/core");
1636
+ var Geometry = class {
1637
+ id;
1638
+ /** Determines how vertices are read from the 'vertex' attributes */
1639
+ topology;
1640
+ vertexCount;
1641
+ indices;
1642
+ attributes;
1643
+ userData = {};
1644
+ constructor(props) {
1645
+ const { attributes = {}, indices = null, vertexCount = null } = props;
1646
+ this.id = props.id || (0, import_core11.uid)("geometry");
1647
+ this.topology = props.topology;
1648
+ if (indices) {
1649
+ this.indices = ArrayBuffer.isView(indices) ? { value: indices, size: 1 } : indices;
1650
+ }
1651
+ this.attributes = {};
1652
+ for (const [attributeName, attributeValue] of Object.entries(attributes)) {
1653
+ const attribute = ArrayBuffer.isView(attributeValue) ? { value: attributeValue } : attributeValue;
1654
+ (0, import_core11.assert)(
1655
+ ArrayBuffer.isView(attribute.value),
1656
+ `${this._print(attributeName)}: must be typed array or object with value as typed array`
1657
+ );
1658
+ if ((attributeName === "POSITION" || attributeName === "positions") && !attribute.size) {
1659
+ attribute.size = 3;
1660
+ }
1661
+ if (attributeName === "indices") {
1662
+ (0, import_core11.assert)(!this.indices);
1663
+ this.indices = attribute;
1664
+ } else {
1665
+ this.attributes[attributeName] = attribute;
1666
+ }
1667
+ }
1668
+ if (this.indices && this.indices.isIndexed !== void 0) {
1669
+ this.indices = Object.assign({}, this.indices);
1670
+ delete this.indices.isIndexed;
1671
+ }
1672
+ this.vertexCount = vertexCount || this._calculateVertexCount(this.attributes, this.indices);
1673
+ }
1674
+ getVertexCount() {
1675
+ return this.vertexCount;
1676
+ }
1677
+ /**
1678
+ * Return an object with all attributes plus indices added as a field.
1679
+ * TODO Geometry types are a mess
1680
+ */
1681
+ getAttributes() {
1682
+ return this.indices ? { indices: this.indices, ...this.attributes } : this.attributes;
1683
+ }
1684
+ // PRIVATE
1685
+ _print(attributeName) {
1686
+ return `Geometry ${this.id} attribute ${attributeName}`;
1687
+ }
1688
+ /**
1689
+ * GeometryAttribute
1690
+ * value: typed array
1691
+ * type: indices, vertices, uvs
1692
+ * size: elements per vertex
1693
+ * target: WebGL buffer type (string or constant)
1694
+ *
1695
+ * @param attributes
1696
+ * @param indices
1697
+ * @returns
1698
+ */
1699
+ _setAttributes(attributes, indices) {
1700
+ return this;
1701
+ }
1702
+ _calculateVertexCount(attributes, indices) {
1703
+ if (indices) {
1704
+ return indices.value.length;
1705
+ }
1706
+ let vertexCount = Infinity;
1707
+ for (const attribute of Object.values(attributes)) {
1708
+ const { value, size, constant } = attribute;
1709
+ if (!constant && value && size >= 1) {
1710
+ vertexCount = Math.min(vertexCount, value.length / size);
1711
+ }
1712
+ }
1713
+ (0, import_core11.assert)(Number.isFinite(vertexCount));
1714
+ return vertexCount;
1715
+ }
1716
+ };
1717
+
1718
+ // src/lib/clip-space.ts
1719
+ var CLIPSPACE_VERTEX_SHADER = import_core12.glsl`\
1720
+ in vec2 aClipSpacePosition;
1721
+ in vec2 aTexCoord;
1722
+ in vec2 aCoordinate;
1723
+
1724
+ out vec2 position;
1725
+ out vec2 coordinate;
1726
+ out vec2 uv;
1727
+
1728
+ void main(void) {
1729
+ gl_Position = vec4(aClipSpacePosition, 0., 1.);
1730
+ position = aClipSpacePosition;
1731
+ coordinate = aCoordinate;
1732
+ uv = aTexCoord;
1733
+ }
1734
+ `;
1735
+ var POSITIONS = [-1, -1, 1, -1, -1, 1, 1, 1];
1736
+ var ClipSpace = class extends Model {
1737
+ constructor(device, opts) {
1738
+ const TEX_COORDS = POSITIONS.map((coord) => coord === -1 ? 0 : coord);
1739
+ super(
1740
+ device,
1741
+ {
1742
+ ...opts,
1743
+ vs: CLIPSPACE_VERTEX_SHADER,
1744
+ vertexCount: 4,
1745
+ geometry: new Geometry({
1746
+ topology: "triangle-strip",
1747
+ vertexCount: 4,
1748
+ attributes: {
1749
+ aClipSpacePosition: { size: 2, value: new Float32Array(POSITIONS) },
1750
+ aTexCoord: { size: 2, value: new Float32Array(TEX_COORDS) },
1751
+ aCoordinate: { size: 2, value: new Float32Array(TEX_COORDS) }
1752
+ }
1753
+ })
1754
+ }
1755
+ );
1756
+ }
1757
+ };
1758
+
1759
+ // src/scenegraph/scenegraph-node.ts
1760
+ var import_core13 = require("@luma.gl/core");
1761
+ var import_core14 = require("@math.gl/core");
1762
+ var ScenegraphNode = class {
1763
+ id;
1764
+ matrix = new import_core14.Matrix4();
1765
+ display = true;
1766
+ position = new import_core14.Vector3();
1767
+ rotation = new import_core14.Vector3();
1768
+ scale = new import_core14.Vector3(1, 1, 1);
1769
+ userData = {};
1770
+ props = {};
1771
+ constructor(props = {}) {
1772
+ const { id } = props;
1773
+ this.id = id || (0, import_core13.uid)(this.constructor.name);
1774
+ this._setScenegraphNodeProps(props);
1775
+ }
1776
+ getBounds() {
1777
+ return null;
1778
+ }
1779
+ destroy() {
1780
+ }
1781
+ /** @deprecated use .destroy() */
1782
+ delete() {
1783
+ this.destroy();
1784
+ }
1785
+ setProps(props) {
1786
+ this._setScenegraphNodeProps(props);
1787
+ return this;
1788
+ }
1789
+ toString() {
1790
+ return `{type: ScenegraphNode, id: ${this.id})}`;
1791
+ }
1792
+ setPosition(position) {
1793
+ (0, import_core13.assert)(position.length === 3, "setPosition requires vector argument");
1794
+ this.position = position;
1795
+ return this;
1796
+ }
1797
+ setRotation(rotation) {
1798
+ (0, import_core13.assert)(rotation.length === 3, "setRotation requires vector argument");
1799
+ this.rotation = rotation;
1800
+ return this;
1801
+ }
1802
+ setScale(scale) {
1803
+ (0, import_core13.assert)(scale.length === 3, "setScale requires vector argument");
1804
+ this.scale = scale;
1805
+ return this;
1806
+ }
1807
+ setMatrix(matrix, copyMatrix = true) {
1808
+ if (copyMatrix) {
1809
+ this.matrix.copy(matrix);
1810
+ } else {
1811
+ this.matrix = matrix;
1812
+ }
1813
+ }
1814
+ setMatrixComponents(components) {
1815
+ const { position, rotation, scale, update = true } = components;
1816
+ if (position) {
1817
+ this.setPosition(position);
1818
+ }
1819
+ if (rotation) {
1820
+ this.setRotation(rotation);
1821
+ }
1822
+ if (scale) {
1823
+ this.setScale(scale);
1824
+ }
1825
+ if (update) {
1826
+ this.updateMatrix();
1827
+ }
1828
+ return this;
1829
+ }
1830
+ updateMatrix() {
1831
+ const pos = this.position;
1832
+ const rot = this.rotation;
1833
+ const scale = this.scale;
1834
+ this.matrix.identity();
1835
+ this.matrix.translate(pos);
1836
+ this.matrix.rotateXYZ(rot);
1837
+ this.matrix.scale(scale);
1838
+ return this;
1839
+ }
1840
+ update(options = {}) {
1841
+ const { position, rotation, scale } = options;
1842
+ if (position) {
1843
+ this.setPosition(position);
1844
+ }
1845
+ if (rotation) {
1846
+ this.setRotation(rotation);
1847
+ }
1848
+ if (scale) {
1849
+ this.setScale(scale);
1850
+ }
1851
+ this.updateMatrix();
1852
+ return this;
1853
+ }
1854
+ getCoordinateUniforms(viewMatrix, modelMatrix) {
1855
+ (0, import_core13.assert)(viewMatrix);
1856
+ modelMatrix = modelMatrix || this.matrix;
1857
+ const worldMatrix = new import_core14.Matrix4(viewMatrix).multiplyRight(modelMatrix);
1858
+ const worldInverse = worldMatrix.invert();
1859
+ const worldInverseTranspose = worldInverse.transpose();
1860
+ return {
1861
+ viewMatrix,
1862
+ modelMatrix,
1863
+ objectMatrix: modelMatrix,
1864
+ worldMatrix,
1865
+ worldInverseMatrix: worldInverse,
1866
+ worldInverseTransposeMatrix: worldInverseTranspose
1867
+ };
1868
+ }
1869
+ // TODO - copied code, not yet vetted
1870
+ /*
1871
+ transform() {
1872
+ if (!this.parent) {
1873
+ this.endPosition.set(this.position);
1874
+ this.endRotation.set(this.rotation);
1875
+ this.endScale.set(this.scale);
1876
+ } else {
1877
+ const parent = this.parent;
1878
+ this.endPosition.set(this.position.add(parent.endPosition));
1879
+ this.endRotation.set(this.rotation.add(parent.endRotation));
1880
+ this.endScale.set(this.scale.add(parent.endScale));
1881
+ }
1882
+
1883
+ const ch = this.children;
1884
+ for (let i = 0; i < ch.length; ++i) {
1885
+ ch[i].transform();
1886
+ }
1887
+
1888
+ return this;
1889
+ }
1890
+ */
1891
+ _setScenegraphNodeProps(props) {
1892
+ if ("display" in props) {
1893
+ this.display = props.display;
1894
+ }
1895
+ if ("position" in props) {
1896
+ this.setPosition(props.position);
1897
+ }
1898
+ if ("rotation" in props) {
1899
+ this.setRotation(props.rotation);
1900
+ }
1901
+ if ("scale" in props) {
1902
+ this.setScale(props.scale);
1903
+ }
1904
+ if ("matrix" in props) {
1905
+ this.setMatrix(props.matrix);
1906
+ }
1907
+ Object.assign(this.props, props);
1908
+ }
1909
+ };
1910
+
1911
+ // src/scenegraph/group-node.ts
1912
+ var import_core15 = require("@math.gl/core");
1913
+ var import_core16 = require("@luma.gl/core");
1914
+ var GroupNode = class extends ScenegraphNode {
1915
+ children;
1916
+ constructor(props = {}) {
1917
+ props = Array.isArray(props) ? { children: props } : props;
1918
+ const { children = [] } = props;
1919
+ import_core16.log.assert(
1920
+ children.every((child) => child instanceof ScenegraphNode),
1921
+ "every child must an instance of ScenegraphNode"
1922
+ );
1923
+ super(props);
1924
+ this.children = children;
1925
+ }
1926
+ getBounds() {
1927
+ const result = [[Infinity, Infinity, Infinity], [-Infinity, -Infinity, -Infinity]];
1928
+ this.traverse((node, { worldMatrix }) => {
1929
+ const bounds = node.getBounds();
1930
+ if (!bounds) {
1931
+ return;
1932
+ }
1933
+ const [min, max] = bounds;
1934
+ const center = new import_core15.Vector3(min).add(max).divide([2, 2, 2]);
1935
+ worldMatrix.transformAsPoint(center, center);
1936
+ const halfSize = new import_core15.Vector3(max).subtract(min).divide([2, 2, 2]);
1937
+ worldMatrix.transformAsVector(halfSize, halfSize);
1938
+ for (let v = 0; v < 8; v++) {
1939
+ const position = new import_core15.Vector3(
1940
+ v & 1 ? -1 : 1,
1941
+ v & 2 ? -1 : 1,
1942
+ v & 4 ? -1 : 1
1943
+ ).multiply(halfSize).add(center);
1944
+ for (let i = 0; i < 3; i++) {
1945
+ result[0][i] = Math.min(result[0][i], position[i]);
1946
+ result[1][i] = Math.max(result[1][i], position[i]);
1947
+ }
1948
+ }
1949
+ });
1950
+ if (!Number.isFinite(result[0][0])) {
1951
+ return null;
1952
+ }
1953
+ return result;
1954
+ }
1955
+ destroy() {
1956
+ this.children.forEach((child) => child.destroy());
1957
+ this.removeAll();
1958
+ super.destroy();
1959
+ }
1960
+ // Unpacks arrays and nested arrays of children
1961
+ add(...children) {
1962
+ for (const child of children) {
1963
+ if (Array.isArray(child)) {
1964
+ this.add(...child);
1965
+ } else {
1966
+ this.children.push(child);
1967
+ }
1968
+ }
1969
+ return this;
1970
+ }
1971
+ remove(child) {
1972
+ const children = this.children;
1973
+ const indexOf = children.indexOf(child);
1974
+ if (indexOf > -1) {
1975
+ children.splice(indexOf, 1);
1976
+ }
1977
+ return this;
1978
+ }
1979
+ removeAll() {
1980
+ this.children = [];
1981
+ return this;
1982
+ }
1983
+ traverse(visitor, { worldMatrix = new import_core15.Matrix4() } = {}) {
1984
+ const modelMatrix = new import_core15.Matrix4(worldMatrix).multiplyRight(this.matrix);
1985
+ for (const child of this.children) {
1986
+ if (child instanceof GroupNode) {
1987
+ child.traverse(visitor, { worldMatrix: modelMatrix });
1988
+ } else {
1989
+ visitor(child, { worldMatrix: modelMatrix });
1990
+ }
1991
+ }
1992
+ }
1993
+ };
1994
+
1995
+ // src/scenegraph/model-node.ts
1996
+ var ModelNode = class extends ScenegraphNode {
1997
+ model;
1998
+ bounds = null;
1999
+ managedResources;
2000
+ // TODO - is this used? override callbacks to make sure we call them with this
2001
+ // onBeforeRender = null;
2002
+ // onAfterRender = null;
2003
+ // AfterRender = null;
2004
+ constructor(props) {
2005
+ super(props);
2006
+ this.model = props.model;
2007
+ this.managedResources = props.managedResources || [];
2008
+ this.bounds = props.bounds || null;
2009
+ this.setProps(props);
2010
+ }
2011
+ getBounds() {
2012
+ return this.bounds;
2013
+ }
2014
+ destroy() {
2015
+ if (this.model) {
2016
+ this.model.destroy();
2017
+ this.model = null;
2018
+ }
2019
+ this.managedResources.forEach((resource) => resource.destroy());
2020
+ this.managedResources = [];
2021
+ }
2022
+ // Expose model methods
2023
+ draw(renderPass) {
2024
+ return this.model.draw(renderPass);
2025
+ }
2026
+ };
2027
+
2028
+ // src/geometries/cone-geometry.ts
2029
+ var import_core18 = require("@luma.gl/core");
2030
+
2031
+ // src/geometries/truncated-cone-geometry.ts
2032
+ var import_core17 = require("@luma.gl/core");
2033
+ var INDEX_OFFSETS = {
2034
+ x: [2, 0, 1],
2035
+ y: [0, 1, 2],
2036
+ z: [1, 2, 0]
2037
+ };
2038
+ var TruncatedConeGeometry = class extends Geometry {
2039
+ constructor(props = {}) {
2040
+ const { id = (0, import_core17.uid)("truncated-code-geometry") } = props;
2041
+ const { indices, attributes } = tesselateTruncatedCone(props);
2042
+ super({
2043
+ ...props,
2044
+ id,
2045
+ topology: "triangle-list",
2046
+ indices,
2047
+ attributes: {
2048
+ POSITION: { size: 3, value: attributes.POSITION },
2049
+ NORMAL: { size: 3, value: attributes.NORMAL },
2050
+ TEXCOORD_0: { size: 2, value: attributes.TEXCOORD_0 },
2051
+ ...props.attributes
2052
+ }
2053
+ });
2054
+ }
2055
+ };
2056
+ function tesselateTruncatedCone(props = {}) {
2057
+ const {
2058
+ bottomRadius = 0,
2059
+ topRadius = 0,
2060
+ height = 1,
2061
+ nradial = 10,
2062
+ nvertical = 10,
2063
+ verticalAxis = "y",
2064
+ topCap = false,
2065
+ bottomCap = false
2066
+ } = props;
2067
+ const extra = (topCap ? 2 : 0) + (bottomCap ? 2 : 0);
2068
+ const numVertices = (nradial + 1) * (nvertical + 1 + extra);
2069
+ const slant = Math.atan2(bottomRadius - topRadius, height);
2070
+ const msin = Math.sin;
2071
+ const mcos = Math.cos;
2072
+ const mpi = Math.PI;
2073
+ const cosSlant = mcos(slant);
2074
+ const sinSlant = msin(slant);
2075
+ const start = topCap ? -2 : 0;
2076
+ const end = nvertical + (bottomCap ? 2 : 0);
2077
+ const vertsAroundEdge = nradial + 1;
2078
+ const indices = new Uint16Array(nradial * (nvertical + extra) * 6);
2079
+ const indexOffset = INDEX_OFFSETS[verticalAxis];
2080
+ const positions = new Float32Array(numVertices * 3);
2081
+ const normals = new Float32Array(numVertices * 3);
2082
+ const texCoords = new Float32Array(numVertices * 2);
2083
+ let i3 = 0;
2084
+ let i2 = 0;
2085
+ for (let i = start; i <= end; i++) {
2086
+ let v = i / nvertical;
2087
+ let y = height * v;
2088
+ let ringRadius;
2089
+ if (i < 0) {
2090
+ y = 0;
2091
+ v = 1;
2092
+ ringRadius = bottomRadius;
2093
+ } else if (i > nvertical) {
2094
+ y = height;
2095
+ v = 1;
2096
+ ringRadius = topRadius;
2097
+ } else {
2098
+ ringRadius = bottomRadius + (topRadius - bottomRadius) * (i / nvertical);
2099
+ }
2100
+ if (i === -2 || i === nvertical + 2) {
2101
+ ringRadius = 0;
2102
+ v = 0;
2103
+ }
2104
+ y -= height / 2;
2105
+ for (let j = 0; j < vertsAroundEdge; j++) {
2106
+ const sin = msin(j * mpi * 2 / nradial);
2107
+ const cos = mcos(j * mpi * 2 / nradial);
2108
+ positions[i3 + indexOffset[0]] = sin * ringRadius;
2109
+ positions[i3 + indexOffset[1]] = y;
2110
+ positions[i3 + indexOffset[2]] = cos * ringRadius;
2111
+ normals[i3 + indexOffset[0]] = i < 0 || i > nvertical ? 0 : sin * cosSlant;
2112
+ normals[i3 + indexOffset[1]] = i < 0 ? -1 : i > nvertical ? 1 : sinSlant;
2113
+ normals[i3 + indexOffset[2]] = i < 0 || i > nvertical ? 0 : cos * cosSlant;
2114
+ texCoords[i2 + 0] = j / nradial;
2115
+ texCoords[i2 + 1] = v;
2116
+ i2 += 2;
2117
+ i3 += 3;
2118
+ }
2119
+ }
2120
+ for (let i = 0; i < nvertical + extra; i++) {
2121
+ for (let j = 0; j < nradial; j++) {
2122
+ const index = (i * nradial + j) * 6;
2123
+ indices[index + 0] = vertsAroundEdge * (i + 0) + 0 + j;
2124
+ indices[index + 1] = vertsAroundEdge * (i + 0) + 1 + j;
2125
+ indices[index + 2] = vertsAroundEdge * (i + 1) + 1 + j;
2126
+ indices[index + 3] = vertsAroundEdge * (i + 0) + 0 + j;
2127
+ indices[index + 4] = vertsAroundEdge * (i + 1) + 1 + j;
2128
+ indices[index + 5] = vertsAroundEdge * (i + 1) + 0 + j;
2129
+ }
2130
+ }
2131
+ return {
2132
+ indices,
2133
+ attributes: {
2134
+ POSITION: positions,
2135
+ NORMAL: normals,
2136
+ TEXCOORD_0: texCoords
2137
+ }
2138
+ };
2139
+ }
2140
+
2141
+ // src/geometries/cone-geometry.ts
2142
+ var ConeGeometry = class extends TruncatedConeGeometry {
2143
+ constructor(props = {}) {
2144
+ const { id = (0, import_core18.uid)("cone-geometry"), radius = 1, cap = true } = props;
2145
+ super({
2146
+ ...props,
2147
+ id,
2148
+ topRadius: 0,
2149
+ topCap: Boolean(cap),
2150
+ bottomCap: Boolean(cap),
2151
+ bottomRadius: radius
2152
+ });
2153
+ }
2154
+ };
2155
+
2156
+ // src/geometries/cube-geometry.ts
2157
+ var import_core19 = require("@luma.gl/core");
2158
+ var CubeGeometry = class extends Geometry {
2159
+ constructor(props = {}) {
2160
+ const { id = (0, import_core19.uid)("cube-geometry"), indices = true } = props;
2161
+ super(indices ? {
2162
+ ...props,
2163
+ id,
2164
+ topology: "triangle-list",
2165
+ indices: { size: 1, value: CUBE_INDICES },
2166
+ attributes: { ...ATTRIBUTES, ...props.attributes }
2167
+ } : {
2168
+ ...props,
2169
+ id,
2170
+ topology: "triangle-list",
2171
+ indices: void 0,
2172
+ attributes: { ...NON_INDEXED_ATTRIBUTES, ...props.attributes }
2173
+ });
2174
+ }
2175
+ };
2176
+ var CUBE_INDICES = new Uint16Array([
2177
+ 0,
2178
+ 1,
2179
+ 2,
2180
+ 0,
2181
+ 2,
2182
+ 3,
2183
+ 4,
2184
+ 5,
2185
+ 6,
2186
+ 4,
2187
+ 6,
2188
+ 7,
2189
+ 8,
2190
+ 9,
2191
+ 10,
2192
+ 8,
2193
+ 10,
2194
+ 11,
2195
+ 12,
2196
+ 13,
2197
+ 14,
2198
+ 12,
2199
+ 14,
2200
+ 15,
2201
+ 16,
2202
+ 17,
2203
+ 18,
2204
+ 16,
2205
+ 18,
2206
+ 19,
2207
+ 20,
2208
+ 21,
2209
+ 22,
2210
+ 20,
2211
+ 22,
2212
+ 23
2213
+ ]);
2214
+ var CUBE_POSITIONS = new Float32Array([
2215
+ -1,
2216
+ -1,
2217
+ 1,
2218
+ 1,
2219
+ -1,
2220
+ 1,
2221
+ 1,
2222
+ 1,
2223
+ 1,
2224
+ -1,
2225
+ 1,
2226
+ 1,
2227
+ -1,
2228
+ -1,
2229
+ -1,
2230
+ -1,
2231
+ 1,
2232
+ -1,
2233
+ 1,
2234
+ 1,
2235
+ -1,
2236
+ 1,
2237
+ -1,
2238
+ -1,
2239
+ -1,
2240
+ 1,
2241
+ -1,
2242
+ -1,
2243
+ 1,
2244
+ 1,
2245
+ 1,
2246
+ 1,
2247
+ 1,
2248
+ 1,
2249
+ 1,
2250
+ -1,
2251
+ -1,
2252
+ -1,
2253
+ -1,
2254
+ 1,
2255
+ -1,
2256
+ -1,
2257
+ 1,
2258
+ -1,
2259
+ 1,
2260
+ -1,
2261
+ -1,
2262
+ 1,
2263
+ 1,
2264
+ -1,
2265
+ -1,
2266
+ 1,
2267
+ 1,
2268
+ -1,
2269
+ 1,
2270
+ 1,
2271
+ 1,
2272
+ 1,
2273
+ -1,
2274
+ 1,
2275
+ -1,
2276
+ -1,
2277
+ -1,
2278
+ -1,
2279
+ -1,
2280
+ 1,
2281
+ -1,
2282
+ 1,
2283
+ 1,
2284
+ -1,
2285
+ 1,
2286
+ -1
2287
+ ]);
2288
+ var CUBE_NORMALS = new Float32Array([
2289
+ // Front face
2290
+ 0,
2291
+ 0,
2292
+ 1,
2293
+ 0,
2294
+ 0,
2295
+ 1,
2296
+ 0,
2297
+ 0,
2298
+ 1,
2299
+ 0,
2300
+ 0,
2301
+ 1,
2302
+ // Back face
2303
+ 0,
2304
+ 0,
2305
+ -1,
2306
+ 0,
2307
+ 0,
2308
+ -1,
2309
+ 0,
2310
+ 0,
2311
+ -1,
2312
+ 0,
2313
+ 0,
2314
+ -1,
2315
+ // Top face
2316
+ 0,
2317
+ 1,
2318
+ 0,
2319
+ 0,
2320
+ 1,
2321
+ 0,
2322
+ 0,
2323
+ 1,
2324
+ 0,
2325
+ 0,
2326
+ 1,
2327
+ 0,
2328
+ // Bottom face
2329
+ 0,
2330
+ -1,
2331
+ 0,
2332
+ 0,
2333
+ -1,
2334
+ 0,
2335
+ 0,
2336
+ -1,
2337
+ 0,
2338
+ 0,
2339
+ -1,
2340
+ 0,
2341
+ // Right face
2342
+ 1,
2343
+ 0,
2344
+ 0,
2345
+ 1,
2346
+ 0,
2347
+ 0,
2348
+ 1,
2349
+ 0,
2350
+ 0,
2351
+ 1,
2352
+ 0,
2353
+ 0,
2354
+ // Left face
2355
+ -1,
2356
+ 0,
2357
+ 0,
2358
+ -1,
2359
+ 0,
2360
+ 0,
2361
+ -1,
2362
+ 0,
2363
+ 0,
2364
+ -1,
2365
+ 0,
2366
+ 0
2367
+ ]);
2368
+ var CUBE_TEX_COORDS = new Float32Array([
2369
+ // Front face
2370
+ 0,
2371
+ 0,
2372
+ 1,
2373
+ 0,
2374
+ 1,
2375
+ 1,
2376
+ 0,
2377
+ 1,
2378
+ // Back face
2379
+ 1,
2380
+ 0,
2381
+ 1,
2382
+ 1,
2383
+ 0,
2384
+ 1,
2385
+ 0,
2386
+ 0,
2387
+ // Top face
2388
+ 0,
2389
+ 1,
2390
+ 0,
2391
+ 0,
2392
+ 1,
2393
+ 0,
2394
+ 1,
2395
+ 1,
2396
+ // Bottom face
2397
+ 1,
2398
+ 1,
2399
+ 0,
2400
+ 1,
2401
+ 0,
2402
+ 0,
2403
+ 1,
2404
+ 0,
2405
+ // Right face
2406
+ 1,
2407
+ 0,
2408
+ 1,
2409
+ 1,
2410
+ 0,
2411
+ 1,
2412
+ 0,
2413
+ 0,
2414
+ // Left face
2415
+ 0,
2416
+ 0,
2417
+ 1,
2418
+ 0,
2419
+ 1,
2420
+ 1,
2421
+ 0,
2422
+ 1
2423
+ ]);
2424
+ var CUBE_NON_INDEXED_POSITIONS = new Float32Array([
2425
+ 1,
2426
+ -1,
2427
+ 1,
2428
+ -1,
2429
+ -1,
2430
+ 1,
2431
+ -1,
2432
+ -1,
2433
+ -1,
2434
+ 1,
2435
+ -1,
2436
+ -1,
2437
+ 1,
2438
+ -1,
2439
+ 1,
2440
+ -1,
2441
+ -1,
2442
+ -1,
2443
+ 1,
2444
+ 1,
2445
+ 1,
2446
+ 1,
2447
+ -1,
2448
+ 1,
2449
+ 1,
2450
+ -1,
2451
+ -1,
2452
+ 1,
2453
+ 1,
2454
+ -1,
2455
+ 1,
2456
+ 1,
2457
+ 1,
2458
+ 1,
2459
+ -1,
2460
+ -1,
2461
+ -1,
2462
+ 1,
2463
+ 1,
2464
+ 1,
2465
+ 1,
2466
+ 1,
2467
+ 1,
2468
+ 1,
2469
+ -1,
2470
+ -1,
2471
+ 1,
2472
+ -1,
2473
+ -1,
2474
+ 1,
2475
+ 1,
2476
+ 1,
2477
+ 1,
2478
+ -1,
2479
+ -1,
2480
+ -1,
2481
+ 1,
2482
+ -1,
2483
+ 1,
2484
+ 1,
2485
+ -1,
2486
+ 1,
2487
+ -1,
2488
+ -1,
2489
+ -1,
2490
+ -1,
2491
+ -1,
2492
+ -1,
2493
+ 1,
2494
+ -1,
2495
+ 1,
2496
+ -1,
2497
+ 1,
2498
+ 1,
2499
+ 1,
2500
+ -1,
2501
+ 1,
2502
+ 1,
2503
+ -1,
2504
+ -1,
2505
+ 1,
2506
+ -1,
2507
+ -1,
2508
+ 1,
2509
+ 1,
2510
+ -1,
2511
+ 1,
2512
+ 1,
2513
+ 1,
2514
+ 1,
2515
+ 1,
2516
+ -1,
2517
+ -1,
2518
+ -1,
2519
+ -1,
2520
+ -1,
2521
+ -1,
2522
+ 1,
2523
+ -1,
2524
+ 1,
2525
+ 1,
2526
+ -1,
2527
+ 1,
2528
+ -1,
2529
+ -1,
2530
+ -1,
2531
+ 1,
2532
+ -1
2533
+ ]);
2534
+ var CUBE_NON_INDEXED_TEX_COORDS = new Float32Array([
2535
+ 1,
2536
+ 1,
2537
+ 0,
2538
+ 1,
2539
+ 0,
2540
+ 0,
2541
+ 1,
2542
+ 0,
2543
+ 1,
2544
+ 1,
2545
+ 0,
2546
+ 0,
2547
+ 1,
2548
+ 1,
2549
+ 0,
2550
+ 1,
2551
+ 0,
2552
+ 0,
2553
+ 1,
2554
+ 0,
2555
+ 1,
2556
+ 1,
2557
+ 0,
2558
+ 0,
2559
+ 1,
2560
+ 1,
2561
+ 0,
2562
+ 1,
2563
+ 0,
2564
+ 0,
2565
+ 1,
2566
+ 0,
2567
+ 1,
2568
+ 1,
2569
+ 0,
2570
+ 0,
2571
+ 1,
2572
+ 1,
2573
+ 0,
2574
+ 1,
2575
+ 0,
2576
+ 0,
2577
+ 1,
2578
+ 0,
2579
+ 1,
2580
+ 1,
2581
+ 0,
2582
+ 0,
2583
+ 1,
2584
+ 1,
2585
+ 0,
2586
+ 1,
2587
+ 0,
2588
+ 0,
2589
+ 0,
2590
+ 0,
2591
+ 1,
2592
+ 0,
2593
+ 1,
2594
+ 1,
2595
+ 1,
2596
+ 1,
2597
+ 0,
2598
+ 1,
2599
+ 0,
2600
+ 0,
2601
+ 1,
2602
+ 0,
2603
+ 1,
2604
+ 1,
2605
+ 0,
2606
+ 0
2607
+ ]);
2608
+ var CUBE_NON_INDEXED_COLORS = new Float32Array([
2609
+ 1,
2610
+ 0,
2611
+ 1,
2612
+ 1,
2613
+ 0,
2614
+ 0,
2615
+ 1,
2616
+ 1,
2617
+ 0,
2618
+ 0,
2619
+ 0,
2620
+ 1,
2621
+ 1,
2622
+ 0,
2623
+ 0,
2624
+ 1,
2625
+ 1,
2626
+ 0,
2627
+ 1,
2628
+ 1,
2629
+ 0,
2630
+ 0,
2631
+ 0,
2632
+ 1,
2633
+ 1,
2634
+ 1,
2635
+ 1,
2636
+ 1,
2637
+ 1,
2638
+ 0,
2639
+ 1,
2640
+ 1,
2641
+ 1,
2642
+ 0,
2643
+ 0,
2644
+ 1,
2645
+ 1,
2646
+ 1,
2647
+ 0,
2648
+ 1,
2649
+ 1,
2650
+ 1,
2651
+ 1,
2652
+ 1,
2653
+ 1,
2654
+ 0,
2655
+ 0,
2656
+ 1,
2657
+ 0,
2658
+ 1,
2659
+ 1,
2660
+ 1,
2661
+ 1,
2662
+ 1,
2663
+ 1,
2664
+ 1,
2665
+ 1,
2666
+ 1,
2667
+ 0,
2668
+ 1,
2669
+ 0,
2670
+ 1,
2671
+ 0,
2672
+ 1,
2673
+ 0,
2674
+ 1,
2675
+ 1,
2676
+ 1,
2677
+ 1,
2678
+ 1,
2679
+ 0,
2680
+ 1,
2681
+ 0,
2682
+ 0,
2683
+ 1,
2684
+ 1,
2685
+ 0,
2686
+ 1,
2687
+ 1,
2688
+ 1,
2689
+ 0,
2690
+ 1,
2691
+ 0,
2692
+ 1,
2693
+ 0,
2694
+ 0,
2695
+ 0,
2696
+ 1,
2697
+ 0,
2698
+ 0,
2699
+ 1,
2700
+ 1,
2701
+ 0,
2702
+ 1,
2703
+ 0,
2704
+ 1,
2705
+ 1,
2706
+ 1,
2707
+ 1,
2708
+ 1,
2709
+ 0,
2710
+ 1,
2711
+ 1,
2712
+ 1,
2713
+ 0,
2714
+ 0,
2715
+ 1,
2716
+ 1,
2717
+ 0,
2718
+ 0,
2719
+ 1,
2720
+ 1,
2721
+ 1,
2722
+ 0,
2723
+ 1,
2724
+ 1,
2725
+ 1,
2726
+ 1,
2727
+ 1,
2728
+ 1,
2729
+ 1,
2730
+ 0,
2731
+ 0,
2732
+ 1,
2733
+ 0,
2734
+ 0,
2735
+ 0,
2736
+ 1,
2737
+ 0,
2738
+ 1,
2739
+ 0,
2740
+ 1,
2741
+ 1,
2742
+ 1,
2743
+ 0,
2744
+ 1,
2745
+ 1,
2746
+ 0,
2747
+ 0,
2748
+ 1,
2749
+ 0,
2750
+ 1,
2751
+ 0,
2752
+ 1
2753
+ ]);
2754
+ var ATTRIBUTES = {
2755
+ POSITION: { size: 3, value: CUBE_POSITIONS },
2756
+ NORMAL: { size: 3, value: CUBE_NORMALS },
2757
+ TEXCOORD_0: { size: 2, value: CUBE_TEX_COORDS }
2758
+ };
2759
+ var NON_INDEXED_ATTRIBUTES = {
2760
+ POSITION: { size: 3, value: CUBE_NON_INDEXED_POSITIONS },
2761
+ // NORMAL: {size: 3, value: CUBE_NON_INDEXED_NORMALS},
2762
+ TEXCOORD_0: { size: 2, value: CUBE_NON_INDEXED_TEX_COORDS },
2763
+ COLOR_0: { size: 3, value: CUBE_NON_INDEXED_COLORS }
2764
+ };
2765
+
2766
+ // src/geometries/cylinder-geometry.ts
2767
+ var import_core20 = require("@luma.gl/core");
2768
+ var CylinderGeometry = class extends TruncatedConeGeometry {
2769
+ constructor(props = {}) {
2770
+ const { id = (0, import_core20.uid)("cylinder-geometry"), radius = 1 } = props;
2771
+ super({
2772
+ ...props,
2773
+ id,
2774
+ bottomRadius: radius,
2775
+ topRadius: radius
2776
+ });
2777
+ }
2778
+ };
2779
+
2780
+ // src/geometries/ico-sphere-geometry.ts
2781
+ var import_core21 = require("@luma.gl/core");
2782
+ var import_core22 = require("@math.gl/core");
2783
+ var ICO_POSITIONS = [-1, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 1, 0, -1, 0, 1, 0, 0];
2784
+ var ICO_INDICES = [3, 4, 5, 3, 5, 1, 3, 1, 0, 3, 0, 4, 4, 0, 2, 4, 2, 5, 2, 0, 1, 5, 2, 1];
2785
+ var IcoSphereGeometry = class extends Geometry {
2786
+ constructor(props = {}) {
2787
+ const { id = (0, import_core21.uid)("ico-sphere-geometry") } = props;
2788
+ const { indices, attributes } = tesselateIcosaHedron(props);
2789
+ super({
2790
+ ...props,
2791
+ id,
2792
+ topology: "triangle-list",
2793
+ indices,
2794
+ attributes: { ...attributes, ...props.attributes }
2795
+ });
2796
+ }
2797
+ };
2798
+ function tesselateIcosaHedron(props) {
2799
+ const { iterations = 0 } = props;
2800
+ const PI = Math.PI;
2801
+ const PI2 = PI * 2;
2802
+ const positions = [...ICO_POSITIONS];
2803
+ let indices = [...ICO_INDICES];
2804
+ positions.push();
2805
+ indices.push();
2806
+ const getMiddlePoint = (() => {
2807
+ const pointMemo = {};
2808
+ return (i1, i2) => {
2809
+ i1 *= 3;
2810
+ i2 *= 3;
2811
+ const mini = i1 < i2 ? i1 : i2;
2812
+ const maxi = i1 > i2 ? i1 : i2;
2813
+ const key = `${mini}|${maxi}`;
2814
+ if (key in pointMemo) {
2815
+ return pointMemo[key];
2816
+ }
2817
+ const x1 = positions[i1];
2818
+ const y1 = positions[i1 + 1];
2819
+ const z1 = positions[i1 + 2];
2820
+ const x2 = positions[i2];
2821
+ const y2 = positions[i2 + 1];
2822
+ const z2 = positions[i2 + 2];
2823
+ let xm = (x1 + x2) / 2;
2824
+ let ym = (y1 + y2) / 2;
2825
+ let zm = (z1 + z2) / 2;
2826
+ const len = Math.sqrt(xm * xm + ym * ym + zm * zm);
2827
+ xm /= len;
2828
+ ym /= len;
2829
+ zm /= len;
2830
+ positions.push(xm, ym, zm);
2831
+ return pointMemo[key] = positions.length / 3 - 1;
2832
+ };
2833
+ })();
2834
+ for (let i = 0; i < iterations; i++) {
2835
+ const indices2 = [];
2836
+ for (let j = 0; j < indices.length; j += 3) {
2837
+ const a = getMiddlePoint(indices[j + 0], indices[j + 1]);
2838
+ const b = getMiddlePoint(indices[j + 1], indices[j + 2]);
2839
+ const c = getMiddlePoint(indices[j + 2], indices[j + 0]);
2840
+ indices2.push(c, indices[j + 0], a, a, indices[j + 1], b, b, indices[j + 2], c, a, b, c);
2841
+ }
2842
+ indices = indices2;
2843
+ }
2844
+ const normals = new Array(positions.length);
2845
+ const texCoords = new Array(positions.length / 3 * 2);
2846
+ const l = indices.length;
2847
+ for (let i = l - 3; i >= 0; i -= 3) {
2848
+ const i1 = indices[i + 0];
2849
+ const i2 = indices[i + 1];
2850
+ const i3 = indices[i + 2];
2851
+ const in1 = i1 * 3;
2852
+ const in2 = i2 * 3;
2853
+ const in3 = i3 * 3;
2854
+ const iu1 = i1 * 2;
2855
+ const iu2 = i2 * 2;
2856
+ const iu3 = i3 * 2;
2857
+ const x1 = positions[in1 + 0];
2858
+ const y1 = positions[in1 + 1];
2859
+ const z1 = positions[in1 + 2];
2860
+ const theta1 = Math.acos(z1 / Math.sqrt(x1 * x1 + y1 * y1 + z1 * z1));
2861
+ const phi1 = Math.atan2(y1, x1) + PI;
2862
+ const v1 = theta1 / PI;
2863
+ const u1 = 1 - phi1 / PI2;
2864
+ const x2 = positions[in2 + 0];
2865
+ const y2 = positions[in2 + 1];
2866
+ const z2 = positions[in2 + 2];
2867
+ const theta2 = Math.acos(z2 / Math.sqrt(x2 * x2 + y2 * y2 + z2 * z2));
2868
+ const phi2 = Math.atan2(y2, x2) + PI;
2869
+ const v2 = theta2 / PI;
2870
+ const u2 = 1 - phi2 / PI2;
2871
+ const x3 = positions[in3 + 0];
2872
+ const y3 = positions[in3 + 1];
2873
+ const z3 = positions[in3 + 2];
2874
+ const theta3 = Math.acos(z3 / Math.sqrt(x3 * x3 + y3 * y3 + z3 * z3));
2875
+ const phi3 = Math.atan2(y3, x3) + PI;
2876
+ const v3 = theta3 / PI;
2877
+ const u3 = 1 - phi3 / PI2;
2878
+ const vec1 = [x3 - x2, y3 - y2, z3 - z2];
2879
+ const vec2 = [x1 - x2, y1 - y2, z1 - z2];
2880
+ const normal = new import_core22.Vector3(vec1).cross(vec2).normalize();
2881
+ let newIndex;
2882
+ if ((u1 === 0 || u2 === 0 || u3 === 0) && (u1 === 0 || u1 > 0.5) && (u2 === 0 || u2 > 0.5) && (u3 === 0 || u3 > 0.5)) {
2883
+ positions.push(positions[in1 + 0], positions[in1 + 1], positions[in1 + 2]);
2884
+ newIndex = positions.length / 3 - 1;
2885
+ indices.push(newIndex);
2886
+ texCoords[newIndex * 2 + 0] = 1;
2887
+ texCoords[newIndex * 2 + 1] = v1;
2888
+ normals[newIndex * 3 + 0] = normal.x;
2889
+ normals[newIndex * 3 + 1] = normal.y;
2890
+ normals[newIndex * 3 + 2] = normal.z;
2891
+ positions.push(positions[in2 + 0], positions[in2 + 1], positions[in2 + 2]);
2892
+ newIndex = positions.length / 3 - 1;
2893
+ indices.push(newIndex);
2894
+ texCoords[newIndex * 2 + 0] = 1;
2895
+ texCoords[newIndex * 2 + 1] = v2;
2896
+ normals[newIndex * 3 + 0] = normal.x;
2897
+ normals[newIndex * 3 + 1] = normal.y;
2898
+ normals[newIndex * 3 + 2] = normal.z;
2899
+ positions.push(positions[in3 + 0], positions[in3 + 1], positions[in3 + 2]);
2900
+ newIndex = positions.length / 3 - 1;
2901
+ indices.push(newIndex);
2902
+ texCoords[newIndex * 2 + 0] = 1;
2903
+ texCoords[newIndex * 2 + 1] = v3;
2904
+ normals[newIndex * 3 + 0] = normal.x;
2905
+ normals[newIndex * 3 + 1] = normal.y;
2906
+ normals[newIndex * 3 + 2] = normal.z;
2907
+ }
2908
+ normals[in1 + 0] = normals[in2 + 0] = normals[in3 + 0] = normal.x;
2909
+ normals[in1 + 1] = normals[in2 + 1] = normals[in3 + 1] = normal.y;
2910
+ normals[in1 + 2] = normals[in2 + 2] = normals[in3 + 2] = normal.z;
2911
+ texCoords[iu1 + 0] = u1;
2912
+ texCoords[iu1 + 1] = v1;
2913
+ texCoords[iu2 + 0] = u2;
2914
+ texCoords[iu2 + 1] = v2;
2915
+ texCoords[iu3 + 0] = u3;
2916
+ texCoords[iu3 + 1] = v3;
2917
+ }
2918
+ return {
2919
+ indices: { size: 1, value: new Uint16Array(indices) },
2920
+ attributes: {
2921
+ POSITION: { size: 3, value: new Float32Array(positions) },
2922
+ NORMAL: { size: 3, value: new Float32Array(normals) },
2923
+ TEXCOORD_0: { size: 2, value: new Float32Array(texCoords) }
2924
+ }
2925
+ };
2926
+ }
2927
+
2928
+ // src/geometries/plane-geometry.ts
2929
+ var import_core23 = require("@luma.gl/core");
2930
+
2931
+ // src/geometry/geometry-utils.ts
2932
+ function unpackIndexedGeometry(geometry) {
2933
+ const { indices, attributes } = geometry;
2934
+ if (!indices) {
2935
+ return geometry;
2936
+ }
2937
+ const vertexCount = indices.value.length;
2938
+ const unpackedAttributes = {};
2939
+ for (const attributeName in attributes) {
2940
+ const attribute = attributes[attributeName];
2941
+ const { constant, value, size } = attribute;
2942
+ if (constant || !size) {
2943
+ continue;
2944
+ }
2945
+ const unpackedValue = new value.constructor(vertexCount * size);
2946
+ for (let x = 0; x < vertexCount; ++x) {
2947
+ const index = indices.value[x];
2948
+ for (let i = 0; i < size; i++) {
2949
+ unpackedValue[x * size + i] = value[index * size + i];
2950
+ }
2951
+ }
2952
+ unpackedAttributes[attributeName] = { size, value: unpackedValue };
2953
+ }
2954
+ return {
2955
+ attributes: Object.assign({}, attributes, unpackedAttributes)
2956
+ };
2957
+ }
2958
+
2959
+ // src/geometries/plane-geometry.ts
2960
+ var PlaneGeometry = class extends Geometry {
2961
+ constructor(props = {}) {
2962
+ const { id = (0, import_core23.uid)("plane-geometry") } = props;
2963
+ const { indices, attributes } = tesselatePlane(props);
2964
+ super({
2965
+ ...props,
2966
+ id,
2967
+ topology: "triangle-list",
2968
+ indices,
2969
+ attributes: { ...attributes, ...props.attributes }
2970
+ });
2971
+ }
2972
+ };
2973
+ function tesselatePlane(props) {
2974
+ const { type = "x,y", offset = 0, flipCull = false, unpack = false } = props;
2975
+ const coords = type.split(",");
2976
+ let c1len = props[`${coords[0]}len`] || 1;
2977
+ const c2len = props[`${coords[1]}len`] || 1;
2978
+ const subdivisions1 = props[`n${coords[0]}`] || 1;
2979
+ const subdivisions2 = props[`n${coords[1]}`] || 1;
2980
+ const numVertices = (subdivisions1 + 1) * (subdivisions2 + 1);
2981
+ const positions = new Float32Array(numVertices * 3);
2982
+ const normals = new Float32Array(numVertices * 3);
2983
+ const texCoords = new Float32Array(numVertices * 2);
2984
+ if (flipCull) {
2985
+ c1len = -c1len;
2986
+ }
2987
+ let i2 = 0;
2988
+ let i3 = 0;
2989
+ for (let z = 0; z <= subdivisions2; z++) {
2990
+ for (let x = 0; x <= subdivisions1; x++) {
2991
+ const u = x / subdivisions1;
2992
+ const v = z / subdivisions2;
2993
+ texCoords[i2 + 0] = flipCull ? 1 - u : u;
2994
+ texCoords[i2 + 1] = v;
2995
+ switch (type) {
2996
+ case "x,y":
2997
+ positions[i3 + 0] = c1len * u - c1len * 0.5;
2998
+ positions[i3 + 1] = c2len * v - c2len * 0.5;
2999
+ positions[i3 + 2] = offset;
3000
+ normals[i3 + 0] = 0;
3001
+ normals[i3 + 1] = 0;
3002
+ normals[i3 + 2] = flipCull ? 1 : -1;
3003
+ break;
3004
+ case "x,z":
3005
+ positions[i3 + 0] = c1len * u - c1len * 0.5;
3006
+ positions[i3 + 1] = offset;
3007
+ positions[i3 + 2] = c2len * v - c2len * 0.5;
3008
+ normals[i3 + 0] = 0;
3009
+ normals[i3 + 1] = flipCull ? 1 : -1;
3010
+ normals[i3 + 2] = 0;
3011
+ break;
3012
+ case "y,z":
3013
+ positions[i3 + 0] = offset;
3014
+ positions[i3 + 1] = c1len * u - c1len * 0.5;
3015
+ positions[i3 + 2] = c2len * v - c2len * 0.5;
3016
+ normals[i3 + 0] = flipCull ? 1 : -1;
3017
+ normals[i3 + 1] = 0;
3018
+ normals[i3 + 2] = 0;
3019
+ break;
3020
+ default:
3021
+ throw new Error("PlaneGeometry: unknown type");
3022
+ }
3023
+ i2 += 2;
3024
+ i3 += 3;
3025
+ }
3026
+ }
3027
+ const numVertsAcross = subdivisions1 + 1;
3028
+ const indices = new Uint16Array(subdivisions1 * subdivisions2 * 6);
3029
+ for (let z = 0; z < subdivisions2; z++) {
3030
+ for (let x = 0; x < subdivisions1; x++) {
3031
+ const index = (z * subdivisions1 + x) * 6;
3032
+ indices[index + 0] = (z + 0) * numVertsAcross + x;
3033
+ indices[index + 1] = (z + 1) * numVertsAcross + x;
3034
+ indices[index + 2] = (z + 0) * numVertsAcross + x + 1;
3035
+ indices[index + 3] = (z + 1) * numVertsAcross + x;
3036
+ indices[index + 4] = (z + 1) * numVertsAcross + x + 1;
3037
+ indices[index + 5] = (z + 0) * numVertsAcross + x + 1;
3038
+ }
3039
+ }
3040
+ const geometry = {
3041
+ indices: { size: 1, value: indices },
3042
+ attributes: {
3043
+ POSITION: { size: 3, value: positions },
3044
+ NORMAL: { size: 3, value: normals },
3045
+ TEXCOORD_0: { size: 2, value: texCoords }
3046
+ }
3047
+ };
3048
+ return unpack ? unpackIndexedGeometry(geometry) : geometry;
3049
+ }
3050
+
3051
+ // src/geometries/sphere-geometry.ts
3052
+ var import_core24 = require("@luma.gl/core");
3053
+ var SphereGeometry = class extends Geometry {
3054
+ constructor(props = {}) {
3055
+ const { id = (0, import_core24.uid)("sphere-geometry") } = props;
3056
+ const { indices, attributes } = tesselateSphere(props);
3057
+ super({
3058
+ ...props,
3059
+ id,
3060
+ topology: "triangle-list",
3061
+ indices,
3062
+ attributes: { ...attributes, ...props.attributes }
3063
+ });
3064
+ }
3065
+ };
3066
+ function tesselateSphere(props) {
3067
+ const { nlat = 10, nlong = 10 } = props;
3068
+ const startLat = 0;
3069
+ const endLat = Math.PI;
3070
+ const latRange = endLat - startLat;
3071
+ const startLong = 0;
3072
+ const endLong = 2 * Math.PI;
3073
+ const longRange = endLong - startLong;
3074
+ const numVertices = (nlat + 1) * (nlong + 1);
3075
+ const radius = (n1, n2, n3, u, v) => props.radius || 1;
3076
+ const positions = new Float32Array(numVertices * 3);
3077
+ const normals = new Float32Array(numVertices * 3);
3078
+ const texCoords = new Float32Array(numVertices * 2);
3079
+ const IndexType = numVertices > 65535 ? Uint32Array : Uint16Array;
3080
+ const indices = new IndexType(nlat * nlong * 6);
3081
+ for (let y = 0; y <= nlat; y++) {
3082
+ for (let x = 0; x <= nlong; x++) {
3083
+ const u = x / nlong;
3084
+ const v = y / nlat;
3085
+ const index = x + y * (nlong + 1);
3086
+ const i2 = index * 2;
3087
+ const i3 = index * 3;
3088
+ const theta = longRange * u;
3089
+ const phi = latRange * v;
3090
+ const sinTheta = Math.sin(theta);
3091
+ const cosTheta = Math.cos(theta);
3092
+ const sinPhi = Math.sin(phi);
3093
+ const cosPhi = Math.cos(phi);
3094
+ const ux = cosTheta * sinPhi;
3095
+ const uy = cosPhi;
3096
+ const uz = sinTheta * sinPhi;
3097
+ const r = radius(ux, uy, uz, u, v);
3098
+ positions[i3 + 0] = r * ux;
3099
+ positions[i3 + 1] = r * uy;
3100
+ positions[i3 + 2] = r * uz;
3101
+ normals[i3 + 0] = ux;
3102
+ normals[i3 + 1] = uy;
3103
+ normals[i3 + 2] = uz;
3104
+ texCoords[i2 + 0] = u;
3105
+ texCoords[i2 + 1] = 1 - v;
3106
+ }
3107
+ }
3108
+ const numVertsAround = nlong + 1;
3109
+ for (let x = 0; x < nlong; x++) {
3110
+ for (let y = 0; y < nlat; y++) {
3111
+ const index = (x * nlat + y) * 6;
3112
+ indices[index + 0] = y * numVertsAround + x;
3113
+ indices[index + 1] = y * numVertsAround + x + 1;
3114
+ indices[index + 2] = (y + 1) * numVertsAround + x;
3115
+ indices[index + 3] = (y + 1) * numVertsAround + x;
3116
+ indices[index + 4] = y * numVertsAround + x + 1;
3117
+ indices[index + 5] = (y + 1) * numVertsAround + x + 1;
3118
+ }
3119
+ }
3120
+ return {
3121
+ indices: { size: 1, value: indices },
3122
+ attributes: {
3123
+ POSITION: { size: 3, value: positions },
3124
+ NORMAL: { size: 3, value: normals },
3125
+ TEXCOORD_0: { size: 2, value: texCoords }
3126
+ }
3127
+ };
3128
+ }