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

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 (673) hide show
  1. package/README.md +9 -0
  2. package/dist/animation/animation-clip.cjs +36 -0
  3. package/dist/animation/animation-interpolation.cjs +115 -0
  4. package/dist/animation/animation-mixer.cjs +302 -0
  5. package/dist/animation/animation-track.cjs +55 -0
  6. package/dist/animation/animator.cjs +75 -0
  7. package/dist/animation/deform-positions.cjs +69 -0
  8. package/dist/animation/deform-positions.d.ts +13 -0
  9. package/dist/animation/deform-positions.d.ts.map +1 -0
  10. package/dist/animation/deform-positions.js +49 -0
  11. package/dist/animation/deform-positions.js.map +1 -0
  12. package/dist/animation/key-frames.cjs +81 -0
  13. package/dist/animation/morph-targets.cjs +162 -0
  14. package/dist/animation/node-animation-binding.cjs +67 -0
  15. package/dist/animation/node-animation-binding.d.ts +9 -0
  16. package/dist/animation/node-animation-binding.d.ts.map +1 -0
  17. package/dist/animation/node-animation-binding.js +45 -0
  18. package/dist/animation/node-animation-binding.js.map +1 -0
  19. package/dist/animation/property-animation-binding.cjs +159 -0
  20. package/dist/animation/property-animation-binding.d.ts +29 -0
  21. package/dist/animation/property-animation-binding.d.ts.map +1 -0
  22. package/dist/animation/property-animation-binding.js +138 -0
  23. package/dist/animation/property-animation-binding.js.map +1 -0
  24. package/dist/animation/scenegraph-animator.cjs +122 -0
  25. package/dist/animation/scenegraph-animator.d.ts +37 -0
  26. package/dist/animation/scenegraph-animator.d.ts.map +1 -0
  27. package/dist/animation/scenegraph-animator.js +99 -0
  28. package/dist/animation/scenegraph-animator.js.map +1 -0
  29. package/dist/animation/skin.cjs +49 -0
  30. package/dist/animation/texture-transform.cjs +41 -0
  31. package/dist/animation/texture-transform.d.ts +8 -0
  32. package/dist/animation/texture-transform.d.ts.map +1 -0
  33. package/dist/animation/texture-transform.js +17 -0
  34. package/dist/animation/texture-transform.js.map +1 -0
  35. package/dist/animation/timeline.cjs +129 -0
  36. package/dist/animation-loop/animation-loop-template.cjs +33 -0
  37. package/dist/animation-loop/animation-loop.cjs +498 -0
  38. package/dist/animation-loop/animation-loop.d.ts +2 -1
  39. package/dist/animation-loop/animation-loop.d.ts.map +1 -1
  40. package/dist/animation-loop/animation-loop.js +9 -3
  41. package/dist/animation-loop/animation-loop.js.map +1 -1
  42. package/dist/animation-loop/animation-props.cjs +15 -0
  43. package/dist/animation-loop/make-animation-loop.cjs +104 -0
  44. package/dist/animation-loop/request-animation-frame.cjs +43 -0
  45. package/dist/application-utils/load-file.cjs +77 -0
  46. package/dist/application-utils/random.cjs +38 -0
  47. package/dist/audio/audio-controller.cjs +429 -0
  48. package/dist/audio/audio-controller.d.ts +146 -0
  49. package/dist/audio/audio-controller.d.ts.map +1 -0
  50. package/dist/audio/audio-controller.js +445 -0
  51. package/dist/audio/audio-controller.js.map +1 -0
  52. package/dist/audio/audio-environment.cjs +157 -0
  53. package/dist/audio/audio-environment.d.ts +49 -0
  54. package/dist/audio/audio-environment.d.ts.map +1 -0
  55. package/dist/audio/audio-environment.js +148 -0
  56. package/dist/audio/audio-environment.js.map +1 -0
  57. package/dist/audio/audio-graph.cjs +182 -0
  58. package/dist/audio/audio-graph.d.ts +58 -0
  59. package/dist/audio/audio-graph.d.ts.map +1 -0
  60. package/dist/audio/audio-graph.js +181 -0
  61. package/dist/audio/audio-graph.js.map +1 -0
  62. package/dist/compute/buffer-transform.cjs +146 -0
  63. package/dist/compute/buffer-transform.d.ts +15 -5
  64. package/dist/compute/buffer-transform.d.ts.map +1 -1
  65. package/dist/compute/buffer-transform.js +56 -12
  66. package/dist/compute/buffer-transform.js.map +1 -1
  67. package/dist/compute/computation.cjs +331 -0
  68. package/dist/compute/computation.d.ts +2 -4
  69. package/dist/compute/computation.d.ts.map +1 -1
  70. package/dist/compute/computation.js +3 -14
  71. package/dist/compute/computation.js.map +1 -1
  72. package/dist/compute/swap.cjs +132 -0
  73. package/dist/compute/texture-transform.cjs +142 -0
  74. package/dist/compute/texture-transform.d.ts +11 -7
  75. package/dist/compute/texture-transform.d.ts.map +1 -1
  76. package/dist/compute/texture-transform.js +16 -6
  77. package/dist/compute/texture-transform.js.map +1 -1
  78. package/dist/controls/orbit-controls.cjs +283 -0
  79. package/dist/controls/orbit-controls.d.ts +2 -0
  80. package/dist/controls/orbit-controls.d.ts.map +1 -1
  81. package/dist/controls/orbit-controls.js +2 -1
  82. package/dist/controls/orbit-controls.js.map +1 -1
  83. package/dist/debug/copy-texture-to-image.cjs +84 -0
  84. package/dist/debug/debug-framebuffer.cjs +113 -0
  85. package/dist/debug/debug-shader-layout.cjs +45 -0
  86. package/dist/debug/pixel-data-utils.cjs +54 -0
  87. package/dist/dist.dev.js +11517 -6015
  88. package/dist/dist.min.js +39 -35
  89. package/dist/dynamic-buffer/dynamic-buffer.cjs +39 -0
  90. package/dist/dynamic-buffer/dynamic-buffer.d.ts +1 -170
  91. package/dist/dynamic-buffer/dynamic-buffer.d.ts.map +1 -1
  92. package/dist/dynamic-buffer/dynamic-buffer.js +2 -312
  93. package/dist/dynamic-buffer/dynamic-buffer.js.map +1 -1
  94. package/dist/dynamic-texture/dynamic-texture.cjs +27 -0
  95. package/dist/dynamic-texture/dynamic-texture.d.ts +1 -114
  96. package/dist/dynamic-texture/dynamic-texture.d.ts.map +1 -1
  97. package/dist/dynamic-texture/dynamic-texture.js +2 -584
  98. package/dist/dynamic-texture/dynamic-texture.js.map +1 -1
  99. package/dist/dynamic-texture/texture-binding-source.cjs +31 -0
  100. package/dist/dynamic-texture/texture-binding-source.d.ts +1 -54
  101. package/dist/dynamic-texture/texture-binding-source.d.ts.map +1 -1
  102. package/dist/dynamic-texture/texture-binding-source.js +2 -51
  103. package/dist/dynamic-texture/texture-binding-source.js.map +1 -1
  104. package/dist/dynamic-texture/texture-data.cjs +53 -0
  105. package/dist/dynamic-texture/texture-data.d.ts +1 -145
  106. package/dist/dynamic-texture/texture-data.d.ts.map +1 -1
  107. package/dist/dynamic-texture/texture-data.js +2 -209
  108. package/dist/dynamic-texture/texture-data.js.map +1 -1
  109. package/dist/dynamic-texture/video-texture.cjs +269 -0
  110. package/dist/dynamic-texture/video-texture.d.ts +1 -1
  111. package/dist/dynamic-texture/video-texture.d.ts.map +1 -1
  112. package/dist/experimental/controls/comparison-splitter.cjs +231 -0
  113. package/dist/experimental/controls/comparison-splitter.d.ts +54 -0
  114. package/dist/experimental/controls/comparison-splitter.d.ts.map +1 -0
  115. package/dist/experimental/controls/comparison-splitter.js +215 -0
  116. package/dist/experimental/controls/comparison-splitter.js.map +1 -0
  117. package/dist/experimental/controls/flat-controller.cjs +301 -0
  118. package/dist/experimental/controls/flat-controller.d.ts +80 -0
  119. package/dist/experimental/controls/flat-controller.d.ts.map +1 -0
  120. package/dist/experimental/controls/flat-controller.js +295 -0
  121. package/dist/experimental/controls/flat-controller.js.map +1 -0
  122. package/dist/experimental/controls/index.cjs +35 -0
  123. package/dist/experimental/controls/index.cjs.map +6 -0
  124. package/dist/experimental/controls/index.d.ts +7 -0
  125. package/dist/experimental/controls/index.d.ts.map +1 -0
  126. package/dist/experimental/controls/index.js +7 -0
  127. package/dist/experimental/controls/index.js.map +1 -0
  128. package/dist/experimental/controls/orbit-controls.cjs +27 -0
  129. package/dist/experimental/controls/orbit-controls.d.ts +3 -0
  130. package/dist/experimental/controls/orbit-controls.d.ts.map +1 -0
  131. package/dist/experimental/controls/orbit-controls.js +5 -0
  132. package/dist/experimental/controls/orbit-controls.js.map +1 -0
  133. package/dist/experimental/materials/emissive-material.cjs +126 -0
  134. package/dist/experimental/materials/emissive-material.d.ts +38 -0
  135. package/dist/experimental/materials/emissive-material.d.ts.map +1 -0
  136. package/dist/experimental/materials/emissive-material.js +100 -0
  137. package/dist/experimental/materials/emissive-material.js.map +1 -0
  138. package/dist/experimental/materials/glass-material.cjs +570 -0
  139. package/dist/experimental/materials/glass-material.d.ts +107 -0
  140. package/dist/experimental/materials/glass-material.d.ts.map +1 -0
  141. package/dist/experimental/materials/glass-material.js +544 -0
  142. package/dist/experimental/materials/glass-material.js.map +1 -0
  143. package/dist/experimental/materials/glass-transmission.cjs +954 -0
  144. package/dist/experimental/materials/glass-transmission.d.ts +193 -0
  145. package/dist/experimental/materials/glass-transmission.d.ts.map +1 -0
  146. package/dist/experimental/materials/glass-transmission.js +928 -0
  147. package/dist/experimental/materials/glass-transmission.js.map +1 -0
  148. package/dist/experimental/materials/index.cjs +61 -0
  149. package/dist/experimental/materials/index.cjs.map +6 -0
  150. package/dist/experimental/materials/index.d.ts +14 -0
  151. package/dist/experimental/materials/index.d.ts.map +1 -0
  152. package/dist/experimental/materials/index.js +11 -0
  153. package/dist/experimental/materials/index.js.map +1 -0
  154. package/dist/experimental/materials/optical-caustics.cjs +201 -0
  155. package/dist/experimental/materials/optical-caustics.d.ts +69 -0
  156. package/dist/experimental/materials/optical-caustics.d.ts.map +1 -0
  157. package/dist/experimental/materials/optical-caustics.js +180 -0
  158. package/dist/experimental/materials/optical-caustics.js.map +1 -0
  159. package/dist/experimental/materials/optical-lighting.cjs +169 -0
  160. package/dist/experimental/materials/optical-lighting.d.ts +7 -0
  161. package/dist/experimental/materials/optical-lighting.d.ts.map +1 -0
  162. package/dist/experimental/materials/optical-lighting.js +144 -0
  163. package/dist/experimental/materials/optical-lighting.js.map +1 -0
  164. package/dist/experimental/materials/optical-point-lights.cjs +258 -0
  165. package/dist/experimental/materials/optical-point-lights.d.ts +68 -0
  166. package/dist/experimental/materials/optical-point-lights.d.ts.map +1 -0
  167. package/dist/experimental/materials/optical-point-lights.js +237 -0
  168. package/dist/experimental/materials/optical-point-lights.js.map +1 -0
  169. package/dist/experimental/materials/reflective-material.cjs +216 -0
  170. package/dist/experimental/materials/reflective-material.d.ts +46 -0
  171. package/dist/experimental/materials/reflective-material.d.ts.map +1 -0
  172. package/dist/experimental/materials/reflective-material.js +190 -0
  173. package/dist/experimental/materials/reflective-material.js.map +1 -0
  174. package/dist/experimental/textures/html-texture.cjs +221 -0
  175. package/dist/experimental/textures/html-texture.d.ts +85 -0
  176. package/dist/experimental/textures/html-texture.d.ts.map +1 -0
  177. package/dist/experimental/textures/html-texture.js +206 -0
  178. package/dist/experimental/textures/html-texture.js.map +1 -0
  179. package/dist/experimental/textures/index.cjs +33 -0
  180. package/dist/experimental/textures/index.cjs.map +6 -0
  181. package/dist/experimental/textures/index.d.ts +5 -0
  182. package/dist/experimental/textures/index.d.ts.map +1 -0
  183. package/dist/experimental/textures/index.js +7 -0
  184. package/dist/experimental/textures/index.js.map +1 -0
  185. package/dist/experimental/textures/packed-pixels.cjs +248 -0
  186. package/dist/experimental/textures/packed-pixels.d.ts +17 -0
  187. package/dist/experimental/textures/packed-pixels.d.ts.map +1 -0
  188. package/dist/experimental/textures/packed-pixels.js +237 -0
  189. package/dist/experimental/textures/packed-pixels.js.map +1 -0
  190. package/dist/experimental/textures/rgba-decoder.cjs +60 -0
  191. package/dist/experimental/textures/rgba-decoder.d.ts +29 -0
  192. package/dist/experimental/textures/rgba-decoder.d.ts.map +1 -0
  193. package/dist/experimental/textures/rgba-decoder.js +43 -0
  194. package/dist/experimental/textures/rgba-decoder.js.map +1 -0
  195. package/dist/experimental/webxr/index.cjs +38 -0
  196. package/dist/experimental/webxr/index.cjs.map +6 -0
  197. package/dist/experimental/webxr/index.d.ts +9 -0
  198. package/dist/experimental/webxr/index.d.ts.map +1 -0
  199. package/dist/experimental/webxr/index.js +8 -0
  200. package/dist/experimental/webxr/index.js.map +1 -0
  201. package/dist/experimental/webxr/webxr-animation-frame-provider.cjs +38 -0
  202. package/dist/experimental/webxr/webxr-animation-frame-provider.d.ts +9 -0
  203. package/dist/experimental/webxr/webxr-animation-frame-provider.d.ts.map +1 -0
  204. package/dist/experimental/webxr/webxr-animation-frame-provider.js +17 -0
  205. package/dist/experimental/webxr/webxr-animation-frame-provider.js.map +1 -0
  206. package/dist/experimental/webxr/webxr-camera-texture.cjs +157 -0
  207. package/dist/experimental/webxr/webxr-camera-texture.d.ts +48 -0
  208. package/dist/experimental/webxr/webxr-camera-texture.d.ts.map +1 -0
  209. package/dist/experimental/webxr/webxr-camera-texture.js +144 -0
  210. package/dist/experimental/webxr/webxr-camera-texture.js.map +1 -0
  211. package/dist/experimental/webxr/webxr-input.cjs +93 -0
  212. package/dist/experimental/webxr/webxr-input.d.ts +24 -0
  213. package/dist/experimental/webxr/webxr-input.d.ts.map +1 -0
  214. package/dist/experimental/webxr/webxr-input.js +70 -0
  215. package/dist/experimental/webxr/webxr-input.js.map +1 -0
  216. package/dist/experimental/webxr/webxr-manager.cjs +356 -0
  217. package/dist/experimental/webxr/webxr-manager.d.ts +91 -0
  218. package/dist/experimental/webxr/webxr-manager.d.ts.map +1 -0
  219. package/dist/experimental/webxr/webxr-manager.js +354 -0
  220. package/dist/experimental/webxr/webxr-manager.js.map +1 -0
  221. package/dist/experimental/webxr/webxr-types.cjs +15 -0
  222. package/dist/experimental/webxr/webxr-types.d.ts +152 -0
  223. package/dist/experimental/webxr/webxr-types.d.ts.map +1 -0
  224. package/dist/experimental/webxr/webxr-types.js +5 -0
  225. package/dist/experimental/webxr/webxr-types.js.map +1 -0
  226. package/dist/geometry/edge-geometry.cjs +171 -0
  227. package/dist/geometry/edge-geometry.d.ts +3 -2
  228. package/dist/geometry/edge-geometry.d.ts.map +1 -1
  229. package/dist/geometry/edge-geometry.js.map +1 -1
  230. package/dist/geometry/geometry-primitives.cjs +189 -0
  231. package/dist/geometry/geometry-primitives.d.ts +60 -0
  232. package/dist/geometry/geometry-primitives.d.ts.map +1 -0
  233. package/dist/geometry/geometry-primitives.js +161 -0
  234. package/dist/geometry/geometry-primitives.js.map +1 -0
  235. package/dist/geometry/geometry-table.cjs +15 -0
  236. package/dist/geometry/geometry-utils.cjs +147 -0
  237. package/dist/geometry/geometry-utils.d.ts +7 -15
  238. package/dist/geometry/geometry-utils.d.ts.map +1 -1
  239. package/dist/geometry/geometry-utils.js +9 -55
  240. package/dist/geometry/geometry-utils.js.map +1 -1
  241. package/dist/geometry/geometry.cjs +90 -0
  242. package/dist/geometry/geometry.d.ts +9 -69
  243. package/dist/geometry/geometry.d.ts.map +1 -1
  244. package/dist/geometry/geometry.js +27 -93
  245. package/dist/geometry/geometry.js.map +1 -1
  246. package/dist/geometry/gpu-geometry.cjs +130 -0
  247. package/dist/geometry/gpu-geometry.d.ts +4 -2
  248. package/dist/geometry/gpu-geometry.d.ts.map +1 -1
  249. package/dist/geometry/gpu-geometry.js +3 -3
  250. package/dist/geometry/gpu-geometry.js.map +1 -1
  251. package/dist/geometry/gpu-vector-geometry-adapter.cjs +88 -0
  252. package/dist/geometry/gpu-vector-geometry-adapter.d.ts +5 -0
  253. package/dist/geometry/gpu-vector-geometry-adapter.d.ts.map +1 -0
  254. package/dist/geometry/gpu-vector-geometry-adapter.js +73 -0
  255. package/dist/geometry/gpu-vector-geometry-adapter.js.map +1 -0
  256. package/dist/geometry/gpu-vector-geometry.cjs +40 -0
  257. package/dist/geometry/gpu-vector-geometry.d.ts +21 -0
  258. package/dist/geometry/gpu-vector-geometry.d.ts.map +1 -0
  259. package/dist/geometry/gpu-vector-geometry.js +19 -0
  260. package/dist/geometry/gpu-vector-geometry.js.map +1 -0
  261. package/dist/geometry/mesh-simplification.cjs +385 -0
  262. package/dist/geometry/ring-geometry.cjs +104 -0
  263. package/dist/geometry/ring-geometry.d.ts +17 -0
  264. package/dist/geometry/ring-geometry.d.ts.map +1 -0
  265. package/dist/geometry/ring-geometry.js +94 -0
  266. package/dist/geometry/ring-geometry.js.map +1 -0
  267. package/dist/geometry/stroke-geometry.cjs +171 -0
  268. package/dist/graph/models/index.cjs +66 -0
  269. package/dist/graph/models/index.cjs.map +6 -0
  270. package/dist/graph/models/index.d.ts +7 -0
  271. package/dist/graph/models/index.d.ts.map +1 -0
  272. package/dist/graph/models/index.js +10 -0
  273. package/dist/graph/models/index.js.map +1 -0
  274. package/dist/graph/models/path/path-attribute-model.cjs +421 -0
  275. package/dist/graph/models/path/path-attribute-model.d.ts +142 -0
  276. package/dist/graph/models/path/path-attribute-model.d.ts.map +1 -0
  277. package/dist/graph/models/path/path-attribute-model.js +409 -0
  278. package/dist/graph/models/path/path-attribute-model.js.map +1 -0
  279. package/dist/graph/models/path/path-storage-model.cjs +711 -0
  280. package/dist/graph/models/path/path-storage-model.d.ts +174 -0
  281. package/dist/graph/models/path/path-storage-model.d.ts.map +1 -0
  282. package/dist/graph/models/path/path-storage-model.js +720 -0
  283. package/dist/graph/models/path/path-storage-model.js.map +1 -0
  284. package/dist/graph/models/path/path-trips-storage-model.cjs +271 -0
  285. package/dist/graph/models/path/path-trips-storage-model.d.ts +58 -0
  286. package/dist/graph/models/path/path-trips-storage-model.d.ts.map +1 -0
  287. package/dist/graph/models/path/path-trips-storage-model.js +248 -0
  288. package/dist/graph/models/path/path-trips-storage-model.js.map +1 -0
  289. package/dist/graph/models/polygon/polygon-attribute-model.cjs +117 -0
  290. package/dist/graph/models/polygon/polygon-attribute-model.d.ts +53 -0
  291. package/dist/graph/models/polygon/polygon-attribute-model.d.ts.map +1 -0
  292. package/dist/graph/models/polygon/polygon-attribute-model.js +101 -0
  293. package/dist/graph/models/polygon/polygon-attribute-model.js.map +1 -0
  294. package/dist/graph/models/polygon/polygon-shaders.cjs +283 -0
  295. package/dist/graph/models/polygon/polygon-shaders.d.ts +77 -0
  296. package/dist/graph/models/polygon/polygon-shaders.d.ts.map +1 -0
  297. package/dist/graph/models/polygon/polygon-shaders.js +242 -0
  298. package/dist/graph/models/polygon/polygon-shaders.js.map +1 -0
  299. package/dist/graph/models/polygon/polygon-storage-model.cjs +111 -0
  300. package/dist/graph/models/polygon/polygon-storage-model.d.ts +53 -0
  301. package/dist/graph/models/polygon/polygon-storage-model.d.ts.map +1 -0
  302. package/dist/graph/models/polygon/polygon-storage-model.js +92 -0
  303. package/dist/graph/models/polygon/polygon-storage-model.js.map +1 -0
  304. package/dist/graph/physics/index.cjs +50 -0
  305. package/dist/graph/physics/index.cjs.map +6 -0
  306. package/dist/graph/physics/index.d.ts +12 -0
  307. package/dist/graph/physics/index.d.ts.map +1 -0
  308. package/dist/graph/physics/index.js +12 -0
  309. package/dist/graph/physics/index.js.map +1 -0
  310. package/dist/graph/physics/physics-scenegraph.cjs +92 -0
  311. package/dist/graph/physics/physics-scenegraph.d.ts +35 -0
  312. package/dist/graph/physics/physics-scenegraph.d.ts.map +1 -0
  313. package/dist/graph/physics/physics-scenegraph.js +80 -0
  314. package/dist/graph/physics/physics-scenegraph.js.map +1 -0
  315. package/dist/graph/physics/scenegraph-behaviors.cjs +164 -0
  316. package/dist/graph/physics/scenegraph-behaviors.d.ts +37 -0
  317. package/dist/graph/physics/scenegraph-behaviors.d.ts.map +1 -0
  318. package/dist/graph/physics/scenegraph-behaviors.js +145 -0
  319. package/dist/graph/physics/scenegraph-behaviors.js.map +1 -0
  320. package/dist/graph/physics/scenegraph-instance.cjs +246 -0
  321. package/dist/graph/physics/scenegraph-instance.d.ts +59 -0
  322. package/dist/graph/physics/scenegraph-instance.d.ts.map +1 -0
  323. package/dist/graph/physics/scenegraph-instance.js +241 -0
  324. package/dist/graph/physics/scenegraph-instance.js.map +1 -0
  325. package/dist/graph/physics/scenegraph-joints.cjs +51 -0
  326. package/dist/graph/physics/scenegraph-joints.d.ts +5 -0
  327. package/dist/graph/physics/scenegraph-joints.d.ts.map +1 -0
  328. package/dist/graph/physics/scenegraph-joints.js +31 -0
  329. package/dist/graph/physics/scenegraph-joints.js.map +1 -0
  330. package/dist/graph/physics/scenegraph-motion.cjs +177 -0
  331. package/dist/graph/physics/scenegraph-motion.d.ts +37 -0
  332. package/dist/graph/physics/scenegraph-motion.d.ts.map +1 -0
  333. package/dist/graph/physics/scenegraph-motion.js +168 -0
  334. package/dist/graph/physics/scenegraph-motion.js.map +1 -0
  335. package/dist/graph/physics/scenegraph-properties.cjs +170 -0
  336. package/dist/graph/physics/scenegraph-properties.d.ts +37 -0
  337. package/dist/graph/physics/scenegraph-properties.d.ts.map +1 -0
  338. package/dist/graph/physics/scenegraph-properties.js +186 -0
  339. package/dist/graph/physics/scenegraph-properties.js.map +1 -0
  340. package/dist/graph/physics/scenegraph-publication.cjs +112 -0
  341. package/dist/graph/physics/scenegraph-publication.d.ts +23 -0
  342. package/dist/graph/physics/scenegraph-publication.d.ts.map +1 -0
  343. package/dist/graph/physics/scenegraph-publication.js +99 -0
  344. package/dist/graph/physics/scenegraph-publication.js.map +1 -0
  345. package/dist/graph/physics/scenegraph-session.cjs +256 -0
  346. package/dist/graph/physics/scenegraph-session.d.ts +68 -0
  347. package/dist/graph/physics/scenegraph-session.d.ts.map +1 -0
  348. package/dist/graph/physics/scenegraph-session.js +249 -0
  349. package/dist/graph/physics/scenegraph-session.js.map +1 -0
  350. package/dist/graph/tables/gpu-table-geometry.cjs +84 -0
  351. package/dist/graph/tables/gpu-table-geometry.d.ts +32 -0
  352. package/dist/graph/tables/gpu-table-geometry.d.ts.map +1 -0
  353. package/dist/graph/tables/gpu-table-geometry.js +67 -0
  354. package/dist/graph/tables/gpu-table-geometry.js.map +1 -0
  355. package/dist/graph/tables/gpu-table-model.cjs +459 -0
  356. package/dist/graph/tables/gpu-table-model.d.ts +67 -0
  357. package/dist/graph/tables/gpu-table-model.d.ts.map +1 -0
  358. package/dist/graph/tables/gpu-table-model.js +457 -0
  359. package/dist/graph/tables/gpu-table-model.js.map +1 -0
  360. package/dist/graph/tables/gpu-table-transform.cjs +341 -0
  361. package/dist/graph/tables/gpu-table-transform.d.ts +61 -0
  362. package/dist/graph/tables/gpu-table-transform.d.ts.map +1 -0
  363. package/dist/graph/tables/gpu-table-transform.js +333 -0
  364. package/dist/graph/tables/gpu-table-transform.js.map +1 -0
  365. package/dist/graph/tables/index.cjs +33 -0
  366. package/dist/graph/tables/index.cjs.map +6 -0
  367. package/dist/graph/tables/index.d.ts +4 -0
  368. package/dist/graph/tables/index.d.ts.map +1 -0
  369. package/dist/graph/tables/index.js +7 -0
  370. package/dist/graph/tables/index.js.map +1 -0
  371. package/dist/index.cjs +303 -10629
  372. package/dist/index.cjs.map +3 -3
  373. package/dist/index.d.ts +46 -19
  374. package/dist/index.d.ts.map +1 -1
  375. package/dist/index.js +33 -10
  376. package/dist/index.js.map +1 -1
  377. package/dist/interactivity/interactivity.cjs +570 -0
  378. package/dist/interactivity/interactivity.d.ts +107 -0
  379. package/dist/interactivity/interactivity.d.ts.map +1 -0
  380. package/dist/interactivity/interactivity.js +575 -0
  381. package/dist/interactivity/interactivity.js.map +1 -0
  382. package/dist/interactivity/physics.cjs +15 -0
  383. package/dist/interactivity/physics.d.ts +12 -0
  384. package/dist/interactivity/physics.d.ts.map +1 -0
  385. package/dist/interactivity/physics.js +5 -0
  386. package/dist/interactivity/physics.js.map +1 -0
  387. package/dist/material/material-factory.cjs +99 -0
  388. package/dist/material/material-factory.d.ts +1 -1
  389. package/dist/material/material-factory.d.ts.map +1 -1
  390. package/dist/material/material.cjs +239 -0
  391. package/dist/material/material.d.ts +2 -2
  392. package/dist/material/material.d.ts.map +1 -1
  393. package/dist/material/material.js +2 -2
  394. package/dist/material/material.js.map +1 -1
  395. package/dist/model/gpu-vector-bindings.cjs +226 -0
  396. package/dist/model/gpu-vector-bindings.d.ts +36 -0
  397. package/dist/model/gpu-vector-bindings.d.ts.map +1 -0
  398. package/dist/model/gpu-vector-bindings.js +217 -0
  399. package/dist/model/gpu-vector-bindings.js.map +1 -0
  400. package/dist/model/gpu-vector-draw-batches.cjs +82 -0
  401. package/dist/model/gpu-vector-draw-batches.d.ts +5 -0
  402. package/dist/model/gpu-vector-draw-batches.d.ts.map +1 -0
  403. package/dist/model/gpu-vector-draw-batches.js +73 -0
  404. package/dist/model/gpu-vector-draw-batches.js.map +1 -0
  405. package/dist/model/gpu-vector-model-batches.cjs +94 -0
  406. package/dist/model/gpu-vector-model-batches.d.ts +41 -0
  407. package/dist/model/gpu-vector-model-batches.d.ts.map +1 -0
  408. package/dist/model/gpu-vector-model-batches.js +77 -0
  409. package/dist/model/gpu-vector-model-batches.js.map +1 -0
  410. package/dist/model/gpu-vector-model.cjs +1264 -0
  411. package/dist/model/gpu-vector-model.d.ts +352 -0
  412. package/dist/model/gpu-vector-model.d.ts.map +1 -0
  413. package/dist/model/gpu-vector-model.js +1375 -0
  414. package/dist/model/gpu-vector-model.js.map +1 -0
  415. package/dist/model/model.cjs +134 -0
  416. package/dist/model/model.d.ts +22 -306
  417. package/dist/model/model.d.ts.map +1 -1
  418. package/dist/model/model.js +68 -1092
  419. package/dist/model/model.js.map +1 -1
  420. package/dist/model/split-uniforms-and-bindings.cjs +44 -0
  421. package/dist/model/split-uniforms-and-bindings.d.ts +1 -1
  422. package/dist/model/split-uniforms-and-bindings.d.ts.map +1 -1
  423. package/dist/model/split-uniforms-and-bindings.js +5 -2
  424. package/dist/model/split-uniforms-and-bindings.js.map +1 -1
  425. package/dist/models/billboard-texture-model.cjs +167 -0
  426. package/dist/models/billboard-texture-model.d.ts +1 -1
  427. package/dist/models/billboard-texture-model.d.ts.map +1 -1
  428. package/dist/models/billboard-texture-model.js +1 -1
  429. package/dist/models/billboard-texture-model.js.map +1 -1
  430. package/dist/models/billboard-texture-module.cjs +61 -0
  431. package/dist/models/clip-space.cjs +103 -0
  432. package/dist/models/clip-space.d.ts +4 -1
  433. package/dist/models/clip-space.d.ts.map +1 -1
  434. package/dist/models/clip-space.js +16 -13
  435. package/dist/models/clip-space.js.map +1 -1
  436. package/dist/models/directional-light-model.cjs +45 -0
  437. package/dist/models/directional-light-model.js +1 -1
  438. package/dist/models/directional-light-model.js.map +1 -1
  439. package/dist/models/light-model-utils.cjs +426 -0
  440. package/dist/models/point-light-model.cjs +44 -0
  441. package/dist/models/point-light-model.js +1 -1
  442. package/dist/models/point-light-model.js.map +1 -1
  443. package/dist/models/spot-light-model.cjs +45 -0
  444. package/dist/models/spot-light-model.js +1 -1
  445. package/dist/models/spot-light-model.js.map +1 -1
  446. package/dist/modules/picking/color-picking.cjs +209 -0
  447. package/dist/modules/picking/color-picking.d.ts +1 -1
  448. package/dist/modules/picking/index-color-picking.cjs +230 -0
  449. package/dist/modules/picking/index-color-picking.d.ts +1 -1
  450. package/dist/modules/picking/index-picking.cjs +201 -0
  451. package/dist/modules/picking/index-picking.d.ts +1 -1
  452. package/dist/modules/picking/legacy-color-picking.cjs +28 -0
  453. package/dist/modules/picking/legacy-color-picking.d.ts +1 -1
  454. package/dist/modules/picking/legacy-picking-manager.cjs +92 -0
  455. package/dist/modules/picking/picking-manager.cjs +360 -0
  456. package/dist/modules/picking/picking-uniforms.cjs +140 -0
  457. package/dist/modules/picking/picking-uniforms.d.ts +1 -1
  458. package/dist/modules/picking/picking-uniforms.d.ts.map +1 -1
  459. package/dist/modules/picking/picking.cjs +43 -0
  460. package/dist/modules/picking/picking.d.ts +1 -1
  461. package/dist/passes/get-fragment-shader.cjs +119 -0
  462. package/dist/passes/shader-pass-renderer.cjs +722 -0
  463. package/dist/passes/shader-pass-renderer.d.ts +2 -2
  464. package/dist/passes/shader-pass-renderer.d.ts.map +1 -1
  465. package/dist/passes/shader-pass-renderer.js +1 -1
  466. package/dist/passes/shader-pass-renderer.js.map +1 -1
  467. package/dist/passes/texture-transform-module.cjs +78 -0
  468. package/dist/scenegraph/controllers/area-light-controller.cjs +143 -0
  469. package/dist/scenegraph/controllers/area-light-controller.d.ts +31 -0
  470. package/dist/scenegraph/controllers/area-light-controller.d.ts.map +1 -0
  471. package/dist/scenegraph/controllers/area-light-controller.js +130 -0
  472. package/dist/scenegraph/controllers/area-light-controller.js.map +1 -0
  473. package/dist/scenegraph/controllers/billboard-controller.cjs +156 -0
  474. package/dist/scenegraph/controllers/billboard-controller.d.ts +45 -0
  475. package/dist/scenegraph/controllers/billboard-controller.d.ts.map +1 -0
  476. package/dist/scenegraph/controllers/billboard-controller.js +156 -0
  477. package/dist/scenegraph/controllers/billboard-controller.js.map +1 -0
  478. package/dist/scenegraph/controllers/joint-controller.cjs +71 -0
  479. package/dist/scenegraph/controllers/joint-controller.d.ts +30 -0
  480. package/dist/scenegraph/controllers/joint-controller.d.ts.map +1 -0
  481. package/dist/scenegraph/controllers/joint-controller.js +53 -0
  482. package/dist/scenegraph/controllers/joint-controller.js.map +1 -0
  483. package/dist/scenegraph/controllers/material-variants.cjs +61 -0
  484. package/dist/scenegraph/controllers/material-variants.d.ts +42 -0
  485. package/dist/scenegraph/controllers/material-variants.d.ts.map +1 -0
  486. package/dist/scenegraph/controllers/material-variants.js +40 -0
  487. package/dist/scenegraph/controllers/material-variants.js.map +1 -0
  488. package/dist/scenegraph/controllers/morph-controller.cjs +61 -0
  489. package/dist/scenegraph/controllers/morph-controller.d.ts +19 -0
  490. package/dist/scenegraph/controllers/morph-controller.d.ts.map +1 -0
  491. package/dist/scenegraph/controllers/morph-controller.js +41 -0
  492. package/dist/scenegraph/controllers/morph-controller.js.map +1 -0
  493. package/dist/scenegraph/controllers/skin-controller.cjs +111 -0
  494. package/dist/scenegraph/controllers/skin-controller.d.ts +36 -0
  495. package/dist/scenegraph/controllers/skin-controller.d.ts.map +1 -0
  496. package/dist/scenegraph/controllers/skin-controller.js +90 -0
  497. package/dist/scenegraph/controllers/skin-controller.js.map +1 -0
  498. package/dist/scenegraph/group-node.cjs +129 -0
  499. package/dist/scenegraph/model-node.cjs +68 -0
  500. package/dist/scenegraph/physics-transforms.cjs +95 -0
  501. package/dist/scenegraph/physics-transforms.d.ts +13 -0
  502. package/dist/scenegraph/physics-transforms.d.ts.map +1 -0
  503. package/dist/scenegraph/physics-transforms.js +72 -0
  504. package/dist/scenegraph/physics-transforms.js.map +1 -0
  505. package/dist/scenegraph/published-transforms.cjs +37 -0
  506. package/dist/scenegraph/published-transforms.d.ts +17 -0
  507. package/dist/scenegraph/published-transforms.d.ts.map +1 -0
  508. package/dist/scenegraph/published-transforms.js +16 -0
  509. package/dist/scenegraph/published-transforms.js.map +1 -0
  510. package/dist/scenegraph/scenegraph-bounds.cjs +51 -0
  511. package/dist/scenegraph/scenegraph-node.cjs +182 -0
  512. package/dist/shader-inputs.cjs +231 -0
  513. package/dist/shader-inputs.d.ts +1 -1
  514. package/dist/shader-inputs.d.ts.map +1 -1
  515. package/dist/utils/buffer-layout-helper.cjs +52 -0
  516. package/dist/utils/buffer-layout-order.cjs +37 -0
  517. package/dist/utils/deep-equal.cjs +65 -0
  518. package/dist/utils/get-platform-info.cjs +21 -0
  519. package/dist/utils/get-platform-info.d.ts +2 -0
  520. package/dist/utils/get-platform-info.d.ts.map +1 -0
  521. package/dist/utils/get-platform-info.js +5 -0
  522. package/dist/utils/get-platform-info.js.map +1 -0
  523. package/dist/utils/gpu-vector-batch-structure.cjs +45 -0
  524. package/dist/utils/gpu-vector-batch-structure.d.ts +12 -0
  525. package/dist/utils/gpu-vector-batch-structure.d.ts.map +1 -0
  526. package/dist/utils/gpu-vector-batch-structure.js +27 -0
  527. package/dist/utils/gpu-vector-batch-structure.js.map +1 -0
  528. package/dist/utils/shader-module-utils.cjs +148 -0
  529. package/dist/utils/uid.cjs +32 -0
  530. package/package.json +47 -8
  531. package/src/animation/deform-positions.ts +62 -0
  532. package/src/animation/node-animation-binding.ts +54 -0
  533. package/src/animation/property-animation-binding.ts +212 -0
  534. package/src/animation/scenegraph-animator.ts +117 -0
  535. package/src/animation/texture-transform.ts +59 -0
  536. package/src/animation-loop/animation-loop.ts +10 -3
  537. package/src/audio/audio-controller.ts +583 -0
  538. package/src/audio/audio-environment.ts +202 -0
  539. package/src/audio/audio-graph.ts +253 -0
  540. package/src/compute/buffer-transform.ts +71 -16
  541. package/src/compute/computation.ts +4 -19
  542. package/src/compute/texture-transform.ts +25 -12
  543. package/src/controls/orbit-controls.ts +4 -1
  544. package/src/dynamic-buffer/dynamic-buffer.ts +15 -449
  545. package/src/dynamic-texture/dynamic-texture.ts +5 -760
  546. package/src/dynamic-texture/texture-binding-source.ts +8 -90
  547. package/src/dynamic-texture/texture-data.ts +31 -340
  548. package/src/dynamic-texture/video-texture.ts +1 -1
  549. package/src/experimental/controls/comparison-splitter.ts +269 -0
  550. package/src/experimental/controls/flat-controller.ts +403 -0
  551. package/src/experimental/controls/index.ts +16 -0
  552. package/src/experimental/controls/orbit-controls.ts +6 -0
  553. package/src/experimental/materials/emissive-material.ts +120 -0
  554. package/src/experimental/materials/glass-material.ts +607 -0
  555. package/src/experimental/materials/glass-transmission.ts +1023 -0
  556. package/src/experimental/materials/index.ts +49 -0
  557. package/src/experimental/materials/optical-caustics.ts +234 -0
  558. package/src/experimental/materials/optical-lighting.ts +148 -0
  559. package/src/experimental/materials/optical-point-lights.ts +288 -0
  560. package/src/experimental/materials/reflective-material.ts +214 -0
  561. package/src/experimental/textures/html-texture.ts +285 -0
  562. package/src/experimental/textures/index.ts +8 -0
  563. package/src/experimental/textures/packed-pixels.ts +351 -0
  564. package/src/experimental/textures/rgba-decoder.ts +79 -0
  565. package/src/experimental/webxr/index.ts +21 -0
  566. package/src/experimental/webxr/webxr-animation-frame-provider.ts +22 -0
  567. package/src/experimental/webxr/webxr-camera-texture.ts +195 -0
  568. package/src/experimental/webxr/webxr-input.ts +117 -0
  569. package/src/experimental/webxr/webxr-manager.ts +524 -0
  570. package/src/experimental/webxr/webxr-types.ts +192 -0
  571. package/src/geometry/edge-geometry.ts +7 -3
  572. package/src/geometry/geometry-primitives.ts +226 -0
  573. package/src/geometry/geometry-utils.ts +16 -71
  574. package/src/geometry/geometry.ts +36 -163
  575. package/src/geometry/gpu-geometry.ts +9 -4
  576. package/src/geometry/gpu-vector-geometry-adapter.ts +78 -0
  577. package/src/geometry/gpu-vector-geometry.ts +33 -0
  578. package/src/geometry/ring-geometry.ts +117 -0
  579. package/src/graph/models/index.ts +45 -0
  580. package/src/graph/models/path/path-attribute-model.ts +563 -0
  581. package/src/graph/models/path/path-storage-model.ts +996 -0
  582. package/src/graph/models/path/path-trips-storage-model.ts +286 -0
  583. package/src/graph/models/polygon/polygon-attribute-model.ts +165 -0
  584. package/src/graph/models/polygon/polygon-shaders.ts +279 -0
  585. package/src/graph/models/polygon/polygon-storage-model.ts +146 -0
  586. package/src/graph/physics/index.ts +24 -0
  587. package/src/graph/physics/physics-scenegraph.ts +112 -0
  588. package/src/graph/physics/scenegraph-behaviors.ts +169 -0
  589. package/src/graph/physics/scenegraph-instance.ts +296 -0
  590. package/src/graph/physics/scenegraph-joints.ts +37 -0
  591. package/src/graph/physics/scenegraph-motion.ts +175 -0
  592. package/src/graph/physics/scenegraph-properties.ts +241 -0
  593. package/src/graph/physics/scenegraph-publication.ts +116 -0
  594. package/src/graph/physics/scenegraph-session.ts +317 -0
  595. package/src/graph/tables/gpu-table-geometry.ts +88 -0
  596. package/src/graph/tables/gpu-table-model.ts +661 -0
  597. package/src/graph/tables/gpu-table-transform.ts +497 -0
  598. package/src/graph/tables/index.ts +18 -0
  599. package/src/index.ts +144 -27
  600. package/src/interactivity/interactivity.ts +670 -0
  601. package/src/interactivity/physics.ts +19 -0
  602. package/src/material/material-factory.ts +1 -1
  603. package/src/material/material.ts +2 -2
  604. package/src/model/gpu-vector-bindings.ts +276 -0
  605. package/src/model/gpu-vector-draw-batches.ts +116 -0
  606. package/src/model/gpu-vector-model-batches.ts +142 -0
  607. package/src/model/gpu-vector-model.ts +1819 -0
  608. package/src/model/model.ts +91 -1444
  609. package/src/model/split-uniforms-and-bindings.ts +6 -3
  610. package/src/models/billboard-texture-model.ts +1 -1
  611. package/src/models/clip-space.ts +21 -14
  612. package/src/models/directional-light-model.ts +1 -1
  613. package/src/models/point-light-model.ts +1 -1
  614. package/src/models/spot-light-model.ts +1 -1
  615. package/src/modules/picking/legacy-picking-manager.ts +1 -1
  616. package/src/modules/picking/picking-uniforms.ts +1 -1
  617. package/src/passes/shader-pass-renderer.ts +2 -2
  618. package/src/scenegraph/controllers/area-light-controller.ts +152 -0
  619. package/src/scenegraph/controllers/billboard-controller.ts +204 -0
  620. package/src/scenegraph/controllers/joint-controller.ts +81 -0
  621. package/src/scenegraph/controllers/material-variants.ts +70 -0
  622. package/src/scenegraph/controllers/morph-controller.ts +61 -0
  623. package/src/scenegraph/controllers/skin-controller.ts +125 -0
  624. package/src/scenegraph/physics-transforms.ts +82 -0
  625. package/src/scenegraph/published-transforms.ts +18 -0
  626. package/src/shader-inputs.ts +1 -1
  627. package/src/utils/get-platform-info.ts +5 -0
  628. package/src/utils/gpu-vector-batch-structure.ts +36 -0
  629. package/dist/compute/kernel.d.ts +0 -54
  630. package/dist/compute/kernel.d.ts.map +0 -1
  631. package/dist/compute/kernel.js +0 -103
  632. package/dist/compute/kernel.js.map +0 -1
  633. package/dist/compute/render-kernel.d.ts +0 -65
  634. package/dist/compute/render-kernel.d.ts.map +0 -1
  635. package/dist/compute/render-kernel.js +0 -129
  636. package/dist/compute/render-kernel.js.map +0 -1
  637. package/dist/geometries/cone-geometry.d.ts +0 -12
  638. package/dist/geometries/cone-geometry.d.ts.map +0 -1
  639. package/dist/geometries/cone-geometry.js +0 -19
  640. package/dist/geometries/cone-geometry.js.map +0 -1
  641. package/dist/geometries/cube-geometry.d.ts +0 -14
  642. package/dist/geometries/cube-geometry.d.ts.map +0 -1
  643. package/dist/geometries/cube-geometry.js +0 -222
  644. package/dist/geometries/cube-geometry.js.map +0 -1
  645. package/dist/geometries/cylinder-geometry.d.ts +0 -11
  646. package/dist/geometries/cylinder-geometry.d.ts.map +0 -1
  647. package/dist/geometries/cylinder-geometry.js +0 -17
  648. package/dist/geometries/cylinder-geometry.js.map +0 -1
  649. package/dist/geometries/ico-sphere-geometry.d.ts +0 -11
  650. package/dist/geometries/ico-sphere-geometry.d.ts.map +0 -1
  651. package/dist/geometries/ico-sphere-geometry.js +0 -158
  652. package/dist/geometries/ico-sphere-geometry.js.map +0 -1
  653. package/dist/geometries/plane-geometry.d.ts +0 -20
  654. package/dist/geometries/plane-geometry.d.ts.map +0 -1
  655. package/dist/geometries/plane-geometry.js +0 -106
  656. package/dist/geometries/plane-geometry.js.map +0 -1
  657. package/dist/geometries/sphere-geometry.d.ts +0 -12
  658. package/dist/geometries/sphere-geometry.d.ts.map +0 -1
  659. package/dist/geometries/sphere-geometry.js +0 -88
  660. package/dist/geometries/sphere-geometry.js.map +0 -1
  661. package/dist/geometries/truncated-cone-geometry.d.ts +0 -23
  662. package/dist/geometries/truncated-cone-geometry.d.ts.map +0 -1
  663. package/dist/geometries/truncated-cone-geometry.js +0 -112
  664. package/dist/geometries/truncated-cone-geometry.js.map +0 -1
  665. package/src/compute/kernel.ts +0 -146
  666. package/src/compute/render-kernel.ts +0 -192
  667. package/src/geometries/cone-geometry.ts +0 -31
  668. package/src/geometries/cube-geometry.ts +0 -258
  669. package/src/geometries/cylinder-geometry.ts +0 -28
  670. package/src/geometries/ico-sphere-geometry.ts +0 -193
  671. package/src/geometries/plane-geometry.ts +0 -142
  672. package/src/geometries/sphere-geometry.ts +0 -113
  673. package/src/geometries/truncated-cone-geometry.ts +0 -145
