voxljs 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (369) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +111 -2
  3. package/dist/audio/SpatialAudioEngine.d.ts +47 -0
  4. package/dist/audio/SpatialAudioEngine.js +264 -0
  5. package/dist/audio/SpatialAudioEngine.js.map +1 -0
  6. package/dist/audio/index.d.ts +1 -0
  7. package/dist/audio/index.js +2 -0
  8. package/dist/audio/index.js.map +1 -0
  9. package/dist/cameras/Camera.d.ts +64 -0
  10. package/dist/cameras/Camera.js +201 -0
  11. package/dist/cameras/Camera.js.map +1 -0
  12. package/dist/compat/loaderCompat.d.ts +224 -0
  13. package/dist/compat/loaderCompat.js +805 -0
  14. package/dist/compat/loaderCompat.js.map +1 -0
  15. package/dist/constants.d.ts +246 -0
  16. package/dist/constants.js +263 -0
  17. package/dist/constants.js.map +1 -0
  18. package/dist/core/BufferAttribute.d.ts +96 -0
  19. package/dist/core/BufferAttribute.js +338 -0
  20. package/dist/core/BufferAttribute.js.map +1 -0
  21. package/dist/core/BufferGeometry.d.ts +118 -0
  22. package/dist/core/BufferGeometry.js +506 -0
  23. package/dist/core/BufferGeometry.js.map +1 -0
  24. package/dist/core/Clock.d.ts +12 -0
  25. package/dist/core/Clock.js +42 -0
  26. package/dist/core/Clock.js.map +1 -0
  27. package/dist/core/EventDispatcher.d.ts +13 -0
  28. package/dist/core/EventDispatcher.js +46 -0
  29. package/dist/core/EventDispatcher.js.map +1 -0
  30. package/dist/core/Group.d.ts +5 -0
  31. package/dist/core/Group.js +9 -0
  32. package/dist/core/Group.js.map +1 -0
  33. package/dist/core/InstancedBufferAttribute.d.ts +13 -0
  34. package/dist/core/InstancedBufferAttribute.js +28 -0
  35. package/dist/core/InstancedBufferAttribute.js.map +1 -0
  36. package/dist/core/Mesh.d.ts +80 -0
  37. package/dist/core/Mesh.js +234 -0
  38. package/dist/core/Mesh.js.map +1 -0
  39. package/dist/core/Object3D.d.ts +132 -0
  40. package/dist/core/Object3D.js +562 -0
  41. package/dist/core/Object3D.js.map +1 -0
  42. package/dist/core/constants.d.ts +3 -0
  43. package/dist/core/constants.js +2 -0
  44. package/dist/core/constants.js.map +1 -0
  45. package/dist/core/index.d.ts +9 -0
  46. package/dist/core/index.js +10 -0
  47. package/dist/core/index.js.map +1 -0
  48. package/dist/geometries/Geometries.d.ts +78 -0
  49. package/dist/geometries/Geometries.js +584 -0
  50. package/dist/geometries/Geometries.js.map +1 -0
  51. package/dist/index.d.ts +33 -0
  52. package/dist/index.js +34 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/input/InputManager.d.ts +58 -0
  55. package/dist/input/InputManager.js +170 -0
  56. package/dist/input/InputManager.js.map +1 -0
  57. package/dist/input/index.d.ts +1 -0
  58. package/dist/input/index.js +2 -0
  59. package/dist/input/index.js.map +1 -0
  60. package/dist/lights/Lights.d.ts +74 -0
  61. package/dist/lights/Lights.js +125 -0
  62. package/dist/lights/Lights.js.map +1 -0
  63. package/dist/materials/ExtendedMaterials.d.ts +106 -0
  64. package/dist/materials/ExtendedMaterials.js +91 -0
  65. package/dist/materials/ExtendedMaterials.js.map +1 -0
  66. package/dist/materials/LineBasicMaterial.d.ts +20 -0
  67. package/dist/materials/LineBasicMaterial.js +39 -0
  68. package/dist/materials/LineBasicMaterial.js.map +1 -0
  69. package/dist/materials/Material.d.ts +131 -0
  70. package/dist/materials/Material.js +289 -0
  71. package/dist/materials/Material.js.map +1 -0
  72. package/dist/materials/MeshBasicMaterial.d.ts +44 -0
  73. package/dist/materials/MeshBasicMaterial.js +76 -0
  74. package/dist/materials/MeshBasicMaterial.js.map +1 -0
  75. package/dist/materials/MeshLambertMaterial.d.ts +68 -0
  76. package/dist/materials/MeshLambertMaterial.js +103 -0
  77. package/dist/materials/MeshLambertMaterial.js.map +1 -0
  78. package/dist/materials/PointsMaterial.d.ts +20 -0
  79. package/dist/materials/PointsMaterial.js +39 -0
  80. package/dist/materials/PointsMaterial.js.map +1 -0
  81. package/dist/materials/ShaderMaterial.d.ts +45 -0
  82. package/dist/materials/ShaderMaterial.js +175 -0
  83. package/dist/materials/ShaderMaterial.js.map +1 -0
  84. package/dist/materials/index.d.ts +6 -0
  85. package/dist/materials/index.js +7 -0
  86. package/dist/materials/index.js.map +1 -0
  87. package/dist/math/Box3.d.ts +54 -0
  88. package/dist/math/Box3.js +256 -0
  89. package/dist/math/Box3.js.map +1 -0
  90. package/dist/math/Color.d.ts +57 -0
  91. package/dist/math/Color.js +394 -0
  92. package/dist/math/Color.js.map +1 -0
  93. package/dist/math/Euler.d.ts +33 -0
  94. package/dist/math/Euler.js +192 -0
  95. package/dist/math/Euler.js.map +1 -0
  96. package/dist/math/Frustum.d.ts +44 -0
  97. package/dist/math/Frustum.js +174 -0
  98. package/dist/math/Frustum.js.map +1 -0
  99. package/dist/math/MathUtils.d.ts +48 -0
  100. package/dist/math/MathUtils.js +169 -0
  101. package/dist/math/MathUtils.js.map +1 -0
  102. package/dist/math/Matrix3.d.ts +32 -0
  103. package/dist/math/Matrix3.js +221 -0
  104. package/dist/math/Matrix3.js.map +1 -0
  105. package/dist/math/Matrix4.d.ts +55 -0
  106. package/dist/math/Matrix4.js +630 -0
  107. package/dist/math/Matrix4.js.map +1 -0
  108. package/dist/math/Noise.d.ts +43 -0
  109. package/dist/math/Noise.js +219 -0
  110. package/dist/math/Noise.js.map +1 -0
  111. package/dist/math/Plane.d.ts +35 -0
  112. package/dist/math/Plane.js +115 -0
  113. package/dist/math/Plane.js.map +1 -0
  114. package/dist/math/Quaternion.d.ts +48 -0
  115. package/dist/math/Quaternion.js +394 -0
  116. package/dist/math/Quaternion.js.map +1 -0
  117. package/dist/math/Ray.d.ts +30 -0
  118. package/dist/math/Ray.js +284 -0
  119. package/dist/math/Ray.js.map +1 -0
  120. package/dist/math/Sphere.d.ts +34 -0
  121. package/dist/math/Sphere.js +152 -0
  122. package/dist/math/Sphere.js.map +1 -0
  123. package/dist/math/Vector2.d.ts +63 -0
  124. package/dist/math/Vector2.js +268 -0
  125. package/dist/math/Vector2.js.map +1 -0
  126. package/dist/math/Vector3.d.ts +93 -0
  127. package/dist/math/Vector3.js +461 -0
  128. package/dist/math/Vector3.js.map +1 -0
  129. package/dist/math/Vector4.d.ts +67 -0
  130. package/dist/math/Vector4.js +435 -0
  131. package/dist/math/Vector4.js.map +1 -0
  132. package/dist/math/constants.d.ts +71 -0
  133. package/dist/math/constants.js +44 -0
  134. package/dist/math/constants.js.map +1 -0
  135. package/dist/math/index.d.ts +15 -0
  136. package/dist/math/index.js +16 -0
  137. package/dist/math/index.js.map +1 -0
  138. package/dist/net/RemotePlayerAvatar.d.ts +46 -0
  139. package/dist/net/RemotePlayerAvatar.js +151 -0
  140. package/dist/net/RemotePlayerAvatar.js.map +1 -0
  141. package/dist/net/VoxelMultiplayerServer.d.ts +68 -0
  142. package/dist/net/VoxelMultiplayerServer.js +345 -0
  143. package/dist/net/VoxelMultiplayerServer.js.map +1 -0
  144. package/dist/net/VoxelNetClient.d.ts +137 -0
  145. package/dist/net/VoxelNetClient.js +536 -0
  146. package/dist/net/VoxelNetClient.js.map +1 -0
  147. package/dist/net/index.d.ts +4 -0
  148. package/dist/net/index.js +5 -0
  149. package/dist/net/index.js.map +1 -0
  150. package/dist/net/protocol.d.ts +129 -0
  151. package/dist/net/protocol.js +177 -0
  152. package/dist/net/protocol.js.map +1 -0
  153. package/dist/objects/ExtendedObjects.d.ts +36 -0
  154. package/dist/objects/ExtendedObjects.js +212 -0
  155. package/dist/objects/ExtendedObjects.js.map +1 -0
  156. package/dist/objects/InstancedMesh.d.ts +36 -0
  157. package/dist/objects/InstancedMesh.js +190 -0
  158. package/dist/objects/InstancedMesh.js.map +1 -0
  159. package/dist/objects/Line.d.ts +12 -0
  160. package/dist/objects/Line.js +194 -0
  161. package/dist/objects/Line.js.map +1 -0
  162. package/dist/objects/LineSegments.d.ts +8 -0
  163. package/dist/objects/LineSegments.js +42 -0
  164. package/dist/objects/LineSegments.js.map +1 -0
  165. package/dist/objects/ParticleSystem.d.ts +81 -0
  166. package/dist/objects/ParticleSystem.js +239 -0
  167. package/dist/objects/ParticleSystem.js.map +1 -0
  168. package/dist/objects/Raycaster.d.ts +113 -0
  169. package/dist/objects/Raycaster.js +253 -0
  170. package/dist/objects/Raycaster.js.map +1 -0
  171. package/dist/objects/index.d.ts +5 -0
  172. package/dist/objects/index.js +6 -0
  173. package/dist/objects/index.js.map +1 -0
  174. package/dist/perf/DynamicResolutionScaler.d.ts +73 -0
  175. package/dist/perf/DynamicResolutionScaler.js +142 -0
  176. package/dist/perf/DynamicResolutionScaler.js.map +1 -0
  177. package/dist/perf/PerfProfiler.d.ts +121 -0
  178. package/dist/perf/PerfProfiler.js +290 -0
  179. package/dist/perf/PerfProfiler.js.map +1 -0
  180. package/dist/perf/index.d.ts +2 -0
  181. package/dist/perf/index.js +3 -0
  182. package/dist/perf/index.js.map +1 -0
  183. package/dist/physics/StructuralIntegritySolver.d.ts +50 -0
  184. package/dist/physics/StructuralIntegritySolver.js +135 -0
  185. package/dist/physics/StructuralIntegritySolver.js.map +1 -0
  186. package/dist/physics/VoxelCharacterController.d.ts +74 -0
  187. package/dist/physics/VoxelCharacterController.js +237 -0
  188. package/dist/physics/VoxelCharacterController.js.map +1 -0
  189. package/dist/physics/index.d.ts +2 -0
  190. package/dist/physics/index.js +3 -0
  191. package/dist/physics/index.js.map +1 -0
  192. package/dist/postprocessing/CopyShader.d.ts +9 -0
  193. package/dist/postprocessing/CopyShader.js +20 -0
  194. package/dist/postprocessing/CopyShader.js.map +1 -0
  195. package/dist/postprocessing/EffectComposer.d.ts +46 -0
  196. package/dist/postprocessing/EffectComposer.js +205 -0
  197. package/dist/postprocessing/EffectComposer.js.map +1 -0
  198. package/dist/postprocessing/FullScreenQuad.d.ts +13 -0
  199. package/dist/postprocessing/FullScreenQuad.js +44 -0
  200. package/dist/postprocessing/FullScreenQuad.js.map +1 -0
  201. package/dist/postprocessing/OutputPass.d.ts +16 -0
  202. package/dist/postprocessing/OutputPass.js +119 -0
  203. package/dist/postprocessing/OutputPass.js.map +1 -0
  204. package/dist/postprocessing/Pass.d.ts +12 -0
  205. package/dist/postprocessing/Pass.js +15 -0
  206. package/dist/postprocessing/Pass.js.map +1 -0
  207. package/dist/postprocessing/RenderPass.d.ts +17 -0
  208. package/dist/postprocessing/RenderPass.js +51 -0
  209. package/dist/postprocessing/RenderPass.js.map +1 -0
  210. package/dist/postprocessing/ShaderPass.d.ts +15 -0
  211. package/dist/postprocessing/ShaderPass.js +47 -0
  212. package/dist/postprocessing/ShaderPass.js.map +1 -0
  213. package/dist/postprocessing/index.d.ts +7 -0
  214. package/dist/postprocessing/index.js +8 -0
  215. package/dist/postprocessing/index.js.map +1 -0
  216. package/dist/renderers/WebGLRenderTarget.d.ts +44 -0
  217. package/dist/renderers/WebGLRenderTarget.js +72 -0
  218. package/dist/renderers/WebGLRenderTarget.js.map +1 -0
  219. package/dist/renderers/WebGLRenderer.d.ts +275 -0
  220. package/dist/renderers/WebGLRenderer.js +1860 -0
  221. package/dist/renderers/WebGLRenderer.js.map +1 -0
  222. package/dist/renderers/index.d.ts +17 -0
  223. package/dist/renderers/index.js +18 -0
  224. package/dist/renderers/index.js.map +1 -0
  225. package/dist/renderers/webgl/WebGLAttributes.d.ts +32 -0
  226. package/dist/renderers/webgl/WebGLAttributes.js +115 -0
  227. package/dist/renderers/webgl/WebGLAttributes.js.map +1 -0
  228. package/dist/renderers/webgl/WebGLBackground.d.ts +23 -0
  229. package/dist/renderers/webgl/WebGLBackground.js +49 -0
  230. package/dist/renderers/webgl/WebGLBackground.js.map +1 -0
  231. package/dist/renderers/webgl/WebGLBindingStates.d.ts +30 -0
  232. package/dist/renderers/webgl/WebGLBindingStates.js +270 -0
  233. package/dist/renderers/webgl/WebGLBindingStates.js.map +1 -0
  234. package/dist/renderers/webgl/WebGLBufferRenderer.d.ts +36 -0
  235. package/dist/renderers/webgl/WebGLBufferRenderer.js +100 -0
  236. package/dist/renderers/webgl/WebGLBufferRenderer.js.map +1 -0
  237. package/dist/renderers/webgl/WebGLProgram.d.ts +109 -0
  238. package/dist/renderers/webgl/WebGLProgram.js +1059 -0
  239. package/dist/renderers/webgl/WebGLProgram.js.map +1 -0
  240. package/dist/renderers/webgl/WebGLPrograms.d.ts +62 -0
  241. package/dist/renderers/webgl/WebGLPrograms.js +285 -0
  242. package/dist/renderers/webgl/WebGLPrograms.js.map +1 -0
  243. package/dist/renderers/webgl/WebGLProperties.d.ts +8 -0
  244. package/dist/renderers/webgl/WebGLProperties.js +27 -0
  245. package/dist/renderers/webgl/WebGLProperties.js.map +1 -0
  246. package/dist/renderers/webgl/WebGLRenderLists.d.ts +29 -0
  247. package/dist/renderers/webgl/WebGLRenderLists.js +105 -0
  248. package/dist/renderers/webgl/WebGLRenderLists.js.map +1 -0
  249. package/dist/renderers/webgl/WebGLRenderStates.d.ts +104 -0
  250. package/dist/renderers/webgl/WebGLRenderStates.js +195 -0
  251. package/dist/renderers/webgl/WebGLRenderStates.js.map +1 -0
  252. package/dist/renderers/webgl/WebGLShader.d.ts +2 -0
  253. package/dist/renderers/webgl/WebGLShader.js +15 -0
  254. package/dist/renderers/webgl/WebGLShader.js.map +1 -0
  255. package/dist/renderers/webgl/WebGLState.d.ts +64 -0
  256. package/dist/renderers/webgl/WebGLState.js +464 -0
  257. package/dist/renderers/webgl/WebGLState.js.map +1 -0
  258. package/dist/renderers/webgl/WebGLTextures.d.ts +84 -0
  259. package/dist/renderers/webgl/WebGLTextures.js +391 -0
  260. package/dist/renderers/webgl/WebGLTextures.js.map +1 -0
  261. package/dist/renderers/webgl/WebGLUniforms.d.ts +23 -0
  262. package/dist/renderers/webgl/WebGLUniforms.js +480 -0
  263. package/dist/renderers/webgl/WebGLUniforms.js.map +1 -0
  264. package/dist/renderers/webgl/constants.d.ts +1 -0
  265. package/dist/renderers/webgl/constants.js +2 -0
  266. package/dist/renderers/webgl/constants.js.map +1 -0
  267. package/dist/renderers/webgpu/WebGPUCompute.d.ts +130 -0
  268. package/dist/renderers/webgpu/WebGPUCompute.js +308 -0
  269. package/dist/renderers/webgpu/WebGPUCompute.js.map +1 -0
  270. package/dist/renderers/webgpu/WebGPURenderer.d.ts +149 -0
  271. package/dist/renderers/webgpu/WebGPURenderer.js +1062 -0
  272. package/dist/renderers/webgpu/WebGPURenderer.js.map +1 -0
  273. package/dist/renderers/webgpu/index.d.ts +2 -0
  274. package/dist/renderers/webgpu/index.js +3 -0
  275. package/dist/renderers/webgpu/index.js.map +1 -0
  276. package/dist/scenes/Fog.d.ts +18 -0
  277. package/dist/scenes/Fog.js +25 -0
  278. package/dist/scenes/Fog.js.map +1 -0
  279. package/dist/scenes/FogExp2.d.ts +16 -0
  280. package/dist/scenes/FogExp2.js +23 -0
  281. package/dist/scenes/FogExp2.js.map +1 -0
  282. package/dist/scenes/Scene.d.ts +49 -0
  283. package/dist/scenes/Scene.js +158 -0
  284. package/dist/scenes/Scene.js.map +1 -0
  285. package/dist/scenes/index.d.ts +3 -0
  286. package/dist/scenes/index.js +4 -0
  287. package/dist/scenes/index.js.map +1 -0
  288. package/dist/textures/CanvasTexture.d.ts +6 -0
  289. package/dist/textures/CanvasTexture.js +11 -0
  290. package/dist/textures/CanvasTexture.js.map +1 -0
  291. package/dist/textures/DataTexture.d.ts +7 -0
  292. package/dist/textures/DataTexture.js +13 -0
  293. package/dist/textures/DataTexture.js.map +1 -0
  294. package/dist/textures/DepthTexture.d.ts +6 -0
  295. package/dist/textures/DepthTexture.js +13 -0
  296. package/dist/textures/DepthTexture.js.map +1 -0
  297. package/dist/textures/Texture.d.ts +51 -0
  298. package/dist/textures/Texture.js +105 -0
  299. package/dist/textures/Texture.js.map +1 -0
  300. package/dist/textures/index.d.ts +4 -0
  301. package/dist/textures/index.js +5 -0
  302. package/dist/textures/index.js.map +1 -0
  303. package/dist/ui/DomBuilder.d.ts +60 -0
  304. package/dist/ui/DomBuilder.js +283 -0
  305. package/dist/ui/DomBuilder.js.map +1 -0
  306. package/dist/ui/InGameHud.d.ts +80 -0
  307. package/dist/ui/InGameHud.js +372 -0
  308. package/dist/ui/InGameHud.js.map +1 -0
  309. package/dist/ui/Signal.d.ts +39 -0
  310. package/dist/ui/Signal.js +78 -0
  311. package/dist/ui/Signal.js.map +1 -0
  312. package/dist/ui/index.d.ts +3 -0
  313. package/dist/ui/index.js +4 -0
  314. package/dist/ui/index.js.map +1 -0
  315. package/dist/voxel/ChunkBatchRenderer.d.ts +145 -0
  316. package/dist/voxel/ChunkBatchRenderer.js +785 -0
  317. package/dist/voxel/ChunkBatchRenderer.js.map +1 -0
  318. package/dist/voxel/ChunkStreamManager.d.ts +73 -0
  319. package/dist/voxel/ChunkStreamManager.js +181 -0
  320. package/dist/voxel/ChunkStreamManager.js.map +1 -0
  321. package/dist/voxel/CloudLODSystem.d.ts +136 -0
  322. package/dist/voxel/CloudLODSystem.js +862 -0
  323. package/dist/voxel/CloudLODSystem.js.map +1 -0
  324. package/dist/voxel/GPUChunkCuller.d.ts +35 -0
  325. package/dist/voxel/GPUChunkCuller.js +187 -0
  326. package/dist/voxel/GPUChunkCuller.js.map +1 -0
  327. package/dist/voxel/HorizonOcclusionCuller.d.ts +77 -0
  328. package/dist/voxel/HorizonOcclusionCuller.js +206 -0
  329. package/dist/voxel/HorizonOcclusionCuller.js.map +1 -0
  330. package/dist/voxel/SilhouetteLightVolumes.d.ts +295 -0
  331. package/dist/voxel/SilhouetteLightVolumes.js +1668 -0
  332. package/dist/voxel/SilhouetteLightVolumes.js.map +1 -0
  333. package/dist/voxel/VolumeWakeField.d.ts +116 -0
  334. package/dist/voxel/VolumeWakeField.js +212 -0
  335. package/dist/voxel/VolumeWakeField.js.map +1 -0
  336. package/dist/voxel/VoxImporter.d.ts +31 -0
  337. package/dist/voxel/VoxImporter.js +140 -0
  338. package/dist/voxel/VoxImporter.js.map +1 -0
  339. package/dist/voxel/VoxelBlockRegistry.d.ts +68 -0
  340. package/dist/voxel/VoxelBlockRegistry.js +128 -0
  341. package/dist/voxel/VoxelBlockRegistry.js.map +1 -0
  342. package/dist/voxel/VoxelLightEngine.d.ts +57 -0
  343. package/dist/voxel/VoxelLightEngine.js +309 -0
  344. package/dist/voxel/VoxelLightEngine.js.map +1 -0
  345. package/dist/voxel/VoxelMesher.d.ts +146 -0
  346. package/dist/voxel/VoxelMesher.js +784 -0
  347. package/dist/voxel/VoxelMesher.js.map +1 -0
  348. package/dist/voxel/VoxelMesherWorkerPool.d.ts +62 -0
  349. package/dist/voxel/VoxelMesherWorkerPool.js +514 -0
  350. package/dist/voxel/VoxelMesherWorkerPool.js.map +1 -0
  351. package/dist/voxel/VoxelPotatoShader.d.ts +43 -0
  352. package/dist/voxel/VoxelPotatoShader.js +256 -0
  353. package/dist/voxel/VoxelPotatoShader.js.map +1 -0
  354. package/dist/voxel/VoxelSilhouetteShadows.d.ts +249 -0
  355. package/dist/voxel/VoxelSilhouetteShadows.js +960 -0
  356. package/dist/voxel/VoxelSilhouetteShadows.js.map +1 -0
  357. package/dist/voxel/VoxelStorage.d.ts +48 -0
  358. package/dist/voxel/VoxelStorage.js +315 -0
  359. package/dist/voxel/VoxelStorage.js.map +1 -0
  360. package/dist/voxel/index.d.ts +15 -0
  361. package/dist/voxel/index.js +16 -0
  362. package/dist/voxel/index.js.map +1 -0
  363. package/dist/world/VoxelWorld.d.ts +342 -0
  364. package/dist/world/VoxelWorld.js +1801 -0
  365. package/dist/world/VoxelWorld.js.map +1 -0
  366. package/dist/world/index.d.ts +1 -0
  367. package/dist/world/index.js +2 -0
  368. package/dist/world/index.js.map +1 -0
  369. package/package.json +43 -4
