@anov/3d 0.0.3 → 0.0.4-alpha12

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 (586) hide show
  1. package/README.md +1 -144
  2. package/dist/applicationApi.d.ts +34 -0
  3. package/dist/{core/cssRenderer.js → applicationApi.js} +53 -21
  4. package/dist/environment/index.d.ts +24 -0
  5. package/dist/environment/index.js +84 -0
  6. package/dist/environment/time/index.d.ts +12 -0
  7. package/dist/environment/time/index.js +27 -0
  8. package/dist/environment/weather/type.d.ts +15 -0
  9. package/dist/environment/weather/type.js +27 -0
  10. package/dist/hooksManager.d.ts +2 -0
  11. package/dist/hooksManager.js +15 -0
  12. package/dist/index.d.ts +15 -3
  13. package/dist/index.js +38 -5
  14. package/dist/messageStatus.d.ts +49 -0
  15. package/dist/messageStatus.js +50 -0
  16. package/dist/utils/index.d.ts +11 -44
  17. package/dist/utils/index.js +29 -73
  18. package/dist/utils/messageFn.d.ts +12 -0
  19. package/dist/utils/messageFn.js +33 -0
  20. package/package.json +8 -24
  21. package/dist/commonEnu.d.ts +0 -5
  22. package/dist/commonEnu.js +0 -6
  23. package/dist/core/camera.d.ts +0 -32
  24. package/dist/core/camera.js +0 -74
  25. package/dist/core/control/transformControls.d.ts +0 -12
  26. package/dist/core/control/transformControls.js +0 -72
  27. package/dist/core/cssRenderer.d.ts +0 -17
  28. package/dist/core/global/global.d.ts +0 -27
  29. package/dist/core/global/global.js +0 -72
  30. package/dist/core/global/globalControl.d.ts +0 -17
  31. package/dist/core/global/globalControl.js +0 -62
  32. package/dist/core/group.d.ts +0 -53
  33. package/dist/core/group.js +0 -135
  34. package/dist/core/line.d.ts +0 -13
  35. package/dist/core/line.js +0 -83
  36. package/dist/core/mesh.d.ts +0 -49
  37. package/dist/core/mesh.js +0 -146
  38. package/dist/core/model.d.ts +0 -29
  39. package/dist/core/model.js +0 -85
  40. package/dist/core/scene.d.ts +0 -175
  41. package/dist/core/scene.js +0 -389
  42. package/dist/core/use/useScene.d.ts +0 -10
  43. package/dist/core/use/useScene.js +0 -14
  44. package/dist/core/use/useframe.d.ts +0 -6
  45. package/dist/core/use/useframe.js +0 -11
  46. package/dist/export.d.ts +0 -40
  47. package/dist/export.js +0 -36
  48. package/dist/threeCell.d.ts +0 -8
  49. package/dist/threeCell.js +0 -16
  50. package/dist/type.d.ts +0 -4
  51. package/dist/type.js +0 -1
  52. package/dist/utils/createElement.d.ts +0 -103
  53. package/dist/utils/createElement.js +0 -145
  54. package/dist/utils/createLabel.d.ts +0 -2
  55. package/dist/utils/createLabel.js +0 -4
  56. package/dist/utils/line.d.ts +0 -0
  57. package/dist/utils/line.js +0 -0
  58. package/dist/utils/move.d.ts +0 -48
  59. package/dist/utils/move.js +0 -149
  60. package/examples/fonts/LICENSE +0 -13
  61. package/examples/fonts/README.md +0 -11
  62. package/examples/fonts/droid/NOTICE +0 -190
  63. package/examples/fonts/droid/README.txt +0 -18
  64. package/examples/fonts/droid/droid_sans_bold.typeface.json +0 -1
  65. package/examples/fonts/droid/droid_sans_mono_regular.typeface.json +0 -1
  66. package/examples/fonts/droid/droid_sans_regular.typeface.json +0 -1
  67. package/examples/fonts/droid/droid_serif_bold.typeface.json +0 -1
  68. package/examples/fonts/droid/droid_serif_regular.typeface.json +0 -1
  69. package/examples/fonts/gentilis_bold.typeface.json +0 -1
  70. package/examples/fonts/gentilis_regular.typeface.json +0 -1
  71. package/examples/fonts/helvetiker_bold.typeface.json +0 -1
  72. package/examples/fonts/helvetiker_regular.typeface.json +0 -1
  73. package/examples/fonts/optimer_bold.typeface.json +0 -1
  74. package/examples/fonts/optimer_regular.typeface.json +0 -1
  75. package/examples/fonts/ttf/README.md +0 -9
  76. package/examples/fonts/ttf/kenpixel.ttf +0 -0
  77. package/examples/jsm/animation/AnimationClipCreator.js +0 -116
  78. package/examples/jsm/animation/CCDIKSolver.js +0 -482
  79. package/examples/jsm/animation/MMDAnimationHelper.js +0 -1207
  80. package/examples/jsm/animation/MMDPhysics.js +0 -1406
  81. package/examples/jsm/cameras/CinematicCamera.js +0 -208
  82. package/examples/jsm/capabilities/WebGL.js +0 -91
  83. package/examples/jsm/capabilities/WebGPU.js +0 -53
  84. package/examples/jsm/controls/ArcballControls.js +0 -3224
  85. package/examples/jsm/controls/DragControls.js +0 -220
  86. package/examples/jsm/controls/FirstPersonControls.js +0 -325
  87. package/examples/jsm/controls/FlyControls.js +0 -300
  88. package/examples/jsm/controls/MapControls.js +0 -28
  89. package/examples/jsm/controls/OrbitControls.js +0 -1388
  90. package/examples/jsm/controls/PointerLockControls.js +0 -162
  91. package/examples/jsm/controls/TrackballControls.js +0 -828
  92. package/examples/jsm/controls/TransformControls.js +0 -1557
  93. package/examples/jsm/csm/CSM.js +0 -384
  94. package/examples/jsm/csm/CSMFrustum.js +0 -152
  95. package/examples/jsm/csm/CSMHelper.js +0 -193
  96. package/examples/jsm/csm/CSMShader.js +0 -252
  97. package/examples/jsm/curves/CurveExtras.js +0 -422
  98. package/examples/jsm/curves/NURBSCurve.js +0 -80
  99. package/examples/jsm/curves/NURBSSurface.js +0 -52
  100. package/examples/jsm/curves/NURBSUtils.js +0 -487
  101. package/examples/jsm/effects/AnaglyphEffect.js +0 -154
  102. package/examples/jsm/effects/AsciiEffect.js +0 -263
  103. package/examples/jsm/effects/OutlineEffect.js +0 -539
  104. package/examples/jsm/effects/ParallaxBarrierEffect.js +0 -119
  105. package/examples/jsm/effects/PeppersGhostEffect.js +0 -153
  106. package/examples/jsm/effects/StereoEffect.js +0 -55
  107. package/examples/jsm/environments/DebugEnvironment.js +0 -52
  108. package/examples/jsm/environments/RoomEnvironment.js +0 -148
  109. package/examples/jsm/exporters/DRACOExporter.js +0 -267
  110. package/examples/jsm/exporters/EXRExporter.js +0 -501
  111. package/examples/jsm/exporters/GLTFExporter.js +0 -3161
  112. package/examples/jsm/exporters/KTX2Exporter.js +0 -292
  113. package/examples/jsm/exporters/MMDExporter.js +0 -217
  114. package/examples/jsm/exporters/OBJExporter.js +0 -284
  115. package/examples/jsm/exporters/PLYExporter.js +0 -528
  116. package/examples/jsm/exporters/STLExporter.js +0 -199
  117. package/examples/jsm/exporters/USDZExporter.js +0 -711
  118. package/examples/jsm/geometries/BoxLineGeometry.js +0 -69
  119. package/examples/jsm/geometries/ConvexGeometry.js +0 -53
  120. package/examples/jsm/geometries/DecalGeometry.js +0 -356
  121. package/examples/jsm/geometries/ParametricGeometries.js +0 -254
  122. package/examples/jsm/geometries/ParametricGeometry.js +0 -139
  123. package/examples/jsm/geometries/RoundedBoxGeometry.js +0 -155
  124. package/examples/jsm/geometries/TeapotGeometry.js +0 -704
  125. package/examples/jsm/geometries/TextGeometry.js +0 -57
  126. package/examples/jsm/helpers/LightProbeHelper.js +0 -130
  127. package/examples/jsm/helpers/OctreeHelper.js +0 -73
  128. package/examples/jsm/helpers/PositionalAudioHelper.js +0 -109
  129. package/examples/jsm/helpers/RectAreaLightHelper.js +0 -85
  130. package/examples/jsm/helpers/VertexNormalsHelper.js +0 -96
  131. package/examples/jsm/helpers/VertexTangentsHelper.js +0 -88
  132. package/examples/jsm/helpers/ViewHelper.js +0 -333
  133. package/examples/jsm/interactive/HTMLMesh.js +0 -565
  134. package/examples/jsm/interactive/InteractiveGroup.js +0 -116
  135. package/examples/jsm/interactive/SelectionBox.js +0 -227
  136. package/examples/jsm/interactive/SelectionHelper.js +0 -104
  137. package/examples/jsm/libs/ammo.wasm.js +0 -822
  138. package/examples/jsm/libs/ammo.wasm.wasm +0 -0
  139. package/examples/jsm/libs/basis/README.md +0 -46
  140. package/examples/jsm/libs/basis/basis_transcoder.js +0 -21
  141. package/examples/jsm/libs/basis/basis_transcoder.wasm +0 -0
  142. package/examples/jsm/libs/chevrotain.module.min.js +0 -141
  143. package/examples/jsm/libs/draco/README.md +0 -32
  144. package/examples/jsm/libs/draco/draco_decoder.js +0 -34
  145. package/examples/jsm/libs/draco/draco_decoder.wasm +0 -0
  146. package/examples/jsm/libs/draco/draco_encoder.js +0 -33
  147. package/examples/jsm/libs/draco/draco_wasm_wrapper.js +0 -117
  148. package/examples/jsm/libs/draco/gltf/draco_decoder.js +0 -33
  149. package/examples/jsm/libs/draco/gltf/draco_decoder.wasm +0 -0
  150. package/examples/jsm/libs/draco/gltf/draco_encoder.js +0 -33
  151. package/examples/jsm/libs/draco/gltf/draco_wasm_wrapper.js +0 -116
  152. package/examples/jsm/libs/ecsy.module.js +0 -1792
  153. package/examples/jsm/libs/fflate.module.js +0 -2474
  154. package/examples/jsm/libs/ktx-parse.module.js +0 -1
  155. package/examples/jsm/libs/lil-gui.module.min.js +0 -8
  156. package/examples/jsm/libs/lottie_canvas.module.js +0 -14844
  157. package/examples/jsm/libs/meshopt_decoder.module.js +0 -178
  158. package/examples/jsm/libs/mikktspace.module.js +0 -128
  159. package/examples/jsm/libs/mmdparser.module.js +0 -11530
  160. package/examples/jsm/libs/motion-controllers.module.js +0 -397
  161. package/examples/jsm/libs/opentype.module.js +0 -14568
  162. package/examples/jsm/libs/potpack.module.js +0 -125
  163. package/examples/jsm/libs/rhino3dm/rhino3dm.js +0 -21
  164. package/examples/jsm/libs/rhino3dm/rhino3dm.module.js +0 -16
  165. package/examples/jsm/libs/rhino3dm/rhino3dm.wasm +0 -0
  166. package/examples/jsm/libs/stats.module.js +0 -167
  167. package/examples/jsm/libs/tween.module.js +0 -803
  168. package/examples/jsm/libs/utif.module.js +0 -1579
  169. package/examples/jsm/libs/zstddec.module.js +0 -1
  170. package/examples/jsm/lights/IESSpotLight.js +0 -25
  171. package/examples/jsm/lights/LightProbeGenerator.js +0 -252
  172. package/examples/jsm/lights/RectAreaLightUniformsLib.js +0 -79
  173. package/examples/jsm/lines/Line2.js +0 -19
  174. package/examples/jsm/lines/LineGeometry.js +0 -79
  175. package/examples/jsm/lines/LineMaterial.js +0 -702
  176. package/examples/jsm/lines/LineSegments2.js +0 -361
  177. package/examples/jsm/lines/LineSegmentsGeometry.js +0 -241
  178. package/examples/jsm/lines/Wireframe.js +0 -56
  179. package/examples/jsm/lines/WireframeGeometry2.js +0 -24
  180. package/examples/jsm/loaders/3DMLoader.js +0 -1497
  181. package/examples/jsm/loaders/3MFLoader.js +0 -1478
  182. package/examples/jsm/loaders/AMFLoader.js +0 -521
  183. package/examples/jsm/loaders/BVHLoader.js +0 -437
  184. package/examples/jsm/loaders/ColladaLoader.js +0 -4122
  185. package/examples/jsm/loaders/DDSLoader.js +0 -274
  186. package/examples/jsm/loaders/DRACOLoader.js +0 -612
  187. package/examples/jsm/loaders/EXRLoader.js +0 -2309
  188. package/examples/jsm/loaders/FBXLoader.js +0 -4142
  189. package/examples/jsm/loaders/FontLoader.js +0 -183
  190. package/examples/jsm/loaders/GCodeLoader.js +0 -261
  191. package/examples/jsm/loaders/GLTFLoader.js +0 -4576
  192. package/examples/jsm/loaders/HDRCubeTextureLoader.js +0 -115
  193. package/examples/jsm/loaders/IESLoader.js +0 -337
  194. package/examples/jsm/loaders/KMZLoader.js +0 -130
  195. package/examples/jsm/loaders/KTX2Loader.js +0 -868
  196. package/examples/jsm/loaders/KTXLoader.js +0 -176
  197. package/examples/jsm/loaders/LDrawLoader.js +0 -2464
  198. package/examples/jsm/loaders/LUT3dlLoader.js +0 -151
  199. package/examples/jsm/loaders/LUTCubeLoader.js +0 -153
  200. package/examples/jsm/loaders/LWOLoader.js +0 -1052
  201. package/examples/jsm/loaders/LogLuvLoader.js +0 -606
  202. package/examples/jsm/loaders/LottieLoader.js +0 -77
  203. package/examples/jsm/loaders/MD2Loader.js +0 -399
  204. package/examples/jsm/loaders/MDDLoader.js +0 -102
  205. package/examples/jsm/loaders/MMDLoader.js +0 -2273
  206. package/examples/jsm/loaders/MTLLoader.js +0 -567
  207. package/examples/jsm/loaders/MaterialXLoader.js +0 -734
  208. package/examples/jsm/loaders/NRRDLoader.js +0 -699
  209. package/examples/jsm/loaders/OBJLoader.js +0 -905
  210. package/examples/jsm/loaders/PCDLoader.js +0 -467
  211. package/examples/jsm/loaders/PDBLoader.js +0 -232
  212. package/examples/jsm/loaders/PLYLoader.js +0 -771
  213. package/examples/jsm/loaders/PVRLoader.js +0 -251
  214. package/examples/jsm/loaders/RGBELoader.js +0 -468
  215. package/examples/jsm/loaders/RGBMLoader.js +0 -1065
  216. package/examples/jsm/loaders/STLLoader.js +0 -403
  217. package/examples/jsm/loaders/SVGLoader.js +0 -3172
  218. package/examples/jsm/loaders/TDSLoader.js +0 -1124
  219. package/examples/jsm/loaders/TGALoader.js +0 -517
  220. package/examples/jsm/loaders/TIFFLoader.js +0 -36
  221. package/examples/jsm/loaders/TTFLoader.js +0 -214
  222. package/examples/jsm/loaders/TiltLoader.js +0 -520
  223. package/examples/jsm/loaders/USDZLoader.js +0 -633
  224. package/examples/jsm/loaders/VOXLoader.js +0 -311
  225. package/examples/jsm/loaders/VRMLLoader.js +0 -3533
  226. package/examples/jsm/loaders/VTKLoader.js +0 -1163
  227. package/examples/jsm/loaders/XYZLoader.js +0 -106
  228. package/examples/jsm/loaders/lwo/IFFParser.js +0 -1218
  229. package/examples/jsm/loaders/lwo/LWO2Parser.js +0 -414
  230. package/examples/jsm/loaders/lwo/LWO3Parser.js +0 -373
  231. package/examples/jsm/materials/MeshGouraudMaterial.js +0 -420
  232. package/examples/jsm/math/Capsule.js +0 -137
  233. package/examples/jsm/math/ColorConverter.js +0 -36
  234. package/examples/jsm/math/ConvexHull.js +0 -1271
  235. package/examples/jsm/math/ImprovedNoise.js +0 -71
  236. package/examples/jsm/math/Lut.js +0 -204
  237. package/examples/jsm/math/MeshSurfaceSampler.js +0 -250
  238. package/examples/jsm/math/OBB.js +0 -423
  239. package/examples/jsm/math/Octree.js +0 -462
  240. package/examples/jsm/math/SimplexNoise.js +0 -444
  241. package/examples/jsm/misc/ConvexObjectBreaker.js +0 -519
  242. package/examples/jsm/misc/GPUComputationRenderer.js +0 -446
  243. package/examples/jsm/misc/Gyroscope.js +0 -66
  244. package/examples/jsm/misc/MD2Character.js +0 -276
  245. package/examples/jsm/misc/MD2CharacterComplex.js +0 -576
  246. package/examples/jsm/misc/MorphAnimMesh.js +0 -75
  247. package/examples/jsm/misc/MorphBlendMesh.js +0 -322
  248. package/examples/jsm/misc/ProgressiveLightMap.js +0 -323
  249. package/examples/jsm/misc/RollerCoaster.js +0 -566
  250. package/examples/jsm/misc/TubePainter.js +0 -205
  251. package/examples/jsm/misc/Volume.js +0 -473
  252. package/examples/jsm/misc/VolumeSlice.js +0 -229
  253. package/examples/jsm/modifiers/CurveModifier.js +0 -326
  254. package/examples/jsm/modifiers/EdgeSplitModifier.js +0 -279
  255. package/examples/jsm/modifiers/SimplifyModifier.js +0 -525
  256. package/examples/jsm/modifiers/TessellateModifier.js +0 -307
  257. package/examples/jsm/nodes/Nodes.js +0 -171
  258. package/examples/jsm/nodes/accessors/BitangentNode.js +0 -89
  259. package/examples/jsm/nodes/accessors/BufferAttributeNode.js +0 -99
  260. package/examples/jsm/nodes/accessors/BufferNode.js +0 -30
  261. package/examples/jsm/nodes/accessors/CameraNode.js +0 -98
  262. package/examples/jsm/nodes/accessors/CubeTextureNode.js +0 -103
  263. package/examples/jsm/nodes/accessors/ExtendedMaterialNode.js +0 -77
  264. package/examples/jsm/nodes/accessors/InstanceNode.js +0 -71
  265. package/examples/jsm/nodes/accessors/MaterialNode.js +0 -267
  266. package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +0 -39
  267. package/examples/jsm/nodes/accessors/ModelNode.js +0 -34
  268. package/examples/jsm/nodes/accessors/ModelViewProjectionNode.js +0 -29
  269. package/examples/jsm/nodes/accessors/MorphNode.js +0 -70
  270. package/examples/jsm/nodes/accessors/NormalNode.js +0 -96
  271. package/examples/jsm/nodes/accessors/Object3DNode.js +0 -150
  272. package/examples/jsm/nodes/accessors/PointUVNode.js +0 -26
  273. package/examples/jsm/nodes/accessors/PositionNode.js +0 -104
  274. package/examples/jsm/nodes/accessors/ReferenceNode.js +0 -72
  275. package/examples/jsm/nodes/accessors/ReflectVectorNode.js +0 -35
  276. package/examples/jsm/nodes/accessors/SceneNode.js +0 -52
  277. package/examples/jsm/nodes/accessors/SkinningNode.js +0 -93
  278. package/examples/jsm/nodes/accessors/StorageBufferNode.js +0 -27
  279. package/examples/jsm/nodes/accessors/TangentNode.js +0 -103
  280. package/examples/jsm/nodes/accessors/TextureBicubicNode.js +0 -94
  281. package/examples/jsm/nodes/accessors/TextureNode.js +0 -271
  282. package/examples/jsm/nodes/accessors/TextureSizeNode.js +0 -35
  283. package/examples/jsm/nodes/accessors/UVNode.js +0 -47
  284. package/examples/jsm/nodes/accessors/UserDataNode.js +0 -29
  285. package/examples/jsm/nodes/code/CodeNode.js +0 -78
  286. package/examples/jsm/nodes/code/ExpressionNode.js +0 -37
  287. package/examples/jsm/nodes/code/FunctionCallNode.js +0 -96
  288. package/examples/jsm/nodes/code/FunctionNode.js +0 -127
  289. package/examples/jsm/nodes/code/ScriptableNode.js +0 -488
  290. package/examples/jsm/nodes/code/ScriptableValueNode.js +0 -167
  291. package/examples/jsm/nodes/core/ArrayUniformNode.js +0 -26
  292. package/examples/jsm/nodes/core/AttributeNode.js +0 -102
  293. package/examples/jsm/nodes/core/BypassNode.js +0 -45
  294. package/examples/jsm/nodes/core/CacheNode.js +0 -46
  295. package/examples/jsm/nodes/core/ConstNode.js +0 -32
  296. package/examples/jsm/nodes/core/ContextNode.js +0 -61
  297. package/examples/jsm/nodes/core/IndexNode.js +0 -66
  298. package/examples/jsm/nodes/core/InputNode.js +0 -83
  299. package/examples/jsm/nodes/core/LightingModel.js +0 -15
  300. package/examples/jsm/nodes/core/Node.js +0 -454
  301. package/examples/jsm/nodes/core/NodeAttribute.js +0 -15
  302. package/examples/jsm/nodes/core/NodeBuilder.js +0 -1016
  303. package/examples/jsm/nodes/core/NodeCache.js +0 -26
  304. package/examples/jsm/nodes/core/NodeCode.js +0 -15
  305. package/examples/jsm/nodes/core/NodeFrame.js +0 -110
  306. package/examples/jsm/nodes/core/NodeFunction.js +0 -22
  307. package/examples/jsm/nodes/core/NodeFunctionInput.js +0 -17
  308. package/examples/jsm/nodes/core/NodeKeywords.js +0 -80
  309. package/examples/jsm/nodes/core/NodeParser.js +0 -11
  310. package/examples/jsm/nodes/core/NodeUniform.js +0 -28
  311. package/examples/jsm/nodes/core/NodeUtils.js +0 -212
  312. package/examples/jsm/nodes/core/NodeVar.js +0 -14
  313. package/examples/jsm/nodes/core/NodeVarying.js +0 -17
  314. package/examples/jsm/nodes/core/PropertyNode.js +0 -61
  315. package/examples/jsm/nodes/core/StackNode.js +0 -99
  316. package/examples/jsm/nodes/core/TempNode.js +0 -58
  317. package/examples/jsm/nodes/core/UniformNode.js +0 -61
  318. package/examples/jsm/nodes/core/VarNode.js +0 -87
  319. package/examples/jsm/nodes/core/VaryingNode.js +0 -69
  320. package/examples/jsm/nodes/core/constants.js +0 -27
  321. package/examples/jsm/nodes/display/BlendModeNode.js +0 -99
  322. package/examples/jsm/nodes/display/BumpMapNode.js +0 -77
  323. package/examples/jsm/nodes/display/ColorAdjustmentNode.js +0 -100
  324. package/examples/jsm/nodes/display/ColorSpaceNode.js +0 -108
  325. package/examples/jsm/nodes/display/FrontFacingNode.js +0 -27
  326. package/examples/jsm/nodes/display/NormalMapNode.js +0 -106
  327. package/examples/jsm/nodes/display/PosterizeNode.js +0 -32
  328. package/examples/jsm/nodes/display/ToneMappingNode.js +0 -141
  329. package/examples/jsm/nodes/display/ViewportDepthNode.js +0 -69
  330. package/examples/jsm/nodes/display/ViewportDepthTextureNode.js +0 -34
  331. package/examples/jsm/nodes/display/ViewportNode.js +0 -115
  332. package/examples/jsm/nodes/display/ViewportSharedTextureNode.js +0 -31
  333. package/examples/jsm/nodes/display/ViewportTextureNode.js +0 -75
  334. package/examples/jsm/nodes/fog/FogExp2Node.js +0 -35
  335. package/examples/jsm/nodes/fog/FogNode.js +0 -37
  336. package/examples/jsm/nodes/fog/FogRangeNode.js +0 -34
  337. package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +0 -40
  338. package/examples/jsm/nodes/functions/BSDF/BRDF_Lambert.js +0 -9
  339. package/examples/jsm/nodes/functions/BSDF/BRDF_Sheen.js +0 -43
  340. package/examples/jsm/nodes/functions/BSDF/DFGApprox.js +0 -29
  341. package/examples/jsm/nodes/functions/BSDF/D_GGX.js +0 -18
  342. package/examples/jsm/nodes/functions/BSDF/EnvironmentBRDF.js +0 -13
  343. package/examples/jsm/nodes/functions/BSDF/F_Schlick.js +0 -16
  344. package/examples/jsm/nodes/functions/BSDF/Schlick_to_F0.js +0 -13
  345. package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +0 -20
  346. package/examples/jsm/nodes/functions/PhongLightingModel.js +0 -67
  347. package/examples/jsm/nodes/functions/PhysicalLightingModel.js +0 -343
  348. package/examples/jsm/nodes/functions/material/getGeometryRoughness.js +0 -13
  349. package/examples/jsm/nodes/functions/material/getRoughness.js +0 -18
  350. package/examples/jsm/nodes/geometry/RangeNode.js +0 -104
  351. package/examples/jsm/nodes/gpgpu/ComputeNode.js +0 -85
  352. package/examples/jsm/nodes/lighting/AONode.js +0 -27
  353. package/examples/jsm/nodes/lighting/AmbientLightNode.js +0 -27
  354. package/examples/jsm/nodes/lighting/AnalyticLightNode.js +0 -184
  355. package/examples/jsm/nodes/lighting/DirectionalLightNode.js +0 -40
  356. package/examples/jsm/nodes/lighting/EnvironmentNode.js +0 -191
  357. package/examples/jsm/nodes/lighting/HemisphereLightNode.js +0 -55
  358. package/examples/jsm/nodes/lighting/IESSpotLightNode.js +0 -39
  359. package/examples/jsm/nodes/lighting/LightNode.js +0 -57
  360. package/examples/jsm/nodes/lighting/LightUtils.js +0 -17
  361. package/examples/jsm/nodes/lighting/LightingContextNode.js +0 -102
  362. package/examples/jsm/nodes/lighting/LightingNode.js +0 -21
  363. package/examples/jsm/nodes/lighting/LightsNode.js +0 -128
  364. package/examples/jsm/nodes/lighting/PointLightNode.js +0 -68
  365. package/examples/jsm/nodes/lighting/SpotLightNode.js +0 -89
  366. package/examples/jsm/nodes/loaders/NodeLoader.js +0 -108
  367. package/examples/jsm/nodes/loaders/NodeMaterialLoader.js +0 -59
  368. package/examples/jsm/nodes/loaders/NodeObjectLoader.js +0 -70
  369. package/examples/jsm/nodes/materials/LineBasicNodeMaterial.js +0 -28
  370. package/examples/jsm/nodes/materials/Materials.js +0 -12
  371. package/examples/jsm/nodes/materials/MeshBasicNodeMaterial.js +0 -27
  372. package/examples/jsm/nodes/materials/MeshLambertNodeMaterial.js +0 -34
  373. package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +0 -40
  374. package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +0 -65
  375. package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +0 -128
  376. package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +0 -80
  377. package/examples/jsm/nodes/materials/NodeMaterial.js +0 -536
  378. package/examples/jsm/nodes/materials/PointsNodeMaterial.js +0 -49
  379. package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +0 -103
  380. package/examples/jsm/nodes/materialx/DISCLAIMER.md +0 -199
  381. package/examples/jsm/nodes/materialx/MaterialXNodes.js +0 -68
  382. package/examples/jsm/nodes/materialx/lib/mx_hsv.js +0 -56
  383. package/examples/jsm/nodes/materialx/lib/mx_noise.js +0 -618
  384. package/examples/jsm/nodes/materialx/lib/mx_transform_color.js +0 -19
  385. package/examples/jsm/nodes/math/CondNode.js +0 -86
  386. package/examples/jsm/nodes/math/MathNode.js +0 -359
  387. package/examples/jsm/nodes/math/OperatorNode.js +0 -269
  388. package/examples/jsm/nodes/parsers/GLSLNodeFunction.js +0 -152
  389. package/examples/jsm/nodes/parsers/GLSLNodeParser.js +0 -14
  390. package/examples/jsm/nodes/procedural/CheckerNode.js +0 -42
  391. package/examples/jsm/nodes/shadernode/ShaderNode.js +0 -420
  392. package/examples/jsm/nodes/utils/ArrayElementNode.js +0 -33
  393. package/examples/jsm/nodes/utils/ConvertNode.js +0 -65
  394. package/examples/jsm/nodes/utils/DiscardNode.js +0 -26
  395. package/examples/jsm/nodes/utils/EquirectUVNode.js +0 -33
  396. package/examples/jsm/nodes/utils/JoinNode.js +0 -51
  397. package/examples/jsm/nodes/utils/LoopNode.js +0 -186
  398. package/examples/jsm/nodes/utils/MatcapUVNode.js +0 -30
  399. package/examples/jsm/nodes/utils/MaxMipLevelNode.js +0 -46
  400. package/examples/jsm/nodes/utils/OscNode.js +0 -81
  401. package/examples/jsm/nodes/utils/PackingNode.js +0 -55
  402. package/examples/jsm/nodes/utils/RemapNode.js +0 -42
  403. package/examples/jsm/nodes/utils/RotateUVNode.js +0 -43
  404. package/examples/jsm/nodes/utils/SpecularMIPLevelNode.js +0 -37
  405. package/examples/jsm/nodes/utils/SplitNode.js +0 -104
  406. package/examples/jsm/nodes/utils/SpriteSheetUVNode.js +0 -41
  407. package/examples/jsm/nodes/utils/TimerNode.js +0 -94
  408. package/examples/jsm/nodes/utils/TriplanarTexturesNode.js +0 -62
  409. package/examples/jsm/objects/GroundProjectedSkybox.js +0 -172
  410. package/examples/jsm/objects/Lensflare.js +0 -377
  411. package/examples/jsm/objects/MarchingCubes.js +0 -1176
  412. package/examples/jsm/objects/Reflector.js +0 -264
  413. package/examples/jsm/objects/ReflectorForSSRPass.js +0 -349
  414. package/examples/jsm/objects/Refractor.js +0 -324
  415. package/examples/jsm/objects/ShadowMesh.js +0 -80
  416. package/examples/jsm/objects/Sky.js +0 -219
  417. package/examples/jsm/objects/Water.js +0 -330
  418. package/examples/jsm/objects/Water2.js +0 -358
  419. package/examples/jsm/offscreen/jank.js +0 -45
  420. package/examples/jsm/offscreen/offscreen.js +0 -8
  421. package/examples/jsm/offscreen/scene.js +0 -86
  422. package/examples/jsm/physics/AmmoPhysics.js +0 -285
  423. package/examples/jsm/physics/RapierPhysics.js +0 -199
  424. package/examples/jsm/postprocessing/AfterimagePass.js +0 -104
  425. package/examples/jsm/postprocessing/BloomPass.js +0 -172
  426. package/examples/jsm/postprocessing/BokehPass.js +0 -140
  427. package/examples/jsm/postprocessing/ClearPass.js +0 -46
  428. package/examples/jsm/postprocessing/CubeTexturePass.js +0 -85
  429. package/examples/jsm/postprocessing/DotScreenPass.js +0 -65
  430. package/examples/jsm/postprocessing/EffectComposer.js +0 -231
  431. package/examples/jsm/postprocessing/FilmPass.js +0 -66
  432. package/examples/jsm/postprocessing/GlitchPass.js +0 -128
  433. package/examples/jsm/postprocessing/HalftonePass.js +0 -79
  434. package/examples/jsm/postprocessing/LUTPass.js +0 -173
  435. package/examples/jsm/postprocessing/MaskPass.js +0 -104
  436. package/examples/jsm/postprocessing/OutlinePass.js +0 -654
  437. package/examples/jsm/postprocessing/OutputPass.js +0 -91
  438. package/examples/jsm/postprocessing/Pass.js +0 -84
  439. package/examples/jsm/postprocessing/RenderPass.js +0 -81
  440. package/examples/jsm/postprocessing/RenderPixelatedPass.js +0 -235
  441. package/examples/jsm/postprocessing/SAOPass.js +0 -411
  442. package/examples/jsm/postprocessing/SMAAPass.js +0 -201
  443. package/examples/jsm/postprocessing/SSAARenderPass.js +0 -228
  444. package/examples/jsm/postprocessing/SSAOPass.js +0 -440
  445. package/examples/jsm/postprocessing/SSRPass.js +0 -641
  446. package/examples/jsm/postprocessing/SavePass.js +0 -79
  447. package/examples/jsm/postprocessing/ShaderPass.js +0 -77
  448. package/examples/jsm/postprocessing/TAARenderPass.js +0 -189
  449. package/examples/jsm/postprocessing/TexturePass.js +0 -67
  450. package/examples/jsm/postprocessing/UnrealBloomPass.js +0 -415
  451. package/examples/jsm/renderers/CSS2DRenderer.js +0 -215
  452. package/examples/jsm/renderers/CSS3DRenderer.js +0 -335
  453. package/examples/jsm/renderers/Projector.js +0 -918
  454. package/examples/jsm/renderers/SVGRenderer.js +0 -553
  455. package/examples/jsm/renderers/common/Animation.js +0 -58
  456. package/examples/jsm/renderers/common/Attributes.js +0 -75
  457. package/examples/jsm/renderers/common/Backend.js +0 -162
  458. package/examples/jsm/renderers/common/Background.js +0 -136
  459. package/examples/jsm/renderers/common/Binding.js +0 -19
  460. package/examples/jsm/renderers/common/Bindings.js +0 -165
  461. package/examples/jsm/renderers/common/Buffer.js +0 -38
  462. package/examples/jsm/renderers/common/BufferUtils.js +0 -33
  463. package/examples/jsm/renderers/common/ChainMap.js +0 -89
  464. package/examples/jsm/renderers/common/ComputePipeline.js +0 -17
  465. package/examples/jsm/renderers/common/Constants.js +0 -14
  466. package/examples/jsm/renderers/common/CubeRenderTarget.js +0 -65
  467. package/examples/jsm/renderers/common/DataMap.js +0 -54
  468. package/examples/jsm/renderers/common/Geometries.js +0 -215
  469. package/examples/jsm/renderers/common/Info.js +0 -73
  470. package/examples/jsm/renderers/common/Pipeline.js +0 -13
  471. package/examples/jsm/renderers/common/Pipelines.js +0 -370
  472. package/examples/jsm/renderers/common/ProgrammableStage.js +0 -18
  473. package/examples/jsm/renderers/common/RenderContext.js +0 -38
  474. package/examples/jsm/renderers/common/RenderContexts.js +0 -49
  475. package/examples/jsm/renderers/common/RenderList.js +0 -178
  476. package/examples/jsm/renderers/common/RenderLists.js +0 -38
  477. package/examples/jsm/renderers/common/RenderObject.js +0 -129
  478. package/examples/jsm/renderers/common/RenderObjects.js +0 -95
  479. package/examples/jsm/renderers/common/RenderPipeline.js +0 -16
  480. package/examples/jsm/renderers/common/Renderer.js +0 -895
  481. package/examples/jsm/renderers/common/SampledTexture.js +0 -80
  482. package/examples/jsm/renderers/common/Sampler.js +0 -18
  483. package/examples/jsm/renderers/common/StorageBuffer.js +0 -17
  484. package/examples/jsm/renderers/common/Textures.js +0 -218
  485. package/examples/jsm/renderers/common/Uniform.js +0 -140
  486. package/examples/jsm/renderers/common/UniformBuffer.js +0 -15
  487. package/examples/jsm/renderers/common/UniformsGroup.js +0 -299
  488. package/examples/jsm/renderers/common/nodes/NodeSampledTexture.js +0 -39
  489. package/examples/jsm/renderers/common/nodes/NodeSampler.js +0 -21
  490. package/examples/jsm/renderers/common/nodes/NodeUniform.js +0 -135
  491. package/examples/jsm/renderers/common/nodes/Nodes.js +0 -330
  492. package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +0 -340
  493. package/examples/jsm/renderers/webgl/nodes/SlotNode.js +0 -26
  494. package/examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js +0 -764
  495. package/examples/jsm/renderers/webgl/nodes/WebGLNodes.js +0 -49
  496. package/examples/jsm/renderers/webgpu/WebGPUBackend.js +0 -844
  497. package/examples/jsm/renderers/webgpu/WebGPURenderer.js +0 -32
  498. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +0 -902
  499. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeFunction.js +0 -104
  500. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeParser.js +0 -14
  501. package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +0 -274
  502. package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +0 -223
  503. package/examples/jsm/renderers/webgpu/utils/WebGPUConstants.js +0 -324
  504. package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +0 -533
  505. package/examples/jsm/renderers/webgpu/utils/WebGPUTextureMipmapUtils.js +0 -163
  506. package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +0 -964
  507. package/examples/jsm/renderers/webgpu/utils/WebGPUUtils.js +0 -92
  508. package/examples/jsm/shaders/ACESFilmicToneMappingShader.js +0 -87
  509. package/examples/jsm/shaders/AfterimageShader.js +0 -56
  510. package/examples/jsm/shaders/BasicShader.js +0 -27
  511. package/examples/jsm/shaders/BleachBypassShader.js +0 -62
  512. package/examples/jsm/shaders/BlendShader.js +0 -47
  513. package/examples/jsm/shaders/BokehShader.js +0 -143
  514. package/examples/jsm/shaders/BokehShader2.js +0 -393
  515. package/examples/jsm/shaders/BrightnessContrastShader.js +0 -54
  516. package/examples/jsm/shaders/ColorCorrectionShader.js +0 -50
  517. package/examples/jsm/shaders/ColorifyShader.js +0 -51
  518. package/examples/jsm/shaders/ConvolutionShader.js +0 -103
  519. package/examples/jsm/shaders/CopyShader.js +0 -45
  520. package/examples/jsm/shaders/DOFMipMapShader.js +0 -54
  521. package/examples/jsm/shaders/DepthLimitedBlurShader.js +0 -166
  522. package/examples/jsm/shaders/DigitalGlitch.js +0 -101
  523. package/examples/jsm/shaders/DotScreenShader.js +0 -70
  524. package/examples/jsm/shaders/ExposureShader.js +0 -44
  525. package/examples/jsm/shaders/FXAAShader.js +0 -286
  526. package/examples/jsm/shaders/FilmShader.js +0 -102
  527. package/examples/jsm/shaders/FocusShader.js +0 -87
  528. package/examples/jsm/shaders/FreiChenShader.js +0 -94
  529. package/examples/jsm/shaders/GammaCorrectionShader.js +0 -43
  530. package/examples/jsm/shaders/GodRaysShader.js +0 -313
  531. package/examples/jsm/shaders/HalftoneShader.js +0 -310
  532. package/examples/jsm/shaders/HorizontalBlurShader.js +0 -59
  533. package/examples/jsm/shaders/HorizontalTiltShiftShader.js +0 -61
  534. package/examples/jsm/shaders/HueSaturationShader.js +0 -65
  535. package/examples/jsm/shaders/KaleidoShader.js +0 -56
  536. package/examples/jsm/shaders/LuminosityHighPassShader.js +0 -64
  537. package/examples/jsm/shaders/LuminosityShader.js +0 -46
  538. package/examples/jsm/shaders/MMDToonShader.js +0 -132
  539. package/examples/jsm/shaders/MirrorShader.js +0 -54
  540. package/examples/jsm/shaders/NormalMapShader.js +0 -53
  541. package/examples/jsm/shaders/OutputShader.js +0 -78
  542. package/examples/jsm/shaders/RGBShiftShader.js +0 -54
  543. package/examples/jsm/shaders/SAOShader.js +0 -188
  544. package/examples/jsm/shaders/SMAAShader.js +0 -460
  545. package/examples/jsm/shaders/SSAOShader.js +0 -288
  546. package/examples/jsm/shaders/SSRShader.js +0 -364
  547. package/examples/jsm/shaders/SepiaShader.js +0 -52
  548. package/examples/jsm/shaders/SobelOperatorShader.js +0 -90
  549. package/examples/jsm/shaders/SubsurfaceScatteringShader.js +0 -88
  550. package/examples/jsm/shaders/TechnicolorShader.js +0 -43
  551. package/examples/jsm/shaders/ToonShader.js +0 -326
  552. package/examples/jsm/shaders/TriangleBlurShader.js +0 -72
  553. package/examples/jsm/shaders/UnpackDepthRGBAShader.js +0 -45
  554. package/examples/jsm/shaders/VelocityShader.js +0 -128
  555. package/examples/jsm/shaders/VerticalBlurShader.js +0 -59
  556. package/examples/jsm/shaders/VerticalTiltShiftShader.js +0 -61
  557. package/examples/jsm/shaders/VignetteShader.js +0 -51
  558. package/examples/jsm/shaders/VolumeShader.js +0 -289
  559. package/examples/jsm/shaders/WaterRefractionShader.js +0 -93
  560. package/examples/jsm/textures/FlakesTexture.js +0 -40
  561. package/examples/jsm/utils/BufferGeometryUtils.js +0 -1373
  562. package/examples/jsm/utils/CameraUtils.js +0 -73
  563. package/examples/jsm/utils/GPUStatsPanel.js +0 -128
  564. package/examples/jsm/utils/GeometryCompressionUtils.js +0 -639
  565. package/examples/jsm/utils/GeometryUtils.js +0 -221
  566. package/examples/jsm/utils/LDrawUtils.js +0 -202
  567. package/examples/jsm/utils/PackedPhongMaterial.js +0 -178
  568. package/examples/jsm/utils/SceneUtils.js +0 -254
  569. package/examples/jsm/utils/ShadowMapViewer.js +0 -210
  570. package/examples/jsm/utils/SkeletonUtils.js +0 -413
  571. package/examples/jsm/utils/TextureUtils.js +0 -86
  572. package/examples/jsm/utils/UVsDebug.js +0 -165
  573. package/examples/jsm/utils/WorkerPool.js +0 -102
  574. package/examples/jsm/webxr/ARButton.js +0 -208
  575. package/examples/jsm/webxr/OculusHandModel.js +0 -109
  576. package/examples/jsm/webxr/OculusHandPointerModel.js +0 -413
  577. package/examples/jsm/webxr/Text2D.js +0 -38
  578. package/examples/jsm/webxr/VRButton.js +0 -200
  579. package/examples/jsm/webxr/XRButton.js +0 -198
  580. package/examples/jsm/webxr/XRControllerModelFactory.js +0 -299
  581. package/examples/jsm/webxr/XREstimatedLight.js +0 -223
  582. package/examples/jsm/webxr/XRHandMeshModel.js +0 -112
  583. package/examples/jsm/webxr/XRHandModelFactory.js +0 -105
  584. package/examples/jsm/webxr/XRHandPrimitiveModel.js +0 -103
  585. package/examples/jsm/webxr/XRPlanes.js +0 -100
  586. package/lib/3d.min.js +0 -1
