@npm9912/v-map 0.1.0

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 (438) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +185 -0
  3. package/dist/cjs/_commonjsHelpers-B83fTs8d.js +36 -0
  4. package/dist/cjs/app-globals-V2Kpy_OQ.js +5 -0
  5. package/dist/cjs/cesium-provider-BiFFyAl9.js +2598 -0
  6. package/dist/cjs/deck-provider-Ctq3Q8a1.js +47824 -0
  7. package/dist/cjs/geotiff-CEwvF9cG.js +47 -0
  8. package/dist/cjs/geotiff-source-RaNzzWkC.js +1522 -0
  9. package/dist/cjs/index-B1oGO1g-.js +10658 -0
  10. package/dist/cjs/index-B8LHqjyg.js +1765 -0
  11. package/dist/cjs/index-BIL4VsgP.js +310 -0
  12. package/dist/cjs/index-Blku2QY8.js +167 -0
  13. package/dist/cjs/index-CJvvX4yx.js +21 -0
  14. package/dist/cjs/index-CbVT-Con.js +699 -0
  15. package/dist/cjs/index-ISOEpMC3.js +20478 -0
  16. package/dist/cjs/index-JSwBbvGA.js +1621 -0
  17. package/dist/cjs/index.browser-DQhD8Jwl.js +6873 -0
  18. package/dist/cjs/index.cjs.js +2 -0
  19. package/dist/cjs/layer-extension-B_olS0rc.js +65 -0
  20. package/dist/cjs/leaflet-provider-DOqfs7g5.js +1815 -0
  21. package/dist/cjs/loader.cjs.js +13 -0
  22. package/dist/cjs/main-dist-7TykwFci.js +2655 -0
  23. package/dist/cjs/messages-D7h4m8Tx.js +186 -0
  24. package/dist/cjs/openlayers-provider-Dfeg6L4n.js +1604 -0
  25. package/dist/cjs/polygon-layer-B9PrN7vr.js +1300 -0
  26. package/dist/cjs/scenegraph-layer-DwNoxQdi.js +2530 -0
  27. package/dist/cjs/styleconfig-CVRqArk-.js +23 -0
  28. package/dist/cjs/v-map-builder.cjs.entry.js +3786 -0
  29. package/dist/cjs/v-map-layer-geojson_12.cjs.entry.js +40894 -0
  30. package/dist/cjs/v-map-layer-helper-iAzxAg9I.js +285 -0
  31. package/dist/cjs/v-map-layer-terrain-geotiff.cjs.entry.js +258 -0
  32. package/dist/cjs/v-map-layercontrol.cjs.entry.js +247 -0
  33. package/dist/cjs/v-map.cjs.js +25 -0
  34. package/dist/cjs/v-map.v-map-layer-osm.v-map-layergroup-BsXp3BoL.js +582 -0
  35. package/dist/cjs/v-map_3.cjs.entry.js +12 -0
  36. package/dist/collection/collection-manifest.json +30 -0
  37. package/dist/collection/components/v-map/v-map.css +3 -0
  38. package/dist/collection/components/v-map/v-map.js +467 -0
  39. package/dist/collection/components/v-map/v-map.test.js +33 -0
  40. package/dist/collection/components/v-map-builder/v-map-builder.css +1 -0
  41. package/dist/collection/components/v-map-builder/v-map-builder.js +913 -0
  42. package/dist/collection/components/v-map-builder/v-map-builder.test.js +56 -0
  43. package/dist/collection/components/v-map-layer-geojson/v-map-layer-geojson.js +862 -0
  44. package/dist/collection/components/v-map-layer-geojson/v-map-layer-geojson.test.js +42 -0
  45. package/dist/collection/components/v-map-layer-geotiff/v-map-layer-geotiff.css +4 -0
  46. package/dist/collection/components/v-map-layer-geotiff/v-map-layer-geotiff.js +500 -0
  47. package/dist/collection/components/v-map-layer-geotiff/v-map-layer-geotiff.test.js +38 -0
  48. package/dist/collection/components/v-map-layer-google/v-map-layer-google.css +1 -0
  49. package/dist/collection/components/v-map-layer-google/v-map-layer-google.js +442 -0
  50. package/dist/collection/components/v-map-layer-osm/error-api.test.js +108 -0
  51. package/dist/collection/components/v-map-layer-osm/v-map-layer-osm.css +4 -0
  52. package/dist/collection/components/v-map-layer-osm/v-map-layer-osm.js +311 -0
  53. package/dist/collection/components/v-map-layer-osm/v-map-layer-osm.test.js +36 -0
  54. package/dist/collection/components/v-map-layer-scatterplot/v-map-layer-scatterplot.css +1 -0
  55. package/dist/collection/components/v-map-layer-scatterplot/v-map-layer-scatterplot.js +305 -0
  56. package/dist/collection/components/v-map-layer-terrain/v-map-layer-terrain.css +3 -0
  57. package/dist/collection/components/v-map-layer-terrain/v-map-layer-terrain.js +548 -0
  58. package/dist/collection/components/v-map-layer-terrain/v-map-layer-terrain.test.js +36 -0
  59. package/dist/collection/components/v-map-layer-terrain-geotiff/v-map-layer-terrain-geotiff.css +3 -0
  60. package/dist/collection/components/v-map-layer-terrain-geotiff/v-map-layer-terrain-geotiff.js +735 -0
  61. package/dist/collection/components/v-map-layer-terrain-geotiff/v-map-layer-terrain-geotiff.test.js +42 -0
  62. package/dist/collection/components/v-map-layer-tile3d/v-map-layer-tile3d.css +3 -0
  63. package/dist/collection/components/v-map-layer-tile3d/v-map-layer-tile3d.js +449 -0
  64. package/dist/collection/components/v-map-layer-tile3d/v-map-layer-tile3d.test.js +50 -0
  65. package/dist/collection/components/v-map-layer-wcs/v-map-layer-wcs.css +1 -0
  66. package/dist/collection/components/v-map-layer-wcs/v-map-layer-wcs.js +448 -0
  67. package/dist/collection/components/v-map-layer-wcs/v-map-layer-wcs.test.js +39 -0
  68. package/dist/collection/components/v-map-layer-wfs/v-map-layer-wfs.css +1 -0
  69. package/dist/collection/components/v-map-layer-wfs/v-map-layer-wfs.js +489 -0
  70. package/dist/collection/components/v-map-layer-wfs/v-map-layer-wfs.test.js +43 -0
  71. package/dist/collection/components/v-map-layer-wkt/v-map-layer-wkt.css +1 -0
  72. package/dist/collection/components/v-map-layer-wkt/v-map-layer-wkt.js +811 -0
  73. package/dist/collection/components/v-map-layer-wkt/v-map-layer-wkt.test.js +34 -0
  74. package/dist/collection/components/v-map-layer-wms/v-map-layer-wms.css +1 -0
  75. package/dist/collection/components/v-map-layer-wms/v-map-layer-wms.js +453 -0
  76. package/dist/collection/components/v-map-layer-wms/v-map-layer-wms.test.js +36 -0
  77. package/dist/collection/components/v-map-layer-xyz/v-map-layer-xyz.css +1 -0
  78. package/dist/collection/components/v-map-layer-xyz/v-map-layer-xyz.js +331 -0
  79. package/dist/collection/components/v-map-layer-xyz/v-map-layer-xyz.test.js +28 -0
  80. package/dist/collection/components/v-map-layercontrol/v-map-layercontrol.css +74 -0
  81. package/dist/collection/components/v-map-layercontrol/v-map-layercontrol.js +277 -0
  82. package/dist/collection/components/v-map-layercontrol/v-map-layercontrol.test.js +134 -0
  83. package/dist/collection/components/v-map-layergroup/v-map-layergroup.css +4 -0
  84. package/dist/collection/components/v-map-layergroup/v-map-layergroup.js +212 -0
  85. package/dist/collection/components/v-map-layergroup/v-map-layergroup.test.js +39 -0
  86. package/dist/collection/components/v-map-style/v-map-style.css +38 -0
  87. package/dist/collection/components/v-map-style/v-map-style.js +492 -0
  88. package/dist/collection/components/v-map-style/v-map-style.unit.js +62 -0
  89. package/dist/collection/index.js +1 -0
  90. package/dist/collection/layer/v-map-layer-helper.js +281 -0
  91. package/dist/collection/layer/v-map-layer-helper.unit.js +234 -0
  92. package/dist/collection/lib/cesium-loader.js +58 -0
  93. package/dist/collection/lib/ensure-importmap.js +12 -0
  94. package/dist/collection/lib/ensure-importmap.unit.js +57 -0
  95. package/dist/collection/lib/versions.gen.js +6 -0
  96. package/dist/collection/lib/vstyle.js +8 -0
  97. package/dist/collection/map-provider/cesium/CesiumGeoTIFFTerrainProvider.js +285 -0
  98. package/dist/collection/map-provider/cesium/CesiumLayerGroups.js +159 -0
  99. package/dist/collection/map-provider/cesium/GeoTIFFImageryProvider.js +192 -0
  100. package/dist/collection/map-provider/cesium/GeoTIFFImageryProvider.test.js +57 -0
  101. package/dist/collection/map-provider/cesium/cesium-provider.js +1408 -0
  102. package/dist/collection/map-provider/cesium/i-layer.js +1 -0
  103. package/dist/collection/map-provider/cesium/layer-manager.js +467 -0
  104. package/dist/collection/map-provider/deck/DeckGLGeoTIFFLayer.js +483 -0
  105. package/dist/collection/map-provider/deck/DeckGLGeoTIFFTerrainLayer.js +410 -0
  106. package/dist/collection/map-provider/deck/LayerGroupWithModel.js +169 -0
  107. package/dist/collection/map-provider/deck/LayerGroups.js +192 -0
  108. package/dist/collection/map-provider/deck/LayerModel.js +1 -0
  109. package/dist/collection/map-provider/deck/RenderableGroup.js +1 -0
  110. package/dist/collection/map-provider/deck/deck-provider.js +1563 -0
  111. package/dist/collection/map-provider/geotiff/geotiff-source.js +172 -0
  112. package/dist/collection/map-provider/geotiff/utils/AABB2D.js +24 -0
  113. package/dist/collection/map-provider/geotiff/utils/BVHNode2D.js +166 -0
  114. package/dist/collection/map-provider/geotiff/utils/GeoTIFFTileProcessor.js +484 -0
  115. package/dist/collection/map-provider/geotiff/utils/Triangle.js +1 -0
  116. package/dist/collection/map-provider/geotiff/utils/Triangulation.js +321 -0
  117. package/dist/collection/map-provider/geotiff/utils/colormap-utils.js +190 -0
  118. package/dist/collection/map-provider/geotiff/utils/normalization-utils.js +122 -0
  119. package/dist/collection/map-provider/geotiff/utils/sampling-utils.js +108 -0
  120. package/dist/collection/map-provider/leaflet/GeoTIFFGridLayer.js +147 -0
  121. package/dist/collection/map-provider/leaflet/WCSGridLayer.js +124 -0
  122. package/dist/collection/map-provider/leaflet/google-map-tiles-layer.js +352 -0
  123. package/dist/collection/map-provider/leaflet/leaflet-helpers.js +94 -0
  124. package/dist/collection/map-provider/leaflet/leaflet-provider.js +1095 -0
  125. package/dist/collection/map-provider/ol/CustomGeoTiff.js +145 -0
  126. package/dist/collection/map-provider/ol/openlayers-helper.js +26 -0
  127. package/dist/collection/map-provider/ol/openlayers-provider.js +1427 -0
  128. package/dist/collection/map-provider/provider-factory.js +44 -0
  129. package/dist/collection/map-provider/provider-factory.unit.js +66 -0
  130. package/dist/collection/testing/browser-test-utils.js +49 -0
  131. package/dist/collection/testing/e2e-testing.js +122 -0
  132. package/dist/collection/testing/e2e-utils.js +70 -0
  133. package/dist/collection/testing/geotiff-test-server.js +100 -0
  134. package/dist/collection/testing/mocks/geostyler-lyrx-parser.js +12 -0
  135. package/dist/collection/testing/mocks/geostyler-mapbox-parser.js +12 -0
  136. package/dist/collection/testing/mocks/geostyler-qgis-parser.js +12 -0
  137. package/dist/collection/testing/mocks/geostyler-sld-parser.js +13 -0
  138. package/dist/collection/testing/mocks/geostyler-style.js +5 -0
  139. package/dist/collection/testing/setupTests.browser.js +1 -0
  140. package/dist/collection/testing/setupTests.stencil.js +20 -0
  141. package/dist/collection/testing/setupTests.vitest.js +59 -0
  142. package/dist/collection/testing/stencil-testing-wrapper.js +43 -0
  143. package/dist/collection/testing/styleMock.js +1 -0
  144. package/dist/collection/types/color.js +1 -0
  145. package/dist/collection/types/cssmode.js +1 -0
  146. package/dist/collection/types/flavour.js +1 -0
  147. package/dist/collection/types/layerconfig.js +1 -0
  148. package/dist/collection/types/lonlat.js +1 -0
  149. package/dist/collection/types/mapinitoptions.js +1 -0
  150. package/dist/collection/types/mapprovider.js +1 -0
  151. package/dist/collection/types/provideroptions.js +1 -0
  152. package/dist/collection/types/styleconfig.js +19 -0
  153. package/dist/collection/types/styling.js +13 -0
  154. package/dist/collection/types/styling.unit.js +37 -0
  155. package/dist/collection/types/vmaplayer.js +1 -0
  156. package/dist/collection/utils/async-mutex.js +28 -0
  157. package/dist/collection/utils/diff.js +142 -0
  158. package/dist/collection/utils/diff.unit.js +59 -0
  159. package/dist/collection/utils/dom-env.js +43 -0
  160. package/dist/collection/utils/dom-env.unit.js +92 -0
  161. package/dist/collection/utils/events.js +8 -0
  162. package/dist/collection/utils/logger.js +183 -0
  163. package/dist/collection/utils/logger.unit.js +98 -0
  164. package/dist/collection/utils/messages.js +12 -0
  165. package/dist/collection/utils/spatial-utils.js +27 -0
  166. package/dist/collection/utils/spatial-utils.unit.js +24 -0
  167. package/dist/components/_commonjsHelpers.js +1 -0
  168. package/dist/components/cesium-provider.js +1 -0
  169. package/dist/components/deck-provider.js +1 -0
  170. package/dist/components/events.js +1 -0
  171. package/dist/components/geotiff-source.js +1 -0
  172. package/dist/components/geotiff.js +4 -0
  173. package/dist/components/index.browser.js +15 -0
  174. package/dist/components/index.d.ts +35 -0
  175. package/dist/components/index.js +1 -0
  176. package/dist/components/index2.js +1 -0
  177. package/dist/components/index3.js +1 -0
  178. package/dist/components/index4.js +1 -0
  179. package/dist/components/index5.js +1 -0
  180. package/dist/components/index6.js +1 -0
  181. package/dist/components/index7.js +1 -0
  182. package/dist/components/index8.js +7 -0
  183. package/dist/components/layer-extension.js +1 -0
  184. package/dist/components/leaflet-provider.js +1 -0
  185. package/dist/components/main-dist.js +1 -0
  186. package/dist/components/messages.js +1 -0
  187. package/dist/components/openlayers-provider.js +1 -0
  188. package/dist/components/polygon-layer.js +1 -0
  189. package/dist/components/scenegraph-layer.js +1 -0
  190. package/dist/components/styleconfig.js +1 -0
  191. package/dist/components/styling.js +1 -0
  192. package/dist/components/v-map-builder.d.ts +11 -0
  193. package/dist/components/v-map-builder.js +2 -0
  194. package/dist/components/v-map-layer-geojson.d.ts +11 -0
  195. package/dist/components/v-map-layer-geojson.js +1 -0
  196. package/dist/components/v-map-layer-geojson2.js +1 -0
  197. package/dist/components/v-map-layer-geotiff.d.ts +11 -0
  198. package/dist/components/v-map-layer-geotiff.js +1 -0
  199. package/dist/components/v-map-layer-geotiff2.js +1 -0
  200. package/dist/components/v-map-layer-google.d.ts +11 -0
  201. package/dist/components/v-map-layer-google.js +1 -0
  202. package/dist/components/v-map-layer-google2.js +1 -0
  203. package/dist/components/v-map-layer-helper.js +1 -0
  204. package/dist/components/v-map-layer-osm.d.ts +11 -0
  205. package/dist/components/v-map-layer-osm.js +1 -0
  206. package/dist/components/v-map-layer-osm2.js +1 -0
  207. package/dist/components/v-map-layer-scatterplot.d.ts +11 -0
  208. package/dist/components/v-map-layer-scatterplot.js +1 -0
  209. package/dist/components/v-map-layer-scatterplot2.js +1 -0
  210. package/dist/components/v-map-layer-terrain-geotiff.d.ts +11 -0
  211. package/dist/components/v-map-layer-terrain-geotiff.js +1 -0
  212. package/dist/components/v-map-layer-terrain.d.ts +11 -0
  213. package/dist/components/v-map-layer-terrain.js +1 -0
  214. package/dist/components/v-map-layer-terrain2.js +1 -0
  215. package/dist/components/v-map-layer-tile3d.d.ts +11 -0
  216. package/dist/components/v-map-layer-tile3d.js +1 -0
  217. package/dist/components/v-map-layer-tile3d2.js +1 -0
  218. package/dist/components/v-map-layer-wcs.d.ts +11 -0
  219. package/dist/components/v-map-layer-wcs.js +1 -0
  220. package/dist/components/v-map-layer-wcs2.js +1 -0
  221. package/dist/components/v-map-layer-wfs.d.ts +11 -0
  222. package/dist/components/v-map-layer-wfs.js +1 -0
  223. package/dist/components/v-map-layer-wfs2.js +1 -0
  224. package/dist/components/v-map-layer-wkt.d.ts +11 -0
  225. package/dist/components/v-map-layer-wkt.js +1 -0
  226. package/dist/components/v-map-layer-wkt2.js +1 -0
  227. package/dist/components/v-map-layer-wms.d.ts +11 -0
  228. package/dist/components/v-map-layer-wms.js +1 -0
  229. package/dist/components/v-map-layer-wms2.js +1 -0
  230. package/dist/components/v-map-layer-xyz.d.ts +11 -0
  231. package/dist/components/v-map-layer-xyz.js +1 -0
  232. package/dist/components/v-map-layer-xyz2.js +1 -0
  233. package/dist/components/v-map-layercontrol.d.ts +11 -0
  234. package/dist/components/v-map-layercontrol.js +1 -0
  235. package/dist/components/v-map-layergroup.d.ts +11 -0
  236. package/dist/components/v-map-layergroup.js +1 -0
  237. package/dist/components/v-map-layergroup2.js +1 -0
  238. package/dist/components/v-map-style.d.ts +11 -0
  239. package/dist/components/v-map-style.js +1 -0
  240. package/dist/components/v-map-style2.js +10 -0
  241. package/dist/components/v-map.d.ts +11 -0
  242. package/dist/components/v-map.js +1 -0
  243. package/dist/components/v-map2.js +1 -0
  244. package/dist/esm/_commonjsHelpers-E-ZsRS8r.js +32 -0
  245. package/dist/esm/app-globals-DQuL1Twl.js +3 -0
  246. package/dist/esm/cesium-provider-BJfAup3w.js +2596 -0
  247. package/dist/esm/deck-provider-C7U9VDEq.js +47709 -0
  248. package/dist/esm/geotiff-BEWxTIfH.js +45 -0
  249. package/dist/esm/geotiff-source-esnDnC-u.js +1516 -0
  250. package/dist/esm/index-B1zwA4IC.js +685 -0
  251. package/dist/esm/index-BBpiaTpT.js +165 -0
  252. package/dist/esm/index-BIEmlzCf.js +1697 -0
  253. package/dist/esm/index-BUHa4Jj0.js +307 -0
  254. package/dist/esm/index-DbSdn93t.js +20461 -0
  255. package/dist/esm/index-RpJarvr_.js +10656 -0
  256. package/dist/esm/index-jN06TXUp.js +14 -0
  257. package/dist/esm/index-jzneDarq.js +1613 -0
  258. package/dist/esm/index.browser-DhQAXuA7.js +6860 -0
  259. package/dist/esm/index.js +1 -0
  260. package/dist/esm/layer-extension-CZXK5goK.js +63 -0
  261. package/dist/esm/leaflet-provider-Q41TB6ku.js +1794 -0
  262. package/dist/esm/loader.js +11 -0
  263. package/dist/esm/main-dist-CwnA7_Xn.js +2652 -0
  264. package/dist/esm/messages-CMKJzsgL.js +180 -0
  265. package/dist/esm/openlayers-provider-CMsDsQTQ.js +1602 -0
  266. package/dist/esm/polygon-layer-ByhxGhWC.js +1295 -0
  267. package/dist/esm/scenegraph-layer-09K_B6DT.js +2526 -0
  268. package/dist/esm/styleconfig-B-bAcABs.js +21 -0
  269. package/dist/esm/v-map-builder.entry.js +3784 -0
  270. package/dist/esm/v-map-layer-geojson_12.entry.js +40881 -0
  271. package/dist/esm/v-map-layer-helper-Dys44Cgo.js +283 -0
  272. package/dist/esm/v-map-layer-terrain-geotiff.entry.js +256 -0
  273. package/dist/esm/v-map-layercontrol.entry.js +245 -0
  274. package/dist/esm/v-map.js +21 -0
  275. package/dist/esm/v-map.v-map-layer-osm.v-map-layergroup-B4pFHuSf.js +572 -0
  276. package/dist/esm/v-map_3.entry.js +4 -0
  277. package/dist/index.cjs.js +1 -0
  278. package/dist/index.js +1 -0
  279. package/dist/types/cesium-augment.d.ts +5 -0
  280. package/dist/types/components/v-map/v-map.d.ts +70 -0
  281. package/dist/types/components/v-map/v-map.test.d.ts +1 -0
  282. package/dist/types/components/v-map-builder/v-map-builder.d.ts +48 -0
  283. package/dist/types/components/v-map-builder/v-map-builder.test.d.ts +1 -0
  284. package/dist/types/components/v-map-layer-geojson/v-map-layer-geojson.d.ts +129 -0
  285. package/dist/types/components/v-map-layer-geojson/v-map-layer-geojson.test.d.ts +1 -0
  286. package/dist/types/components/v-map-layer-geotiff/v-map-layer-geotiff.d.ts +74 -0
  287. package/dist/types/components/v-map-layer-geotiff/v-map-layer-geotiff.test.d.ts +1 -0
  288. package/dist/types/components/v-map-layer-google/v-map-layer-google.d.ts +78 -0
  289. package/dist/types/components/v-map-layer-osm/error-api.test.d.ts +1 -0
  290. package/dist/types/components/v-map-layer-osm/v-map-layer-osm.d.ts +50 -0
  291. package/dist/types/components/v-map-layer-osm/v-map-layer-osm.test.d.ts +1 -0
  292. package/dist/types/components/v-map-layer-scatterplot/v-map-layer-scatterplot.d.ts +54 -0
  293. package/dist/types/components/v-map-layer-terrain/v-map-layer-terrain.d.ts +74 -0
  294. package/dist/types/components/v-map-layer-terrain/v-map-layer-terrain.test.d.ts +1 -0
  295. package/dist/types/components/v-map-layer-terrain-geotiff/v-map-layer-terrain-geotiff.d.ts +117 -0
  296. package/dist/types/components/v-map-layer-terrain-geotiff/v-map-layer-terrain-geotiff.test.d.ts +1 -0
  297. package/dist/types/components/v-map-layer-tile3d/v-map-layer-tile3d.d.ts +69 -0
  298. package/dist/types/components/v-map-layer-tile3d/v-map-layer-tile3d.test.d.ts +1 -0
  299. package/dist/types/components/v-map-layer-wcs/v-map-layer-wcs.d.ts +47 -0
  300. package/dist/types/components/v-map-layer-wcs/v-map-layer-wcs.test.d.ts +1 -0
  301. package/dist/types/components/v-map-layer-wfs/v-map-layer-wfs.d.ts +59 -0
  302. package/dist/types/components/v-map-layer-wfs/v-map-layer-wfs.test.d.ts +1 -0
  303. package/dist/types/components/v-map-layer-wkt/v-map-layer-wkt.d.ts +132 -0
  304. package/dist/types/components/v-map-layer-wkt/v-map-layer-wkt.test.d.ts +1 -0
  305. package/dist/types/components/v-map-layer-wms/v-map-layer-wms.d.ts +76 -0
  306. package/dist/types/components/v-map-layer-wms/v-map-layer-wms.test.d.ts +1 -0
  307. package/dist/types/components/v-map-layer-xyz/v-map-layer-xyz.d.ts +59 -0
  308. package/dist/types/components/v-map-layer-xyz/v-map-layer-xyz.test.d.ts +1 -0
  309. package/dist/types/components/v-map-layercontrol/v-map-layercontrol.d.ts +44 -0
  310. package/dist/types/components/v-map-layercontrol/v-map-layercontrol.test.d.ts +1 -0
  311. package/dist/types/components/v-map-layergroup/v-map-layergroup.d.ts +31 -0
  312. package/dist/types/components/v-map-layergroup/v-map-layergroup.test.d.ts +1 -0
  313. package/dist/types/components/v-map-style/v-map-style.d.ts +75 -0
  314. package/dist/types/components/v-map-style/v-map-style.unit.d.ts +1 -0
  315. package/dist/types/components.d.ts +2391 -0
  316. package/dist/types/globals.d.ts +16 -0
  317. package/dist/types/index.d.ts +10 -0
  318. package/dist/types/layer/v-map-layer-helper.d.ts +45 -0
  319. package/dist/types/layer/v-map-layer-helper.unit.d.ts +1 -0
  320. package/dist/types/leaflet-augment.d.ts +15 -0
  321. package/dist/types/lib/cesium-loader.d.ts +3 -0
  322. package/dist/types/lib/ensure-importmap.d.ts +3 -0
  323. package/dist/types/lib/ensure-importmap.unit.d.ts +1 -0
  324. package/dist/types/lib/versions.gen.d.ts +5 -0
  325. package/dist/types/lib/vstyle.d.ts +44 -0
  326. package/dist/types/map-provider/cesium/CesiumGeoTIFFTerrainProvider.d.ts +92 -0
  327. package/dist/types/map-provider/cesium/CesiumLayerGroups.d.ts +64 -0
  328. package/dist/types/map-provider/cesium/GeoTIFFImageryProvider.d.ts +75 -0
  329. package/dist/types/map-provider/cesium/GeoTIFFImageryProvider.test.d.ts +1 -0
  330. package/dist/types/map-provider/cesium/cesium-provider.d.ts +87 -0
  331. package/dist/types/map-provider/cesium/i-layer.d.ts +11 -0
  332. package/dist/types/map-provider/cesium/layer-manager.d.ts +31 -0
  333. package/dist/types/map-provider/deck/DeckGLGeoTIFFLayer.d.ts +91 -0
  334. package/dist/types/map-provider/deck/DeckGLGeoTIFFTerrainLayer.d.ts +82 -0
  335. package/dist/types/map-provider/deck/LayerGroupWithModel.d.ts +55 -0
  336. package/dist/types/map-provider/deck/LayerGroups.d.ts +63 -0
  337. package/dist/types/map-provider/deck/LayerModel.d.ts +8 -0
  338. package/dist/types/map-provider/deck/RenderableGroup.d.ts +20 -0
  339. package/dist/types/map-provider/deck/deck-provider.d.ts +92 -0
  340. package/dist/types/map-provider/geotiff/geotiff-source.d.ts +30 -0
  341. package/dist/types/map-provider/geotiff/utils/AABB2D.d.ts +28 -0
  342. package/dist/types/map-provider/geotiff/utils/BVHNode2D.d.ts +36 -0
  343. package/dist/types/map-provider/geotiff/utils/GeoTIFFTileProcessor.d.ts +116 -0
  344. package/dist/types/map-provider/geotiff/utils/Triangle.d.ts +5 -0
  345. package/dist/types/map-provider/geotiff/utils/Triangulation.d.ts +94 -0
  346. package/dist/types/map-provider/geotiff/utils/colormap-utils.d.ts +47 -0
  347. package/dist/types/map-provider/geotiff/utils/normalization-utils.d.ts +39 -0
  348. package/dist/types/map-provider/geotiff/utils/sampling-utils.d.ts +13 -0
  349. package/dist/types/map-provider/leaflet/GeoTIFFGridLayer.d.ts +34 -0
  350. package/dist/types/map-provider/leaflet/WCSGridLayer.d.ts +38 -0
  351. package/dist/types/map-provider/leaflet/google-map-tiles-layer.d.ts +73 -0
  352. package/dist/types/map-provider/leaflet/leaflet-helpers.d.ts +6 -0
  353. package/dist/types/map-provider/leaflet/leaflet-provider.d.ts +73 -0
  354. package/dist/types/map-provider/ol/CustomGeoTiff.d.ts +14 -0
  355. package/dist/types/map-provider/ol/openlayers-helper.d.ts +2 -0
  356. package/dist/types/map-provider/ol/openlayers-provider.d.ts +80 -0
  357. package/dist/types/map-provider/provider-factory.d.ts +12 -0
  358. package/dist/types/map-provider/provider-factory.unit.d.ts +1 -0
  359. package/dist/types/namespaces.d.ts +3 -0
  360. package/dist/types/ol-augment.d.ts +3 -0
  361. package/dist/types/ol-override.d.ts +7 -0
  362. package/dist/types/ol.d.ts +10 -0
  363. package/dist/types/stencil-public-runtime.d.ts +1860 -0
  364. package/dist/types/testing/browser-test-utils.d.ts +6 -0
  365. package/dist/types/testing/e2e-testing.d.ts +5 -0
  366. package/dist/types/testing/e2e-utils.d.ts +4 -0
  367. package/dist/types/testing/geotiff-test-server.d.ts +5 -0
  368. package/dist/types/testing/mocks/geostyler-lyrx-parser.d.ts +11 -0
  369. package/dist/types/testing/mocks/geostyler-mapbox-parser.d.ts +11 -0
  370. package/dist/types/testing/mocks/geostyler-qgis-parser.d.ts +11 -0
  371. package/dist/types/testing/mocks/geostyler-sld-parser.d.ts +11 -0
  372. package/dist/types/testing/mocks/geostyler-style.d.ts +5 -0
  373. package/dist/types/testing/setupTests.browser.d.ts +1 -0
  374. package/dist/types/testing/setupTests.stencil.d.ts +1 -0
  375. package/dist/types/testing/setupTests.vitest.d.ts +1 -0
  376. package/dist/types/testing/stencil-testing-wrapper.d.ts +3 -0
  377. package/dist/types/types/color.d.ts +1 -0
  378. package/dist/types/types/cssmode.d.ts +1 -0
  379. package/dist/types/types/flavour.d.ts +1 -0
  380. package/dist/types/types/layerconfig.d.ts +207 -0
  381. package/dist/types/types/lonlat.d.ts +1 -0
  382. package/dist/types/types/mapinitoptions.d.ts +4 -0
  383. package/dist/types/types/mapprovider.d.ts +46 -0
  384. package/dist/types/types/provideroptions.d.ts +8 -0
  385. package/dist/types/types/styleconfig.d.ts +27 -0
  386. package/dist/types/types/styling.d.ts +24 -0
  387. package/dist/types/types/styling.unit.d.ts +1 -0
  388. package/dist/types/types/vmaplayer.d.ts +10 -0
  389. package/dist/types/utils/async-mutex.d.ts +7 -0
  390. package/dist/types/utils/diff.d.ts +64 -0
  391. package/dist/types/utils/diff.unit.d.ts +1 -0
  392. package/dist/types/utils/dom-env.d.ts +5 -0
  393. package/dist/types/utils/dom-env.unit.d.ts +1 -0
  394. package/dist/types/utils/events.d.ts +29 -0
  395. package/dist/types/utils/logger.d.ts +47 -0
  396. package/dist/types/utils/logger.unit.d.ts +1 -0
  397. package/dist/types/utils/messages.d.ts +12 -0
  398. package/dist/types/utils/spatial-utils.d.ts +6 -0
  399. package/dist/types/utils/spatial-utils.unit.d.ts +1 -0
  400. package/dist/types/versions.d.ts +7 -0
  401. package/dist/v-map/index.esm.js +0 -0
  402. package/dist/v-map/p--vVleK-M.js +1 -0
  403. package/dist/v-map/p-09d10db0.entry.js +1 -0
  404. package/dist/v-map/p-5eba6058.entry.js +10 -0
  405. package/dist/v-map/p-6b102336.entry.js +1 -0
  406. package/dist/v-map/p-B-bAcABs.js +1 -0
  407. package/dist/v-map/p-BBpiaTpT.js +1 -0
  408. package/dist/v-map/p-BdijL4Av.js +1 -0
  409. package/dist/v-map/p-Be3r33VF.js +4 -0
  410. package/dist/v-map/p-BeFu0ap4.js +1 -0
  411. package/dist/v-map/p-BxFJezdK.js +1 -0
  412. package/dist/v-map/p-CMKJzsgL.js +1 -0
  413. package/dist/v-map/p-CXfA_q8m.js +1 -0
  414. package/dist/v-map/p-CZqY0yW4.js +1 -0
  415. package/dist/v-map/p-CafTHT9i.js +1 -0
  416. package/dist/v-map/p-DCTHyf58.js +1 -0
  417. package/dist/v-map/p-DQuL1Twl.js +1 -0
  418. package/dist/v-map/p-DR9McdNX.js +1 -0
  419. package/dist/v-map/p-Dckgonw8.js +1 -0
  420. package/dist/v-map/p-DhQAXuA7.js +15 -0
  421. package/dist/v-map/p-DmICdG34.js +7 -0
  422. package/dist/v-map/p-DrOQ9V4h.js +1 -0
  423. package/dist/v-map/p-DvHXtWUg.js +1 -0
  424. package/dist/v-map/p-E-ZsRS8r.js +1 -0
  425. package/dist/v-map/p-MyTSFnEk.js +1 -0
  426. package/dist/v-map/p-RpJarvr_.js +1 -0
  427. package/dist/v-map/p-WaMDUuAz.js +1 -0
  428. package/dist/v-map/p-aa410e64.entry.js +2 -0
  429. package/dist/v-map/p-c21c93fe.entry.js +1 -0
  430. package/dist/v-map/p-jzneDarq.js +2 -0
  431. package/dist/v-map/p-uiIP-taz.js +1 -0
  432. package/dist/v-map/v-map.esm.js +1 -0
  433. package/loader/cdn.js +1 -0
  434. package/loader/index.cjs.js +1 -0
  435. package/loader/index.d.ts +24 -0
  436. package/loader/index.es2017.js +1 -0
  437. package/loader/index.js +2 -0
  438. package/package.json +193 -0
