@mapcomponents/react-maplibre 0.1.69 → 0.1.71

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 (523) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +3 -2
  3. package/dist/components/MlComponentTemplate/MlComponentTemplate.d.ts +1 -6
  4. package/dist/components/MlCreatePdfButton/MlCreatePdfButton.d.ts +3 -3
  5. package/dist/components/MlCreatePdfForm/MlCreatePdfForm.d.ts +7 -2
  6. package/dist/components/MlCreatePngButton/MlCreatePngButton.d.ts +22 -0
  7. package/dist/components/MlCreatePngButton/MlCreatePngButton.stories.d.ts +14 -0
  8. package/dist/components/MlGpxViewer/util/{MetadataDrawer.d.ts → Metadata.d.ts} +1 -2
  9. package/dist/components/MlGpxViewer/util/MlGpxDemoLoader.d.ts +1 -1
  10. package/dist/hooks/useExportMap/lib.d.ts +16 -1
  11. package/dist/index.d.ts +2 -0
  12. package/dist/index.esm.js +292 -287
  13. package/dist/index.esm.js.map +1 -1
  14. package/dist/ui_components/Sidebar.d.ts +5 -3
  15. package/dist/ui_components/TopToolbar.d.ts +8 -7
  16. package/package.json +1 -2
  17. package/.babelrc +0 -22
  18. package/.editorconfig +0 -19
  19. package/.eslintignore +0 -12
  20. package/.eslintrc.js +0 -30
  21. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -41
  22. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -22
  23. package/.github/workflows/check-catalogue-metadata-schema.yml +0 -19
  24. package/.github/workflows/check-formatting.yml +0 -46
  25. package/.github/workflows/node_version_test.yml +0 -26
  26. package/.github/workflows/publish.yml +0 -21
  27. package/.github/workflows/storybook.yml +0 -28
  28. package/.prettierignore +0 -11
  29. package/.prettierrc.json +0 -6
  30. package/.storybook/.babelrc +0 -26
  31. package/.storybook/main.js +0 -40
  32. package/.storybook/manager.js +0 -6
  33. package/.storybook/mapcomponents_logo.png +0 -0
  34. package/.storybook/preview.js +0 -33
  35. package/.storybook/style.css +0 -15
  36. package/.storybook/wheregroupTheme.js +0 -9
  37. package/config/env.js +0 -106
  38. package/config/jest/babelTransform.js +0 -29
  39. package/config/jest/cssTransform.js +0 -14
  40. package/config/jest/fileTransform.js +0 -40
  41. package/config/paths.js +0 -75
  42. package/coverage/clover.xml +0 -2018
  43. package/coverage/coverage-final.json +0 -60
  44. package/coverage/lcov-report/base.css +0 -224
  45. package/coverage/lcov-report/block-navigation.js +0 -87
  46. package/coverage/lcov-report/favicon.png +0 -0
  47. package/coverage/lcov-report/index.html +0 -731
  48. package/coverage/lcov-report/prettify.css +0 -1
  49. package/coverage/lcov-report/prettify.js +0 -2
  50. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  51. package/coverage/lcov-report/sorter.js +0 -196
  52. package/coverage/lcov-report/src/components/MapLibreMap/MapLibreMap.tsx.html +0 -466
  53. package/coverage/lcov-report/src/components/MapLibreMap/index.html +0 -116
  54. package/coverage/lcov-report/src/components/MlCenterPosition/MlCenterPosition.tsx.html +0 -322
  55. package/coverage/lcov-report/src/components/MlCenterPosition/index.html +0 -116
  56. package/coverage/lcov-report/src/components/MlCreatePdfButton/MlCreatePdfButton.tsx.html +0 -238
  57. package/coverage/lcov-report/src/components/MlCreatePdfButton/index.html +0 -116
  58. package/coverage/lcov-report/src/components/MlCreatePdfForm/MlCreatePdfForm.cy.tsx.html +0 -148
  59. package/coverage/lcov-report/src/components/MlCreatePdfForm/MlCreatePdfForm.tsx.html +0 -196
  60. package/coverage/lcov-report/src/components/MlCreatePdfForm/index.html +0 -131
  61. package/coverage/lcov-report/src/components/MlFeatureEditor/MlFeatureEditor.tsx.html +0 -535
  62. package/coverage/lcov-report/src/components/MlFeatureEditor/index.html +0 -116
  63. package/coverage/lcov-report/src/components/MlFillExtrusionLayer/MlFillExtrusionLayer.tsx.html +0 -340
  64. package/coverage/lcov-report/src/components/MlFillExtrusionLayer/index.html +0 -116
  65. package/coverage/lcov-report/src/components/MlFollowGps/MlFollowGps.tsx.html +0 -808
  66. package/coverage/lcov-report/src/components/MlFollowGps/index.html +0 -116
  67. package/coverage/lcov-report/src/components/MlGeoJsonLayer/MlGeoJsonLayer.tsx.html +0 -469
  68. package/coverage/lcov-report/src/components/MlGeoJsonLayer/index.html +0 -116
  69. package/coverage/lcov-report/src/components/MlGeoJsonLayer/story_utils/MlGeoJsonLayer.lineStyler.js.html +0 -652
  70. package/coverage/lcov-report/src/components/MlGeoJsonLayer/story_utils/MlGeoJsonLayer.polygonStyler.js.html +0 -649
  71. package/coverage/lcov-report/src/components/MlGeoJsonLayer/story_utils/MlGeojsonLayerCircleStyler.tsx.html +0 -112
  72. package/coverage/lcov-report/src/components/MlGeoJsonLayer/story_utils/MlGeojsonLayerHeatMapStyler.tsx.html +0 -115
  73. package/coverage/lcov-report/src/components/MlGeoJsonLayer/story_utils/index.html +0 -161
  74. package/coverage/lcov-report/src/components/MlGeojsonLayerWithSource/MlGeojsonLayerWithSource.tsx.html +0 -469
  75. package/coverage/lcov-report/src/components/MlGeojsonLayerWithSource/index.html +0 -116
  76. package/coverage/lcov-report/src/components/MlGpxViewer/MlGpxViewer.tsx.html +0 -394
  77. package/coverage/lcov-report/src/components/MlGpxViewer/index.html +0 -116
  78. package/coverage/lcov-report/src/components/MlImageMarkerLayer/MlImageMarkerLayer.tsx.html +0 -385
  79. package/coverage/lcov-report/src/components/MlImageMarkerLayer/index.html +0 -116
  80. package/coverage/lcov-report/src/components/MlLayer/MlLayer.tsx.html +0 -247
  81. package/coverage/lcov-report/src/components/MlLayer/index.html +0 -116
  82. package/coverage/lcov-report/src/components/MlLayerMagnify/MlLayerMagnify.tsx.html +0 -745
  83. package/coverage/lcov-report/src/components/MlLayerMagnify/index.html +0 -116
  84. package/coverage/lcov-report/src/components/MlLayerSwipe/MlLayerSwipe.tsx.html +0 -520
  85. package/coverage/lcov-report/src/components/MlLayerSwipe/index.html +0 -116
  86. package/coverage/lcov-report/src/components/MlLayerSwitcher/MlLayerSwitcher.js.html +0 -736
  87. package/coverage/lcov-report/src/components/MlLayerSwitcher/components/LayerBox.js.html +0 -316
  88. package/coverage/lcov-report/src/components/MlLayerSwitcher/components/index.html +0 -116
  89. package/coverage/lcov-report/src/components/MlLayerSwitcher/index.html +0 -116
  90. package/coverage/lcov-report/src/components/MlMarker/MlMarker.tsx.html +0 -505
  91. package/coverage/lcov-report/src/components/MlMarker/index.html +0 -116
  92. package/coverage/lcov-report/src/components/MlMeasureTool/MlMeasureTool.tsx.html +0 -265
  93. package/coverage/lcov-report/src/components/MlMeasureTool/index.html +0 -116
  94. package/coverage/lcov-report/src/components/MlNavigationCompass/MlNavigationCompass.tsx.html +0 -763
  95. package/coverage/lcov-report/src/components/MlNavigationCompass/index.html +0 -116
  96. package/coverage/lcov-report/src/components/MlNavigationTools/MlNavigationTools.tsx.html +0 -613
  97. package/coverage/lcov-report/src/components/MlNavigationTools/index.html +0 -116
  98. package/coverage/lcov-report/src/components/MlOsmLayer/MlOsmLayer.js.html +0 -298
  99. package/coverage/lcov-report/src/components/MlOsmLayer/MlOsmLayer.stories_.js.html +0 -232
  100. package/coverage/lcov-report/src/components/MlOsmLayer/index.html +0 -131
  101. package/coverage/lcov-report/src/components/MlScaleReference/MlScaleReference.tsx.html +0 -412
  102. package/coverage/lcov-report/src/components/MlScaleReference/index.html +0 -116
  103. package/coverage/lcov-report/src/components/MlShareMapState/MlShareMapState.tsx.html +0 -892
  104. package/coverage/lcov-report/src/components/MlShareMapState/index.html +0 -116
  105. package/coverage/lcov-report/src/components/MlSketchTool/LayerList/ColorPicker.tsx.html +0 -214
  106. package/coverage/lcov-report/src/components/MlSketchTool/LayerList/LayerList.tsx.html +0 -121
  107. package/coverage/lcov-report/src/components/MlSketchTool/LayerList/LayerListItem.tsx.html +0 -412
  108. package/coverage/lcov-report/src/components/MlSketchTool/LayerList/LayerPropertyForm.tsx.html +0 -463
  109. package/coverage/lcov-report/src/components/MlSketchTool/LayerList/index.html +0 -161
  110. package/coverage/lcov-report/src/components/MlSketchTool/MlSketchTool.tsx.html +0 -898
  111. package/coverage/lcov-report/src/components/MlSketchTool/index.html +0 -116
  112. package/coverage/lcov-report/src/components/MlSpatialElevationProfile/MlSpatialElevationProfile.tsx.html +0 -514
  113. package/coverage/lcov-report/src/components/MlSpatialElevationProfile/index.html +0 -116
  114. package/coverage/lcov-report/src/components/MlThreeJsLayer/MlThreeJsLayer.js.html +0 -703
  115. package/coverage/lcov-report/src/components/MlThreeJsLayer/MlThreejsLayer.tsx.html +0 -769
  116. package/coverage/lcov-report/src/components/MlThreeJsLayer/index.html +0 -131
  117. package/coverage/lcov-report/src/components/MlTransitionGeoJsonLayer/MlTransitionGeoJsonLayer.tsx.html +0 -406
  118. package/coverage/lcov-report/src/components/MlTransitionGeoJsonLayer/index.html +0 -116
  119. package/coverage/lcov-report/src/components/MlUseMapDebugger/MlUseMapDebugger.js.html +0 -310
  120. package/coverage/lcov-report/src/components/MlUseMapDebugger/index.html +0 -116
  121. package/coverage/lcov-report/src/components/MlVectorTileLayer/MlVectorTileLayer.tsx.html +0 -517
  122. package/coverage/lcov-report/src/components/MlVectorTileLayer/index.html +0 -116
  123. package/coverage/lcov-report/src/components/MlWmsFeatureInfoPopup/MlWmsFeatureInfoPopup.js.html +0 -277
  124. package/coverage/lcov-report/src/components/MlWmsFeatureInfoPopup/index.html +0 -116
  125. package/coverage/lcov-report/src/components/MlWmsLayer/MlWmsLayer.tsx.html +0 -739
  126. package/coverage/lcov-report/src/components/MlWmsLayer/index.html +0 -116
  127. package/coverage/lcov-report/src/components/MlWmsLoader/MlWmsLoader.tsx.html +0 -1102
  128. package/coverage/lcov-report/src/components/MlWmsLoader/index.html +0 -116
  129. package/coverage/lcov-report/src/contexts/MapContext.tsx.html +0 -403
  130. package/coverage/lcov-report/src/contexts/SimpleDataContext.js.html +0 -103
  131. package/coverage/lcov-report/src/contexts/SimpleDataProvider.js.html +0 -277
  132. package/coverage/lcov-report/src/contexts/index.html +0 -146
  133. package/coverage/lcov-report/src/hooks/index.html +0 -191
  134. package/coverage/lcov-report/src/hooks/useCameraFollowPath/index.html +0 -116
  135. package/coverage/lcov-report/src/hooks/useCameraFollowPath/useCameraFollowPath.tsx.html +0 -661
  136. package/coverage/lcov-report/src/hooks/useExportMap/index.html +0 -131
  137. package/coverage/lcov-report/src/hooks/useExportMap/index.ts.html +0 -175
  138. package/coverage/lcov-report/src/hooks/useExportMap/lib.ts.html +0 -559
  139. package/coverage/lcov-report/src/hooks/useGpx/index.html +0 -116
  140. package/coverage/lcov-report/src/hooks/useGpx/useGpx.tsx.html +0 -295
  141. package/coverage/lcov-report/src/hooks/useLayer.ts.html +0 -787
  142. package/coverage/lcov-report/src/hooks/useLayerEvent.js.html +0 -232
  143. package/coverage/lcov-report/src/hooks/useLayerFilter/index.html +0 -116
  144. package/coverage/lcov-report/src/hooks/useLayerFilter/useLayerFilter.ts.html +0 -184
  145. package/coverage/lcov-report/src/hooks/useLayerHoverPopup/index.html +0 -116
  146. package/coverage/lcov-report/src/hooks/useLayerHoverPopup/useLayerHoverPopup.tsx.html +0 -334
  147. package/coverage/lcov-report/src/hooks/useMap.ts.html +0 -358
  148. package/coverage/lcov-report/src/hooks/useMapState.ts.html +0 -631
  149. package/coverage/lcov-report/src/hooks/useSource.ts.html +0 -337
  150. package/coverage/lcov-report/src/hooks/useWms.ts.html +0 -397
  151. package/coverage/lcov-report/src/index.html +0 -116
  152. package/coverage/lcov-report/src/index.ts.html +0 -316
  153. package/coverage/lcov.info +0 -3987
  154. package/cypress/support/commands.ts +0 -37
  155. package/cypress/support/component-index.html +0 -12
  156. package/cypress/support/component.ts +0 -46
  157. package/cypress.config.ts +0 -101
  158. package/dist/components/MlCreatePdfButton/lib/createPdf.d.ts +0 -2
  159. package/dist/components/MlCreatePdfButton/lib/nominatimMap.d.ts +0 -2
  160. package/eslintErrorTest.js +0 -10
  161. package/public/assets/3D/godzilla_simple.glb +0 -0
  162. package/public/assets/dop.png +0 -0
  163. package/public/assets/historic.png +0 -0
  164. package/public/assets/marker.png +0 -0
  165. package/public/assets/osm.png +0 -0
  166. package/public/assets/sample.gpx +0 -716
  167. package/public/assets/sample1.gpx +0 -3003
  168. package/public/assets/sample2.gpx +0 -1264
  169. package/public/assets/sample3.gpx +0 -912
  170. package/public/assets/wg-marker.png +0 -0
  171. package/public/catalogue/.gitkeep +0 -0
  172. package/public/catalogue/mc_meta.json +0 -1
  173. package/public/favicon.ico +0 -0
  174. package/public/index.html +0 -39
  175. package/public/logo.png +0 -0
  176. package/public/manifest.json +0 -25
  177. package/public/robots.txt +0 -3
  178. package/public/thumbnails/MapLibreMap.png +0 -0
  179. package/public/thumbnails/MlCameraFollowPath.png +0 -0
  180. package/public/thumbnails/MlCreatePdfButton.png +0 -0
  181. package/public/thumbnails/MlCreatePdfForm.png +0 -0
  182. package/public/thumbnails/MlDeckGlLayer.png +0 -0
  183. package/public/thumbnails/MlDeckGlTerrainLayer.png +0 -0
  184. package/public/thumbnails/MlDemoDashboard.png +0 -0
  185. package/public/thumbnails/MlFeatureEditor.png +0 -0
  186. package/public/thumbnails/MlFillExtrusionLayer.png +0 -0
  187. package/public/thumbnails/MlFollowGps.png +0 -0
  188. package/public/thumbnails/MlGeoJsonLayer.png +0 -0
  189. package/public/thumbnails/MlGpxViewer.png +0 -0
  190. package/public/thumbnails/MlHillshadeLayer.png +0 -0
  191. package/public/thumbnails/MlIconLayer.png +0 -0
  192. package/public/thumbnails/MlLaermkarte.png +0 -0
  193. package/public/thumbnails/MlLayerMagnify.png +0 -0
  194. package/public/thumbnails/MlLayerSwipe.png +0 -0
  195. package/public/thumbnails/MlMapDrawTools.png +0 -0
  196. package/public/thumbnails/MlMeasureTool.png +0 -0
  197. package/public/thumbnails/MlMobilerImker.png +0 -0
  198. package/public/thumbnails/MlNavigationCompass.png +0 -0
  199. package/public/thumbnails/MlNavigationTools.png +0 -0
  200. package/public/thumbnails/MlOsmLayer.png +0 -0
  201. package/public/thumbnails/MlScaleReference.png +0 -0
  202. package/public/thumbnails/MlSketchTool.png +0 -0
  203. package/public/thumbnails/MlSpatialElevationProfile.png +0 -0
  204. package/public/thumbnails/MlThreeJsLayer.png +0 -0
  205. package/public/thumbnails/MlTransitionGeoJsonLayer.png +0 -0
  206. package/public/thumbnails/MlVectorTileLayer.png +0 -0
  207. package/public/thumbnails/MlWanderApp.png +0 -0
  208. package/public/thumbnails/MlWmsLayer.png +0 -0
  209. package/public/thumbnails/MlWmsLoader.png +0 -0
  210. package/public/thumbnails/useCameraFollowPath.png +0 -0
  211. package/rollup.config.js +0 -74
  212. package/scripts/build-catalogue-markdown-docs.js +0 -28
  213. package/scripts/build-catalogue-meta.js +0 -42
  214. package/scripts/create-map-component.sh +0 -36
  215. package/scripts/test.js +0 -53
  216. package/src/@types/assets/index.d.ts +0 -20
  217. package/src/App.css +0 -0
  218. package/src/components/MapLibreMap/MapLibreMap.stories.js +0 -106
  219. package/src/components/MapLibreMap/MapLibreMap.test.js +0 -84
  220. package/src/components/MapLibreMap/MapLibreMap.tsx +0 -127
  221. package/src/components/MapLibreMap/lib/MapLibreGlWrapper.test.js +0 -395
  222. package/src/components/MapLibreMap/lib/MapLibreGlWrapper.ts +0 -691
  223. package/src/components/MlBasicComponent.js +0 -39
  224. package/src/components/MlCenterPosition/MlCenterPosition.doc.de.md +0 -3
  225. package/src/components/MlCenterPosition/MlCenterPosition.meta_.json +0 -14
  226. package/src/components/MlCenterPosition/MlCenterPosition.stories.tsx +0 -20
  227. package/src/components/MlCenterPosition/MlCenterPosition.tsx +0 -79
  228. package/src/components/MlComponentTemplate/MlComponentTemplate.doc.de.md +0 -3
  229. package/src/components/MlComponentTemplate/MlComponentTemplate.meta_.json +0 -14
  230. package/src/components/MlComponentTemplate/MlComponentTemplate.stories.tsx +0 -20
  231. package/src/components/MlComponentTemplate/MlComponentTemplate.tsx +0 -42
  232. package/src/components/MlCreatePdfButton/MlCreatePdfButton.doc.de.md +0 -1
  233. package/src/components/MlCreatePdfButton/MlCreatePdfButton.doc.en.md +0 -1
  234. package/src/components/MlCreatePdfButton/MlCreatePdfButton.meta_.json +0 -14
  235. package/src/components/MlCreatePdfButton/MlCreatePdfButton.stories.tsx +0 -35
  236. package/src/components/MlCreatePdfButton/MlCreatePdfButton.tsx +0 -51
  237. package/src/components/MlCreatePdfButton/lib/createPdf.ts +0 -189
  238. package/src/components/MlCreatePdfButton/lib/nominatimMap.ts +0 -57
  239. package/src/components/MlCreatePdfForm/MlCreatePdfForm.cy.tsx +0 -21
  240. package/src/components/MlCreatePdfForm/MlCreatePdfForm.doc.de.md +0 -3
  241. package/src/components/MlCreatePdfForm/MlCreatePdfForm.meta.json +0 -14
  242. package/src/components/MlCreatePdfForm/MlCreatePdfForm.stories.tsx +0 -165
  243. package/src/components/MlCreatePdfForm/MlCreatePdfForm.tsx +0 -37
  244. package/src/components/MlCreatePdfForm/lib/PdfContext.tsx +0 -51
  245. package/src/components/MlCreatePdfForm/lib/PdfForm.tsx +0 -257
  246. package/src/components/MlCreatePdfForm/lib/PdfPreview.tsx +0 -327
  247. package/src/components/MlCreatePdfForm/lib/_PdfPreview.tsx +0 -399
  248. package/src/components/MlCreatePdfForm/lib/pdf.templates.ts +0 -82
  249. package/src/components/MlCreatePdfForm/lib/pdfContext.d.ts +0 -24
  250. package/src/components/MlCreatePdfForm/lib/preview.css +0 -114
  251. package/src/components/MlFeatureEditor/MlFeatureEditor.css +0 -0
  252. package/src/components/MlFeatureEditor/MlFeatureEditor.doc.de.md +0 -1
  253. package/src/components/MlFeatureEditor/MlFeatureEditor.doc.en.md +0 -1
  254. package/src/components/MlFeatureEditor/MlFeatureEditor.meta.json +0 -14
  255. package/src/components/MlFeatureEditor/MlFeatureEditor.stories.js +0 -91
  256. package/src/components/MlFeatureEditor/MlFeatureEditor.test.js +0 -126
  257. package/src/components/MlFeatureEditor/MlFeatureEditor.tsx +0 -150
  258. package/src/components/MlFeatureEditor/custom-direct-select-mode.js +0 -303
  259. package/src/components/MlFeatureEditor/custom-polygon-mode.js +0 -188
  260. package/src/components/MlFeatureEditor/custom-select-mode.js +0 -406
  261. package/src/components/MlFeatureEditor/lib/LICENSE.md +0 -18
  262. package/src/components/MlFeatureEditor/lib/common_selectors.js +0 -72
  263. package/src/components/MlFeatureEditor/lib/constants.js +0 -104
  264. package/src/components/MlFeatureEditor/lib/constrain_feature_movement.js +0 -72
  265. package/src/components/MlFeatureEditor/lib/create_midpoint.js +0 -42
  266. package/src/components/MlFeatureEditor/lib/create_supplementary_points.js +0 -102
  267. package/src/components/MlFeatureEditor/lib/create_vertex.js +0 -35
  268. package/src/components/MlFeatureEditor/lib/double_click_zoom.js +0 -30
  269. package/src/components/MlFeatureEditor/lib/euclidean_distance.js +0 -9
  270. package/src/components/MlFeatureEditor/lib/features_at.js +0 -52
  271. package/src/components/MlFeatureEditor/lib/get_features_and_set_cursor.js +0 -28
  272. package/src/components/MlFeatureEditor/lib/is_click.js +0 -22
  273. package/src/components/MlFeatureEditor/lib/is_event_at_coordinates.js +0 -10
  274. package/src/components/MlFeatureEditor/lib/is_tap.js +0 -19
  275. package/src/components/MlFeatureEditor/lib/map_event_to_bounding_box.js +0 -18
  276. package/src/components/MlFeatureEditor/lib/mode_handler.js +0 -120
  277. package/src/components/MlFeatureEditor/lib/mouse_event_point.js +0 -23
  278. package/src/components/MlFeatureEditor/lib/move_features.js +0 -47
  279. package/src/components/MlFeatureEditor/lib/sort_features.js +0 -45
  280. package/src/components/MlFeatureEditor/lib/string_set.js +0 -59
  281. package/src/components/MlFeatureEditor/lib/string_sets_are_equal.js +0 -8
  282. package/src/components/MlFeatureEditor/lib/theme.js +0 -236
  283. package/src/components/MlFeatureEditor/lib/to_dense_array.js +0 -15
  284. package/src/components/MlFeatureEditor/lib/utils.js +0 -51
  285. package/src/components/MlFillExtrusionLayer/MlFillExtrusionLayer.doc.de.md +0 -1
  286. package/src/components/MlFillExtrusionLayer/MlFillExtrusionLayer.doc.en.md +0 -1
  287. package/src/components/MlFillExtrusionLayer/MlFillExtrusionLayer.meta.json +0 -14
  288. package/src/components/MlFillExtrusionLayer/MlFillExtrusionLayer.stories.js +0 -24
  289. package/src/components/MlFillExtrusionLayer/MlFillExtrusionLayer.test.js +0 -15
  290. package/src/components/MlFillExtrusionLayer/MlFillExtrusionLayer.tsx +0 -85
  291. package/src/components/MlFollowGps/MlFollowGps.doc.de.md +0 -1
  292. package/src/components/MlFollowGps/MlFollowGps.doc.en.md +0 -1
  293. package/src/components/MlFollowGps/MlFollowGps.meta.json +0 -14
  294. package/src/components/MlFollowGps/MlFollowGps.stories.js +0 -40
  295. package/src/components/MlFollowGps/MlFollowGps.test.js +0 -63
  296. package/src/components/MlFollowGps/MlFollowGps.tsx +0 -241
  297. package/src/components/MlGeoJsonLayer/MlGeoJsonLayer.doc.de.md +0 -1
  298. package/src/components/MlGeoJsonLayer/MlGeoJsonLayer.doc.en.md +0 -1
  299. package/src/components/MlGeoJsonLayer/MlGeoJsonLayer.meta.json +0 -14
  300. package/src/components/MlGeoJsonLayer/MlGeoJsonLayer.stories.tsx +0 -191
  301. package/src/components/MlGeoJsonLayer/MlGeoJsonLayer.test.js +0 -20
  302. package/src/components/MlGeoJsonLayer/MlGeoJsonLayer.tsx +0 -128
  303. package/src/components/MlGeoJsonLayer/assets/earthquake.json +0 -109937
  304. package/src/components/MlGeoJsonLayer/assets/sample_1.json +0 -140
  305. package/src/components/MlGeoJsonLayer/assets/sample_2.json +0 -142
  306. package/src/components/MlGeoJsonLayer/assets/sample_polygon_1.json +0 -33
  307. package/src/components/MlGeoJsonLayer/assets/wg_locations.json +0 -65
  308. package/src/components/MlGeoJsonLayer/story_utils/MlGeoJsonLayer.lineStyler.js +0 -189
  309. package/src/components/MlGeoJsonLayer/story_utils/MlGeoJsonLayer.polygonStyler.js +0 -188
  310. package/src/components/MlGeoJsonLayer/story_utils/MlGeojsonLayerCircleStyler.tsx +0 -9
  311. package/src/components/MlGeoJsonLayer/story_utils/MlGeojsonLayerHeatMapStyler.tsx +0 -10
  312. package/src/components/MlGeoJsonLayer/util/getDefaultLayerTypeByGeometry.ts +0 -31
  313. package/src/components/MlGeoJsonLayer/util/getDefaultPaintPropsByType.ts +0 -37
  314. package/src/components/MlGeojsonLayerWithSource/MlGeojsonLayerWithSource.doc.de.md +0 -3
  315. package/src/components/MlGeojsonLayerWithSource/MlGeojsonLayerWithSource.meta_.json +0 -14
  316. package/src/components/MlGeojsonLayerWithSource/MlGeojsonLayerWithSource.stories.tsx +0 -19
  317. package/src/components/MlGeojsonLayerWithSource/MlGeojsonLayerWithSource.tsx +0 -128
  318. package/src/components/MlGpxViewer/MlGpxViewer.doc.de.md +0 -1
  319. package/src/components/MlGpxViewer/MlGpxViewer.doc.en.md +0 -1
  320. package/src/components/MlGpxViewer/MlGpxViewer.meta.json +0 -14
  321. package/src/components/MlGpxViewer/MlGpxViewer.stories.tsx +0 -100
  322. package/src/components/MlGpxViewer/MlGpxViewer.test.js +0 -53
  323. package/src/components/MlGpxViewer/MlGpxViewer.tsx +0 -103
  324. package/src/components/MlGpxViewer/util/GeoJsonContext.ts +0 -13
  325. package/src/components/MlGpxViewer/util/GeoJsonProvider.tsx +0 -25
  326. package/src/components/MlGpxViewer/util/MetadataDrawer.tsx +0 -38
  327. package/src/components/MlGpxViewer/util/MlGpxDemoLoader.tsx +0 -130
  328. package/src/components/MlGpxViewer/util/MlGpxViewerInstructions.tsx +0 -71
  329. package/src/components/MlImageMarkerLayer/MlImageMarkerLayer.doc.de.md +0 -3
  330. package/src/components/MlImageMarkerLayer/MlImageMarkerLayer.meta_.json +0 -14
  331. package/src/components/MlImageMarkerLayer/MlImageMarkerLayer.stories.tsx +0 -41
  332. package/src/components/MlImageMarkerLayer/MlImageMarkerLayer.test.js +0 -38
  333. package/src/components/MlImageMarkerLayer/MlImageMarkerLayer.tsx +0 -100
  334. package/src/components/MlLayer/MlLayer.doc.de.md +0 -3
  335. package/src/components/MlLayer/MlLayer.meta_.json +0 -14
  336. package/src/components/MlLayer/MlLayer.test.js +0 -117
  337. package/src/components/MlLayer/MlLayer.tsx +0 -54
  338. package/src/components/MlLayerMagnify/MlLayerMagnify.doc.de.md +0 -1
  339. package/src/components/MlLayerMagnify/MlLayerMagnify.doc.en.md +0 -1
  340. package/src/components/MlLayerMagnify/MlLayerMagnify.meta.json +0 -14
  341. package/src/components/MlLayerMagnify/MlLayerMagnify.stories.tsx +0 -44
  342. package/src/components/MlLayerMagnify/MlLayerMagnify.test.tsx +0 -83
  343. package/src/components/MlLayerMagnify/MlLayerMagnify.tsx +0 -220
  344. package/src/components/MlLayerMagnify/style.css +0 -48
  345. package/src/components/MlLayerSwipe/MlLayerSwipe.doc.de.md +0 -1
  346. package/src/components/MlLayerSwipe/MlLayerSwipe.doc.en.md +0 -1
  347. package/src/components/MlLayerSwipe/MlLayerSwipe.meta.json +0 -14
  348. package/src/components/MlLayerSwipe/MlLayerSwipe.stories.tsx +0 -36
  349. package/src/components/MlLayerSwipe/MlLayerSwipe.test.js +0 -86
  350. package/src/components/MlLayerSwipe/MlLayerSwipe.tsx +0 -145
  351. package/src/components/MlLayerSwipe/style.css +0 -48
  352. package/src/components/MlLayerSwitcher/MlLayerSwitcher.css +0 -17
  353. package/src/components/MlLayerSwitcher/MlLayerSwitcher.doc.de.md +0 -3
  354. package/src/components/MlLayerSwitcher/MlLayerSwitcher.js +0 -217
  355. package/src/components/MlLayerSwitcher/MlLayerSwitcher.meta_.json +0 -14
  356. package/src/components/MlLayerSwitcher/MlLayerSwitcher.stories.js +0 -103
  357. package/src/components/MlLayerSwitcher/assets/sample_1.json +0 -26
  358. package/src/components/MlLayerSwitcher/assets/sample_2.json +0 -22
  359. package/src/components/MlLayerSwitcher/components/LayerBox.js +0 -77
  360. package/src/components/MlMarker/MlMarker.doc.de.md +0 -3
  361. package/src/components/MlMarker/MlMarker.meta_.json +0 -14
  362. package/src/components/MlMarker/MlMarker.stories.js +0 -22
  363. package/src/components/MlMarker/MlMarker.tsx +0 -140
  364. package/src/components/MlMeasureTool/MlMeasureTool.doc.de.md +0 -3
  365. package/src/components/MlMeasureTool/MlMeasureTool.meta.json +0 -14
  366. package/src/components/MlMeasureTool/MlMeasureTool.stories.js +0 -96
  367. package/src/components/MlMeasureTool/MlMeasureTool.tsx +0 -60
  368. package/src/components/MlNavigationCompass/MlNavigationCompass.doc.de.md +0 -1
  369. package/src/components/MlNavigationCompass/MlNavigationCompass.doc.en.md +0 -1
  370. package/src/components/MlNavigationCompass/MlNavigationCompass.meta.json +0 -14
  371. package/src/components/MlNavigationCompass/MlNavigationCompass.stories.js +0 -63
  372. package/src/components/MlNavigationCompass/MlNavigationCompass.test.js +0 -68
  373. package/src/components/MlNavigationCompass/MlNavigationCompass.tsx +0 -226
  374. package/src/components/MlNavigationCompass/assets/needle.svg +0 -17
  375. package/src/components/MlNavigationCompass/assets/needle__.svg +0 -19
  376. package/src/components/MlNavigationCompass/assets/rotate_left.svg +0 -13
  377. package/src/components/MlNavigationCompass/assets/rotate_right.svg +0 -15
  378. package/src/components/MlNavigationTools/MlNavigationTools.doc.de.md +0 -1
  379. package/src/components/MlNavigationTools/MlNavigationTools.doc.en.md +0 -1
  380. package/src/components/MlNavigationTools/MlNavigationTools.meta.json +0 -14
  381. package/src/components/MlNavigationTools/MlNavigationTools.stories.js +0 -64
  382. package/src/components/MlNavigationTools/MlNavigationTools.tsx +0 -176
  383. package/src/components/MlOsmLayer/MlOsmLayer.js +0 -71
  384. package/src/components/MlOsmLayer/MlOsmLayer.stories_.js +0 -49
  385. package/src/components/MlOsmLayer/MlOsmLayer.test.js +0 -19
  386. package/src/components/MlScaleReference/MlScaleReference.doc.de.md +0 -1
  387. package/src/components/MlScaleReference/MlScaleReference.doc.en.md +0 -1
  388. package/src/components/MlScaleReference/MlScaleReference.meta.json +0 -14
  389. package/src/components/MlScaleReference/MlScaleReference.stories.js +0 -51
  390. package/src/components/MlScaleReference/MlScaleReference.tsx +0 -109
  391. package/src/components/MlShareMapState/MlShareMapState.doc.de.md +0 -3
  392. package/src/components/MlShareMapState/MlShareMapState.meta_.json +0 -14
  393. package/src/components/MlShareMapState/MlShareMapState.stories.tsx +0 -100
  394. package/src/components/MlShareMapState/MlShareMapState.tsx +0 -269
  395. package/src/components/MlSketchTool/LayerList/ColorPicker.tsx +0 -43
  396. package/src/components/MlSketchTool/LayerList/LayerList.tsx +0 -12
  397. package/src/components/MlSketchTool/LayerList/LayerListItem.tsx +0 -109
  398. package/src/components/MlSketchTool/LayerList/LayerPropertyForm.tsx +0 -126
  399. package/src/components/MlSketchTool/MlSketchTool.doc.de.md +0 -3
  400. package/src/components/MlSketchTool/MlSketchTool.meta.json +0 -14
  401. package/src/components/MlSketchTool/MlSketchTool.stories.tsx +0 -26
  402. package/src/components/MlSketchTool/MlSketchTool.tsx +0 -271
  403. package/src/components/MlSpatialElevationProfile/MlSpatialElevationProfile.doc.de.md +0 -1
  404. package/src/components/MlSpatialElevationProfile/MlSpatialElevationProfile.doc.en.md +0 -1
  405. package/src/components/MlSpatialElevationProfile/MlSpatialElevationProfile.meta.json +0 -14
  406. package/src/components/MlSpatialElevationProfile/MlSpatialElevationProfile.stories.tsx +0 -121
  407. package/src/components/MlSpatialElevationProfile/MlSpatialElevationProfile.test.js +0 -48
  408. package/src/components/MlSpatialElevationProfile/MlSpatialElevationProfile.tsx +0 -143
  409. package/src/components/MlSpatialElevationProfile/util/getElevationData.tsx +0 -103
  410. package/src/components/MlThreeJsLayer/MlThreeJsLayer.doc.de.md +0 -1
  411. package/src/components/MlThreeJsLayer/MlThreeJsLayer.doc.en.md +0 -1
  412. package/src/components/MlThreeJsLayer/MlThreeJsLayer.js +0 -207
  413. package/src/components/MlThreeJsLayer/MlThreeJsLayer.meta.json +0 -14
  414. package/src/components/MlThreeJsLayer/MlThreeJsLayer.stories.tsx +0 -37
  415. package/src/components/MlThreeJsLayer/MlThreeJsLayer.test.js +0 -33
  416. package/src/components/MlThreeJsLayer/MlThreejsLayer.tsx +0 -228
  417. package/src/components/MlThreeJsLayer/lib/GLTFLoader.js +0 -3331
  418. package/src/components/MlTransitionGeoJsonLayer/MlTransitionGeoJsonLayer.doc.de.md +0 -3
  419. package/src/components/MlTransitionGeoJsonLayer/MlTransitionGeoJsonLayer.meta.json +0 -14
  420. package/src/components/MlTransitionGeoJsonLayer/MlTransitionGeoJsonLayer.stories.js +0 -52
  421. package/src/components/MlTransitionGeoJsonLayer/MlTransitionGeoJsonLayer.test.js +0 -20
  422. package/src/components/MlTransitionGeoJsonLayer/MlTransitionGeoJsonLayer.tsx +0 -107
  423. package/src/components/MlTransitionGeoJsonLayer/assets/sample_1.json +0 -26
  424. package/src/components/MlTransitionGeoJsonLayer/assets/sample_2.json +0 -22
  425. package/src/components/MlTransitionGeoJsonLayer/assets/sample_polygon_1.json +0 -33
  426. package/src/components/MlTransitionGeoJsonLayer/util/transitionFunctions.js +0 -221
  427. package/src/components/MlUseMapDebugger/MlUseMapDebugger.doc.de.md +0 -3
  428. package/src/components/MlUseMapDebugger/MlUseMapDebugger.js +0 -75
  429. package/src/components/MlUseMapDebugger/MlUseMapDebugger.meta_.json +0 -14
  430. package/src/components/MlUseMapDebugger/MlUseMapDebugger.stories.js +0 -30
  431. package/src/components/MlVectorTileLayer/MlVectorTileLayer.doc.de.md +0 -1
  432. package/src/components/MlVectorTileLayer/MlVectorTileLayer.doc.en.md +0 -1
  433. package/src/components/MlVectorTileLayer/MlVectorTileLayer.meta.json +0 -14
  434. package/src/components/MlVectorTileLayer/MlVectorTileLayer.stories.js +0 -52
  435. package/src/components/MlVectorTileLayer/MlVectorTileLayer.test.js +0 -40
  436. package/src/components/MlVectorTileLayer/MlVectorTileLayer.tsx +0 -144
  437. package/src/components/MlWmsFeatureInfoPopup/MlWmsFeatureInfoPopup.doc.de.md +0 -3
  438. package/src/components/MlWmsFeatureInfoPopup/MlWmsFeatureInfoPopup.js +0 -64
  439. package/src/components/MlWmsFeatureInfoPopup/MlWmsFeatureInfoPopup.meta_.json +0 -14
  440. package/src/components/MlWmsFeatureInfoPopup/MlWmsFeatureInfoPopup.stories.tsx +0 -22
  441. package/src/components/MlWmsLayer/MlWmsLayer.stories.js +0 -49
  442. package/src/components/MlWmsLayer/MlWmsLayer.test.js +0 -19
  443. package/src/components/MlWmsLayer/MlWmsLayer.tsx +0 -218
  444. package/src/components/MlWmsLoader/MlWmsLoader.doc.de.md +0 -1
  445. package/src/components/MlWmsLoader/MlWmsLoader.doc.en.md +0 -1
  446. package/src/components/MlWmsLoader/MlWmsLoader.meta.json +0 -14
  447. package/src/components/MlWmsLoader/MlWmsLoader.stories.tsx +0 -81
  448. package/src/components/MlWmsLoader/MlWmsLoader.tsx +0 -339
  449. package/src/components/MlWmsLoader/utils/MlWmsLoaderInstructions.tsx +0 -50
  450. package/src/components/MlWmsLoader/utils/WMSLinks.tsx +0 -128
  451. package/src/contexts/MapComponentsProvider.test.js +0 -260
  452. package/src/contexts/MapContext.tsx +0 -106
  453. package/src/contexts/SimpleDataContext.js +0 -6
  454. package/src/contexts/SimpleDataProvider.js +0 -64
  455. package/src/contexts/SimpleDataProvider.test.js +0 -68
  456. package/src/custom.d.ts +0 -4
  457. package/src/decorators/EmptyMapDecorator.js +0 -38
  458. package/src/decorators/MapContextDecorator.js +0 -39
  459. package/src/decorators/MapContextDecoratorHooks.js +0 -39
  460. package/src/decorators/MultiMapContextDecorator.js +0 -80
  461. package/src/decorators/NoNavToolsDecorator.js +0 -33
  462. package/src/decorators/ThemeDecorator.js +0 -24
  463. package/src/decorators/style.css +0 -34
  464. package/src/hooks/assets/pointWG.json +0 -13
  465. package/src/hooks/useCameraFollowPath/useCameraFollowPath.doc.de.md +0 -4
  466. package/src/hooks/useCameraFollowPath/useCameraFollowPath.doc.en.md +0 -1
  467. package/src/hooks/useCameraFollowPath/useCameraFollowPath.meta.json +0 -14
  468. package/src/hooks/useCameraFollowPath/useCameraFollowPath.stories.tsx +0 -192
  469. package/src/hooks/useCameraFollowPath/useCameraFollowPath.tsx +0 -192
  470. package/src/hooks/useExportMap/index.ts +0 -30
  471. package/src/hooks/useExportMap/lib.ts +0 -158
  472. package/src/hooks/useGpx/lib/gpxConverter.js +0 -521
  473. package/src/hooks/useGpx/useGpx.doc.de.md +0 -3
  474. package/src/hooks/useGpx/useGpx.meta_.json +0 -15
  475. package/src/hooks/useGpx/useGpx.stories.js +0 -20
  476. package/src/hooks/useGpx/useGpx.tsx +0 -70
  477. package/src/hooks/useLayer.test.js +0 -205
  478. package/src/hooks/useLayer.ts +0 -234
  479. package/src/hooks/useLayerEvent.js +0 -49
  480. package/src/hooks/useLayerFilter/useLayerFilter.doc.de.md +0 -3
  481. package/src/hooks/useLayerFilter/useLayerFilter.meta_.json +0 -14
  482. package/src/hooks/useLayerFilter/useLayerFilter.stories.tsx +0 -40
  483. package/src/hooks/useLayerFilter/useLayerFilter.ts +0 -33
  484. package/src/hooks/useLayerHoverPopup/useLayerHoverPopup.doc.de.md +0 -3
  485. package/src/hooks/useLayerHoverPopup/useLayerHoverPopup.meta_.json +0 -15
  486. package/src/hooks/useLayerHoverPopup/useLayerHoverPopup.stories.js +0 -20
  487. package/src/hooks/useLayerHoverPopup/useLayerHoverPopup.tsx +0 -83
  488. package/src/hooks/useMap.test.tsx +0 -48
  489. package/src/hooks/useMap.ts +0 -91
  490. package/src/hooks/useMapState.stories.js +0 -120
  491. package/src/hooks/useMapState.ts +0 -182
  492. package/src/hooks/useSource.ts +0 -84
  493. package/src/hooks/useSources.stories.js +0 -232
  494. package/src/hooks/useWms.ts +0 -104
  495. package/src/index.ts +0 -78
  496. package/src/setupTests.js +0 -113
  497. package/src/stories/components/Readme.js +0 -7
  498. package/src/ui_components/Dropzone.tsx +0 -104
  499. package/src/ui_components/ImageLoader.tsx +0 -83
  500. package/src/ui_components/LayerList/LayerList.stories.tsx +0 -136
  501. package/src/ui_components/LayerList/LayerList.tsx +0 -12
  502. package/src/ui_components/LayerList/LayerListFolder.tsx +0 -82
  503. package/src/ui_components/LayerList/LayerListItem.tsx +0 -180
  504. package/src/ui_components/LayerList/assets/sample_1.json +0 -26
  505. package/src/ui_components/LayerList/assets/sample_2.json +0 -22
  506. package/src/ui_components/LayerList/assets/sample_polygon_1.json +0 -33
  507. package/src/ui_components/LayerList/assets/style.json +0 -2599
  508. package/src/ui_components/LayerList/util/LayerListItemVectorLayer.tsx +0 -92
  509. package/src/ui_components/LayerList/util/LayerPropertyForm.tsx +0 -125
  510. package/src/ui_components/LayerList/util/input/ColorPicker.tsx +0 -44
  511. package/src/ui_components/LoadingOverlay.css +0 -9
  512. package/src/ui_components/LoadingOverlayContext.tsx +0 -79
  513. package/src/ui_components/MapcomponentsTheme.tsx +0 -133
  514. package/src/ui_components/Sidebar.tsx +0 -87
  515. package/src/ui_components/Tooltip.tsx +0 -17
  516. package/src/ui_components/TopToolbar.tsx +0 -24
  517. package/src/ui_components/UploadButton.tsx +0 -57
  518. package/src/util/BubbleForInstructions.js +0 -48
  519. package/src/util/Instructions.tsx +0 -60
  520. package/src/util/index.js +0 -4
  521. package/src/util/layerRemovalTest.js +0 -121
  522. package/src/util/sourceRemovalTest.js +0 -113
  523. package/tsconfig.json +0 -34