@@ -0,0 +1,805 @@
1
+ /**
2
+ * Lightweight Three.js loader, skeleton, interleaved buffer, and animation compatibility
3
+ * primitives so `three/examples/jsm/loaders/GLTFLoader.js` and `DRACOLoader.js` execute
4
+ * cleanly against our custom engine without pulling `three` core into the bundle.
5
+ */
6
+ import { Color, Matrix4, Quaternion, Vector3 } from '../math/index.js';
7
+ import { BufferAttribute, Float32BufferAttribute } from '../core/BufferAttribute.js';
8
+ import { BufferGeometry } from '../core/BufferGeometry.js';
9
+ import { Mesh } from '../core/Mesh.js';
10
+ import { Object3D } from '../core/Object3D.js';
11
+ import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
12
+ import { LineSegments } from '../objects/LineSegments.js';
13
+ import { Texture } from '../textures/Texture.js';
14
+ import { AttachedBindMode, InterpolateDiscrete, InterpolateLinear, LoopOnce, LoopPingPong, LoopRepeat, } from '../constants.js';
15
+ const _offsetMatrix = new Matrix4();
16
+ const _identityMatrix = new Matrix4();
17
+ const _q0 = new Quaternion();
18
+ const _q1 = new Quaternion();
19
+ const _qOut = new Quaternion();
20
+ const _invRootMatrix = new Matrix4();
21
+ const _boneMatrix = new Matrix4();
22
+ const _bonePos = new Vector3();
23
+ export class InterleavedBuffer {
24
+ constructor(array, stride) {
25
+ this.isInterleavedBuffer = true;
26
+ this.usage = 35044;
27
+ this.version = 0;
28
+ this.array = array;
29
+ this.stride = stride;
30
+ this.count = array !== undefined ? array.length / stride : 0;
31
+ }
32
+ set needsUpdate(value) {
33
+ if (value)
34
+ this.version++;
35
+ }
36
+ clone() {
37
+ const ClonedCtor = this.array.constructor;
38
+ return new InterleavedBuffer(new ClonedCtor(this.array), this.stride);
39
+ }
40
+ }
41
+ export class InterleavedBufferAttribute {
42
+ constructor(interleavedBuffer, itemSize, offset, normalized = false) {
43
+ this.isInterleavedBufferAttribute = true;
44
+ this.name = '';
45
+ this.data = interleavedBuffer;
46
+ this.itemSize = itemSize;
47
+ this.offset = offset;
48
+ this.normalized = normalized;
49
+ }
50
+ get count() {
51
+ return this.data.count;
52
+ }
53
+ get array() {
54
+ return this.data.array;
55
+ }
56
+ getX(index) {
57
+ return this.data.array[index * this.data.stride + this.offset];
58
+ }
59
+ getY(index) {
60
+ return this.data.array[index * this.data.stride + this.offset + 1];
61
+ }
62
+ getZ(index) {
63
+ return this.data.array[index * this.data.stride + this.offset + 2];
64
+ }
65
+ getW(index) {
66
+ return this.data.array[index * this.data.stride + this.offset + 3];
67
+ }
68
+ clone() {
69
+ const out = new Float32Array(this.count * this.itemSize);
70
+ for (let i = 0; i < this.count; i++) {
71
+ const base = i * this.data.stride + this.offset;
72
+ for (let k = 0; k < this.itemSize; k++) {
73
+ out[i * this.itemSize + k] = this.data.array[base + k];
74
+ }
75
+ }
76
+ return new BufferAttribute(out, this.itemSize, this.normalized);
77
+ }
78
+ }
79
+ export class Bone extends Object3D {
80
+ constructor() {
81
+ super(...arguments);
82
+ this.isBone = true;
83
+ this.type = 'Bone';
84
+ }
85
+ }
86
+ export class Skeleton {
87
+ constructor(bones = [], boneInverses = []) {
88
+ this.boneTexture = null;
89
+ this.frame = -1;
90
+ this.bones = bones.slice();
91
+ this.boneInverses = boneInverses.slice();
92
+ this.boneMatrices = new Float32Array(this.bones.length * 16);
93
+ if (this.boneInverses.length === 0 && this.bones.length > 0) {
94
+ this.calculateInverses();
95
+ }
96
+ }
97
+ calculateInverses() {
98
+ this.boneInverses.length = 0;
99
+ for (let i = 0; i < this.bones.length; i++) {
100
+ const inv = new Matrix4();
101
+ if (this.bones[i])
102
+ inv.copy(this.bones[i].matrixWorld).invert();
103
+ this.boneInverses.push(inv);
104
+ }
105
+ }
106
+ pose() {
107
+ for (let i = 0; i < this.bones.length; i++) {
108
+ const bone = this.bones[i];
109
+ if (bone && this.boneInverses[i]) {
110
+ bone.matrixWorld.copy(this.boneInverses[i]).invert();
111
+ }
112
+ }
113
+ for (let i = 0; i < this.bones.length; i++) {
114
+ const bone = this.bones[i];
115
+ if (!bone)
116
+ continue;
117
+ if (bone.parent && bone.parent.isBone) {
118
+ bone.matrix.copy(bone.parent.matrixWorld).invert().multiply(bone.matrixWorld);
119
+ }
120
+ else {
121
+ bone.matrix.copy(bone.matrixWorld);
122
+ }
123
+ bone.matrix.decompose(bone.position, bone.quaternion, bone.scale);
124
+ }
125
+ }
126
+ update() {
127
+ const bones = this.bones;
128
+ const boneInverses = this.boneInverses;
129
+ const needed = bones.length * 16;
130
+ if (this.boneMatrices.length < needed) {
131
+ this.boneMatrices = new Float32Array(needed);
132
+ }
133
+ for (let i = 0; i < bones.length; i++) {
134
+ const matrix = bones[i] ? bones[i].matrixWorld : _identityMatrix;
135
+ const inverse = boneInverses[i] ?? _identityMatrix;
136
+ _offsetMatrix.multiplyMatrices(matrix, inverse);
137
+ _offsetMatrix.toArray(this.boneMatrices, i * 16);
138
+ }
139
+ if (this.boneTexture !== null) {
140
+ this.boneTexture.needsUpdate = true;
141
+ }
142
+ }
143
+ dispose() {
144
+ if (this.boneTexture !== null) {
145
+ this.boneTexture.dispose();
146
+ this.boneTexture = null;
147
+ }
148
+ }
149
+ }
150
+ export class SkinnedMesh extends Mesh {
151
+ constructor() {
152
+ super(...arguments);
153
+ this.isSkinnedMesh = true;
154
+ this.type = 'SkinnedMesh';
155
+ this.bindMode = AttachedBindMode;
156
+ this.bindMatrix = new Matrix4();
157
+ this.bindMatrixInverse = new Matrix4();
158
+ this.skeleton = null;
159
+ }
160
+ bind(skeleton, bindMatrix) {
161
+ this.skeleton = skeleton;
162
+ if (bindMatrix === undefined) {
163
+ this.updateMatrixWorld(true);
164
+ this.skeleton.calculateInverses();
165
+ bindMatrix = this.matrixWorld;
166
+ }
167
+ this.bindMatrix.copy(bindMatrix);
168
+ this.bindMatrixInverse.copy(bindMatrix).invert();
169
+ }
170
+ }
171
+ export class Interpolant {
172
+ constructor(parameterPositions, sampleValues, sampleSize, resultBuffer) {
173
+ this.settings = null;
174
+ this.DefaultSettings_ = {};
175
+ this._cachedIndex = 0;
176
+ this.parameterPositions = parameterPositions;
177
+ this.sampleValues = sampleValues;
178
+ this.valueSize = sampleSize;
179
+ this.resultBuffer = resultBuffer ?? new Float32Array(sampleSize);
180
+ }
181
+ copySampleValue_(index) {
182
+ const result = this.resultBuffer;
183
+ const values = this.sampleValues;
184
+ const stride = this.valueSize;
185
+ const offset = index * stride;
186
+ for (let i = 0; i < stride; i++) {
187
+ result[i] = values[offset + i];
188
+ }
189
+ return result;
190
+ }
191
+ interpolate_(i1, t0, t, t1) {
192
+ const result = this.resultBuffer;
193
+ const values = this.sampleValues;
194
+ const stride = this.valueSize;
195
+ const offset1 = i1 * stride;
196
+ const offset0 = offset1 - stride;
197
+ const weight1 = t1 !== t0 ? (t - t0) / (t1 - t0) : 0;
198
+ const weight0 = 1 - weight1;
199
+ for (let i = 0; i < stride; i++) {
200
+ result[i] = values[offset0 + i] * weight0 + values[offset1 + i] * weight1;
201
+ }
202
+ return result;
203
+ }
204
+ evaluate(t) {
205
+ const pp = this.parameterPositions;
206
+ const len = pp.length;
207
+ if (len === 0)
208
+ return this.resultBuffer;
209
+ if (len === 1 || t <= pp[0])
210
+ return this.copySampleValue_(0);
211
+ if (t >= pp[len - 1])
212
+ return this.copySampleValue_(len - 1);
213
+ // Binary search for interval [i1 - 1, i1] where pp[i1 - 1] <= t <= pp[i1]
214
+ let lo = 1;
215
+ let hi = len - 1;
216
+ while (lo < hi) {
217
+ const mid = (lo + hi) >>> 1;
218
+ if (pp[mid] < t) {
219
+ lo = mid + 1;
220
+ }
221
+ else {
222
+ hi = mid;
223
+ }
224
+ }
225
+ this._cachedIndex = lo;
226
+ return this.interpolate_(lo, pp[lo - 1], t, pp[lo]);
227
+ }
228
+ }
229
+ export class DiscreteInterpolant extends Interpolant {
230
+ interpolate_(i1, _t0, _t, _t1) {
231
+ return this.copySampleValue_(i1 - 1);
232
+ }
233
+ }
234
+ export class LinearInterpolant extends Interpolant {
235
+ }
236
+ export class QuaternionLinearInterpolant extends Interpolant {
237
+ interpolate_(i1, t0, t, t1) {
238
+ const result = this.resultBuffer;
239
+ const values = this.sampleValues;
240
+ const stride = this.valueSize;
241
+ const alpha = t1 !== t0 ? (t - t0) / (t1 - t0) : 0;
242
+ const offset1 = i1 * stride;
243
+ const offset0 = offset1 - stride;
244
+ for (let offset = 0; offset < stride; offset += 4) {
245
+ _q0.set(values[offset0 + offset], values[offset0 + offset + 1], values[offset0 + offset + 2], values[offset0 + offset + 3]);
246
+ _q1.set(values[offset1 + offset], values[offset1 + offset + 1], values[offset1 + offset + 2], values[offset1 + offset + 3]);
247
+ _qOut.slerpQuaternions(_q0, _q1, alpha);
248
+ result[offset] = _qOut.x;
249
+ result[offset + 1] = _qOut.y;
250
+ result[offset + 2] = _qOut.z;
251
+ result[offset + 3] = _qOut.w;
252
+ }
253
+ return result;
254
+ }
255
+ }
256
+ export class KeyframeTrack {
257
+ constructor(name, times, values, interpolation = InterpolateLinear) {
258
+ this.ValueTypeName = 'number';
259
+ this.name = name;
260
+ this.times = new Float32Array(times);
261
+ this.values = new Float32Array(values);
262
+ this.interpolation = interpolation;
263
+ }
264
+ getValueSize() {
265
+ return this.times.length > 0 ? Math.max(1, Math.floor(this.values.length / this.times.length)) : 1;
266
+ }
267
+ createInterpolant(result) {
268
+ const size = this.getValueSize();
269
+ if (this.interpolation === InterpolateDiscrete) {
270
+ return new DiscreteInterpolant(this.times, this.values, size, result);
271
+ }
272
+ return new LinearInterpolant(this.times, this.values, size, result);
273
+ }
274
+ }
275
+ export class NumberKeyframeTrack extends KeyframeTrack {
276
+ constructor() {
277
+ super(...arguments);
278
+ this.ValueTypeName = 'number';
279
+ }
280
+ }
281
+ export class VectorKeyframeTrack extends KeyframeTrack {
282
+ constructor() {
283
+ super(...arguments);
284
+ this.ValueTypeName = 'vector';
285
+ }
286
+ }
287
+ export class QuaternionKeyframeTrack extends KeyframeTrack {
288
+ constructor() {
289
+ super(...arguments);
290
+ this.ValueTypeName = 'quaternion';
291
+ }
292
+ createInterpolant(result) {
293
+ const size = this.getValueSize();
294
+ if (this.interpolation === InterpolateDiscrete) {
295
+ return new DiscreteInterpolant(this.times, this.values, size, result);
296
+ }
297
+ return new QuaternionLinearInterpolant(this.times, this.values, size, result);
298
+ }
299
+ }
300
+ export class AnimationClip {
301
+ constructor(name = '', duration = -1, tracks = []) {
302
+ this.uuid = '';
303
+ this.name = name;
304
+ this.tracks = tracks;
305
+ this.duration = duration;
306
+ if (this.duration < 0) {
307
+ this.resetDuration();
308
+ }
309
+ }
310
+ resetDuration() {
311
+ let maxTime = 0;
312
+ for (let i = 0; i < this.tracks.length; i++) {
313
+ const times = this.tracks[i].times;
314
+ if (times.length > 0) {
315
+ const last = times[times.length - 1];
316
+ if (last > maxTime)
317
+ maxTime = last;
318
+ }
319
+ }
320
+ this.duration = maxTime;
321
+ return this;
322
+ }
323
+ static findByName(clips, name) {
324
+ for (let i = 0; i < clips.length; i++) {
325
+ if (clips[i].name === name)
326
+ return clips[i];
327
+ }
328
+ return null;
329
+ }
330
+ }
331
+ function parseTrackName(trackName) {
332
+ // Supports "NodeName.position", "NodeName.quaternion", "NodeName.morphTargetInfluences[0]", ".position"
333
+ const lastDot = trackName.lastIndexOf('.');
334
+ let nodeName = '';
335
+ let propPart = trackName;
336
+ if (lastDot !== -1) {
337
+ nodeName = trackName.slice(0, lastDot);
338
+ propPart = trackName.slice(lastDot + 1);
339
+ }
340
+ const bracketMatch = /^([^\[]+)\[([^\]]+)\]$/.exec(propPart);
341
+ if (bracketMatch) {
342
+ return { nodeName, propertyName: bracketMatch[1], propertyIndex: bracketMatch[2] };
343
+ }
344
+ return { nodeName, propertyName: propPart, propertyIndex: null };
345
+ }
346
+ export class AnimationAction {
347
+ constructor(clip, localRoot = null) {
348
+ this.time = 0;
349
+ this.timeScale = 1;
350
+ this.weight = 1;
351
+ this.loop = LoopRepeat;
352
+ this.repetitions = Infinity;
353
+ this.paused = false;
354
+ this.enabled = true;
355
+ this.clampWhenFinished = false;
356
+ /** @internal */
357
+ this._running = false;
358
+ this.clip = clip;
359
+ this.localRoot = localRoot;
360
+ this._bindings = clip.tracks.map((track) => {
361
+ const parsed = parseTrackName(track.name);
362
+ return {
363
+ ...parsed,
364
+ track,
365
+ interpolant: track.createInterpolant(),
366
+ };
367
+ });
368
+ }
369
+ play() {
370
+ this._running = true;
371
+ this.paused = false;
372
+ this.enabled = true;
373
+ return this;
374
+ }
375
+ stop() {
376
+ this._running = false;
377
+ this.time = 0;
378
+ return this;
379
+ }
380
+ reset() {
381
+ this.paused = false;
382
+ this.enabled = true;
383
+ this.time = 0;
384
+ return this;
385
+ }
386
+ setLoop(mode, repetitions) {
387
+ this.loop = mode;
388
+ this.repetitions = repetitions;
389
+ return this;
390
+ }
391
+ setEffectiveTimeScale(timeScale) {
392
+ this.timeScale = timeScale;
393
+ return this;
394
+ }
395
+ setEffectiveWeight(weight) {
396
+ this.weight = weight;
397
+ return this;
398
+ }
399
+ isRunning() {
400
+ return this._running && this.enabled && !this.paused && this.timeScale !== 0;
401
+ }
402
+ }
403
+ export class AnimationMixer {
404
+ constructor(root) {
405
+ this._actions = [];
406
+ this.time = 0;
407
+ this.timeScale = 1;
408
+ this._root = root;
409
+ }
410
+ clipAction(clip, optionalRoot) {
411
+ const localRoot = optionalRoot ?? null;
412
+ for (let i = 0; i < this._actions.length; i++) {
413
+ const a = this._actions[i];
414
+ if (a.clip === clip && a.localRoot === localRoot) {
415
+ return a;
416
+ }
417
+ }
418
+ const action = new AnimationAction(clip, localRoot);
419
+ this._actions.push(action);
420
+ return action;
421
+ }
422
+ stopAllAction() {
423
+ for (let i = 0; i < this._actions.length; i++) {
424
+ this._actions[i].stop();
425
+ }
426
+ return this;
427
+ }
428
+ uncacheClip(clip) {
429
+ this._actions = this._actions.filter((a) => a.clip !== clip);
430
+ }
431
+ getRoot() {
432
+ return this._root;
433
+ }
434
+ _applyBinding(root, binding, sampleTime) {
435
+ let target = root;
436
+ if (binding.nodeName) {
437
+ if (root.name === binding.nodeName) {
438
+ target = root;
439
+ }
440
+ else {
441
+ target = root.getObjectByName(binding.nodeName);
442
+ }
443
+ }
444
+ if (!target)
445
+ return;
446
+ const val = binding.interpolant.evaluate(sampleTime);
447
+ const prop = binding.propertyName;
448
+ if (prop === 'position' && val.length >= 3) {
449
+ target.position.set(val[0], val[1], val[2]);
450
+ }
451
+ else if (prop === 'scale' && val.length >= 3) {
452
+ target.scale.set(val[0], val[1], val[2]);
453
+ }
454
+ else if (prop === 'quaternion' && val.length >= 4) {
455
+ target.quaternion.set(val[0], val[1], val[2], val[3]).normalize();
456
+ }
457
+ else if (prop === 'rotation' && val.length >= 3) {
458
+ target.rotation.set(val[0], val[1], val[2]);
459
+ }
460
+ else if (prop === 'visible') {
461
+ target.visible = val[0] !== 0;
462
+ }
463
+ else if (binding.propertyIndex !== null) {
464
+ const container = target[prop];
465
+ if (container && typeof container === 'object') {
466
+ container[binding.propertyIndex] = val[0];
467
+ }
468
+ }
469
+ else {
470
+ const obj = target;
471
+ if (val.length === 1) {
472
+ obj[prop] = val[0];
473
+ }
474
+ }
475
+ }
476
+ update(deltaTime) {
477
+ const dt = deltaTime * this.timeScale;
478
+ this.time += dt;
479
+ for (let i = 0; i < this._actions.length; i++) {
480
+ const action = this._actions[i];
481
+ if (!action._running || !action.enabled)
482
+ continue;
483
+ const duration = action.clip.duration;
484
+ if (!action.paused) {
485
+ action.time += dt * action.timeScale;
486
+ }
487
+ let sampleTime = action.time;
488
+ if (duration > 0) {
489
+ if (action.loop === LoopOnce) {
490
+ if (sampleTime >= duration) {
491
+ sampleTime = duration;
492
+ action.time = duration;
493
+ if (!action.clampWhenFinished) {
494
+ action._running = false;
495
+ }
496
+ else {
497
+ action.paused = true;
498
+ }
499
+ }
500
+ else if (sampleTime < 0) {
501
+ sampleTime = 0;
502
+ action.time = 0;
503
+ }
504
+ }
505
+ else if (action.loop === LoopPingPong) {
506
+ const cycle = duration * 2;
507
+ const mod = ((sampleTime % cycle) + cycle) % cycle;
508
+ sampleTime = mod <= duration ? mod : cycle - mod;
509
+ }
510
+ else {
511
+ // LoopRepeat
512
+ sampleTime = ((sampleTime % duration) + duration) % duration;
513
+ }
514
+ }
515
+ else {
516
+ sampleTime = 0;
517
+ }
518
+ const root = action.localRoot ?? this._root;
519
+ for (let b = 0; b < action._bindings.length; b++) {
520
+ this._applyBinding(root, action._bindings[b], sampleTime);
521
+ }
522
+ }
523
+ return this;
524
+ }
525
+ }
526
+ function collectBones(object, out) {
527
+ if (object.isBone) {
528
+ out.push(object);
529
+ }
530
+ for (let i = 0; i < object.children.length; i++) {
531
+ collectBones(object.children[i], out);
532
+ }
533
+ }
534
+ export class SkeletonHelper extends LineSegments {
535
+ constructor(object) {
536
+ const bones = [];
537
+ collectBones(object, bones);
538
+ const vertices = [];
539
+ const colors = [];
540
+ const color1 = new Color(0, 0, 1);
541
+ const color2 = new Color(0, 1, 0);
542
+ for (let i = 0; i < bones.length; i++) {
543
+ const bone = bones[i];
544
+ if (bone.parent && bone.parent.isBone) {
545
+ vertices.push(0, 0, 0, 0, 0, 0);
546
+ colors.push(color1.r, color1.g, color1.b, color2.r, color2.g, color2.b);
547
+ }
548
+ }
549
+ const geometry = new BufferGeometry();
550
+ geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3));
551
+ geometry.setAttribute('color', new Float32BufferAttribute(colors, 3));
552
+ const material = new LineBasicMaterial({
553
+ vertexColors: true,
554
+ depthTest: false,
555
+ depthWrite: false,
556
+ toneMapped: false,
557
+ transparent: true,
558
+ });
559
+ super(geometry, material);
560
+ this.isSkeletonHelper = true;
561
+ this.type = 'SkeletonHelper';
562
+ this.bones = [];
563
+ this.root = object;
564
+ this.bones = bones;
565
+ this.matrix = object.matrixWorld;
566
+ this.matrixAutoUpdate = false;
567
+ this.updateMatrixWorld(true);
568
+ }
569
+ updateMatrixWorld(force) {
570
+ const bones = this.bones;
571
+ const position = this.geometry.attributes.position;
572
+ if (position && position.count > 0) {
573
+ this.root.updateMatrixWorld(true);
574
+ _invRootMatrix.copy(this.root.matrixWorld).invert();
575
+ let j = 0;
576
+ for (let i = 0; i < bones.length; i++) {
577
+ const bone = bones[i];
578
+ if (bone.parent && bone.parent.isBone) {
579
+ _boneMatrix.multiplyMatrices(_invRootMatrix, bone.matrixWorld);
580
+ _bonePos.setFromMatrixPosition(_boneMatrix);
581
+ position.setXYZ(j, _bonePos.x, _bonePos.y, _bonePos.z);
582
+ _boneMatrix.multiplyMatrices(_invRootMatrix, bone.parent.matrixWorld);
583
+ _bonePos.setFromMatrixPosition(_boneMatrix);
584
+ position.setXYZ(j + 1, _bonePos.x, _bonePos.y, _bonePos.z);
585
+ j += 2;
586
+ }
587
+ }
588
+ position.needsUpdate = true;
589
+ }
590
+ super.updateMatrixWorld(force);
591
+ }
592
+ dispose() {
593
+ this.geometry.dispose?.();
594
+ if (!Array.isArray(this.material)) {
595
+ this.material.dispose?.();
596
+ }
597
+ }
598
+ }
599
+ export const PropertyBinding = {
600
+ sanitizeNodeName(name) {
601
+ return name.replace(/\s/g, '_').replace(/[\[\].:/]/g, '');
602
+ },
603
+ };
604
+ export class LoadingManager {
605
+ constructor(onLoad, onProgress, onError) {
606
+ this.isLoading = false;
607
+ this.itemsLoaded = 0;
608
+ this.itemsTotal = 0;
609
+ this._urlModifier = null;
610
+ this._handlers = [];
611
+ this.onLoad = onLoad;
612
+ this.onProgress = onProgress;
613
+ this.onError = onError;
614
+ }
615
+ itemStart(url) {
616
+ this.itemsTotal++;
617
+ if (!this.isLoading) {
618
+ this.onStart?.(url, this.itemsLoaded, this.itemsTotal);
619
+ }
620
+ this.isLoading = true;
621
+ }
622
+ itemEnd(url) {
623
+ this.itemsLoaded++;
624
+ this.onProgress?.(url, this.itemsLoaded, this.itemsTotal);
625
+ if (this.itemsLoaded >= this.itemsTotal) {
626
+ this.isLoading = false;
627
+ this.onLoad?.();
628
+ }
629
+ }
630
+ itemError(url) {
631
+ this.onError?.(url);
632
+ }
633
+ setURLModifier(transform) {
634
+ this._urlModifier = transform;
635
+ return this;
636
+ }
637
+ resolveURL(url) {
638
+ return this._urlModifier ? this._urlModifier(url) : url;
639
+ }
640
+ addHandler(regex, loader) {
641
+ this._handlers.push({ regex, loader });
642
+ return this;
643
+ }
644
+ getHandler(file) {
645
+ for (let i = 0; i < this._handlers.length; i++) {
646
+ const h = this._handlers[i];
647
+ if (h.regex.test(file))
648
+ return h.loader;
649
+ }
650
+ return null;
651
+ }
652
+ }
653
+ export const DefaultLoadingManager = new LoadingManager();
654
+ export class Loader {
655
+ constructor(manager) {
656
+ this.crossOrigin = 'anonymous';
657
+ this.withCredentials = false;
658
+ this.path = '';
659
+ this.resourcePath = '';
660
+ this.requestHeader = {};
661
+ this.manager = manager ?? DefaultLoadingManager;
662
+ }
663
+ setCrossOrigin(crossOrigin) {
664
+ this.crossOrigin = crossOrigin;
665
+ return this;
666
+ }
667
+ setWithCredentials(value) {
668
+ this.withCredentials = value;
669
+ return this;
670
+ }
671
+ setPath(path) {
672
+ this.path = path;
673
+ return this;
674
+ }
675
+ setResourcePath(resourcePath) {
676
+ this.resourcePath = resourcePath;
677
+ return this;
678
+ }
679
+ setRequestHeader(requestHeader) {
680
+ this.requestHeader = requestHeader;
681
+ return this;
682
+ }
683
+ }
684
+ export class FileLoader extends Loader {
685
+ constructor() {
686
+ super(...arguments);
687
+ this.responseType = '';
688
+ }
689
+ setResponseType(value) {
690
+ this.responseType = value;
691
+ return this;
692
+ }
693
+ load(url, onLoad, _onProgress, onError) {
694
+ const fullUrl = this.path ? this.path + url : url;
695
+ const resolved = this.manager.resolveURL(fullUrl);
696
+ this.manager.itemStart(resolved);
697
+ const init = {
698
+ headers: this.requestHeader,
699
+ credentials: this.withCredentials ? 'include' : 'same-origin',
700
+ };
701
+ fetch(resolved, init)
702
+ .then((res) => {
703
+ if (!res.ok)
704
+ throw new Error(`HTTP ${res.status} loading ${resolved}`);
705
+ return this.responseType === 'arraybuffer' ? res.arrayBuffer() : res.text();
706
+ })
707
+ .then((data) => {
708
+ this.manager.itemEnd(resolved);
709
+ onLoad?.(data);
710
+ })
711
+ .catch((err) => {
712
+ this.manager.itemError(resolved);
713
+ this.manager.itemEnd(resolved);
714
+ onError?.(err);
715
+ });
716
+ }
717
+ loadAsync(url, onProgress) {
718
+ return new Promise((resolve, reject) => {
719
+ this.load(url, resolve, onProgress, reject);
720
+ });
721
+ }
722
+ }
723
+ export class ImageBitmapLoader extends Loader {
724
+ constructor() {
725
+ super(...arguments);
726
+ this.options = { premultiplyAlpha: 'none' };
727
+ }
728
+ setOptions(options) {
729
+ this.options = options;
730
+ return this;
731
+ }
732
+ load(url, onLoad, _onProgress, onError) {
733
+ const fullUrl = this.path ? this.path + url : url;
734
+ const resolved = this.manager.resolveURL(fullUrl);
735
+ this.manager.itemStart(resolved);
736
+ const init = {
737
+ headers: this.requestHeader,
738
+ credentials: this.withCredentials ? 'include' : 'same-origin',
739
+ };
740
+ fetch(resolved, init)
741
+ .then((res) => {
742
+ if (!res.ok)
743
+ throw new Error(`HTTP ${res.status} loading ${resolved}`);
744
+ return res.blob();
745
+ })
746
+ .then((blob) => createImageBitmap(blob, this.options))
747
+ .then((bitmap) => {
748
+ this.manager.itemEnd(resolved);
749
+ onLoad?.(bitmap);
750
+ })
751
+ .catch((err) => {
752
+ this.manager.itemError(resolved);
753
+ this.manager.itemEnd(resolved);
754
+ onError?.(err);
755
+ });
756
+ }
757
+ loadAsync(url, onProgress) {
758
+ return new Promise((resolve, reject) => {
759
+ this.load(url, resolve, onProgress, reject);
760
+ });
761
+ }
762
+ }
763
+ export class TextureLoader extends Loader {
764
+ load(url, onLoad, _onProgress, onError) {
765
+ const texture = new Texture();
766
+ const fullUrl = this.path ? this.path + url : url;
767
+ const resolved = this.manager.resolveURL(fullUrl);
768
+ this.manager.itemStart(resolved);
769
+ const img = new Image();
770
+ img.crossOrigin = this.crossOrigin;
771
+ img.onload = () => {
772
+ texture.image = img;
773
+ texture.needsUpdate = true;
774
+ this.manager.itemEnd(resolved);
775
+ onLoad?.(texture);
776
+ };
777
+ img.onerror = (err) => {
778
+ this.manager.itemError(resolved);
779
+ this.manager.itemEnd(resolved);
780
+ onError?.(err);
781
+ };
782
+ img.src = resolved;
783
+ return texture;
784
+ }
785
+ loadAsync(url, onProgress) {
786
+ return new Promise((resolve, reject) => {
787
+ this.load(url, resolve, onProgress, reject);
788
+ });
789
+ }
790
+ }
791
+ export const LoaderUtils = {
792
+ extractUrlBase(url) {
793
+ const index = url.lastIndexOf('/');
794
+ return index === -1 ? './' : url.slice(0, index + 1);
795
+ },
796
+ resolveURL(url, path) {
797
+ if (!url)
798
+ return '';
799
+ if (/^https?:\/\//i.test(url) || /^data:.*,.*$/i.test(url) || /^blob:.*$/i.test(url)) {
800
+ return url;
801
+ }
802
+ return path + url;
803
+ },
804
+ };
805
+ //# sourceMappingURL=loaderCompat.js.map