@@ -0,0 +1,2530 @@
1
+ 'use strict';
2
+
3
+ var gltf = require('@loaders.gl/gltf');
4
+ var deckProvider = require('./deck-provider-Ctq3Q8a1.js');
5
+
6
+ // luma.gl
7
+ // SPDX-License-Identifier: MIT
8
+ // Copyright (c) vis.gl contributors
9
+ // Attribution:
10
+ // MIT license, Copyright (c) 2016-2017 Mohamad Moneimne and Contributors
11
+ // This fragment shader defines a reference implementation for Physically Based Shading of
12
+ // a microfacet surface material defined by a glTF model.
13
+ // TODO - better do the checks outside of shader
14
+ const vs$2 = /* glsl */ `\
15
+ out vec3 pbr_vPosition;
16
+ out vec2 pbr_vUV;
17
+
18
+ #ifdef HAS_NORMALS
19
+ # ifdef HAS_TANGENTS
20
+ out mat3 pbr_vTBN;
21
+ # else
22
+ out vec3 pbr_vNormal;
23
+ # endif
24
+ #endif
25
+
26
+ void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, vec2 uv)
27
+ {
28
+ vec4 pos = pbrProjection.modelMatrix * position;
29
+ pbr_vPosition = vec3(pos.xyz) / pos.w;
30
+
31
+ #ifdef HAS_NORMALS
32
+ #ifdef HAS_TANGENTS
33
+ vec3 normalW = normalize(vec3(pbrProjection.normalMatrix * vec4(normal.xyz, 0.0)));
34
+ vec3 tangentW = normalize(vec3(pbrProjection.modelMatrix * vec4(tangent.xyz, 0.0)));
35
+ vec3 bitangentW = cross(normalW, tangentW) * tangent.w;
36
+ pbr_vTBN = mat3(tangentW, bitangentW, normalW);
37
+ #else // HAS_TANGENTS != 1
38
+ pbr_vNormal = normalize(vec3(pbrProjection.modelMatrix * vec4(normal.xyz, 0.0)));
39
+ #endif
40
+ #endif
41
+
42
+ #ifdef HAS_UV
43
+ pbr_vUV = uv;
44
+ #else
45
+ pbr_vUV = vec2(0.,0.);
46
+ #endif
47
+ }
48
+ `;
49
+ const fs$2 = /* glsl */ `\
50
+ precision highp float;
51
+
52
+ uniform pbrMaterialUniforms {
53
+ // Material is unlit
54
+ bool unlit;
55
+
56
+ // Base color map
57
+ bool baseColorMapEnabled;
58
+ vec4 baseColorFactor;
59
+
60
+ bool normalMapEnabled;
61
+ float normalScale; // #ifdef HAS_NORMALMAP
62
+
63
+ bool emissiveMapEnabled;
64
+ vec3 emissiveFactor; // #ifdef HAS_EMISSIVEMAP
65
+
66
+ vec2 metallicRoughnessValues;
67
+ bool metallicRoughnessMapEnabled;
68
+
69
+ bool occlusionMapEnabled;
70
+ float occlusionStrength; // #ifdef HAS_OCCLUSIONMAP
71
+
72
+ bool alphaCutoffEnabled;
73
+ float alphaCutoff; // #ifdef ALPHA_CUTOFF
74
+
75
+ // IBL
76
+ bool IBLenabled;
77
+ vec2 scaleIBLAmbient; // #ifdef USE_IBL
78
+
79
+ // debugging flags used for shader output of intermediate PBR variables
80
+ // #ifdef PBR_DEBUG
81
+ vec4 scaleDiffBaseMR;
82
+ vec4 scaleFGDSpec;
83
+ // #endif
84
+ } pbrMaterial;
85
+
86
+ // Samplers
87
+ #ifdef HAS_BASECOLORMAP
88
+ uniform sampler2D pbr_baseColorSampler;
89
+ #endif
90
+ #ifdef HAS_NORMALMAP
91
+ uniform sampler2D pbr_normalSampler;
92
+ #endif
93
+ #ifdef HAS_EMISSIVEMAP
94
+ uniform sampler2D pbr_emissiveSampler;
95
+ #endif
96
+ #ifdef HAS_METALROUGHNESSMAP
97
+ uniform sampler2D pbr_metallicRoughnessSampler;
98
+ #endif
99
+ #ifdef HAS_OCCLUSIONMAP
100
+ uniform sampler2D pbr_occlusionSampler;
101
+ #endif
102
+ #ifdef USE_IBL
103
+ uniform samplerCube pbr_diffuseEnvSampler;
104
+ uniform samplerCube pbr_specularEnvSampler;
105
+ uniform sampler2D pbr_brdfLUT;
106
+ #endif
107
+
108
+ // Inputs from vertex shader
109
+
110
+ in vec3 pbr_vPosition;
111
+ in vec2 pbr_vUV;
112
+
113
+ #ifdef HAS_NORMALS
114
+ #ifdef HAS_TANGENTS
115
+ in mat3 pbr_vTBN;
116
+ #else
117
+ in vec3 pbr_vNormal;
118
+ #endif
119
+ #endif
120
+
121
+ // Encapsulate the various inputs used by the various functions in the shading equation
122
+ // We store values in this struct to simplify the integration of alternative implementations
123
+ // of the shading terms, outlined in the Readme.MD Appendix.
124
+ struct PBRInfo {
125
+ float NdotL; // cos angle between normal and light direction
126
+ float NdotV; // cos angle between normal and view direction
127
+ float NdotH; // cos angle between normal and half vector
128
+ float LdotH; // cos angle between light direction and half vector
129
+ float VdotH; // cos angle between view direction and half vector
130
+ float perceptualRoughness; // roughness value, as authored by the model creator (input to shader)
131
+ float metalness; // metallic value at the surface
132
+ vec3 reflectance0; // full reflectance color (normal incidence angle)
133
+ vec3 reflectance90; // reflectance color at grazing angle
134
+ float alphaRoughness; // roughness mapped to a more linear change in the roughness (proposed by [2])
135
+ vec3 diffuseColor; // color contribution from diffuse lighting
136
+ vec3 specularColor; // color contribution from specular lighting
137
+ vec3 n; // normal at surface point
138
+ vec3 v; // vector from surface point to camera
139
+ };
140
+
141
+ const float M_PI = 3.141592653589793;
142
+ const float c_MinRoughness = 0.04;
143
+
144
+ vec4 SRGBtoLINEAR(vec4 srgbIn)
145
+ {
146
+ #ifdef MANUAL_SRGB
147
+ #ifdef SRGB_FAST_APPROXIMATION
148
+ vec3 linOut = pow(srgbIn.xyz,vec3(2.2));
149
+ #else // SRGB_FAST_APPROXIMATION
150
+ vec3 bLess = step(vec3(0.04045),srgbIn.xyz);
151
+ vec3 linOut = mix( srgbIn.xyz/vec3(12.92), pow((srgbIn.xyz+vec3(0.055))/vec3(1.055),vec3(2.4)), bLess );
152
+ #endif //SRGB_FAST_APPROXIMATION
153
+ return vec4(linOut,srgbIn.w);;
154
+ #else //MANUAL_SRGB
155
+ return srgbIn;
156
+ #endif //MANUAL_SRGB
157
+ }
158
+
159
+ // Find the normal for this fragment, pulling either from a predefined normal map
160
+ // or from the interpolated mesh normal and tangent attributes.
161
+ vec3 getNormal()
162
+ {
163
+ // Retrieve the tangent space matrix
164
+ #ifndef HAS_TANGENTS
165
+ vec3 pos_dx = dFdx(pbr_vPosition);
166
+ vec3 pos_dy = dFdy(pbr_vPosition);
167
+ vec3 tex_dx = dFdx(vec3(pbr_vUV, 0.0));
168
+ vec3 tex_dy = dFdy(vec3(pbr_vUV, 0.0));
169
+ vec3 t = (tex_dy.t * pos_dx - tex_dx.t * pos_dy) / (tex_dx.s * tex_dy.t - tex_dy.s * tex_dx.t);
170
+
171
+ #ifdef HAS_NORMALS
172
+ vec3 ng = normalize(pbr_vNormal);
173
+ #else
174
+ vec3 ng = cross(pos_dx, pos_dy);
175
+ #endif
176
+
177
+ t = normalize(t - ng * dot(ng, t));
178
+ vec3 b = normalize(cross(ng, t));
179
+ mat3 tbn = mat3(t, b, ng);
180
+ #else // HAS_TANGENTS
181
+ mat3 tbn = pbr_vTBN;
182
+ #endif
183
+
184
+ #ifdef HAS_NORMALMAP
185
+ vec3 n = texture(pbr_normalSampler, pbr_vUV).rgb;
186
+ n = normalize(tbn * ((2.0 * n - 1.0) * vec3(pbrMaterial.normalScale, pbrMaterial.normalScale, 1.0)));
187
+ #else
188
+ // The tbn matrix is linearly interpolated, so we need to re-normalize
189
+ vec3 n = normalize(tbn[2].xyz);
190
+ #endif
191
+
192
+ return n;
193
+ }
194
+
195
+ // Calculation of the lighting contribution from an optional Image Based Light source.
196
+ // Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1].
197
+ // See our README.md on Environment Maps [3] for additional discussion.
198
+ #ifdef USE_IBL
199
+ vec3 getIBLContribution(PBRInfo pbrInfo, vec3 n, vec3 reflection)
200
+ {
201
+ float mipCount = 9.0; // resolution of 512x512
202
+ float lod = (pbrInfo.perceptualRoughness * mipCount);
203
+ // retrieve a scale and bias to F0. See [1], Figure 3
204
+ vec3 brdf = SRGBtoLINEAR(texture(pbr_brdfLUT,
205
+ vec2(pbrInfo.NdotV, 1.0 - pbrInfo.perceptualRoughness))).rgb;
206
+ vec3 diffuseLight = SRGBtoLINEAR(texture(pbr_diffuseEnvSampler, n)).rgb;
207
+
208
+ #ifdef USE_TEX_LOD
209
+ vec3 specularLight = SRGBtoLINEAR(texture(pbr_specularEnvSampler, reflection, lod)).rgb;
210
+ #else
211
+ vec3 specularLight = SRGBtoLINEAR(texture(pbr_specularEnvSampler, reflection)).rgb;
212
+ #endif
213
+
214
+ vec3 diffuse = diffuseLight * pbrInfo.diffuseColor;
215
+ vec3 specular = specularLight * (pbrInfo.specularColor * brdf.x + brdf.y);
216
+
217
+ // For presentation, this allows us to disable IBL terms
218
+ diffuse *= pbrMaterial.scaleIBLAmbient.x;
219
+ specular *= pbrMaterial.scaleIBLAmbient.y;
220
+
221
+ return diffuse + specular;
222
+ }
223
+ #endif
224
+
225
+ // Basic Lambertian diffuse
226
+ // Implementation from Lambert's Photometria https://archive.org/details/lambertsphotome00lambgoog
227
+ // See also [1], Equation 1
228
+ vec3 diffuse(PBRInfo pbrInfo)
229
+ {
230
+ return pbrInfo.diffuseColor / M_PI;
231
+ }
232
+
233
+ // The following equation models the Fresnel reflectance term of the spec equation (aka F())
234
+ // Implementation of fresnel from [4], Equation 15
235
+ vec3 specularReflection(PBRInfo pbrInfo)
236
+ {
237
+ return pbrInfo.reflectance0 +
238
+ (pbrInfo.reflectance90 - pbrInfo.reflectance0) *
239
+ pow(clamp(1.0 - pbrInfo.VdotH, 0.0, 1.0), 5.0);
240
+ }
241
+
242
+ // This calculates the specular geometric attenuation (aka G()),
243
+ // where rougher material will reflect less light back to the viewer.
244
+ // This implementation is based on [1] Equation 4, and we adopt their modifications to
245
+ // alphaRoughness as input as originally proposed in [2].
246
+ float geometricOcclusion(PBRInfo pbrInfo)
247
+ {
248
+ float NdotL = pbrInfo.NdotL;
249
+ float NdotV = pbrInfo.NdotV;
250
+ float r = pbrInfo.alphaRoughness;
251
+
252
+ float attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));
253
+ float attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));
254
+ return attenuationL * attenuationV;
255
+ }
256
+
257
+ // The following equation(s) model the distribution of microfacet normals across
258
+ // the area being drawn (aka D())
259
+ // Implementation from "Average Irregularity Representation of a Roughened Surface
260
+ // for Ray Reflection" by T. S. Trowbridge, and K. P. Reitz
261
+ // Follows the distribution function recommended in the SIGGRAPH 2013 course notes
262
+ // from EPIC Games [1], Equation 3.
263
+ float microfacetDistribution(PBRInfo pbrInfo)
264
+ {
265
+ float roughnessSq = pbrInfo.alphaRoughness * pbrInfo.alphaRoughness;
266
+ float f = (pbrInfo.NdotH * roughnessSq - pbrInfo.NdotH) * pbrInfo.NdotH + 1.0;
267
+ return roughnessSq / (M_PI * f * f);
268
+ }
269
+
270
+ void PBRInfo_setAmbientLight(inout PBRInfo pbrInfo) {
271
+ pbrInfo.NdotL = 1.0;
272
+ pbrInfo.NdotH = 0.0;
273
+ pbrInfo.LdotH = 0.0;
274
+ pbrInfo.VdotH = 1.0;
275
+ }
276
+
277
+ void PBRInfo_setDirectionalLight(inout PBRInfo pbrInfo, vec3 lightDirection) {
278
+ vec3 n = pbrInfo.n;
279
+ vec3 v = pbrInfo.v;
280
+ vec3 l = normalize(lightDirection); // Vector from surface point to light
281
+ vec3 h = normalize(l+v); // Half vector between both l and v
282
+
283
+ pbrInfo.NdotL = clamp(dot(n, l), 0.001, 1.0);
284
+ pbrInfo.NdotH = clamp(dot(n, h), 0.0, 1.0);
285
+ pbrInfo.LdotH = clamp(dot(l, h), 0.0, 1.0);
286
+ pbrInfo.VdotH = clamp(dot(v, h), 0.0, 1.0);
287
+ }
288
+
289
+ void PBRInfo_setPointLight(inout PBRInfo pbrInfo, PointLight pointLight) {
290
+ vec3 light_direction = normalize(pointLight.position - pbr_vPosition);
291
+ PBRInfo_setDirectionalLight(pbrInfo, light_direction);
292
+ }
293
+
294
+ vec3 calculateFinalColor(PBRInfo pbrInfo, vec3 lightColor) {
295
+ // Calculate the shading terms for the microfacet specular shading model
296
+ vec3 F = specularReflection(pbrInfo);
297
+ float G = geometricOcclusion(pbrInfo);
298
+ float D = microfacetDistribution(pbrInfo);
299
+
300
+ // Calculation of analytical lighting contribution
301
+ vec3 diffuseContrib = (1.0 - F) * diffuse(pbrInfo);
302
+ vec3 specContrib = F * G * D / (4.0 * pbrInfo.NdotL * pbrInfo.NdotV);
303
+ // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law)
304
+ return pbrInfo.NdotL * lightColor * (diffuseContrib + specContrib);
305
+ }
306
+
307
+ vec4 pbr_filterColor(vec4 colorUnused)
308
+ {
309
+ // The albedo may be defined from a base texture or a flat color
310
+ #ifdef HAS_BASECOLORMAP
311
+ vec4 baseColor = SRGBtoLINEAR(texture(pbr_baseColorSampler, pbr_vUV)) * pbrMaterial.baseColorFactor;
312
+ #else
313
+ vec4 baseColor = pbrMaterial.baseColorFactor;
314
+ #endif
315
+
316
+ #ifdef ALPHA_CUTOFF
317
+ if (baseColor.a < pbrMaterial.alphaCutoff) {
318
+ discard;
319
+ }
320
+ #endif
321
+
322
+ vec3 color = vec3(0, 0, 0);
323
+
324
+ if(pbrMaterial.unlit){
325
+ color.rgb = baseColor.rgb;
326
+ }
327
+ else{
328
+ // Metallic and Roughness material properties are packed together
329
+ // In glTF, these factors can be specified by fixed scalar values
330
+ // or from a metallic-roughness map
331
+ float perceptualRoughness = pbrMaterial.metallicRoughnessValues.y;
332
+ float metallic = pbrMaterial.metallicRoughnessValues.x;
333
+ #ifdef HAS_METALROUGHNESSMAP
334
+ // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
335
+ // This layout intentionally reserves the 'r' channel for (optional) occlusion map data
336
+ vec4 mrSample = texture(pbr_metallicRoughnessSampler, pbr_vUV);
337
+ perceptualRoughness = mrSample.g * perceptualRoughness;
338
+ metallic = mrSample.b * metallic;
339
+ #endif
340
+ perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);
341
+ metallic = clamp(metallic, 0.0, 1.0);
342
+ // Roughness is authored as perceptual roughness; as is convention,
343
+ // convert to material roughness by squaring the perceptual roughness [2].
344
+ float alphaRoughness = perceptualRoughness * perceptualRoughness;
345
+
346
+ vec3 f0 = vec3(0.04);
347
+ vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0);
348
+ diffuseColor *= 1.0 - metallic;
349
+ vec3 specularColor = mix(f0, baseColor.rgb, metallic);
350
+
351
+ // Compute reflectance.
352
+ float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);
353
+
354
+ // For typical incident reflectance range (between 4% to 100%) set the grazing
355
+ // reflectance to 100% for typical fresnel effect.
356
+ // For very low reflectance range on highly diffuse objects (below 4%),
357
+ // incrementally reduce grazing reflecance to 0%.
358
+ float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);
359
+ vec3 specularEnvironmentR0 = specularColor.rgb;
360
+ vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;
361
+
362
+ vec3 n = getNormal(); // normal at surface point
363
+ vec3 v = normalize(pbrProjection.camera - pbr_vPosition); // Vector from surface point to camera
364
+
365
+ float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
366
+ vec3 reflection = -normalize(reflect(v, n));
367
+
368
+ PBRInfo pbrInfo = PBRInfo(
369
+ 0.0, // NdotL
370
+ NdotV,
371
+ 0.0, // NdotH
372
+ 0.0, // LdotH
373
+ 0.0, // VdotH
374
+ perceptualRoughness,
375
+ metallic,
376
+ specularEnvironmentR0,
377
+ specularEnvironmentR90,
378
+ alphaRoughness,
379
+ diffuseColor,
380
+ specularColor,
381
+ n,
382
+ v
383
+ );
384
+
385
+
386
+ #ifdef USE_LIGHTS
387
+ // Apply ambient light
388
+ PBRInfo_setAmbientLight(pbrInfo);
389
+ color += calculateFinalColor(pbrInfo, lighting.ambientColor);
390
+
391
+ // Apply directional light
392
+ for(int i = 0; i < lighting.directionalLightCount; i++) {
393
+ if (i < lighting.directionalLightCount) {
394
+ PBRInfo_setDirectionalLight(pbrInfo, lighting_getDirectionalLight(i).direction);
395
+ color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);
396
+ }
397
+ }
398
+
399
+ // Apply point light
400
+ for(int i = 0; i < lighting.pointLightCount; i++) {
401
+ if (i < lighting.pointLightCount) {
402
+ PBRInfo_setPointLight(pbrInfo, lighting_getPointLight(i));
403
+ float attenuation = getPointLightAttenuation(lighting_getPointLight(i), distance(lighting_getPointLight(i).position, pbr_vPosition));
404
+ color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color / attenuation);
405
+ }
406
+ }
407
+ #endif
408
+
409
+ // Calculate lighting contribution from image based lighting source (IBL)
410
+ #ifdef USE_IBL
411
+ if (pbrMaterial.IBLenabled) {
412
+ color += getIBLContribution(pbrInfo, n, reflection);
413
+ }
414
+ #endif
415
+
416
+ // Apply optional PBR terms for additional (optional) shading
417
+ #ifdef HAS_OCCLUSIONMAP
418
+ if (pbrMaterial.occlusionMapEnabled) {
419
+ float ao = texture(pbr_occlusionSampler, pbr_vUV).r;
420
+ color = mix(color, color * ao, pbrMaterial.occlusionStrength);
421
+ }
422
+ #endif
423
+
424
+ #ifdef HAS_EMISSIVEMAP
425
+ if (pbrMaterial.emissiveMapEnabled) {
426
+ vec3 emissive = SRGBtoLINEAR(texture(pbr_emissiveSampler, pbr_vUV)).rgb * pbrMaterial.emissiveFactor;
427
+ color += emissive;
428
+ }
429
+ #endif
430
+
431
+ // This section uses mix to override final color for reference app visualization
432
+ // of various parameters in the lighting equation.
433
+ #ifdef PBR_DEBUG
434
+ // TODO: Figure out how to debug multiple lights
435
+
436
+ // color = mix(color, F, pbr_scaleFGDSpec.x);
437
+ // color = mix(color, vec3(G), pbr_scaleFGDSpec.y);
438
+ // color = mix(color, vec3(D), pbr_scaleFGDSpec.z);
439
+ // color = mix(color, specContrib, pbr_scaleFGDSpec.w);
440
+
441
+ // color = mix(color, diffuseContrib, pbr_scaleDiffBaseMR.x);
442
+ color = mix(color, baseColor.rgb, pbrMaterial.scaleDiffBaseMR.y);
443
+ color = mix(color, vec3(metallic), pbrMaterial.scaleDiffBaseMR.z);
444
+ color = mix(color, vec3(perceptualRoughness), pbrMaterial.scaleDiffBaseMR.w);
445
+ #endif
446
+
447
+ }
448
+
449
+ return vec4(pow(color,vec3(1.0/2.2)), baseColor.a);
450
+ }
451
+ `;
452
+
453
+ // luma.gl
454
+ // SPDX-License-Identifier: MIT
455
+ // Copyright (c) vis.gl contributors
456
+ // Attribution:
457
+ // MIT license, Copyright (c) 2016-2017 Mohamad Moneimne and Contributors
458
+ // This fragment shader defines a reference implementation for Physically Based Shading of
459
+ // a microfacet surface material defined by a glTF model.
460
+ // TODO - better do the checks outside of shader
461
+ const source = /* wgsl */ `\
462
+ struct PBRFragmentInputs {
463
+ pbr_vPosition: vec3f,
464
+ pbr_vUV: vec2f,
465
+ pbr_vTBN: mat3f,
466
+ pbr_vNormal: vec3f
467
+ };
468
+
469
+ var fragmentInputs: PBRFragmentInputs;
470
+
471
+ fn pbr_setPositionNormalTangentUV(position: vec4f, normal: vec4f, tangent: vec4f, uv: vec2f)
472
+ {
473
+ var pos: vec4f = pbrProjection.modelMatrix * position;
474
+ pbr_vPosition = vec3(pos.xyz) / pos.w;
475
+
476
+ #ifdef HAS_NORMALS
477
+ #ifdef HAS_TANGENTS
478
+ let normalW: vec3f = normalize(vec3(pbrProjection.normalMatrix * vec4(normal.xyz, 0.0)));
479
+ let tangentW: vec3f = normalize(vec3(pbrProjection.modelMatrix * vec4(tangent.xyz, 0.0)));
480
+ let bitangentW: vec3f = cross(normalW, tangentW) * tangent.w;
481
+ fragmentInputs,pbr_vTBN = mat3(tangentW, bitangentW, normalW);
482
+ #else // HAS_TANGENTS != 1
483
+ fragmentInputs.pbr_vNormal = normalize(vec3(pbrProjection.modelMatrix * vec4(normal.xyz, 0.0)));
484
+ #endif
485
+ #endif
486
+
487
+ #ifdef HAS_UV
488
+ pbr_vUV = uv;
489
+ #else
490
+ pbr_vUV = vec2(0.,0.);
491
+ #endif
492
+ }
493
+
494
+ struct pbrMaterialUniforms {
495
+ // Material is unlit
496
+ unlit: uint32,
497
+
498
+ // Base color map
499
+ baseColorMapEnabled: uint32,
500
+ baseColorFactor: vec4f,
501
+
502
+ normalMapEnabled : uint32,
503
+ normalScale: f32, // #ifdef HAS_NORMALMAP
504
+
505
+ emissiveMapEnabled: uint32,
506
+ emissiveFactor: vec3f, // #ifdef HAS_EMISSIVEMAP
507
+
508
+ metallicRoughnessValues: vec2f,
509
+ metallicRoughnessMapEnabled: uint32,
510
+
511
+ occlusionMapEnabled: i32,
512
+ occlusionStrength: f32, // #ifdef HAS_OCCLUSIONMAP
513
+
514
+ alphaCutoffEnabled: i32,
515
+ alphaCutoff: f32, // #ifdef ALPHA_CUTOFF
516
+
517
+ // IBL
518
+ IBLenabled: i32,
519
+ scaleIBLAmbient: vec2f, // #ifdef USE_IBL
520
+
521
+ // debugging flags used for shader output of intermediate PBR variables
522
+ // #ifdef PBR_DEBUG
523
+ scaleDiffBaseMR: vec4f,
524
+ scaleFGDSpec: vec4f
525
+ // #endif
526
+ }
527
+
528
+ @binding(2) @group(0) var<uniform> material : pbrMaterialUniforms;
529
+
530
+ // Samplers
531
+ #ifdef HAS_BASECOLORMAP
532
+ uniform sampler2D pbr_baseColorSampler;
533
+ #endif
534
+ #ifdef HAS_NORMALMAP
535
+ uniform sampler2D pbr_normalSampler;
536
+ #endif
537
+ #ifdef HAS_EMISSIVEMAP
538
+ uniform sampler2D pbr_emissiveSampler;
539
+ #endif
540
+ #ifdef HAS_METALROUGHNESSMAP
541
+ uniform sampler2D pbr_metallicRoughnessSampler;
542
+ #endif
543
+ #ifdef HAS_OCCLUSIONMAP
544
+ uniform sampler2D pbr_occlusionSampler;
545
+ #endif
546
+ #ifdef USE_IBL
547
+ uniform samplerCube pbr_diffuseEnvSampler;
548
+ uniform samplerCube pbr_specularEnvSampler;
549
+ uniform sampler2D pbr_brdfLUT;
550
+ #endif
551
+
552
+ // Encapsulate the various inputs used by the various functions in the shading equation
553
+ // We store values in this struct to simplify the integration of alternative implementations
554
+ // of the shading terms, outlined in the Readme.MD Appendix.
555
+ struct PBRInfo {
556
+ NdotL: f32, // cos angle between normal and light direction
557
+ NdotV: f32, // cos angle between normal and view direction
558
+ NdotH: f32, // cos angle between normal and half vector
559
+ LdotH: f32, // cos angle between light direction and half vector
560
+ VdotH: f32, // cos angle between view direction and half vector
561
+ perceptualRoughness: f32, // roughness value, as authored by the model creator (input to shader)
562
+ metalness: f32, // metallic value at the surface
563
+ reflectance0: vec3f, // full reflectance color (normal incidence angle)
564
+ reflectance90: vec3f, // reflectance color at grazing angle
565
+ alphaRoughness: f32, // roughness mapped to a more linear change in the roughness (proposed by [2])
566
+ diffuseColor: vec3f, // color contribution from diffuse lighting
567
+ specularColor: vec3f, // color contribution from specular lighting
568
+ n: vec3f, // normal at surface point
569
+ v: vec3f, // vector from surface point to camera
570
+ };
571
+
572
+ const M_PI = 3.141592653589793;
573
+ const c_MinRoughness = 0.04;
574
+
575
+ fn SRGBtoLINEAR(srgbIn: vec4f ) -> vec4f
576
+ {
577
+ #ifdef MANUAL_SRGB
578
+ #ifdef SRGB_FAST_APPROXIMATION
579
+ var linOut: vec3f = pow(srgbIn.xyz,vec3(2.2));
580
+ #else // SRGB_FAST_APPROXIMATION
581
+ var bLess: vec3f = step(vec3(0.04045),srgbIn.xyz);
582
+ var linOut: vec3f = mix( srgbIn.xyz/vec3(12.92), pow((srgbIn.xyz+vec3(0.055))/vec3(1.055),vec3(2.4)), bLess );
583
+ #endif //SRGB_FAST_APPROXIMATION
584
+ return vec4f(linOut,srgbIn.w);;
585
+ #else //MANUAL_SRGB
586
+ return srgbIn;
587
+ #endif //MANUAL_SRGB
588
+ }
589
+
590
+ // Find the normal for this fragment, pulling either from a predefined normal map
591
+ // or from the interpolated mesh normal and tangent attributes.
592
+ fn getNormal() -> vec3f
593
+ {
594
+ // Retrieve the tangent space matrix
595
+ #ifndef HAS_TANGENTS
596
+ var pos_dx: vec3f = dFdx(pbr_vPosition);
597
+ var pos_dy: vec3f = dFdy(pbr_vPosition);
598
+ var tex_dx: vec3f = dFdx(vec3(pbr_vUV, 0.0));
599
+ var tex_dy: vec3f = dFdy(vec3(pbr_vUV, 0.0));
600
+ var t: vec3f = (tex_dy.t * pos_dx - tex_dx.t * pos_dy) / (tex_dx.s * tex_dy.t - tex_dy.s * tex_dx.t);
601
+
602
+ #ifdef HAS_NORMALS
603
+ var ng: vec3f = normalize(pbr_vNormal);
604
+ #else
605
+ var ng: vec3f = cross(pos_dx, pos_dy);
606
+ #endif
607
+
608
+ t = normalize(t - ng * dot(ng, t));
609
+ var b: vec3f = normalize(cross(ng, t));
610
+ var tbn: mat3f = mat3f(t, b, ng);
611
+ #else // HAS_TANGENTS
612
+ var tbn: mat3f = pbr_vTBN;
613
+ #endif
614
+
615
+ #ifdef HAS_NORMALMAP
616
+ vec3 n = texture(pbr_normalSampler, pbr_vUV).rgb;
617
+ n = normalize(tbn * ((2.0 * n - 1.0) * vec3(pbrMaterial.normalScale, pbrMaterial.normalScale, 1.0)));
618
+ #else
619
+ // The tbn matrix is linearly interpolated, so we need to re-normalize
620
+ vec3 n = normalize(tbn[2].xyz);
621
+ #endif
622
+
623
+ return n;
624
+ }
625
+
626
+ // Calculation of the lighting contribution from an optional Image Based Light source.
627
+ // Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1].
628
+ // See our README.md on Environment Maps [3] for additional discussion.
629
+ #ifdef USE_IBL
630
+ fn getIBLContribution(PBRInfo pbrInfo, vec3 n, vec3 reflection) -> vec3f
631
+ {
632
+ float mipCount = 9.0; // resolution of 512x512
633
+ float lod = (pbrInfo.perceptualRoughness * mipCount);
634
+ // retrieve a scale and bias to F0. See [1], Figure 3
635
+ vec3 brdf = SRGBtoLINEAR(texture(pbr_brdfLUT,
636
+ vec2(pbrInfo.NdotV, 1.0 - pbrInfo.perceptualRoughness))).rgb;
637
+ vec3 diffuseLight = SRGBtoLINEAR(texture(pbr_diffuseEnvSampler, n)).rgb;
638
+
639
+ #ifdef USE_TEX_LOD
640
+ vec3 specularLight = SRGBtoLINEAR(texture(pbr_specularEnvSampler, reflection, lod)).rgb;
641
+ #else
642
+ vec3 specularLight = SRGBtoLINEAR(texture(pbr_specularEnvSampler, reflection)).rgb;
643
+ #endif
644
+
645
+ vec3 diffuse = diffuseLight * pbrInfo.diffuseColor;
646
+ vec3 specular = specularLight * (pbrInfo.specularColor * brdf.x + brdf.y);
647
+
648
+ // For presentation, this allows us to disable IBL terms
649
+ diffuse *= pbrMaterial.scaleIBLAmbient.x;
650
+ specular *= pbrMaterial.scaleIBLAmbient.y;
651
+
652
+ return diffuse + specular;
653
+ }
654
+ #endif
655
+
656
+ // Basic Lambertian diffuse
657
+ // Implementation from Lambert's Photometria https://archive.org/details/lambertsphotome00lambgoog
658
+ // See also [1], Equation 1
659
+ fn diffuse(pbrInfo: PBRInfo) -> vec3<f32> {
660
+ return pbrInfo.diffuseColor / PI;
661
+ }
662
+
663
+ // The following equation models the Fresnel reflectance term of the spec equation (aka F())
664
+ // Implementation of fresnel from [4], Equation 15
665
+ fn specularReflection(pbrInfo: PBRInfo) -> vec3<f32> {
666
+ return pbrInfo.reflectance0 +
667
+ (pbrInfo.reflectance90 - pbrInfo.reflectance0) *
668
+ pow(clamp(1.0 - pbrInfo.VdotH, 0.0, 1.0), 5.0);
669
+ }
670
+
671
+ // This calculates the specular geometric attenuation (aka G()),
672
+ // where rougher material will reflect less light back to the viewer.
673
+ // This implementation is based on [1] Equation 4, and we adopt their modifications to
674
+ // alphaRoughness as input as originally proposed in [2].
675
+ fn geometricOcclusion(pbrInfo: PBRInfo) -> f32 {
676
+ let NdotL: f32 = pbrInfo.NdotL;
677
+ let NdotV: f32 = pbrInfo.NdotV;
678
+ let r: f32 = pbrInfo.alphaRoughness;
679
+
680
+ let attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));
681
+ let attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));
682
+ return attenuationL * attenuationV;
683
+ }
684
+
685
+ // The following equation(s) model the distribution of microfacet normals across
686
+ // the area being drawn (aka D())
687
+ // Implementation from "Average Irregularity Representation of a Roughened Surface
688
+ // for Ray Reflection" by T. S. Trowbridge, and K. P. Reitz
689
+ // Follows the distribution function recommended in the SIGGRAPH 2013 course notes
690
+ // from EPIC Games [1], Equation 3.
691
+ fn microfacetDistribution(pbrInfo: PBRInfo) -> f32 {
692
+ let roughnessSq = pbrInfo.alphaRoughness * pbrInfo.alphaRoughness;
693
+ let f = (pbrInfo.NdotH * roughnessSq - pbrInfo.NdotH) * pbrInfo.NdotH + 1.0;
694
+ return roughnessSq / (PI * f * f);
695
+ }
696
+
697
+ fn PBRInfo_setAmbientLight(pbrInfo: ptr<function, PBRInfo>) {
698
+ (*pbrInfo).NdotL = 1.0;
699
+ (*pbrInfo).NdotH = 0.0;
700
+ (*pbrInfo).LdotH = 0.0;
701
+ (*pbrInfo).VdotH = 1.0;
702
+ }
703
+
704
+ fn PBRInfo_setDirectionalLight(pbrInfo: ptr<function, PBRInfo>, lightDirection: vec3<f32>) {
705
+ let n = (*pbrInfo).n;
706
+ let v = (*pbrInfo).v;
707
+ let l = normalize(lightDirection); // Vector from surface point to light
708
+ let h = normalize(l + v); // Half vector between both l and v
709
+
710
+ (*pbrInfo).NdotL = clamp(dot(n, l), 0.001, 1.0);
711
+ (*pbrInfo).NdotH = clamp(dot(n, h), 0.0, 1.0);
712
+ (*pbrInfo).LdotH = clamp(dot(l, h), 0.0, 1.0);
713
+ (*pbrInfo).VdotH = clamp(dot(v, h), 0.0, 1.0);
714
+ }
715
+
716
+ fn PBRInfo_setPointLight(pbrInfo: ptr<function, PBRInfo>, pointLight: PointLight) {
717
+ let light_direction = normalize(pointLight.position - pbr_vPosition);
718
+ PBRInfo_setDirectionalLight(pbrInfo, light_direction);
719
+ }
720
+
721
+ fn calculateFinalColor(pbrInfo: PBRInfo, lightColor: vec3<f32>) -> vec3<f32> {
722
+ // Calculate the shading terms for the microfacet specular shading model
723
+ let F = specularReflection(pbrInfo);
724
+ let G = geometricOcclusion(pbrInfo);
725
+ let D = microfacetDistribution(pbrInfo);
726
+
727
+ // Calculation of analytical lighting contribution
728
+ let diffuseContrib = (1.0 - F) * diffuse(pbrInfo);
729
+ let specContrib = F * G * D / (4.0 * pbrInfo.NdotL * pbrInfo.NdotV);
730
+ // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law)
731
+ return pbrInfo.NdotL * lightColor * (diffuseContrib + specContrib);
732
+ }
733
+
734
+ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
735
+ // The albedo may be defined from a base texture or a flat color
736
+ var baseColor: vec4<f32>;
737
+ #ifdef HAS_BASECOLORMAP
738
+ baseColor = SRGBtoLINEAR(textureSample(pbr_baseColorSampler, pbr_baseColorSampler, pbr_vUV)) * pbrMaterial.baseColorFactor;
739
+ #else
740
+ baseColor = pbrMaterial.baseColorFactor;
741
+ #endif
742
+
743
+ #ifdef ALPHA_CUTOFF
744
+ if (baseColor.a < pbrMaterial.alphaCutoff) {
745
+ discard;
746
+ }
747
+ #endif
748
+
749
+ var color = vec3<f32>(0.0, 0.0, 0.0);
750
+
751
+ if (pbrMaterial.unlit) {
752
+ color = baseColor.rgb;
753
+ } else {
754
+ // Metallic and Roughness material properties are packed together
755
+ // In glTF, these factors can be specified by fixed scalar values
756
+ // or from a metallic-roughness map
757
+ var perceptualRoughness = pbrMaterial.metallicRoughnessValues.y;
758
+ var metallic = pbrMaterial.metallicRoughnessValues.x;
759
+ #ifdef HAS_METALROUGHNESSMAP
760
+ // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
761
+ // This layout intentionally reserves the 'r' channel for (optional) occlusion map data
762
+ let mrSample = textureSample(pbr_metallicRoughnessSampler, pbr_metallicRoughnessSampler, pbr_vUV);
763
+ perceptualRoughness = mrSample.g * perceptualRoughness;
764
+ metallic = mrSample.b * metallic;
765
+ #endif
766
+ perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);
767
+ metallic = clamp(metallic, 0.0, 1.0);
768
+ // Roughness is authored as perceptual roughness; as is convention,
769
+ // convert to material roughness by squaring the perceptual roughness [2].
770
+ let alphaRoughness = perceptualRoughness * perceptualRoughness;
771
+
772
+ let f0 = vec3<f32>(0.04);
773
+ var diffuseColor = baseColor.rgb * (vec3<f32>(1.0) - f0);
774
+ diffuseColor *= 1.0 - metallic;
775
+ let specularColor = mix(f0, baseColor.rgb, metallic);
776
+
777
+ // Compute reflectance.
778
+ let reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);
779
+
780
+ // For typical incident reflectance range (between 4% to 100%) set the grazing
781
+ // reflectance to 100% for typical fresnel effect.
782
+ // For very low reflectance range on highly diffuse objects (below 4%),
783
+ // incrementally reduce grazing reflectance to 0%.
784
+ let reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);
785
+ let specularEnvironmentR0 = specularColor;
786
+ let specularEnvironmentR90 = vec3<f32>(1.0, 1.0, 1.0) * reflectance90;
787
+
788
+ let n = getNormal(); // normal at surface point
789
+ let v = normalize(pbrProjection.camera - pbr_vPosition); // Vector from surface point to camera
790
+
791
+ let NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
792
+ let reflection = -normalize(reflect(v, n));
793
+
794
+ var pbrInfo = PBRInfo(
795
+ 0.0, // NdotL
796
+ NdotV,
797
+ 0.0, // NdotH
798
+ 0.0, // LdotH
799
+ 0.0, // VdotH
800
+ perceptualRoughness,
801
+ metallic,
802
+ specularEnvironmentR0,
803
+ specularEnvironmentR90,
804
+ alphaRoughness,
805
+ diffuseColor,
806
+ specularColor,
807
+ n,
808
+ v
809
+ );
810
+
811
+ #ifdef USE_LIGHTS
812
+ // Apply ambient light
813
+ PBRInfo_setAmbientLight(&pbrInfo);
814
+ color += calculateFinalColor(pbrInfo, lighting.ambientColor);
815
+
816
+ // Apply directional light
817
+ for (var i = 0; i < lighting.directionalLightCount; i++) {
818
+ if (i < lighting.directionalLightCount) {
819
+ PBRInfo_setDirectionalLight(&pbrInfo, lighting_getDirectionalLight(i).direction);
820
+ color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);
821
+ }
822
+ }
823
+
824
+ // Apply point light
825
+ for (var i = 0; i < lighting.pointLightCount; i++) {
826
+ if (i < lighting.pointLightCount) {
827
+ PBRInfo_setPointLight(&pbrInfo, lighting_getPointLight(i));
828
+ let attenuation = getPointLightAttenuation(lighting_getPointLight(i), distance(lighting_getPointLight(i).position, pbr_vPosition));
829
+ color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color / attenuation);
830
+ }
831
+ }
832
+ #endif
833
+
834
+ // Calculate lighting contribution from image based lighting source (IBL)
835
+ #ifdef USE_IBL
836
+ if (pbrMaterial.IBLenabled) {
837
+ color += getIBLContribution(pbrInfo, n, reflection);
838
+ }
839
+ #endif
840
+
841
+ // Apply optional PBR terms for additional (optional) shading
842
+ #ifdef HAS_OCCLUSIONMAP
843
+ if (pbrMaterial.occlusionMapEnabled) {
844
+ let ao = textureSample(pbr_occlusionSampler, pbr_occlusionSampler, pbr_vUV).r;
845
+ color = mix(color, color * ao, pbrMaterial.occlusionStrength);
846
+ }
847
+ #endif
848
+
849
+ #ifdef HAS_EMISSIVEMAP
850
+ if (pbrMaterial.emissiveMapEnabled) {
851
+ let emissive = SRGBtoLINEAR(textureSample(pbr_emissiveSampler, pbr_emissiveSampler, pbr_vUV)).rgb * pbrMaterial.emissiveFactor;
852
+ color += emissive;
853
+ }
854
+ #endif
855
+
856
+ // This section uses mix to override final color for reference app visualization
857
+ // of various parameters in the lighting equation.
858
+ #ifdef PBR_DEBUG
859
+ // TODO: Figure out how to debug multiple lights
860
+
861
+ // color = mix(color, F, pbr_scaleFGDSpec.x);
862
+ // color = mix(color, vec3(G), pbr_scaleFGDSpec.y);
863
+ // color = mix(color, vec3(D), pbr_scaleFGDSpec.z);
864
+ // color = mix(color, specContrib, pbr_scaleFGDSpec.w);
865
+
866
+ // color = mix(color, diffuseContrib, pbr_scaleDiffBaseMR.x);
867
+ color = mix(color, baseColor.rgb, pbrMaterial.scaleDiffBaseMR.y);
868
+ color = mix(color, vec3<f32>(metallic), pbrMaterial.scaleDiffBaseMR.z);
869
+ color = mix(color, vec3<f32>(perceptualRoughness), pbrMaterial.scaleDiffBaseMR.w);
870
+ #endif
871
+ }
872
+
873
+ return vec4<f32>(pow(color, vec3<f32>(1.0 / 2.2)), baseColor.a);
874
+ }
875
+ `;
876
+
877
+ // luma.gl
878
+ // SPDX-License-Identifier: MIT
879
+ // Copyright (c) vis.gl contributors
880
+ const uniformBlock$1 = /* glsl */ `\
881
+ uniform pbrProjectionUniforms {
882
+ mat4 modelViewProjectionMatrix;
883
+ mat4 modelMatrix;
884
+ mat4 normalMatrix;
885
+ vec3 camera;
886
+ } pbrProjection;
887
+ `;
888
+ const pbrProjection = {
889
+ name: 'pbrProjection',
890
+ vs: uniformBlock$1,
891
+ fs: uniformBlock$1,
892
+ // TODO why is this needed?
893
+ getUniforms: props => props,
894
+ uniformTypes: {
895
+ modelViewProjectionMatrix: 'mat4x4<f32>',
896
+ modelMatrix: 'mat4x4<f32>',
897
+ normalMatrix: 'mat4x4<f32>',
898
+ camera: 'vec3<i32>'
899
+ }
900
+ };
901
+
902
+ // luma.gl
903
+ // SPDX-License-Identifier: MIT
904
+ // Copyright (c) vis.gl contributors
905
+ /**
906
+ * An implementation of PBR (Physically-Based Rendering).
907
+ * Physically Based Shading of a microfacet surface defined by a glTF material.
908
+ */
909
+ const pbrMaterial = {
910
+ props: {},
911
+ uniforms: {},
912
+ name: 'pbrMaterial',
913
+ dependencies: [deckProvider.lighting, pbrProjection],
914
+ source,
915
+ vs: vs$2,
916
+ fs: fs$2,
917
+ defines: {
918
+ LIGHTING_FRAGMENT: true,
919
+ HAS_NORMALMAP: false,
920
+ HAS_EMISSIVEMAP: false,
921
+ HAS_OCCLUSIONMAP: false,
922
+ HAS_BASECOLORMAP: false,
923
+ HAS_METALROUGHNESSMAP: false,
924
+ ALPHA_CUTOFF: false,
925
+ USE_IBL: false,
926
+ PBR_DEBUG: false
927
+ },
928
+ getUniforms: props => props,
929
+ uniformTypes: {
930
+ // Material is unlit
931
+ unlit: 'i32',
932
+ // Base color map
933
+ baseColorMapEnabled: 'i32',
934
+ baseColorFactor: 'vec4<f32>',
935
+ normalMapEnabled: 'i32',
936
+ normalScale: 'f32', // #ifdef HAS_NORMALMAP
937
+ emissiveMapEnabled: 'i32',
938
+ emissiveFactor: 'vec3<f32>', // #ifdef HAS_EMISSIVEMAP
939
+ metallicRoughnessValues: 'vec2<f32>',
940
+ metallicRoughnessMapEnabled: 'i32',
941
+ occlusionMapEnabled: 'i32',
942
+ occlusionStrength: 'f32', // #ifdef HAS_OCCLUSIONMAP
943
+ alphaCutoffEnabled: 'i32',
944
+ alphaCutoff: 'f32', // #ifdef ALPHA_CUTOFF
945
+ // IBL
946
+ IBLenabled: 'i32',
947
+ scaleIBLAmbient: 'vec2<f32>', // #ifdef USE_IBL
948
+ // debugging flags used for shader output of intermediate PBR variables
949
+ // #ifdef PBR_DEBUG
950
+ scaleDiffBaseMR: 'vec4<f32>',
951
+ scaleFGDSpec: 'vec4<f32>'
952
+ }
953
+ };
954
+
955
+ // luma.gl
956
+ // SPDX-License-Identifier: MIT
957
+ // Copyright (c) vis.gl contributors
958
+ class ScenegraphNode {
959
+ id;
960
+ matrix = new deckProvider.Matrix4();
961
+ display = true;
962
+ position = new deckProvider.Vector3();
963
+ rotation = new deckProvider.Vector3();
964
+ scale = new deckProvider.Vector3(1, 1, 1);
965
+ userData = {};
966
+ props = {};
967
+ constructor(props = {}) {
968
+ const { id } = props;
969
+ this.id = id || deckProvider.uid(this.constructor.name);
970
+ this._setScenegraphNodeProps(props);
971
+ }
972
+ getBounds() {
973
+ return null;
974
+ }
975
+ destroy() { }
976
+ /** @deprecated use .destroy() */
977
+ delete() {
978
+ this.destroy();
979
+ }
980
+ setProps(props) {
981
+ this._setScenegraphNodeProps(props);
982
+ return this;
983
+ }
984
+ toString() {
985
+ return `{type: ScenegraphNode, id: ${this.id})}`;
986
+ }
987
+ setPosition(position) {
988
+ // assert(position.length === 3, 'setPosition requires vector argument');
989
+ this.position = position;
990
+ return this;
991
+ }
992
+ setRotation(rotation) {
993
+ // assert(rotation.length === 3, 'setRotation requires vector argument');
994
+ this.rotation = rotation;
995
+ return this;
996
+ }
997
+ setScale(scale) {
998
+ // assert(scale.length === 3, 'setScale requires vector argument');
999
+ this.scale = scale;
1000
+ return this;
1001
+ }
1002
+ setMatrix(matrix, copyMatrix = true) {
1003
+ if (copyMatrix) {
1004
+ this.matrix.copy(matrix);
1005
+ }
1006
+ else {
1007
+ this.matrix = matrix;
1008
+ }
1009
+ }
1010
+ setMatrixComponents(components) {
1011
+ const { position, rotation, scale, update = true } = components;
1012
+ if (position) {
1013
+ this.setPosition(position);
1014
+ }
1015
+ if (rotation) {
1016
+ this.setRotation(rotation);
1017
+ }
1018
+ if (scale) {
1019
+ this.setScale(scale);
1020
+ }
1021
+ if (update) {
1022
+ this.updateMatrix();
1023
+ }
1024
+ return this;
1025
+ }
1026
+ updateMatrix() {
1027
+ const pos = this.position;
1028
+ const rot = this.rotation;
1029
+ const scale = this.scale;
1030
+ this.matrix.identity();
1031
+ this.matrix.translate(pos);
1032
+ this.matrix.rotateXYZ(rot);
1033
+ this.matrix.scale(scale);
1034
+ return this;
1035
+ }
1036
+ update(options = {}) {
1037
+ const { position, rotation, scale } = options;
1038
+ if (position) {
1039
+ this.setPosition(position);
1040
+ }
1041
+ if (rotation) {
1042
+ this.setRotation(rotation);
1043
+ }
1044
+ if (scale) {
1045
+ this.setScale(scale);
1046
+ }
1047
+ this.updateMatrix();
1048
+ return this;
1049
+ }
1050
+ getCoordinateUniforms(viewMatrix, modelMatrix) {
1051
+ // TODO - solve multiple class problem
1052
+ // assert(viewMatrix instanceof Matrix4);
1053
+ // assert(viewMatrix);
1054
+ modelMatrix = modelMatrix || this.matrix;
1055
+ const worldMatrix = new deckProvider.Matrix4(viewMatrix).multiplyRight(modelMatrix);
1056
+ const worldInverse = worldMatrix.invert();
1057
+ const worldInverseTranspose = worldInverse.transpose();
1058
+ return {
1059
+ viewMatrix,
1060
+ modelMatrix,
1061
+ objectMatrix: modelMatrix,
1062
+ worldMatrix,
1063
+ worldInverseMatrix: worldInverse,
1064
+ worldInverseTransposeMatrix: worldInverseTranspose
1065
+ };
1066
+ }
1067
+ // TODO - copied code, not yet vetted
1068
+ /*
1069
+ transform() {
1070
+ if (!this.parent) {
1071
+ this.endPosition.set(this.position);
1072
+ this.endRotation.set(this.rotation);
1073
+ this.endScale.set(this.scale);
1074
+ } else {
1075
+ const parent = this.parent;
1076
+ this.endPosition.set(this.position.add(parent.endPosition));
1077
+ this.endRotation.set(this.rotation.add(parent.endRotation));
1078
+ this.endScale.set(this.scale.add(parent.endScale));
1079
+ }
1080
+
1081
+ const ch = this.children;
1082
+ for (let i = 0; i < ch.length; ++i) {
1083
+ ch[i].transform();
1084
+ }
1085
+
1086
+ return this;
1087
+ }
1088
+ */
1089
+ _setScenegraphNodeProps(props) {
1090
+ // if ('display' in props) {
1091
+ // this.display = props.display;
1092
+ // }
1093
+ if ('position' in props) {
1094
+ this.setPosition(props.position);
1095
+ }
1096
+ if ('rotation' in props) {
1097
+ this.setRotation(props.rotation);
1098
+ }
1099
+ if ('scale' in props) {
1100
+ this.setScale(props.scale);
1101
+ }
1102
+ // Matrix overwrites other props
1103
+ if ('matrix' in props) {
1104
+ this.setMatrix(props.matrix);
1105
+ }
1106
+ Object.assign(this.props, props);
1107
+ }
1108
+ }
1109
+
1110
+ // luma.gl
1111
+ // SPDX-License-Identifier: MIT
1112
+ // Copyright (c) vis.gl contributors
1113
+ class GroupNode extends ScenegraphNode {
1114
+ children;
1115
+ constructor(props = {}) {
1116
+ props = Array.isArray(props) ? { children: props } : props;
1117
+ const { children = [] } = props;
1118
+ deckProvider.log.assert(children.every(child => child instanceof ScenegraphNode), 'every child must an instance of ScenegraphNode');
1119
+ super(props);
1120
+ this.children = children;
1121
+ }
1122
+ getBounds() {
1123
+ const result = [
1124
+ [Infinity, Infinity, Infinity],
1125
+ [-Infinity, -Infinity, -Infinity]
1126
+ ];
1127
+ this.traverse((node, { worldMatrix }) => {
1128
+ const bounds = node.getBounds();
1129
+ if (!bounds) {
1130
+ return;
1131
+ }
1132
+ const [min, max] = bounds;
1133
+ const center = new deckProvider.Vector3(min).add(max).divide([2, 2, 2]);
1134
+ worldMatrix.transformAsPoint(center, center);
1135
+ const halfSize = new deckProvider.Vector3(max).subtract(min).divide([2, 2, 2]);
1136
+ worldMatrix.transformAsVector(halfSize, halfSize);
1137
+ for (let v = 0; v < 8; v++) {
1138
+ // Test all 8 corners of the box
1139
+ const position = new deckProvider.Vector3(v & 0b001 ? -1 : 1, v & 0b010 ? -1 : 1, v & 0b100 ? -1 : 1)
1140
+ .multiply(halfSize)
1141
+ .add(center);
1142
+ for (let i = 0; i < 3; i++) {
1143
+ result[0][i] = Math.min(result[0][i], position[i]);
1144
+ result[1][i] = Math.max(result[1][i], position[i]);
1145
+ }
1146
+ }
1147
+ });
1148
+ if (!Number.isFinite(result[0][0])) {
1149
+ return null;
1150
+ }
1151
+ return result;
1152
+ }
1153
+ destroy() {
1154
+ this.children.forEach(child => child.destroy());
1155
+ this.removeAll();
1156
+ super.destroy();
1157
+ }
1158
+ // Unpacks arrays and nested arrays of children
1159
+ add(...children) {
1160
+ for (const child of children) {
1161
+ if (Array.isArray(child)) {
1162
+ this.add(...child);
1163
+ }
1164
+ else {
1165
+ this.children.push(child);
1166
+ }
1167
+ }
1168
+ return this;
1169
+ }
1170
+ remove(child) {
1171
+ const children = this.children;
1172
+ const indexOf = children.indexOf(child);
1173
+ if (indexOf > -1) {
1174
+ children.splice(indexOf, 1);
1175
+ }
1176
+ return this;
1177
+ }
1178
+ removeAll() {
1179
+ this.children = [];
1180
+ return this;
1181
+ }
1182
+ traverse(visitor, { worldMatrix = new deckProvider.Matrix4() } = {}) {
1183
+ const modelMatrix = new deckProvider.Matrix4(worldMatrix).multiplyRight(this.matrix);
1184
+ for (const child of this.children) {
1185
+ if (child instanceof GroupNode) {
1186
+ child.traverse(visitor, { worldMatrix: modelMatrix });
1187
+ }
1188
+ else {
1189
+ visitor(child, { worldMatrix: modelMatrix });
1190
+ }
1191
+ }
1192
+ }
1193
+ }
1194
+
1195
+ // luma.gl
1196
+ // SPDX-License-Identifier: MIT
1197
+ // Copyright (c) vis.gl contributors
1198
+ class ModelNode extends ScenegraphNode {
1199
+ model;
1200
+ bounds = null;
1201
+ managedResources;
1202
+ // TODO - is this used? override callbacks to make sure we call them with this
1203
+ // onBeforeRender = null;
1204
+ // onAfterRender = null;
1205
+ // AfterRender = null;
1206
+ constructor(props) {
1207
+ super(props);
1208
+ // Create new Model or used supplied Model
1209
+ this.model = props.model;
1210
+ this.managedResources = props.managedResources || [];
1211
+ this.bounds = props.bounds || null;
1212
+ this.setProps(props);
1213
+ }
1214
+ destroy() {
1215
+ if (this.model) {
1216
+ this.model.destroy();
1217
+ // @ts-expect-error
1218
+ this.model = null;
1219
+ }
1220
+ this.managedResources.forEach(resource => resource.destroy());
1221
+ this.managedResources = [];
1222
+ }
1223
+ getBounds() {
1224
+ return this.bounds;
1225
+ }
1226
+ // Expose model methods
1227
+ draw(renderPass) {
1228
+ // Return value indicates if something was actually drawn
1229
+ return this.model.draw(renderPass);
1230
+ }
1231
+ }
1232
+
1233
+ // luma.gl
1234
+ // SPDX-License-Identifier: MIT
1235
+ // Copyright (c) vis.gl contributors
1236
+ function convertSampler(gltfSampler) {
1237
+ return {
1238
+ addressModeU: convertSamplerWrapMode(gltfSampler.wrapS),
1239
+ addressModeV: convertSamplerWrapMode(gltfSampler.wrapT),
1240
+ magFilter: convertSamplerMagFilter(gltfSampler.magFilter),
1241
+ ...convertSamplerMinFilter(gltfSampler.minFilter)
1242
+ };
1243
+ }
1244
+ function convertSamplerWrapMode(mode) {
1245
+ switch (mode) {
1246
+ case 33071:
1247
+ return 'clamp-to-edge';
1248
+ case 10497:
1249
+ return 'repeat';
1250
+ case 33648:
1251
+ return 'mirror-repeat';
1252
+ default:
1253
+ return undefined;
1254
+ }
1255
+ }
1256
+ function convertSamplerMagFilter(mode) {
1257
+ switch (mode) {
1258
+ case 9728:
1259
+ return 'nearest';
1260
+ case 9729:
1261
+ return 'linear';
1262
+ default:
1263
+ return undefined;
1264
+ }
1265
+ }
1266
+ function convertSamplerMinFilter(mode) {
1267
+ switch (mode) {
1268
+ case 9728:
1269
+ return { minFilter: 'nearest' };
1270
+ case 9729:
1271
+ return { minFilter: 'linear' };
1272
+ case 9984:
1273
+ return { minFilter: 'nearest', mipmapFilter: 'nearest' };
1274
+ case 9985:
1275
+ return { minFilter: 'linear', mipmapFilter: 'nearest' };
1276
+ case 9986:
1277
+ return { minFilter: 'nearest', mipmapFilter: 'linear' };
1278
+ case 9987:
1279
+ return { minFilter: 'linear', mipmapFilter: 'linear' };
1280
+ default:
1281
+ return {};
1282
+ }
1283
+ }
1284
+
1285
+ // luma.gl
1286
+ // SPDX-License-Identifier: MIT
1287
+ // Copyright (c) vis.gl contributors
1288
+ /**
1289
+ * Parses a GLTF material definition into uniforms and parameters for the PBR shader module
1290
+ */
1291
+ function parsePBRMaterial(device, material, attributes, options) {
1292
+ const parsedMaterial = {
1293
+ defines: {
1294
+ // TODO: Use EXT_sRGB if available (Standard in WebGL 2.0)
1295
+ MANUAL_SRGB: true,
1296
+ SRGB_FAST_APPROXIMATION: true
1297
+ },
1298
+ bindings: {},
1299
+ uniforms: {
1300
+ // TODO: find better values?
1301
+ camera: [0, 0, 0], // Model should override
1302
+ metallicRoughnessValues: [1, 1] // Default is 1 and 1
1303
+ },
1304
+ parameters: {},
1305
+ glParameters: {},
1306
+ generatedTextures: []
1307
+ };
1308
+ // TODO - always available
1309
+ parsedMaterial.defines['USE_TEX_LOD'] = true;
1310
+ const { imageBasedLightingEnvironment } = options;
1311
+ if (imageBasedLightingEnvironment) {
1312
+ parsedMaterial.bindings.pbr_diffuseEnvSampler =
1313
+ imageBasedLightingEnvironment.diffuseEnvSampler.texture;
1314
+ parsedMaterial.bindings.pbr_specularEnvSampler =
1315
+ imageBasedLightingEnvironment.specularEnvSampler.texture;
1316
+ parsedMaterial.bindings.pbr_BrdfLUT = imageBasedLightingEnvironment.brdfLutTexture.texture;
1317
+ parsedMaterial.uniforms.scaleIBLAmbient = [1, 1];
1318
+ }
1319
+ if (options?.pbrDebug) {
1320
+ parsedMaterial.defines['PBR_DEBUG'] = true;
1321
+ // Override final color for reference app visualization of various parameters in the lighting equation.
1322
+ parsedMaterial.uniforms.scaleDiffBaseMR = [0, 0, 0, 0];
1323
+ parsedMaterial.uniforms.scaleFGDSpec = [0, 0, 0, 0];
1324
+ }
1325
+ if (attributes['NORMAL'])
1326
+ parsedMaterial.defines['HAS_NORMALS'] = true;
1327
+ if (attributes['TANGENT'] && options?.useTangents)
1328
+ parsedMaterial.defines['HAS_TANGENTS'] = true;
1329
+ if (attributes['TEXCOORD_0'])
1330
+ parsedMaterial.defines['HAS_UV'] = true;
1331
+ if (options?.imageBasedLightingEnvironment)
1332
+ parsedMaterial.defines['USE_IBL'] = true;
1333
+ if (options?.lights)
1334
+ parsedMaterial.defines['USE_LIGHTS'] = true;
1335
+ if (material) {
1336
+ parseMaterial(device, material, parsedMaterial);
1337
+ }
1338
+ return parsedMaterial;
1339
+ }
1340
+ /** Parse GLTF material record */
1341
+ function parseMaterial(device, material, parsedMaterial) {
1342
+ parsedMaterial.uniforms.unlit = Boolean(material.unlit);
1343
+ if (material.pbrMetallicRoughness) {
1344
+ parsePbrMetallicRoughness(device, material.pbrMetallicRoughness, parsedMaterial);
1345
+ }
1346
+ if (material.normalTexture) {
1347
+ addTexture(device, material.normalTexture, 'pbr_normalSampler', 'HAS_NORMALMAP', parsedMaterial);
1348
+ const { scale = 1 } = material.normalTexture;
1349
+ parsedMaterial.uniforms.normalScale = scale;
1350
+ }
1351
+ if (material.occlusionTexture) {
1352
+ addTexture(device, material.occlusionTexture, 'pbr_occlusionSampler', 'HAS_OCCLUSIONMAP', parsedMaterial);
1353
+ const { strength = 1 } = material.occlusionTexture;
1354
+ parsedMaterial.uniforms.occlusionStrength = strength;
1355
+ }
1356
+ if (material.emissiveTexture) {
1357
+ addTexture(device, material.emissiveTexture, 'pbr_emissiveSampler', 'HAS_EMISSIVEMAP', parsedMaterial);
1358
+ parsedMaterial.uniforms.emissiveFactor = material.emissiveFactor || [0, 0, 0];
1359
+ }
1360
+ switch (material.alphaMode || 'MASK') {
1361
+ case 'MASK':
1362
+ const { alphaCutoff = 0.5 } = material;
1363
+ parsedMaterial.defines['ALPHA_CUTOFF'] = true;
1364
+ parsedMaterial.uniforms.alphaCutoff = alphaCutoff;
1365
+ break;
1366
+ case 'BLEND':
1367
+ deckProvider.log.warn('glTF BLEND alphaMode might not work well because it requires mesh sorting')();
1368
+ // WebGPU style parameters
1369
+ parsedMaterial.parameters.blend = true;
1370
+ parsedMaterial.parameters.blendColorOperation = 'add';
1371
+ parsedMaterial.parameters.blendColorSrcFactor = 'src-alpha';
1372
+ parsedMaterial.parameters.blendColorDstFactor = 'one-minus-src-alpha';
1373
+ parsedMaterial.parameters.blendAlphaOperation = 'add';
1374
+ parsedMaterial.parameters.blendAlphaSrcFactor = 'one';
1375
+ parsedMaterial.parameters.blendAlphaDstFactor = 'one-minus-src-alpha';
1376
+ // GL parameters
1377
+ // TODO - remove in favor of parameters
1378
+ parsedMaterial.glParameters['blend'] = true;
1379
+ parsedMaterial.glParameters['blendEquation'] = 32774;
1380
+ parsedMaterial.glParameters['blendFunc'] = [
1381
+ 770,
1382
+ 771,
1383
+ 1,
1384
+ 771
1385
+ ];
1386
+ break;
1387
+ }
1388
+ }
1389
+ /** Parse GLTF material sub record */
1390
+ function parsePbrMetallicRoughness(device, pbrMetallicRoughness, parsedMaterial) {
1391
+ if (pbrMetallicRoughness.baseColorTexture) {
1392
+ addTexture(device, pbrMetallicRoughness.baseColorTexture, 'pbr_baseColorSampler', 'HAS_BASECOLORMAP', parsedMaterial);
1393
+ }
1394
+ parsedMaterial.uniforms.baseColorFactor = pbrMetallicRoughness.baseColorFactor || [1, 1, 1, 1];
1395
+ if (pbrMetallicRoughness.metallicRoughnessTexture) {
1396
+ addTexture(device, pbrMetallicRoughness.metallicRoughnessTexture, 'pbr_metallicRoughnessSampler', 'HAS_METALROUGHNESSMAP', parsedMaterial);
1397
+ }
1398
+ const { metallicFactor = 1, roughnessFactor = 1 } = pbrMetallicRoughness;
1399
+ parsedMaterial.uniforms.metallicRoughnessValues = [metallicFactor, roughnessFactor];
1400
+ }
1401
+ /** Create a texture from a glTF texture/sampler/image combo and add it to bindings */
1402
+ function addTexture(device, gltfTexture, uniformName, define, parsedMaterial) {
1403
+ const image = gltfTexture.texture.source.image;
1404
+ let textureOptions;
1405
+ if (image.compressed) {
1406
+ textureOptions = image;
1407
+ }
1408
+ else {
1409
+ // Texture2D accepts a promise that returns an image as data (Async Textures)
1410
+ textureOptions = { data: image };
1411
+ }
1412
+ const gltfSampler = {
1413
+ wrapS: 10497, // default REPEAT S (U) wrapping mode.
1414
+ wrapT: 10497, // default REPEAT T (V) wrapping mode.
1415
+ ...gltfTexture?.texture?.sampler
1416
+ };
1417
+ const texture = device.createTexture({
1418
+ id: gltfTexture.uniformName || gltfTexture.id,
1419
+ sampler: convertSampler(gltfSampler),
1420
+ ...textureOptions
1421
+ });
1422
+ parsedMaterial.bindings[uniformName] = texture;
1423
+ if (define)
1424
+ parsedMaterial.defines[define] = true;
1425
+ parsedMaterial.generatedTextures.push(texture);
1426
+ }
1427
+ /*
1428
+ /**
1429
+ * Parses a GLTF material definition into uniforms and parameters for the PBR shader module
1430
+ *
1431
+ export class PBRMaterialParser {
1432
+ readonly device: Device;
1433
+
1434
+ readonly defines: Record<string, boolean>;
1435
+ readonly bindings: Record<string, Binding>;
1436
+ readonly uniforms: Record<string, any>;
1437
+ readonly parameters: Record<string, any>;
1438
+
1439
+ /** Hold on to generated textures, we destroy them in the destroy method *
1440
+ readonly generatedTextures: Texture[];
1441
+
1442
+ constructor(device: Device, props: PBRMaterialParserProps) {
1443
+ const {attributes, material, pbrDebug, imageBasedLightingEnvironment, lights, useTangents} =
1444
+ props;
1445
+ this.device = device;
1446
+
1447
+ this.defines = {
1448
+ // TODO: Use EXT_sRGB if available (Standard in WebGL 2.0)
1449
+ MANUAL_SRGB: true,
1450
+ SRGB_FAST_APPROXIMATION: true
1451
+ };
1452
+
1453
+ if (this.device.features.has('glsl-texture-lod')) {
1454
+ this.defines.USE_TEX_LOD = true;
1455
+ }
1456
+
1457
+ this.uniforms = {
1458
+ // TODO: find better values?
1459
+ camera: [0, 0, 0], // Model should override
1460
+
1461
+ metallicRoughnessValues: [1, 1] // Default is 1 and 1
1462
+ };
1463
+
1464
+ this.bindings = {};
1465
+
1466
+ this.parameters = {};
1467
+ this.generatedTextures = [];
1468
+
1469
+ if (imageBasedLightingEnvironment) {
1470
+ this.bindings.pbr_diffuseEnvSampler = imageBasedLightingEnvironment.getDiffuseEnvSampler();
1471
+ this.bindings.pbr_specularEnvSampler = imageBasedLightingEnvironment.getSpecularEnvSampler();
1472
+ this.bindings.pbr_BrdfLUT = imageBasedLightingEnvironment.getBrdfTexture();
1473
+ this.uniforms.scaleIBLAmbient = [1, 1];
1474
+ }
1475
+
1476
+ if (pbrDebug) {
1477
+ // Override final color for reference app visualization
1478
+ // of various parameters in the lighting equation.
1479
+ this.uniforms.scaleDiffBaseMR = [0, 0, 0, 0];
1480
+ this.uniforms.scaleFGDSpec = [0, 0, 0, 0];
1481
+ }
1482
+
1483
+ this.defineIfPresent(attributes.NORMAL, 'HAS_NORMALS');
1484
+ this.defineIfPresent(attributes.TANGENT && useTangents, 'HAS_TANGENTS');
1485
+ this.defineIfPresent(attributes.TEXCOORD_0, 'HAS_UV');
1486
+
1487
+ this.defineIfPresent(imageBasedLightingEnvironment, 'USE_IBL');
1488
+ this.defineIfPresent(lights, 'USE_LIGHTS');
1489
+ this.defineIfPresent(pbrDebug, 'PBR_DEBUG');
1490
+
1491
+ if (material) {
1492
+ this.parseMaterial(material);
1493
+ }
1494
+ }
1495
+
1496
+ /**
1497
+ * Destroy all generated resources to release memory.
1498
+ *
1499
+ destroy(): void {
1500
+ this.generatedTextures.forEach(texture => texture.destroy());
1501
+ }
1502
+
1503
+ /** Add a define if the the value is non-nullish *
1504
+ defineIfPresent(value: unknown, name: string): void {
1505
+ if (value) {
1506
+ this.defines[name] = 1;
1507
+ }
1508
+ }
1509
+
1510
+ /** Parse GLTF material record *
1511
+ parseMaterial(material) {
1512
+ this.uniforms.unlit = Boolean(material.unlit);
1513
+
1514
+ if (material.pbrMetallicRoughness) {
1515
+ this.parsePbrMetallicRoughness(material.pbrMetallicRoughness);
1516
+ }
1517
+ if (material.normalTexture) {
1518
+ this.addTexture(material.normalTexture, 'pbr_normalSampler', 'HAS_NORMALMAP');
1519
+
1520
+ const {scale = 1} = material.normalTexture;
1521
+ this.uniforms.normalScale = scale;
1522
+ }
1523
+ if (material.occlusionTexture) {
1524
+ this.addTexture(material.occlusionTexture, 'pbr_occlusionSampler', 'HAS_OCCLUSIONMAP');
1525
+
1526
+ const {strength = 1} = material.occlusionTexture;
1527
+ this.uniforms.occlusionStrength = strength;
1528
+ }
1529
+ if (material.emissiveTexture) {
1530
+ this.addTexture(material.emissiveTexture, 'pbr_emissiveSampler', 'HAS_EMISSIVEMAP');
1531
+ this.uniforms.emissiveFactor = material.emissiveFactor || [0, 0, 0];
1532
+ }
1533
+ if (material.alphaMode === 'MASK') {
1534
+ const {alphaCutoff = 0.5} = material;
1535
+ this.defines.ALPHA_CUTOFF = true;
1536
+ this.uniforms.u_AlphaCutoff = alphaCutoff;
1537
+ } else if (material.alphaMode === 'BLEND') {
1538
+ log.warn('BLEND alphaMode might not work well because it requires mesh sorting')();
1539
+ Object.assign(this.parameters, {
1540
+ blend: true,
1541
+ blendEquation: GL.FUNC_ADD,
1542
+ blendFunc: [GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA, GL.ONE, GL.ONE_MINUS_SRC_ALPHA]
1543
+ });
1544
+ }
1545
+ }
1546
+
1547
+ /** Parse GLTF material sub record *
1548
+ parsePbrMetallicRoughness(pbrMetallicRoughness) {
1549
+ if (pbrMetallicRoughness.baseColorTexture) {
1550
+ this.addTexture(
1551
+ pbrMetallicRoughness.baseColorTexture,
1552
+ 'pbr_baseColorSampler',
1553
+ 'HAS_BASECOLORMAP'
1554
+ );
1555
+ }
1556
+ this.uniforms.baseColorFactor = pbrMetallicRoughness.baseColorFactor || [1, 1, 1, 1];
1557
+
1558
+ if (pbrMetallicRoughness.metallicRoughnessTexture) {
1559
+ this.addTexture(
1560
+ pbrMetallicRoughness.metallicRoughnessTexture,
1561
+ 'pbr_metallicRoughnessSampler',
1562
+ 'HAS_METALROUGHNESSMAP'
1563
+ );
1564
+ }
1565
+ const {metallicFactor = 1, roughnessFactor = 1} = pbrMetallicRoughness;
1566
+ this.uniforms.metallicRoughnessValues = [metallicFactor, roughnessFactor];
1567
+ }
1568
+
1569
+ /** Create a texture from a glTF texture/sampler/image combo and add it to bindings *
1570
+ addTexture(gltfTexture, name, define = null) {
1571
+ const parameters = gltfTexture?.texture?.sampler?.parameters || {};
1572
+
1573
+ const image = gltfTexture.texture.source.image;
1574
+ let textureOptions;
1575
+ let specialTextureParameters = {};
1576
+ if (image.compressed) {
1577
+ textureOptions = image;
1578
+ specialTextureParameters = {
1579
+ [GL.TEXTURE_MIN_FILTER]: image.data.length > 1 ? GL.LINEAR_MIPMAP_NEAREST : GL.LINEAR
1580
+ };
1581
+ } else {
1582
+ // Texture2D accepts a promise that returns an image as data (Async Textures)
1583
+ textureOptions = {data: image};
1584
+ }
1585
+
1586
+ const texture: Texture = this.device.createTexture({
1587
+ id: gltfTexture.name || gltfTexture.id,
1588
+ parameters: {
1589
+ ...parameters,
1590
+ ...specialTextureParameters
1591
+ },
1592
+ pixelStore: {
1593
+ [GL.UNPACK_FLIP_Y_WEBGL]: false
1594
+ },
1595
+ ...textureOptions
1596
+ });
1597
+ this.bindings[name] = texture;
1598
+ this.defineIfPresent(define, define);
1599
+ this.generatedTextures.push(texture);
1600
+ }
1601
+ }
1602
+ */
1603
+
1604
+ // luma.gl
1605
+ // SPDX-License-Identifier: MIT
1606
+ // Copyright (c) vis.gl contributors
1607
+ // NOTE: Modules other than `@luma.gl/webgl` should not import `GL` from
1608
+ // `@luma.gl/constants`. Locally we use `GLEnum` instead of `GL` to avoid
1609
+ // conflicts with the `babel-plugin-inline-webgl-constants` plugin.
1610
+ // eslint-disable-next-line no-shadow
1611
+ var GLEnum;
1612
+ (function (GLEnum) {
1613
+ GLEnum[GLEnum["POINTS"] = 0] = "POINTS";
1614
+ GLEnum[GLEnum["LINES"] = 1] = "LINES";
1615
+ GLEnum[GLEnum["LINE_LOOP"] = 2] = "LINE_LOOP";
1616
+ GLEnum[GLEnum["LINE_STRIP"] = 3] = "LINE_STRIP";
1617
+ GLEnum[GLEnum["TRIANGLES"] = 4] = "TRIANGLES";
1618
+ GLEnum[GLEnum["TRIANGLE_STRIP"] = 5] = "TRIANGLE_STRIP";
1619
+ GLEnum[GLEnum["TRIANGLE_FAN"] = 6] = "TRIANGLE_FAN";
1620
+ })(GLEnum || (GLEnum = {}));
1621
+ function convertGLDrawModeToTopology(drawMode) {
1622
+ // prettier-ignore
1623
+ switch (drawMode) {
1624
+ case GLEnum.POINTS: return 'point-list';
1625
+ case GLEnum.LINES: return 'line-list';
1626
+ case GLEnum.LINE_STRIP: return 'line-strip';
1627
+ case GLEnum.TRIANGLES: return 'triangle-list';
1628
+ case GLEnum.TRIANGLE_STRIP: return 'triangle-strip';
1629
+ default: throw new Error(String(drawMode));
1630
+ }
1631
+ }
1632
+
1633
+ // luma.gl
1634
+ // SPDX-License-Identifier: MIT
1635
+ // Copyright (c) vis.gl contributors
1636
+ const SHADER = /* WGSL */ `
1637
+ layout(0) positions: vec4; // in vec4 POSITION;
1638
+
1639
+ #ifdef HAS_NORMALS
1640
+ in vec4 normals; // in vec4 NORMAL;
1641
+ #endif
1642
+
1643
+ #ifdef HAS_TANGENTS
1644
+ in vec4 TANGENT;
1645
+ #endif
1646
+
1647
+ #ifdef HAS_UV
1648
+ // in vec2 TEXCOORD_0;
1649
+ in vec2 texCoords;
1650
+ #endif
1651
+
1652
+ @vertex
1653
+ void main(void) {
1654
+ vec4 _NORMAL = vec4(0.);
1655
+ vec4 _TANGENT = vec4(0.);
1656
+ vec2 _TEXCOORD_0 = vec2(0.);
1657
+
1658
+ #ifdef HAS_NORMALS
1659
+ _NORMAL = normals;
1660
+ #endif
1661
+
1662
+ #ifdef HAS_TANGENTS
1663
+ _TANGENT = TANGENT;
1664
+ #endif
1665
+
1666
+ #ifdef HAS_UV
1667
+ _TEXCOORD_0 = texCoords;
1668
+ #endif
1669
+
1670
+ pbr_setPositionNormalTangentUV(positions, _NORMAL, _TANGENT, _TEXCOORD_0);
1671
+ gl_Position = u_MVPMatrix * positions;
1672
+ }
1673
+
1674
+ @fragment
1675
+ out vec4 fragmentColor;
1676
+
1677
+ void main(void) {
1678
+ vec3 pos = pbr_vPosition;
1679
+ fragmentColor = pbr_filterColor(vec4(1.0));
1680
+ }
1681
+ `;
1682
+ // TODO rename attributes to POSITION/NORMAL etc
1683
+ // See gpu-geometry.ts: getAttributeBuffersFromGeometry()
1684
+ const vs$1 = /* glsl */ `\
1685
+ #version 300 es
1686
+
1687
+ // in vec4 POSITION;
1688
+ in vec4 positions;
1689
+
1690
+ #ifdef HAS_NORMALS
1691
+ // in vec4 NORMAL;
1692
+ in vec4 normals;
1693
+ #endif
1694
+
1695
+ #ifdef HAS_TANGENTS
1696
+ in vec4 TANGENT;
1697
+ #endif
1698
+
1699
+ #ifdef HAS_UV
1700
+ // in vec2 TEXCOORD_0;
1701
+ in vec2 texCoords;
1702
+ #endif
1703
+
1704
+ void main(void) {
1705
+ vec4 _NORMAL = vec4(0.);
1706
+ vec4 _TANGENT = vec4(0.);
1707
+ vec2 _TEXCOORD_0 = vec2(0.);
1708
+
1709
+ #ifdef HAS_NORMALS
1710
+ _NORMAL = normals;
1711
+ #endif
1712
+
1713
+ #ifdef HAS_TANGENTS
1714
+ _TANGENT = TANGENT;
1715
+ #endif
1716
+
1717
+ #ifdef HAS_UV
1718
+ _TEXCOORD_0 = texCoords;
1719
+ #endif
1720
+
1721
+ pbr_setPositionNormalTangentUV(positions, _NORMAL, _TANGENT, _TEXCOORD_0);
1722
+ gl_Position = pbrProjection.modelViewProjectionMatrix * positions;
1723
+ }
1724
+ `;
1725
+ const fs$1 = /* glsl */ `\
1726
+ #version 300 es
1727
+ out vec4 fragmentColor;
1728
+
1729
+ void main(void) {
1730
+ vec3 pos = pbr_vPosition;
1731
+ fragmentColor = pbr_filterColor(vec4(1.0));
1732
+ }
1733
+ `;
1734
+ /** Creates a luma.gl Model from GLTF data*/
1735
+ function createGLTFModel(device, options) {
1736
+ const { id, geometry, parsedPPBRMaterial, vertexCount, modelOptions = {} } = options;
1737
+ deckProvider.log.info(4, 'createGLTFModel defines: ', parsedPPBRMaterial.defines)();
1738
+ // Calculate managedResources
1739
+ // TODO: Implement resource management logic that will
1740
+ // not deallocate resources/textures/buffers that are shared
1741
+ const managedResources = [];
1742
+ // managedResources.push(...parsedMaterial.generatedTextures);
1743
+ // managedResources.push(...Object.values(attributes).map((attribute) => attribute.buffer));
1744
+ const parameters = {
1745
+ depthWriteEnabled: true,
1746
+ depthCompare: 'less',
1747
+ depthFormat: 'depth24plus',
1748
+ cullMode: 'back'
1749
+ };
1750
+ const modelProps = {
1751
+ id,
1752
+ source: SHADER,
1753
+ vs: vs$1,
1754
+ fs: fs$1,
1755
+ geometry,
1756
+ topology: geometry.topology,
1757
+ vertexCount,
1758
+ modules: [pbrMaterial],
1759
+ ...modelOptions,
1760
+ defines: { ...parsedPPBRMaterial.defines, ...modelOptions.defines },
1761
+ parameters: { ...parameters, ...parsedPPBRMaterial.parameters, ...modelOptions.parameters }
1762
+ };
1763
+ const model = new deckProvider.Model(device, modelProps);
1764
+ const { camera, ...pbrMaterialProps } = {
1765
+ ...parsedPPBRMaterial.uniforms,
1766
+ ...modelOptions.uniforms,
1767
+ ...parsedPPBRMaterial.bindings,
1768
+ ...modelOptions.bindings
1769
+ };
1770
+ model.shaderInputs.setProps({ pbrMaterial: pbrMaterialProps, pbrProjection: { camera } });
1771
+ return new ModelNode({ managedResources, model });
1772
+ }
1773
+
1774
+ // luma.gl
1775
+ // SPDX-License-Identifier: MIT
1776
+ // Copyright (c) vis.gl contributors
1777
+ const defaultOptions = {
1778
+ modelOptions: {},
1779
+ pbrDebug: false,
1780
+ imageBasedLightingEnvironment: undefined,
1781
+ lights: true,
1782
+ useTangents: false
1783
+ };
1784
+ /**
1785
+ * GLTF instantiator for luma.gl
1786
+ * Walks the parsed and resolved glTF structure and builds a luma.gl scenegraph
1787
+ */
1788
+ function parseGLTF(device, gltf, options_ = {}) {
1789
+ const options = { ...defaultOptions, ...options_ };
1790
+ const sceneNodes = gltf.scenes.map(gltfScene => createScene(device, gltfScene, gltf.nodes, options));
1791
+ return sceneNodes;
1792
+ }
1793
+ function createScene(device, gltfScene, gltfNodes, options) {
1794
+ const gltfSceneNodes = gltfScene.nodes || [];
1795
+ const nodes = gltfSceneNodes.map(node => createNode(device, node, gltfNodes, options));
1796
+ const sceneNode = new GroupNode({
1797
+ id: gltfScene.name || gltfScene.id,
1798
+ children: nodes
1799
+ });
1800
+ return sceneNode;
1801
+ }
1802
+ function createNode(device, gltfNode, gltfNodes, options) {
1803
+ if (!gltfNode._node) {
1804
+ const gltfChildren = gltfNode.children || [];
1805
+ const children = gltfChildren.map(child => createNode(device, child, gltfNodes, options));
1806
+ // Node can have children nodes and meshes at the same time
1807
+ if (gltfNode.mesh) {
1808
+ children.push(createMesh(device, gltfNode.mesh, options));
1809
+ }
1810
+ const node = new GroupNode({
1811
+ id: gltfNode.name || gltfNode.id,
1812
+ children
1813
+ });
1814
+ if (gltfNode.matrix) {
1815
+ node.setMatrix(gltfNode.matrix);
1816
+ }
1817
+ else {
1818
+ node.matrix.identity();
1819
+ if (gltfNode.translation) {
1820
+ node.matrix.translate(gltfNode.translation);
1821
+ }
1822
+ if (gltfNode.rotation) {
1823
+ const rotationMatrix = new deckProvider.Matrix4().fromQuaternion(gltfNode.rotation);
1824
+ node.matrix.multiplyRight(rotationMatrix);
1825
+ }
1826
+ if (gltfNode.scale) {
1827
+ node.matrix.scale(gltfNode.scale);
1828
+ }
1829
+ }
1830
+ gltfNode._node = node;
1831
+ }
1832
+ // Copy _node so that gltf-animator can access
1833
+ const topLevelNode = gltfNodes.find(node => node.id === gltfNode.id);
1834
+ topLevelNode._node = gltfNode._node;
1835
+ return gltfNode._node;
1836
+ }
1837
+ function createMesh(device, gltfMesh, options) {
1838
+ // TODO: avoid changing the gltf
1839
+ if (!gltfMesh._mesh) {
1840
+ const gltfPrimitives = gltfMesh.primitives || [];
1841
+ const primitives = gltfPrimitives.map((gltfPrimitive, i) => createPrimitive(device, gltfPrimitive, i, gltfMesh, options));
1842
+ const mesh = new GroupNode({
1843
+ id: gltfMesh.name || gltfMesh.id,
1844
+ children: primitives
1845
+ });
1846
+ gltfMesh._mesh = mesh;
1847
+ }
1848
+ return gltfMesh._mesh;
1849
+ }
1850
+ function createPrimitive(device, gltfPrimitive, i, gltfMesh, options) {
1851
+ const id = gltfPrimitive.name || `${gltfMesh.name || gltfMesh.id}-primitive-${i}`;
1852
+ const topology = convertGLDrawModeToTopology(gltfPrimitive.mode || 4);
1853
+ const vertexCount = gltfPrimitive.indices
1854
+ ? gltfPrimitive.indices.count
1855
+ : getVertexCount();
1856
+ const geometry = createGeometry(id, gltfPrimitive, topology);
1857
+ const parsedPPBRMaterial = parsePBRMaterial(device, gltfPrimitive.material, geometry.attributes, options);
1858
+ const modelNode = createGLTFModel(device, {
1859
+ id,
1860
+ geometry: createGeometry(id, gltfPrimitive, topology),
1861
+ parsedPPBRMaterial,
1862
+ modelOptions: options.modelOptions,
1863
+ vertexCount
1864
+ });
1865
+ modelNode.bounds = [gltfPrimitive.attributes.POSITION.min, gltfPrimitive.attributes.POSITION.max];
1866
+ // TODO this holds on to all the CPU side texture and attribute data
1867
+ // modelNode.material = gltfPrimitive.material;
1868
+ return modelNode;
1869
+ }
1870
+ function getVertexCount(attributes) {
1871
+ throw new Error('getVertexCount not implemented');
1872
+ }
1873
+ function createGeometry(id, gltfPrimitive, topology) {
1874
+ const attributes = {};
1875
+ for (const [attributeName, attribute] of Object.entries(gltfPrimitive.attributes)) {
1876
+ const { components, size, value } = attribute;
1877
+ attributes[attributeName] = { size: size ?? components, value };
1878
+ }
1879
+ return new deckProvider.Geometry({
1880
+ id,
1881
+ topology,
1882
+ indices: gltfPrimitive.indices.value,
1883
+ attributes
1884
+ });
1885
+ }
1886
+
1887
+ const scratchQuaternion = new deckProvider.Quaternion();
1888
+ function interpolate(time, { input, interpolation, output }, target, path) {
1889
+ const maxTime = input[input.length - 1];
1890
+ const animationTime = time % maxTime;
1891
+ const nextIndex = input.findIndex(t => t >= animationTime);
1892
+ const previousIndex = Math.max(0, nextIndex - 1);
1893
+ if (!Array.isArray(target[path])) {
1894
+ switch (path) {
1895
+ case 'translation':
1896
+ target[path] = [0, 0, 0];
1897
+ break;
1898
+ case 'rotation':
1899
+ target[path] = [0, 0, 0, 1];
1900
+ break;
1901
+ case 'scale':
1902
+ target[path] = [1, 1, 1];
1903
+ break;
1904
+ default:
1905
+ deckProvider.log.warn(`Bad animation path ${path}`)();
1906
+ }
1907
+ }
1908
+ // assert(target[path].length === output[previousIndex].length);
1909
+ const previousTime = input[previousIndex];
1910
+ const nextTime = input[nextIndex];
1911
+ switch (interpolation) {
1912
+ case 'STEP':
1913
+ stepInterpolate(target, path, output[previousIndex]);
1914
+ break;
1915
+ case 'LINEAR':
1916
+ if (nextTime > previousTime) {
1917
+ const ratio = (animationTime - previousTime) / (nextTime - previousTime);
1918
+ linearInterpolate(target, path, output[previousIndex], output[nextIndex], ratio);
1919
+ }
1920
+ break;
1921
+ case 'CUBICSPLINE':
1922
+ if (nextTime > previousTime) {
1923
+ const ratio = (animationTime - previousTime) / (nextTime - previousTime);
1924
+ const tDiff = nextTime - previousTime;
1925
+ const p0 = output[3 * previousIndex + 1];
1926
+ const outTangent0 = output[3 * previousIndex + 2];
1927
+ const inTangent1 = output[3 * nextIndex + 0];
1928
+ const p1 = output[3 * nextIndex + 1];
1929
+ cubicsplineInterpolate(target, path, { p0, outTangent0, inTangent1, p1, tDiff, ratio });
1930
+ }
1931
+ break;
1932
+ default:
1933
+ deckProvider.log.warn(`Interpolation ${interpolation} not supported`)();
1934
+ break;
1935
+ }
1936
+ }
1937
+ function linearInterpolate(target, path, start, stop, ratio) {
1938
+ if (!target[path]) {
1939
+ throw new Error();
1940
+ }
1941
+ if (path === 'rotation') {
1942
+ // SLERP when path is rotation
1943
+ scratchQuaternion.slerp({ start, target: stop, ratio });
1944
+ for (let i = 0; i < scratchQuaternion.length; i++) {
1945
+ target[path][i] = scratchQuaternion[i];
1946
+ }
1947
+ }
1948
+ else {
1949
+ // regular interpolation
1950
+ for (let i = 0; i < start.length; i++) {
1951
+ target[path][i] = ratio * stop[i] + (1 - ratio) * start[i];
1952
+ }
1953
+ }
1954
+ }
1955
+ function cubicsplineInterpolate(target, path, { p0, outTangent0, inTangent1, p1, tDiff, ratio: t }) {
1956
+ if (!target[path]) {
1957
+ throw new Error();
1958
+ }
1959
+ // TODO: Quaternion might need normalization
1960
+ for (let i = 0; i < target[path].length; i++) {
1961
+ const m0 = outTangent0[i] * tDiff;
1962
+ const m1 = inTangent1[i] * tDiff;
1963
+ target[path][i] =
1964
+ (2 * Math.pow(t, 3) - 3 * Math.pow(t, 2) + 1) * p0[i] +
1965
+ (Math.pow(t, 3) - 2 * Math.pow(t, 2) + t) * m0 +
1966
+ (-2 * Math.pow(t, 3) + 3 * Math.pow(t, 2)) * p1[i] +
1967
+ (Math.pow(t, 3) - Math.pow(t, 2)) * m1;
1968
+ }
1969
+ }
1970
+ function stepInterpolate(target, path, value) {
1971
+ if (!target[path]) {
1972
+ throw new Error();
1973
+ }
1974
+ for (let i = 0; i < value.length; i++) {
1975
+ target[path][i] = value[i];
1976
+ }
1977
+ }
1978
+
1979
+ // luma.gl
1980
+ // SPDX-License-Identifier: MIT
1981
+ // Copyright (c) vis.gl contributors
1982
+ class GLTFSingleAnimator {
1983
+ animation;
1984
+ startTime = 0;
1985
+ playing = true;
1986
+ speed = 1;
1987
+ constructor(props) {
1988
+ this.animation = props.animation;
1989
+ this.animation.name ||= 'unnamed';
1990
+ Object.assign(this, props);
1991
+ }
1992
+ setTime(timeMs) {
1993
+ if (!this.playing) {
1994
+ return;
1995
+ }
1996
+ const absTime = timeMs / 1000;
1997
+ const time = (absTime - this.startTime) * this.speed;
1998
+ this.animation.channels.forEach(({ sampler, target, path }) => {
1999
+ interpolate(time, sampler, target, path);
2000
+ applyTranslationRotationScale(target, target._node);
2001
+ });
2002
+ }
2003
+ }
2004
+ class GLTFAnimator {
2005
+ animations;
2006
+ constructor(props) {
2007
+ this.animations = props.animations.map((animation, index) => {
2008
+ const name = animation.name || `Animation-${index}`;
2009
+ return new GLTFSingleAnimator({
2010
+ animation: { name, channels: animation.channels }
2011
+ });
2012
+ });
2013
+ }
2014
+ /** @deprecated Use .setTime(). Will be removed (deck.gl is using this) */
2015
+ animate(time) {
2016
+ deckProvider.log.warn('GLTFAnimator#animate is deprecated. Use GLTFAnimator#setTime instead')();
2017
+ this.setTime(time);
2018
+ }
2019
+ setTime(time) {
2020
+ this.animations.forEach(animation => animation.setTime(time));
2021
+ }
2022
+ getAnimations() {
2023
+ return this.animations;
2024
+ }
2025
+ }
2026
+ // TODO: share with GLTFInstantiator
2027
+ const scratchMatrix = new deckProvider.Matrix4();
2028
+ function applyTranslationRotationScale(gltfNode, node) {
2029
+ node.matrix.identity();
2030
+ if (gltfNode.translation) {
2031
+ node.matrix.translate(gltfNode.translation);
2032
+ }
2033
+ if (gltfNode.rotation) {
2034
+ const rotationMatrix = scratchMatrix.fromQuaternion(gltfNode.rotation);
2035
+ node.matrix.multiplyRight(rotationMatrix);
2036
+ }
2037
+ if (gltfNode.scale) {
2038
+ node.matrix.scale(gltfNode.scale);
2039
+ }
2040
+ }
2041
+
2042
+ // luma.gl
2043
+ // SPDX-License-Identifier: MIT
2044
+ // Copyright (c) vis.gl contributors
2045
+ const ATTRIBUTE_TYPE_TO_COMPONENTS = {
2046
+ SCALAR: 1,
2047
+ VEC2: 2,
2048
+ VEC3: 3,
2049
+ VEC4: 4,
2050
+ MAT2: 4,
2051
+ MAT3: 9,
2052
+ MAT4: 16
2053
+ };
2054
+ const ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY = {
2055
+ 5120: Int8Array,
2056
+ 5121: Uint8Array,
2057
+ 5122: Int16Array,
2058
+ 5123: Uint16Array,
2059
+ 5125: Uint32Array,
2060
+ 5126: Float32Array
2061
+ };
2062
+ function accessorToTypedArray(accessor) {
2063
+ const ArrayType = ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY[accessor.componentType];
2064
+ const components = ATTRIBUTE_TYPE_TO_COMPONENTS[accessor.type];
2065
+ const length = components * accessor.count;
2066
+ const { buffer, byteOffset = 0 } = accessor.bufferView?.data ?? {};
2067
+ const typedArray = new ArrayType(buffer, byteOffset + (accessor.byteOffset || 0), length);
2068
+ return { typedArray, components };
2069
+ }
2070
+
2071
+ // luma.gl
2072
+ // SPDX-License-Identifier: MIT
2073
+ // Copyright (c) vis.gl contributors
2074
+ function parseGLTFAnimations(gltf) {
2075
+ const gltfAnimations = gltf.animations || [];
2076
+ return gltfAnimations.map((animation, index) => {
2077
+ const name = animation.name || `Animation-${index}`;
2078
+ const samplers = animation.samplers.map(({ input, interpolation = 'LINEAR', output }) => ({
2079
+ input: accessorToJsArray(gltf.accessors[input]),
2080
+ interpolation,
2081
+ output: accessorToJsArray(gltf.accessors[output])
2082
+ }));
2083
+ const channels = animation.channels.map(({ sampler, target }) => ({
2084
+ sampler: samplers[sampler],
2085
+ target: gltf.nodes[target.node ?? 0],
2086
+ path: target.path
2087
+ }));
2088
+ return { name, channels };
2089
+ });
2090
+ }
2091
+ //
2092
+ function accessorToJsArray(accessor) {
2093
+ if (!accessor._animation) {
2094
+ const { typedArray: array, components } = accessorToTypedArray(accessor);
2095
+ if (components === 1) {
2096
+ accessor._animation = Array.from(array);
2097
+ }
2098
+ else {
2099
+ // Slice array
2100
+ const slicedArray = [];
2101
+ for (let i = 0; i < array.length; i += components) {
2102
+ slicedArray.push(Array.from(array.slice(i, i + components)));
2103
+ }
2104
+ accessor._animation = slicedArray;
2105
+ }
2106
+ }
2107
+ return accessor._animation;
2108
+ }
2109
+
2110
+ /** Deeply copies a JS data structure */
2111
+ function deepCopy(object) {
2112
+ // don't copy binary data
2113
+ if (ArrayBuffer.isView(object) ||
2114
+ object instanceof ArrayBuffer ||
2115
+ object instanceof ImageBitmap) {
2116
+ return object;
2117
+ }
2118
+ if (Array.isArray(object)) {
2119
+ return object.map(deepCopy);
2120
+ }
2121
+ if (object && typeof object === 'object') {
2122
+ const result = {};
2123
+ for (const key in object) {
2124
+ result[key] = deepCopy(object[key]);
2125
+ }
2126
+ return result;
2127
+ }
2128
+ return object;
2129
+ }
2130
+
2131
+ // luma.gl
2132
+ // SPDX-License-Identifier: MIT
2133
+ // Copyright (c) vis.gl contributors
2134
+ function createScenegraphsFromGLTF(device, gltf, options) {
2135
+ gltf = deepCopy(gltf);
2136
+ const scenes = parseGLTF(device, gltf, options);
2137
+ // Note: There is a nasty dependency on injected nodes in the glTF
2138
+ const animations = parseGLTFAnimations(gltf);
2139
+ const animator = new GLTFAnimator({ animations });
2140
+ return { scenes, animator };
2141
+ }
2142
+
2143
+ // deck.gl
2144
+ // SPDX-License-Identifier: MIT
2145
+ // Copyright (c) vis.gl contributors
2146
+ async function waitForGLTFAssets(gltfObjects) {
2147
+ const remaining = [];
2148
+ gltfObjects.scenes.forEach(scene => {
2149
+ scene.traverse((modelNode) => {
2150
+ // Not really clear how we can access the uniforms?
2151
+ // TODO v9 getUnforms() was removed, hack it with props.uniforms
2152
+ // Object.values((modelNode as ModelNode).model.uniforms).forEach((uniform: any) => {
2153
+ // if (uniform.loaded === false) {
2154
+ // remaining.push(uniform);
2155
+ // }
2156
+ // });
2157
+ });
2158
+ });
2159
+ return await waitWhileCondition(() => remaining.some(uniform => !uniform.loaded));
2160
+ }
2161
+ async function waitWhileCondition(condition) {
2162
+ while (condition()) {
2163
+ await new Promise(resolve => requestAnimationFrame(resolve));
2164
+ }
2165
+ }
2166
+
2167
+ // deck.gl
2168
+ // SPDX-License-Identifier: MIT
2169
+ // Copyright (c) vis.gl contributors
2170
+ const uniformBlock = `\
2171
+ uniform scenegraphUniforms {
2172
+ float sizeScale;
2173
+ float sizeMinPixels;
2174
+ float sizeMaxPixels;
2175
+ mat4 sceneModelMatrix;
2176
+ bool composeModelMatrix;
2177
+ } scenegraph;
2178
+ `;
2179
+ const scenegraphUniforms = {
2180
+ name: 'scenegraph',
2181
+ vs: uniformBlock,
2182
+ fs: uniformBlock,
2183
+ uniformTypes: {
2184
+ sizeScale: 'f32',
2185
+ sizeMinPixels: 'f32',
2186
+ sizeMaxPixels: 'f32',
2187
+ sceneModelMatrix: 'mat4x4<f32>',
2188
+ composeModelMatrix: 'f32'
2189
+ }
2190
+ };
2191
+
2192
+ // deck.gl
2193
+ // SPDX-License-Identifier: MIT
2194
+ // Copyright (c) vis.gl contributors
2195
+ var vs = `\
2196
+ #version 300 es
2197
+ #define SHADER_NAME scenegraph-layer-vertex-shader
2198
+ in vec3 instancePositions;
2199
+ in vec3 instancePositions64Low;
2200
+ in vec4 instanceColors;
2201
+ in vec3 instancePickingColors;
2202
+ in vec3 instanceModelMatrixCol0;
2203
+ in vec3 instanceModelMatrixCol1;
2204
+ in vec3 instanceModelMatrixCol2;
2205
+ in vec3 instanceTranslation;
2206
+ in vec3 positions;
2207
+ #ifdef HAS_UV
2208
+ in vec2 texCoords;
2209
+ #endif
2210
+ #ifdef LIGHTING_PBR
2211
+ #ifdef HAS_NORMALS
2212
+ in vec3 normals;
2213
+ #endif
2214
+ #endif
2215
+ out vec4 vColor;
2216
+ #ifndef LIGHTING_PBR
2217
+ #ifdef HAS_UV
2218
+ out vec2 vTEXCOORD_0;
2219
+ #endif
2220
+ #endif
2221
+ void main(void) {
2222
+ #if defined(HAS_UV) && !defined(LIGHTING_PBR)
2223
+ vTEXCOORD_0 = texCoords;
2224
+ geometry.uv = texCoords;
2225
+ #endif
2226
+ geometry.worldPosition = instancePositions;
2227
+ geometry.pickingColor = instancePickingColors;
2228
+ mat3 instanceModelMatrix = mat3(instanceModelMatrixCol0, instanceModelMatrixCol1, instanceModelMatrixCol2);
2229
+ vec3 normal = vec3(0.0, 0.0, 1.0);
2230
+ #ifdef LIGHTING_PBR
2231
+ #ifdef HAS_NORMALS
2232
+ normal = instanceModelMatrix * (scenegraph.sceneModelMatrix * vec4(normals, 0.0)).xyz;
2233
+ #endif
2234
+ #endif
2235
+ float originalSize = project_size_to_pixel(scenegraph.sizeScale);
2236
+ float clampedSize = clamp(originalSize, scenegraph.sizeMinPixels, scenegraph.sizeMaxPixels);
2237
+ vec3 pos = (instanceModelMatrix * (scenegraph.sceneModelMatrix * vec4(positions, 1.0)).xyz) * scenegraph.sizeScale * (clampedSize / originalSize) + instanceTranslation;
2238
+ if(scenegraph.composeModelMatrix) {
2239
+ DECKGL_FILTER_SIZE(pos, geometry);
2240
+ geometry.normal = project_normal(normal);
2241
+ geometry.worldPosition += pos;
2242
+ gl_Position = project_position_to_clipspace(pos + instancePositions, instancePositions64Low, vec3(0.0), geometry.position);
2243
+ }
2244
+ else {
2245
+ pos = project_size(pos);
2246
+ DECKGL_FILTER_SIZE(pos, geometry);
2247
+ gl_Position = project_position_to_clipspace(instancePositions, instancePositions64Low, pos, geometry.position);
2248
+ geometry.normal = project_normal(normal);
2249
+ }
2250
+ DECKGL_FILTER_GL_POSITION(gl_Position, geometry);
2251
+ #ifdef LIGHTING_PBR
2252
+ pbr_vPosition = geometry.position.xyz;
2253
+ #ifdef HAS_NORMALS
2254
+ pbr_vNormal = geometry.normal;
2255
+ #endif
2256
+ #ifdef HAS_UV
2257
+ pbr_vUV = texCoords;
2258
+ #else
2259
+ pbr_vUV = vec2(0., 0.);
2260
+ #endif
2261
+ geometry.uv = pbr_vUV;
2262
+ #endif
2263
+ vColor = instanceColors;
2264
+ DECKGL_FILTER_COLOR(vColor, geometry);
2265
+ }
2266
+ `;
2267
+
2268
+ // deck.gl
2269
+ // SPDX-License-Identifier: MIT
2270
+ // Copyright (c) vis.gl contributors
2271
+ var fs = `\
2272
+ #version 300 es
2273
+ #define SHADER_NAME scenegraph-layer-fragment-shader
2274
+ in vec4 vColor;
2275
+ out vec4 fragColor;
2276
+ #ifndef LIGHTING_PBR
2277
+ #if defined(HAS_UV) && defined(HAS_BASECOLORMAP)
2278
+ in vec2 vTEXCOORD_0;
2279
+ uniform sampler2D pbr_baseColorSampler;
2280
+ #endif
2281
+ #endif
2282
+ void main(void) {
2283
+ #ifdef LIGHTING_PBR
2284
+ fragColor = vColor * pbr_filterColor(vec4(0));
2285
+ geometry.uv = pbr_vUV;
2286
+ #else
2287
+ #if defined(HAS_UV) && defined(HAS_BASECOLORMAP)
2288
+ fragColor = vColor * texture(pbr_baseColorSampler, vTEXCOORD_0);
2289
+ geometry.uv = vTEXCOORD_0;
2290
+ #else
2291
+ fragColor = vColor;
2292
+ #endif
2293
+ #endif
2294
+ fragColor.a *= layer.opacity;
2295
+ DECKGL_FILTER_COLOR(fragColor, geometry);
2296
+ }
2297
+ `;
2298
+
2299
+ // deck.gl
2300
+ // SPDX-License-Identifier: MIT
2301
+ // Copyright (c) vis.gl contributors
2302
+ const DEFAULT_COLOR = [255, 255, 255, 255];
2303
+ const defaultProps = {
2304
+ scenegraph: { type: 'object', value: null, async: true },
2305
+ getScene: gltf => {
2306
+ if (gltf && gltf.scenes) {
2307
+ // gltf post processor replaces `gltf.scene` number with the scene `object`
2308
+ return typeof gltf.scene === 'object' ? gltf.scene : gltf.scenes[gltf.scene || 0];
2309
+ }
2310
+ return gltf;
2311
+ },
2312
+ getAnimator: scenegraph => scenegraph && scenegraph.animator,
2313
+ _animations: null,
2314
+ sizeScale: { type: 'number', value: 1, min: 0 },
2315
+ sizeMinPixels: { type: 'number', min: 0, value: 0 },
2316
+ sizeMaxPixels: { type: 'number', min: 0, value: Number.MAX_SAFE_INTEGER },
2317
+ getPosition: { type: 'accessor', value: (x) => x.position },
2318
+ getColor: { type: 'accessor', value: DEFAULT_COLOR },
2319
+ // flat or pbr
2320
+ _lighting: 'flat',
2321
+ // _lighting must be pbr for this to work
2322
+ _imageBasedLightingEnvironment: undefined,
2323
+ // yaw, pitch and roll are in degrees
2324
+ // https://en.wikipedia.org/wiki/Euler_angles
2325
+ // [pitch, yaw, roll]
2326
+ getOrientation: { type: 'accessor', value: [0, 0, 0] },
2327
+ getScale: { type: 'accessor', value: [1, 1, 1] },
2328
+ getTranslation: { type: 'accessor', value: [0, 0, 0] },
2329
+ // 4x4 matrix
2330
+ getTransformMatrix: { type: 'accessor', value: [] },
2331
+ loaders: [gltf.GLTFLoader]
2332
+ };
2333
+ /** Render a number of instances of a complete glTF scenegraph. */
2334
+ class ScenegraphLayer extends deckProvider.Layer {
2335
+ getShaders() {
2336
+ const defines = {};
2337
+ let pbr;
2338
+ if (this.props._lighting === 'pbr') {
2339
+ pbr = pbrMaterial;
2340
+ defines.LIGHTING_PBR = 1;
2341
+ }
2342
+ else {
2343
+ // Dummy shader module needed to handle
2344
+ // pbrMaterial.pbr_baseColorSampler binding
2345
+ pbr = { name: 'pbrMaterial' };
2346
+ }
2347
+ const modules = [deckProvider.project32, deckProvider.picking, scenegraphUniforms, pbr];
2348
+ return super.getShaders({ defines, vs, fs, modules });
2349
+ }
2350
+ initializeState() {
2351
+ const attributeManager = this.getAttributeManager();
2352
+ // attributeManager is always defined for primitive layers
2353
+ attributeManager.addInstanced({
2354
+ instancePositions: {
2355
+ size: 3,
2356
+ type: 'float64',
2357
+ fp64: this.use64bitPositions(),
2358
+ accessor: 'getPosition',
2359
+ transition: true
2360
+ },
2361
+ instanceColors: {
2362
+ type: 'unorm8',
2363
+ size: this.props.colorFormat.length,
2364
+ accessor: 'getColor',
2365
+ defaultValue: DEFAULT_COLOR,
2366
+ transition: true
2367
+ },
2368
+ instanceModelMatrix: deckProvider.MATRIX_ATTRIBUTES
2369
+ });
2370
+ }
2371
+ updateState(params) {
2372
+ super.updateState(params);
2373
+ const { props, oldProps } = params;
2374
+ if (props.scenegraph !== oldProps.scenegraph) {
2375
+ this._updateScenegraph();
2376
+ }
2377
+ else if (props._animations !== oldProps._animations) {
2378
+ this._applyAnimationsProp(this.state.animator, props._animations);
2379
+ }
2380
+ }
2381
+ finalizeState(context) {
2382
+ super.finalizeState(context);
2383
+ this.state.scenegraph?.destroy();
2384
+ }
2385
+ get isLoaded() {
2386
+ return Boolean(this.state?.scenegraph && super.isLoaded);
2387
+ }
2388
+ _updateScenegraph() {
2389
+ const props = this.props;
2390
+ const { device } = this.context;
2391
+ let scenegraphData = null;
2392
+ if (props.scenegraph instanceof ScenegraphNode) {
2393
+ // Signature 1: props.scenegraph is a proper luma.gl Scenegraph
2394
+ scenegraphData = { scenes: [props.scenegraph] };
2395
+ }
2396
+ else if (props.scenegraph && typeof props.scenegraph === 'object') {
2397
+ // Converts loaders.gl gltf to luma.gl scenegraph using the undocumented @luma.gl/experimental function
2398
+ const gltf$1 = props.scenegraph;
2399
+ // Tiles3DLoader already processes GLTF
2400
+ const processedGLTF = gltf$1.json ? gltf.postProcessGLTF(gltf$1) : gltf$1;
2401
+ const gltfObjects = createScenegraphsFromGLTF(device, processedGLTF, this._getModelOptions());
2402
+ scenegraphData = { gltf: processedGLTF, ...gltfObjects };
2403
+ waitForGLTFAssets(gltfObjects)
2404
+ .then(() => {
2405
+ this.setNeedsRedraw();
2406
+ })
2407
+ .catch(ex => {
2408
+ this.raiseError(ex, 'loading glTF');
2409
+ });
2410
+ }
2411
+ const options = { layer: this, device: this.context.device };
2412
+ const scenegraph = props.getScene(scenegraphData, options);
2413
+ const animator = props.getAnimator(scenegraphData, options);
2414
+ if (scenegraph instanceof GroupNode) {
2415
+ this.state.scenegraph?.destroy();
2416
+ this._applyAnimationsProp(animator, props._animations);
2417
+ const models = [];
2418
+ scenegraph.traverse(node => {
2419
+ if (node instanceof ModelNode) {
2420
+ models.push(node.model);
2421
+ }
2422
+ });
2423
+ this.setState({ scenegraph, animator, models });
2424
+ this.getAttributeManager().invalidateAll();
2425
+ }
2426
+ else if (scenegraph !== null) {
2427
+ deckProvider.defaultLogger.warn('invalid scenegraph:', scenegraph)();
2428
+ }
2429
+ }
2430
+ _applyAnimationsProp(animator, animationsProp) {
2431
+ if (!animator || !animationsProp) {
2432
+ return;
2433
+ }
2434
+ const animations = animator.getAnimations();
2435
+ // sort() to ensure '*' comes first so that other values can override
2436
+ Object.keys(animationsProp)
2437
+ .sort()
2438
+ .forEach(key => {
2439
+ // Key can be:
2440
+ // - number for index number
2441
+ // - name for animation name
2442
+ // - * to affect all animations
2443
+ const value = animationsProp[key];
2444
+ if (key === '*') {
2445
+ animations.forEach(animation => {
2446
+ Object.assign(animation, value);
2447
+ });
2448
+ }
2449
+ else if (Number.isFinite(Number(key))) {
2450
+ const number = Number(key);
2451
+ if (number >= 0 && number < animations.length) {
2452
+ Object.assign(animations[number], value);
2453
+ }
2454
+ else {
2455
+ deckProvider.defaultLogger.warn(`animation ${key} not found`)();
2456
+ }
2457
+ }
2458
+ else {
2459
+ const findResult = animations.find(({ animation }) => animation.name === key);
2460
+ if (findResult) {
2461
+ Object.assign(findResult, value);
2462
+ }
2463
+ else {
2464
+ deckProvider.defaultLogger.warn(`animation ${key} not found`)();
2465
+ }
2466
+ }
2467
+ });
2468
+ }
2469
+ _getModelOptions() {
2470
+ const { _imageBasedLightingEnvironment } = this.props;
2471
+ let env;
2472
+ if (_imageBasedLightingEnvironment) {
2473
+ if (typeof _imageBasedLightingEnvironment === 'function') {
2474
+ env = _imageBasedLightingEnvironment({ gl: this.context.gl, layer: this });
2475
+ }
2476
+ else {
2477
+ env = _imageBasedLightingEnvironment;
2478
+ }
2479
+ }
2480
+ return {
2481
+ imageBasedLightingEnvironment: env,
2482
+ modelOptions: {
2483
+ id: this.props.id,
2484
+ isInstanced: true,
2485
+ bufferLayout: this.getAttributeManager().getBufferLayouts(),
2486
+ ...this.getShaders()
2487
+ },
2488
+ // tangents are not supported
2489
+ useTangents: false
2490
+ };
2491
+ }
2492
+ draw({ context }) {
2493
+ if (!this.state.scenegraph)
2494
+ return;
2495
+ if (this.props._animations && this.state.animator) {
2496
+ this.state.animator.animate(context.timeline.getTime());
2497
+ this.setNeedsRedraw();
2498
+ }
2499
+ const { viewport, renderPass } = this.context;
2500
+ const { sizeScale, sizeMinPixels, sizeMaxPixels, coordinateSystem } = this.props;
2501
+ const pbrProjectionProps = {
2502
+ camera: viewport.cameraPosition
2503
+ };
2504
+ const numInstances = this.getNumInstances();
2505
+ this.state.scenegraph.traverse((node, { worldMatrix }) => {
2506
+ if (node instanceof ModelNode) {
2507
+ const { model } = node;
2508
+ model.setInstanceCount(numInstances);
2509
+ const scenegraphProps = {
2510
+ sizeScale,
2511
+ sizeMinPixels,
2512
+ sizeMaxPixels,
2513
+ composeModelMatrix: deckProvider.shouldComposeModelMatrix(viewport, coordinateSystem),
2514
+ sceneModelMatrix: worldMatrix
2515
+ };
2516
+ model.shaderInputs.setProps({
2517
+ pbrProjection: pbrProjectionProps,
2518
+ scenegraph: scenegraphProps
2519
+ });
2520
+ model.draw(renderPass);
2521
+ }
2522
+ });
2523
+ }
2524
+ }
2525
+ ScenegraphLayer.defaultProps = defaultProps;
2526
+ ScenegraphLayer.layerName = 'ScenegraphLayer';
2527
+
2528
+ exports.ScenegraphLayer = ScenegraphLayer;
2529
+ exports.parsePBRMaterial = parsePBRMaterial;
2530
+ exports.pbrMaterial = pbrMaterial;