@@ -1,4576 +0,0 @@
1
- import {
2
- AnimationClip,
3
- Bone,
4
- Box3,
5
- BufferAttribute,
6
- BufferGeometry,
7
- ClampToEdgeWrapping,
8
- Color,
9
- DirectionalLight,
10
- DoubleSide,
11
- FileLoader,
12
- FrontSide,
13
- Group,
14
- ImageBitmapLoader,
15
- InstancedMesh,
16
- InterleavedBuffer,
17
- InterleavedBufferAttribute,
18
- Interpolant,
19
- InterpolateDiscrete,
20
- InterpolateLinear,
21
- Line,
22
- LineBasicMaterial,
23
- LineLoop,
24
- LineSegments,
25
- LinearFilter,
26
- LinearMipmapLinearFilter,
27
- LinearMipmapNearestFilter,
28
- Loader,
29
- LoaderUtils,
30
- Material,
31
- MathUtils,
32
- Matrix4,
33
- Mesh,
34
- MeshBasicMaterial,
35
- MeshPhysicalMaterial,
36
- MeshStandardMaterial,
37
- MirroredRepeatWrapping,
38
- NearestFilter,
39
- NearestMipmapLinearFilter,
40
- NearestMipmapNearestFilter,
41
- NumberKeyframeTrack,
42
- Object3D,
43
- OrthographicCamera,
44
- PerspectiveCamera,
45
- PointLight,
46
- Points,
47
- PointsMaterial,
48
- PropertyBinding,
49
- Quaternion,
50
- QuaternionKeyframeTrack,
51
- RepeatWrapping,
52
- Skeleton,
53
- SkinnedMesh,
54
- Sphere,
55
- SpotLight,
56
- Texture,
57
- TextureLoader,
58
- TriangleFanDrawMode,
59
- TriangleStripDrawMode,
60
- Vector2,
61
- Vector3,
62
- VectorKeyframeTrack,
63
- SRGBColorSpace
64
- } from 'three';
65
- import { toTrianglesDrawMode } from '../utils/BufferGeometryUtils.js';
66
-
67
- class GLTFLoader extends Loader {
68
-
69
- constructor( manager ) {
70
-
71
- super( manager );
72
-
73
- this.dracoLoader = null;
74
- this.ktx2Loader = null;
75
- this.meshoptDecoder = null;
76
-
77
- this.pluginCallbacks = [];
78
-
79
- this.register( function ( parser ) {
80
-
81
- return new GLTFMaterialsClearcoatExtension( parser );
82
-
83
- } );
84
-
85
- this.register( function ( parser ) {
86
-
87
- return new GLTFTextureBasisUExtension( parser );
88
-
89
- } );
90
-
91
- this.register( function ( parser ) {
92
-
93
- return new GLTFTextureWebPExtension( parser );
94
-
95
- } );
96
-
97
- this.register( function ( parser ) {
98
-
99
- return new GLTFTextureAVIFExtension( parser );
100
-
101
- } );
102
-
103
- this.register( function ( parser ) {
104
-
105
- return new GLTFMaterialsSheenExtension( parser );
106
-
107
- } );
108
-
109
- this.register( function ( parser ) {
110
-
111
- return new GLTFMaterialsTransmissionExtension( parser );
112
-
113
- } );
114
-
115
- this.register( function ( parser ) {
116
-
117
- return new GLTFMaterialsVolumeExtension( parser );
118
-
119
- } );
120
-
121
- this.register( function ( parser ) {
122
-
123
- return new GLTFMaterialsIorExtension( parser );
124
-
125
- } );
126
-
127
- this.register( function ( parser ) {
128
-
129
- return new GLTFMaterialsEmissiveStrengthExtension( parser );
130
-
131
- } );
132
-
133
- this.register( function ( parser ) {
134
-
135
- return new GLTFMaterialsSpecularExtension( parser );
136
-
137
- } );
138
-
139
- this.register( function ( parser ) {
140
-
141
- return new GLTFMaterialsIridescenceExtension( parser );
142
-
143
- } );
144
-
145
- this.register( function ( parser ) {
146
-
147
- return new GLTFMaterialsAnisotropyExtension( parser );
148
-
149
- } );
150
-
151
- this.register( function ( parser ) {
152
-
153
- return new GLTFLightsExtension( parser );
154
-
155
- } );
156
-
157
- this.register( function ( parser ) {
158
-
159
- return new GLTFMeshoptCompression( parser );
160
-
161
- } );
162
-
163
- this.register( function ( parser ) {
164
-
165
- return new GLTFMeshGpuInstancing( parser );
166
-
167
- } );
168
-
169
- }
170
-
171
- load( url, onLoad, onProgress, onError ) {
172
-
173
- const scope = this;
174
-
175
- let resourcePath;
176
-
177
- if ( this.resourcePath !== '' ) {
178
-
179
- resourcePath = this.resourcePath;
180
-
181
- } else if ( this.path !== '' ) {
182
-
183
- resourcePath = this.path;
184
-
185
- } else {
186
-
187
- resourcePath = LoaderUtils.extractUrlBase( url );
188
-
189
- }
190
-
191
- // Tells the LoadingManager to track an extra item, which resolves after
192
- // the model is fully loaded. This means the count of items loaded will
193
- // be incorrect, but ensures manager.onLoad() does not fire early.
194
- this.manager.itemStart( url );
195
-
196
- const _onError = function ( e ) {
197
-
198
- if ( onError ) {
199
-
200
- onError( e );
201
-
202
- } else {
203
-
204
- console.error( e );
205
-
206
- }
207
-
208
- scope.manager.itemError( url );
209
- scope.manager.itemEnd( url );
210
-
211
- };
212
-
213
- const loader = new FileLoader( this.manager );
214
-
215
- loader.setPath( this.path );
216
- loader.setResponseType( 'arraybuffer' );
217
- loader.setRequestHeader( this.requestHeader );
218
- loader.setWithCredentials( this.withCredentials );
219
-
220
- loader.load( url, function ( data ) {
221
-
222
- try {
223
-
224
- scope.parse( data, resourcePath, function ( gltf ) {
225
-
226
- onLoad( gltf );
227
-
228
- scope.manager.itemEnd( url );
229
-
230
- }, _onError );
231
-
232
- } catch ( e ) {
233
-
234
- _onError( e );
235
-
236
- }
237
-
238
- }, onProgress, _onError );
239
-
240
- }
241
-
242
- setDRACOLoader( dracoLoader ) {
243
-
244
- this.dracoLoader = dracoLoader;
245
- return this;
246
-
247
- }
248
-
249
- setDDSLoader() {
250
-
251
- throw new Error(
252
-
253
- 'THREE.GLTFLoader: "MSFT_texture_dds" no longer supported. Please update to "KHR_texture_basisu".'
254
-
255
- );
256
-
257
- }
258
-
259
- setKTX2Loader( ktx2Loader ) {
260
-
261
- this.ktx2Loader = ktx2Loader;
262
- return this;
263
-
264
- }
265
-
266
- setMeshoptDecoder( meshoptDecoder ) {
267
-
268
- this.meshoptDecoder = meshoptDecoder;
269
- return this;
270
-
271
- }
272
-
273
- register( callback ) {
274
-
275
- if ( this.pluginCallbacks.indexOf( callback ) === - 1 ) {
276
-
277
- this.pluginCallbacks.push( callback );
278
-
279
- }
280
-
281
- return this;
282
-
283
- }
284
-
285
- unregister( callback ) {
286
-
287
- if ( this.pluginCallbacks.indexOf( callback ) !== - 1 ) {
288
-
289
- this.pluginCallbacks.splice( this.pluginCallbacks.indexOf( callback ), 1 );
290
-
291
- }
292
-
293
- return this;
294
-
295
- }
296
-
297
- parse( data, path, onLoad, onError ) {
298
-
299
- let json;
300
- const extensions = {};
301
- const plugins = {};
302
- const textDecoder = new TextDecoder();
303
-
304
- if ( typeof data === 'string' ) {
305
-
306
- json = JSON.parse( data );
307
-
308
- } else if ( data instanceof ArrayBuffer ) {
309
-
310
- const magic = textDecoder.decode( new Uint8Array( data, 0, 4 ) );
311
-
312
- if ( magic === BINARY_EXTENSION_HEADER_MAGIC ) {
313
-
314
- try {
315
-
316
- extensions[ EXTENSIONS.KHR_BINARY_GLTF ] = new GLTFBinaryExtension( data );
317
-
318
- } catch ( error ) {
319
-
320
- if ( onError ) onError( error );
321
- return;
322
-
323
- }
324
-
325
- json = JSON.parse( extensions[ EXTENSIONS.KHR_BINARY_GLTF ].content );
326
-
327
- } else {
328
-
329
- json = JSON.parse( textDecoder.decode( data ) );
330
-
331
- }
332
-
333
- } else {
334
-
335
- json = data;
336
-
337
- }
338
-
339
- if ( json.asset === undefined || json.asset.version[ 0 ] < 2 ) {
340
-
341
- if ( onError ) onError( new Error( 'THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.' ) );
342
- return;
343
-
344
- }
345
-
346
- const parser = new GLTFParser( json, {
347
-
348
- path: path || this.resourcePath || '',
349
- crossOrigin: this.crossOrigin,
350
- requestHeader: this.requestHeader,
351
- manager: this.manager,
352
- ktx2Loader: this.ktx2Loader,
353
- meshoptDecoder: this.meshoptDecoder
354
-
355
- } );
356
-
357
- parser.fileLoader.setRequestHeader( this.requestHeader );
358
-
359
- for ( let i = 0; i < this.pluginCallbacks.length; i ++ ) {
360
-
361
- const plugin = this.pluginCallbacks[ i ]( parser );
362
- plugins[ plugin.name ] = plugin;
363
-
364
- // Workaround to avoid determining as unknown extension
365
- // in addUnknownExtensionsToUserData().
366
- // Remove this workaround if we move all the existing
367
- // extension handlers to plugin system
368
- extensions[ plugin.name ] = true;
369
-
370
- }
371
-
372
- if ( json.extensionsUsed ) {
373
-
374
- for ( let i = 0; i < json.extensionsUsed.length; ++ i ) {
375
-
376
- const extensionName = json.extensionsUsed[ i ];
377
- const extensionsRequired = json.extensionsRequired || [];
378
-
379
- switch ( extensionName ) {
380
-
381
- case EXTENSIONS.KHR_MATERIALS_UNLIT:
382
- extensions[ extensionName ] = new GLTFMaterialsUnlitExtension();
383
- break;
384
-
385
- case EXTENSIONS.KHR_DRACO_MESH_COMPRESSION:
386
- extensions[ extensionName ] = new GLTFDracoMeshCompressionExtension( json, this.dracoLoader );
387
- break;
388
-
389
- case EXTENSIONS.KHR_TEXTURE_TRANSFORM:
390
- extensions[ extensionName ] = new GLTFTextureTransformExtension();
391
- break;
392
-
393
- case EXTENSIONS.KHR_MESH_QUANTIZATION:
394
- extensions[ extensionName ] = new GLTFMeshQuantizationExtension();
395
- break;
396
-
397
- default:
398
-
399
- if ( extensionsRequired.indexOf( extensionName ) >= 0 && plugins[ extensionName ] === undefined ) {
400
-
401
- console.warn( 'THREE.GLTFLoader: Unknown extension "' + extensionName + '".' );
402
-
403
- }
404
-
405
- }
406
-
407
- }
408
-
409
- }
410
-
411
- parser.setExtensions( extensions );
412
- parser.setPlugins( plugins );
413
- parser.parse( onLoad, onError );
414
-
415
- }
416
-
417
- parseAsync( data, path ) {
418
-
419
- const scope = this;
420
-
421
- return new Promise( function ( resolve, reject ) {
422
-
423
- scope.parse( data, path, resolve, reject );
424
-
425
- } );
426
-
427
- }
428
-
429
- }
430
-
431
- /* GLTFREGISTRY */
432
-
433
- function GLTFRegistry() {
434
-
435
- let objects = {};
436
-
437
- return {
438
-
439
- get: function ( key ) {
440
-
441
- return objects[ key ];
442
-
443
- },
444
-
445
- add: function ( key, object ) {
446
-
447
- objects[ key ] = object;
448
-
449
- },
450
-
451
- remove: function ( key ) {
452
-
453
- delete objects[ key ];
454
-
455
- },
456
-
457
- removeAll: function () {
458
-
459
- objects = {};
460
-
461
- }
462
-
463
- };
464
-
465
- }
466
-
467
- /*********************************/
468
- /********** EXTENSIONS ***********/
469
- /*********************************/
470
-
471
- const EXTENSIONS = {
472
- KHR_BINARY_GLTF: 'KHR_binary_glTF',
473
- KHR_DRACO_MESH_COMPRESSION: 'KHR_draco_mesh_compression',
474
- KHR_LIGHTS_PUNCTUAL: 'KHR_lights_punctual',
475
- KHR_MATERIALS_CLEARCOAT: 'KHR_materials_clearcoat',
476
- KHR_MATERIALS_IOR: 'KHR_materials_ior',
477
- KHR_MATERIALS_SHEEN: 'KHR_materials_sheen',
478
- KHR_MATERIALS_SPECULAR: 'KHR_materials_specular',
479
- KHR_MATERIALS_TRANSMISSION: 'KHR_materials_transmission',
480
- KHR_MATERIALS_IRIDESCENCE: 'KHR_materials_iridescence',
481
- KHR_MATERIALS_ANISOTROPY: 'KHR_materials_anisotropy',
482
- KHR_MATERIALS_UNLIT: 'KHR_materials_unlit',
483
- KHR_MATERIALS_VOLUME: 'KHR_materials_volume',
484
- KHR_TEXTURE_BASISU: 'KHR_texture_basisu',
485
- KHR_TEXTURE_TRANSFORM: 'KHR_texture_transform',
486
- KHR_MESH_QUANTIZATION: 'KHR_mesh_quantization',
487
- KHR_MATERIALS_EMISSIVE_STRENGTH: 'KHR_materials_emissive_strength',
488
- EXT_TEXTURE_WEBP: 'EXT_texture_webp',
489
- EXT_TEXTURE_AVIF: 'EXT_texture_avif',
490
- EXT_MESHOPT_COMPRESSION: 'EXT_meshopt_compression',
491
- EXT_MESH_GPU_INSTANCING: 'EXT_mesh_gpu_instancing'
492
- };
493
-
494
- /**
495
- * Punctual Lights Extension
496
- *
497
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual
498
- */
499
- class GLTFLightsExtension {
500
-
501
- constructor( parser ) {
502
-
503
- this.parser = parser;
504
- this.name = EXTENSIONS.KHR_LIGHTS_PUNCTUAL;
505
-
506
- // Object3D instance caches
507
- this.cache = { refs: {}, uses: {} };
508
-
509
- }
510
-
511
- _markDefs() {
512
-
513
- const parser = this.parser;
514
- const nodeDefs = this.parser.json.nodes || [];
515
-
516
- for ( let nodeIndex = 0, nodeLength = nodeDefs.length; nodeIndex < nodeLength; nodeIndex ++ ) {
517
-
518
- const nodeDef = nodeDefs[ nodeIndex ];
519
-
520
- if ( nodeDef.extensions
521
- && nodeDef.extensions[ this.name ]
522
- && nodeDef.extensions[ this.name ].light !== undefined ) {
523
-
524
- parser._addNodeRef( this.cache, nodeDef.extensions[ this.name ].light );
525
-
526
- }
527
-
528
- }
529
-
530
- }
531
-
532
- _loadLight( lightIndex ) {
533
-
534
- const parser = this.parser;
535
- const cacheKey = 'light:' + lightIndex;
536
- let dependency = parser.cache.get( cacheKey );
537
-
538
- if ( dependency ) return dependency;
539
-
540
- const json = parser.json;
541
- const extensions = ( json.extensions && json.extensions[ this.name ] ) || {};
542
- const lightDefs = extensions.lights || [];
543
- const lightDef = lightDefs[ lightIndex ];
544
- let lightNode;
545
-
546
- const color = new Color( 0xffffff );
547
-
548
- if ( lightDef.color !== undefined ) color.fromArray( lightDef.color );
549
-
550
- const range = lightDef.range !== undefined ? lightDef.range : 0;
551
-
552
- switch ( lightDef.type ) {
553
-
554
- case 'directional':
555
- lightNode = new DirectionalLight( color );
556
- lightNode.target.position.set( 0, 0, - 1 );
557
- lightNode.add( lightNode.target );
558
- break;
559
-
560
- case 'point':
561
- lightNode = new PointLight( color );
562
- lightNode.distance = range;
563
- break;
564
-
565
- case 'spot':
566
- lightNode = new SpotLight( color );
567
- lightNode.distance = range;
568
- // Handle spotlight properties.
569
- lightDef.spot = lightDef.spot || {};
570
- lightDef.spot.innerConeAngle = lightDef.spot.innerConeAngle !== undefined ? lightDef.spot.innerConeAngle : 0;
571
- lightDef.spot.outerConeAngle = lightDef.spot.outerConeAngle !== undefined ? lightDef.spot.outerConeAngle : Math.PI / 4.0;
572
- lightNode.angle = lightDef.spot.outerConeAngle;
573
- lightNode.penumbra = 1.0 - lightDef.spot.innerConeAngle / lightDef.spot.outerConeAngle;
574
- lightNode.target.position.set( 0, 0, - 1 );
575
- lightNode.add( lightNode.target );
576
- break;
577
-
578
- default:
579
- throw new Error( 'THREE.GLTFLoader: Unexpected light type: ' + lightDef.type );
580
-
581
- }
582
-
583
- // Some lights (e.g. spot) default to a position other than the origin. Reset the position
584
- // here, because node-level parsing will only override position if explicitly specified.
585
- lightNode.position.set( 0, 0, 0 );
586
-
587
- lightNode.decay = 2;
588
-
589
- assignExtrasToUserData( lightNode, lightDef );
590
-
591
- if ( lightDef.intensity !== undefined ) lightNode.intensity = lightDef.intensity;
592
-
593
- lightNode.name = parser.createUniqueName( lightDef.name || ( 'light_' + lightIndex ) );
594
-
595
- dependency = Promise.resolve( lightNode );
596
-
597
- parser.cache.add( cacheKey, dependency );
598
-
599
- return dependency;
600
-
601
- }
602
-
603
- getDependency( type, index ) {
604
-
605
- if ( type !== 'light' ) return;
606
-
607
- return this._loadLight( index );
608
-
609
- }
610
-
611
- createNodeAttachment( nodeIndex ) {
612
-
613
- const self = this;
614
- const parser = this.parser;
615
- const json = parser.json;
616
- const nodeDef = json.nodes[ nodeIndex ];
617
- const lightDef = ( nodeDef.extensions && nodeDef.extensions[ this.name ] ) || {};
618
- const lightIndex = lightDef.light;
619
-
620
- if ( lightIndex === undefined ) return null;
621
-
622
- return this._loadLight( lightIndex ).then( function ( light ) {
623
-
624
- return parser._getNodeRef( self.cache, lightIndex, light );
625
-
626
- } );
627
-
628
- }
629
-
630
- }
631
-
632
- /**
633
- * Unlit Materials Extension
634
- *
635
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit
636
- */
637
- class GLTFMaterialsUnlitExtension {
638
-
639
- constructor() {
640
-
641
- this.name = EXTENSIONS.KHR_MATERIALS_UNLIT;
642
-
643
- }
644
-
645
- getMaterialType() {
646
-
647
- return MeshBasicMaterial;
648
-
649
- }
650
-
651
- extendParams( materialParams, materialDef, parser ) {
652
-
653
- const pending = [];
654
-
655
- materialParams.color = new Color( 1.0, 1.0, 1.0 );
656
- materialParams.opacity = 1.0;
657
-
658
- const metallicRoughness = materialDef.pbrMetallicRoughness;
659
-
660
- if ( metallicRoughness ) {
661
-
662
- if ( Array.isArray( metallicRoughness.baseColorFactor ) ) {
663
-
664
- const array = metallicRoughness.baseColorFactor;
665
-
666
- materialParams.color.fromArray( array );
667
- materialParams.opacity = array[ 3 ];
668
-
669
- }
670
-
671
- if ( metallicRoughness.baseColorTexture !== undefined ) {
672
-
673
- pending.push( parser.assignTexture( materialParams, 'map', metallicRoughness.baseColorTexture, SRGBColorSpace ) );
674
-
675
- }
676
-
677
- }
678
-
679
- return Promise.all( pending );
680
-
681
- }
682
-
683
- }
684
-
685
- /**
686
- * Materials Emissive Strength Extension
687
- *
688
- * Specification: https://github.com/KhronosGroup/glTF/blob/5768b3ce0ef32bc39cdf1bef10b948586635ead3/extensions/2.0/Khronos/KHR_materials_emissive_strength/README.md
689
- */
690
- class GLTFMaterialsEmissiveStrengthExtension {
691
-
692
- constructor( parser ) {
693
-
694
- this.parser = parser;
695
- this.name = EXTENSIONS.KHR_MATERIALS_EMISSIVE_STRENGTH;
696
-
697
- }
698
-
699
- extendMaterialParams( materialIndex, materialParams ) {
700
-
701
- const parser = this.parser;
702
- const materialDef = parser.json.materials[ materialIndex ];
703
-
704
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
705
-
706
- return Promise.resolve();
707
-
708
- }
709
-
710
- const emissiveStrength = materialDef.extensions[ this.name ].emissiveStrength;
711
-
712
- if ( emissiveStrength !== undefined ) {
713
-
714
- materialParams.emissiveIntensity = emissiveStrength;
715
-
716
- }
717
-
718
- return Promise.resolve();
719
-
720
- }
721
-
722
- }
723
-
724
- /**
725
- * Clearcoat Materials Extension
726
- *
727
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_clearcoat
728
- */
729
- class GLTFMaterialsClearcoatExtension {
730
-
731
- constructor( parser ) {
732
-
733
- this.parser = parser;
734
- this.name = EXTENSIONS.KHR_MATERIALS_CLEARCOAT;
735
-
736
- }
737
-
738
- getMaterialType( materialIndex ) {
739
-
740
- const parser = this.parser;
741
- const materialDef = parser.json.materials[ materialIndex ];
742
-
743
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
744
-
745
- return MeshPhysicalMaterial;
746
-
747
- }
748
-
749
- extendMaterialParams( materialIndex, materialParams ) {
750
-
751
- const parser = this.parser;
752
- const materialDef = parser.json.materials[ materialIndex ];
753
-
754
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
755
-
756
- return Promise.resolve();
757
-
758
- }
759
-
760
- const pending = [];
761
-
762
- const extension = materialDef.extensions[ this.name ];
763
-
764
- if ( extension.clearcoatFactor !== undefined ) {
765
-
766
- materialParams.clearcoat = extension.clearcoatFactor;
767
-
768
- }
769
-
770
- if ( extension.clearcoatTexture !== undefined ) {
771
-
772
- pending.push( parser.assignTexture( materialParams, 'clearcoatMap', extension.clearcoatTexture ) );
773
-
774
- }
775
-
776
- if ( extension.clearcoatRoughnessFactor !== undefined ) {
777
-
778
- materialParams.clearcoatRoughness = extension.clearcoatRoughnessFactor;
779
-
780
- }
781
-
782
- if ( extension.clearcoatRoughnessTexture !== undefined ) {
783
-
784
- pending.push( parser.assignTexture( materialParams, 'clearcoatRoughnessMap', extension.clearcoatRoughnessTexture ) );
785
-
786
- }
787
-
788
- if ( extension.clearcoatNormalTexture !== undefined ) {
789
-
790
- pending.push( parser.assignTexture( materialParams, 'clearcoatNormalMap', extension.clearcoatNormalTexture ) );
791
-
792
- if ( extension.clearcoatNormalTexture.scale !== undefined ) {
793
-
794
- const scale = extension.clearcoatNormalTexture.scale;
795
-
796
- materialParams.clearcoatNormalScale = new Vector2( scale, scale );
797
-
798
- }
799
-
800
- }
801
-
802
- return Promise.all( pending );
803
-
804
- }
805
-
806
- }
807
-
808
- /**
809
- * Iridescence Materials Extension
810
- *
811
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_iridescence
812
- */
813
- class GLTFMaterialsIridescenceExtension {
814
-
815
- constructor( parser ) {
816
-
817
- this.parser = parser;
818
- this.name = EXTENSIONS.KHR_MATERIALS_IRIDESCENCE;
819
-
820
- }
821
-
822
- getMaterialType( materialIndex ) {
823
-
824
- const parser = this.parser;
825
- const materialDef = parser.json.materials[ materialIndex ];
826
-
827
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
828
-
829
- return MeshPhysicalMaterial;
830
-
831
- }
832
-
833
- extendMaterialParams( materialIndex, materialParams ) {
834
-
835
- const parser = this.parser;
836
- const materialDef = parser.json.materials[ materialIndex ];
837
-
838
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
839
-
840
- return Promise.resolve();
841
-
842
- }
843
-
844
- const pending = [];
845
-
846
- const extension = materialDef.extensions[ this.name ];
847
-
848
- if ( extension.iridescenceFactor !== undefined ) {
849
-
850
- materialParams.iridescence = extension.iridescenceFactor;
851
-
852
- }
853
-
854
- if ( extension.iridescenceTexture !== undefined ) {
855
-
856
- pending.push( parser.assignTexture( materialParams, 'iridescenceMap', extension.iridescenceTexture ) );
857
-
858
- }
859
-
860
- if ( extension.iridescenceIor !== undefined ) {
861
-
862
- materialParams.iridescenceIOR = extension.iridescenceIor;
863
-
864
- }
865
-
866
- if ( materialParams.iridescenceThicknessRange === undefined ) {
867
-
868
- materialParams.iridescenceThicknessRange = [ 100, 400 ];
869
-
870
- }
871
-
872
- if ( extension.iridescenceThicknessMinimum !== undefined ) {
873
-
874
- materialParams.iridescenceThicknessRange[ 0 ] = extension.iridescenceThicknessMinimum;
875
-
876
- }
877
-
878
- if ( extension.iridescenceThicknessMaximum !== undefined ) {
879
-
880
- materialParams.iridescenceThicknessRange[ 1 ] = extension.iridescenceThicknessMaximum;
881
-
882
- }
883
-
884
- if ( extension.iridescenceThicknessTexture !== undefined ) {
885
-
886
- pending.push( parser.assignTexture( materialParams, 'iridescenceThicknessMap', extension.iridescenceThicknessTexture ) );
887
-
888
- }
889
-
890
- return Promise.all( pending );
891
-
892
- }
893
-
894
- }
895
-
896
- /**
897
- * Sheen Materials Extension
898
- *
899
- * Specification: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_sheen
900
- */
901
- class GLTFMaterialsSheenExtension {
902
-
903
- constructor( parser ) {
904
-
905
- this.parser = parser;
906
- this.name = EXTENSIONS.KHR_MATERIALS_SHEEN;
907
-
908
- }
909
-
910
- getMaterialType( materialIndex ) {
911
-
912
- const parser = this.parser;
913
- const materialDef = parser.json.materials[ materialIndex ];
914
-
915
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
916
-
917
- return MeshPhysicalMaterial;
918
-
919
- }
920
-
921
- extendMaterialParams( materialIndex, materialParams ) {
922
-
923
- const parser = this.parser;
924
- const materialDef = parser.json.materials[ materialIndex ];
925
-
926
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
927
-
928
- return Promise.resolve();
929
-
930
- }
931
-
932
- const pending = [];
933
-
934
- materialParams.sheenColor = new Color( 0, 0, 0 );
935
- materialParams.sheenRoughness = 0;
936
- materialParams.sheen = 1;
937
-
938
- const extension = materialDef.extensions[ this.name ];
939
-
940
- if ( extension.sheenColorFactor !== undefined ) {
941
-
942
- materialParams.sheenColor.fromArray( extension.sheenColorFactor );
943
-
944
- }
945
-
946
- if ( extension.sheenRoughnessFactor !== undefined ) {
947
-
948
- materialParams.sheenRoughness = extension.sheenRoughnessFactor;
949
-
950
- }
951
-
952
- if ( extension.sheenColorTexture !== undefined ) {
953
-
954
- pending.push( parser.assignTexture( materialParams, 'sheenColorMap', extension.sheenColorTexture, SRGBColorSpace ) );
955
-
956
- }
957
-
958
- if ( extension.sheenRoughnessTexture !== undefined ) {
959
-
960
- pending.push( parser.assignTexture( materialParams, 'sheenRoughnessMap', extension.sheenRoughnessTexture ) );
961
-
962
- }
963
-
964
- return Promise.all( pending );
965
-
966
- }
967
-
968
- }
969
-
970
- /**
971
- * Transmission Materials Extension
972
- *
973
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_transmission
974
- * Draft: https://github.com/KhronosGroup/glTF/pull/1698
975
- */
976
- class GLTFMaterialsTransmissionExtension {
977
-
978
- constructor( parser ) {
979
-
980
- this.parser = parser;
981
- this.name = EXTENSIONS.KHR_MATERIALS_TRANSMISSION;
982
-
983
- }
984
-
985
- getMaterialType( materialIndex ) {
986
-
987
- const parser = this.parser;
988
- const materialDef = parser.json.materials[ materialIndex ];
989
-
990
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
991
-
992
- return MeshPhysicalMaterial;
993
-
994
- }
995
-
996
- extendMaterialParams( materialIndex, materialParams ) {
997
-
998
- const parser = this.parser;
999
- const materialDef = parser.json.materials[ materialIndex ];
1000
-
1001
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
1002
-
1003
- return Promise.resolve();
1004
-
1005
- }
1006
-
1007
- const pending = [];
1008
-
1009
- const extension = materialDef.extensions[ this.name ];
1010
-
1011
- if ( extension.transmissionFactor !== undefined ) {
1012
-
1013
- materialParams.transmission = extension.transmissionFactor;
1014
-
1015
- }
1016
-
1017
- if ( extension.transmissionTexture !== undefined ) {
1018
-
1019
- pending.push( parser.assignTexture( materialParams, 'transmissionMap', extension.transmissionTexture ) );
1020
-
1021
- }
1022
-
1023
- return Promise.all( pending );
1024
-
1025
- }
1026
-
1027
- }
1028
-
1029
- /**
1030
- * Materials Volume Extension
1031
- *
1032
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_volume
1033
- */
1034
- class GLTFMaterialsVolumeExtension {
1035
-
1036
- constructor( parser ) {
1037
-
1038
- this.parser = parser;
1039
- this.name = EXTENSIONS.KHR_MATERIALS_VOLUME;
1040
-
1041
- }
1042
-
1043
- getMaterialType( materialIndex ) {
1044
-
1045
- const parser = this.parser;
1046
- const materialDef = parser.json.materials[ materialIndex ];
1047
-
1048
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
1049
-
1050
- return MeshPhysicalMaterial;
1051
-
1052
- }
1053
-
1054
- extendMaterialParams( materialIndex, materialParams ) {
1055
-
1056
- const parser = this.parser;
1057
- const materialDef = parser.json.materials[ materialIndex ];
1058
-
1059
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
1060
-
1061
- return Promise.resolve();
1062
-
1063
- }
1064
-
1065
- const pending = [];
1066
-
1067
- const extension = materialDef.extensions[ this.name ];
1068
-
1069
- materialParams.thickness = extension.thicknessFactor !== undefined ? extension.thicknessFactor : 0;
1070
-
1071
- if ( extension.thicknessTexture !== undefined ) {
1072
-
1073
- pending.push( parser.assignTexture( materialParams, 'thicknessMap', extension.thicknessTexture ) );
1074
-
1075
- }
1076
-
1077
- materialParams.attenuationDistance = extension.attenuationDistance || Infinity;
1078
-
1079
- const colorArray = extension.attenuationColor || [ 1, 1, 1 ];
1080
- materialParams.attenuationColor = new Color( colorArray[ 0 ], colorArray[ 1 ], colorArray[ 2 ] );
1081
-
1082
- return Promise.all( pending );
1083
-
1084
- }
1085
-
1086
- }
1087
-
1088
- /**
1089
- * Materials ior Extension
1090
- *
1091
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_ior
1092
- */
1093
- class GLTFMaterialsIorExtension {
1094
-
1095
- constructor( parser ) {
1096
-
1097
- this.parser = parser;
1098
- this.name = EXTENSIONS.KHR_MATERIALS_IOR;
1099
-
1100
- }
1101
-
1102
- getMaterialType( materialIndex ) {
1103
-
1104
- const parser = this.parser;
1105
- const materialDef = parser.json.materials[ materialIndex ];
1106
-
1107
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
1108
-
1109
- return MeshPhysicalMaterial;
1110
-
1111
- }
1112
-
1113
- extendMaterialParams( materialIndex, materialParams ) {
1114
-
1115
- const parser = this.parser;
1116
- const materialDef = parser.json.materials[ materialIndex ];
1117
-
1118
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
1119
-
1120
- return Promise.resolve();
1121
-
1122
- }
1123
-
1124
- const extension = materialDef.extensions[ this.name ];
1125
-
1126
- materialParams.ior = extension.ior !== undefined ? extension.ior : 1.5;
1127
-
1128
- return Promise.resolve();
1129
-
1130
- }
1131
-
1132
- }
1133
-
1134
- /**
1135
- * Materials specular Extension
1136
- *
1137
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_specular
1138
- */
1139
- class GLTFMaterialsSpecularExtension {
1140
-
1141
- constructor( parser ) {
1142
-
1143
- this.parser = parser;
1144
- this.name = EXTENSIONS.KHR_MATERIALS_SPECULAR;
1145
-
1146
- }
1147
-
1148
- getMaterialType( materialIndex ) {
1149
-
1150
- const parser = this.parser;
1151
- const materialDef = parser.json.materials[ materialIndex ];
1152
-
1153
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
1154
-
1155
- return MeshPhysicalMaterial;
1156
-
1157
- }
1158
-
1159
- extendMaterialParams( materialIndex, materialParams ) {
1160
-
1161
- const parser = this.parser;
1162
- const materialDef = parser.json.materials[ materialIndex ];
1163
-
1164
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
1165
-
1166
- return Promise.resolve();
1167
-
1168
- }
1169
-
1170
- const pending = [];
1171
-
1172
- const extension = materialDef.extensions[ this.name ];
1173
-
1174
- materialParams.specularIntensity = extension.specularFactor !== undefined ? extension.specularFactor : 1.0;
1175
-
1176
- if ( extension.specularTexture !== undefined ) {
1177
-
1178
- pending.push( parser.assignTexture( materialParams, 'specularIntensityMap', extension.specularTexture ) );
1179
-
1180
- }
1181
-
1182
- const colorArray = extension.specularColorFactor || [ 1, 1, 1 ];
1183
- materialParams.specularColor = new Color( colorArray[ 0 ], colorArray[ 1 ], colorArray[ 2 ] );
1184
-
1185
- if ( extension.specularColorTexture !== undefined ) {
1186
-
1187
- pending.push( parser.assignTexture( materialParams, 'specularColorMap', extension.specularColorTexture, SRGBColorSpace ) );
1188
-
1189
- }
1190
-
1191
- return Promise.all( pending );
1192
-
1193
- }
1194
-
1195
- }
1196
-
1197
- /**
1198
- * Materials anisotropy Extension
1199
- *
1200
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_anisotropy
1201
- */
1202
- class GLTFMaterialsAnisotropyExtension {
1203
-
1204
- constructor( parser ) {
1205
-
1206
- this.parser = parser;
1207
- this.name = EXTENSIONS.KHR_MATERIALS_ANISOTROPY;
1208
-
1209
- }
1210
-
1211
- getMaterialType( materialIndex ) {
1212
-
1213
- const parser = this.parser;
1214
- const materialDef = parser.json.materials[ materialIndex ];
1215
-
1216
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
1217
-
1218
- return MeshPhysicalMaterial;
1219
-
1220
- }
1221
-
1222
- extendMaterialParams( materialIndex, materialParams ) {
1223
-
1224
- const parser = this.parser;
1225
- const materialDef = parser.json.materials[ materialIndex ];
1226
-
1227
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
1228
-
1229
- return Promise.resolve();
1230
-
1231
- }
1232
-
1233
- const pending = [];
1234
-
1235
- const extension = materialDef.extensions[ this.name ];
1236
-
1237
- if ( extension.anisotropyStrength !== undefined ) {
1238
-
1239
- materialParams.anisotropy = extension.anisotropyStrength;
1240
-
1241
- }
1242
-
1243
- if ( extension.anisotropyRotation !== undefined ) {
1244
-
1245
- materialParams.anisotropyRotation = extension.anisotropyRotation;
1246
-
1247
- }
1248
-
1249
- if ( extension.anisotropyTexture !== undefined ) {
1250
-
1251
- pending.push( parser.assignTexture( materialParams, 'anisotropyMap', extension.anisotropyTexture ) );
1252
-
1253
- }
1254
-
1255
- return Promise.all( pending );
1256
-
1257
- }
1258
-
1259
- }
1260
-
1261
- /**
1262
- * BasisU Texture Extension
1263
- *
1264
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_texture_basisu
1265
- */
1266
- class GLTFTextureBasisUExtension {
1267
-
1268
- constructor( parser ) {
1269
-
1270
- this.parser = parser;
1271
- this.name = EXTENSIONS.KHR_TEXTURE_BASISU;
1272
-
1273
- }
1274
-
1275
- loadTexture( textureIndex ) {
1276
-
1277
- const parser = this.parser;
1278
- const json = parser.json;
1279
-
1280
- const textureDef = json.textures[ textureIndex ];
1281
-
1282
- if ( ! textureDef.extensions || ! textureDef.extensions[ this.name ] ) {
1283
-
1284
- return null;
1285
-
1286
- }
1287
-
1288
- const extension = textureDef.extensions[ this.name ];
1289
- const loader = parser.options.ktx2Loader;
1290
-
1291
- if ( ! loader ) {
1292
-
1293
- if ( json.extensionsRequired && json.extensionsRequired.indexOf( this.name ) >= 0 ) {
1294
-
1295
- throw new Error( 'THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures' );
1296
-
1297
- } else {
1298
-
1299
- // Assumes that the extension is optional and that a fallback texture is present
1300
- return null;
1301
-
1302
- }
1303
-
1304
- }
1305
-
1306
- return parser.loadTextureImage( textureIndex, extension.source, loader );
1307
-
1308
- }
1309
-
1310
- }
1311
-
1312
- /**
1313
- * WebP Texture Extension
1314
- *
1315
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_texture_webp
1316
- */
1317
- class GLTFTextureWebPExtension {
1318
-
1319
- constructor( parser ) {
1320
-
1321
- this.parser = parser;
1322
- this.name = EXTENSIONS.EXT_TEXTURE_WEBP;
1323
- this.isSupported = null;
1324
-
1325
- }
1326
-
1327
- loadTexture( textureIndex ) {
1328
-
1329
- const name = this.name;
1330
- const parser = this.parser;
1331
- const json = parser.json;
1332
-
1333
- const textureDef = json.textures[ textureIndex ];
1334
-
1335
- if ( ! textureDef.extensions || ! textureDef.extensions[ name ] ) {
1336
-
1337
- return null;
1338
-
1339
- }
1340
-
1341
- const extension = textureDef.extensions[ name ];
1342
- const source = json.images[ extension.source ];
1343
-
1344
- let loader = parser.textureLoader;
1345
- if ( source.uri ) {
1346
-
1347
- const handler = parser.options.manager.getHandler( source.uri );
1348
- if ( handler !== null ) loader = handler;
1349
-
1350
- }
1351
-
1352
- return this.detectSupport().then( function ( isSupported ) {
1353
-
1354
- if ( isSupported ) return parser.loadTextureImage( textureIndex, extension.source, loader );
1355
-
1356
- if ( json.extensionsRequired && json.extensionsRequired.indexOf( name ) >= 0 ) {
1357
-
1358
- throw new Error( 'THREE.GLTFLoader: WebP required by asset but unsupported.' );
1359
-
1360
- }
1361
-
1362
- // Fall back to PNG or JPEG.
1363
- return parser.loadTexture( textureIndex );
1364
-
1365
- } );
1366
-
1367
- }
1368
-
1369
- detectSupport() {
1370
-
1371
- if ( ! this.isSupported ) {
1372
-
1373
- this.isSupported = new Promise( function ( resolve ) {
1374
-
1375
- const image = new Image();
1376
-
1377
- // Lossy test image. Support for lossy images doesn't guarantee support for all
1378
- // WebP images, unfortunately.
1379
- image.src = 'data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA';
1380
-
1381
- image.onload = image.onerror = function () {
1382
-
1383
- resolve( image.height === 1 );
1384
-
1385
- };
1386
-
1387
- } );
1388
-
1389
- }
1390
-
1391
- return this.isSupported;
1392
-
1393
- }
1394
-
1395
- }
1396
-
1397
- /**
1398
- * AVIF Texture Extension
1399
- *
1400
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_texture_avif
1401
- */
1402
- class GLTFTextureAVIFExtension {
1403
-
1404
- constructor( parser ) {
1405
-
1406
- this.parser = parser;
1407
- this.name = EXTENSIONS.EXT_TEXTURE_AVIF;
1408
- this.isSupported = null;
1409
-
1410
- }
1411
-
1412
- loadTexture( textureIndex ) {
1413
-
1414
- const name = this.name;
1415
- const parser = this.parser;
1416
- const json = parser.json;
1417
-
1418
- const textureDef = json.textures[ textureIndex ];
1419
-
1420
- if ( ! textureDef.extensions || ! textureDef.extensions[ name ] ) {
1421
-
1422
- return null;
1423
-
1424
- }
1425
-
1426
- const extension = textureDef.extensions[ name ];
1427
- const source = json.images[ extension.source ];
1428
-
1429
- let loader = parser.textureLoader;
1430
- if ( source.uri ) {
1431
-
1432
- const handler = parser.options.manager.getHandler( source.uri );
1433
- if ( handler !== null ) loader = handler;
1434
-
1435
- }
1436
-
1437
- return this.detectSupport().then( function ( isSupported ) {
1438
-
1439
- if ( isSupported ) return parser.loadTextureImage( textureIndex, extension.source, loader );
1440
-
1441
- if ( json.extensionsRequired && json.extensionsRequired.indexOf( name ) >= 0 ) {
1442
-
1443
- throw new Error( 'THREE.GLTFLoader: AVIF required by asset but unsupported.' );
1444
-
1445
- }
1446
-
1447
- // Fall back to PNG or JPEG.
1448
- return parser.loadTexture( textureIndex );
1449
-
1450
- } );
1451
-
1452
- }
1453
-
1454
- detectSupport() {
1455
-
1456
- if ( ! this.isSupported ) {
1457
-
1458
- this.isSupported = new Promise( function ( resolve ) {
1459
-
1460
- const image = new Image();
1461
-
1462
- // Lossy test image.
1463
- image.src = 'data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAABcAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAEAAAABAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQAMAAAAABNjb2xybmNseAACAAIABoAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAAB9tZGF0EgAKCBgABogQEDQgMgkQAAAAB8dSLfI=';
1464
- image.onload = image.onerror = function () {
1465
-
1466
- resolve( image.height === 1 );
1467
-
1468
- };
1469
-
1470
- } );
1471
-
1472
- }
1473
-
1474
- return this.isSupported;
1475
-
1476
- }
1477
-
1478
- }
1479
-
1480
- /**
1481
- * meshopt BufferView Compression Extension
1482
- *
1483
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_meshopt_compression
1484
- */
1485
- class GLTFMeshoptCompression {
1486
-
1487
- constructor( parser ) {
1488
-
1489
- this.name = EXTENSIONS.EXT_MESHOPT_COMPRESSION;
1490
- this.parser = parser;
1491
-
1492
- }
1493
-
1494
- loadBufferView( index ) {
1495
-
1496
- const json = this.parser.json;
1497
- const bufferView = json.bufferViews[ index ];
1498
-
1499
- if ( bufferView.extensions && bufferView.extensions[ this.name ] ) {
1500
-
1501
- const extensionDef = bufferView.extensions[ this.name ];
1502
-
1503
- const buffer = this.parser.getDependency( 'buffer', extensionDef.buffer );
1504
- const decoder = this.parser.options.meshoptDecoder;
1505
-
1506
- if ( ! decoder || ! decoder.supported ) {
1507
-
1508
- if ( json.extensionsRequired && json.extensionsRequired.indexOf( this.name ) >= 0 ) {
1509
-
1510
- throw new Error( 'THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files' );
1511
-
1512
- } else {
1513
-
1514
- // Assumes that the extension is optional and that fallback buffer data is present
1515
- return null;
1516
-
1517
- }
1518
-
1519
- }
1520
-
1521
- return buffer.then( function ( res ) {
1522
-
1523
- const byteOffset = extensionDef.byteOffset || 0;
1524
- const byteLength = extensionDef.byteLength || 0;
1525
-
1526
- const count = extensionDef.count;
1527
- const stride = extensionDef.byteStride;
1528
-
1529
- const source = new Uint8Array( res, byteOffset, byteLength );
1530
-
1531
- if ( decoder.decodeGltfBufferAsync ) {
1532
-
1533
- return decoder.decodeGltfBufferAsync( count, stride, source, extensionDef.mode, extensionDef.filter ).then( function ( res ) {
1534
-
1535
- return res.buffer;
1536
-
1537
- } );
1538
-
1539
- } else {
1540
-
1541
- // Support for MeshoptDecoder 0.18 or earlier, without decodeGltfBufferAsync
1542
- return decoder.ready.then( function () {
1543
-
1544
- const result = new ArrayBuffer( count * stride );
1545
- decoder.decodeGltfBuffer( new Uint8Array( result ), count, stride, source, extensionDef.mode, extensionDef.filter );
1546
- return result;
1547
-
1548
- } );
1549
-
1550
- }
1551
-
1552
- } );
1553
-
1554
- } else {
1555
-
1556
- return null;
1557
-
1558
- }
1559
-
1560
- }
1561
-
1562
- }
1563
-
1564
- /**
1565
- * GPU Instancing Extension
1566
- *
1567
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_mesh_gpu_instancing
1568
- *
1569
- */
1570
- class GLTFMeshGpuInstancing {
1571
-
1572
- constructor( parser ) {
1573
-
1574
- this.name = EXTENSIONS.EXT_MESH_GPU_INSTANCING;
1575
- this.parser = parser;
1576
-
1577
- }
1578
-
1579
- createNodeMesh( nodeIndex ) {
1580
-
1581
- const json = this.parser.json;
1582
- const nodeDef = json.nodes[ nodeIndex ];
1583
-
1584
- if ( ! nodeDef.extensions || ! nodeDef.extensions[ this.name ] ||
1585
- nodeDef.mesh === undefined ) {
1586
-
1587
- return null;
1588
-
1589
- }
1590
-
1591
- const meshDef = json.meshes[ nodeDef.mesh ];
1592
-
1593
- // No Points or Lines + Instancing support yet
1594
-
1595
- for ( const primitive of meshDef.primitives ) {
1596
-
1597
- if ( primitive.mode !== WEBGL_CONSTANTS.TRIANGLES &&
1598
- primitive.mode !== WEBGL_CONSTANTS.TRIANGLE_STRIP &&
1599
- primitive.mode !== WEBGL_CONSTANTS.TRIANGLE_FAN &&
1600
- primitive.mode !== undefined ) {
1601
-
1602
- return null;
1603
-
1604
- }
1605
-
1606
- }
1607
-
1608
- const extensionDef = nodeDef.extensions[ this.name ];
1609
- const attributesDef = extensionDef.attributes;
1610
-
1611
- // @TODO: Can we support InstancedMesh + SkinnedMesh?
1612
-
1613
- const pending = [];
1614
- const attributes = {};
1615
-
1616
- for ( const key in attributesDef ) {
1617
-
1618
- pending.push( this.parser.getDependency( 'accessor', attributesDef[ key ] ).then( accessor => {
1619
-
1620
- attributes[ key ] = accessor;
1621
- return attributes[ key ];
1622
-
1623
- } ) );
1624
-
1625
- }
1626
-
1627
- if ( pending.length < 1 ) {
1628
-
1629
- return null;
1630
-
1631
- }
1632
-
1633
- pending.push( this.parser.createNodeMesh( nodeIndex ) );
1634
-
1635
- return Promise.all( pending ).then( results => {
1636
-
1637
- const nodeObject = results.pop();
1638
- const meshes = nodeObject.isGroup ? nodeObject.children : [ nodeObject ];
1639
- const count = results[ 0 ].count; // All attribute counts should be same
1640
- const instancedMeshes = [];
1641
-
1642
- for ( const mesh of meshes ) {
1643
-
1644
- // Temporal variables
1645
- const m = new Matrix4();
1646
- const p = new Vector3();
1647
- const q = new Quaternion();
1648
- const s = new Vector3( 1, 1, 1 );
1649
-
1650
- const instancedMesh = new InstancedMesh( mesh.geometry, mesh.material, count );
1651
-
1652
- for ( let i = 0; i < count; i ++ ) {
1653
-
1654
- if ( attributes.TRANSLATION ) {
1655
-
1656
- p.fromBufferAttribute( attributes.TRANSLATION, i );
1657
-
1658
- }
1659
-
1660
- if ( attributes.ROTATION ) {
1661
-
1662
- q.fromBufferAttribute( attributes.ROTATION, i );
1663
-
1664
- }
1665
-
1666
- if ( attributes.SCALE ) {
1667
-
1668
- s.fromBufferAttribute( attributes.SCALE, i );
1669
-
1670
- }
1671
-
1672
- instancedMesh.setMatrixAt( i, m.compose( p, q, s ) );
1673
-
1674
- }
1675
-
1676
- // Add instance attributes to the geometry, excluding TRS.
1677
- for ( const attributeName in attributes ) {
1678
-
1679
- if ( attributeName !== 'TRANSLATION' &&
1680
- attributeName !== 'ROTATION' &&
1681
- attributeName !== 'SCALE' ) {
1682
-
1683
- mesh.geometry.setAttribute( attributeName, attributes[ attributeName ] );
1684
-
1685
- }
1686
-
1687
- }
1688
-
1689
- // Just in case
1690
- Object3D.prototype.copy.call( instancedMesh, mesh );
1691
-
1692
- this.parser.assignFinalMaterial( instancedMesh );
1693
-
1694
- instancedMeshes.push( instancedMesh );
1695
-
1696
- }
1697
-
1698
- if ( nodeObject.isGroup ) {
1699
-
1700
- nodeObject.clear();
1701
-
1702
- nodeObject.add( ... instancedMeshes );
1703
-
1704
- return nodeObject;
1705
-
1706
- }
1707
-
1708
- return instancedMeshes[ 0 ];
1709
-
1710
- } );
1711
-
1712
- }
1713
-
1714
- }
1715
-
1716
- /* BINARY EXTENSION */
1717
- const BINARY_EXTENSION_HEADER_MAGIC = 'glTF';
1718
- const BINARY_EXTENSION_HEADER_LENGTH = 12;
1719
- const BINARY_EXTENSION_CHUNK_TYPES = { JSON: 0x4E4F534A, BIN: 0x004E4942 };
1720
-
1721
- class GLTFBinaryExtension {
1722
-
1723
- constructor( data ) {
1724
-
1725
- this.name = EXTENSIONS.KHR_BINARY_GLTF;
1726
- this.content = null;
1727
- this.body = null;
1728
-
1729
- const headerView = new DataView( data, 0, BINARY_EXTENSION_HEADER_LENGTH );
1730
- const textDecoder = new TextDecoder();
1731
-
1732
- this.header = {
1733
- magic: textDecoder.decode( new Uint8Array( data.slice( 0, 4 ) ) ),
1734
- version: headerView.getUint32( 4, true ),
1735
- length: headerView.getUint32( 8, true )
1736
- };
1737
-
1738
- if ( this.header.magic !== BINARY_EXTENSION_HEADER_MAGIC ) {
1739
-
1740
- throw new Error( 'THREE.GLTFLoader: Unsupported glTF-Binary header.' );
1741
-
1742
- } else if ( this.header.version < 2.0 ) {
1743
-
1744
- throw new Error( 'THREE.GLTFLoader: Legacy binary file detected.' );
1745
-
1746
- }
1747
-
1748
- const chunkContentsLength = this.header.length - BINARY_EXTENSION_HEADER_LENGTH;
1749
- const chunkView = new DataView( data, BINARY_EXTENSION_HEADER_LENGTH );
1750
- let chunkIndex = 0;
1751
-
1752
- while ( chunkIndex < chunkContentsLength ) {
1753
-
1754
- const chunkLength = chunkView.getUint32( chunkIndex, true );
1755
- chunkIndex += 4;
1756
-
1757
- const chunkType = chunkView.getUint32( chunkIndex, true );
1758
- chunkIndex += 4;
1759
-
1760
- if ( chunkType === BINARY_EXTENSION_CHUNK_TYPES.JSON ) {
1761
-
1762
- const contentArray = new Uint8Array( data, BINARY_EXTENSION_HEADER_LENGTH + chunkIndex, chunkLength );
1763
- this.content = textDecoder.decode( contentArray );
1764
-
1765
- } else if ( chunkType === BINARY_EXTENSION_CHUNK_TYPES.BIN ) {
1766
-
1767
- const byteOffset = BINARY_EXTENSION_HEADER_LENGTH + chunkIndex;
1768
- this.body = data.slice( byteOffset, byteOffset + chunkLength );
1769
-
1770
- }
1771
-
1772
- // Clients must ignore chunks with unknown types.
1773
-
1774
- chunkIndex += chunkLength;
1775
-
1776
- }
1777
-
1778
- if ( this.content === null ) {
1779
-
1780
- throw new Error( 'THREE.GLTFLoader: JSON content not found.' );
1781
-
1782
- }
1783
-
1784
- }
1785
-
1786
- }
1787
-
1788
- /**
1789
- * DRACO Mesh Compression Extension
1790
- *
1791
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression
1792
- */
1793
- class GLTFDracoMeshCompressionExtension {
1794
-
1795
- constructor( json, dracoLoader ) {
1796
-
1797
- if ( ! dracoLoader ) {
1798
-
1799
- throw new Error( 'THREE.GLTFLoader: No DRACOLoader instance provided.' );
1800
-
1801
- }
1802
-
1803
- this.name = EXTENSIONS.KHR_DRACO_MESH_COMPRESSION;
1804
- this.json = json;
1805
- this.dracoLoader = dracoLoader;
1806
- this.dracoLoader.preload();
1807
-
1808
- }
1809
-
1810
- decodePrimitive( primitive, parser ) {
1811
-
1812
- const json = this.json;
1813
- const dracoLoader = this.dracoLoader;
1814
- const bufferViewIndex = primitive.extensions[ this.name ].bufferView;
1815
- const gltfAttributeMap = primitive.extensions[ this.name ].attributes;
1816
- const threeAttributeMap = {};
1817
- const attributeNormalizedMap = {};
1818
- const attributeTypeMap = {};
1819
-
1820
- for ( const attributeName in gltfAttributeMap ) {
1821
-
1822
- const threeAttributeName = ATTRIBUTES[ attributeName ] || attributeName.toLowerCase();
1823
-
1824
- threeAttributeMap[ threeAttributeName ] = gltfAttributeMap[ attributeName ];
1825
-
1826
- }
1827
-
1828
- for ( const attributeName in primitive.attributes ) {
1829
-
1830
- const threeAttributeName = ATTRIBUTES[ attributeName ] || attributeName.toLowerCase();
1831
-
1832
- if ( gltfAttributeMap[ attributeName ] !== undefined ) {
1833
-
1834
- const accessorDef = json.accessors[ primitive.attributes[ attributeName ] ];
1835
- const componentType = WEBGL_COMPONENT_TYPES[ accessorDef.componentType ];
1836
-
1837
- attributeTypeMap[ threeAttributeName ] = componentType.name;
1838
- attributeNormalizedMap[ threeAttributeName ] = accessorDef.normalized === true;
1839
-
1840
- }
1841
-
1842
- }
1843
-
1844
- return parser.getDependency( 'bufferView', bufferViewIndex ).then( function ( bufferView ) {
1845
-
1846
- return new Promise( function ( resolve ) {
1847
-
1848
- dracoLoader.decodeDracoFile( bufferView, function ( geometry ) {
1849
-
1850
- for ( const attributeName in geometry.attributes ) {
1851
-
1852
- const attribute = geometry.attributes[ attributeName ];
1853
- const normalized = attributeNormalizedMap[ attributeName ];
1854
-
1855
- if ( normalized !== undefined ) attribute.normalized = normalized;
1856
-
1857
- }
1858
-
1859
- resolve( geometry );
1860
-
1861
- }, threeAttributeMap, attributeTypeMap );
1862
-
1863
- } );
1864
-
1865
- } );
1866
-
1867
- }
1868
-
1869
- }
1870
-
1871
- /**
1872
- * Texture Transform Extension
1873
- *
1874
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_texture_transform
1875
- */
1876
- class GLTFTextureTransformExtension {
1877
-
1878
- constructor() {
1879
-
1880
- this.name = EXTENSIONS.KHR_TEXTURE_TRANSFORM;
1881
-
1882
- }
1883
-
1884
- extendTexture( texture, transform ) {
1885
-
1886
- if ( ( transform.texCoord === undefined || transform.texCoord === texture.channel )
1887
- && transform.offset === undefined
1888
- && transform.rotation === undefined
1889
- && transform.scale === undefined ) {
1890
-
1891
- // See https://github.com/mrdoob/three.js/issues/21819.
1892
- return texture;
1893
-
1894
- }
1895
-
1896
- texture = texture.clone();
1897
-
1898
- if ( transform.texCoord !== undefined ) {
1899
-
1900
- texture.channel = transform.texCoord;
1901
-
1902
- }
1903
-
1904
- if ( transform.offset !== undefined ) {
1905
-
1906
- texture.offset.fromArray( transform.offset );
1907
-
1908
- }
1909
-
1910
- if ( transform.rotation !== undefined ) {
1911
-
1912
- texture.rotation = transform.rotation;
1913
-
1914
- }
1915
-
1916
- if ( transform.scale !== undefined ) {
1917
-
1918
- texture.repeat.fromArray( transform.scale );
1919
-
1920
- }
1921
-
1922
- texture.needsUpdate = true;
1923
-
1924
- return texture;
1925
-
1926
- }
1927
-
1928
- }
1929
-
1930
- /**
1931
- * Mesh Quantization Extension
1932
- *
1933
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization
1934
- */
1935
- class GLTFMeshQuantizationExtension {
1936
-
1937
- constructor() {
1938
-
1939
- this.name = EXTENSIONS.KHR_MESH_QUANTIZATION;
1940
-
1941
- }
1942
-
1943
- }
1944
-
1945
- /*********************************/
1946
- /********** INTERPOLATION ********/
1947
- /*********************************/
1948
-
1949
- // Spline Interpolation
1950
- // Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#appendix-c-spline-interpolation
1951
- class GLTFCubicSplineInterpolant extends Interpolant {
1952
-
1953
- constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
1954
-
1955
- super( parameterPositions, sampleValues, sampleSize, resultBuffer );
1956
-
1957
- }
1958
-
1959
- copySampleValue_( index ) {
1960
-
1961
- // Copies a sample value to the result buffer. See description of glTF
1962
- // CUBICSPLINE values layout in interpolate_() function below.
1963
-
1964
- const result = this.resultBuffer,
1965
- values = this.sampleValues,
1966
- valueSize = this.valueSize,
1967
- offset = index * valueSize * 3 + valueSize;
1968
-
1969
- for ( let i = 0; i !== valueSize; i ++ ) {
1970
-
1971
- result[ i ] = values[ offset + i ];
1972
-
1973
- }
1974
-
1975
- return result;
1976
-
1977
- }
1978
-
1979
- interpolate_( i1, t0, t, t1 ) {
1980
-
1981
- const result = this.resultBuffer;
1982
- const values = this.sampleValues;
1983
- const stride = this.valueSize;
1984
-
1985
- const stride2 = stride * 2;
1986
- const stride3 = stride * 3;
1987
-
1988
- const td = t1 - t0;
1989
-
1990
- const p = ( t - t0 ) / td;
1991
- const pp = p * p;
1992
- const ppp = pp * p;
1993
-
1994
- const offset1 = i1 * stride3;
1995
- const offset0 = offset1 - stride3;
1996
-
1997
- const s2 = - 2 * ppp + 3 * pp;
1998
- const s3 = ppp - pp;
1999
- const s0 = 1 - s2;
2000
- const s1 = s3 - pp + p;
2001
-
2002
- // Layout of keyframe output values for CUBICSPLINE animations:
2003
- // [ inTangent_1, splineVertex_1, outTangent_1, inTangent_2, splineVertex_2, ... ]
2004
- for ( let i = 0; i !== stride; i ++ ) {
2005
-
2006
- const p0 = values[ offset0 + i + stride ]; // splineVertex_k
2007
- const m0 = values[ offset0 + i + stride2 ] * td; // outTangent_k * (t_k+1 - t_k)
2008
- const p1 = values[ offset1 + i + stride ]; // splineVertex_k+1
2009
- const m1 = values[ offset1 + i ] * td; // inTangent_k+1 * (t_k+1 - t_k)
2010
-
2011
- result[ i ] = s0 * p0 + s1 * m0 + s2 * p1 + s3 * m1;
2012
-
2013
- }
2014
-
2015
- return result;
2016
-
2017
- }
2018
-
2019
- }
2020
-
2021
- const _q = new Quaternion();
2022
-
2023
- class GLTFCubicSplineQuaternionInterpolant extends GLTFCubicSplineInterpolant {
2024
-
2025
- interpolate_( i1, t0, t, t1 ) {
2026
-
2027
- const result = super.interpolate_( i1, t0, t, t1 );
2028
-
2029
- _q.fromArray( result ).normalize().toArray( result );
2030
-
2031
- return result;
2032
-
2033
- }
2034
-
2035
- }
2036
-
2037
-
2038
- /*********************************/
2039
- /********** INTERNALS ************/
2040
- /*********************************/
2041
-
2042
- /* CONSTANTS */
2043
-
2044
- const WEBGL_CONSTANTS = {
2045
- FLOAT: 5126,
2046
- //FLOAT_MAT2: 35674,
2047
- FLOAT_MAT3: 35675,
2048
- FLOAT_MAT4: 35676,
2049
- FLOAT_VEC2: 35664,
2050
- FLOAT_VEC3: 35665,
2051
- FLOAT_VEC4: 35666,
2052
- LINEAR: 9729,
2053
- REPEAT: 10497,
2054
- SAMPLER_2D: 35678,
2055
- POINTS: 0,
2056
- LINES: 1,
2057
- LINE_LOOP: 2,
2058
- LINE_STRIP: 3,
2059
- TRIANGLES: 4,
2060
- TRIANGLE_STRIP: 5,
2061
- TRIANGLE_FAN: 6,
2062
- UNSIGNED_BYTE: 5121,
2063
- UNSIGNED_SHORT: 5123
2064
- };
2065
-
2066
- const WEBGL_COMPONENT_TYPES = {
2067
- 5120: Int8Array,
2068
- 5121: Uint8Array,
2069
- 5122: Int16Array,
2070
- 5123: Uint16Array,
2071
- 5125: Uint32Array,
2072
- 5126: Float32Array
2073
- };
2074
-
2075
- const WEBGL_FILTERS = {
2076
- 9728: NearestFilter,
2077
- 9729: LinearFilter,
2078
- 9984: NearestMipmapNearestFilter,
2079
- 9985: LinearMipmapNearestFilter,
2080
- 9986: NearestMipmapLinearFilter,
2081
- 9987: LinearMipmapLinearFilter
2082
- };
2083
-
2084
- const WEBGL_WRAPPINGS = {
2085
- 33071: ClampToEdgeWrapping,
2086
- 33648: MirroredRepeatWrapping,
2087
- 10497: RepeatWrapping
2088
- };
2089
-
2090
- const WEBGL_TYPE_SIZES = {
2091
- 'SCALAR': 1,
2092
- 'VEC2': 2,
2093
- 'VEC3': 3,
2094
- 'VEC4': 4,
2095
- 'MAT2': 4,
2096
- 'MAT3': 9,
2097
- 'MAT4': 16
2098
- };
2099
-
2100
- const ATTRIBUTES = {
2101
- POSITION: 'position',
2102
- NORMAL: 'normal',
2103
- TANGENT: 'tangent',
2104
- TEXCOORD_0: 'uv',
2105
- TEXCOORD_1: 'uv1',
2106
- TEXCOORD_2: 'uv2',
2107
- TEXCOORD_3: 'uv3',
2108
- COLOR_0: 'color',
2109
- WEIGHTS_0: 'skinWeight',
2110
- JOINTS_0: 'skinIndex',
2111
- };
2112
-
2113
- const PATH_PROPERTIES = {
2114
- scale: 'scale',
2115
- translation: 'position',
2116
- rotation: 'quaternion',
2117
- weights: 'morphTargetInfluences'
2118
- };
2119
-
2120
- const INTERPOLATION = {
2121
- CUBICSPLINE: undefined, // We use a custom interpolant (GLTFCubicSplineInterpolation) for CUBICSPLINE tracks. Each
2122
- // keyframe track will be initialized with a default interpolation type, then modified.
2123
- LINEAR: InterpolateLinear,
2124
- STEP: InterpolateDiscrete
2125
- };
2126
-
2127
- const ALPHA_MODES = {
2128
- OPAQUE: 'OPAQUE',
2129
- MASK: 'MASK',
2130
- BLEND: 'BLEND'
2131
- };
2132
-
2133
- /**
2134
- * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#default-material
2135
- */
2136
- function createDefaultMaterial( cache ) {
2137
-
2138
- if ( cache[ 'DefaultMaterial' ] === undefined ) {
2139
-
2140
- cache[ 'DefaultMaterial' ] = new MeshStandardMaterial( {
2141
- color: 0xFFFFFF,
2142
- emissive: 0x000000,
2143
- metalness: 1,
2144
- roughness: 1,
2145
- transparent: false,
2146
- depthTest: true,
2147
- side: FrontSide
2148
- } );
2149
-
2150
- }
2151
-
2152
- return cache[ 'DefaultMaterial' ];
2153
-
2154
- }
2155
-
2156
- function addUnknownExtensionsToUserData( knownExtensions, object, objectDef ) {
2157
-
2158
- // Add unknown glTF extensions to an object's userData.
2159
-
2160
- for ( const name in objectDef.extensions ) {
2161
-
2162
- if ( knownExtensions[ name ] === undefined ) {
2163
-
2164
- object.userData.gltfExtensions = object.userData.gltfExtensions || {};
2165
- object.userData.gltfExtensions[ name ] = objectDef.extensions[ name ];
2166
-
2167
- }
2168
-
2169
- }
2170
-
2171
- }
2172
-
2173
- /**
2174
- * @param {Object3D|Material|BufferGeometry} object
2175
- * @param {GLTF.definition} gltfDef
2176
- */
2177
- function assignExtrasToUserData( object, gltfDef ) {
2178
-
2179
- if ( gltfDef.extras !== undefined ) {
2180
-
2181
- if ( typeof gltfDef.extras === 'object' ) {
2182
-
2183
- Object.assign( object.userData, gltfDef.extras );
2184
-
2185
- } else {
2186
-
2187
- console.warn( 'THREE.GLTFLoader: Ignoring primitive type .extras, ' + gltfDef.extras );
2188
-
2189
- }
2190
-
2191
- }
2192
-
2193
- }
2194
-
2195
- /**
2196
- * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#morph-targets
2197
- *
2198
- * @param {BufferGeometry} geometry
2199
- * @param {Array<GLTF.Target>} targets
2200
- * @param {GLTFParser} parser
2201
- * @return {Promise<BufferGeometry>}
2202
- */
2203
- function addMorphTargets( geometry, targets, parser ) {
2204
-
2205
- let hasMorphPosition = false;
2206
- let hasMorphNormal = false;
2207
- let hasMorphColor = false;
2208
-
2209
- for ( let i = 0, il = targets.length; i < il; i ++ ) {
2210
-
2211
- const target = targets[ i ];
2212
-
2213
- if ( target.POSITION !== undefined ) hasMorphPosition = true;
2214
- if ( target.NORMAL !== undefined ) hasMorphNormal = true;
2215
- if ( target.COLOR_0 !== undefined ) hasMorphColor = true;
2216
-
2217
- if ( hasMorphPosition && hasMorphNormal && hasMorphColor ) break;
2218
-
2219
- }
2220
-
2221
- if ( ! hasMorphPosition && ! hasMorphNormal && ! hasMorphColor ) return Promise.resolve( geometry );
2222
-
2223
- const pendingPositionAccessors = [];
2224
- const pendingNormalAccessors = [];
2225
- const pendingColorAccessors = [];
2226
-
2227
- for ( let i = 0, il = targets.length; i < il; i ++ ) {
2228
-
2229
- const target = targets[ i ];
2230
-
2231
- if ( hasMorphPosition ) {
2232
-
2233
- const pendingAccessor = target.POSITION !== undefined
2234
- ? parser.getDependency( 'accessor', target.POSITION )
2235
- : geometry.attributes.position;
2236
-
2237
- pendingPositionAccessors.push( pendingAccessor );
2238
-
2239
- }
2240
-
2241
- if ( hasMorphNormal ) {
2242
-
2243
- const pendingAccessor = target.NORMAL !== undefined
2244
- ? parser.getDependency( 'accessor', target.NORMAL )
2245
- : geometry.attributes.normal;
2246
-
2247
- pendingNormalAccessors.push( pendingAccessor );
2248
-
2249
- }
2250
-
2251
- if ( hasMorphColor ) {
2252
-
2253
- const pendingAccessor = target.COLOR_0 !== undefined
2254
- ? parser.getDependency( 'accessor', target.COLOR_0 )
2255
- : geometry.attributes.color;
2256
-
2257
- pendingColorAccessors.push( pendingAccessor );
2258
-
2259
- }
2260
-
2261
- }
2262
-
2263
- return Promise.all( [
2264
- Promise.all( pendingPositionAccessors ),
2265
- Promise.all( pendingNormalAccessors ),
2266
- Promise.all( pendingColorAccessors )
2267
- ] ).then( function ( accessors ) {
2268
-
2269
- const morphPositions = accessors[ 0 ];
2270
- const morphNormals = accessors[ 1 ];
2271
- const morphColors = accessors[ 2 ];
2272
-
2273
- if ( hasMorphPosition ) geometry.morphAttributes.position = morphPositions;
2274
- if ( hasMorphNormal ) geometry.morphAttributes.normal = morphNormals;
2275
- if ( hasMorphColor ) geometry.morphAttributes.color = morphColors;
2276
- geometry.morphTargetsRelative = true;
2277
-
2278
- return geometry;
2279
-
2280
- } );
2281
-
2282
- }
2283
-
2284
- /**
2285
- * @param {Mesh} mesh
2286
- * @param {GLTF.Mesh} meshDef
2287
- */
2288
- function updateMorphTargets( mesh, meshDef ) {
2289
-
2290
- mesh.updateMorphTargets();
2291
-
2292
- if ( meshDef.weights !== undefined ) {
2293
-
2294
- for ( let i = 0, il = meshDef.weights.length; i < il; i ++ ) {
2295
-
2296
- mesh.morphTargetInfluences[ i ] = meshDef.weights[ i ];
2297
-
2298
- }
2299
-
2300
- }
2301
-
2302
- // .extras has user-defined data, so check that .extras.targetNames is an array.
2303
- if ( meshDef.extras && Array.isArray( meshDef.extras.targetNames ) ) {
2304
-
2305
- const targetNames = meshDef.extras.targetNames;
2306
-
2307
- if ( mesh.morphTargetInfluences.length === targetNames.length ) {
2308
-
2309
- mesh.morphTargetDictionary = {};
2310
-
2311
- for ( let i = 0, il = targetNames.length; i < il; i ++ ) {
2312
-
2313
- mesh.morphTargetDictionary[ targetNames[ i ] ] = i;
2314
-
2315
- }
2316
-
2317
- } else {
2318
-
2319
- console.warn( 'THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.' );
2320
-
2321
- }
2322
-
2323
- }
2324
-
2325
- }
2326
-
2327
- function createPrimitiveKey( primitiveDef ) {
2328
-
2329
- let geometryKey;
2330
-
2331
- const dracoExtension = primitiveDef.extensions && primitiveDef.extensions[ EXTENSIONS.KHR_DRACO_MESH_COMPRESSION ];
2332
-
2333
- if ( dracoExtension ) {
2334
-
2335
- geometryKey = 'draco:' + dracoExtension.bufferView
2336
- + ':' + dracoExtension.indices
2337
- + ':' + createAttributesKey( dracoExtension.attributes );
2338
-
2339
- } else {
2340
-
2341
- geometryKey = primitiveDef.indices + ':' + createAttributesKey( primitiveDef.attributes ) + ':' + primitiveDef.mode;
2342
-
2343
- }
2344
-
2345
- if ( primitiveDef.targets !== undefined ) {
2346
-
2347
- for ( let i = 0, il = primitiveDef.targets.length; i < il; i ++ ) {
2348
-
2349
- geometryKey += ':' + createAttributesKey( primitiveDef.targets[ i ] );
2350
-
2351
- }
2352
-
2353
- }
2354
-
2355
- return geometryKey;
2356
-
2357
- }
2358
-
2359
- function createAttributesKey( attributes ) {
2360
-
2361
- let attributesKey = '';
2362
-
2363
- const keys = Object.keys( attributes ).sort();
2364
-
2365
- for ( let i = 0, il = keys.length; i < il; i ++ ) {
2366
-
2367
- attributesKey += keys[ i ] + ':' + attributes[ keys[ i ] ] + ';';
2368
-
2369
- }
2370
-
2371
- return attributesKey;
2372
-
2373
- }
2374
-
2375
- function getNormalizedComponentScale( constructor ) {
2376
-
2377
- // Reference:
2378
- // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization#encoding-quantized-data
2379
-
2380
- switch ( constructor ) {
2381
-
2382
- case Int8Array:
2383
- return 1 / 127;
2384
-
2385
- case Uint8Array:
2386
- return 1 / 255;
2387
-
2388
- case Int16Array:
2389
- return 1 / 32767;
2390
-
2391
- case Uint16Array:
2392
- return 1 / 65535;
2393
-
2394
- default:
2395
- throw new Error( 'THREE.GLTFLoader: Unsupported normalized accessor component type.' );
2396
-
2397
- }
2398
-
2399
- }
2400
-
2401
- function getImageURIMimeType( uri ) {
2402
-
2403
- if ( uri.search( /\.jpe?g($|\?)/i ) > 0 || uri.search( /^data\:image\/jpeg/ ) === 0 ) return 'image/jpeg';
2404
- if ( uri.search( /\.webp($|\?)/i ) > 0 || uri.search( /^data\:image\/webp/ ) === 0 ) return 'image/webp';
2405
-
2406
- return 'image/png';
2407
-
2408
- }
2409
-
2410
- const _identityMatrix = new Matrix4();
2411
-
2412
- /* GLTF PARSER */
2413
-
2414
- class GLTFParser {
2415
-
2416
- constructor( json = {}, options = {} ) {
2417
-
2418
- this.json = json;
2419
- this.extensions = {};
2420
- this.plugins = {};
2421
- this.options = options;
2422
-
2423
- // loader object cache
2424
- this.cache = new GLTFRegistry();
2425
-
2426
- // associations between Three.js objects and glTF elements
2427
- this.associations = new Map();
2428
-
2429
- // BufferGeometry caching
2430
- this.primitiveCache = {};
2431
-
2432
- // Node cache
2433
- this.nodeCache = {};
2434
-
2435
- // Object3D instance caches
2436
- this.meshCache = { refs: {}, uses: {} };
2437
- this.cameraCache = { refs: {}, uses: {} };
2438
- this.lightCache = { refs: {}, uses: {} };
2439
-
2440
- this.sourceCache = {};
2441
- this.textureCache = {};
2442
-
2443
- // Track node names, to ensure no duplicates
2444
- this.nodeNamesUsed = {};
2445
-
2446
- // Use an ImageBitmapLoader if imageBitmaps are supported. Moves much of the
2447
- // expensive work of uploading a texture to the GPU off the main thread.
2448
-
2449
- let isSafari = false;
2450
- let isFirefox = false;
2451
- let firefoxVersion = - 1;
2452
-
2453
- if ( typeof navigator !== 'undefined' ) {
2454
-
2455
- isSafari = /^((?!chrome|android).)*safari/i.test( navigator.userAgent ) === true;
2456
- isFirefox = navigator.userAgent.indexOf( 'Firefox' ) > - 1;
2457
- firefoxVersion = isFirefox ? navigator.userAgent.match( /Firefox\/([0-9]+)\./ )[ 1 ] : - 1;
2458
-
2459
- }
2460
-
2461
- if ( typeof createImageBitmap === 'undefined' || isSafari || ( isFirefox && firefoxVersion < 98 ) ) {
2462
-
2463
- this.textureLoader = new TextureLoader( this.options.manager );
2464
-
2465
- } else {
2466
-
2467
- this.textureLoader = new ImageBitmapLoader( this.options.manager );
2468
-
2469
- }
2470
-
2471
- this.textureLoader.setCrossOrigin( this.options.crossOrigin );
2472
- this.textureLoader.setRequestHeader( this.options.requestHeader );
2473
-
2474
- this.fileLoader = new FileLoader( this.options.manager );
2475
- this.fileLoader.setResponseType( 'arraybuffer' );
2476
-
2477
- if ( this.options.crossOrigin === 'use-credentials' ) {
2478
-
2479
- this.fileLoader.setWithCredentials( true );
2480
-
2481
- }
2482
-
2483
- }
2484
-
2485
- setExtensions( extensions ) {
2486
-
2487
- this.extensions = extensions;
2488
-
2489
- }
2490
-
2491
- setPlugins( plugins ) {
2492
-
2493
- this.plugins = plugins;
2494
-
2495
- }
2496
-
2497
- parse( onLoad, onError ) {
2498
-
2499
- const parser = this;
2500
- const json = this.json;
2501
- const extensions = this.extensions;
2502
-
2503
- // Clear the loader cache
2504
- this.cache.removeAll();
2505
- this.nodeCache = {};
2506
-
2507
- // Mark the special nodes/meshes in json for efficient parse
2508
- this._invokeAll( function ( ext ) {
2509
-
2510
- return ext._markDefs && ext._markDefs();
2511
-
2512
- } );
2513
-
2514
- Promise.all( this._invokeAll( function ( ext ) {
2515
-
2516
- return ext.beforeRoot && ext.beforeRoot();
2517
-
2518
- } ) ).then( function () {
2519
-
2520
- return Promise.all( [
2521
-
2522
- parser.getDependencies( 'scene' ),
2523
- parser.getDependencies( 'animation' ),
2524
- parser.getDependencies( 'camera' ),
2525
-
2526
- ] );
2527
-
2528
- } ).then( function ( dependencies ) {
2529
-
2530
- const result = {
2531
- scene: dependencies[ 0 ][ json.scene || 0 ],
2532
- scenes: dependencies[ 0 ],
2533
- animations: dependencies[ 1 ],
2534
- cameras: dependencies[ 2 ],
2535
- asset: json.asset,
2536
- parser: parser,
2537
- userData: {}
2538
- };
2539
-
2540
- addUnknownExtensionsToUserData( extensions, result, json );
2541
-
2542
- assignExtrasToUserData( result, json );
2543
-
2544
- Promise.all( parser._invokeAll( function ( ext ) {
2545
-
2546
- return ext.afterRoot && ext.afterRoot( result );
2547
-
2548
- } ) ).then( function () {
2549
-
2550
- onLoad( result );
2551
-
2552
- } );
2553
-
2554
- } ).catch( onError );
2555
-
2556
- }
2557
-
2558
- /**
2559
- * Marks the special nodes/meshes in json for efficient parse.
2560
- */
2561
- _markDefs() {
2562
-
2563
- const nodeDefs = this.json.nodes || [];
2564
- const skinDefs = this.json.skins || [];
2565
- const meshDefs = this.json.meshes || [];
2566
-
2567
- // Nothing in the node definition indicates whether it is a Bone or an
2568
- // Object3D. Use the skins' joint references to mark bones.
2569
- for ( let skinIndex = 0, skinLength = skinDefs.length; skinIndex < skinLength; skinIndex ++ ) {
2570
-
2571
- const joints = skinDefs[ skinIndex ].joints;
2572
-
2573
- for ( let i = 0, il = joints.length; i < il; i ++ ) {
2574
-
2575
- nodeDefs[ joints[ i ] ].isBone = true;
2576
-
2577
- }
2578
-
2579
- }
2580
-
2581
- // Iterate over all nodes, marking references to shared resources,
2582
- // as well as skeleton joints.
2583
- for ( let nodeIndex = 0, nodeLength = nodeDefs.length; nodeIndex < nodeLength; nodeIndex ++ ) {
2584
-
2585
- const nodeDef = nodeDefs[ nodeIndex ];
2586
-
2587
- if ( nodeDef.mesh !== undefined ) {
2588
-
2589
- this._addNodeRef( this.meshCache, nodeDef.mesh );
2590
-
2591
- // Nothing in the mesh definition indicates whether it is
2592
- // a SkinnedMesh or Mesh. Use the node's mesh reference
2593
- // to mark SkinnedMesh if node has skin.
2594
- if ( nodeDef.skin !== undefined ) {
2595
-
2596
- meshDefs[ nodeDef.mesh ].isSkinnedMesh = true;
2597
-
2598
- }
2599
-
2600
- }
2601
-
2602
- if ( nodeDef.camera !== undefined ) {
2603
-
2604
- this._addNodeRef( this.cameraCache, nodeDef.camera );
2605
-
2606
- }
2607
-
2608
- }
2609
-
2610
- }
2611
-
2612
- /**
2613
- * Counts references to shared node / Object3D resources. These resources
2614
- * can be reused, or "instantiated", at multiple nodes in the scene
2615
- * hierarchy. Mesh, Camera, and Light instances are instantiated and must
2616
- * be marked. Non-scenegraph resources (like Materials, Geometries, and
2617
- * Textures) can be reused directly and are not marked here.
2618
- *
2619
- * Example: CesiumMilkTruck sample model reuses "Wheel" meshes.
2620
- */
2621
- _addNodeRef( cache, index ) {
2622
-
2623
- if ( index === undefined ) return;
2624
-
2625
- if ( cache.refs[ index ] === undefined ) {
2626
-
2627
- cache.refs[ index ] = cache.uses[ index ] = 0;
2628
-
2629
- }
2630
-
2631
- cache.refs[ index ] ++;
2632
-
2633
- }
2634
-
2635
- /** Returns a reference to a shared resource, cloning it if necessary. */
2636
- _getNodeRef( cache, index, object ) {
2637
-
2638
- if ( cache.refs[ index ] <= 1 ) return object;
2639
-
2640
- const ref = object.clone();
2641
-
2642
- // Propagates mappings to the cloned object, prevents mappings on the
2643
- // original object from being lost.
2644
- const updateMappings = ( original, clone ) => {
2645
-
2646
- const mappings = this.associations.get( original );
2647
- if ( mappings != null ) {
2648
-
2649
- this.associations.set( clone, mappings );
2650
-
2651
- }
2652
-
2653
- for ( const [ i, child ] of original.children.entries() ) {
2654
-
2655
- updateMappings( child, clone.children[ i ] );
2656
-
2657
- }
2658
-
2659
- };
2660
-
2661
- updateMappings( object, ref );
2662
-
2663
- ref.name += '_instance_' + ( cache.uses[ index ] ++ );
2664
-
2665
- return ref;
2666
-
2667
- }
2668
-
2669
- _invokeOne( func ) {
2670
-
2671
- const extensions = Object.values( this.plugins );
2672
- extensions.push( this );
2673
-
2674
- for ( let i = 0; i < extensions.length; i ++ ) {
2675
-
2676
- const result = func( extensions[ i ] );
2677
-
2678
- if ( result ) return result;
2679
-
2680
- }
2681
-
2682
- return null;
2683
-
2684
- }
2685
-
2686
- _invokeAll( func ) {
2687
-
2688
- const extensions = Object.values( this.plugins );
2689
- extensions.unshift( this );
2690
-
2691
- const pending = [];
2692
-
2693
- for ( let i = 0; i < extensions.length; i ++ ) {
2694
-
2695
- const result = func( extensions[ i ] );
2696
-
2697
- if ( result ) pending.push( result );
2698
-
2699
- }
2700
-
2701
- return pending;
2702
-
2703
- }
2704
-
2705
- /**
2706
- * Requests the specified dependency asynchronously, with caching.
2707
- * @param {string} type
2708
- * @param {number} index
2709
- * @return {Promise<Object3D|Material|THREE.Texture|AnimationClip|ArrayBuffer|Object>}
2710
- */
2711
- getDependency( type, index ) {
2712
-
2713
- const cacheKey = type + ':' + index;
2714
- let dependency = this.cache.get( cacheKey );
2715
-
2716
- if ( ! dependency ) {
2717
-
2718
- switch ( type ) {
2719
-
2720
- case 'scene':
2721
- dependency = this.loadScene( index );
2722
- break;
2723
-
2724
- case 'node':
2725
- dependency = this._invokeOne( function ( ext ) {
2726
-
2727
- return ext.loadNode && ext.loadNode( index );
2728
-
2729
- } );
2730
- break;
2731
-
2732
- case 'mesh':
2733
- dependency = this._invokeOne( function ( ext ) {
2734
-
2735
- return ext.loadMesh && ext.loadMesh( index );
2736
-
2737
- } );
2738
- break;
2739
-
2740
- case 'accessor':
2741
- dependency = this.loadAccessor( index );
2742
- break;
2743
-
2744
- case 'bufferView':
2745
- dependency = this._invokeOne( function ( ext ) {
2746
-
2747
- return ext.loadBufferView && ext.loadBufferView( index );
2748
-
2749
- } );
2750
- break;
2751
-
2752
- case 'buffer':
2753
- dependency = this.loadBuffer( index );
2754
- break;
2755
-
2756
- case 'material':
2757
- dependency = this._invokeOne( function ( ext ) {
2758
-
2759
- return ext.loadMaterial && ext.loadMaterial( index );
2760
-
2761
- } );
2762
- break;
2763
-
2764
- case 'texture':
2765
- dependency = this._invokeOne( function ( ext ) {
2766
-
2767
- return ext.loadTexture && ext.loadTexture( index );
2768
-
2769
- } );
2770
- break;
2771
-
2772
- case 'skin':
2773
- dependency = this.loadSkin( index );
2774
- break;
2775
-
2776
- case 'animation':
2777
- dependency = this._invokeOne( function ( ext ) {
2778
-
2779
- return ext.loadAnimation && ext.loadAnimation( index );
2780
-
2781
- } );
2782
- break;
2783
-
2784
- case 'camera':
2785
- dependency = this.loadCamera( index );
2786
- break;
2787
-
2788
- default:
2789
- dependency = this._invokeOne( function ( ext ) {
2790
-
2791
- return ext != this && ext.getDependency && ext.getDependency( type, index );
2792
-
2793
- } );
2794
-
2795
- if ( ! dependency ) {
2796
-
2797
- throw new Error( 'Unknown type: ' + type );
2798
-
2799
- }
2800
-
2801
- break;
2802
-
2803
- }
2804
-
2805
- this.cache.add( cacheKey, dependency );
2806
-
2807
- }
2808
-
2809
- return dependency;
2810
-
2811
- }
2812
-
2813
- /**
2814
- * Requests all dependencies of the specified type asynchronously, with caching.
2815
- * @param {string} type
2816
- * @return {Promise<Array<Object>>}
2817
- */
2818
- getDependencies( type ) {
2819
-
2820
- let dependencies = this.cache.get( type );
2821
-
2822
- if ( ! dependencies ) {
2823
-
2824
- const parser = this;
2825
- const defs = this.json[ type + ( type === 'mesh' ? 'es' : 's' ) ] || [];
2826
-
2827
- dependencies = Promise.all( defs.map( function ( def, index ) {
2828
-
2829
- return parser.getDependency( type, index );
2830
-
2831
- } ) );
2832
-
2833
- this.cache.add( type, dependencies );
2834
-
2835
- }
2836
-
2837
- return dependencies;
2838
-
2839
- }
2840
-
2841
- /**
2842
- * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
2843
- * @param {number} bufferIndex
2844
- * @return {Promise<ArrayBuffer>}
2845
- */
2846
- loadBuffer( bufferIndex ) {
2847
-
2848
- const bufferDef = this.json.buffers[ bufferIndex ];
2849
- const loader = this.fileLoader;
2850
-
2851
- if ( bufferDef.type && bufferDef.type !== 'arraybuffer' ) {
2852
-
2853
- throw new Error( 'THREE.GLTFLoader: ' + bufferDef.type + ' buffer type is not supported.' );
2854
-
2855
- }
2856
-
2857
- // If present, GLB container is required to be the first buffer.
2858
- if ( bufferDef.uri === undefined && bufferIndex === 0 ) {
2859
-
2860
- return Promise.resolve( this.extensions[ EXTENSIONS.KHR_BINARY_GLTF ].body );
2861
-
2862
- }
2863
-
2864
- const options = this.options;
2865
-
2866
- return new Promise( function ( resolve, reject ) {
2867
-
2868
- loader.load( LoaderUtils.resolveURL( bufferDef.uri, options.path ), resolve, undefined, function () {
2869
-
2870
- reject( new Error( 'THREE.GLTFLoader: Failed to load buffer "' + bufferDef.uri + '".' ) );
2871
-
2872
- } );
2873
-
2874
- } );
2875
-
2876
- }
2877
-
2878
- /**
2879
- * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
2880
- * @param {number} bufferViewIndex
2881
- * @return {Promise<ArrayBuffer>}
2882
- */
2883
- loadBufferView( bufferViewIndex ) {
2884
-
2885
- const bufferViewDef = this.json.bufferViews[ bufferViewIndex ];
2886
-
2887
- return this.getDependency( 'buffer', bufferViewDef.buffer ).then( function ( buffer ) {
2888
-
2889
- const byteLength = bufferViewDef.byteLength || 0;
2890
- const byteOffset = bufferViewDef.byteOffset || 0;
2891
- return buffer.slice( byteOffset, byteOffset + byteLength );
2892
-
2893
- } );
2894
-
2895
- }
2896
-
2897
- /**
2898
- * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#accessors
2899
- * @param {number} accessorIndex
2900
- * @return {Promise<BufferAttribute|InterleavedBufferAttribute>}
2901
- */
2902
- loadAccessor( accessorIndex ) {
2903
-
2904
- const parser = this;
2905
- const json = this.json;
2906
-
2907
- const accessorDef = this.json.accessors[ accessorIndex ];
2908
-
2909
- if ( accessorDef.bufferView === undefined && accessorDef.sparse === undefined ) {
2910
-
2911
- const itemSize = WEBGL_TYPE_SIZES[ accessorDef.type ];
2912
- const TypedArray = WEBGL_COMPONENT_TYPES[ accessorDef.componentType ];
2913
- const normalized = accessorDef.normalized === true;
2914
-
2915
- const array = new TypedArray( accessorDef.count * itemSize );
2916
- return Promise.resolve( new BufferAttribute( array, itemSize, normalized ) );
2917
-
2918
- }
2919
-
2920
- const pendingBufferViews = [];
2921
-
2922
- if ( accessorDef.bufferView !== undefined ) {
2923
-
2924
- pendingBufferViews.push( this.getDependency( 'bufferView', accessorDef.bufferView ) );
2925
-
2926
- } else {
2927
-
2928
- pendingBufferViews.push( null );
2929
-
2930
- }
2931
-
2932
- if ( accessorDef.sparse !== undefined ) {
2933
-
2934
- pendingBufferViews.push( this.getDependency( 'bufferView', accessorDef.sparse.indices.bufferView ) );
2935
- pendingBufferViews.push( this.getDependency( 'bufferView', accessorDef.sparse.values.bufferView ) );
2936
-
2937
- }
2938
-
2939
- return Promise.all( pendingBufferViews ).then( function ( bufferViews ) {
2940
-
2941
- const bufferView = bufferViews[ 0 ];
2942
-
2943
- const itemSize = WEBGL_TYPE_SIZES[ accessorDef.type ];
2944
- const TypedArray = WEBGL_COMPONENT_TYPES[ accessorDef.componentType ];
2945
-
2946
- // For VEC3: itemSize is 3, elementBytes is 4, itemBytes is 12.
2947
- const elementBytes = TypedArray.BYTES_PER_ELEMENT;
2948
- const itemBytes = elementBytes * itemSize;
2949
- const byteOffset = accessorDef.byteOffset || 0;
2950
- const byteStride = accessorDef.bufferView !== undefined ? json.bufferViews[ accessorDef.bufferView ].byteStride : undefined;
2951
- const normalized = accessorDef.normalized === true;
2952
- let array, bufferAttribute;
2953
-
2954
- // The buffer is not interleaved if the stride is the item size in bytes.
2955
- if ( byteStride && byteStride !== itemBytes ) {
2956
-
2957
- // Each "slice" of the buffer, as defined by 'count' elements of 'byteStride' bytes, gets its own InterleavedBuffer
2958
- // This makes sure that IBA.count reflects accessor.count properly
2959
- const ibSlice = Math.floor( byteOffset / byteStride );
2960
- const ibCacheKey = 'InterleavedBuffer:' + accessorDef.bufferView + ':' + accessorDef.componentType + ':' + ibSlice + ':' + accessorDef.count;
2961
- let ib = parser.cache.get( ibCacheKey );
2962
-
2963
- if ( ! ib ) {
2964
-
2965
- array = new TypedArray( bufferView, ibSlice * byteStride, accessorDef.count * byteStride / elementBytes );
2966
-
2967
- // Integer parameters to IB/IBA are in array elements, not bytes.
2968
- ib = new InterleavedBuffer( array, byteStride / elementBytes );
2969
-
2970
- parser.cache.add( ibCacheKey, ib );
2971
-
2972
- }
2973
-
2974
- bufferAttribute = new InterleavedBufferAttribute( ib, itemSize, ( byteOffset % byteStride ) / elementBytes, normalized );
2975
-
2976
- } else {
2977
-
2978
- if ( bufferView === null ) {
2979
-
2980
- array = new TypedArray( accessorDef.count * itemSize );
2981
-
2982
- } else {
2983
-
2984
- array = new TypedArray( bufferView, byteOffset, accessorDef.count * itemSize );
2985
-
2986
- }
2987
-
2988
- bufferAttribute = new BufferAttribute( array, itemSize, normalized );
2989
-
2990
- }
2991
-
2992
- // https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#sparse-accessors
2993
- if ( accessorDef.sparse !== undefined ) {
2994
-
2995
- const itemSizeIndices = WEBGL_TYPE_SIZES.SCALAR;
2996
- const TypedArrayIndices = WEBGL_COMPONENT_TYPES[ accessorDef.sparse.indices.componentType ];
2997
-
2998
- const byteOffsetIndices = accessorDef.sparse.indices.byteOffset || 0;
2999
- const byteOffsetValues = accessorDef.sparse.values.byteOffset || 0;
3000
-
3001
- const sparseIndices = new TypedArrayIndices( bufferViews[ 1 ], byteOffsetIndices, accessorDef.sparse.count * itemSizeIndices );
3002
- const sparseValues = new TypedArray( bufferViews[ 2 ], byteOffsetValues, accessorDef.sparse.count * itemSize );
3003
-
3004
- if ( bufferView !== null ) {
3005
-
3006
- // Avoid modifying the original ArrayBuffer, if the bufferView wasn't initialized with zeroes.
3007
- bufferAttribute = new BufferAttribute( bufferAttribute.array.slice(), bufferAttribute.itemSize, bufferAttribute.normalized );
3008
-
3009
- }
3010
-
3011
- for ( let i = 0, il = sparseIndices.length; i < il; i ++ ) {
3012
-
3013
- const index = sparseIndices[ i ];
3014
-
3015
- bufferAttribute.setX( index, sparseValues[ i * itemSize ] );
3016
- if ( itemSize >= 2 ) bufferAttribute.setY( index, sparseValues[ i * itemSize + 1 ] );
3017
- if ( itemSize >= 3 ) bufferAttribute.setZ( index, sparseValues[ i * itemSize + 2 ] );
3018
- if ( itemSize >= 4 ) bufferAttribute.setW( index, sparseValues[ i * itemSize + 3 ] );
3019
- if ( itemSize >= 5 ) throw new Error( 'THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.' );
3020
-
3021
- }
3022
-
3023
- }
3024
-
3025
- return bufferAttribute;
3026
-
3027
- } );
3028
-
3029
- }
3030
-
3031
- /**
3032
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#textures
3033
- * @param {number} textureIndex
3034
- * @return {Promise<THREE.Texture|null>}
3035
- */
3036
- loadTexture( textureIndex ) {
3037
-
3038
- const json = this.json;
3039
- const options = this.options;
3040
- const textureDef = json.textures[ textureIndex ];
3041
- const sourceIndex = textureDef.source;
3042
- const sourceDef = json.images[ sourceIndex ];
3043
-
3044
- let loader = this.textureLoader;
3045
-
3046
- if ( sourceDef.uri ) {
3047
-
3048
- const handler = options.manager.getHandler( sourceDef.uri );
3049
- if ( handler !== null ) loader = handler;
3050
-
3051
- }
3052
-
3053
- return this.loadTextureImage( textureIndex, sourceIndex, loader );
3054
-
3055
- }
3056
-
3057
- loadTextureImage( textureIndex, sourceIndex, loader ) {
3058
-
3059
- const parser = this;
3060
- const json = this.json;
3061
-
3062
- const textureDef = json.textures[ textureIndex ];
3063
- const sourceDef = json.images[ sourceIndex ];
3064
-
3065
- const cacheKey = ( sourceDef.uri || sourceDef.bufferView ) + ':' + textureDef.sampler;
3066
-
3067
- if ( this.textureCache[ cacheKey ] ) {
3068
-
3069
- // See https://github.com/mrdoob/three.js/issues/21559.
3070
- return this.textureCache[ cacheKey ];
3071
-
3072
- }
3073
-
3074
- const promise = this.loadImageSource( sourceIndex, loader ).then( function ( texture ) {
3075
-
3076
- texture.flipY = false;
3077
-
3078
- texture.name = textureDef.name || sourceDef.name || '';
3079
-
3080
- if ( texture.name === '' && typeof sourceDef.uri === 'string' && sourceDef.uri.startsWith( 'data:image/' ) === false ) {
3081
-
3082
- texture.name = sourceDef.uri;
3083
-
3084
- }
3085
-
3086
- const samplers = json.samplers || {};
3087
- const sampler = samplers[ textureDef.sampler ] || {};
3088
-
3089
- texture.magFilter = WEBGL_FILTERS[ sampler.magFilter ] || LinearFilter;
3090
- texture.minFilter = WEBGL_FILTERS[ sampler.minFilter ] || LinearMipmapLinearFilter;
3091
- texture.wrapS = WEBGL_WRAPPINGS[ sampler.wrapS ] || RepeatWrapping;
3092
- texture.wrapT = WEBGL_WRAPPINGS[ sampler.wrapT ] || RepeatWrapping;
3093
-
3094
- parser.associations.set( texture, { textures: textureIndex } );
3095
-
3096
- return texture;
3097
-
3098
- } ).catch( function () {
3099
-
3100
- return null;
3101
-
3102
- } );
3103
-
3104
- this.textureCache[ cacheKey ] = promise;
3105
-
3106
- return promise;
3107
-
3108
- }
3109
-
3110
- loadImageSource( sourceIndex, loader ) {
3111
-
3112
- const parser = this;
3113
- const json = this.json;
3114
- const options = this.options;
3115
-
3116
- if ( this.sourceCache[ sourceIndex ] !== undefined ) {
3117
-
3118
- return this.sourceCache[ sourceIndex ].then( ( texture ) => texture.clone() );
3119
-
3120
- }
3121
-
3122
- const sourceDef = json.images[ sourceIndex ];
3123
-
3124
- const URL = self.URL || self.webkitURL;
3125
-
3126
- let sourceURI = sourceDef.uri || '';
3127
- let isObjectURL = false;
3128
-
3129
- if ( sourceDef.bufferView !== undefined ) {
3130
-
3131
- // Load binary image data from bufferView, if provided.
3132
-
3133
- sourceURI = parser.getDependency( 'bufferView', sourceDef.bufferView ).then( function ( bufferView ) {
3134
-
3135
- isObjectURL = true;
3136
- const blob = new Blob( [ bufferView ], { type: sourceDef.mimeType } );
3137
- sourceURI = URL.createObjectURL( blob );
3138
- return sourceURI;
3139
-
3140
- } );
3141
-
3142
- } else if ( sourceDef.uri === undefined ) {
3143
-
3144
- throw new Error( 'THREE.GLTFLoader: Image ' + sourceIndex + ' is missing URI and bufferView' );
3145
-
3146
- }
3147
-
3148
- const promise = Promise.resolve( sourceURI ).then( function ( sourceURI ) {
3149
-
3150
- return new Promise( function ( resolve, reject ) {
3151
-
3152
- let onLoad = resolve;
3153
-
3154
- if ( loader.isImageBitmapLoader === true ) {
3155
-
3156
- onLoad = function ( imageBitmap ) {
3157
-
3158
- const texture = new Texture( imageBitmap );
3159
- texture.needsUpdate = true;
3160
-
3161
- resolve( texture );
3162
-
3163
- };
3164
-
3165
- }
3166
-
3167
- loader.load( LoaderUtils.resolveURL( sourceURI, options.path ), onLoad, undefined, reject );
3168
-
3169
- } );
3170
-
3171
- } ).then( function ( texture ) {
3172
-
3173
- // Clean up resources and configure Texture.
3174
-
3175
- if ( isObjectURL === true ) {
3176
-
3177
- URL.revokeObjectURL( sourceURI );
3178
-
3179
- }
3180
-
3181
- texture.userData.mimeType = sourceDef.mimeType || getImageURIMimeType( sourceDef.uri );
3182
-
3183
- return texture;
3184
-
3185
- } ).catch( function ( error ) {
3186
-
3187
- console.error( 'THREE.GLTFLoader: Couldn\'t load texture', sourceURI );
3188
- throw error;
3189
-
3190
- } );
3191
-
3192
- this.sourceCache[ sourceIndex ] = promise;
3193
- return promise;
3194
-
3195
- }
3196
-
3197
- /**
3198
- * Asynchronously assigns a texture to the given material parameters.
3199
- * @param {Object} materialParams
3200
- * @param {string} mapName
3201
- * @param {Object} mapDef
3202
- * @return {Promise<Texture>}
3203
- */
3204
- assignTexture( materialParams, mapName, mapDef, colorSpace ) {
3205
-
3206
- const parser = this;
3207
-
3208
- return this.getDependency( 'texture', mapDef.index ).then( function ( texture ) {
3209
-
3210
- if ( ! texture ) return null;
3211
-
3212
- if ( mapDef.texCoord !== undefined && mapDef.texCoord > 0 ) {
3213
-
3214
- texture = texture.clone();
3215
- texture.channel = mapDef.texCoord;
3216
-
3217
- }
3218
-
3219
- if ( parser.extensions[ EXTENSIONS.KHR_TEXTURE_TRANSFORM ] ) {
3220
-
3221
- const transform = mapDef.extensions !== undefined ? mapDef.extensions[ EXTENSIONS.KHR_TEXTURE_TRANSFORM ] : undefined;
3222
-
3223
- if ( transform ) {
3224
-
3225
- const gltfReference = parser.associations.get( texture );
3226
- texture = parser.extensions[ EXTENSIONS.KHR_TEXTURE_TRANSFORM ].extendTexture( texture, transform );
3227
- parser.associations.set( texture, gltfReference );
3228
-
3229
- }
3230
-
3231
- }
3232
-
3233
- if ( colorSpace !== undefined ) {
3234
-
3235
- texture.colorSpace = colorSpace;
3236
-
3237
- }
3238
-
3239
- materialParams[ mapName ] = texture;
3240
-
3241
- return texture;
3242
-
3243
- } );
3244
-
3245
- }
3246
-
3247
- /**
3248
- * Assigns final material to a Mesh, Line, or Points instance. The instance
3249
- * already has a material (generated from the glTF material options alone)
3250
- * but reuse of the same glTF material may require multiple threejs materials
3251
- * to accommodate different primitive types, defines, etc. New materials will
3252
- * be created if necessary, and reused from a cache.
3253
- * @param {Object3D} mesh Mesh, Line, or Points instance.
3254
- */
3255
- assignFinalMaterial( mesh ) {
3256
-
3257
- const geometry = mesh.geometry;
3258
- let material = mesh.material;
3259
-
3260
- const useDerivativeTangents = geometry.attributes.tangent === undefined;
3261
- const useVertexColors = geometry.attributes.color !== undefined;
3262
- const useFlatShading = geometry.attributes.normal === undefined;
3263
-
3264
- if ( mesh.isPoints ) {
3265
-
3266
- const cacheKey = 'PointsMaterial:' + material.uuid;
3267
-
3268
- let pointsMaterial = this.cache.get( cacheKey );
3269
-
3270
- if ( ! pointsMaterial ) {
3271
-
3272
- pointsMaterial = new PointsMaterial();
3273
- Material.prototype.copy.call( pointsMaterial, material );
3274
- pointsMaterial.color.copy( material.color );
3275
- pointsMaterial.map = material.map;
3276
- pointsMaterial.sizeAttenuation = false; // glTF spec says points should be 1px
3277
-
3278
- this.cache.add( cacheKey, pointsMaterial );
3279
-
3280
- }
3281
-
3282
- material = pointsMaterial;
3283
-
3284
- } else if ( mesh.isLine ) {
3285
-
3286
- const cacheKey = 'LineBasicMaterial:' + material.uuid;
3287
-
3288
- let lineMaterial = this.cache.get( cacheKey );
3289
-
3290
- if ( ! lineMaterial ) {
3291
-
3292
- lineMaterial = new LineBasicMaterial();
3293
- Material.prototype.copy.call( lineMaterial, material );
3294
- lineMaterial.color.copy( material.color );
3295
- lineMaterial.map = material.map;
3296
-
3297
- this.cache.add( cacheKey, lineMaterial );
3298
-
3299
- }
3300
-
3301
- material = lineMaterial;
3302
-
3303
- }
3304
-
3305
- // Clone the material if it will be modified
3306
- if ( useDerivativeTangents || useVertexColors || useFlatShading ) {
3307
-
3308
- let cacheKey = 'ClonedMaterial:' + material.uuid + ':';
3309
-
3310
- if ( useDerivativeTangents ) cacheKey += 'derivative-tangents:';
3311
- if ( useVertexColors ) cacheKey += 'vertex-colors:';
3312
- if ( useFlatShading ) cacheKey += 'flat-shading:';
3313
-
3314
- let cachedMaterial = this.cache.get( cacheKey );
3315
-
3316
- if ( ! cachedMaterial ) {
3317
-
3318
- cachedMaterial = material.clone();
3319
-
3320
- if ( useVertexColors ) cachedMaterial.vertexColors = true;
3321
- if ( useFlatShading ) cachedMaterial.flatShading = true;
3322
-
3323
- if ( useDerivativeTangents ) {
3324
-
3325
- // https://github.com/mrdoob/three.js/issues/11438#issuecomment-507003995
3326
- if ( cachedMaterial.normalScale ) cachedMaterial.normalScale.y *= - 1;
3327
- if ( cachedMaterial.clearcoatNormalScale ) cachedMaterial.clearcoatNormalScale.y *= - 1;
3328
-
3329
- }
3330
-
3331
- this.cache.add( cacheKey, cachedMaterial );
3332
-
3333
- this.associations.set( cachedMaterial, this.associations.get( material ) );
3334
-
3335
- }
3336
-
3337
- material = cachedMaterial;
3338
-
3339
- }
3340
-
3341
- mesh.material = material;
3342
-
3343
- }
3344
-
3345
- getMaterialType( /* materialIndex */ ) {
3346
-
3347
- return MeshStandardMaterial;
3348
-
3349
- }
3350
-
3351
- /**
3352
- * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#materials
3353
- * @param {number} materialIndex
3354
- * @return {Promise<Material>}
3355
- */
3356
- loadMaterial( materialIndex ) {
3357
-
3358
- const parser = this;
3359
- const json = this.json;
3360
- const extensions = this.extensions;
3361
- const materialDef = json.materials[ materialIndex ];
3362
-
3363
- let materialType;
3364
- const materialParams = {};
3365
- const materialExtensions = materialDef.extensions || {};
3366
-
3367
- const pending = [];
3368
-
3369
- if ( materialExtensions[ EXTENSIONS.KHR_MATERIALS_UNLIT ] ) {
3370
-
3371
- const kmuExtension = extensions[ EXTENSIONS.KHR_MATERIALS_UNLIT ];
3372
- materialType = kmuExtension.getMaterialType();
3373
- pending.push( kmuExtension.extendParams( materialParams, materialDef, parser ) );
3374
-
3375
- } else {
3376
-
3377
- // Specification:
3378
- // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#metallic-roughness-material
3379
-
3380
- const metallicRoughness = materialDef.pbrMetallicRoughness || {};
3381
-
3382
- materialParams.color = new Color( 1.0, 1.0, 1.0 );
3383
- materialParams.opacity = 1.0;
3384
-
3385
- if ( Array.isArray( metallicRoughness.baseColorFactor ) ) {
3386
-
3387
- const array = metallicRoughness.baseColorFactor;
3388
-
3389
- materialParams.color.fromArray( array );
3390
- materialParams.opacity = array[ 3 ];
3391
-
3392
- }
3393
-
3394
- if ( metallicRoughness.baseColorTexture !== undefined ) {
3395
-
3396
- pending.push( parser.assignTexture( materialParams, 'map', metallicRoughness.baseColorTexture, SRGBColorSpace ) );
3397
-
3398
- }
3399
-
3400
- materialParams.metalness = metallicRoughness.metallicFactor !== undefined ? metallicRoughness.metallicFactor : 1.0;
3401
- materialParams.roughness = metallicRoughness.roughnessFactor !== undefined ? metallicRoughness.roughnessFactor : 1.0;
3402
-
3403
- if ( metallicRoughness.metallicRoughnessTexture !== undefined ) {
3404
-
3405
- pending.push( parser.assignTexture( materialParams, 'metalnessMap', metallicRoughness.metallicRoughnessTexture ) );
3406
- pending.push( parser.assignTexture( materialParams, 'roughnessMap', metallicRoughness.metallicRoughnessTexture ) );
3407
-
3408
- }
3409
-
3410
- materialType = this._invokeOne( function ( ext ) {
3411
-
3412
- return ext.getMaterialType && ext.getMaterialType( materialIndex );
3413
-
3414
- } );
3415
-
3416
- pending.push( Promise.all( this._invokeAll( function ( ext ) {
3417
-
3418
- return ext.extendMaterialParams && ext.extendMaterialParams( materialIndex, materialParams );
3419
-
3420
- } ) ) );
3421
-
3422
- }
3423
-
3424
- if ( materialDef.doubleSided === true ) {
3425
-
3426
- materialParams.side = DoubleSide;
3427
-
3428
- }
3429
-
3430
- const alphaMode = materialDef.alphaMode || ALPHA_MODES.OPAQUE;
3431
-
3432
- if ( alphaMode === ALPHA_MODES.BLEND ) {
3433
-
3434
- materialParams.transparent = true;
3435
-
3436
- // See: https://github.com/mrdoob/three.js/issues/17706
3437
- materialParams.depthWrite = false;
3438
-
3439
- } else {
3440
-
3441
- materialParams.transparent = false;
3442
-
3443
- if ( alphaMode === ALPHA_MODES.MASK ) {
3444
-
3445
- materialParams.alphaTest = materialDef.alphaCutoff !== undefined ? materialDef.alphaCutoff : 0.5;
3446
-
3447
- }
3448
-
3449
- }
3450
-
3451
- if ( materialDef.normalTexture !== undefined && materialType !== MeshBasicMaterial ) {
3452
-
3453
- pending.push( parser.assignTexture( materialParams, 'normalMap', materialDef.normalTexture ) );
3454
-
3455
- materialParams.normalScale = new Vector2( 1, 1 );
3456
-
3457
- if ( materialDef.normalTexture.scale !== undefined ) {
3458
-
3459
- const scale = materialDef.normalTexture.scale;
3460
-
3461
- materialParams.normalScale.set( scale, scale );
3462
-
3463
- }
3464
-
3465
- }
3466
-
3467
- if ( materialDef.occlusionTexture !== undefined && materialType !== MeshBasicMaterial ) {
3468
-
3469
- pending.push( parser.assignTexture( materialParams, 'aoMap', materialDef.occlusionTexture ) );
3470
-
3471
- if ( materialDef.occlusionTexture.strength !== undefined ) {
3472
-
3473
- materialParams.aoMapIntensity = materialDef.occlusionTexture.strength;
3474
-
3475
- }
3476
-
3477
- }
3478
-
3479
- if ( materialDef.emissiveFactor !== undefined && materialType !== MeshBasicMaterial ) {
3480
-
3481
- materialParams.emissive = new Color().fromArray( materialDef.emissiveFactor );
3482
-
3483
- }
3484
-
3485
- if ( materialDef.emissiveTexture !== undefined && materialType !== MeshBasicMaterial ) {
3486
-
3487
- pending.push( parser.assignTexture( materialParams, 'emissiveMap', materialDef.emissiveTexture, SRGBColorSpace ) );
3488
-
3489
- }
3490
-
3491
- return Promise.all( pending ).then( function () {
3492
-
3493
- const material = new materialType( materialParams );
3494
-
3495
- if ( materialDef.name ) material.name = materialDef.name;
3496
-
3497
- assignExtrasToUserData( material, materialDef );
3498
-
3499
- parser.associations.set( material, { materials: materialIndex } );
3500
-
3501
- if ( materialDef.extensions ) addUnknownExtensionsToUserData( extensions, material, materialDef );
3502
-
3503
- return material;
3504
-
3505
- } );
3506
-
3507
- }
3508
-
3509
- /** When Object3D instances are targeted by animation, they need unique names. */
3510
- createUniqueName( originalName ) {
3511
-
3512
- const sanitizedName = PropertyBinding.sanitizeNodeName( originalName || '' );
3513
-
3514
- if ( sanitizedName in this.nodeNamesUsed ) {
3515
-
3516
- return sanitizedName + '_' + ( ++ this.nodeNamesUsed[ sanitizedName ] );
3517
-
3518
- } else {
3519
-
3520
- this.nodeNamesUsed[ sanitizedName ] = 0;
3521
-
3522
- return sanitizedName;
3523
-
3524
- }
3525
-
3526
- }
3527
-
3528
- /**
3529
- * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#geometry
3530
- *
3531
- * Creates BufferGeometries from primitives.
3532
- *
3533
- * @param {Array<GLTF.Primitive>} primitives
3534
- * @return {Promise<Array<BufferGeometry>>}
3535
- */
3536
- loadGeometries( primitives ) {
3537
-
3538
- const parser = this;
3539
- const extensions = this.extensions;
3540
- const cache = this.primitiveCache;
3541
-
3542
- function createDracoPrimitive( primitive ) {
3543
-
3544
- return extensions[ EXTENSIONS.KHR_DRACO_MESH_COMPRESSION ]
3545
- .decodePrimitive( primitive, parser )
3546
- .then( function ( geometry ) {
3547
-
3548
- return addPrimitiveAttributes( geometry, primitive, parser );
3549
-
3550
- } );
3551
-
3552
- }
3553
-
3554
- const pending = [];
3555
-
3556
- for ( let i = 0, il = primitives.length; i < il; i ++ ) {
3557
-
3558
- const primitive = primitives[ i ];
3559
- const cacheKey = createPrimitiveKey( primitive );
3560
-
3561
- // See if we've already created this geometry
3562
- const cached = cache[ cacheKey ];
3563
-
3564
- if ( cached ) {
3565
-
3566
- // Use the cached geometry if it exists
3567
- pending.push( cached.promise );
3568
-
3569
- } else {
3570
-
3571
- let geometryPromise;
3572
-
3573
- if ( primitive.extensions && primitive.extensions[ EXTENSIONS.KHR_DRACO_MESH_COMPRESSION ] ) {
3574
-
3575
- // Use DRACO geometry if available
3576
- geometryPromise = createDracoPrimitive( primitive );
3577
-
3578
- } else {
3579
-
3580
- // Otherwise create a new geometry
3581
- geometryPromise = addPrimitiveAttributes( new BufferGeometry(), primitive, parser );
3582
-
3583
- }
3584
-
3585
- // Cache this geometry
3586
- cache[ cacheKey ] = { primitive: primitive, promise: geometryPromise };
3587
-
3588
- pending.push( geometryPromise );
3589
-
3590
- }
3591
-
3592
- }
3593
-
3594
- return Promise.all( pending );
3595
-
3596
- }
3597
-
3598
- /**
3599
- * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#meshes
3600
- * @param {number} meshIndex
3601
- * @return {Promise<Group|Mesh|SkinnedMesh>}
3602
- */
3603
- loadMesh( meshIndex ) {
3604
-
3605
- const parser = this;
3606
- const json = this.json;
3607
- const extensions = this.extensions;
3608
-
3609
- const meshDef = json.meshes[ meshIndex ];
3610
- const primitives = meshDef.primitives;
3611
-
3612
- const pending = [];
3613
-
3614
- for ( let i = 0, il = primitives.length; i < il; i ++ ) {
3615
-
3616
- const material = primitives[ i ].material === undefined
3617
- ? createDefaultMaterial( this.cache )
3618
- : this.getDependency( 'material', primitives[ i ].material );
3619
-
3620
- pending.push( material );
3621
-
3622
- }
3623
-
3624
- pending.push( parser.loadGeometries( primitives ) );
3625
-
3626
- return Promise.all( pending ).then( function ( results ) {
3627
-
3628
- const materials = results.slice( 0, results.length - 1 );
3629
- const geometries = results[ results.length - 1 ];
3630
-
3631
- const meshes = [];
3632
-
3633
- for ( let i = 0, il = geometries.length; i < il; i ++ ) {
3634
-
3635
- const geometry = geometries[ i ];
3636
- const primitive = primitives[ i ];
3637
-
3638
- // 1. create Mesh
3639
-
3640
- let mesh;
3641
-
3642
- const material = materials[ i ];
3643
-
3644
- if ( primitive.mode === WEBGL_CONSTANTS.TRIANGLES ||
3645
- primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP ||
3646
- primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN ||
3647
- primitive.mode === undefined ) {
3648
-
3649
- // .isSkinnedMesh isn't in glTF spec. See ._markDefs()
3650
- mesh = meshDef.isSkinnedMesh === true
3651
- ? new SkinnedMesh( geometry, material )
3652
- : new Mesh( geometry, material );
3653
-
3654
- if ( mesh.isSkinnedMesh === true ) {
3655
-
3656
- // normalize skin weights to fix malformed assets (see #15319)
3657
- mesh.normalizeSkinWeights();
3658
-
3659
- }
3660
-
3661
- if ( primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP ) {
3662
-
3663
- mesh.geometry = toTrianglesDrawMode( mesh.geometry, TriangleStripDrawMode );
3664
-
3665
- } else if ( primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN ) {
3666
-
3667
- mesh.geometry = toTrianglesDrawMode( mesh.geometry, TriangleFanDrawMode );
3668
-
3669
- }
3670
-
3671
- } else if ( primitive.mode === WEBGL_CONSTANTS.LINES ) {
3672
-
3673
- mesh = new LineSegments( geometry, material );
3674
-
3675
- } else if ( primitive.mode === WEBGL_CONSTANTS.LINE_STRIP ) {
3676
-
3677
- mesh = new Line( geometry, material );
3678
-
3679
- } else if ( primitive.mode === WEBGL_CONSTANTS.LINE_LOOP ) {
3680
-
3681
- mesh = new LineLoop( geometry, material );
3682
-
3683
- } else if ( primitive.mode === WEBGL_CONSTANTS.POINTS ) {
3684
-
3685
- mesh = new Points( geometry, material );
3686
-
3687
- } else {
3688
-
3689
- throw new Error( 'THREE.GLTFLoader: Primitive mode unsupported: ' + primitive.mode );
3690
-
3691
- }
3692
-
3693
- if ( Object.keys( mesh.geometry.morphAttributes ).length > 0 ) {
3694
-
3695
- updateMorphTargets( mesh, meshDef );
3696
-
3697
- }
3698
-
3699
- mesh.name = parser.createUniqueName( meshDef.name || ( 'mesh_' + meshIndex ) );
3700
-
3701
- assignExtrasToUserData( mesh, meshDef );
3702
-
3703
- if ( primitive.extensions ) addUnknownExtensionsToUserData( extensions, mesh, primitive );
3704
-
3705
- parser.assignFinalMaterial( mesh );
3706
-
3707
- meshes.push( mesh );
3708
-
3709
- }
3710
-
3711
- for ( let i = 0, il = meshes.length; i < il; i ++ ) {
3712
-
3713
- parser.associations.set( meshes[ i ], {
3714
- meshes: meshIndex,
3715
- primitives: i
3716
- } );
3717
-
3718
- }
3719
-
3720
- if ( meshes.length === 1 ) {
3721
-
3722
- if ( meshDef.extensions ) addUnknownExtensionsToUserData( extensions, meshes[ 0 ], meshDef );
3723
-
3724
- return meshes[ 0 ];
3725
-
3726
- }
3727
-
3728
- const group = new Group();
3729
-
3730
- if ( meshDef.extensions ) addUnknownExtensionsToUserData( extensions, group, meshDef );
3731
-
3732
- parser.associations.set( group, { meshes: meshIndex } );
3733
-
3734
- for ( let i = 0, il = meshes.length; i < il; i ++ ) {
3735
-
3736
- group.add( meshes[ i ] );
3737
-
3738
- }
3739
-
3740
- return group;
3741
-
3742
- } );
3743
-
3744
- }
3745
-
3746
- /**
3747
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#cameras
3748
- * @param {number} cameraIndex
3749
- * @return {Promise<THREE.Camera>}
3750
- */
3751
- loadCamera( cameraIndex ) {
3752
-
3753
- let camera;
3754
- const cameraDef = this.json.cameras[ cameraIndex ];
3755
- const params = cameraDef[ cameraDef.type ];
3756
-
3757
- if ( ! params ) {
3758
-
3759
- console.warn( 'THREE.GLTFLoader: Missing camera parameters.' );
3760
- return;
3761
-
3762
- }
3763
-
3764
- if ( cameraDef.type === 'perspective' ) {
3765
-
3766
- camera = new PerspectiveCamera( MathUtils.radToDeg( params.yfov ), params.aspectRatio || 1, params.znear || 1, params.zfar || 2e6 );
3767
-
3768
- } else if ( cameraDef.type === 'orthographic' ) {
3769
-
3770
- camera = new OrthographicCamera( - params.xmag, params.xmag, params.ymag, - params.ymag, params.znear, params.zfar );
3771
-
3772
- }
3773
-
3774
- if ( cameraDef.name ) camera.name = this.createUniqueName( cameraDef.name );
3775
-
3776
- assignExtrasToUserData( camera, cameraDef );
3777
-
3778
- return Promise.resolve( camera );
3779
-
3780
- }
3781
-
3782
- /**
3783
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins
3784
- * @param {number} skinIndex
3785
- * @return {Promise<Skeleton>}
3786
- */
3787
- loadSkin( skinIndex ) {
3788
-
3789
- const skinDef = this.json.skins[ skinIndex ];
3790
-
3791
- const pending = [];
3792
-
3793
- for ( let i = 0, il = skinDef.joints.length; i < il; i ++ ) {
3794
-
3795
- pending.push( this._loadNodeShallow( skinDef.joints[ i ] ) );
3796
-
3797
- }
3798
-
3799
- if ( skinDef.inverseBindMatrices !== undefined ) {
3800
-
3801
- pending.push( this.getDependency( 'accessor', skinDef.inverseBindMatrices ) );
3802
-
3803
- } else {
3804
-
3805
- pending.push( null );
3806
-
3807
- }
3808
-
3809
- return Promise.all( pending ).then( function ( results ) {
3810
-
3811
- const inverseBindMatrices = results.pop();
3812
- const jointNodes = results;
3813
-
3814
- // Note that bones (joint nodes) may or may not be in the
3815
- // scene graph at this time.
3816
-
3817
- const bones = [];
3818
- const boneInverses = [];
3819
-
3820
- for ( let i = 0, il = jointNodes.length; i < il; i ++ ) {
3821
-
3822
- const jointNode = jointNodes[ i ];
3823
-
3824
- if ( jointNode ) {
3825
-
3826
- bones.push( jointNode );
3827
-
3828
- const mat = new Matrix4();
3829
-
3830
- if ( inverseBindMatrices !== null ) {
3831
-
3832
- mat.fromArray( inverseBindMatrices.array, i * 16 );
3833
-
3834
- }
3835
-
3836
- boneInverses.push( mat );
3837
-
3838
- } else {
3839
-
3840
- console.warn( 'THREE.GLTFLoader: Joint "%s" could not be found.', skinDef.joints[ i ] );
3841
-
3842
- }
3843
-
3844
- }
3845
-
3846
- return new Skeleton( bones, boneInverses );
3847
-
3848
- } );
3849
-
3850
- }
3851
-
3852
- /**
3853
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#animations
3854
- * @param {number} animationIndex
3855
- * @return {Promise<AnimationClip>}
3856
- */
3857
- loadAnimation( animationIndex ) {
3858
-
3859
- const json = this.json;
3860
- const parser = this;
3861
-
3862
- const animationDef = json.animations[ animationIndex ];
3863
- const animationName = animationDef.name ? animationDef.name : 'animation_' + animationIndex;
3864
-
3865
- const pendingNodes = [];
3866
- const pendingInputAccessors = [];
3867
- const pendingOutputAccessors = [];
3868
- const pendingSamplers = [];
3869
- const pendingTargets = [];
3870
-
3871
- for ( let i = 0, il = animationDef.channels.length; i < il; i ++ ) {
3872
-
3873
- const channel = animationDef.channels[ i ];
3874
- const sampler = animationDef.samplers[ channel.sampler ];
3875
- const target = channel.target;
3876
- const name = target.node;
3877
- const input = animationDef.parameters !== undefined ? animationDef.parameters[ sampler.input ] : sampler.input;
3878
- const output = animationDef.parameters !== undefined ? animationDef.parameters[ sampler.output ] : sampler.output;
3879
-
3880
- if ( target.node === undefined ) continue;
3881
-
3882
- pendingNodes.push( this.getDependency( 'node', name ) );
3883
- pendingInputAccessors.push( this.getDependency( 'accessor', input ) );
3884
- pendingOutputAccessors.push( this.getDependency( 'accessor', output ) );
3885
- pendingSamplers.push( sampler );
3886
- pendingTargets.push( target );
3887
-
3888
- }
3889
-
3890
- return Promise.all( [
3891
-
3892
- Promise.all( pendingNodes ),
3893
- Promise.all( pendingInputAccessors ),
3894
- Promise.all( pendingOutputAccessors ),
3895
- Promise.all( pendingSamplers ),
3896
- Promise.all( pendingTargets )
3897
-
3898
- ] ).then( function ( dependencies ) {
3899
-
3900
- const nodes = dependencies[ 0 ];
3901
- const inputAccessors = dependencies[ 1 ];
3902
- const outputAccessors = dependencies[ 2 ];
3903
- const samplers = dependencies[ 3 ];
3904
- const targets = dependencies[ 4 ];
3905
-
3906
- const tracks = [];
3907
-
3908
- for ( let i = 0, il = nodes.length; i < il; i ++ ) {
3909
-
3910
- const node = nodes[ i ];
3911
- const inputAccessor = inputAccessors[ i ];
3912
- const outputAccessor = outputAccessors[ i ];
3913
- const sampler = samplers[ i ];
3914
- const target = targets[ i ];
3915
-
3916
- if ( node === undefined ) continue;
3917
-
3918
- if ( node.updateMatrix ) {
3919
-
3920
- node.updateMatrix();
3921
-
3922
- }
3923
-
3924
- const createdTracks = parser._createAnimationTracks( node, inputAccessor, outputAccessor, sampler, target );
3925
-
3926
- if ( createdTracks ) {
3927
-
3928
- for ( let k = 0; k < createdTracks.length; k ++ ) {
3929
-
3930
- tracks.push( createdTracks[ k ] );
3931
-
3932
- }
3933
-
3934
- }
3935
-
3936
- }
3937
-
3938
- return new AnimationClip( animationName, undefined, tracks );
3939
-
3940
- } );
3941
-
3942
- }
3943
-
3944
- createNodeMesh( nodeIndex ) {
3945
-
3946
- const json = this.json;
3947
- const parser = this;
3948
- const nodeDef = json.nodes[ nodeIndex ];
3949
-
3950
- if ( nodeDef.mesh === undefined ) return null;
3951
-
3952
- return parser.getDependency( 'mesh', nodeDef.mesh ).then( function ( mesh ) {
3953
-
3954
- const node = parser._getNodeRef( parser.meshCache, nodeDef.mesh, mesh );
3955
-
3956
- // if weights are provided on the node, override weights on the mesh.
3957
- if ( nodeDef.weights !== undefined ) {
3958
-
3959
- node.traverse( function ( o ) {
3960
-
3961
- if ( ! o.isMesh ) return;
3962
-
3963
- for ( let i = 0, il = nodeDef.weights.length; i < il; i ++ ) {
3964
-
3965
- o.morphTargetInfluences[ i ] = nodeDef.weights[ i ];
3966
-
3967
- }
3968
-
3969
- } );
3970
-
3971
- }
3972
-
3973
- return node;
3974
-
3975
- } );
3976
-
3977
- }
3978
-
3979
- /**
3980
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#nodes-and-hierarchy
3981
- * @param {number} nodeIndex
3982
- * @return {Promise<Object3D>}
3983
- */
3984
- loadNode( nodeIndex ) {
3985
-
3986
- const json = this.json;
3987
- const parser = this;
3988
-
3989
- const nodeDef = json.nodes[ nodeIndex ];
3990
-
3991
- const nodePending = parser._loadNodeShallow( nodeIndex );
3992
-
3993
- const childPending = [];
3994
- const childrenDef = nodeDef.children || [];
3995
-
3996
- for ( let i = 0, il = childrenDef.length; i < il; i ++ ) {
3997
-
3998
- childPending.push( parser.getDependency( 'node', childrenDef[ i ] ) );
3999
-
4000
- }
4001
-
4002
- const skeletonPending = nodeDef.skin === undefined
4003
- ? Promise.resolve( null )
4004
- : parser.getDependency( 'skin', nodeDef.skin );
4005
-
4006
- return Promise.all( [
4007
- nodePending,
4008
- Promise.all( childPending ),
4009
- skeletonPending
4010
- ] ).then( function ( results ) {
4011
-
4012
- const node = results[ 0 ];
4013
- const children = results[ 1 ];
4014
- const skeleton = results[ 2 ];
4015
-
4016
- if ( skeleton !== null ) {
4017
-
4018
- // This full traverse should be fine because
4019
- // child glTF nodes have not been added to this node yet.
4020
- node.traverse( function ( mesh ) {
4021
-
4022
- if ( ! mesh.isSkinnedMesh ) return;
4023
-
4024
- mesh.bind( skeleton, _identityMatrix );
4025
-
4026
- } );
4027
-
4028
- }
4029
-
4030
- for ( let i = 0, il = children.length; i < il; i ++ ) {
4031
-
4032
- node.add( children[ i ] );
4033
-
4034
- }
4035
-
4036
- return node;
4037
-
4038
- } );
4039
-
4040
- }
4041
-
4042
- // ._loadNodeShallow() parses a single node.
4043
- // skin and child nodes are created and added in .loadNode() (no '_' prefix).
4044
- _loadNodeShallow( nodeIndex ) {
4045
-
4046
- const json = this.json;
4047
- const extensions = this.extensions;
4048
- const parser = this;
4049
-
4050
- // This method is called from .loadNode() and .loadSkin().
4051
- // Cache a node to avoid duplication.
4052
-
4053
- if ( this.nodeCache[ nodeIndex ] !== undefined ) {
4054
-
4055
- return this.nodeCache[ nodeIndex ];
4056
-
4057
- }
4058
-
4059
- const nodeDef = json.nodes[ nodeIndex ];
4060
-
4061
- // reserve node's name before its dependencies, so the root has the intended name.
4062
- const nodeName = nodeDef.name ? parser.createUniqueName( nodeDef.name ) : '';
4063
-
4064
- const pending = [];
4065
-
4066
- const meshPromise = parser._invokeOne( function ( ext ) {
4067
-
4068
- return ext.createNodeMesh && ext.createNodeMesh( nodeIndex );
4069
-
4070
- } );
4071
-
4072
- if ( meshPromise ) {
4073
-
4074
- pending.push( meshPromise );
4075
-
4076
- }
4077
-
4078
- if ( nodeDef.camera !== undefined ) {
4079
-
4080
- pending.push( parser.getDependency( 'camera', nodeDef.camera ).then( function ( camera ) {
4081
-
4082
- return parser._getNodeRef( parser.cameraCache, nodeDef.camera, camera );
4083
-
4084
- } ) );
4085
-
4086
- }
4087
-
4088
- parser._invokeAll( function ( ext ) {
4089
-
4090
- return ext.createNodeAttachment && ext.createNodeAttachment( nodeIndex );
4091
-
4092
- } ).forEach( function ( promise ) {
4093
-
4094
- pending.push( promise );
4095
-
4096
- } );
4097
-
4098
- this.nodeCache[ nodeIndex ] = Promise.all( pending ).then( function ( objects ) {
4099
-
4100
- let node;
4101
-
4102
- // .isBone isn't in glTF spec. See ._markDefs
4103
- if ( nodeDef.isBone === true ) {
4104
-
4105
- node = new Bone();
4106
-
4107
- } else if ( objects.length > 1 ) {
4108
-
4109
- node = new Group();
4110
-
4111
- } else if ( objects.length === 1 ) {
4112
-
4113
- node = objects[ 0 ];
4114
-
4115
- } else {
4116
-
4117
- node = new Object3D();
4118
-
4119
- }
4120
-
4121
- if ( node !== objects[ 0 ] ) {
4122
-
4123
- for ( let i = 0, il = objects.length; i < il; i ++ ) {
4124
-
4125
- node.add( objects[ i ] );
4126
-
4127
- }
4128
-
4129
- }
4130
-
4131
- if ( nodeDef.name ) {
4132
-
4133
- node.userData.name = nodeDef.name;
4134
- node.name = nodeName;
4135
-
4136
- }
4137
-
4138
- assignExtrasToUserData( node, nodeDef );
4139
-
4140
- if ( nodeDef.extensions ) addUnknownExtensionsToUserData( extensions, node, nodeDef );
4141
-
4142
- if ( nodeDef.matrix !== undefined ) {
4143
-
4144
- const matrix = new Matrix4();
4145
- matrix.fromArray( nodeDef.matrix );
4146
- node.applyMatrix4( matrix );
4147
-
4148
- } else {
4149
-
4150
- if ( nodeDef.translation !== undefined ) {
4151
-
4152
- node.position.fromArray( nodeDef.translation );
4153
-
4154
- }
4155
-
4156
- if ( nodeDef.rotation !== undefined ) {
4157
-
4158
- node.quaternion.fromArray( nodeDef.rotation );
4159
-
4160
- }
4161
-
4162
- if ( nodeDef.scale !== undefined ) {
4163
-
4164
- node.scale.fromArray( nodeDef.scale );
4165
-
4166
- }
4167
-
4168
- }
4169
-
4170
- if ( ! parser.associations.has( node ) ) {
4171
-
4172
- parser.associations.set( node, {} );
4173
-
4174
- }
4175
-
4176
- parser.associations.get( node ).nodes = nodeIndex;
4177
-
4178
- return node;
4179
-
4180
- } );
4181
-
4182
- return this.nodeCache[ nodeIndex ];
4183
-
4184
- }
4185
-
4186
- /**
4187
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#scenes
4188
- * @param {number} sceneIndex
4189
- * @return {Promise<Group>}
4190
- */
4191
- loadScene( sceneIndex ) {
4192
-
4193
- const extensions = this.extensions;
4194
- const sceneDef = this.json.scenes[ sceneIndex ];
4195
- const parser = this;
4196
-
4197
- // Loader returns Group, not Scene.
4198
- // See: https://github.com/mrdoob/three.js/issues/18342#issuecomment-578981172
4199
- const scene = new Group();
4200
- if ( sceneDef.name ) scene.name = parser.createUniqueName( sceneDef.name );
4201
-
4202
- assignExtrasToUserData( scene, sceneDef );
4203
-
4204
- if ( sceneDef.extensions ) addUnknownExtensionsToUserData( extensions, scene, sceneDef );
4205
-
4206
- const nodeIds = sceneDef.nodes || [];
4207
-
4208
- const pending = [];
4209
-
4210
- for ( let i = 0, il = nodeIds.length; i < il; i ++ ) {
4211
-
4212
- pending.push( parser.getDependency( 'node', nodeIds[ i ] ) );
4213
-
4214
- }
4215
-
4216
- return Promise.all( pending ).then( function ( nodes ) {
4217
-
4218
- for ( let i = 0, il = nodes.length; i < il; i ++ ) {
4219
-
4220
- scene.add( nodes[ i ] );
4221
-
4222
- }
4223
-
4224
- // Removes dangling associations, associations that reference a node that
4225
- // didn't make it into the scene.
4226
- const reduceAssociations = ( node ) => {
4227
-
4228
- const reducedAssociations = new Map();
4229
-
4230
- for ( const [ key, value ] of parser.associations ) {
4231
-
4232
- if ( key instanceof Material || key instanceof Texture ) {
4233
-
4234
- reducedAssociations.set( key, value );
4235
-
4236
- }
4237
-
4238
- }
4239
-
4240
- node.traverse( ( node ) => {
4241
-
4242
- const mappings = parser.associations.get( node );
4243
-
4244
- if ( mappings != null ) {
4245
-
4246
- reducedAssociations.set( node, mappings );
4247
-
4248
- }
4249
-
4250
- } );
4251
-
4252
- return reducedAssociations;
4253
-
4254
- };
4255
-
4256
- parser.associations = reduceAssociations( scene );
4257
-
4258
- return scene;
4259
-
4260
- } );
4261
-
4262
- }
4263
-
4264
- _createAnimationTracks( node, inputAccessor, outputAccessor, sampler, target ) {
4265
-
4266
- const tracks = [];
4267
-
4268
- const targetName = node.name ? node.name : node.uuid;
4269
- const targetNames = [];
4270
-
4271
- if ( PATH_PROPERTIES[ target.path ] === PATH_PROPERTIES.weights ) {
4272
-
4273
- node.traverse( function ( object ) {
4274
-
4275
- if ( object.morphTargetInfluences ) {
4276
-
4277
- targetNames.push( object.name ? object.name : object.uuid );
4278
-
4279
- }
4280
-
4281
- } );
4282
-
4283
- } else {
4284
-
4285
- targetNames.push( targetName );
4286
-
4287
- }
4288
-
4289
- let TypedKeyframeTrack;
4290
-
4291
- switch ( PATH_PROPERTIES[ target.path ] ) {
4292
-
4293
- case PATH_PROPERTIES.weights:
4294
-
4295
- TypedKeyframeTrack = NumberKeyframeTrack;
4296
- break;
4297
-
4298
- case PATH_PROPERTIES.rotation:
4299
-
4300
- TypedKeyframeTrack = QuaternionKeyframeTrack;
4301
- break;
4302
-
4303
- case PATH_PROPERTIES.position:
4304
- case PATH_PROPERTIES.scale:
4305
-
4306
- TypedKeyframeTrack = VectorKeyframeTrack;
4307
- break;
4308
-
4309
- default:
4310
-
4311
- switch ( outputAccessor.itemSize ) {
4312
-
4313
- case 1:
4314
- TypedKeyframeTrack = NumberKeyframeTrack;
4315
- break;
4316
- case 2:
4317
- case 3:
4318
- default:
4319
- TypedKeyframeTrack = VectorKeyframeTrack;
4320
- break;
4321
-
4322
- }
4323
-
4324
- break;
4325
-
4326
- }
4327
-
4328
- const interpolation = sampler.interpolation !== undefined ? INTERPOLATION[ sampler.interpolation ] : InterpolateLinear;
4329
-
4330
-
4331
- const outputArray = this._getArrayFromAccessor( outputAccessor );
4332
-
4333
- for ( let j = 0, jl = targetNames.length; j < jl; j ++ ) {
4334
-
4335
- const track = new TypedKeyframeTrack(
4336
- targetNames[ j ] + '.' + PATH_PROPERTIES[ target.path ],
4337
- inputAccessor.array,
4338
- outputArray,
4339
- interpolation
4340
- );
4341
-
4342
- // Override interpolation with custom factory method.
4343
- if ( sampler.interpolation === 'CUBICSPLINE' ) {
4344
-
4345
- this._createCubicSplineTrackInterpolant( track );
4346
-
4347
- }
4348
-
4349
- tracks.push( track );
4350
-
4351
- }
4352
-
4353
- return tracks;
4354
-
4355
- }
4356
-
4357
- _getArrayFromAccessor( accessor ) {
4358
-
4359
- let outputArray = accessor.array;
4360
-
4361
- if ( accessor.normalized ) {
4362
-
4363
- const scale = getNormalizedComponentScale( outputArray.constructor );
4364
- const scaled = new Float32Array( outputArray.length );
4365
-
4366
- for ( let j = 0, jl = outputArray.length; j < jl; j ++ ) {
4367
-
4368
- scaled[ j ] = outputArray[ j ] * scale;
4369
-
4370
- }
4371
-
4372
- outputArray = scaled;
4373
-
4374
- }
4375
-
4376
- return outputArray;
4377
-
4378
- }
4379
-
4380
- _createCubicSplineTrackInterpolant( track ) {
4381
-
4382
- track.createInterpolant = function InterpolantFactoryMethodGLTFCubicSpline( result ) {
4383
-
4384
- // A CUBICSPLINE keyframe in glTF has three output values for each input value,
4385
- // representing inTangent, splineVertex, and outTangent. As a result, track.getValueSize()
4386
- // must be divided by three to get the interpolant's sampleSize argument.
4387
-
4388
- const interpolantType = ( this instanceof QuaternionKeyframeTrack ) ? GLTFCubicSplineQuaternionInterpolant : GLTFCubicSplineInterpolant;
4389
-
4390
- return new interpolantType( this.times, this.values, this.getValueSize() / 3, result );
4391
-
4392
- };
4393
-
4394
- // Mark as CUBICSPLINE. `track.getInterpolation()` doesn't support custom interpolants.
4395
- track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline = true;
4396
-
4397
- }
4398
-
4399
- }
4400
-
4401
- /**
4402
- * @param {BufferGeometry} geometry
4403
- * @param {GLTF.Primitive} primitiveDef
4404
- * @param {GLTFParser} parser
4405
- */
4406
- function computeBounds( geometry, primitiveDef, parser ) {
4407
-
4408
- const attributes = primitiveDef.attributes;
4409
-
4410
- const box = new Box3();
4411
-
4412
- if ( attributes.POSITION !== undefined ) {
4413
-
4414
- const accessor = parser.json.accessors[ attributes.POSITION ];
4415
-
4416
- const min = accessor.min;
4417
- const max = accessor.max;
4418
-
4419
- // glTF requires 'min' and 'max', but VRM (which extends glTF) currently ignores that requirement.
4420
-
4421
- if ( min !== undefined && max !== undefined ) {
4422
-
4423
- box.set(
4424
- new Vector3( min[ 0 ], min[ 1 ], min[ 2 ] ),
4425
- new Vector3( max[ 0 ], max[ 1 ], max[ 2 ] )
4426
- );
4427
-
4428
- if ( accessor.normalized ) {
4429
-
4430
- const boxScale = getNormalizedComponentScale( WEBGL_COMPONENT_TYPES[ accessor.componentType ] );
4431
- box.min.multiplyScalar( boxScale );
4432
- box.max.multiplyScalar( boxScale );
4433
-
4434
- }
4435
-
4436
- } else {
4437
-
4438
- console.warn( 'THREE.GLTFLoader: Missing min/max properties for accessor POSITION.' );
4439
-
4440
- return;
4441
-
4442
- }
4443
-
4444
- } else {
4445
-
4446
- return;
4447
-
4448
- }
4449
-
4450
- const targets = primitiveDef.targets;
4451
-
4452
- if ( targets !== undefined ) {
4453
-
4454
- const maxDisplacement = new Vector3();
4455
- const vector = new Vector3();
4456
-
4457
- for ( let i = 0, il = targets.length; i < il; i ++ ) {
4458
-
4459
- const target = targets[ i ];
4460
-
4461
- if ( target.POSITION !== undefined ) {
4462
-
4463
- const accessor = parser.json.accessors[ target.POSITION ];
4464
- const min = accessor.min;
4465
- const max = accessor.max;
4466
-
4467
- // glTF requires 'min' and 'max', but VRM (which extends glTF) currently ignores that requirement.
4468
-
4469
- if ( min !== undefined && max !== undefined ) {
4470
-
4471
- // we need to get max of absolute components because target weight is [-1,1]
4472
- vector.setX( Math.max( Math.abs( min[ 0 ] ), Math.abs( max[ 0 ] ) ) );
4473
- vector.setY( Math.max( Math.abs( min[ 1 ] ), Math.abs( max[ 1 ] ) ) );
4474
- vector.setZ( Math.max( Math.abs( min[ 2 ] ), Math.abs( max[ 2 ] ) ) );
4475
-
4476
-
4477
- if ( accessor.normalized ) {
4478
-
4479
- const boxScale = getNormalizedComponentScale( WEBGL_COMPONENT_TYPES[ accessor.componentType ] );
4480
- vector.multiplyScalar( boxScale );
4481
-
4482
- }
4483
-
4484
- // Note: this assumes that the sum of all weights is at most 1. This isn't quite correct - it's more conservative
4485
- // to assume that each target can have a max weight of 1. However, for some use cases - notably, when morph targets
4486
- // are used to implement key-frame animations and as such only two are active at a time - this results in very large
4487
- // boxes. So for now we make a box that's sometimes a touch too small but is hopefully mostly of reasonable size.
4488
- maxDisplacement.max( vector );
4489
-
4490
- } else {
4491
-
4492
- console.warn( 'THREE.GLTFLoader: Missing min/max properties for accessor POSITION.' );
4493
-
4494
- }
4495
-
4496
- }
4497
-
4498
- }
4499
-
4500
- // As per comment above this box isn't conservative, but has a reasonable size for a very large number of morph targets.
4501
- box.expandByVector( maxDisplacement );
4502
-
4503
- }
4504
-
4505
- geometry.boundingBox = box;
4506
-
4507
- const sphere = new Sphere();
4508
-
4509
- box.getCenter( sphere.center );
4510
- sphere.radius = box.min.distanceTo( box.max ) / 2;
4511
-
4512
- geometry.boundingSphere = sphere;
4513
-
4514
- }
4515
-
4516
- /**
4517
- * @param {BufferGeometry} geometry
4518
- * @param {GLTF.Primitive} primitiveDef
4519
- * @param {GLTFParser} parser
4520
- * @return {Promise<BufferGeometry>}
4521
- */
4522
- function addPrimitiveAttributes( geometry, primitiveDef, parser ) {
4523
-
4524
- const attributes = primitiveDef.attributes;
4525
-
4526
- const pending = [];
4527
-
4528
- function assignAttributeAccessor( accessorIndex, attributeName ) {
4529
-
4530
- return parser.getDependency( 'accessor', accessorIndex )
4531
- .then( function ( accessor ) {
4532
-
4533
- geometry.setAttribute( attributeName, accessor );
4534
-
4535
- } );
4536
-
4537
- }
4538
-
4539
- for ( const gltfAttributeName in attributes ) {
4540
-
4541
- const threeAttributeName = ATTRIBUTES[ gltfAttributeName ] || gltfAttributeName.toLowerCase();
4542
-
4543
- // Skip attributes already provided by e.g. Draco extension.
4544
- if ( threeAttributeName in geometry.attributes ) continue;
4545
-
4546
- pending.push( assignAttributeAccessor( attributes[ gltfAttributeName ], threeAttributeName ) );
4547
-
4548
- }
4549
-
4550
- if ( primitiveDef.indices !== undefined && ! geometry.index ) {
4551
-
4552
- const accessor = parser.getDependency( 'accessor', primitiveDef.indices ).then( function ( accessor ) {
4553
-
4554
- geometry.setIndex( accessor );
4555
-
4556
- } );
4557
-
4558
- pending.push( accessor );
4559
-
4560
- }
4561
-
4562
- assignExtrasToUserData( geometry, primitiveDef );
4563
-
4564
- computeBounds( geometry, primitiveDef, parser );
4565
-
4566
- return Promise.all( pending ).then( function () {
4567
-
4568
- return primitiveDef.targets !== undefined
4569
- ? addMorphTargets( geometry, primitiveDef.targets, parser )
4570
- : geometry;
4571
-
4572
- } );
4573
-
4574
- }
4575
-
4576
- export { GLTFLoader };