@@ -1,3331 +0,0 @@
1
- import * as THREE from "three";
2
-
3
- class GLTFLoader extends THREE.Loader {
4
- constructor(manager) {
5
- super(manager);
6
- this.dracoLoader = null;
7
- this.ktx2Loader = null;
8
- this.meshoptDecoder = null;
9
- this.pluginCallbacks = [];
10
- this.register(function (parser) {
11
- return new GLTFMaterialsClearcoatExtension(parser);
12
- });
13
- this.register(function (parser) {
14
- return new GLTFTextureBasisUExtension(parser);
15
- });
16
- this.register(function (parser) {
17
- return new GLTFTextureWebPExtension(parser);
18
- });
19
- this.register(function (parser) {
20
- return new GLTFMaterialsSheenExtension(parser);
21
- });
22
- this.register(function (parser) {
23
- return new GLTFMaterialsTransmissionExtension(parser);
24
- });
25
- this.register(function (parser) {
26
- return new GLTFMaterialsVolumeExtension(parser);
27
- });
28
- this.register(function (parser) {
29
- return new GLTFMaterialsIorExtension(parser);
30
- });
31
- this.register(function (parser) {
32
- return new GLTFMaterialsSpecularExtension(parser);
33
- });
34
- this.register(function (parser) {
35
- return new GLTFLightsExtension(parser);
36
- });
37
- this.register(function (parser) {
38
- return new GLTFMeshoptCompression(parser);
39
- });
40
- }
41
-
42
- load(url, onLoad, onProgress, onError) {
43
- const scope = this;
44
- let resourcePath;
45
-
46
- if (this.resourcePath !== "") {
47
- resourcePath = this.resourcePath;
48
- } else if (this.path !== "") {
49
- resourcePath = this.path;
50
- } else {
51
- resourcePath = THREE.LoaderUtils.extractUrlBase(url);
52
- } // Tells the LoadingManager to track an extra item, which resolves after
53
- // the model is fully loaded. This means the count of items loaded will
54
- // be incorrect, but ensures manager.onLoad() does not fire early.
55
-
56
- this.manager.itemStart(url);
57
-
58
- const _onError = function (e) {
59
- if (onError) {
60
- onError(e);
61
- } else {
62
- console.error(e);
63
- }
64
-
65
- scope.manager.itemError(url);
66
- scope.manager.itemEnd(url);
67
- };
68
-
69
- const loader = new THREE.FileLoader(this.manager);
70
- loader.setPath(this.path);
71
- loader.setResponseType("arraybuffer");
72
- loader.setRequestHeader(this.requestHeader);
73
- loader.setWithCredentials(this.withCredentials);
74
- loader.load(
75
- url,
76
- function (data) {
77
- try {
78
- scope.parse(
79
- data,
80
- resourcePath,
81
- function (gltf) {
82
- onLoad(gltf);
83
- scope.manager.itemEnd(url);
84
- },
85
- _onError
86
- );
87
- } catch (e) {
88
- _onError(e);
89
- }
90
- },
91
- onProgress,
92
- _onError
93
- );
94
- }
95
-
96
- setDRACOLoader(dracoLoader) {
97
- this.dracoLoader = dracoLoader;
98
- return this;
99
- }
100
-
101
- setDDSLoader() {
102
- throw new Error(
103
- 'THREE.GLTFLoader: "MSFT_texture_dds" no longer supported. Please update to "KHR_texture_basisu".'
104
- );
105
- }
106
-
107
- setKTX2Loader(ktx2Loader) {
108
- this.ktx2Loader = ktx2Loader;
109
- return this;
110
- }
111
-
112
- setMeshoptDecoder(meshoptDecoder) {
113
- this.meshoptDecoder = meshoptDecoder;
114
- return this;
115
- }
116
-
117
- register(callback) {
118
- if (this.pluginCallbacks.indexOf(callback) === -1) {
119
- this.pluginCallbacks.push(callback);
120
- }
121
-
122
- return this;
123
- }
124
-
125
- unregister(callback) {
126
- if (this.pluginCallbacks.indexOf(callback) !== -1) {
127
- this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(callback), 1);
128
- }
129
-
130
- return this;
131
- }
132
-
133
- parse(data, path, onLoad, onError) {
134
- let content;
135
- const extensions = {};
136
- const plugins = {};
137
-
138
- if (typeof data === "string") {
139
- content = data;
140
- } else {
141
- const magic = THREE.LoaderUtils.decodeText(new Uint8Array(data, 0, 4));
142
-
143
- if (magic === BINARY_EXTENSION_HEADER_MAGIC) {
144
- try {
145
- extensions[EXTENSIONS.KHR_BINARY_GLTF] = new GLTFBinaryExtension(data);
146
- } catch (error) {
147
- if (onError) onError(error);
148
- return;
149
- }
150
-
151
- content = extensions[EXTENSIONS.KHR_BINARY_GLTF].content;
152
- } else {
153
- content = THREE.LoaderUtils.decodeText(new Uint8Array(data));
154
- }
155
- }
156
-
157
- const json = JSON.parse(content);
158
-
159
- if (json.asset === undefined || json.asset.version[0] < 2) {
160
- if (onError)
161
- onError(
162
- new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.")
163
- );
164
- return;
165
- }
166
-
167
- const parser = new GLTFParser(json, {
168
- path: path || this.resourcePath || "",
169
- crossOrigin: this.crossOrigin,
170
- requestHeader: this.requestHeader,
171
- manager: this.manager,
172
- ktx2Loader: this.ktx2Loader,
173
- meshoptDecoder: this.meshoptDecoder,
174
- });
175
- parser.fileLoader.setRequestHeader(this.requestHeader);
176
-
177
- for (let i = 0; i < this.pluginCallbacks.length; i++) {
178
- const plugin = this.pluginCallbacks[i](parser);
179
- plugins[plugin.name] = plugin; // Workaround to avoid determining as unknown extension
180
- // in addUnknownExtensionsToUserData().
181
- // Remove this workaround if we move all the existing
182
- // extension handlers to plugin system
183
-
184
- extensions[plugin.name] = true;
185
- }
186
-
187
- if (json.extensionsUsed) {
188
- for (let i = 0; i < json.extensionsUsed.length; ++i) {
189
- const extensionName = json.extensionsUsed[i];
190
- const extensionsRequired = json.extensionsRequired || [];
191
-
192
- switch (extensionName) {
193
- case EXTENSIONS.KHR_MATERIALS_UNLIT:
194
- extensions[extensionName] = new GLTFMaterialsUnlitExtension();
195
- break;
196
-
197
- case EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS:
198
- extensions[extensionName] = new GLTFMaterialsPbrSpecularGlossinessExtension();
199
- break;
200
-
201
- case EXTENSIONS.KHR_DRACO_MESH_COMPRESSION:
202
- extensions[extensionName] = new GLTFDracoMeshCompressionExtension(
203
- json,
204
- this.dracoLoader
205
- );
206
- break;
207
-
208
- case EXTENSIONS.KHR_TEXTURE_TRANSFORM:
209
- extensions[extensionName] = new GLTFTextureTransformExtension();
210
- break;
211
-
212
- case EXTENSIONS.KHR_MESH_QUANTIZATION:
213
- extensions[extensionName] = new GLTFMeshQuantizationExtension();
214
- break;
215
-
216
- default:
217
- if (
218
- extensionsRequired.indexOf(extensionName) >= 0 &&
219
- plugins[extensionName] === undefined
220
- ) {
221
- console.warn('THREE.GLTFLoader: Unknown extension "' + extensionName + '".');
222
- }
223
- }
224
- }
225
- }
226
-
227
- parser.setExtensions(extensions);
228
- parser.setPlugins(plugins);
229
- parser.parse(onLoad, onError);
230
- }
231
-
232
- parseAsync(data, path) {
233
- const scope = this;
234
- return new Promise(function (resolve, reject) {
235
- scope.parse(data, path, resolve, reject);
236
- });
237
- }
238
- }
239
- /* GLTFREGISTRY */
240
-
241
- function GLTFRegistry() {
242
- let objects = {};
243
- return {
244
- get: function (key) {
245
- return objects[key];
246
- },
247
- add: function (key, object) {
248
- objects[key] = object;
249
- },
250
- remove: function (key) {
251
- delete objects[key];
252
- },
253
- removeAll: function () {
254
- objects = {};
255
- },
256
- };
257
- }
258
- /*********************************/
259
-
260
- /********** EXTENSIONS ***********/
261
-
262
- /*********************************/
263
-
264
- const EXTENSIONS = {
265
- KHR_BINARY_GLTF: "KHR_binary_glTF",
266
- KHR_DRACO_MESH_COMPRESSION: "KHR_draco_mesh_compression",
267
- KHR_LIGHTS_PUNCTUAL: "KHR_lights_punctual",
268
- KHR_MATERIALS_CLEARCOAT: "KHR_materials_clearcoat",
269
- KHR_MATERIALS_IOR: "KHR_materials_ior",
270
- KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS: "KHR_materials_pbrSpecularGlossiness",
271
- KHR_MATERIALS_SHEEN: "KHR_materials_sheen",
272
- KHR_MATERIALS_SPECULAR: "KHR_materials_specular",
273
- KHR_MATERIALS_TRANSMISSION: "KHR_materials_transmission",
274
- KHR_MATERIALS_UNLIT: "KHR_materials_unlit",
275
- KHR_MATERIALS_VOLUME: "KHR_materials_volume",
276
- KHR_TEXTURE_BASISU: "KHR_texture_basisu",
277
- KHR_TEXTURE_TRANSFORM: "KHR_texture_transform",
278
- KHR_MESH_QUANTIZATION: "KHR_mesh_quantization",
279
- EXT_TEXTURE_WEBP: "EXT_texture_webp",
280
- EXT_MESHOPT_COMPRESSION: "EXT_meshopt_compression",
281
- };
282
- /**
283
- * Punctual Lights Extension
284
- *
285
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual
286
- */
287
-
288
- class GLTFLightsExtension {
289
- constructor(parser) {
290
- this.parser = parser;
291
- this.name = EXTENSIONS.KHR_LIGHTS_PUNCTUAL; // THREE.Object3D instance caches
292
-
293
- this.cache = {
294
- refs: {},
295
- uses: {},
296
- };
297
- }
298
-
299
- _markDefs() {
300
- const parser = this.parser;
301
- const nodeDefs = this.parser.json.nodes || [];
302
-
303
- for (let nodeIndex = 0, nodeLength = nodeDefs.length; nodeIndex < nodeLength; nodeIndex++) {
304
- const nodeDef = nodeDefs[nodeIndex];
305
-
306
- if (
307
- nodeDef.extensions &&
308
- nodeDef.extensions[this.name] &&
309
- nodeDef.extensions[this.name].light !== undefined
310
- ) {
311
- parser._addNodeRef(this.cache, nodeDef.extensions[this.name].light);
312
- }
313
- }
314
- }
315
-
316
- _loadLight(lightIndex) {
317
- const parser = this.parser;
318
- const cacheKey = "light:" + lightIndex;
319
- let dependency = parser.cache.get(cacheKey);
320
- if (dependency) return dependency;
321
- const json = parser.json;
322
- const extensions = (json.extensions && json.extensions[this.name]) || {};
323
- const lightDefs = extensions.lights || [];
324
- const lightDef = lightDefs[lightIndex];
325
- let lightNode;
326
- const color = new THREE.Color(0xffffff);
327
- if (lightDef.color !== undefined) color.fromArray(lightDef.color);
328
- const range = lightDef.range !== undefined ? lightDef.range : 0;
329
-
330
- switch (lightDef.type) {
331
- case "directional":
332
- lightNode = new THREE.DirectionalLight(color);
333
- lightNode.target.position.set(0, 0, -1);
334
- lightNode.add(lightNode.target);
335
- break;
336
-
337
- case "point":
338
- lightNode = new THREE.PointLight(color);
339
- lightNode.distance = range;
340
- break;
341
-
342
- case "spot":
343
- lightNode = new THREE.SpotLight(color);
344
- lightNode.distance = range; // Handle spotlight properties.
345
-
346
- lightDef.spot = lightDef.spot || {};
347
- lightDef.spot.innerConeAngle =
348
- lightDef.spot.innerConeAngle !== undefined ? lightDef.spot.innerConeAngle : 0;
349
- lightDef.spot.outerConeAngle =
350
- lightDef.spot.outerConeAngle !== undefined
351
- ? lightDef.spot.outerConeAngle
352
- : Math.PI / 4.0;
353
- lightNode.angle = lightDef.spot.outerConeAngle;
354
- lightNode.penumbra = 1.0 - lightDef.spot.innerConeAngle / lightDef.spot.outerConeAngle;
355
- lightNode.target.position.set(0, 0, -1);
356
- lightNode.add(lightNode.target);
357
- break;
358
-
359
- default:
360
- throw new Error("THREE.GLTFLoader: Unexpected light type: " + lightDef.type);
361
- } // Some lights (e.g. spot) default to a position other than the origin. Reset the position
362
- // here, because node-level parsing will only override position if explicitly specified.
363
-
364
- lightNode.position.set(0, 0, 0);
365
- lightNode.decay = 2;
366
- if (lightDef.intensity !== undefined) lightNode.intensity = lightDef.intensity;
367
- lightNode.name = parser.createUniqueName(lightDef.name || "light_" + lightIndex);
368
- dependency = Promise.resolve(lightNode);
369
- parser.cache.add(cacheKey, dependency);
370
- return dependency;
371
- }
372
-
373
- createNodeAttachment(nodeIndex) {
374
- const self = this;
375
- const parser = this.parser;
376
- const json = parser.json;
377
- const nodeDef = json.nodes[nodeIndex];
378
- const lightDef = (nodeDef.extensions && nodeDef.extensions[this.name]) || {};
379
- const lightIndex = lightDef.light;
380
- if (lightIndex === undefined) return null;
381
- return this._loadLight(lightIndex).then(function (light) {
382
- return parser._getNodeRef(self.cache, lightIndex, light);
383
- });
384
- }
385
- }
386
- /**
387
- * Unlit Materials Extension
388
- *
389
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit
390
- */
391
-
392
- class GLTFMaterialsUnlitExtension {
393
- constructor() {
394
- this.name = EXTENSIONS.KHR_MATERIALS_UNLIT;
395
- }
396
-
397
- getMaterialType() {
398
- return THREE.MeshBasicMaterial;
399
- }
400
-
401
- extendParams(materialParams, materialDef, parser) {
402
- const pending = [];
403
- materialParams.color = new THREE.Color(1.0, 1.0, 1.0);
404
- materialParams.opacity = 1.0;
405
- const metallicRoughness = materialDef.pbrMetallicRoughness;
406
-
407
- if (metallicRoughness) {
408
- if (Array.isArray(metallicRoughness.baseColorFactor)) {
409
- const array = metallicRoughness.baseColorFactor;
410
- materialParams.color.fromArray(array);
411
- materialParams.opacity = array[3];
412
- }
413
-
414
- if (metallicRoughness.baseColorTexture !== undefined) {
415
- pending.push(
416
- parser.assignTexture(materialParams, "map", metallicRoughness.baseColorTexture)
417
- );
418
- }
419
- }
420
-
421
- return Promise.all(pending);
422
- }
423
- }
424
- /**
425
- * Clearcoat Materials Extension
426
- *
427
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_clearcoat
428
- */
429
-
430
- class GLTFMaterialsClearcoatExtension {
431
- constructor(parser) {
432
- this.parser = parser;
433
- this.name = EXTENSIONS.KHR_MATERIALS_CLEARCOAT;
434
- }
435
-
436
- getMaterialType(materialIndex) {
437
- const parser = this.parser;
438
- const materialDef = parser.json.materials[materialIndex];
439
- if (!materialDef.extensions || !materialDef.extensions[this.name]) return null;
440
- return THREE.MeshPhysicalMaterial;
441
- }
442
-
443
- extendMaterialParams(materialIndex, materialParams) {
444
- const parser = this.parser;
445
- const materialDef = parser.json.materials[materialIndex];
446
-
447
- if (!materialDef.extensions || !materialDef.extensions[this.name]) {
448
- return Promise.resolve();
449
- }
450
-
451
- const pending = [];
452
- const extension = materialDef.extensions[this.name];
453
-
454
- if (extension.clearcoatFactor !== undefined) {
455
- materialParams.clearcoat = extension.clearcoatFactor;
456
- }
457
-
458
- if (extension.clearcoatTexture !== undefined) {
459
- pending.push(
460
- parser.assignTexture(materialParams, "clearcoatMap", extension.clearcoatTexture)
461
- );
462
- }
463
-
464
- if (extension.clearcoatRoughnessFactor !== undefined) {
465
- materialParams.clearcoatRoughness = extension.clearcoatRoughnessFactor;
466
- }
467
-
468
- if (extension.clearcoatRoughnessTexture !== undefined) {
469
- pending.push(
470
- parser.assignTexture(
471
- materialParams,
472
- "clearcoatRoughnessMap",
473
- extension.clearcoatRoughnessTexture
474
- )
475
- );
476
- }
477
-
478
- if (extension.clearcoatNormalTexture !== undefined) {
479
- pending.push(
480
- parser.assignTexture(
481
- materialParams,
482
- "clearcoatNormalMap",
483
- extension.clearcoatNormalTexture
484
- )
485
- );
486
-
487
- if (extension.clearcoatNormalTexture.scale !== undefined) {
488
- const scale = extension.clearcoatNormalTexture.scale;
489
- materialParams.clearcoatNormalScale = new THREE.Vector2(scale, scale);
490
- }
491
- }
492
-
493
- return Promise.all(pending);
494
- }
495
- }
496
- /**
497
- * Sheen Materials Extension
498
- *
499
- * Specification: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_sheen
500
- */
501
-
502
- class GLTFMaterialsSheenExtension {
503
- constructor(parser) {
504
- this.parser = parser;
505
- this.name = EXTENSIONS.KHR_MATERIALS_SHEEN;
506
- }
507
-
508
- getMaterialType(materialIndex) {
509
- const parser = this.parser;
510
- const materialDef = parser.json.materials[materialIndex];
511
- if (!materialDef.extensions || !materialDef.extensions[this.name]) return null;
512
- return THREE.MeshPhysicalMaterial;
513
- }
514
-
515
- extendMaterialParams(materialIndex, materialParams) {
516
- const parser = this.parser;
517
- const materialDef = parser.json.materials[materialIndex];
518
-
519
- if (!materialDef.extensions || !materialDef.extensions[this.name]) {
520
- return Promise.resolve();
521
- }
522
-
523
- const pending = [];
524
- materialParams.sheenColor = new THREE.Color(0, 0, 0);
525
- materialParams.sheenRoughness = 0;
526
- materialParams.sheen = 1;
527
- const extension = materialDef.extensions[this.name];
528
-
529
- if (extension.sheenColorFactor !== undefined) {
530
- materialParams.sheenColor.fromArray(extension.sheenColorFactor);
531
- }
532
-
533
- if (extension.sheenRoughnessFactor !== undefined) {
534
- materialParams.sheenRoughness = extension.sheenRoughnessFactor;
535
- }
536
-
537
- if (extension.sheenColorTexture !== undefined) {
538
- pending.push(
539
- parser.assignTexture(materialParams, "sheenColorMap", extension.sheenColorTexture)
540
- );
541
- }
542
-
543
- if (extension.sheenRoughnessTexture !== undefined) {
544
- pending.push(
545
- parser.assignTexture(materialParams, "sheenRoughnessMap", extension.sheenRoughnessTexture)
546
- );
547
- }
548
-
549
- return Promise.all(pending);
550
- }
551
- }
552
- /**
553
- * Transmission Materials Extension
554
- *
555
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_transmission
556
- * Draft: https://github.com/KhronosGroup/glTF/pull/1698
557
- */
558
-
559
- class GLTFMaterialsTransmissionExtension {
560
- constructor(parser) {
561
- this.parser = parser;
562
- this.name = EXTENSIONS.KHR_MATERIALS_TRANSMISSION;
563
- }
564
-
565
- getMaterialType(materialIndex) {
566
- const parser = this.parser;
567
- const materialDef = parser.json.materials[materialIndex];
568
- if (!materialDef.extensions || !materialDef.extensions[this.name]) return null;
569
- return THREE.MeshPhysicalMaterial;
570
- }
571
-
572
- extendMaterialParams(materialIndex, materialParams) {
573
- const parser = this.parser;
574
- const materialDef = parser.json.materials[materialIndex];
575
-
576
- if (!materialDef.extensions || !materialDef.extensions[this.name]) {
577
- return Promise.resolve();
578
- }
579
-
580
- const pending = [];
581
- const extension = materialDef.extensions[this.name];
582
-
583
- if (extension.transmissionFactor !== undefined) {
584
- materialParams.transmission = extension.transmissionFactor;
585
- }
586
-
587
- if (extension.transmissionTexture !== undefined) {
588
- pending.push(
589
- parser.assignTexture(materialParams, "transmissionMap", extension.transmissionTexture)
590
- );
591
- }
592
-
593
- return Promise.all(pending);
594
- }
595
- }
596
- /**
597
- * Materials Volume Extension
598
- *
599
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_volume
600
- */
601
-
602
- class GLTFMaterialsVolumeExtension {
603
- constructor(parser) {
604
- this.parser = parser;
605
- this.name = EXTENSIONS.KHR_MATERIALS_VOLUME;
606
- }
607
-
608
- getMaterialType(materialIndex) {
609
- const parser = this.parser;
610
- const materialDef = parser.json.materials[materialIndex];
611
- if (!materialDef.extensions || !materialDef.extensions[this.name]) return null;
612
- return THREE.MeshPhysicalMaterial;
613
- }
614
-
615
- extendMaterialParams(materialIndex, materialParams) {
616
- const parser = this.parser;
617
- const materialDef = parser.json.materials[materialIndex];
618
-
619
- if (!materialDef.extensions || !materialDef.extensions[this.name]) {
620
- return Promise.resolve();
621
- }
622
-
623
- const pending = [];
624
- const extension = materialDef.extensions[this.name];
625
- materialParams.thickness =
626
- extension.thicknessFactor !== undefined ? extension.thicknessFactor : 0;
627
-
628
- if (extension.thicknessTexture !== undefined) {
629
- pending.push(
630
- parser.assignTexture(materialParams, "thicknessMap", extension.thicknessTexture)
631
- );
632
- }
633
-
634
- materialParams.attenuationDistance = extension.attenuationDistance || 0;
635
- const colorArray = extension.attenuationColor || [1, 1, 1];
636
- materialParams.attenuationColor = new THREE.Color(
637
- colorArray[0],
638
- colorArray[1],
639
- colorArray[2]
640
- );
641
- return Promise.all(pending);
642
- }
643
- }
644
- /**
645
- * Materials ior Extension
646
- *
647
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_ior
648
- */
649
-
650
- class GLTFMaterialsIorExtension {
651
- constructor(parser) {
652
- this.parser = parser;
653
- this.name = EXTENSIONS.KHR_MATERIALS_IOR;
654
- }
655
-
656
- getMaterialType(materialIndex) {
657
- const parser = this.parser;
658
- const materialDef = parser.json.materials[materialIndex];
659
- if (!materialDef.extensions || !materialDef.extensions[this.name]) return null;
660
- return THREE.MeshPhysicalMaterial;
661
- }
662
-
663
- extendMaterialParams(materialIndex, materialParams) {
664
- const parser = this.parser;
665
- const materialDef = parser.json.materials[materialIndex];
666
-
667
- if (!materialDef.extensions || !materialDef.extensions[this.name]) {
668
- return Promise.resolve();
669
- }
670
-
671
- const extension = materialDef.extensions[this.name];
672
- materialParams.ior = extension.ior !== undefined ? extension.ior : 1.5;
673
- return Promise.resolve();
674
- }
675
- }
676
- /**
677
- * Materials specular Extension
678
- *
679
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_specular
680
- */
681
-
682
- class GLTFMaterialsSpecularExtension {
683
- constructor(parser) {
684
- this.parser = parser;
685
- this.name = EXTENSIONS.KHR_MATERIALS_SPECULAR;
686
- }
687
-
688
- getMaterialType(materialIndex) {
689
- const parser = this.parser;
690
- const materialDef = parser.json.materials[materialIndex];
691
- if (!materialDef.extensions || !materialDef.extensions[this.name]) return null;
692
- return THREE.MeshPhysicalMaterial;
693
- }
694
-
695
- extendMaterialParams(materialIndex, materialParams) {
696
- const parser = this.parser;
697
- const materialDef = parser.json.materials[materialIndex];
698
-
699
- if (!materialDef.extensions || !materialDef.extensions[this.name]) {
700
- return Promise.resolve();
701
- }
702
-
703
- const pending = [];
704
- const extension = materialDef.extensions[this.name];
705
- materialParams.specularIntensity =
706
- extension.specularFactor !== undefined ? extension.specularFactor : 1.0;
707
-
708
- if (extension.specularTexture !== undefined) {
709
- pending.push(
710
- parser.assignTexture(materialParams, "specularIntensityMap", extension.specularTexture)
711
- );
712
- }
713
-
714
- const colorArray = extension.specularColorFactor || [1, 1, 1];
715
- materialParams.specularColor = new THREE.Color(colorArray[0], colorArray[1], colorArray[2]);
716
-
717
- if (extension.specularColorTexture !== undefined) {
718
- pending.push(
719
- parser
720
- .assignTexture(materialParams, "specularColorMap", extension.specularColorTexture)
721
- .then(function (texture) {
722
- texture.encoding = THREE.sRGBEncoding;
723
- })
724
- );
725
- }
726
-
727
- return Promise.all(pending);
728
- }
729
- }
730
- /**
731
- * BasisU THREE.Texture Extension
732
- *
733
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_texture_basisu
734
- */
735
-
736
- class GLTFTextureBasisUExtension {
737
- constructor(parser) {
738
- this.parser = parser;
739
- this.name = EXTENSIONS.KHR_TEXTURE_BASISU;
740
- }
741
-
742
- loadTexture(textureIndex) {
743
- const parser = this.parser;
744
- const json = parser.json;
745
- const textureDef = json.textures[textureIndex];
746
-
747
- if (!textureDef.extensions || !textureDef.extensions[this.name]) {
748
- return null;
749
- }
750
-
751
- const extension = textureDef.extensions[this.name];
752
- const source = json.images[extension.source];
753
- const loader = parser.options.ktx2Loader;
754
-
755
- if (!loader) {
756
- if (json.extensionsRequired && json.extensionsRequired.indexOf(this.name) >= 0) {
757
- throw new Error(
758
- "THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures"
759
- );
760
- } else {
761
- // Assumes that the extension is optional and that a fallback texture is present
762
- return null;
763
- }
764
- }
765
-
766
- return parser.loadTextureImage(textureIndex, source, loader);
767
- }
768
- }
769
- /**
770
- * WebP THREE.Texture Extension
771
- *
772
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_texture_webp
773
- */
774
-
775
- class GLTFTextureWebPExtension {
776
- constructor(parser) {
777
- this.parser = parser;
778
- this.name = EXTENSIONS.EXT_TEXTURE_WEBP;
779
- this.isSupported = null;
780
- }
781
-
782
- loadTexture(textureIndex) {
783
- const name = this.name;
784
- const parser = this.parser;
785
- const json = parser.json;
786
- const textureDef = json.textures[textureIndex];
787
-
788
- if (!textureDef.extensions || !textureDef.extensions[name]) {
789
- return null;
790
- }
791
-
792
- const extension = textureDef.extensions[name];
793
- const source = json.images[extension.source];
794
- let loader = parser.textureLoader;
795
-
796
- if (source.uri) {
797
- const handler = parser.options.manager.getHandler(source.uri);
798
- if (handler !== null) loader = handler;
799
- }
800
-
801
- return this.detectSupport().then(function (isSupported) {
802
- if (isSupported) return parser.loadTextureImage(textureIndex, source, loader);
803
-
804
- if (json.extensionsRequired && json.extensionsRequired.indexOf(name) >= 0) {
805
- throw new Error("THREE.GLTFLoader: WebP required by asset but unsupported.");
806
- } // Fall back to PNG or JPEG.
807
-
808
- return parser.loadTexture(textureIndex);
809
- });
810
- }
811
-
812
- detectSupport() {
813
- if (!this.isSupported) {
814
- this.isSupported = new Promise(function (resolve) {
815
- const image = new Image(); // Lossy test image. Support for lossy images doesn't guarantee support for all
816
- // WebP images, unfortunately.
817
-
818
- image.src =
819
- "data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA";
820
-
821
- image.onload = image.onerror = function () {
822
- resolve(image.height === 1);
823
- };
824
- });
825
- }
826
-
827
- return this.isSupported;
828
- }
829
- }
830
- /**
831
- * meshopt BufferView Compression Extension
832
- *
833
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_meshopt_compression
834
- */
835
-
836
- class GLTFMeshoptCompression {
837
- constructor(parser) {
838
- this.name = EXTENSIONS.EXT_MESHOPT_COMPRESSION;
839
- this.parser = parser;
840
- }
841
-
842
- loadBufferView(index) {
843
- const json = this.parser.json;
844
- const bufferView = json.bufferViews[index];
845
-
846
- if (bufferView.extensions && bufferView.extensions[this.name]) {
847
- const extensionDef = bufferView.extensions[this.name];
848
- const buffer = this.parser.getDependency("buffer", extensionDef.buffer);
849
- const decoder = this.parser.options.meshoptDecoder;
850
-
851
- if (!decoder || !decoder.supported) {
852
- if (json.extensionsRequired && json.extensionsRequired.indexOf(this.name) >= 0) {
853
- throw new Error(
854
- "THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files"
855
- );
856
- } else {
857
- // Assumes that the extension is optional and that fallback buffer data is present
858
- return null;
859
- }
860
- }
861
-
862
- return Promise.all([buffer, decoder.ready]).then(function (res) {
863
- const byteOffset = extensionDef.byteOffset || 0;
864
- const byteLength = extensionDef.byteLength || 0;
865
- const count = extensionDef.count;
866
- const stride = extensionDef.byteStride;
867
- const result = new ArrayBuffer(count * stride);
868
- const source = new Uint8Array(res[0], byteOffset, byteLength);
869
- decoder.decodeGltfBuffer(
870
- new Uint8Array(result),
871
- count,
872
- stride,
873
- source,
874
- extensionDef.mode,
875
- extensionDef.filter
876
- );
877
- return result;
878
- });
879
- } else {
880
- return null;
881
- }
882
- }
883
- }
884
- /* BINARY EXTENSION */
885
-
886
- const BINARY_EXTENSION_HEADER_MAGIC = "glTF";
887
- const BINARY_EXTENSION_HEADER_LENGTH = 12;
888
- const BINARY_EXTENSION_CHUNK_TYPES = {
889
- JSON: 0x4e4f534a,
890
- BIN: 0x004e4942,
891
- };
892
-
893
- class GLTFBinaryExtension {
894
- constructor(data) {
895
- this.name = EXTENSIONS.KHR_BINARY_GLTF;
896
- this.content = null;
897
- this.body = null;
898
- const headerView = new DataView(data, 0, BINARY_EXTENSION_HEADER_LENGTH);
899
- this.header = {
900
- magic: THREE.LoaderUtils.decodeText(new Uint8Array(data.slice(0, 4))),
901
- version: headerView.getUint32(4, true),
902
- length: headerView.getUint32(8, true),
903
- };
904
-
905
- if (this.header.magic !== BINARY_EXTENSION_HEADER_MAGIC) {
906
- throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");
907
- } else if (this.header.version < 2.0) {
908
- throw new Error("THREE.GLTFLoader: Legacy binary file detected.");
909
- }
910
-
911
- const chunkContentsLength = this.header.length - BINARY_EXTENSION_HEADER_LENGTH;
912
- const chunkView = new DataView(data, BINARY_EXTENSION_HEADER_LENGTH);
913
- let chunkIndex = 0;
914
-
915
- while (chunkIndex < chunkContentsLength) {
916
- const chunkLength = chunkView.getUint32(chunkIndex, true);
917
- chunkIndex += 4;
918
- const chunkType = chunkView.getUint32(chunkIndex, true);
919
- chunkIndex += 4;
920
-
921
- if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.JSON) {
922
- const contentArray = new Uint8Array(
923
- data,
924
- BINARY_EXTENSION_HEADER_LENGTH + chunkIndex,
925
- chunkLength
926
- );
927
- this.content = THREE.LoaderUtils.decodeText(contentArray);
928
- } else if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.BIN) {
929
- const byteOffset = BINARY_EXTENSION_HEADER_LENGTH + chunkIndex;
930
- this.body = data.slice(byteOffset, byteOffset + chunkLength);
931
- } // Clients must ignore chunks with unknown types.
932
-
933
- chunkIndex += chunkLength;
934
- }
935
-
936
- if (this.content === null) {
937
- throw new Error("THREE.GLTFLoader: JSON content not found.");
938
- }
939
- }
940
- }
941
- /**
942
- * DRACO THREE.Mesh Compression Extension
943
- *
944
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression
945
- */
946
-
947
- class GLTFDracoMeshCompressionExtension {
948
- constructor(json, dracoLoader) {
949
- if (!dracoLoader) {
950
- throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");
951
- }
952
-
953
- this.name = EXTENSIONS.KHR_DRACO_MESH_COMPRESSION;
954
- this.json = json;
955
- this.dracoLoader = dracoLoader;
956
- this.dracoLoader.preload();
957
- }
958
-
959
- decodePrimitive(primitive, parser) {
960
- const json = this.json;
961
- const dracoLoader = this.dracoLoader;
962
- const bufferViewIndex = primitive.extensions[this.name].bufferView;
963
- const gltfAttributeMap = primitive.extensions[this.name].attributes;
964
- const threeAttributeMap = {};
965
- const attributeNormalizedMap = {};
966
- const attributeTypeMap = {};
967
-
968
- for (const attributeName in gltfAttributeMap) {
969
- const threeAttributeName = ATTRIBUTES[attributeName] || attributeName.toLowerCase();
970
- threeAttributeMap[threeAttributeName] = gltfAttributeMap[attributeName];
971
- }
972
-
973
- for (const attributeName in primitive.attributes) {
974
- const threeAttributeName = ATTRIBUTES[attributeName] || attributeName.toLowerCase();
975
-
976
- if (gltfAttributeMap[attributeName] !== undefined) {
977
- const accessorDef = json.accessors[primitive.attributes[attributeName]];
978
- const componentType = WEBGL_COMPONENT_TYPES[accessorDef.componentType];
979
- attributeTypeMap[threeAttributeName] = componentType;
980
- attributeNormalizedMap[threeAttributeName] = accessorDef.normalized === true;
981
- }
982
- }
983
-
984
- return parser.getDependency("bufferView", bufferViewIndex).then(function (bufferView) {
985
- return new Promise(function (resolve) {
986
- dracoLoader.decodeDracoFile(
987
- bufferView,
988
- function (geometry) {
989
- for (const attributeName in geometry.attributes) {
990
- const attribute = geometry.attributes[attributeName];
991
- const normalized = attributeNormalizedMap[attributeName];
992
- if (normalized !== undefined) attribute.normalized = normalized;
993
- }
994
-
995
- resolve(geometry);
996
- },
997
- threeAttributeMap,
998
- attributeTypeMap
999
- );
1000
- });
1001
- });
1002
- }
1003
- }
1004
- /**
1005
- * THREE.Texture Transform Extension
1006
- *
1007
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_texture_transform
1008
- */
1009
-
1010
- class GLTFTextureTransformExtension {
1011
- constructor() {
1012
- this.name = EXTENSIONS.KHR_TEXTURE_TRANSFORM;
1013
- }
1014
-
1015
- extendTexture(texture, transform) {
1016
- if (transform.texCoord !== undefined) {
1017
- console.warn(
1018
- 'THREE.GLTFLoader: Custom UV sets in "' + this.name + '" extension not yet supported.'
1019
- );
1020
- }
1021
-
1022
- if (
1023
- transform.offset === undefined &&
1024
- transform.rotation === undefined &&
1025
- transform.scale === undefined
1026
- ) {
1027
- // See https://github.com/mrdoob/three.js/issues/21819.
1028
- return texture;
1029
- }
1030
-
1031
- texture = texture.clone();
1032
-
1033
- if (transform.offset !== undefined) {
1034
- texture.offset.fromArray(transform.offset);
1035
- }
1036
-
1037
- if (transform.rotation !== undefined) {
1038
- texture.rotation = transform.rotation;
1039
- }
1040
-
1041
- if (transform.scale !== undefined) {
1042
- texture.repeat.fromArray(transform.scale);
1043
- }
1044
-
1045
- texture.needsUpdate = true;
1046
- return texture;
1047
- }
1048
- }
1049
- /**
1050
- * Specular-Glossiness Extension
1051
- *
1052
- * Specification: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Archived/KHR_materials_pbrSpecularGlossiness
1053
- */
1054
-
1055
- /**
1056
- * A sub class of StandardMaterial with some of the functionality
1057
- * changed via the `onBeforeCompile` callback
1058
- * @pailhead
1059
- */
1060
-
1061
- class GLTFMeshStandardSGMaterial extends THREE.MeshStandardMaterial {
1062
- constructor(params) {
1063
- super();
1064
- this.isGLTFSpecularGlossinessMaterial = true; //various chunks that need replacing
1065
-
1066
- const specularMapParsFragmentChunk = [
1067
- "#ifdef USE_SPECULARMAP",
1068
- " uniform sampler2D specularMap;",
1069
- "#endif",
1070
- ].join("\n");
1071
- const glossinessMapParsFragmentChunk = [
1072
- "#ifdef USE_GLOSSINESSMAP",
1073
- " uniform sampler2D glossinessMap;",
1074
- "#endif",
1075
- ].join("\n");
1076
- const specularMapFragmentChunk = [
1077
- "vec3 specularFactor = specular;",
1078
- "#ifdef USE_SPECULARMAP",
1079
- " vec4 texelSpecular = texture2D( specularMap, vUv );",
1080
- " // reads channel RGB, compatible with a glTF Specular-Glossiness (RGBA) texture",
1081
- " specularFactor *= texelSpecular.rgb;",
1082
- "#endif",
1083
- ].join("\n");
1084
- const glossinessMapFragmentChunk = [
1085
- "float glossinessFactor = glossiness;",
1086
- "#ifdef USE_GLOSSINESSMAP",
1087
- " vec4 texelGlossiness = texture2D( glossinessMap, vUv );",
1088
- " // reads channel A, compatible with a glTF Specular-Glossiness (RGBA) texture",
1089
- " glossinessFactor *= texelGlossiness.a;",
1090
- "#endif",
1091
- ].join("\n");
1092
- const lightPhysicalFragmentChunk = [
1093
- "PhysicalMaterial material;",
1094
- "material.diffuseColor = diffuseColor.rgb * ( 1. - max( specularFactor.r, max( specularFactor.g, specularFactor.b ) ) );",
1095
- "vec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );",
1096
- "float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );",
1097
- "material.roughness = max( 1.0 - glossinessFactor, 0.0525 ); // 0.0525 corresponds to the base mip of a 256 cubemap.",
1098
- "material.roughness += geometryRoughness;",
1099
- "material.roughness = min( material.roughness, 1.0 );",
1100
- "material.specularColor = specularFactor;",
1101
- ].join("\n");
1102
- const uniforms = {
1103
- specular: {
1104
- value: new THREE.Color().setHex(0xffffff),
1105
- },
1106
- glossiness: {
1107
- value: 1,
1108
- },
1109
- specularMap: {
1110
- value: null,
1111
- },
1112
- glossinessMap: {
1113
- value: null,
1114
- },
1115
- };
1116
- this._extraUniforms = uniforms;
1117
-
1118
- this.onBeforeCompile = function (shader) {
1119
- for (const uniformName in uniforms) {
1120
- shader.uniforms[uniformName] = uniforms[uniformName];
1121
- }
1122
-
1123
- shader.fragmentShader = shader.fragmentShader
1124
- .replace("uniform float roughness;", "uniform vec3 specular;")
1125
- .replace("uniform float metalness;", "uniform float glossiness;")
1126
- .replace("#include <roughnessmap_pars_fragment>", specularMapParsFragmentChunk)
1127
- .replace("#include <metalnessmap_pars_fragment>", glossinessMapParsFragmentChunk)
1128
- .replace("#include <roughnessmap_fragment>", specularMapFragmentChunk)
1129
- .replace("#include <metalnessmap_fragment>", glossinessMapFragmentChunk)
1130
- .replace("#include <lights_physical_fragment>", lightPhysicalFragmentChunk);
1131
- };
1132
-
1133
- Object.defineProperties(this, {
1134
- specular: {
1135
- get: function () {
1136
- return uniforms.specular.value;
1137
- },
1138
- set: function (v) {
1139
- uniforms.specular.value = v;
1140
- },
1141
- },
1142
- specularMap: {
1143
- get: function () {
1144
- return uniforms.specularMap.value;
1145
- },
1146
- set: function (v) {
1147
- uniforms.specularMap.value = v;
1148
-
1149
- if (v) {
1150
- this.defines.USE_SPECULARMAP = ""; // USE_UV is set by the renderer for specular maps
1151
- } else {
1152
- delete this.defines.USE_SPECULARMAP;
1153
- }
1154
- },
1155
- },
1156
- glossiness: {
1157
- get: function () {
1158
- return uniforms.glossiness.value;
1159
- },
1160
- set: function (v) {
1161
- uniforms.glossiness.value = v;
1162
- },
1163
- },
1164
- glossinessMap: {
1165
- get: function () {
1166
- return uniforms.glossinessMap.value;
1167
- },
1168
- set: function (v) {
1169
- uniforms.glossinessMap.value = v;
1170
-
1171
- if (v) {
1172
- this.defines.USE_GLOSSINESSMAP = "";
1173
- this.defines.USE_UV = "";
1174
- } else {
1175
- delete this.defines.USE_GLOSSINESSMAP;
1176
- delete this.defines.USE_UV;
1177
- }
1178
- },
1179
- },
1180
- });
1181
- delete this.metalness;
1182
- delete this.roughness;
1183
- delete this.metalnessMap;
1184
- delete this.roughnessMap;
1185
- this.setValues(params);
1186
- }
1187
-
1188
- copy(source) {
1189
- super.copy(source);
1190
- this.specularMap = source.specularMap;
1191
- this.specular.copy(source.specular);
1192
- this.glossinessMap = source.glossinessMap;
1193
- this.glossiness = source.glossiness;
1194
- delete this.metalness;
1195
- delete this.roughness;
1196
- delete this.metalnessMap;
1197
- delete this.roughnessMap;
1198
- return this;
1199
- }
1200
- }
1201
-
1202
- class GLTFMaterialsPbrSpecularGlossinessExtension {
1203
- constructor() {
1204
- this.name = EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS;
1205
- this.specularGlossinessParams = [
1206
- "color",
1207
- "map",
1208
- "lightMap",
1209
- "lightMapIntensity",
1210
- "aoMap",
1211
- "aoMapIntensity",
1212
- "emissive",
1213
- "emissiveIntensity",
1214
- "emissiveMap",
1215
- "bumpMap",
1216
- "bumpScale",
1217
- "normalMap",
1218
- "normalMapType",
1219
- "displacementMap",
1220
- "displacementScale",
1221
- "displacementBias",
1222
- "specularMap",
1223
- "specular",
1224
- "glossinessMap",
1225
- "glossiness",
1226
- "alphaMap",
1227
- "envMap",
1228
- "envMapIntensity",
1229
- "refractionRatio",
1230
- ];
1231
- }
1232
-
1233
- getMaterialType() {
1234
- return GLTFMeshStandardSGMaterial;
1235
- }
1236
-
1237
- extendParams(materialParams, materialDef, parser) {
1238
- const pbrSpecularGlossiness = materialDef.extensions[this.name];
1239
- materialParams.color = new THREE.Color(1.0, 1.0, 1.0);
1240
- materialParams.opacity = 1.0;
1241
- const pending = [];
1242
-
1243
- if (Array.isArray(pbrSpecularGlossiness.diffuseFactor)) {
1244
- const array = pbrSpecularGlossiness.diffuseFactor;
1245
- materialParams.color.fromArray(array);
1246
- materialParams.opacity = array[3];
1247
- }
1248
-
1249
- if (pbrSpecularGlossiness.diffuseTexture !== undefined) {
1250
- pending.push(
1251
- parser.assignTexture(materialParams, "map", pbrSpecularGlossiness.diffuseTexture)
1252
- );
1253
- }
1254
-
1255
- materialParams.emissive = new THREE.Color(0.0, 0.0, 0.0);
1256
- materialParams.glossiness =
1257
- pbrSpecularGlossiness.glossinessFactor !== undefined
1258
- ? pbrSpecularGlossiness.glossinessFactor
1259
- : 1.0;
1260
- materialParams.specular = new THREE.Color(1.0, 1.0, 1.0);
1261
-
1262
- if (Array.isArray(pbrSpecularGlossiness.specularFactor)) {
1263
- materialParams.specular.fromArray(pbrSpecularGlossiness.specularFactor);
1264
- }
1265
-
1266
- if (pbrSpecularGlossiness.specularGlossinessTexture !== undefined) {
1267
- const specGlossMapDef = pbrSpecularGlossiness.specularGlossinessTexture;
1268
- pending.push(parser.assignTexture(materialParams, "glossinessMap", specGlossMapDef));
1269
- pending.push(parser.assignTexture(materialParams, "specularMap", specGlossMapDef));
1270
- }
1271
-
1272
- return Promise.all(pending);
1273
- }
1274
-
1275
- createMaterial(materialParams) {
1276
- const material = new GLTFMeshStandardSGMaterial(materialParams);
1277
- material.fog = true;
1278
- material.color = materialParams.color;
1279
- material.map = materialParams.map === undefined ? null : materialParams.map;
1280
- material.lightMap = null;
1281
- material.lightMapIntensity = 1.0;
1282
- material.aoMap = materialParams.aoMap === undefined ? null : materialParams.aoMap;
1283
- material.aoMapIntensity = 1.0;
1284
- material.emissive = materialParams.emissive;
1285
- material.emissiveIntensity = 1.0;
1286
- material.emissiveMap =
1287
- materialParams.emissiveMap === undefined ? null : materialParams.emissiveMap;
1288
- material.bumpMap = materialParams.bumpMap === undefined ? null : materialParams.bumpMap;
1289
- material.bumpScale = 1;
1290
- material.normalMap = materialParams.normalMap === undefined ? null : materialParams.normalMap;
1291
- material.normalMapType = THREE.TangentSpaceNormalMap;
1292
- if (materialParams.normalScale) material.normalScale = materialParams.normalScale;
1293
- material.displacementMap = null;
1294
- material.displacementScale = 1;
1295
- material.displacementBias = 0;
1296
- material.specularMap =
1297
- materialParams.specularMap === undefined ? null : materialParams.specularMap;
1298
- material.specular = materialParams.specular;
1299
- material.glossinessMap =
1300
- materialParams.glossinessMap === undefined ? null : materialParams.glossinessMap;
1301
- material.glossiness = materialParams.glossiness;
1302
- material.alphaMap = null;
1303
- material.envMap = materialParams.envMap === undefined ? null : materialParams.envMap;
1304
- material.envMapIntensity = 1.0;
1305
- material.refractionRatio = 0.98;
1306
- return material;
1307
- }
1308
- }
1309
- /**
1310
- * THREE.Mesh Quantization Extension
1311
- *
1312
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization
1313
- */
1314
-
1315
- class GLTFMeshQuantizationExtension {
1316
- constructor() {
1317
- this.name = EXTENSIONS.KHR_MESH_QUANTIZATION;
1318
- }
1319
- }
1320
- /*********************************/
1321
-
1322
- /********** INTERPOLATION ********/
1323
-
1324
- /*********************************/
1325
- // Spline Interpolation
1326
- // Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#appendix-c-spline-interpolation
1327
-
1328
- class GLTFCubicSplineInterpolant extends THREE.Interpolant {
1329
- constructor(parameterPositions, sampleValues, sampleSize, resultBuffer) {
1330
- super(parameterPositions, sampleValues, sampleSize, resultBuffer);
1331
- }
1332
-
1333
- copySampleValue_(index) {
1334
- // Copies a sample value to the result buffer. See description of glTF
1335
- // CUBICSPLINE values layout in interpolate_() function below.
1336
- const result = this.resultBuffer,
1337
- values = this.sampleValues,
1338
- valueSize = this.valueSize,
1339
- offset = index * valueSize * 3 + valueSize;
1340
-
1341
- for (let i = 0; i !== valueSize; i++) {
1342
- result[i] = values[offset + i];
1343
- }
1344
-
1345
- return result;
1346
- }
1347
- }
1348
-
1349
- GLTFCubicSplineInterpolant.prototype.beforeStart_ =
1350
- GLTFCubicSplineInterpolant.prototype.copySampleValue_;
1351
- GLTFCubicSplineInterpolant.prototype.afterEnd_ =
1352
- GLTFCubicSplineInterpolant.prototype.copySampleValue_;
1353
-
1354
- GLTFCubicSplineInterpolant.prototype.interpolate_ = function (i1, t0, t, t1) {
1355
- const result = this.resultBuffer;
1356
- const values = this.sampleValues;
1357
- const stride = this.valueSize;
1358
- const stride2 = stride * 2;
1359
- const stride3 = stride * 3;
1360
- const td = t1 - t0;
1361
- const p = (t - t0) / td;
1362
- const pp = p * p;
1363
- const ppp = pp * p;
1364
- const offset1 = i1 * stride3;
1365
- const offset0 = offset1 - stride3;
1366
- const s2 = -2 * ppp + 3 * pp;
1367
- const s3 = ppp - pp;
1368
- const s0 = 1 - s2;
1369
- const s1 = s3 - pp + p; // Layout of keyframe output values for CUBICSPLINE animations:
1370
- // [ inTangent_1, splineVertex_1, outTangent_1, inTangent_2, splineVertex_2, ... ]
1371
-
1372
- for (let i = 0; i !== stride; i++) {
1373
- const p0 = values[offset0 + i + stride]; // splineVertex_k
1374
-
1375
- const m0 = values[offset0 + i + stride2] * td; // outTangent_k * (t_k+1 - t_k)
1376
-
1377
- const p1 = values[offset1 + i + stride]; // splineVertex_k+1
1378
-
1379
- const m1 = values[offset1 + i] * td; // inTangent_k+1 * (t_k+1 - t_k)
1380
-
1381
- result[i] = s0 * p0 + s1 * m0 + s2 * p1 + s3 * m1;
1382
- }
1383
-
1384
- return result;
1385
- };
1386
-
1387
- const _q = new THREE.Quaternion();
1388
-
1389
- class GLTFCubicSplineQuaternionInterpolant extends GLTFCubicSplineInterpolant {
1390
- interpolate_(i1, t0, t, t1) {
1391
- const result = super.interpolate_(i1, t0, t, t1);
1392
-
1393
- _q.fromArray(result).normalize().toArray(result);
1394
-
1395
- return result;
1396
- }
1397
- }
1398
- /*********************************/
1399
-
1400
- /********** INTERNALS ************/
1401
-
1402
- /*********************************/
1403
-
1404
- /* CONSTANTS */
1405
-
1406
- const WEBGL_CONSTANTS = {
1407
- FLOAT: 5126,
1408
- //FLOAT_MAT2: 35674,
1409
- FLOAT_MAT3: 35675,
1410
- FLOAT_MAT4: 35676,
1411
- FLOAT_VEC2: 35664,
1412
- FLOAT_VEC3: 35665,
1413
- FLOAT_VEC4: 35666,
1414
- LINEAR: 9729,
1415
- REPEAT: 10497,
1416
- SAMPLER_2D: 35678,
1417
- POINTS: 0,
1418
- LINES: 1,
1419
- LINE_LOOP: 2,
1420
- LINE_STRIP: 3,
1421
- TRIANGLES: 4,
1422
- TRIANGLE_STRIP: 5,
1423
- TRIANGLE_FAN: 6,
1424
- UNSIGNED_BYTE: 5121,
1425
- UNSIGNED_SHORT: 5123,
1426
- };
1427
- const WEBGL_COMPONENT_TYPES = {
1428
- 5120: Int8Array,
1429
- 5121: Uint8Array,
1430
- 5122: Int16Array,
1431
- 5123: Uint16Array,
1432
- 5125: Uint32Array,
1433
- 5126: Float32Array,
1434
- };
1435
- const WEBGL_FILTERS = {
1436
- 9728: THREE.NearestFilter,
1437
- 9729: THREE.LinearFilter,
1438
- 9984: THREE.NearestMipmapNearestFilter,
1439
- 9985: THREE.LinearMipmapNearestFilter,
1440
- 9986: THREE.NearestMipmapLinearFilter,
1441
- 9987: THREE.LinearMipmapLinearFilter,
1442
- };
1443
- const WEBGL_WRAPPINGS = {
1444
- 33071: THREE.ClampToEdgeWrapping,
1445
- 33648: THREE.MirroredRepeatWrapping,
1446
- 10497: THREE.RepeatWrapping,
1447
- };
1448
- const WEBGL_TYPE_SIZES = {
1449
- SCALAR: 1,
1450
- VEC2: 2,
1451
- VEC3: 3,
1452
- VEC4: 4,
1453
- MAT2: 4,
1454
- MAT3: 9,
1455
- MAT4: 16,
1456
- };
1457
- const ATTRIBUTES = {
1458
- POSITION: "position",
1459
- NORMAL: "normal",
1460
- TANGENT: "tangent",
1461
- TEXCOORD_0: "uv",
1462
- TEXCOORD_1: "uv2",
1463
- COLOR_0: "color",
1464
- WEIGHTS_0: "skinWeight",
1465
- JOINTS_0: "skinIndex",
1466
- };
1467
- const PATH_PROPERTIES = {
1468
- scale: "scale",
1469
- translation: "position",
1470
- rotation: "quaternion",
1471
- weights: "morphTargetInfluences",
1472
- };
1473
- const INTERPOLATION = {
1474
- CUBICSPLINE: undefined,
1475
- // We use a custom interpolant (GLTFCubicSplineInterpolation) for CUBICSPLINE tracks. Each
1476
- // keyframe track will be initialized with a default interpolation type, then modified.
1477
- LINEAR: THREE.InterpolateLinear,
1478
- STEP: THREE.InterpolateDiscrete,
1479
- };
1480
- const ALPHA_MODES = {
1481
- OPAQUE: "OPAQUE",
1482
- MASK: "MASK",
1483
- BLEND: "BLEND",
1484
- };
1485
- /**
1486
- * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#default-material
1487
- */
1488
-
1489
- function createDefaultMaterial(cache) {
1490
- if (cache["DefaultMaterial"] === undefined) {
1491
- cache["DefaultMaterial"] = new THREE.MeshStandardMaterial({
1492
- color: 0xffffff,
1493
- emissive: 0x000000,
1494
- metalness: 1,
1495
- roughness: 1,
1496
- transparent: false,
1497
- depthTest: true,
1498
- side: THREE.FrontSide,
1499
- });
1500
- }
1501
-
1502
- return cache["DefaultMaterial"];
1503
- }
1504
-
1505
- function addUnknownExtensionsToUserData(knownExtensions, object, objectDef) {
1506
- // Add unknown glTF extensions to an object's userData.
1507
- for (const name in objectDef.extensions) {
1508
- if (knownExtensions[name] === undefined) {
1509
- object.userData.gltfExtensions = object.userData.gltfExtensions || {};
1510
- object.userData.gltfExtensions[name] = objectDef.extensions[name];
1511
- }
1512
- }
1513
- }
1514
- /**
1515
- * @param {Object3D|Material|BufferGeometry} object
1516
- * @param {GLTF.definition} gltfDef
1517
- */
1518
-
1519
- function assignExtrasToUserData(object, gltfDef) {
1520
- if (gltfDef.extras !== undefined) {
1521
- if (typeof gltfDef.extras === "object") {
1522
- Object.assign(object.userData, gltfDef.extras);
1523
- } else {
1524
- console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, " + gltfDef.extras);
1525
- }
1526
- }
1527
- }
1528
- /**
1529
- * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#morph-targets
1530
- *
1531
- * @param {BufferGeometry} geometry
1532
- * @param {Array<GLTF.Target>} targets
1533
- * @param {GLTFParser} parser
1534
- * @return {Promise<BufferGeometry>}
1535
- */
1536
-
1537
- function addMorphTargets(geometry, targets, parser) {
1538
- let hasMorphPosition = false;
1539
- let hasMorphNormal = false;
1540
-
1541
- for (let i = 0, il = targets.length; i < il; i++) {
1542
- const target = targets[i];
1543
- if (target.POSITION !== undefined) hasMorphPosition = true;
1544
- if (target.NORMAL !== undefined) hasMorphNormal = true;
1545
- if (hasMorphPosition && hasMorphNormal) break;
1546
- }
1547
-
1548
- if (!hasMorphPosition && !hasMorphNormal) return Promise.resolve(geometry);
1549
- const pendingPositionAccessors = [];
1550
- const pendingNormalAccessors = [];
1551
-
1552
- for (let i = 0, il = targets.length; i < il; i++) {
1553
- const target = targets[i];
1554
-
1555
- if (hasMorphPosition) {
1556
- const pendingAccessor =
1557
- target.POSITION !== undefined
1558
- ? parser.getDependency("accessor", target.POSITION)
1559
- : geometry.attributes.position;
1560
- pendingPositionAccessors.push(pendingAccessor);
1561
- }
1562
-
1563
- if (hasMorphNormal) {
1564
- const pendingAccessor =
1565
- target.NORMAL !== undefined
1566
- ? parser.getDependency("accessor", target.NORMAL)
1567
- : geometry.attributes.normal;
1568
- pendingNormalAccessors.push(pendingAccessor);
1569
- }
1570
- }
1571
-
1572
- return Promise.all([
1573
- Promise.all(pendingPositionAccessors),
1574
- Promise.all(pendingNormalAccessors),
1575
- ]).then(function (accessors) {
1576
- const morphPositions = accessors[0];
1577
- const morphNormals = accessors[1];
1578
- if (hasMorphPosition) geometry.morphAttributes.position = morphPositions;
1579
- if (hasMorphNormal) geometry.morphAttributes.normal = morphNormals;
1580
- geometry.morphTargetsRelative = true;
1581
- return geometry;
1582
- });
1583
- }
1584
- /**
1585
- * @param {Mesh} mesh
1586
- * @param {GLTF.Mesh} meshDef
1587
- */
1588
-
1589
- function updateMorphTargets(mesh, meshDef) {
1590
- mesh.updateMorphTargets();
1591
-
1592
- if (meshDef.weights !== undefined) {
1593
- for (let i = 0, il = meshDef.weights.length; i < il; i++) {
1594
- mesh.morphTargetInfluences[i] = meshDef.weights[i];
1595
- }
1596
- } // .extras has user-defined data, so check that .extras.targetNames is an array.
1597
-
1598
- if (meshDef.extras && Array.isArray(meshDef.extras.targetNames)) {
1599
- const targetNames = meshDef.extras.targetNames;
1600
-
1601
- if (mesh.morphTargetInfluences.length === targetNames.length) {
1602
- mesh.morphTargetDictionary = {};
1603
-
1604
- for (let i = 0, il = targetNames.length; i < il; i++) {
1605
- mesh.morphTargetDictionary[targetNames[i]] = i;
1606
- }
1607
- } else {
1608
- console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.");
1609
- }
1610
- }
1611
- }
1612
-
1613
- function createPrimitiveKey(primitiveDef) {
1614
- const dracoExtension =
1615
- primitiveDef.extensions && primitiveDef.extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION];
1616
- let geometryKey;
1617
-
1618
- if (dracoExtension) {
1619
- geometryKey =
1620
- "draco:" +
1621
- dracoExtension.bufferView +
1622
- ":" +
1623
- dracoExtension.indices +
1624
- ":" +
1625
- createAttributesKey(dracoExtension.attributes);
1626
- } else {
1627
- geometryKey =
1628
- primitiveDef.indices +
1629
- ":" +
1630
- createAttributesKey(primitiveDef.attributes) +
1631
- ":" +
1632
- primitiveDef.mode;
1633
- }
1634
-
1635
- return geometryKey;
1636
- }
1637
-
1638
- function createAttributesKey(attributes) {
1639
- let attributesKey = "";
1640
- const keys = Object.keys(attributes).sort();
1641
-
1642
- for (let i = 0, il = keys.length; i < il; i++) {
1643
- attributesKey += keys[i] + ":" + attributes[keys[i]] + ";";
1644
- }
1645
-
1646
- return attributesKey;
1647
- }
1648
-
1649
- function getNormalizedComponentScale(constructor) {
1650
- // Reference:
1651
- // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization#encoding-quantized-data
1652
- switch (constructor) {
1653
- case Int8Array:
1654
- return 1 / 127;
1655
-
1656
- case Uint8Array:
1657
- return 1 / 255;
1658
-
1659
- case Int16Array:
1660
- return 1 / 32767;
1661
-
1662
- case Uint16Array:
1663
- return 1 / 65535;
1664
-
1665
- default:
1666
- throw new Error("THREE.GLTFLoader: Unsupported normalized accessor component type.");
1667
- }
1668
- }
1669
- /* GLTF PARSER */
1670
-
1671
- class GLTFParser {
1672
- constructor(json = {}, options = {}) {
1673
- this.json = json;
1674
- this.extensions = {};
1675
- this.plugins = {};
1676
- this.options = options; // loader object cache
1677
-
1678
- this.cache = new GLTFRegistry(); // associations between Three.js objects and glTF elements
1679
-
1680
- this.associations = new Map(); // THREE.BufferGeometry caching
1681
-
1682
- this.primitiveCache = {}; // THREE.Object3D instance caches
1683
-
1684
- this.meshCache = {
1685
- refs: {},
1686
- uses: {},
1687
- };
1688
- this.cameraCache = {
1689
- refs: {},
1690
- uses: {},
1691
- };
1692
- this.lightCache = {
1693
- refs: {},
1694
- uses: {},
1695
- };
1696
- this.textureCache = {}; // Track node names, to ensure no duplicates
1697
-
1698
- this.nodeNamesUsed = {}; // Use an THREE.ImageBitmapLoader if imageBitmaps are supported. Moves much of the
1699
- // expensive work of uploading a texture to the GPU off the main thread.
1700
-
1701
- if (
1702
- typeof createImageBitmap !== "undefined" &&
1703
- /Firefox|^((?!chrome|android).)*safari/i.test(navigator.userAgent) === false
1704
- ) {
1705
- this.textureLoader = new THREE.ImageBitmapLoader(this.options.manager);
1706
- } else {
1707
- this.textureLoader = new THREE.TextureLoader(this.options.manager);
1708
- }
1709
-
1710
- this.textureLoader.setCrossOrigin(this.options.crossOrigin);
1711
- this.textureLoader.setRequestHeader(this.options.requestHeader);
1712
- this.fileLoader = new THREE.FileLoader(this.options.manager);
1713
- this.fileLoader.setResponseType("arraybuffer");
1714
-
1715
- if (this.options.crossOrigin === "use-credentials") {
1716
- this.fileLoader.setWithCredentials(true);
1717
- }
1718
- }
1719
-
1720
- setExtensions(extensions) {
1721
- this.extensions = extensions;
1722
- }
1723
-
1724
- setPlugins(plugins) {
1725
- this.plugins = plugins;
1726
- }
1727
-
1728
- parse(onLoad, onError) {
1729
- const parser = this;
1730
- const json = this.json;
1731
- const extensions = this.extensions; // Clear the loader cache
1732
-
1733
- this.cache.removeAll(); // Mark the special nodes/meshes in json for efficient parse
1734
-
1735
- this._invokeAll(function (ext) {
1736
- return ext._markDefs && ext._markDefs();
1737
- });
1738
-
1739
- Promise.all(
1740
- this._invokeAll(function (ext) {
1741
- return ext.beforeRoot && ext.beforeRoot();
1742
- })
1743
- )
1744
- .then(function () {
1745
- return Promise.all([
1746
- parser.getDependencies("scene"),
1747
- parser.getDependencies("animation"),
1748
- parser.getDependencies("camera"),
1749
- ]);
1750
- })
1751
- .then(function (dependencies) {
1752
- const result = {
1753
- scene: dependencies[0][json.scene || 0],
1754
- scenes: dependencies[0],
1755
- animations: dependencies[1],
1756
- cameras: dependencies[2],
1757
- asset: json.asset,
1758
- parser: parser,
1759
- userData: {},
1760
- };
1761
- addUnknownExtensionsToUserData(extensions, result, json);
1762
- assignExtrasToUserData(result, json);
1763
- Promise.all(
1764
- parser._invokeAll(function (ext) {
1765
- return ext.afterRoot && ext.afterRoot(result);
1766
- })
1767
- ).then(function () {
1768
- onLoad(result);
1769
- });
1770
- })
1771
- .catch(onError);
1772
- }
1773
- /**
1774
- * Marks the special nodes/meshes in json for efficient parse.
1775
- */
1776
-
1777
- _markDefs() {
1778
- const nodeDefs = this.json.nodes || [];
1779
- const skinDefs = this.json.skins || [];
1780
- const meshDefs = this.json.meshes || []; // Nothing in the node definition indicates whether it is a THREE.Bone or an
1781
- // THREE.Object3D. Use the skins' joint references to mark bones.
1782
-
1783
- for (let skinIndex = 0, skinLength = skinDefs.length; skinIndex < skinLength; skinIndex++) {
1784
- const joints = skinDefs[skinIndex].joints;
1785
-
1786
- for (let i = 0, il = joints.length; i < il; i++) {
1787
- nodeDefs[joints[i]].isBone = true;
1788
- }
1789
- } // Iterate over all nodes, marking references to shared resources,
1790
- // as well as skeleton joints.
1791
-
1792
- for (let nodeIndex = 0, nodeLength = nodeDefs.length; nodeIndex < nodeLength; nodeIndex++) {
1793
- const nodeDef = nodeDefs[nodeIndex];
1794
-
1795
- if (nodeDef.mesh !== undefined) {
1796
- this._addNodeRef(this.meshCache, nodeDef.mesh); // Nothing in the mesh definition indicates whether it is
1797
- // a THREE.SkinnedMesh or THREE.Mesh. Use the node's mesh reference
1798
- // to mark THREE.SkinnedMesh if node has skin.
1799
-
1800
- if (nodeDef.skin !== undefined) {
1801
- meshDefs[nodeDef.mesh].isSkinnedMesh = true;
1802
- }
1803
- }
1804
-
1805
- if (nodeDef.camera !== undefined) {
1806
- this._addNodeRef(this.cameraCache, nodeDef.camera);
1807
- }
1808
- }
1809
- }
1810
- /**
1811
- * Counts references to shared node / THREE.Object3D resources. These resources
1812
- * can be reused, or "instantiated", at multiple nodes in the scene
1813
- * hierarchy. THREE.Mesh, Camera, and Light instances are instantiated and must
1814
- * be marked. Non-scenegraph resources (like Materials, Geometries, and
1815
- * Textures) can be reused directly and are not marked here.
1816
- *
1817
- * Example: CesiumMilkTruck sample model reuses "Wheel" meshes.
1818
- */
1819
-
1820
- _addNodeRef(cache, index) {
1821
- if (index === undefined) return;
1822
-
1823
- if (cache.refs[index] === undefined) {
1824
- cache.refs[index] = cache.uses[index] = 0;
1825
- }
1826
-
1827
- cache.refs[index]++;
1828
- }
1829
- /** Returns a reference to a shared resource, cloning it if necessary. */
1830
-
1831
- _getNodeRef(cache, index, object) {
1832
- if (cache.refs[index] <= 1) return object;
1833
- const ref = object.clone(); // Propagates mappings to the cloned object, prevents mappings on the
1834
- // original object from being lost.
1835
-
1836
- const updateMappings = (original, clone) => {
1837
- const mappings = this.associations.get(original);
1838
-
1839
- if (mappings != null) {
1840
- this.associations.set(clone, mappings);
1841
- }
1842
-
1843
- for (const [i, child] of original.children.entries()) {
1844
- updateMappings(child, clone.children[i]);
1845
- }
1846
- };
1847
-
1848
- updateMappings(object, ref);
1849
- ref.name += "_instance_" + cache.uses[index]++;
1850
- return ref;
1851
- }
1852
-
1853
- _invokeOne(func) {
1854
- const extensions = Object.values(this.plugins);
1855
- extensions.push(this);
1856
-
1857
- for (let i = 0; i < extensions.length; i++) {
1858
- const result = func(extensions[i]);
1859
- if (result) return result;
1860
- }
1861
-
1862
- return null;
1863
- }
1864
-
1865
- _invokeAll(func) {
1866
- const extensions = Object.values(this.plugins);
1867
- extensions.unshift(this);
1868
- const pending = [];
1869
-
1870
- for (let i = 0; i < extensions.length; i++) {
1871
- const result = func(extensions[i]);
1872
- if (result) pending.push(result);
1873
- }
1874
-
1875
- return pending;
1876
- }
1877
- /**
1878
- * Requests the specified dependency asynchronously, with caching.
1879
- * @param {string} type
1880
- * @param {number} index
1881
- * @return {Promise<Object3D|Material|THREE.Texture|AnimationClip|ArrayBuffer|Object>}
1882
- */
1883
-
1884
- getDependency(type, index) {
1885
- const cacheKey = type + ":" + index;
1886
- let dependency = this.cache.get(cacheKey);
1887
-
1888
- if (!dependency) {
1889
- switch (type) {
1890
- case "scene":
1891
- dependency = this.loadScene(index);
1892
- break;
1893
-
1894
- case "node":
1895
- dependency = this.loadNode(index);
1896
- break;
1897
-
1898
- case "mesh":
1899
- dependency = this._invokeOne(function (ext) {
1900
- return ext.loadMesh && ext.loadMesh(index);
1901
- });
1902
- break;
1903
-
1904
- case "accessor":
1905
- dependency = this.loadAccessor(index);
1906
- break;
1907
-
1908
- case "bufferView":
1909
- dependency = this._invokeOne(function (ext) {
1910
- return ext.loadBufferView && ext.loadBufferView(index);
1911
- });
1912
- break;
1913
-
1914
- case "buffer":
1915
- dependency = this.loadBuffer(index);
1916
- break;
1917
-
1918
- case "material":
1919
- dependency = this._invokeOne(function (ext) {
1920
- return ext.loadMaterial && ext.loadMaterial(index);
1921
- });
1922
- break;
1923
-
1924
- case "texture":
1925
- dependency = this._invokeOne(function (ext) {
1926
- return ext.loadTexture && ext.loadTexture(index);
1927
- });
1928
- break;
1929
-
1930
- case "skin":
1931
- dependency = this.loadSkin(index);
1932
- break;
1933
-
1934
- case "animation":
1935
- dependency = this.loadAnimation(index);
1936
- break;
1937
-
1938
- case "camera":
1939
- dependency = this.loadCamera(index);
1940
- break;
1941
-
1942
- default:
1943
- throw new Error("Unknown type: " + type);
1944
- }
1945
-
1946
- this.cache.add(cacheKey, dependency);
1947
- }
1948
-
1949
- return dependency;
1950
- }
1951
- /**
1952
- * Requests all dependencies of the specified type asynchronously, with caching.
1953
- * @param {string} type
1954
- * @return {Promise<Array<Object>>}
1955
- */
1956
-
1957
- getDependencies(type) {
1958
- let dependencies = this.cache.get(type);
1959
-
1960
- if (!dependencies) {
1961
- const parser = this;
1962
- const defs = this.json[type + (type === "mesh" ? "es" : "s")] || [];
1963
- dependencies = Promise.all(
1964
- defs.map(function (def, index) {
1965
- return parser.getDependency(type, index);
1966
- })
1967
- );
1968
- this.cache.add(type, dependencies);
1969
- }
1970
-
1971
- return dependencies;
1972
- }
1973
- /**
1974
- * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
1975
- * @param {number} bufferIndex
1976
- * @return {Promise<ArrayBuffer>}
1977
- */
1978
-
1979
- loadBuffer(bufferIndex) {
1980
- const bufferDef = this.json.buffers[bufferIndex];
1981
- const loader = this.fileLoader;
1982
-
1983
- if (bufferDef.type && bufferDef.type !== "arraybuffer") {
1984
- throw new Error("THREE.GLTFLoader: " + bufferDef.type + " buffer type is not supported.");
1985
- } // If present, GLB container is required to be the first buffer.
1986
-
1987
- if (bufferDef.uri === undefined && bufferIndex === 0) {
1988
- return Promise.resolve(this.extensions[EXTENSIONS.KHR_BINARY_GLTF].body);
1989
- }
1990
-
1991
- const options = this.options;
1992
- return new Promise(function (resolve, reject) {
1993
- loader.load(
1994
- THREE.LoaderUtils.resolveURL(bufferDef.uri, options.path),
1995
- resolve,
1996
- undefined,
1997
- function () {
1998
- reject(new Error('THREE.GLTFLoader: Failed to load buffer "' + bufferDef.uri + '".'));
1999
- }
2000
- );
2001
- });
2002
- }
2003
- /**
2004
- * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
2005
- * @param {number} bufferViewIndex
2006
- * @return {Promise<ArrayBuffer>}
2007
- */
2008
-
2009
- loadBufferView(bufferViewIndex) {
2010
- const bufferViewDef = this.json.bufferViews[bufferViewIndex];
2011
- return this.getDependency("buffer", bufferViewDef.buffer).then(function (buffer) {
2012
- const byteLength = bufferViewDef.byteLength || 0;
2013
- const byteOffset = bufferViewDef.byteOffset || 0;
2014
- return buffer.slice(byteOffset, byteOffset + byteLength);
2015
- });
2016
- }
2017
- /**
2018
- * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#accessors
2019
- * @param {number} accessorIndex
2020
- * @return {Promise<BufferAttribute|InterleavedBufferAttribute>}
2021
- */
2022
-
2023
- loadAccessor(accessorIndex) {
2024
- const parser = this;
2025
- const json = this.json;
2026
- const accessorDef = this.json.accessors[accessorIndex];
2027
-
2028
- if (accessorDef.bufferView === undefined && accessorDef.sparse === undefined) {
2029
- // Ignore empty accessors, which may be used to declare runtime
2030
- // information about attributes coming from another source (e.g. Draco
2031
- // compression extension).
2032
- return Promise.resolve(null);
2033
- }
2034
-
2035
- const pendingBufferViews = [];
2036
-
2037
- if (accessorDef.bufferView !== undefined) {
2038
- pendingBufferViews.push(this.getDependency("bufferView", accessorDef.bufferView));
2039
- } else {
2040
- pendingBufferViews.push(null);
2041
- }
2042
-
2043
- if (accessorDef.sparse !== undefined) {
2044
- pendingBufferViews.push(
2045
- this.getDependency("bufferView", accessorDef.sparse.indices.bufferView)
2046
- );
2047
- pendingBufferViews.push(
2048
- this.getDependency("bufferView", accessorDef.sparse.values.bufferView)
2049
- );
2050
- }
2051
-
2052
- return Promise.all(pendingBufferViews).then(function (bufferViews) {
2053
- const bufferView = bufferViews[0];
2054
- const itemSize = WEBGL_TYPE_SIZES[accessorDef.type];
2055
- const TypedArray = WEBGL_COMPONENT_TYPES[accessorDef.componentType]; // For VEC3: itemSize is 3, elementBytes is 4, itemBytes is 12.
2056
-
2057
- const elementBytes = TypedArray.BYTES_PER_ELEMENT;
2058
- const itemBytes = elementBytes * itemSize;
2059
- const byteOffset = accessorDef.byteOffset || 0;
2060
- const byteStride =
2061
- accessorDef.bufferView !== undefined
2062
- ? json.bufferViews[accessorDef.bufferView].byteStride
2063
- : undefined;
2064
- const normalized = accessorDef.normalized === true;
2065
- let array, bufferAttribute; // The buffer is not interleaved if the stride is the item size in bytes.
2066
-
2067
- if (byteStride && byteStride !== itemBytes) {
2068
- // Each "slice" of the buffer, as defined by 'count' elements of 'byteStride' bytes, gets its own THREE.InterleavedBuffer
2069
- // This makes sure that IBA.count reflects accessor.count properly
2070
- const ibSlice = Math.floor(byteOffset / byteStride);
2071
- const ibCacheKey =
2072
- "InterleavedBuffer:" +
2073
- accessorDef.bufferView +
2074
- ":" +
2075
- accessorDef.componentType +
2076
- ":" +
2077
- ibSlice +
2078
- ":" +
2079
- accessorDef.count;
2080
- let ib = parser.cache.get(ibCacheKey);
2081
-
2082
- if (!ib) {
2083
- array = new TypedArray(
2084
- bufferView,
2085
- ibSlice * byteStride,
2086
- (accessorDef.count * byteStride) / elementBytes
2087
- ); // Integer parameters to IB/IBA are in array elements, not bytes.
2088
-
2089
- ib = new THREE.InterleavedBuffer(array, byteStride / elementBytes);
2090
- parser.cache.add(ibCacheKey, ib);
2091
- }
2092
-
2093
- bufferAttribute = new THREE.InterleavedBufferAttribute(
2094
- ib,
2095
- itemSize,
2096
- (byteOffset % byteStride) / elementBytes,
2097
- normalized
2098
- );
2099
- } else {
2100
- if (bufferView === null) {
2101
- array = new TypedArray(accessorDef.count * itemSize);
2102
- } else {
2103
- array = new TypedArray(bufferView, byteOffset, accessorDef.count * itemSize);
2104
- }
2105
-
2106
- bufferAttribute = new THREE.BufferAttribute(array, itemSize, normalized);
2107
- } // https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#sparse-accessors
2108
-
2109
- if (accessorDef.sparse !== undefined) {
2110
- const itemSizeIndices = WEBGL_TYPE_SIZES.SCALAR;
2111
- const TypedArrayIndices = WEBGL_COMPONENT_TYPES[accessorDef.sparse.indices.componentType];
2112
- const byteOffsetIndices = accessorDef.sparse.indices.byteOffset || 0;
2113
- const byteOffsetValues = accessorDef.sparse.values.byteOffset || 0;
2114
- const sparseIndices = new TypedArrayIndices(
2115
- bufferViews[1],
2116
- byteOffsetIndices,
2117
- accessorDef.sparse.count * itemSizeIndices
2118
- );
2119
- const sparseValues = new TypedArray(
2120
- bufferViews[2],
2121
- byteOffsetValues,
2122
- accessorDef.sparse.count * itemSize
2123
- );
2124
-
2125
- if (bufferView !== null) {
2126
- // Avoid modifying the original ArrayBuffer, if the bufferView wasn't initialized with zeroes.
2127
- bufferAttribute = new THREE.BufferAttribute(
2128
- bufferAttribute.array.slice(),
2129
- bufferAttribute.itemSize,
2130
- bufferAttribute.normalized
2131
- );
2132
- }
2133
-
2134
- for (let i = 0, il = sparseIndices.length; i < il; i++) {
2135
- const index = sparseIndices[i];
2136
- bufferAttribute.setX(index, sparseValues[i * itemSize]);
2137
- if (itemSize >= 2) bufferAttribute.setY(index, sparseValues[i * itemSize + 1]);
2138
- if (itemSize >= 3) bufferAttribute.setZ(index, sparseValues[i * itemSize + 2]);
2139
- if (itemSize >= 4) bufferAttribute.setW(index, sparseValues[i * itemSize + 3]);
2140
- if (itemSize >= 5)
2141
- throw new Error(
2142
- "THREE.GLTFLoader: Unsupported itemSize in sparse THREE.BufferAttribute."
2143
- );
2144
- }
2145
- }
2146
-
2147
- return bufferAttribute;
2148
- });
2149
- }
2150
- /**
2151
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#textures
2152
- * @param {number} textureIndex
2153
- * @return {Promise<THREE.Texture>}
2154
- */
2155
-
2156
- loadTexture(textureIndex) {
2157
- const json = this.json;
2158
- const options = this.options;
2159
- const textureDef = json.textures[textureIndex];
2160
- const source = json.images[textureDef.source];
2161
- let loader = this.textureLoader;
2162
-
2163
- if (source.uri) {
2164
- const handler = options.manager.getHandler(source.uri);
2165
- if (handler !== null) loader = handler;
2166
- }
2167
-
2168
- return this.loadTextureImage(textureIndex, source, loader);
2169
- }
2170
-
2171
- loadTextureImage(textureIndex, source, loader) {
2172
- const parser = this;
2173
- const json = this.json;
2174
- const options = this.options;
2175
- const textureDef = json.textures[textureIndex];
2176
- const cacheKey = (source.uri || source.bufferView) + ":" + textureDef.sampler;
2177
-
2178
- if (this.textureCache[cacheKey]) {
2179
- // See https://github.com/mrdoob/three.js/issues/21559.
2180
- return this.textureCache[cacheKey];
2181
- }
2182
-
2183
- const URL = this.URL || this.webkitURL;
2184
- let sourceURI = source.uri || "";
2185
- let isObjectURL = false;
2186
-
2187
- if (source.bufferView !== undefined) {
2188
- // Load binary image data from bufferView, if provided.
2189
- sourceURI = parser
2190
- .getDependency("bufferView", source.bufferView)
2191
- .then(function (bufferView) {
2192
- isObjectURL = true;
2193
- const blob = new Blob([bufferView], {
2194
- type: source.mimeType,
2195
- });
2196
- sourceURI = URL.createObjectURL(blob);
2197
- return sourceURI;
2198
- });
2199
- } else if (source.uri === undefined) {
2200
- throw new Error(
2201
- "THREE.GLTFLoader: Image " + textureIndex + " is missing URI and bufferView"
2202
- );
2203
- }
2204
-
2205
- const promise = Promise.resolve(sourceURI)
2206
- .then(function (sourceURI) {
2207
- return new Promise(function (resolve, reject) {
2208
- let onLoad = resolve;
2209
-
2210
- if (loader.isImageBitmapLoader === true) {
2211
- onLoad = function (imageBitmap) {
2212
- const texture = new THREE.Texture(imageBitmap);
2213
- texture.needsUpdate = true;
2214
- resolve(texture);
2215
- };
2216
- }
2217
-
2218
- loader.load(
2219
- THREE.LoaderUtils.resolveURL(sourceURI, options.path),
2220
- onLoad,
2221
- undefined,
2222
- reject
2223
- );
2224
- });
2225
- })
2226
- .then(function (texture) {
2227
- // Clean up resources and configure THREE.Texture.
2228
- if (isObjectURL === true) {
2229
- URL.revokeObjectURL(sourceURI);
2230
- }
2231
-
2232
- texture.flipY = false;
2233
- if (textureDef.name) texture.name = textureDef.name;
2234
- const samplers = json.samplers || {};
2235
- const sampler = samplers[textureDef.sampler] || {};
2236
- texture.magFilter = WEBGL_FILTERS[sampler.magFilter] || THREE.LinearFilter;
2237
- texture.minFilter = WEBGL_FILTERS[sampler.minFilter] || THREE.LinearMipmapLinearFilter;
2238
- texture.wrapS = WEBGL_WRAPPINGS[sampler.wrapS] || THREE.RepeatWrapping;
2239
- texture.wrapT = WEBGL_WRAPPINGS[sampler.wrapT] || THREE.RepeatWrapping;
2240
- parser.associations.set(texture, {
2241
- textures: textureIndex,
2242
- });
2243
- return texture;
2244
- })
2245
- .catch(function () {
2246
- console.error("THREE.GLTFLoader: Couldn't load texture", sourceURI);
2247
- return null;
2248
- });
2249
- this.textureCache[cacheKey] = promise;
2250
- return promise;
2251
- }
2252
- /**
2253
- * Asynchronously assigns a texture to the given material parameters.
2254
- * @param {Object} materialParams
2255
- * @param {string} mapName
2256
- * @param {Object} mapDef
2257
- * @return {Promise<Texture>}
2258
- */
2259
-
2260
- assignTexture(materialParams, mapName, mapDef) {
2261
- const parser = this;
2262
- return this.getDependency("texture", mapDef.index).then(function (texture) {
2263
- // Materials sample aoMap from UV set 1 and other maps from UV set 0 - this can't be configured
2264
- // However, we will copy UV set 0 to UV set 1 on demand for aoMap
2265
- if (
2266
- mapDef.texCoord !== undefined &&
2267
- mapDef.texCoord != 0 &&
2268
- !(mapName === "aoMap" && mapDef.texCoord == 1)
2269
- ) {
2270
- console.warn(
2271
- "THREE.GLTFLoader: Custom UV set " +
2272
- mapDef.texCoord +
2273
- " for texture " +
2274
- mapName +
2275
- " not yet supported."
2276
- );
2277
- }
2278
-
2279
- if (parser.extensions[EXTENSIONS.KHR_TEXTURE_TRANSFORM]) {
2280
- const transform =
2281
- mapDef.extensions !== undefined
2282
- ? mapDef.extensions[EXTENSIONS.KHR_TEXTURE_TRANSFORM]
2283
- : undefined;
2284
-
2285
- if (transform) {
2286
- const gltfReference = parser.associations.get(texture);
2287
- texture = parser.extensions[EXTENSIONS.KHR_TEXTURE_TRANSFORM].extendTexture(
2288
- texture,
2289
- transform
2290
- );
2291
- parser.associations.set(texture, gltfReference);
2292
- }
2293
- }
2294
-
2295
- materialParams[mapName] = texture;
2296
- return texture;
2297
- });
2298
- }
2299
- /**
2300
- * Assigns final material to a THREE.Mesh, THREE.Line, or THREE.Points instance. The instance
2301
- * already has a material (generated from the glTF material options alone)
2302
- * but reuse of the same glTF material may require multiple threejs materials
2303
- * to accommodate different primitive types, defines, etc. New materials will
2304
- * be created if necessary, and reused from a cache.
2305
- * @param {Object3D} mesh THREE.Mesh, THREE.Line, or THREE.Points instance.
2306
- */
2307
-
2308
- assignFinalMaterial(mesh) {
2309
- const geometry = mesh.geometry;
2310
- let material = mesh.material;
2311
- const useDerivativeTangents = geometry.attributes.tangent === undefined;
2312
- const useVertexColors = geometry.attributes.color !== undefined;
2313
- const useFlatShading = geometry.attributes.normal === undefined;
2314
-
2315
- if (mesh.isPoints) {
2316
- const cacheKey = "PointsMaterial:" + material.uuid;
2317
- let pointsMaterial = this.cache.get(cacheKey);
2318
-
2319
- if (!pointsMaterial) {
2320
- pointsMaterial = new THREE.PointsMaterial();
2321
- THREE.Material.prototype.copy.call(pointsMaterial, material);
2322
- pointsMaterial.color.copy(material.color);
2323
- pointsMaterial.map = material.map;
2324
- pointsMaterial.sizeAttenuation = false; // glTF spec says points should be 1px
2325
-
2326
- this.cache.add(cacheKey, pointsMaterial);
2327
- }
2328
-
2329
- material = pointsMaterial;
2330
- } else if (mesh.isLine) {
2331
- const cacheKey = "LineBasicMaterial:" + material.uuid;
2332
- let lineMaterial = this.cache.get(cacheKey);
2333
-
2334
- if (!lineMaterial) {
2335
- lineMaterial = new THREE.LineBasicMaterial();
2336
- THREE.Material.prototype.copy.call(lineMaterial, material);
2337
- lineMaterial.color.copy(material.color);
2338
- this.cache.add(cacheKey, lineMaterial);
2339
- }
2340
-
2341
- material = lineMaterial;
2342
- } // Clone the material if it will be modified
2343
-
2344
- if (useDerivativeTangents || useVertexColors || useFlatShading) {
2345
- let cacheKey = "ClonedMaterial:" + material.uuid + ":";
2346
- if (material.isGLTFSpecularGlossinessMaterial) cacheKey += "specular-glossiness:";
2347
- if (useDerivativeTangents) cacheKey += "derivative-tangents:";
2348
- if (useVertexColors) cacheKey += "vertex-colors:";
2349
- if (useFlatShading) cacheKey += "flat-shading:";
2350
- let cachedMaterial = this.cache.get(cacheKey);
2351
-
2352
- if (!cachedMaterial) {
2353
- cachedMaterial = material.clone();
2354
- if (useVertexColors) cachedMaterial.vertexColors = true;
2355
- if (useFlatShading) cachedMaterial.flatShading = true;
2356
-
2357
- if (useDerivativeTangents) {
2358
- // https://github.com/mrdoob/three.js/issues/11438#issuecomment-507003995
2359
- if (cachedMaterial.normalScale) cachedMaterial.normalScale.y *= -1;
2360
- if (cachedMaterial.clearcoatNormalScale) cachedMaterial.clearcoatNormalScale.y *= -1;
2361
- }
2362
-
2363
- this.cache.add(cacheKey, cachedMaterial);
2364
- this.associations.set(cachedMaterial, this.associations.get(material));
2365
- }
2366
-
2367
- material = cachedMaterial;
2368
- } // workarounds for mesh and geometry
2369
-
2370
- if (
2371
- material.aoMap &&
2372
- geometry.attributes.uv2 === undefined &&
2373
- geometry.attributes.uv !== undefined
2374
- ) {
2375
- geometry.setAttribute("uv2", geometry.attributes.uv);
2376
- }
2377
-
2378
- mesh.material = material;
2379
- }
2380
-
2381
- getMaterialType() {
2382
- return THREE.MeshStandardMaterial;
2383
- }
2384
- /**
2385
- * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#materials
2386
- * @param {number} materialIndex
2387
- * @return {Promise<Material>}
2388
- */
2389
-
2390
- loadMaterial(materialIndex) {
2391
- const parser = this;
2392
- const json = this.json;
2393
- const extensions = this.extensions;
2394
- const materialDef = json.materials[materialIndex];
2395
- let materialType;
2396
- const materialParams = {};
2397
- const materialExtensions = materialDef.extensions || {};
2398
- const pending = [];
2399
-
2400
- if (materialExtensions[EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS]) {
2401
- const sgExtension = extensions[EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS];
2402
- materialType = sgExtension.getMaterialType();
2403
- pending.push(sgExtension.extendParams(materialParams, materialDef, parser));
2404
- } else if (materialExtensions[EXTENSIONS.KHR_MATERIALS_UNLIT]) {
2405
- const kmuExtension = extensions[EXTENSIONS.KHR_MATERIALS_UNLIT];
2406
- materialType = kmuExtension.getMaterialType();
2407
- pending.push(kmuExtension.extendParams(materialParams, materialDef, parser));
2408
- } else {
2409
- // Specification:
2410
- // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#metallic-roughness-material
2411
- const metallicRoughness = materialDef.pbrMetallicRoughness || {};
2412
- materialParams.color = new THREE.Color(1.0, 1.0, 1.0);
2413
- materialParams.opacity = 1.0;
2414
-
2415
- if (Array.isArray(metallicRoughness.baseColorFactor)) {
2416
- const array = metallicRoughness.baseColorFactor;
2417
- materialParams.color.fromArray(array);
2418
- materialParams.opacity = array[3];
2419
- }
2420
-
2421
- if (metallicRoughness.baseColorTexture !== undefined) {
2422
- pending.push(
2423
- parser.assignTexture(materialParams, "map", metallicRoughness.baseColorTexture)
2424
- );
2425
- }
2426
-
2427
- materialParams.metalness =
2428
- metallicRoughness.metallicFactor !== undefined ? metallicRoughness.metallicFactor : 1.0;
2429
- materialParams.roughness =
2430
- metallicRoughness.roughnessFactor !== undefined ? metallicRoughness.roughnessFactor : 1.0;
2431
-
2432
- if (metallicRoughness.metallicRoughnessTexture !== undefined) {
2433
- pending.push(
2434
- parser.assignTexture(
2435
- materialParams,
2436
- "metalnessMap",
2437
- metallicRoughness.metallicRoughnessTexture
2438
- )
2439
- );
2440
- pending.push(
2441
- parser.assignTexture(
2442
- materialParams,
2443
- "roughnessMap",
2444
- metallicRoughness.metallicRoughnessTexture
2445
- )
2446
- );
2447
- }
2448
-
2449
- materialType = this._invokeOne(function (ext) {
2450
- return ext.getMaterialType && ext.getMaterialType(materialIndex);
2451
- });
2452
- pending.push(
2453
- Promise.all(
2454
- this._invokeAll(function (ext) {
2455
- return (
2456
- ext.extendMaterialParams && ext.extendMaterialParams(materialIndex, materialParams)
2457
- );
2458
- })
2459
- )
2460
- );
2461
- }
2462
-
2463
- if (materialDef.doubleSided === true) {
2464
- materialParams.side = THREE.DoubleSide;
2465
- }
2466
-
2467
- const alphaMode = materialDef.alphaMode || ALPHA_MODES.OPAQUE;
2468
-
2469
- if (alphaMode === ALPHA_MODES.BLEND) {
2470
- materialParams.transparent = true; // See: https://github.com/mrdoob/three.js/issues/17706
2471
-
2472
- materialParams.depthWrite = false;
2473
- } else {
2474
- materialParams.transparent = false;
2475
-
2476
- if (alphaMode === ALPHA_MODES.MASK) {
2477
- materialParams.alphaTest =
2478
- materialDef.alphaCutoff !== undefined ? materialDef.alphaCutoff : 0.5;
2479
- }
2480
- }
2481
-
2482
- if (materialDef.normalTexture !== undefined && materialType !== THREE.MeshBasicMaterial) {
2483
- pending.push(parser.assignTexture(materialParams, "normalMap", materialDef.normalTexture));
2484
- materialParams.normalScale = new THREE.Vector2(1, 1);
2485
-
2486
- if (materialDef.normalTexture.scale !== undefined) {
2487
- const scale = materialDef.normalTexture.scale;
2488
- materialParams.normalScale.set(scale, scale);
2489
- }
2490
- }
2491
-
2492
- if (materialDef.occlusionTexture !== undefined && materialType !== THREE.MeshBasicMaterial) {
2493
- pending.push(parser.assignTexture(materialParams, "aoMap", materialDef.occlusionTexture));
2494
-
2495
- if (materialDef.occlusionTexture.strength !== undefined) {
2496
- materialParams.aoMapIntensity = materialDef.occlusionTexture.strength;
2497
- }
2498
- }
2499
-
2500
- if (materialDef.emissiveFactor !== undefined && materialType !== THREE.MeshBasicMaterial) {
2501
- materialParams.emissive = new THREE.Color().fromArray(materialDef.emissiveFactor);
2502
- }
2503
-
2504
- if (materialDef.emissiveTexture !== undefined && materialType !== THREE.MeshBasicMaterial) {
2505
- pending.push(
2506
- parser.assignTexture(materialParams, "emissiveMap", materialDef.emissiveTexture)
2507
- );
2508
- }
2509
-
2510
- return Promise.all(pending).then(function () {
2511
- let material;
2512
-
2513
- if (materialType === GLTFMeshStandardSGMaterial) {
2514
- material =
2515
- extensions[EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS].createMaterial(
2516
- materialParams
2517
- );
2518
- } else {
2519
- material = new materialType(materialParams);
2520
- }
2521
-
2522
- if (materialDef.name) material.name = materialDef.name; // baseColorTexture, emissiveTexture, and specularGlossinessTexture use sRGB encoding.
2523
-
2524
- if (material.map) material.map.encoding = THREE.sRGBEncoding;
2525
- if (material.emissiveMap) material.emissiveMap.encoding = THREE.sRGBEncoding;
2526
- assignExtrasToUserData(material, materialDef);
2527
- parser.associations.set(material, {
2528
- materials: materialIndex,
2529
- });
2530
- if (materialDef.extensions)
2531
- addUnknownExtensionsToUserData(extensions, material, materialDef);
2532
- return material;
2533
- });
2534
- }
2535
- /** When THREE.Object3D instances are targeted by animation, they need unique names. */
2536
-
2537
- createUniqueName(originalName) {
2538
- const sanitizedName = THREE.PropertyBinding.sanitizeNodeName(originalName || "");
2539
- let name = sanitizedName;
2540
-
2541
- for (let i = 1; this.nodeNamesUsed[name]; ++i) {
2542
- name = sanitizedName + "_" + i;
2543
- }
2544
-
2545
- this.nodeNamesUsed[name] = true;
2546
- return name;
2547
- }
2548
- /**
2549
- * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#geometry
2550
- *
2551
- * Creates BufferGeometries from primitives.
2552
- *
2553
- * @param {Array<GLTF.Primitive>} primitives
2554
- * @return {Promise<Array<BufferGeometry>>}
2555
- */
2556
-
2557
- loadGeometries(primitives) {
2558
- const parser = this;
2559
- const extensions = this.extensions;
2560
- const cache = this.primitiveCache;
2561
-
2562
- function createDracoPrimitive(primitive) {
2563
- return extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION]
2564
- .decodePrimitive(primitive, parser)
2565
- .then(function (geometry) {
2566
- return addPrimitiveAttributes(geometry, primitive, parser);
2567
- });
2568
- }
2569
-
2570
- const pending = [];
2571
-
2572
- for (let i = 0, il = primitives.length; i < il; i++) {
2573
- const primitive = primitives[i];
2574
- const cacheKey = createPrimitiveKey(primitive); // See if we've already created this geometry
2575
-
2576
- const cached = cache[cacheKey];
2577
-
2578
- if (cached) {
2579
- // Use the cached geometry if it exists
2580
- pending.push(cached.promise);
2581
- } else {
2582
- let geometryPromise;
2583
-
2584
- if (primitive.extensions && primitive.extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION]) {
2585
- // Use DRACO geometry if available
2586
- geometryPromise = createDracoPrimitive(primitive);
2587
- } else {
2588
- // Otherwise create a new geometry
2589
- geometryPromise = addPrimitiveAttributes(new THREE.BufferGeometry(), primitive, parser);
2590
- } // Cache this geometry
2591
-
2592
- cache[cacheKey] = {
2593
- primitive: primitive,
2594
- promise: geometryPromise,
2595
- };
2596
- pending.push(geometryPromise);
2597
- }
2598
- }
2599
-
2600
- return Promise.all(pending);
2601
- }
2602
- /**
2603
- * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#meshes
2604
- * @param {number} meshIndex
2605
- * @return {Promise<Group|Mesh|SkinnedMesh>}
2606
- */
2607
-
2608
- loadMesh(meshIndex) {
2609
- const parser = this;
2610
- const json = this.json;
2611
- const extensions = this.extensions;
2612
- const meshDef = json.meshes[meshIndex];
2613
- const primitives = meshDef.primitives;
2614
- const pending = [];
2615
-
2616
- for (let i = 0, il = primitives.length; i < il; i++) {
2617
- const material =
2618
- primitives[i].material === undefined
2619
- ? createDefaultMaterial(this.cache)
2620
- : this.getDependency("material", primitives[i].material);
2621
- pending.push(material);
2622
- }
2623
-
2624
- pending.push(parser.loadGeometries(primitives));
2625
- return Promise.all(pending).then(function (results) {
2626
- const materials = results.slice(0, results.length - 1);
2627
- const geometries = results[results.length - 1];
2628
- const meshes = [];
2629
-
2630
- for (let i = 0, il = geometries.length; i < il; i++) {
2631
- const geometry = geometries[i];
2632
- const primitive = primitives[i]; // 1. create THREE.Mesh
2633
-
2634
- let mesh;
2635
- const material = materials[i];
2636
-
2637
- if (
2638
- primitive.mode === WEBGL_CONSTANTS.TRIANGLES ||
2639
- primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP ||
2640
- primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN ||
2641
- primitive.mode === undefined
2642
- ) {
2643
- // .isSkinnedMesh isn't in glTF spec. See ._markDefs()
2644
- mesh =
2645
- meshDef.isSkinnedMesh === true
2646
- ? new THREE.SkinnedMesh(geometry, material)
2647
- : new THREE.Mesh(geometry, material);
2648
-
2649
- if (mesh.isSkinnedMesh === true && !mesh.geometry.attributes.skinWeight.normalized) {
2650
- // we normalize floating point skin weight array to fix malformed assets (see #15319)
2651
- // it's important to skip this for non-float32 data since normalizeSkinWeights assumes non-normalized inputs
2652
- mesh.normalizeSkinWeights();
2653
- }
2654
-
2655
- if (primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP) {
2656
- mesh.geometry = toTrianglesDrawMode(mesh.geometry, THREE.TriangleStripDrawMode);
2657
- } else if (primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN) {
2658
- mesh.geometry = toTrianglesDrawMode(mesh.geometry, THREE.TriangleFanDrawMode);
2659
- }
2660
- } else if (primitive.mode === WEBGL_CONSTANTS.LINES) {
2661
- mesh = new THREE.LineSegments(geometry, material);
2662
- } else if (primitive.mode === WEBGL_CONSTANTS.LINE_STRIP) {
2663
- mesh = new THREE.Line(geometry, material);
2664
- } else if (primitive.mode === WEBGL_CONSTANTS.LINE_LOOP) {
2665
- mesh = new THREE.LineLoop(geometry, material);
2666
- } else if (primitive.mode === WEBGL_CONSTANTS.POINTS) {
2667
- mesh = new THREE.Points(geometry, material);
2668
- } else {
2669
- throw new Error("THREE.GLTFLoader: Primitive mode unsupported: " + primitive.mode);
2670
- }
2671
-
2672
- if (Object.keys(mesh.geometry.morphAttributes).length > 0) {
2673
- updateMorphTargets(mesh, meshDef);
2674
- }
2675
-
2676
- mesh.name = parser.createUniqueName(meshDef.name || "mesh_" + meshIndex);
2677
- assignExtrasToUserData(mesh, meshDef);
2678
- if (primitive.extensions) addUnknownExtensionsToUserData(extensions, mesh, primitive);
2679
- parser.assignFinalMaterial(mesh);
2680
- meshes.push(mesh);
2681
- }
2682
-
2683
- for (let i = 0, il = meshes.length; i < il; i++) {
2684
- parser.associations.set(meshes[i], {
2685
- meshes: meshIndex,
2686
- primitives: i,
2687
- });
2688
- }
2689
-
2690
- if (meshes.length === 1) {
2691
- return meshes[0];
2692
- }
2693
-
2694
- const group = new THREE.Group();
2695
- parser.associations.set(group, {
2696
- meshes: meshIndex,
2697
- });
2698
-
2699
- for (let i = 0, il = meshes.length; i < il; i++) {
2700
- group.add(meshes[i]);
2701
- }
2702
-
2703
- return group;
2704
- });
2705
- }
2706
- /**
2707
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#cameras
2708
- * @param {number} cameraIndex
2709
- * @return {Promise<THREE.Camera>}
2710
- */
2711
-
2712
- loadCamera(cameraIndex) {
2713
- let camera;
2714
- const cameraDef = this.json.cameras[cameraIndex];
2715
- const params = cameraDef[cameraDef.type];
2716
-
2717
- if (!params) {
2718
- console.warn("THREE.GLTFLoader: Missing camera parameters.");
2719
- return;
2720
- }
2721
-
2722
- if (cameraDef.type === "perspective") {
2723
- camera = new THREE.PerspectiveCamera(
2724
- THREE.MathUtils.radToDeg(params.yfov),
2725
- params.aspectRatio || 1,
2726
- params.znear || 1,
2727
- params.zfar || 2e6
2728
- );
2729
- } else if (cameraDef.type === "orthographic") {
2730
- camera = new THREE.OrthographicCamera(
2731
- -params.xmag,
2732
- params.xmag,
2733
- params.ymag,
2734
- -params.ymag,
2735
- params.znear,
2736
- params.zfar
2737
- );
2738
- }
2739
-
2740
- if (cameraDef.name) camera.name = this.createUniqueName(cameraDef.name);
2741
- assignExtrasToUserData(camera, cameraDef);
2742
- return Promise.resolve(camera);
2743
- }
2744
- /**
2745
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins
2746
- * @param {number} skinIndex
2747
- * @return {Promise<Object>}
2748
- */
2749
-
2750
- loadSkin(skinIndex) {
2751
- const skinDef = this.json.skins[skinIndex];
2752
- const skinEntry = {
2753
- joints: skinDef.joints,
2754
- };
2755
-
2756
- if (skinDef.inverseBindMatrices === undefined) {
2757
- return Promise.resolve(skinEntry);
2758
- }
2759
-
2760
- return this.getDependency("accessor", skinDef.inverseBindMatrices).then(function (accessor) {
2761
- skinEntry.inverseBindMatrices = accessor;
2762
- return skinEntry;
2763
- });
2764
- }
2765
- /**
2766
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#animations
2767
- * @param {number} animationIndex
2768
- * @return {Promise<AnimationClip>}
2769
- */
2770
-
2771
- loadAnimation(animationIndex) {
2772
- const json = this.json;
2773
- const animationDef = json.animations[animationIndex];
2774
- const pendingNodes = [];
2775
- const pendingInputAccessors = [];
2776
- const pendingOutputAccessors = [];
2777
- const pendingSamplers = [];
2778
- const pendingTargets = [];
2779
-
2780
- for (let i = 0, il = animationDef.channels.length; i < il; i++) {
2781
- const channel = animationDef.channels[i];
2782
- const sampler = animationDef.samplers[channel.sampler];
2783
- const target = channel.target;
2784
- const name = target.node !== undefined ? target.node : target.id; // NOTE: target.id is deprecated.
2785
-
2786
- const input =
2787
- animationDef.parameters !== undefined
2788
- ? animationDef.parameters[sampler.input]
2789
- : sampler.input;
2790
- const output =
2791
- animationDef.parameters !== undefined
2792
- ? animationDef.parameters[sampler.output]
2793
- : sampler.output;
2794
- pendingNodes.push(this.getDependency("node", name));
2795
- pendingInputAccessors.push(this.getDependency("accessor", input));
2796
- pendingOutputAccessors.push(this.getDependency("accessor", output));
2797
- pendingSamplers.push(sampler);
2798
- pendingTargets.push(target);
2799
- }
2800
-
2801
- return Promise.all([
2802
- Promise.all(pendingNodes),
2803
- Promise.all(pendingInputAccessors),
2804
- Promise.all(pendingOutputAccessors),
2805
- Promise.all(pendingSamplers),
2806
- Promise.all(pendingTargets),
2807
- ]).then(function (dependencies) {
2808
- const nodes = dependencies[0];
2809
- const inputAccessors = dependencies[1];
2810
- const outputAccessors = dependencies[2];
2811
- const samplers = dependencies[3];
2812
- const targets = dependencies[4];
2813
- const tracks = [];
2814
-
2815
- for (let i = 0, il = nodes.length; i < il; i++) {
2816
- const node = nodes[i];
2817
- const inputAccessor = inputAccessors[i];
2818
- const outputAccessor = outputAccessors[i];
2819
- const sampler = samplers[i];
2820
- const target = targets[i];
2821
- if (node === undefined) continue;
2822
- node.updateMatrix();
2823
- node.matrixAutoUpdate = true;
2824
- let TypedKeyframeTrack;
2825
-
2826
- switch (PATH_PROPERTIES[target.path]) {
2827
- case PATH_PROPERTIES.weights:
2828
- TypedKeyframeTrack = THREE.NumberKeyframeTrack;
2829
- break;
2830
-
2831
- case PATH_PROPERTIES.rotation:
2832
- TypedKeyframeTrack = THREE.QuaternionKeyframeTrack;
2833
- break;
2834
-
2835
- case PATH_PROPERTIES.position:
2836
- case PATH_PROPERTIES.scale:
2837
- default:
2838
- TypedKeyframeTrack = THREE.VectorKeyframeTrack;
2839
- break;
2840
- }
2841
-
2842
- const targetName = node.name ? node.name : node.uuid;
2843
- const interpolation =
2844
- sampler.interpolation !== undefined
2845
- ? INTERPOLATION[sampler.interpolation]
2846
- : THREE.InterpolateLinear;
2847
- const targetNames = [];
2848
-
2849
- if (PATH_PROPERTIES[target.path] === PATH_PROPERTIES.weights) {
2850
- node.traverse(function (object) {
2851
- if (object.morphTargetInfluences) {
2852
- targetNames.push(object.name ? object.name : object.uuid);
2853
- }
2854
- });
2855
- } else {
2856
- targetNames.push(targetName);
2857
- }
2858
-
2859
- let outputArray = outputAccessor.array;
2860
-
2861
- if (outputAccessor.normalized) {
2862
- const scale = getNormalizedComponentScale(outputArray.constructor);
2863
- const scaled = new Float32Array(outputArray.length);
2864
-
2865
- for (let j = 0, jl = outputArray.length; j < jl; j++) {
2866
- scaled[j] = outputArray[j] * scale;
2867
- }
2868
-
2869
- outputArray = scaled;
2870
- }
2871
-
2872
- for (let j = 0, jl = targetNames.length; j < jl; j++) {
2873
- const track = new TypedKeyframeTrack(
2874
- targetNames[j] + "." + PATH_PROPERTIES[target.path],
2875
- inputAccessor.array,
2876
- outputArray,
2877
- interpolation
2878
- ); // Override interpolation with custom factory method.
2879
-
2880
- if (sampler.interpolation === "CUBICSPLINE") {
2881
- track.createInterpolant = function InterpolantFactoryMethodGLTFCubicSpline(result) {
2882
- // A CUBICSPLINE keyframe in glTF has three output values for each input value,
2883
- // representing inTangent, splineVertex, and outTangent. As a result, track.getValueSize()
2884
- // must be divided by three to get the interpolant's sampleSize argument.
2885
- const interpolantType =
2886
- this instanceof THREE.QuaternionKeyframeTrack
2887
- ? GLTFCubicSplineQuaternionInterpolant
2888
- : GLTFCubicSplineInterpolant;
2889
- return new interpolantType(
2890
- this.times,
2891
- this.values,
2892
- this.getValueSize() / 3,
2893
- result
2894
- );
2895
- }; // Mark as CUBICSPLINE. `track.getInterpolation()` doesn't support custom interpolants.
2896
-
2897
- track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline = true;
2898
- }
2899
-
2900
- tracks.push(track);
2901
- }
2902
- }
2903
-
2904
- const name = animationDef.name ? animationDef.name : "animation_" + animationIndex;
2905
- return new THREE.AnimationClip(name, undefined, tracks);
2906
- });
2907
- }
2908
-
2909
- createNodeMesh(nodeIndex) {
2910
- const json = this.json;
2911
- const parser = this;
2912
- const nodeDef = json.nodes[nodeIndex];
2913
- if (nodeDef.mesh === undefined) return null;
2914
- return parser.getDependency("mesh", nodeDef.mesh).then(function (mesh) {
2915
- const node = parser._getNodeRef(parser.meshCache, nodeDef.mesh, mesh); // if weights are provided on the node, override weights on the mesh.
2916
-
2917
- if (nodeDef.weights !== undefined) {
2918
- node.traverse(function (o) {
2919
- if (!o.isMesh) return;
2920
-
2921
- for (let i = 0, il = nodeDef.weights.length; i < il; i++) {
2922
- o.morphTargetInfluences[i] = nodeDef.weights[i];
2923
- }
2924
- });
2925
- }
2926
-
2927
- return node;
2928
- });
2929
- }
2930
- /**
2931
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#nodes-and-hierarchy
2932
- * @param {number} nodeIndex
2933
- * @return {Promise<Object3D>}
2934
- */
2935
-
2936
- loadNode(nodeIndex) {
2937
- const json = this.json;
2938
- const extensions = this.extensions;
2939
- const parser = this;
2940
- const nodeDef = json.nodes[nodeIndex]; // reserve node's name before its dependencies, so the root has the intended name.
2941
-
2942
- const nodeName = nodeDef.name ? parser.createUniqueName(nodeDef.name) : "";
2943
- return (function () {
2944
- const pending = [];
2945
-
2946
- const meshPromise = parser._invokeOne(function (ext) {
2947
- return ext.createNodeMesh && ext.createNodeMesh(nodeIndex);
2948
- });
2949
-
2950
- if (meshPromise) {
2951
- pending.push(meshPromise);
2952
- }
2953
-
2954
- if (nodeDef.camera !== undefined) {
2955
- pending.push(
2956
- parser.getDependency("camera", nodeDef.camera).then(function (camera) {
2957
- return parser._getNodeRef(parser.cameraCache, nodeDef.camera, camera);
2958
- })
2959
- );
2960
- }
2961
-
2962
- parser
2963
- ._invokeAll(function (ext) {
2964
- return ext.createNodeAttachment && ext.createNodeAttachment(nodeIndex);
2965
- })
2966
- .forEach(function (promise) {
2967
- pending.push(promise);
2968
- });
2969
-
2970
- return Promise.all(pending);
2971
- })().then(function (objects) {
2972
- let node; // .isBone isn't in glTF spec. See ._markDefs
2973
-
2974
- if (nodeDef.isBone === true) {
2975
- node = new THREE.Bone();
2976
- } else if (objects.length > 1) {
2977
- node = new THREE.Group();
2978
- } else if (objects.length === 1) {
2979
- node = objects[0];
2980
- } else {
2981
- node = new THREE.Object3D();
2982
- }
2983
-
2984
- if (node !== objects[0]) {
2985
- for (let i = 0, il = objects.length; i < il; i++) {
2986
- node.add(objects[i]);
2987
- }
2988
- }
2989
-
2990
- if (nodeDef.name) {
2991
- node.userData.name = nodeDef.name;
2992
- node.name = nodeName;
2993
- }
2994
-
2995
- assignExtrasToUserData(node, nodeDef);
2996
- if (nodeDef.extensions) addUnknownExtensionsToUserData(extensions, node, nodeDef);
2997
-
2998
- if (nodeDef.matrix !== undefined) {
2999
- const matrix = new THREE.Matrix4();
3000
- matrix.fromArray(nodeDef.matrix);
3001
- node.applyMatrix4(matrix);
3002
- } else {
3003
- if (nodeDef.translation !== undefined) {
3004
- node.position.fromArray(nodeDef.translation);
3005
- }
3006
-
3007
- if (nodeDef.rotation !== undefined) {
3008
- node.quaternion.fromArray(nodeDef.rotation);
3009
- }
3010
-
3011
- if (nodeDef.scale !== undefined) {
3012
- node.scale.fromArray(nodeDef.scale);
3013
- }
3014
- }
3015
-
3016
- if (!parser.associations.has(node)) {
3017
- parser.associations.set(node, {});
3018
- }
3019
-
3020
- parser.associations.get(node).nodes = nodeIndex;
3021
- return node;
3022
- });
3023
- }
3024
- /**
3025
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#scenes
3026
- * @param {number} sceneIndex
3027
- * @return {Promise<Group>}
3028
- */
3029
-
3030
- loadScene(sceneIndex) {
3031
- const json = this.json;
3032
- const extensions = this.extensions;
3033
- const sceneDef = this.json.scenes[sceneIndex];
3034
- const parser = this; // THREE.Loader returns THREE.Group, not Scene.
3035
- // See: https://github.com/mrdoob/three.js/issues/18342#issuecomment-578981172
3036
-
3037
- const scene = new THREE.Group();
3038
- if (sceneDef.name) scene.name = parser.createUniqueName(sceneDef.name);
3039
- assignExtrasToUserData(scene, sceneDef);
3040
- if (sceneDef.extensions) addUnknownExtensionsToUserData(extensions, scene, sceneDef);
3041
- const nodeIds = sceneDef.nodes || [];
3042
- const pending = [];
3043
-
3044
- for (let i = 0, il = nodeIds.length; i < il; i++) {
3045
- pending.push(buildNodeHierarchy(nodeIds[i], scene, json, parser));
3046
- }
3047
-
3048
- return Promise.all(pending).then(function () {
3049
- // Removes dangling associations, associations that reference a node that
3050
- // didn't make it into the scene.
3051
- const reduceAssociations = (node) => {
3052
- const reducedAssociations = new Map();
3053
-
3054
- for (const [key, value] of parser.associations) {
3055
- if (key instanceof THREE.Material || key instanceof THREE.Texture) {
3056
- reducedAssociations.set(key, value);
3057
- }
3058
- }
3059
-
3060
- node.traverse((node) => {
3061
- const mappings = parser.associations.get(node);
3062
-
3063
- if (mappings != null) {
3064
- reducedAssociations.set(node, mappings);
3065
- }
3066
- });
3067
- return reducedAssociations;
3068
- };
3069
-
3070
- parser.associations = reduceAssociations(scene);
3071
- return scene;
3072
- });
3073
- }
3074
- }
3075
-
3076
- function buildNodeHierarchy(nodeId, parentObject, json, parser) {
3077
- const nodeDef = json.nodes[nodeId];
3078
- return parser
3079
- .getDependency("node", nodeId)
3080
- .then(function (node) {
3081
- if (nodeDef.skin === undefined) return node; // build skeleton here as well
3082
-
3083
- let skinEntry;
3084
- return parser
3085
- .getDependency("skin", nodeDef.skin)
3086
- .then(function (skin) {
3087
- skinEntry = skin;
3088
- const pendingJoints = [];
3089
-
3090
- for (let i = 0, il = skinEntry.joints.length; i < il; i++) {
3091
- pendingJoints.push(parser.getDependency("node", skinEntry.joints[i]));
3092
- }
3093
-
3094
- return Promise.all(pendingJoints);
3095
- })
3096
- .then(function (jointNodes) {
3097
- node.traverse(function (mesh) {
3098
- if (!mesh.isMesh) return;
3099
- const bones = [];
3100
- const boneInverses = [];
3101
-
3102
- for (let j = 0, jl = jointNodes.length; j < jl; j++) {
3103
- const jointNode = jointNodes[j];
3104
-
3105
- if (jointNode) {
3106
- bones.push(jointNode);
3107
- const mat = new THREE.Matrix4();
3108
-
3109
- if (skinEntry.inverseBindMatrices !== undefined) {
3110
- mat.fromArray(skinEntry.inverseBindMatrices.array, j * 16);
3111
- }
3112
-
3113
- boneInverses.push(mat);
3114
- } else {
3115
- console.warn(
3116
- 'THREE.GLTFLoader: Joint "%s" could not be found.',
3117
- skinEntry.joints[j]
3118
- );
3119
- }
3120
- }
3121
-
3122
- mesh.bind(new THREE.Skeleton(bones, boneInverses), mesh.matrixWorld);
3123
- });
3124
- return node;
3125
- });
3126
- })
3127
- .then(function (node) {
3128
- // build node hierachy
3129
- parentObject.add(node);
3130
- const pending = [];
3131
-
3132
- if (nodeDef.children) {
3133
- const children = nodeDef.children;
3134
-
3135
- for (let i = 0, il = children.length; i < il; i++) {
3136
- const child = children[i];
3137
- pending.push(buildNodeHierarchy(child, node, json, parser));
3138
- }
3139
- }
3140
-
3141
- return Promise.all(pending);
3142
- });
3143
- }
3144
- /**
3145
- * @param {BufferGeometry} geometry
3146
- * @param {GLTF.Primitive} primitiveDef
3147
- * @param {GLTFParser} parser
3148
- */
3149
-
3150
- function computeBounds(geometry, primitiveDef, parser) {
3151
- const attributes = primitiveDef.attributes;
3152
- const box = new THREE.Box3();
3153
-
3154
- if (attributes.POSITION !== undefined) {
3155
- const accessor = parser.json.accessors[attributes.POSITION];
3156
- const min = accessor.min;
3157
- const max = accessor.max; // glTF requires 'min' and 'max', but VRM (which extends glTF) currently ignores that requirement.
3158
-
3159
- if (min !== undefined && max !== undefined) {
3160
- box.set(
3161
- new THREE.Vector3(min[0], min[1], min[2]),
3162
- new THREE.Vector3(max[0], max[1], max[2])
3163
- );
3164
-
3165
- if (accessor.normalized) {
3166
- const boxScale = getNormalizedComponentScale(
3167
- WEBGL_COMPONENT_TYPES[accessor.componentType]
3168
- );
3169
- box.min.multiplyScalar(boxScale);
3170
- box.max.multiplyScalar(boxScale);
3171
- }
3172
- } else {
3173
- console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");
3174
- return;
3175
- }
3176
- } else {
3177
- return;
3178
- }
3179
-
3180
- const targets = primitiveDef.targets;
3181
-
3182
- if (targets !== undefined) {
3183
- const maxDisplacement = new THREE.Vector3();
3184
- const vector = new THREE.Vector3();
3185
-
3186
- for (let i = 0, il = targets.length; i < il; i++) {
3187
- const target = targets[i];
3188
-
3189
- if (target.POSITION !== undefined) {
3190
- const accessor = parser.json.accessors[target.POSITION];
3191
- const min = accessor.min;
3192
- const max = accessor.max; // glTF requires 'min' and 'max', but VRM (which extends glTF) currently ignores that requirement.
3193
-
3194
- if (min !== undefined && max !== undefined) {
3195
- // we need to get max of absolute components because target weight is [-1,1]
3196
- vector.setX(Math.max(Math.abs(min[0]), Math.abs(max[0])));
3197
- vector.setY(Math.max(Math.abs(min[1]), Math.abs(max[1])));
3198
- vector.setZ(Math.max(Math.abs(min[2]), Math.abs(max[2])));
3199
-
3200
- if (accessor.normalized) {
3201
- const boxScale = getNormalizedComponentScale(
3202
- WEBGL_COMPONENT_TYPES[accessor.componentType]
3203
- );
3204
- vector.multiplyScalar(boxScale);
3205
- } // Note: this assumes that the sum of all weights is at most 1. This isn't quite correct - it's more conservative
3206
- // to assume that each target can have a max weight of 1. However, for some use cases - notably, when morph targets
3207
- // are used to implement key-frame animations and as such only two are active at a time - this results in very large
3208
- // boxes. So for now we make a box that's sometimes a touch too small but is hopefully mostly of reasonable size.
3209
-
3210
- maxDisplacement.max(vector);
3211
- } else {
3212
- console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");
3213
- }
3214
- }
3215
- } // As per comment above this box isn't conservative, but has a reasonable size for a very large number of morph targets.
3216
-
3217
- box.expandByVector(maxDisplacement);
3218
- }
3219
-
3220
- geometry.boundingBox = box;
3221
- const sphere = new THREE.Sphere();
3222
- box.getCenter(sphere.center);
3223
- sphere.radius = box.min.distanceTo(box.max) / 2;
3224
- geometry.boundingSphere = sphere;
3225
- }
3226
- /**
3227
- * @param {BufferGeometry} geometry
3228
- * @param {GLTF.Primitive} primitiveDef
3229
- * @param {GLTFParser} parser
3230
- * @return {Promise<BufferGeometry>}
3231
- */
3232
-
3233
- function addPrimitiveAttributes(geometry, primitiveDef, parser) {
3234
- const attributes = primitiveDef.attributes;
3235
- const pending = [];
3236
-
3237
- function assignAttributeAccessor(accessorIndex, attributeName) {
3238
- return parser.getDependency("accessor", accessorIndex).then(function (accessor) {
3239
- geometry.setAttribute(attributeName, accessor);
3240
- });
3241
- }
3242
-
3243
- for (const gltfAttributeName in attributes) {
3244
- const threeAttributeName = ATTRIBUTES[gltfAttributeName] || gltfAttributeName.toLowerCase(); // Skip attributes already provided by e.g. Draco extension.
3245
-
3246
- if (threeAttributeName in geometry.attributes) continue;
3247
- pending.push(assignAttributeAccessor(attributes[gltfAttributeName], threeAttributeName));
3248
- }
3249
-
3250
- if (primitiveDef.indices !== undefined && !geometry.index) {
3251
- const accessor = parser
3252
- .getDependency("accessor", primitiveDef.indices)
3253
- .then(function (accessor) {
3254
- geometry.setIndex(accessor);
3255
- });
3256
- pending.push(accessor);
3257
- }
3258
-
3259
- assignExtrasToUserData(geometry, primitiveDef);
3260
- computeBounds(geometry, primitiveDef, parser);
3261
- return Promise.all(pending).then(function () {
3262
- return primitiveDef.targets !== undefined
3263
- ? addMorphTargets(geometry, primitiveDef.targets, parser)
3264
- : geometry;
3265
- });
3266
- }
3267
- /**
3268
- * @param {BufferGeometry} geometry
3269
- * @param {Number} drawMode
3270
- * @return {BufferGeometry}
3271
- */
3272
-
3273
- function toTrianglesDrawMode(geometry, drawMode) {
3274
- let index = geometry.getIndex(); // generate index if not present
3275
-
3276
- if (index === null) {
3277
- const indices = [];
3278
- const position = geometry.getAttribute("position");
3279
-
3280
- if (position !== undefined) {
3281
- for (let i = 0; i < position.count; i++) {
3282
- indices.push(i);
3283
- }
3284
-
3285
- geometry.setIndex(indices);
3286
- index = geometry.getIndex();
3287
- } else {
3288
- console.error(
3289
- "THREE.GLTFLoader.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."
3290
- );
3291
- return geometry;
3292
- }
3293
- } //
3294
-
3295
- const numberOfTriangles = index.count - 2;
3296
- const newIndices = [];
3297
-
3298
- if (drawMode === THREE.TriangleFanDrawMode) {
3299
- // gl.TRIANGLE_FAN
3300
- for (let i = 1; i <= numberOfTriangles; i++) {
3301
- newIndices.push(index.getX(0));
3302
- newIndices.push(index.getX(i));
3303
- newIndices.push(index.getX(i + 1));
3304
- }
3305
- } else {
3306
- // gl.TRIANGLE_STRIP
3307
- for (let i = 0; i < numberOfTriangles; i++) {
3308
- if (i % 2 === 0) {
3309
- newIndices.push(index.getX(i));
3310
- newIndices.push(index.getX(i + 1));
3311
- newIndices.push(index.getX(i + 2));
3312
- } else {
3313
- newIndices.push(index.getX(i + 2));
3314
- newIndices.push(index.getX(i + 1));
3315
- newIndices.push(index.getX(i));
3316
- }
3317
- }
3318
- }
3319
-
3320
- if (newIndices.length / 3 !== numberOfTriangles) {
3321
- console.error(
3322
- "THREE.GLTFLoader.toTrianglesDrawMode(): Unable to generate correct amount of triangles."
3323
- );
3324
- } // build final geometry
3325
-
3326
- const newGeometry = geometry.clone();
3327
- newGeometry.setIndex(newIndices);
3328
- return newGeometry;
3329
- }
3330
-
3331
- export default GLTFLoader;