@@ -0,0 +1,1819 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import {type TypedArray} from '@math.gl/core';
6
+ import {
7
+ type RenderPipelineProps,
8
+ type RenderPipelineParameters,
9
+ type BufferLayout,
10
+ type TextureFormatColor,
11
+ type TextureFormatDepthStencil,
12
+ type Shader,
13
+ type VertexArray,
14
+ type TransformFeedback,
15
+ type CommandEncoder,
16
+ type AttributeInfo,
17
+ type Binding,
18
+ type BindingsByGroup,
19
+ type ComputeShaderLayout,
20
+ type PrimitiveTopology,
21
+ type ShaderLayout,
22
+ type AttributeShaderType,
23
+ Device,
24
+ Buffer,
25
+ ExternalTexture,
26
+ Texture,
27
+ TextureView,
28
+ RenderPipeline,
29
+ RenderPass,
30
+ PipelineFactory,
31
+ ShaderFactory,
32
+ UniformStore,
33
+ assert,
34
+ log,
35
+ dataTypeDecoder,
36
+ getAttributeInfosFromLayouts,
37
+ normalizeBindingsByGroup
38
+ } from '@luma.gl/core';
39
+
40
+ import type {
41
+ ShaderBindingDebugRow,
42
+ ShaderModule,
43
+ ShaderPlugin,
44
+ GLSLShaderAssembler,
45
+ WGSLShaderAssembler
46
+ } from '@luma.gl/shadertools';
47
+ import {
48
+ mergeShaderPluginModules,
49
+ resolveShaderPlugins,
50
+ ShaderAssembler
51
+ } from '@luma.gl/shadertools';
52
+
53
+ import {getDebugTableForShaderLayout} from '../debug/debug-shader-layout';
54
+ import {debugFramebuffer} from '../debug/debug-framebuffer';
55
+ import {deepEqual} from '../utils/deep-equal';
56
+ import {BufferLayoutHelper} from '../utils/buffer-layout-helper';
57
+ import {sortedBufferLayoutByShaderSourceLocations} from '../utils/buffer-layout-order';
58
+ import {
59
+ getShaderModuleUniformBlockLayouts,
60
+ mergeInferredShaderLayout,
61
+ mergeShaderModules,
62
+ mergeShaderModuleBindingsIntoLayout,
63
+ shaderModuleHasUniforms
64
+ } from '../utils/shader-module-utils';
65
+ import {getPlatformInfo} from '../utils/get-platform-info';
66
+ import {uid} from '../utils/uid';
67
+ import {
68
+ getGPUVectorModelBatches,
69
+ validateGPUVectorModelLayouts,
70
+ type GPUVectorModelCount,
71
+ type GPUVectorModelData,
72
+ type GPUVectorModelInput,
73
+ type GPUVectorModelInputs,
74
+ type GPUVectorModelDrawBatchesOptions
75
+ } from './gpu-vector-model-batches';
76
+ export {
77
+ getGPUVectorModelBatches,
78
+ type GPUVectorModelCount,
79
+ type GPUVectorModelData,
80
+ type GPUVectorModelInput,
81
+ type GPUVectorModelInputs,
82
+ type GPUVectorModelBatch,
83
+ type GPUVectorModelDrawBatchesOptions
84
+ } from './gpu-vector-model-batches';
85
+
86
+ import {validateGPUVectorBatchStructure} from '../utils/gpu-vector-batch-structure';
87
+ import {drawGPUVectorGroups} from './gpu-vector-draw-batches';
88
+ import {GPUVectorGeometry} from '../geometry/gpu-vector-geometry';
89
+ import {GPUVectorBindings, type GPUVectorModelAttributes} from './gpu-vector-bindings';
90
+ import {ShaderInputs} from '../shader-inputs';
91
+ import {
92
+ DynamicBuffer,
93
+ type DynamicBufferRange,
94
+ isBufferRangeBinding,
95
+ resolveBufferRangeBinding
96
+ } from '@luma.gl/core/dynamic';
97
+ import {
98
+ getTextureBindingLayout,
99
+ isTextureBindingSource,
100
+ type TextureBindingSource
101
+ } from '@luma.gl/core/dynamic';
102
+
103
+ const LOG_DRAW_PRIORITY = 2;
104
+ const LOG_DRAW_TIMEOUT = 10000;
105
+ const PIPELINE_INITIALIZATION_FAILED = 'render pipeline initialization failed';
106
+ const DEPTH_STENCIL_ATTACHMENT_FORMATS: TextureFormatDepthStencil[] = [
107
+ 'stencil8',
108
+ 'depth16unorm',
109
+ 'depth24plus',
110
+ 'depth24plus-stencil8',
111
+ 'depth32float',
112
+ 'depth32float-stencil8'
113
+ ];
114
+ /** Resource accepted by one model binding slot. */
115
+ export type ModelBinding = Binding | TextureBindingSource | DynamicBuffer | DynamicBufferRange;
116
+ type ModelBuffer = Buffer | DynamicBuffer;
117
+ /** Shader layout subset needed while resolving texture binding sources. */
118
+ export type AnyShaderLayout = Pick<ShaderLayout | ComputeShaderLayout, 'bindings'>;
119
+
120
+ export type GPUVectorModelProps = Omit<RenderPipelineProps, 'vs' | 'fs' | 'bindings'> & {
121
+ /** GPU-only mesh inputs, indices, and topology. */
122
+ geometry?: GPUVectorGeometry | null;
123
+ /** Supplemental vertex or instance vectors and constants. */
124
+ attributeVectors?: GPUVectorModelAttributes;
125
+ /** Draw count updated from each vector batch. Defaults to `instance`. */
126
+ gpuVectorCount?: GPUVectorModelCount;
127
+ source?: string;
128
+ /** Input language compiled by the application-registered shader assembler transpiler. */
129
+ sourceLanguage?: string;
130
+ vs?: string | null;
131
+ fs?: string | null;
132
+
133
+ /** Shadertools shader modules added to shader code. */
134
+ modules?: ShaderModule<any, any, any>[];
135
+ /** Shadertools boolean or numeric preprocessor defines that configure shader code. */
136
+ defines?: Record<string, boolean | number>;
137
+ /** Reusable shader assembly plugins resolved for the active GLSL or WGSL backend. */
138
+ plugins?: ShaderPlugin[];
139
+
140
+ /** Shader inputs, used to generate uniform buffers and bindings. */
141
+ shaderInputs?: ShaderInputs;
142
+ /** Shader resource bindings, including dynamic buffers and dynamic textures. */
143
+ bindings?: Record<string, ModelBinding>;
144
+ /** WebGL-only uniforms */
145
+ uniforms?: Record<string, unknown>;
146
+ /** Parameters that are built into the pipeline */
147
+ parameters?: RenderPipelineParameters;
148
+
149
+ /** @deprecated Use instanced rendering? Will be auto-detected in 9.1 */
150
+ isInstanced?: boolean;
151
+ /** instance count */
152
+ instanceCount?: number;
153
+ /** Vertex count */
154
+ vertexCount?: number;
155
+
156
+ /** Optional index buffer. Dynamic buffers are rebound when resized. */
157
+ indexBuffer?: ModelBuffer | null;
158
+ /** Optional indexed draw count. Defaults to vertexCount, then the full bound index buffer length. */
159
+ indexCount?: number;
160
+ /** First vertex byte offset for WebGL indexed draws or first vertex for non-indexed draws. */
161
+ firstVertex?: number;
162
+ /** First index element for WebGPU indexed draws. */
163
+ firstIndex?: number;
164
+ /** Buffer-valued attributes. Dynamic buffers are rebound when resized. */
165
+ attributes?: Record<string, ModelBuffer>;
166
+ /** */
167
+ constantAttributes?: Record<string, TypedArray>;
168
+
169
+ /** Some applications intentionally supply unused attributes and bindings, and want to disable warnings */
170
+ disableWarnings?: boolean;
171
+
172
+ /** @internal For use with {@link TransformFeedback}, WebGL only. */
173
+ varyings?: string[];
174
+
175
+ transformFeedback?: TransformFeedback;
176
+
177
+ /** Show shader source in browser? */
178
+ debugShaders?: 'never' | 'errors' | 'warnings' | 'always';
179
+
180
+ /** Factory used to create a {@link RenderPipeline}. Defaults to {@link Device} default factory. */
181
+ pipelineFactory?: PipelineFactory;
182
+ /** Factory used to create a {@link Shader}. Defaults to {@link Device} default factory. */
183
+ shaderFactory?: ShaderFactory;
184
+ /** Shader assembler. Defaults to the shared assembler for the device's shader language. */
185
+ shaderAssembler?: ShaderAssembler;
186
+ };
187
+
188
+ /**
189
+ * High level draw API for luma.gl.
190
+ *
191
+ * A `GPUVectorModel` encapsulates shaders, geometry attributes, bindings and render
192
+ * pipeline state into a single object. It automatically reuses and rebuilds
193
+ * pipelines as render parameters change and exposes convenient hooks for
194
+ * updating uniforms and attributes.
195
+ *
196
+ * Features:
197
+ * - Reuses and lazily recompiles {@link RenderPipeline | pipelines} as needed.
198
+ * - Integrates with `@luma.gl/shadertools` to assemble GLSL or WGSL from shader modules.
199
+ * - Manages geometry attributes and buffer bindings.
200
+ * - Accepts textures, samplers and uniform buffers as bindings, including texture binding sources.
201
+ * - Provides detailed debug logging and optional shader source inspection.
202
+ */
203
+ export class GPUVectorModel {
204
+ /** Creates a model while allowing the backend to compile its render pipeline asynchronously. */
205
+ static async createAsync<ModelType extends GPUVectorModel, Props = GPUVectorModelProps>(
206
+ this: new (
207
+ device: Device,
208
+ props: Props
209
+ ) => ModelType,
210
+ device: Device,
211
+ props: Props
212
+ ): Promise<ModelType> {
213
+ const ownsCompilation = !PipelineFactory.getAsyncCompilation(device);
214
+ const asyncCompilation = ownsCompilation
215
+ ? PipelineFactory.beginAsyncCompilation(device)
216
+ : PipelineFactory.getAsyncCompilation(device)!;
217
+ let model: ModelType;
218
+ try {
219
+ model = new this(device, props);
220
+ } finally {
221
+ if (ownsCompilation) PipelineFactory.endAsyncCompilation(device, asyncCompilation);
222
+ }
223
+ try {
224
+ if (ownsCompilation) {
225
+ await Promise.all(asyncCompilation);
226
+ } else {
227
+ await model._pipelineInitialization;
228
+ }
229
+ return model;
230
+ } catch (error) {
231
+ model.destroy();
232
+ throw error;
233
+ }
234
+ }
235
+
236
+ static defaultProps: Required<GPUVectorModelProps> = {
237
+ ...RenderPipeline.defaultProps,
238
+ gpuVectorCount: 'instance',
239
+ geometry: null,
240
+ attributeVectors: undefined!,
241
+ source: undefined!,
242
+ sourceLanguage: undefined!,
243
+ vs: null,
244
+ fs: null,
245
+ id: 'unnamed',
246
+ handle: undefined,
247
+ userData: {},
248
+ defines: {},
249
+ modules: [],
250
+ plugins: [],
251
+ indexBuffer: null,
252
+ indexCount: undefined!,
253
+ firstVertex: 0,
254
+ firstIndex: 0,
255
+ attributes: {},
256
+ constantAttributes: {},
257
+ bindings: {},
258
+ uniforms: {},
259
+ varyings: [],
260
+
261
+ isInstanced: undefined!,
262
+ instanceCount: 0,
263
+ vertexCount: 0,
264
+
265
+ shaderInputs: undefined!,
266
+ pipelineFactory: undefined!,
267
+ shaderFactory: undefined!,
268
+ transformFeedback: undefined!,
269
+ shaderAssembler: ShaderAssembler.getDefaultShaderAssembler('glsl'),
270
+
271
+ debugShaders: undefined!,
272
+ disableWarnings: undefined!
273
+ };
274
+
275
+ /** Device that created this model */
276
+ readonly device: Device;
277
+ /** Application provided identifier */
278
+ readonly id: string;
279
+ /** WGSL shader source when using unified shader */
280
+ // @ts-expect-error assigned in function called from constructor
281
+ readonly source: string;
282
+ /** GLSL vertex shader source */
283
+ // @ts-expect-error assigned in function called from constructor
284
+ readonly vs: string;
285
+ /** GLSL fragment shader source */
286
+ // @ts-expect-error assigned in function called from constructor
287
+ readonly fs: string;
288
+ /** Factory used to create render pipelines */
289
+ readonly pipelineFactory: PipelineFactory;
290
+ /** Factory used to create shaders */
291
+ readonly shaderFactory: ShaderFactory;
292
+ /** User-supplied per-model data */
293
+ userData: {[key: string]: any} = {};
294
+
295
+ // Fixed properties (change can trigger pipeline rebuild)
296
+
297
+ /** The render pipeline GPU parameters, depth testing etc */
298
+ parameters: RenderPipelineParameters;
299
+
300
+ /** The primitive topology */
301
+ topology: PrimitiveTopology;
302
+ /** Buffer layout */
303
+ bufferLayout: BufferLayout[];
304
+
305
+ // Dynamic properties
306
+
307
+ /** Use instanced rendering */
308
+ isInstanced: boolean | undefined = undefined;
309
+ /** instance count. `undefined` means not instanced */
310
+ instanceCount: number = 0;
311
+ /** Vertex count */
312
+ vertexCount: number;
313
+ /** Indexed draw count override. Undefined uses vertexCount, then the full bound index buffer. */
314
+ indexCount: number | undefined;
315
+ /** First vertex byte offset for WebGL indexed draws or first vertex for non-indexed draws. */
316
+ firstVertex: number;
317
+ /** First index element for WebGPU indexed draws. */
318
+ firstIndex: number;
319
+
320
+ /** Index buffer */
321
+ indexBuffer: Buffer | null = null;
322
+ /** Buffer-valued attributes */
323
+ bufferAttributes: Record<string, Buffer> = {};
324
+ /** Constant-valued attributes */
325
+ constantAttributes: Record<string, TypedArray> = {};
326
+ /** Bindings (textures, samplers, uniform buffers) */
327
+ bindings: Record<string, ModelBinding> = {};
328
+
329
+ /**
330
+ * VertexArray
331
+ * @note not implemented: if bufferLayout is updated, vertex array has to be rebuilt!
332
+ * @todo - allow application to define multiple vertex arrays?
333
+ * */
334
+ vertexArray!: VertexArray;
335
+
336
+ /** TransformFeedback, WebGL 2 only. */
337
+ transformFeedback: TransformFeedback | null = null;
338
+
339
+ /** The underlying GPU "program". @note May be recreated if parameters change */
340
+ pipeline!: RenderPipeline;
341
+
342
+ /** ShaderInputs instance */
343
+ // @ts-expect-error Assigned in function called by constructor
344
+ shaderInputs: ShaderInputs;
345
+ // @ts-expect-error Assigned in function called by constructor
346
+ _uniformStore: UniformStore;
347
+
348
+ _attributeInfos: Record<string, AttributeInfo> = {};
349
+ protected props: Required<GPUVectorModelProps>;
350
+ private geometryVectorBindings!: GPUVectorBindings;
351
+ private attributeVectorBindings!: GPUVectorBindings;
352
+ private explicitBufferLayout: BufferLayout[] = [];
353
+ private constructorDrawCounts: Pick<GPUVectorModelProps, 'vertexCount' | 'instanceCount'>;
354
+ private constructorDrawOffsets: Pick<GPUVectorModelProps, 'firstVertex' | 'firstIndex'>;
355
+ private drawingVectorBatches = false;
356
+ private indexVector: GPUVectorModelInput | null = null;
357
+ private currentAttributes: NonNullable<GPUVectorModelProps['attributes']> = {};
358
+ private currentAttributeByteOffsets: Record<string, number> = {};
359
+ private _dynamicIndexBufferSource: {source: DynamicBuffer; generation: number} | null = null;
360
+ private _dynamicAttributeBufferSources: Record<
361
+ number,
362
+ {source: DynamicBuffer; generation: number; byteOffset: number}
363
+ > = {};
364
+ private _colorAttachmentFormats: (TextureFormatColor | null)[] | undefined;
365
+ private _depthStencilAttachmentFormat: TextureFormatDepthStencil | undefined;
366
+
367
+ _pipelineNeedsUpdate: string | false = 'newly created';
368
+ private _needsRedraw: string | false = 'initializing';
369
+ private _drawBlockedReason: string | false = false;
370
+ private _destroyed = false;
371
+ private _vertexCountSet = false;
372
+
373
+ /** "Time" of last draw. Monotonically increasing timestamp */
374
+ _lastDrawTimestamp: number = -1;
375
+ private _bindingTable: ShaderBindingDebugRow[] = [];
376
+ private _pipelineInitialization?: Promise<void>;
377
+
378
+ get [Symbol.toStringTag](): string {
379
+ return 'Model';
380
+ }
381
+
382
+ toString(): string {
383
+ return `Model(${this.id})`;
384
+ }
385
+
386
+ constructor(device: Device, props: GPUVectorModelProps) {
387
+ this.constructorDrawOffsets = {firstVertex: props.firstVertex, firstIndex: props.firstIndex};
388
+ const defaultProps = (this.constructor as typeof GPUVectorModel).defaultProps;
389
+ this.constructorDrawCounts = {
390
+ vertexCount: props.vertexCount ?? (defaultProps.vertexCount || undefined),
391
+ instanceCount: props.instanceCount ?? (defaultProps.instanceCount || undefined)
392
+ };
393
+ const defaultShaderAssembler = defaultProps.shaderAssembler;
394
+ const vertexCountSet = Object.hasOwn(props, 'vertexCount');
395
+ this.props = {
396
+ ...defaultProps,
397
+ ...props,
398
+ shaderAssembler:
399
+ props.shaderAssembler ??
400
+ (isShaderAssemblerForLanguage(defaultShaderAssembler, device.info.shadingLanguage)
401
+ ? defaultShaderAssembler
402
+ : ShaderAssembler.getDefaultShaderAssembler(device.info.shadingLanguage))
403
+ };
404
+ this._vertexCountSet = vertexCountSet;
405
+ props = this.props;
406
+ this.id = props.id || uid('model');
407
+ this.device = device;
408
+
409
+ Object.assign(this.userData, props.userData);
410
+
411
+ this.vertexCount = this.props.vertexCount;
412
+ this.indexCount = this.props.indexCount;
413
+ this.firstVertex = this.props.firstVertex;
414
+ this.firstIndex = this.props.firstIndex;
415
+ this.instanceCount = this.props.instanceCount;
416
+
417
+ this.topology = this.props.topology;
418
+ this.bufferLayout = this.props.bufferLayout;
419
+ this.parameters = this.props.parameters;
420
+ // Seed attachment formats before creating the initial WebGPU pipeline. This is required for
421
+ // depth-only models whose intentional empty color target list must not fall back to the canvas
422
+ // format before the first render pass can synchronize attachment state.
423
+ this._colorAttachmentFormats = this.props.colorAttachmentFormats;
424
+ this._depthStencilAttachmentFormat = this.props.depthStencilAttachmentFormat;
425
+
426
+ this.isInstanced = props.isInstanced ?? (props.instanceCount ? true : undefined);
427
+ this.explicitBufferLayout = this.bufferLayout;
428
+ this.geometryVectorBindings = new GPUVectorBindings(device, `${this.id}-geometry`);
429
+ this.attributeVectorBindings = new GPUVectorBindings(device, `${this.id}-attributes`);
430
+ this._initializeProps(props);
431
+
432
+ const platformInfo = getPlatformInfo(device);
433
+ const resolvedPlugins = resolveShaderPlugins(this.props.plugins, platformInfo.shaderLanguage);
434
+
435
+ // Setup shader module inputs
436
+ const shaderInputModules = mergeShaderPluginModules(
437
+ this.props.modules,
438
+ resolvedPlugins.modules
439
+ );
440
+ const moduleMap = Object.fromEntries(shaderInputModules.map(module => [module.name, module]));
441
+
442
+ const shaderInputs =
443
+ props.shaderInputs ||
444
+ new ShaderInputs(moduleMap, {disableWarnings: this.props.disableWarnings});
445
+ if (props.shaderInputs && resolvedPlugins.modules.length > 0) {
446
+ shaderInputs.addModules(resolvedPlugins.modules);
447
+ }
448
+ // @ts-ignore
449
+ this.setShaderInputs(shaderInputs);
450
+
451
+ // Setup shader assembler
452
+ const modules = mergeShaderModules(this.props.modules, shaderInputs.getModules());
453
+ const defines = {...resolvedPlugins.defines, ...this.props.defines};
454
+
455
+ if (this.device.type === 'webgl') {
456
+ this.props._uniformBlockLayouts = getShaderModuleUniformBlockLayouts(modules);
457
+ }
458
+
459
+ this.props.shaderLayout =
460
+ mergeShaderModuleBindingsIntoLayout(this.props.shaderLayout, modules) || null;
461
+
462
+ const isWebGPU = this.device.type === 'webgpu';
463
+
464
+ // WebGPU
465
+ // TODO - hack to support unified WGSL shader
466
+ // TODO - this is wrong, compile a single shader
467
+ if (isWebGPU && this.props.source) {
468
+ // WGSL
469
+ const shaderAssembler = this.props.shaderAssembler;
470
+ // WGSL sources require an assembler with WGSL-specific hooks and binding state.
471
+ assert(isShaderAssemblerForLanguage(shaderAssembler, 'wgsl'));
472
+ const {
473
+ source,
474
+ getUniforms,
475
+ bindingTable,
476
+ entryPoints = {},
477
+ shaderLayout: assembledShaderLayout
478
+ } = shaderAssembler.assembleWGSLShader({
479
+ platformInfo,
480
+ ...this.props,
481
+ modules,
482
+ defines,
483
+ pluginInjections: resolvedPlugins.injections,
484
+ pluginVertexInputs: resolvedPlugins.vertexInputs,
485
+ pluginVaryings: resolvedPlugins.varyings
486
+ });
487
+ this.source = source;
488
+ this.props.vertexEntryPoint = entryPoints.vertex || this.props.vertexEntryPoint;
489
+ this.props.fragmentEntryPoint = entryPoints.fragment || this.props.fragmentEntryPoint;
490
+ // @ts-expect-error
491
+ this._getModuleUniforms = getUniforms;
492
+ this._bindingTable = bindingTable;
493
+ // Infer the layout after modules have been added so their bindings are included.
494
+ const scannedOrReflectedShaderLayout =
495
+ assembledShaderLayout ??
496
+ (device as Device & {getShaderLayout?: (source: string) => any}).getShaderLayout?.(
497
+ this.source
498
+ );
499
+ const inferredShaderLayout = normalizeShaderPluginAttributeNames(
500
+ scannedOrReflectedShaderLayout,
501
+ resolvedPlugins.vertexInputs
502
+ );
503
+ const shaderLayout = mergeInferredShaderLayout(
504
+ this.props.shaderLayout,
505
+ inferredShaderLayout,
506
+ Object.keys(resolvedPlugins.vertexInputs)
507
+ );
508
+ this.props.shaderLayout =
509
+ mergeShaderModuleBindingsIntoLayout(shaderLayout || null, modules) || null;
510
+ } else {
511
+ // GLSL
512
+ const shaderAssembler = this.props.shaderAssembler;
513
+ // GLSL shader pairs require an assembler with GLSL-specific hooks.
514
+ assert(isShaderAssemblerForLanguage(shaderAssembler, 'glsl'));
515
+ const {vs, fs, getUniforms} = shaderAssembler.assembleGLSLShaderPair({
516
+ platformInfo,
517
+ ...this.props,
518
+ modules,
519
+ defines,
520
+ pluginInjections: resolvedPlugins.injections,
521
+ pluginVertexInputs: resolvedPlugins.vertexInputs,
522
+ pluginVaryings: resolvedPlugins.varyings
523
+ });
524
+
525
+ this.vs = vs;
526
+ this.fs = fs;
527
+ // @ts-expect-error
528
+ this._getModuleUniforms = getUniforms;
529
+ this._bindingTable = [];
530
+ }
531
+
532
+ this.pipelineFactory =
533
+ props.pipelineFactory || PipelineFactory.getDefaultPipelineFactory(this.device);
534
+ this.shaderFactory = props.shaderFactory || ShaderFactory.getDefaultShaderFactory(this.device);
535
+
536
+ const asyncCompilation = PipelineFactory.getAsyncCompilation(this.device);
537
+ if (asyncCompilation) {
538
+ this._pipelineInitialization = this._initializePipelineAsync(props);
539
+ asyncCompilation.push(this._pipelineInitialization);
540
+ } else {
541
+ this.pipeline = this._updatePipeline();
542
+ this._initializePipelineResources(props);
543
+ }
544
+ }
545
+
546
+ /** Initializes subclass input policies before shader and pipeline creation. */
547
+ protected _initializeProps(props: GPUVectorModelProps): void {
548
+ if (props.geometry) this.setGeometry(props.geometry);
549
+ if (props.attributeVectors) this.setAttributeVectors(props.attributeVectors);
550
+ }
551
+
552
+ /** Whether this model manages the uniform buffer for a shader-input module. */
553
+ protected _usesManagedUniformBuffer(moduleName: string): boolean {
554
+ void moduleName;
555
+ return true;
556
+ }
557
+
558
+ private async _initializePipelineAsync(props: GPUVectorModelProps): Promise<void> {
559
+ await this._updatePipelineAsync();
560
+ this._initializePipelineResources(props);
561
+ }
562
+
563
+ /** Initializes subclass attributes before explicit constructor bindings are applied. */
564
+ protected _initializeAttributes(): void {
565
+ this.applyVectorAttributes();
566
+ if (this.indexVector) this.bindIndexVector();
567
+ }
568
+
569
+ private _initializePipelineResources(props: GPUVectorModelProps): void {
570
+ this.vertexArray = this.device.createVertexArray({
571
+ shaderLayout: this.pipeline.shaderLayout,
572
+ bufferLayout: this.pipeline.bufferLayout
573
+ });
574
+ this._initializeAttributes();
575
+ if (props.indexBuffer) this.setIndexBuffer(props.indexBuffer);
576
+ if (props.indexCount !== undefined) this.setIndexCount(props.indexCount);
577
+ if (this.constructorDrawOffsets.firstVertex !== undefined)
578
+ this.firstVertex = this.constructorDrawOffsets.firstVertex;
579
+ if (this.constructorDrawOffsets.firstIndex !== undefined)
580
+ this.firstIndex = this.constructorDrawOffsets.firstIndex;
581
+ if (props.isInstanced !== undefined) this.isInstanced = props.isInstanced;
582
+ if (this.constructorDrawCounts.instanceCount !== undefined)
583
+ this.setInstanceCount(this.constructorDrawCounts.instanceCount);
584
+ if (this.constructorDrawCounts.vertexCount !== undefined)
585
+ this.setVertexCount(this.constructorDrawCounts.vertexCount);
586
+ if (props.attributes) this.setAttributes(props.attributes);
587
+ if (props.constantAttributes) this.setConstantAttributes(props.constantAttributes);
588
+ if (props.bindings) this.setBindings(props.bindings);
589
+ if (props.transformFeedback) this.transformFeedback = props.transformFeedback;
590
+ }
591
+
592
+ destroy(): void {
593
+ if (!this._destroyed) {
594
+ // Release pipeline before we destroy the shaders used by the pipeline
595
+ if (this.pipeline) {
596
+ this.pipelineFactory.release(this.pipeline);
597
+ // Release the shaders
598
+ this.shaderFactory.release(this.pipeline.vs);
599
+ if (this.pipeline.fs && this.pipeline.fs !== this.pipeline.vs) {
600
+ this.shaderFactory.release(this.pipeline.fs);
601
+ }
602
+ }
603
+ this.geometryVectorBindings.destroy();
604
+ this.attributeVectorBindings.destroy();
605
+ this._uniformStore.destroy();
606
+ this._destroyed = true;
607
+ }
608
+ }
609
+
610
+ // Draw call
611
+
612
+ /** Query redraw status. Clears the status. */
613
+ needsRedraw(): false | string {
614
+ // Catch any writes to already bound resources
615
+ if (this._getBindingsUpdateTimestamp() > this._lastDrawTimestamp) {
616
+ this.setNeedsRedraw('contents of bound textures or buffers updated');
617
+ }
618
+ const needsRedraw = this._needsRedraw;
619
+ this._needsRedraw = false;
620
+ return needsRedraw;
621
+ }
622
+
623
+ /** Mark the model as needing a redraw */
624
+ setNeedsRedraw(reason: string): void {
625
+ this._needsRedraw ||= reason;
626
+ }
627
+
628
+ /** Returns WGSL binding debug rows for the assembled shader. Returns an empty array for GLSL models. */
629
+ getBindingDebugTable(): readonly ShaderBindingDebugRow[] {
630
+ return this._bindingTable;
631
+ }
632
+
633
+ /**
634
+ * Updates uniforms and pipeline state before opening a render pass.
635
+ *
636
+ * @param commandEncoder - Encoder that should own any GPU uploads emitted
637
+ * during draw preparation.
638
+ */
639
+ predraw(commandEncoder: CommandEncoder): void {
640
+ // Update uniform buffers if needed
641
+ this._syncDynamicBuffers();
642
+ this.updateShaderInputs(commandEncoder);
643
+ // Check if the pipeline is invalidated
644
+ this.pipeline = this._updatePipeline();
645
+ }
646
+
647
+ /**
648
+ * Issue one draw call.
649
+ * @param renderPass - render pass to draw into
650
+ * @returns `true` if the draw call was executed, `false` if resources were not ready.
651
+ */
652
+ draw(renderPass: RenderPass): boolean {
653
+ if (this.indexVector?.length === 0) {
654
+ this._lastDrawTimestamp = this.device.timestamp;
655
+ this._needsRedraw = false;
656
+ return true;
657
+ }
658
+ if (
659
+ !this.drawingVectorBatches &&
660
+ (this.geometryVectorBindings.batchCount !== 1 ||
661
+ this.attributeVectorBindings.batchCount !== 1)
662
+ ) {
663
+ return this.drawVectorGroups(renderPass);
664
+ }
665
+ if (this._drawBlockedReason && !this._pipelineNeedsUpdate) {
666
+ log.info(LOG_DRAW_PRIORITY, `>>> DRAWING ABORTED ${this.id}: ${this._drawBlockedReason}`)();
667
+ return false;
668
+ }
669
+
670
+ const loadingBinding = this._areBindingsLoading();
671
+ if (loadingBinding) {
672
+ log.info(LOG_DRAW_PRIORITY, `>>> DRAWING ABORTED ${this.id}: ${loadingBinding} not loaded`)();
673
+ return false;
674
+ }
675
+
676
+ this._syncAttachmentFormats(renderPass);
677
+
678
+ try {
679
+ renderPass.pushDebugGroup(`${this}.predraw(${renderPass})`);
680
+ if (this.device.type === 'webgpu') {
681
+ // WebGPU uploads cannot be encoded once the render pass is already open.
682
+ // Keep the implicit draw() path working for existing callers by falling
683
+ // back to immediate writes here; callers that need upload ordering
684
+ // across multiple draws/viewports must call predraw(commandEncoder)
685
+ // before beginRenderPass().
686
+ this.updateShaderInputs();
687
+ this._syncDynamicBuffers();
688
+ this.pipeline = this._updatePipeline();
689
+ } else {
690
+ this.predraw(this.device.commandEncoder);
691
+ }
692
+ } finally {
693
+ renderPass.popDebugGroup();
694
+ }
695
+
696
+ let drawSuccess: boolean;
697
+ let pipelineErrored = this.pipeline.isErrored;
698
+ try {
699
+ renderPass.pushDebugGroup(`${this}.draw(${renderPass})`);
700
+ this._logDrawCallStart();
701
+
702
+ // Update the pipeline if invalidated
703
+ // TODO - inside RenderPass is likely the worst place to do this from performance perspective.
704
+ // Application can call GPUVectorModel.predraw() to avoid this.
705
+ this.pipeline = this._updatePipeline();
706
+ pipelineErrored = this.pipeline.isErrored;
707
+
708
+ if (pipelineErrored) {
709
+ log.info(
710
+ LOG_DRAW_PRIORITY,
711
+ `>>> DRAWING ABORTED ${this.id}: ${PIPELINE_INITIALIZATION_FAILED}`
712
+ )();
713
+ drawSuccess = false;
714
+ } else {
715
+ const drawValidationError = this.vertexArray.getDrawValidationError();
716
+ if (drawValidationError) {
717
+ log.info(LOG_DRAW_PRIORITY, `>>> DRAWING ABORTED ${this.id}: ${drawValidationError}`)();
718
+ this._drawBlockedReason = drawValidationError;
719
+ drawSuccess = false;
720
+ } else {
721
+ const shaderLayout = this._getCurrentShaderLayout();
722
+ const syncBindings = this._getBindings(shaderLayout);
723
+ const syncBindGroups = this._getBindGroups(shaderLayout, syncBindings);
724
+
725
+ const {indexBuffer} = this.vertexArray;
726
+ const indexCount = indexBuffer
727
+ ? (this.indexCount ??
728
+ (this._vertexCountSet
729
+ ? this.vertexCount
730
+ : indexBuffer.byteLength / (indexBuffer.indexType === 'uint32' ? 4 : 2)))
731
+ : undefined;
732
+
733
+ renderPass.setPipeline(this.pipeline);
734
+ renderPass.setBindings(syncBindGroups, {
735
+ _bindGroupCacheKeys: this._getBindGroupCacheKeys()
736
+ });
737
+ renderPass.setVertexArray(this.vertexArray);
738
+ const hasNoInstances = this.isInstanced === true && this.instanceCount === 0;
739
+ drawSuccess = hasNoInstances
740
+ ? true
741
+ : renderPass.draw({
742
+ isInstanced: this.isInstanced,
743
+ vertexCount: this.vertexCount,
744
+ instanceCount: this.isInstanced ? this.instanceCount : undefined,
745
+ indexCount,
746
+ firstVertex: this.firstVertex,
747
+ firstIndex: this.firstIndex,
748
+ transformFeedback: this.transformFeedback || undefined,
749
+ uniforms: this.props.uniforms,
750
+ // WebGL shares underlying cached programs even for models that have different
751
+ // parameters and topology, so those compatibility overrides remain per draw.
752
+ parameters: this.parameters,
753
+ topology: this.topology
754
+ });
755
+ }
756
+ }
757
+ } finally {
758
+ renderPass.popDebugGroup();
759
+ this._logDrawCallEnd();
760
+ }
761
+ this._logFramebuffer(renderPass);
762
+
763
+ // Update needsRedraw flag
764
+ if (drawSuccess) {
765
+ this._lastDrawTimestamp = this.device.timestamp;
766
+ this._needsRedraw = false;
767
+ } else if (pipelineErrored) {
768
+ this._needsRedraw = PIPELINE_INITIALIZATION_FAILED;
769
+ this._drawBlockedReason = PIPELINE_INITIALIZATION_FAILED;
770
+ } else if (this._drawBlockedReason) {
771
+ this._needsRedraw = this._drawBlockedReason;
772
+ } else {
773
+ this._needsRedraw = 'waiting for resource initialization';
774
+ }
775
+ return drawSuccess;
776
+ }
777
+
778
+ /** Binds a GPU-only mesh. CPU geometry adaptation belongs in Model. */
779
+ setGeometry(geometry: GPUVectorGeometry | null): void {
780
+ if (geometry) this.setTopology(geometry.topology);
781
+ this.setGeometryVectors(geometry?.attributes ?? {}, geometry?.bufferLayout);
782
+ this.setIndexVector(geometry?.indices ?? null);
783
+ if (geometry?.vertexCount !== undefined) this.setVertexCount(geometry.vertexCount);
784
+ }
785
+
786
+ /** Replaces per-vertex mesh vectors while preserving supplemental attributes. */
787
+ setGeometryVectors(vectors: GPUVectorModelAttributes, bufferLayouts?: BufferLayout[]): void {
788
+ bufferLayouts ??=
789
+ this.getExplicitVectorLayouts(vectors) ??
790
+ this.getExplicitVectorLayouts(vectors, this.geometryVectorBindings.sourceLayouts);
791
+ validateGPUVectorBatchStructure(vectors);
792
+ if (!this.isInstanced || this.attributeVectorBindings.vertexCount !== undefined)
793
+ validateGPUVectorBatchStructure([
794
+ ...Object.values(vectors),
795
+ ...Object.values(this.attributeVectorBindings.inputs)
796
+ ]);
797
+ this.geometryVectorBindings.setInputs(vectors, bufferLayouts, 'vertex');
798
+ this.claimVectorLayouts(this.geometryVectorBindings);
799
+ this.syncVectorBindings();
800
+ const rowCount = this.geometryVectorBindings.rowCount;
801
+ assert(
802
+ rowCount === undefined ||
803
+ this.attributeVectorBindings.vertexCount === undefined ||
804
+ rowCount === this.attributeVectorBindings.vertexCount
805
+ );
806
+ this.setVertexCount(rowCount ?? this.attributeVectorBindings.vertexCount ?? 0);
807
+ }
808
+
809
+ /** Replaces supplemental vectors; instanced models default these inputs to instance step mode. */
810
+ setAttributeVectors(vectors: GPUVectorModelAttributes, bufferLayouts?: BufferLayout[]): void {
811
+ bufferLayouts ??=
812
+ this.getExplicitVectorLayouts(vectors) ??
813
+ this.getExplicitVectorLayouts(vectors, this.attributeVectorBindings.sourceLayouts);
814
+ if (
815
+ this.isInstanced === undefined &&
816
+ (bufferLayouts?.some(layout => layout.stepMode === 'instance') ||
817
+ Object.values(vectors).some(
818
+ vector => vector && 'data' in vector && vector.bufferLayout?.stepMode === 'instance'
819
+ ))
820
+ )
821
+ this.isInstanced = true;
822
+ const usesVertexRows =
823
+ !this.isInstanced ||
824
+ Object.entries(vectors).some(
825
+ ([name, vector]) =>
826
+ vector &&
827
+ 'data' in vector &&
828
+ (bufferLayouts?.find(
829
+ layout =>
830
+ layout.name === name ||
831
+ layout.attributes?.some(attribute => attribute.attribute === name)
832
+ )?.stepMode ?? vector.bufferLayout?.stepMode) === 'vertex'
833
+ );
834
+ if (usesVertexRows)
835
+ validateGPUVectorBatchStructure([
836
+ ...Object.values(this.geometryVectorBindings.inputs),
837
+ ...Object.values(vectors)
838
+ ]);
839
+ this.attributeVectorBindings.setInputs(
840
+ vectors,
841
+ bufferLayouts,
842
+ this.isInstanced ? 'instance' : 'vertex'
843
+ );
844
+ this.claimVectorLayouts(this.attributeVectorBindings);
845
+ this.syncVectorBindings();
846
+ if (this.attributeVectorBindings.instanceCount !== undefined)
847
+ this.setInstanceCount(this.attributeVectorBindings.instanceCount);
848
+ const vertexCount = this.attributeVectorBindings.vertexCount;
849
+ if (vertexCount !== undefined) {
850
+ const geometryRowCount = this.geometryVectorBindings.rowCount;
851
+ // Supplemental vertex columns describe the same rows as the geometry columns.
852
+ assert(geometryRowCount === undefined || geometryRowCount === vertexCount);
853
+ if (geometryRowCount === undefined) this.setVertexCount(vertexCount);
854
+ }
855
+ }
856
+
857
+ /** Binds typed columns using caller-resolved layouts, including packed groups. */
858
+ setGPUAttributes(vectors: GPUVectorModelAttributes, bufferLayouts: BufferLayout[]): void {
859
+ this.setAttributeVectors(vectors, bufferLayouts);
860
+ }
861
+
862
+ /** Replaces the borrowed contiguous uint16/uint32 index vector. */
863
+ setIndexVector(vector: GPUVectorModelInput | null): void {
864
+ if (vector) {
865
+ // Indexed draws consume one contiguous, tightly packed index stream.
866
+ assert(vector.format === 'uint8' || vector.format === 'uint16' || vector.format === 'uint32');
867
+ assert(vector.data.length <= 1);
868
+ assert(
869
+ vector.byteStride === (vector.format === 'uint32' ? 4 : vector.format === 'uint16' ? 2 : 1)
870
+ );
871
+ }
872
+ this.indexVector = vector;
873
+ if (this.vertexArray) this.bindIndexVector();
874
+ }
875
+
876
+ private bindIndexVector(): void {
877
+ const vector = this.indexVector;
878
+ const chunk = vector?.data[0];
879
+ if (chunk && this.indexVector) {
880
+ const buffer = chunk.buffer instanceof DynamicBuffer ? chunk.buffer.buffer : chunk.buffer;
881
+ // Core index-buffer metadata must agree with the vector format and aligned byte offset.
882
+ assert(
883
+ buffer.indexType === this.indexVector.format &&
884
+ chunk.byteOffset % this.indexVector.byteStride === 0
885
+ );
886
+ }
887
+ this.indexVector = null;
888
+ this.setIndexBuffer(chunk?.buffer ?? null);
889
+ this.indexVector = vector;
890
+ this.indexCount = vector?.length;
891
+ this.setDrawOffsets({
892
+ firstVertex: chunk?.byteOffset ?? 0,
893
+ firstIndex: chunk ? chunk.byteOffset / this.indexVector!.byteStride : 0
894
+ });
895
+ }
896
+
897
+ private claimVectorLayouts(group: GPUVectorBindings): void {
898
+ this.explicitBufferLayout = this.explicitBufferLayout.filter(
899
+ layout =>
900
+ !group.claimedNames.has(layout.name) &&
901
+ !layout.attributes?.some(attribute => group.claimedNames.has(attribute.attribute))
902
+ );
903
+ }
904
+
905
+ private getExplicitVectorLayouts(
906
+ vectors: GPUVectorModelAttributes,
907
+ sourceLayouts: BufferLayout[] = this.explicitBufferLayout
908
+ ): BufferLayout[] | undefined {
909
+ const names = new Set(Object.keys(vectors));
910
+ const layouts = sourceLayouts.filter(
911
+ layout =>
912
+ names.has(layout.name) ||
913
+ layout.attributes?.some(attribute => names.has(attribute.attribute))
914
+ );
915
+ return layouts.length ? layouts : undefined;
916
+ }
917
+
918
+ private getVectorBufferLayout(): BufferLayout[] {
919
+ const groups = [this.geometryVectorBindings, this.attributeVectorBindings];
920
+ const explicitLayouts = this.explicitBufferLayout.filter(
921
+ layout =>
922
+ !groups.some(
923
+ group =>
924
+ group.claimedNames.has(layout.name) ||
925
+ layout.attributes?.some(attribute => group.claimedNames.has(attribute.attribute))
926
+ )
927
+ );
928
+ return [
929
+ ...explicitLayouts,
930
+ ...this.geometryVectorBindings.layouts,
931
+ ...this.attributeVectorBindings.layouts
932
+ ];
933
+ }
934
+
935
+ private syncVectorBindings(): void {
936
+ const layouts = this.getVectorBufferLayout();
937
+ if (this.vertexArray) {
938
+ this.applyBufferLayout(layouts);
939
+ this.applyVectorAttributes();
940
+ } else this.bufferLayout = layouts;
941
+ }
942
+
943
+ private applyVectorAttributes(): void {
944
+ const activeNames = new Set(this.bufferLayout.map(layout => layout.name));
945
+ for (const name of Object.keys(this.currentAttributes)) {
946
+ if (!activeNames.has(name)) delete this.currentAttributes[name];
947
+ }
948
+ this.setAttributes(
949
+ {
950
+ ...this.currentAttributes,
951
+ ...this.geometryVectorBindings.buffers,
952
+ ...this.attributeVectorBindings.buffers
953
+ },
954
+ {
955
+ byteOffsets: {
956
+ ...this.currentAttributeByteOffsets,
957
+ ...this.geometryVectorBindings.byteOffsets,
958
+ ...this.attributeVectorBindings.byteOffsets
959
+ },
960
+ disableWarnings: true
961
+ }
962
+ );
963
+ if (this.device.type === 'webgl')
964
+ this.setConstantAttributes({
965
+ ...this.geometryVectorBindings.constants,
966
+ ...this.attributeVectorBindings.constants
967
+ });
968
+ }
969
+
970
+ /** Binds contiguous borrowed vectors; use drawBatches() for multi-chunk inputs. */
971
+ setGPUVectors(vectors: GPUVectorModelInputs, options?: {count?: GPUVectorModelCount}): void {
972
+ const batches = getGPUVectorModelBatches(this.id, vectors);
973
+ // Direct binding requires one physical chunk per vector; never concatenate implicitly.
974
+ assert(batches.length <= 1);
975
+ validateGPUVectorModelLayouts(this.id, vectors, this.bufferLayout);
976
+ if (batches[0]) this.setGPUData(batches[0].data);
977
+ this.setBatchDrawCount(batches[0]?.rowCount ?? 0, options?.count);
978
+ }
979
+
980
+ private drawVectorGroups(renderPass: RenderPass): boolean {
981
+ const drawingVectorBatches = this.drawingVectorBatches;
982
+ const vertexCountSet = this._vertexCountSet;
983
+ this.drawingVectorBatches = true;
984
+ try {
985
+ const success = drawGPUVectorGroups(
986
+ this,
987
+ this.geometryVectorBindings,
988
+ this.attributeVectorBindings,
989
+ () => this.syncVectorBindings(),
990
+ () => GPUVectorModel.prototype.draw.call(this, renderPass)
991
+ );
992
+ if (success) {
993
+ this._lastDrawTimestamp = this.device.timestamp;
994
+ this._needsRedraw = false;
995
+ }
996
+ return success;
997
+ } finally {
998
+ this._vertexCountSet = vertexCountSet;
999
+ this.drawingVectorBatches = drawingVectorBatches;
1000
+ }
1001
+ }
1002
+
1003
+ /** Draws each aligned physical chunk without retaining or taking ownership of input vectors. */
1004
+ drawBatches<Inputs extends GPUVectorModelInputs = GPUVectorModelInputs>(
1005
+ renderPass: RenderPass,
1006
+ {vectors, onBatch}: GPUVectorModelDrawBatchesOptions<Inputs>
1007
+ ): boolean {
1008
+ const batches = getGPUVectorModelBatches(this.id, vectors);
1009
+ validateGPUVectorModelLayouts(this.id, vectors, this.bufferLayout);
1010
+ for (const name of Object.keys(vectors)) {
1011
+ // Transient batches replace existing attributes so every binding can be restored afterward.
1012
+ assert(!vectors[name] || this.currentAttributes[name]);
1013
+ }
1014
+ const previousAttributes = {...this.currentAttributes};
1015
+ const previousAttributeByteOffsets = {...this.currentAttributeByteOffsets};
1016
+ const previousBindings = {...this.bindings};
1017
+ const previousInstanceCount = this.instanceCount;
1018
+ const previousVertexCount = this.vertexCount;
1019
+ const previousIsInstanced = this.isInstanced;
1020
+ const previousVertexCountSet = this._vertexCountSet;
1021
+ const drawingVectorBatches = this.drawingVectorBatches;
1022
+ this.drawingVectorBatches = true;
1023
+ let drawSuccess = true;
1024
+ try {
1025
+ for (const batch of batches) {
1026
+ this.setGPUData(batch.data);
1027
+ this.setBatchDrawCount(batch.rowCount);
1028
+ onBatch?.(batch);
1029
+ drawSuccess = GPUVectorModel.prototype.draw.call(this, renderPass) && drawSuccess;
1030
+ }
1031
+ } finally {
1032
+ this.setAttributes(previousAttributes, {byteOffsets: previousAttributeByteOffsets});
1033
+ for (const name of Object.keys(this.bindings)) {
1034
+ if (!(name in previousBindings)) delete this.bindings[name];
1035
+ }
1036
+ this.setBindings(previousBindings);
1037
+ this.setInstanceCount(previousInstanceCount);
1038
+ this.setVertexCount(previousVertexCount);
1039
+ this.isInstanced = previousIsInstanced;
1040
+ this._vertexCountSet = previousVertexCountSet;
1041
+ this.drawingVectorBatches = drawingVectorBatches;
1042
+ }
1043
+ return drawSuccess;
1044
+ }
1045
+
1046
+ private setGPUData(data: Record<string, GPUVectorModelData>): void {
1047
+ this.setAttributes(
1048
+ Object.fromEntries(Object.entries(data).map(([name, chunk]) => [name, chunk.buffer])),
1049
+ {
1050
+ byteOffsets: Object.fromEntries(
1051
+ Object.entries(data).map(([name, chunk]) => {
1052
+ const layout = this.bufferLayout.find(layout => layout.name === name);
1053
+ const byteOffset = chunk.byteOffset - (layout?.attributes?.[0]?.byteOffset ?? 0);
1054
+ // The layout offset and binding offset together address the start of the chunk.
1055
+ assert(byteOffset >= 0);
1056
+ return [name, byteOffset];
1057
+ })
1058
+ )
1059
+ }
1060
+ );
1061
+ }
1062
+
1063
+ private setBatchDrawCount(
1064
+ rowCount: number,
1065
+ count: GPUVectorModelCount = this.props.gpuVectorCount
1066
+ ): void {
1067
+ if (count === 'instance') {
1068
+ this.setInstanceCount(rowCount);
1069
+ } else if (count === 'vertex') {
1070
+ this.setVertexCount(rowCount);
1071
+ }
1072
+ }
1073
+
1074
+ // Update fixed fields (can trigger pipeline rebuild)
1075
+
1076
+ /**
1077
+ * Updates the primitive topology ('triangle-list', 'triangle-strip' etc).
1078
+ * @note Triggers a pipeline rebuild / pipeline cache fetch on WebGPU
1079
+ */
1080
+ setTopology(topology: PrimitiveTopology): void {
1081
+ if (topology !== this.topology) {
1082
+ this.topology = topology;
1083
+ this._setPipelineNeedsUpdate('topology');
1084
+ }
1085
+ }
1086
+
1087
+ /**
1088
+ * Updates the buffer layout.
1089
+ * @note Triggers a pipeline rebuild / pipeline cache fetch
1090
+ */
1091
+ setBufferLayout(bufferLayout: BufferLayout[]): void {
1092
+ this.explicitBufferLayout = bufferLayout;
1093
+ const geometry = this.geometryVectorBindings;
1094
+ const attributes = this.attributeVectorBindings;
1095
+ const geometryLayouts =
1096
+ this.getExplicitVectorLayouts(geometry.inputs) ?? geometry.sourceLayouts;
1097
+ const attributeLayouts =
1098
+ this.getExplicitVectorLayouts(attributes.inputs) ?? attributes.sourceLayouts;
1099
+ geometry.setInputs(geometry.inputs, geometryLayouts, 'vertex');
1100
+ attributes.setInputs(
1101
+ attributes.inputs,
1102
+ attributeLayouts,
1103
+ this.isInstanced ? 'instance' : 'vertex'
1104
+ );
1105
+ if (!this.isInstanced || attributes.vertexCount !== undefined)
1106
+ validateGPUVectorBatchStructure([
1107
+ ...Object.values(geometry.inputs),
1108
+ ...Object.values(attributes.inputs)
1109
+ ]);
1110
+ this.claimVectorLayouts(geometry);
1111
+ this.claimVectorLayouts(attributes);
1112
+ this.applyBufferLayout(this.getVectorBufferLayout());
1113
+ }
1114
+
1115
+ private applyBufferLayout(nextBufferLayout: BufferLayout[]): void {
1116
+ nextBufferLayout = sortedBufferLayoutByShaderSourceLocations(
1117
+ this.pipeline.shaderLayout,
1118
+ nextBufferLayout
1119
+ );
1120
+ if (deepEqual(nextBufferLayout, this.bufferLayout, -1)) {
1121
+ return;
1122
+ }
1123
+
1124
+ this.bufferLayout = nextBufferLayout;
1125
+ this._setPipelineNeedsUpdate('bufferLayout');
1126
+
1127
+ // Recreate the pipeline
1128
+ this.pipeline = this._updatePipeline();
1129
+
1130
+ // vertex array needs to be updated if we update buffer layout,
1131
+ // but not if we update parameters
1132
+ this.vertexArray = this.device.createVertexArray({
1133
+ shaderLayout: this.pipeline.shaderLayout,
1134
+ bufferLayout: this.pipeline.bufferLayout
1135
+ });
1136
+ this._dynamicAttributeBufferSources = {};
1137
+ this.applyVectorAttributes();
1138
+ if (this.indexBuffer) this.vertexArray.setIndexBuffer(this.indexBuffer);
1139
+ }
1140
+
1141
+ /**
1142
+ * Set GPU parameters.
1143
+ * @note Can trigger a pipeline rebuild / pipeline cache fetch on WebGPU.
1144
+ * On WebGL, parameters are applied at each draw call, so the pipeline is kept.
1145
+ * @param parameters
1146
+ */
1147
+ setParameters(parameters: RenderPipelineParameters) {
1148
+ if (!deepEqual(parameters, this.parameters, 2)) {
1149
+ this.parameters = parameters;
1150
+ if (this.device.type === 'webgl') {
1151
+ this.setNeedsRedraw('parameters');
1152
+ } else {
1153
+ this._setPipelineNeedsUpdate('parameters');
1154
+ }
1155
+ }
1156
+ }
1157
+
1158
+ // Update dynamic fields
1159
+
1160
+ /**
1161
+ * Updates the instance count (used in draw calls)
1162
+ * @note Any attributes with stepMode=instance need to be at least this big
1163
+ */
1164
+ setInstanceCount(instanceCount: number): void {
1165
+ this.instanceCount = instanceCount;
1166
+ // luma.gl examples don't set props.isInstanced and rely on auto-detection
1167
+ // but deck.gl sets instanceCount even for models that are not instanced.
1168
+ if (this.isInstanced === undefined && instanceCount > 0) {
1169
+ this.isInstanced = true;
1170
+ }
1171
+ this.setNeedsRedraw('instanceCount');
1172
+ }
1173
+
1174
+ /**
1175
+ * Updates the vertex count (used in draw calls)
1176
+ * @note Any attributes with stepMode=vertex need to be at least this big
1177
+ */
1178
+ setVertexCount(vertexCount: number): void {
1179
+ this.vertexCount = vertexCount;
1180
+ this._vertexCountSet = true;
1181
+ this.setNeedsRedraw('vertexCount');
1182
+ }
1183
+
1184
+ /** Updates the indexed draw count override. */
1185
+ setIndexCount(indexCount: number | undefined): void {
1186
+ this.indexCount = indexCount;
1187
+ this.setNeedsRedraw('indexCount');
1188
+ }
1189
+
1190
+ /** Updates the first indexed/non-indexed draw offsets. */
1191
+ setDrawOffsets({firstVertex, firstIndex}: {firstVertex: number; firstIndex: number}): void {
1192
+ this.firstVertex = firstVertex;
1193
+ this.firstIndex = firstIndex;
1194
+ this.setNeedsRedraw('drawOffsets');
1195
+ }
1196
+
1197
+ /** Set the shader inputs */
1198
+ setShaderInputs(shaderInputs: ShaderInputs): void {
1199
+ this.shaderInputs = shaderInputs;
1200
+ this._uniformStore = new UniformStore(this.device, this.shaderInputs.modules);
1201
+ // Create uniform buffer bindings for all modules that actually have uniforms
1202
+ for (const [moduleName, module] of Object.entries(this.shaderInputs.modules)) {
1203
+ if (shaderModuleHasUniforms(module) && this._usesManagedUniformBuffer(moduleName)) {
1204
+ const uniformBuffer = this._uniformStore.getManagedUniformBuffer(moduleName);
1205
+ this.bindings[`${moduleName}Uniforms`] = uniformBuffer;
1206
+ }
1207
+ }
1208
+ this.setNeedsRedraw('shaderInputs');
1209
+ }
1210
+
1211
+ /** Update uniform buffers from the model's shader inputs */
1212
+ /**
1213
+ * Flushes current shader-input values into managed uniform buffers and
1214
+ * resource bindings.
1215
+ *
1216
+ * @param commandEncoder - Optional encoder used to order uniform uploads with
1217
+ * subsequent draw commands.
1218
+ */
1219
+ updateShaderInputs(commandEncoder?: CommandEncoder): void {
1220
+ this._uniformStore.setUniforms(this.shaderInputs.getUniformValues(), commandEncoder);
1221
+ this.setBindings(this._getShaderInputBindings());
1222
+ // TODO - this is already tracked through buffer/texture update times?
1223
+ this.setNeedsRedraw('shaderInputs');
1224
+ }
1225
+
1226
+ /** Resolves resource bindings supplied by shader inputs. */
1227
+ protected _getShaderInputBindings(): Record<string, ModelBinding> {
1228
+ return this.shaderInputs.getBindingValues();
1229
+ }
1230
+
1231
+ /**
1232
+ * Sets bindings (textures, samplers, uniform buffers)
1233
+ */
1234
+ setBindings(bindings: Record<string, ModelBinding>): void {
1235
+ Object.assign(this.bindings, bindings);
1236
+ this.setNeedsRedraw('bindings');
1237
+ }
1238
+
1239
+ /**
1240
+ * Updates optional transform feedback. WebGL only.
1241
+ */
1242
+ setTransformFeedback(transformFeedback: TransformFeedback | null): void {
1243
+ this.transformFeedback = transformFeedback;
1244
+ this.setNeedsRedraw('transformFeedback');
1245
+ }
1246
+
1247
+ /**
1248
+ * Sets the index buffer
1249
+ * @todo - how to unset it if we change geometry?
1250
+ */
1251
+ setIndexBuffer(indexBuffer: ModelBuffer | null): void {
1252
+ if (this.indexVector) {
1253
+ this.indexCount = undefined;
1254
+ this.firstVertex = 0;
1255
+ this.firstIndex = 0;
1256
+ }
1257
+ this.indexVector = null;
1258
+ const resolvedIndexBuffer =
1259
+ indexBuffer instanceof DynamicBuffer ? indexBuffer.buffer : indexBuffer;
1260
+ this.indexBuffer = resolvedIndexBuffer;
1261
+ this._dynamicIndexBufferSource =
1262
+ indexBuffer instanceof DynamicBuffer
1263
+ ? {source: indexBuffer, generation: indexBuffer.generation}
1264
+ : null;
1265
+ this.vertexArray.setIndexBuffer(resolvedIndexBuffer);
1266
+ this.setNeedsRedraw('indexBuffer');
1267
+ }
1268
+
1269
+ /**
1270
+ * Sets attributes (buffers)
1271
+ * @param options.byteOffsets Optional byte offsets, keyed by buffer name, where each buffer's
1272
+ * vertex data starts. Buffers without an entry are bound at offset 0.
1273
+ * @note Overrides any attributes previously set with the same name
1274
+ */
1275
+ setAttributes(
1276
+ buffers: Record<string, ModelBuffer>,
1277
+ options?: {disableWarnings?: boolean; byteOffsets?: Record<string, number>}
1278
+ ): void {
1279
+ Object.assign(this.currentAttributes, buffers);
1280
+ for (const name of Object.keys(buffers)) {
1281
+ this.currentAttributeByteOffsets[name] = options?.byteOffsets?.[name] ?? 0;
1282
+ }
1283
+ this._drawBlockedReason = false;
1284
+ const disableWarnings = options?.disableWarnings ?? this.props.disableWarnings;
1285
+ if (buffers['indices']) {
1286
+ log.warn(
1287
+ `Model:${this.id} setAttributes() - indexBuffer should be set using setIndexBuffer()`
1288
+ )();
1289
+ }
1290
+
1291
+ // ensure bufferLayout order matches source layout so we bind
1292
+ // the correct buffers to the correct indices in webgpu.
1293
+ this.bufferLayout = sortedBufferLayoutByShaderSourceLocations(
1294
+ this.pipeline.shaderLayout,
1295
+ this.bufferLayout
1296
+ );
1297
+ const bufferLayoutHelper = new BufferLayoutHelper(this.bufferLayout);
1298
+
1299
+ // Check if all buffers have a layout
1300
+ for (const [bufferName, buffer] of Object.entries(buffers)) {
1301
+ const resolvedBuffer = buffer instanceof DynamicBuffer ? buffer.buffer : buffer;
1302
+ const bufferLayout = bufferLayoutHelper.getBufferLayout(bufferName);
1303
+ if (!bufferLayout) {
1304
+ if (!disableWarnings) {
1305
+ log.warn(`Model(${this.id}): Missing layout for buffer "${bufferName}".`)();
1306
+ }
1307
+ continue; // eslint-disable-line no-continue
1308
+ }
1309
+
1310
+ // In WebGL, for an interleaved attribute we may need to set multiple attributes
1311
+ // but in WebGPU, we set it according to the buffer's position in the vertexArray
1312
+ const attributeNames = bufferLayoutHelper.getAttributeNamesForBuffer(bufferLayout);
1313
+ let set = false;
1314
+ for (const attributeName of attributeNames) {
1315
+ const attributeInfo = this._attributeInfos[attributeName];
1316
+ if (attributeInfo) {
1317
+ const bufferSlot =
1318
+ this.device.type === 'webgpu'
1319
+ ? this.vertexArray.getBufferSlot(attributeInfo.bufferName)
1320
+ : attributeInfo.location;
1321
+ if (bufferSlot === null) {
1322
+ if (!disableWarnings) {
1323
+ log.warn(
1324
+ `Model(${this.id}): Missing vertex array slot for buffer "${attributeInfo.bufferName}".`
1325
+ )();
1326
+ }
1327
+ continue; // eslint-disable-line no-continue
1328
+ }
1329
+
1330
+ const byteOffset = options?.byteOffsets?.[bufferName] ?? 0;
1331
+ this.vertexArray.setBuffer(bufferSlot, resolvedBuffer, byteOffset);
1332
+ if (buffer instanceof DynamicBuffer) {
1333
+ this._dynamicAttributeBufferSources[bufferSlot] = {
1334
+ source: buffer,
1335
+ generation: buffer.generation,
1336
+ byteOffset
1337
+ };
1338
+ } else {
1339
+ delete this._dynamicAttributeBufferSources[bufferSlot];
1340
+ }
1341
+ set = true;
1342
+ }
1343
+ }
1344
+ if (!set && !disableWarnings) {
1345
+ log.warn(
1346
+ `Model(${this.id}): Ignoring buffer "${resolvedBuffer.id}" for unknown attribute "${bufferName}"`
1347
+ )();
1348
+ }
1349
+ }
1350
+ this.setNeedsRedraw('attributes');
1351
+ }
1352
+
1353
+ /**
1354
+ * Sets constant attributes
1355
+ * @note Overrides any attributes previously set with the same name
1356
+ * Constant attributes are only supported in WebGL, not in WebGPU
1357
+ * Any attribute that is disabled in the current vertex array object
1358
+ * is read from the context's global constant value for that attribute location.
1359
+ * @param constantAttributes
1360
+ */
1361
+ setConstantAttributes(
1362
+ attributes: Record<string, TypedArray>,
1363
+ options?: {disableWarnings?: boolean}
1364
+ ): void {
1365
+ for (const [attributeName, value] of Object.entries(attributes)) {
1366
+ const attributeInfo = this._attributeInfos[attributeName];
1367
+ if (attributeInfo) {
1368
+ this.vertexArray.setConstantWebGL(attributeInfo.location, value);
1369
+ } else if (!(options?.disableWarnings ?? this.props.disableWarnings)) {
1370
+ log.warn(
1371
+ `Model "${this.id}: Ignoring constant supplied for unknown attribute "${attributeName}"`
1372
+ )();
1373
+ }
1374
+ }
1375
+ this.setNeedsRedraw('constants');
1376
+ }
1377
+
1378
+ // INTERNAL METHODS
1379
+
1380
+ /** Check that bindings are loaded. Returns id of first binding that is still loading. */
1381
+ _areBindingsLoading(): string | false {
1382
+ for (const binding of Object.values(this.bindings)) {
1383
+ if (isTextureBindingSource(binding) && !binding.isReady) {
1384
+ return binding.id;
1385
+ }
1386
+ }
1387
+ return false;
1388
+ }
1389
+
1390
+ /**
1391
+ * Resolves ready model bindings for the current shader layout.
1392
+ * @param shaderLayout Reflected bindings used to select copied or external texture resolution.
1393
+ */
1394
+ _getBindings(
1395
+ shaderLayout: AnyShaderLayout = this._getCurrentShaderLayout()
1396
+ ): Record<string, Binding> {
1397
+ const validBindings: Record<string, Binding> = {};
1398
+
1399
+ for (const [name, binding] of Object.entries(this.bindings)) {
1400
+ const resolvedBinding = resolveModelBinding(name, binding, shaderLayout);
1401
+ if (resolvedBinding) {
1402
+ validBindings[name] = resolvedBinding;
1403
+ }
1404
+ }
1405
+
1406
+ return validBindings;
1407
+ }
1408
+
1409
+ /**
1410
+ * Groups resolved resource bindings for the current shader layout.
1411
+ * @param shaderLayout Reflected bindings used to group logical binding names.
1412
+ * @param bindings GPUVectorModel bindings already resolved for this draw preparation.
1413
+ */
1414
+ _getBindGroups(
1415
+ shaderLayout: AnyShaderLayout = this._getCurrentShaderLayout(),
1416
+ bindings: Record<string, Binding> = this._getBindings(shaderLayout)
1417
+ ): BindingsByGroup {
1418
+ return shaderLayout.bindings.length
1419
+ ? normalizeBindingsByGroup(shaderLayout, bindings)
1420
+ : {0: bindings};
1421
+ }
1422
+
1423
+ _getBindGroupCacheKeys(): Partial<Record<number, object>> {
1424
+ return {};
1425
+ }
1426
+
1427
+ /** Get the timestamp of the latest updated bound GPU memory resource (buffer/texture). */
1428
+ _getBindingsUpdateTimestamp(): number {
1429
+ let timestamp = 0;
1430
+ if (this._dynamicIndexBufferSource) {
1431
+ timestamp = Math.max(timestamp, this._dynamicIndexBufferSource.source.updateTimestamp);
1432
+ }
1433
+ for (const entry of Object.values(this._dynamicAttributeBufferSources)) {
1434
+ timestamp = Math.max(timestamp, entry.source.updateTimestamp);
1435
+ }
1436
+ for (const binding of Object.values(this.bindings)) {
1437
+ if (binding instanceof TextureView) {
1438
+ timestamp = Math.max(timestamp, binding.texture.updateTimestamp);
1439
+ } else if (
1440
+ binding instanceof Buffer ||
1441
+ binding instanceof Texture ||
1442
+ binding instanceof ExternalTexture
1443
+ ) {
1444
+ timestamp = Math.max(timestamp, binding.updateTimestamp);
1445
+ } else if (binding instanceof DynamicBuffer) {
1446
+ timestamp = Math.max(timestamp, binding.updateTimestamp);
1447
+ } else if (isTextureBindingSource(binding)) {
1448
+ timestamp = binding.isReady
1449
+ ? Math.max(timestamp, binding.updateTimestamp)
1450
+ : // The texture will become available in the future
1451
+ Infinity;
1452
+ } else if (isBufferRangeBinding(binding)) {
1453
+ timestamp = Math.max(
1454
+ timestamp,
1455
+ binding.buffer instanceof DynamicBuffer
1456
+ ? binding.buffer.updateTimestamp
1457
+ : binding.buffer.updateTimestamp
1458
+ );
1459
+ }
1460
+ }
1461
+ return timestamp;
1462
+ }
1463
+
1464
+ /** Mark pipeline as needing update */
1465
+ _setPipelineNeedsUpdate(reason: string): void {
1466
+ this._pipelineNeedsUpdate ||= reason;
1467
+ this._drawBlockedReason = false;
1468
+ this.setNeedsRedraw(reason);
1469
+ }
1470
+
1471
+ /** Update pipeline if needed */
1472
+ _updatePipeline(): RenderPipeline {
1473
+ const update = this._preparePipelineUpdate();
1474
+ if (update) {
1475
+ this.pipeline = this.pipelineFactory.createRenderPipeline(update.props);
1476
+ this._finishPipelineUpdate(update);
1477
+ }
1478
+ return this.pipeline;
1479
+ }
1480
+
1481
+ /** Creates or replaces the render pipeline through the backend's asynchronous compilation path. */
1482
+ async _updatePipelineAsync(): Promise<RenderPipeline> {
1483
+ const update = this._preparePipelineUpdate();
1484
+ if (update) {
1485
+ try {
1486
+ this.pipeline = await this.pipelineFactory.createRenderPipelineAsync(update.props);
1487
+ } catch (error) {
1488
+ this._releasePipelineShaders(update.vertexShader, update.fragmentShader);
1489
+ this._pipelineNeedsUpdate = 'asynchronous pipeline creation failed';
1490
+ throw error;
1491
+ }
1492
+ this._finishPipelineUpdate(update);
1493
+ }
1494
+ return this.pipeline;
1495
+ }
1496
+
1497
+ private _preparePipelineUpdate(): {
1498
+ props: RenderPipelineProps;
1499
+ vertexShader: Shader;
1500
+ fragmentShader: Shader | null;
1501
+ previousVertexShader: Shader | null;
1502
+ previousFragmentShader: Shader | null;
1503
+ } | null {
1504
+ if (!this._pipelineNeedsUpdate) return null;
1505
+ const previousVertexShader = this.pipeline?.vs ?? null;
1506
+ const previousFragmentShader = this.pipeline?.fs ?? null;
1507
+ if (this.pipeline) {
1508
+ log.log(
1509
+ 1,
1510
+ `GPUVectorModel ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`
1511
+ )();
1512
+ }
1513
+ this._pipelineNeedsUpdate = false;
1514
+
1515
+ const vertexShader = this.shaderFactory.createShader({
1516
+ id: `${this.id}-vertex`,
1517
+ stage: 'vertex',
1518
+ source: this.source || this.vs,
1519
+ debugShaders: this.props.debugShaders
1520
+ });
1521
+ let fragmentShader: Shader | null = null;
1522
+ if (this.source) {
1523
+ fragmentShader = vertexShader;
1524
+ } else if (this.fs) {
1525
+ fragmentShader = this.shaderFactory.createShader({
1526
+ id: `${this.id}-fragment`,
1527
+ stage: 'fragment',
1528
+ source: this.fs,
1529
+ debugShaders: this.props.debugShaders
1530
+ });
1531
+ }
1532
+ return {
1533
+ props: {
1534
+ ...this.props,
1535
+ bindings: undefined,
1536
+ bufferLayout: this.bufferLayout,
1537
+ colorAttachmentFormats: this._colorAttachmentFormats,
1538
+ depthStencilAttachmentFormat: this._depthStencilAttachmentFormat,
1539
+ topology: this.topology,
1540
+ parameters: this.parameters,
1541
+ bindGroups: undefined,
1542
+ vs: vertexShader,
1543
+ fs: fragmentShader
1544
+ },
1545
+ vertexShader,
1546
+ fragmentShader,
1547
+ previousVertexShader,
1548
+ previousFragmentShader
1549
+ };
1550
+ }
1551
+
1552
+ private _finishPipelineUpdate(update: {
1553
+ previousVertexShader: Shader | null;
1554
+ previousFragmentShader: Shader | null;
1555
+ }): void {
1556
+ this._attributeInfos = getAttributeInfosFromLayouts(
1557
+ this.pipeline.shaderLayout,
1558
+ this.bufferLayout
1559
+ );
1560
+ this._releasePipelineShaders(update.previousVertexShader, update.previousFragmentShader);
1561
+ }
1562
+
1563
+ private _releasePipelineShaders(
1564
+ vertexShader: Shader | null,
1565
+ fragmentShader: Shader | null
1566
+ ): void {
1567
+ if (vertexShader) this.shaderFactory.release(vertexShader);
1568
+ if (fragmentShader && fragmentShader !== vertexShader) {
1569
+ this.shaderFactory.release(fragmentShader);
1570
+ }
1571
+ }
1572
+
1573
+ /** Throttle draw call logging */
1574
+ _lastLogTime = 0;
1575
+ _logOpen = false;
1576
+
1577
+ _logDrawCallStart(): void {
1578
+ // IF level is 4 or higher, log every frame.
1579
+ const logDrawTimeout = log.level > 3 ? 0 : LOG_DRAW_TIMEOUT;
1580
+ if (log.level < 2 || Date.now() - this._lastLogTime < logDrawTimeout) {
1581
+ return;
1582
+ }
1583
+
1584
+ this._lastLogTime = Date.now();
1585
+ this._logOpen = true;
1586
+
1587
+ log.group(LOG_DRAW_PRIORITY, `>>> DRAWING MODEL ${this.id}`, {collapsed: log.level <= 2})();
1588
+ }
1589
+
1590
+ _logDrawCallEnd(): void {
1591
+ if (this._logOpen) {
1592
+ const shaderLayoutTable = getDebugTableForShaderLayout(this.pipeline.shaderLayout, this.id);
1593
+
1594
+ // log.table(logLevel, attributeTable)();
1595
+ // log.table(logLevel, uniformTable)();
1596
+ log.table(LOG_DRAW_PRIORITY, shaderLayoutTable)();
1597
+
1598
+ const uniformTable = this.shaderInputs.getDebugTable();
1599
+ log.table(LOG_DRAW_PRIORITY, uniformTable)();
1600
+
1601
+ const attributeTable = this._getAttributeDebugTable();
1602
+ log.table(LOG_DRAW_PRIORITY, this._attributeInfos)();
1603
+ log.table(LOG_DRAW_PRIORITY, attributeTable)();
1604
+
1605
+ log.groupEnd(LOG_DRAW_PRIORITY)();
1606
+ this._logOpen = false;
1607
+ }
1608
+ }
1609
+
1610
+ protected _drawCount = 0;
1611
+ _logFramebuffer(renderPass: RenderPass): void {
1612
+ const debugFramebuffers = this.device.props.debugFramebuffers;
1613
+ this._drawCount++;
1614
+ // Update first 3 frames and then every 60 frames
1615
+ if (!debugFramebuffers) {
1616
+ // } || (this._drawCount++ > 3 && this._drawCount % 60)) {
1617
+ return;
1618
+ }
1619
+ const framebuffer = renderPass.props.framebuffer;
1620
+ debugFramebuffer(renderPass, framebuffer, {
1621
+ id: framebuffer?.id || `${this.id}-framebuffer`,
1622
+ minimap: true
1623
+ });
1624
+ }
1625
+
1626
+ _getAttributeDebugTable(): Record<string, Record<string, unknown>> {
1627
+ const table: Record<string, Record<string, unknown>> = {};
1628
+ for (const [name, attributeInfo] of Object.entries(this._attributeInfos)) {
1629
+ const values = this.vertexArray.attributes[attributeInfo.location];
1630
+ table[attributeInfo.location] = {
1631
+ name,
1632
+ type: attributeInfo.shaderType,
1633
+ values: values
1634
+ ? this._getBufferOrConstantValues(values, attributeInfo.bufferDataType)
1635
+ : 'null'
1636
+ };
1637
+ }
1638
+ if (this.vertexArray.indexBuffer) {
1639
+ const {indexBuffer} = this.vertexArray;
1640
+ const values =
1641
+ indexBuffer.indexType === 'uint32'
1642
+ ? new Uint32Array(indexBuffer.debugData)
1643
+ : new Uint16Array(indexBuffer.debugData);
1644
+ table['indices'] = {
1645
+ name: 'indices',
1646
+ type: indexBuffer.indexType,
1647
+ values: values.toString()
1648
+ };
1649
+ }
1650
+ return table;
1651
+ }
1652
+
1653
+ // TODO - fix typing of luma data types
1654
+ _getBufferOrConstantValues(attribute: Buffer | TypedArray, dataType: any): string {
1655
+ const TypedArrayConstructor = dataTypeDecoder.getTypedArrayConstructor(dataType);
1656
+ const typedArray =
1657
+ attribute instanceof Buffer ? new TypedArrayConstructor(attribute.debugData) : attribute;
1658
+ return typedArray.toString();
1659
+ }
1660
+
1661
+ /** Returns the current reflected shader layout or the pre-reflection empty layout. */
1662
+ protected _getCurrentShaderLayout(): AnyShaderLayout {
1663
+ return this.pipeline?.shaderLayout || this.props.shaderLayout || {bindings: []};
1664
+ }
1665
+
1666
+ private _syncDynamicBuffers(): void {
1667
+ if (
1668
+ this._dynamicIndexBufferSource &&
1669
+ this._dynamicIndexBufferSource.generation !== this._dynamicIndexBufferSource.source.generation
1670
+ ) {
1671
+ const resolvedIndexBuffer = this._dynamicIndexBufferSource.source.buffer;
1672
+ this.indexBuffer = resolvedIndexBuffer;
1673
+ this.vertexArray.setIndexBuffer(resolvedIndexBuffer);
1674
+ this._dynamicIndexBufferSource.generation = this._dynamicIndexBufferSource.source.generation;
1675
+ this.setNeedsRedraw('dynamic index buffer');
1676
+ }
1677
+
1678
+ for (const [locationKey, entry] of Object.entries(this._dynamicAttributeBufferSources)) {
1679
+ if (entry.generation !== entry.source.generation) {
1680
+ this.vertexArray.setBuffer(Number(locationKey), entry.source.buffer, entry.byteOffset);
1681
+ entry.generation = entry.source.generation;
1682
+ this.setNeedsRedraw('dynamic attribute buffer');
1683
+ }
1684
+ }
1685
+ }
1686
+ private _syncAttachmentFormats(renderPass: RenderPass): void {
1687
+ if (this.device.type !== 'webgpu') {
1688
+ return;
1689
+ }
1690
+
1691
+ const framebuffer =
1692
+ (
1693
+ renderPass as RenderPass & {
1694
+ framebuffer?: {
1695
+ colorAttachments?: Array<{texture?: {format?: TextureFormatColor}} | null>;
1696
+ depthStencilAttachment?: {texture?: {format?: TextureFormatDepthStencil}} | null;
1697
+ };
1698
+ }
1699
+ ).framebuffer || renderPass.props.framebuffer;
1700
+ const renderBundleProps = renderPass.props as RenderPass['props'] & {
1701
+ colorAttachmentFormats?: (TextureFormatColor | null)[];
1702
+ depthStencilAttachmentFormat?: TextureFormatDepthStencil | false;
1703
+ };
1704
+
1705
+ const nextColorAttachmentFormats =
1706
+ renderBundleProps.colorAttachmentFormats ??
1707
+ framebuffer?.colorAttachments?.map(colorAttachment =>
1708
+ asColorAttachmentFormat(colorAttachment?.texture?.format)
1709
+ );
1710
+ const nextDepthStencilAttachmentFormat =
1711
+ renderBundleProps.depthStencilAttachmentFormat === false
1712
+ ? undefined
1713
+ : (renderBundleProps.depthStencilAttachmentFormat ??
1714
+ asDepthStencilAttachmentFormat(framebuffer?.depthStencilAttachment?.texture?.format));
1715
+
1716
+ if (
1717
+ !deepEqual(this._colorAttachmentFormats, nextColorAttachmentFormats, 1) ||
1718
+ this._depthStencilAttachmentFormat !== nextDepthStencilAttachmentFormat
1719
+ ) {
1720
+ this._colorAttachmentFormats = nextColorAttachmentFormats;
1721
+ this._depthStencilAttachmentFormat = nextDepthStencilAttachmentFormat;
1722
+ this._setPipelineNeedsUpdate('attachment formats');
1723
+ }
1724
+ }
1725
+ }
1726
+
1727
+ // HELPERS
1728
+
1729
+ function isShaderAssemblerForLanguage(
1730
+ shaderAssembler: ShaderAssembler,
1731
+ shaderLanguage: 'glsl'
1732
+ ): shaderAssembler is GLSLShaderAssembler;
1733
+ function isShaderAssemblerForLanguage(
1734
+ shaderAssembler: ShaderAssembler,
1735
+ shaderLanguage: 'wgsl'
1736
+ ): shaderAssembler is WGSLShaderAssembler;
1737
+ function isShaderAssemblerForLanguage(
1738
+ shaderAssembler: ShaderAssembler,
1739
+ shaderLanguage: 'glsl' | 'wgsl'
1740
+ ): shaderAssembler is GLSLShaderAssembler | WGSLShaderAssembler;
1741
+ function isShaderAssemblerForLanguage(
1742
+ shaderAssembler: ShaderAssembler,
1743
+ shaderLanguage: 'glsl' | 'wgsl'
1744
+ ): boolean {
1745
+ if (
1746
+ shaderAssembler.shaderLanguage !== undefined &&
1747
+ shaderAssembler.shaderLanguage !== shaderLanguage
1748
+ ) {
1749
+ return false;
1750
+ }
1751
+
1752
+ return shaderLanguage === 'glsl'
1753
+ ? 'assembleGLSLShaderPair' in shaderAssembler &&
1754
+ typeof shaderAssembler.assembleGLSLShaderPair === 'function'
1755
+ : 'assembleWGSLShader' in shaderAssembler &&
1756
+ typeof shaderAssembler.assembleWGSLShader === 'function';
1757
+ }
1758
+
1759
+ function normalizeShaderPluginAttributeNames(
1760
+ shaderLayout: ShaderLayout | null | undefined,
1761
+ vertexInputs: Record<string, AttributeShaderType>
1762
+ ): ShaderLayout | null | undefined {
1763
+ if (!shaderLayout || Object.keys(vertexInputs).length === 0) {
1764
+ return shaderLayout;
1765
+ }
1766
+
1767
+ return {
1768
+ ...shaderLayout,
1769
+ attributes: shaderLayout.attributes.map(attribute => {
1770
+ const publicName = attribute.name.startsWith('_luma_')
1771
+ ? attribute.name.slice('_luma_'.length)
1772
+ : null;
1773
+ return publicName && vertexInputs[publicName] ? {...attribute, name: publicName} : attribute;
1774
+ })
1775
+ };
1776
+ }
1777
+
1778
+ /**
1779
+ * Resolves one model binding against the current shader layout.
1780
+ * @param bindingName Logical model binding name.
1781
+ * @param binding GPUVectorModel binding or deferred engine binding source.
1782
+ * @param shaderLayout Reflected bindings used to select copied or external texture resolution.
1783
+ * @returns Concrete core binding, or `null` while a deferred source is unavailable.
1784
+ */
1785
+ function resolveModelBinding(
1786
+ bindingName: string,
1787
+ binding: ModelBinding,
1788
+ shaderLayout: AnyShaderLayout
1789
+ ): Binding | null {
1790
+ if (isTextureBindingSource(binding)) {
1791
+ const bindingLayout = getTextureBindingLayout(shaderLayout, bindingName, {
1792
+ fallbackGroup: 0
1793
+ });
1794
+ return bindingLayout ? binding.resolveTextureBinding(bindingLayout) : null;
1795
+ }
1796
+
1797
+ if (binding instanceof DynamicBuffer) {
1798
+ return binding.buffer;
1799
+ }
1800
+
1801
+ if (isBufferRangeBinding(binding)) {
1802
+ return resolveBufferRangeBinding(binding);
1803
+ }
1804
+
1805
+ return binding;
1806
+ }
1807
+ function asColorAttachmentFormat(format?: string | null): TextureFormatColor | null {
1808
+ return format && !isDepthStencilAttachmentFormat(format) ? (format as TextureFormatColor) : null;
1809
+ }
1810
+
1811
+ function asDepthStencilAttachmentFormat(
1812
+ format?: string | null
1813
+ ): TextureFormatDepthStencil | undefined {
1814
+ return format && isDepthStencilAttachmentFormat(format) ? format : undefined;
1815
+ }
1816
+
1817
+ function isDepthStencilAttachmentFormat(format: string): format is TextureFormatDepthStencil {
1818
+ return DEPTH_STENCIL_ATTACHMENT_FORMATS.includes(format as TextureFormatDepthStencil);
1819
+ }