@gnsx/three 0.184.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 (1182) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +85 -0
  3. package/build/three.cjs +79695 -0
  4. package/build/three.core.js +59732 -0
  5. package/build/three.core.min.js +6 -0
  6. package/build/three.module.js +19552 -0
  7. package/build/three.module.min.js +6 -0
  8. package/build/three.tsl.js +654 -0
  9. package/build/three.tsl.min.js +6 -0
  10. package/build/three.webgpu.js +83969 -0
  11. package/build/three.webgpu.min.js +6 -0
  12. package/build/three.webgpu.nodes.js +83702 -0
  13. package/build/three.webgpu.nodes.min.js +6 -0
  14. package/examples/fonts/LICENSE +13 -0
  15. package/examples/fonts/MPLUSRounded1c/MPLUSRounded1c-Regular.typeface.json.zip +0 -0
  16. package/examples/fonts/MPLUSRounded1c/OFL.txt +91 -0
  17. package/examples/fonts/README.md +11 -0
  18. package/examples/fonts/droid/NOTICE +190 -0
  19. package/examples/fonts/droid/README.txt +18 -0
  20. package/examples/fonts/droid/droid_sans_bold.typeface.json +1 -0
  21. package/examples/fonts/droid/droid_sans_mono_regular.typeface.json +1 -0
  22. package/examples/fonts/droid/droid_sans_regular.typeface.json +1 -0
  23. package/examples/fonts/droid/droid_serif_bold.typeface.json +1 -0
  24. package/examples/fonts/droid/droid_serif_regular.typeface.json +1 -0
  25. package/examples/fonts/gentilis_bold.typeface.json +1 -0
  26. package/examples/fonts/gentilis_regular.typeface.json +1 -0
  27. package/examples/fonts/helvetiker_bold.typeface.json +1 -0
  28. package/examples/fonts/helvetiker_regular.typeface.json +1 -0
  29. package/examples/fonts/optimer_bold.typeface.json +1 -0
  30. package/examples/fonts/optimer_regular.typeface.json +1 -0
  31. package/examples/fonts/ttf/README.md +9 -0
  32. package/examples/fonts/ttf/kenpixel.ttf +0 -0
  33. package/examples/jsm/Addons.js +293 -0
  34. package/examples/jsm/animation/AnimationClipCreator.js +168 -0
  35. package/examples/jsm/animation/CCDIKSolver.js +595 -0
  36. package/examples/jsm/capabilities/WebGL.js +113 -0
  37. package/examples/jsm/capabilities/WebGPU.js +59 -0
  38. package/examples/jsm/controls/ArcballControls.js +3539 -0
  39. package/examples/jsm/controls/DragControls.js +452 -0
  40. package/examples/jsm/controls/FirstPersonControls.js +451 -0
  41. package/examples/jsm/controls/FlyControls.js +384 -0
  42. package/examples/jsm/controls/MapControls.js +116 -0
  43. package/examples/jsm/controls/OrbitControls.js +1963 -0
  44. package/examples/jsm/controls/PointerLockControls.js +264 -0
  45. package/examples/jsm/controls/TrackballControls.js +1001 -0
  46. package/examples/jsm/controls/TransformControls.js +1950 -0
  47. package/examples/jsm/csm/CSM.js +598 -0
  48. package/examples/jsm/csm/CSMFrustum.js +209 -0
  49. package/examples/jsm/csm/CSMHelper.js +243 -0
  50. package/examples/jsm/csm/CSMShader.js +307 -0
  51. package/examples/jsm/csm/CSMShadowNode.js +603 -0
  52. package/examples/jsm/curves/CurveExtras.js +694 -0
  53. package/examples/jsm/curves/NURBSCurve.js +155 -0
  54. package/examples/jsm/curves/NURBSSurface.js +98 -0
  55. package/examples/jsm/curves/NURBSUtils.js +532 -0
  56. package/examples/jsm/curves/NURBSVolume.js +82 -0
  57. package/examples/jsm/effects/AnaglyphEffect.js +274 -0
  58. package/examples/jsm/effects/AsciiEffect.js +310 -0
  59. package/examples/jsm/effects/OutlineEffect.js +489 -0
  60. package/examples/jsm/effects/ParallaxBarrierEffect.js +155 -0
  61. package/examples/jsm/effects/StereoEffect.js +91 -0
  62. package/examples/jsm/environments/ColorEnvironment.js +59 -0
  63. package/examples/jsm/environments/DebugEnvironment.js +102 -0
  64. package/examples/jsm/environments/RoomEnvironment.js +185 -0
  65. package/examples/jsm/exporters/DRACOExporter.js +311 -0
  66. package/examples/jsm/exporters/EXRExporter.js +618 -0
  67. package/examples/jsm/exporters/GLTFExporter.js +3738 -0
  68. package/examples/jsm/exporters/KTX2Exporter.js +347 -0
  69. package/examples/jsm/exporters/OBJExporter.js +308 -0
  70. package/examples/jsm/exporters/PLYExporter.js +562 -0
  71. package/examples/jsm/exporters/STLExporter.js +221 -0
  72. package/examples/jsm/exporters/USDZExporter.js +1254 -0
  73. package/examples/jsm/geometries/BoxLineGeometry.js +92 -0
  74. package/examples/jsm/geometries/ConvexGeometry.js +72 -0
  75. package/examples/jsm/geometries/DecalGeometry.js +420 -0
  76. package/examples/jsm/geometries/ParametricFunctions.js +100 -0
  77. package/examples/jsm/geometries/ParametricGeometry.js +172 -0
  78. package/examples/jsm/geometries/RoundedBoxGeometry.js +216 -0
  79. package/examples/jsm/geometries/TeapotGeometry.js +689 -0
  80. package/examples/jsm/geometries/TextGeometry.js +102 -0
  81. package/examples/jsm/gpgpu/BitonicSort.js +715 -0
  82. package/examples/jsm/helpers/AnimationPathHelper.js +302 -0
  83. package/examples/jsm/helpers/LightProbeGridHelper.js +221 -0
  84. package/examples/jsm/helpers/LightProbeHelper.js +165 -0
  85. package/examples/jsm/helpers/LightProbeHelperGPU.js +102 -0
  86. package/examples/jsm/helpers/OctreeHelper.js +109 -0
  87. package/examples/jsm/helpers/PositionalAudioHelper.js +169 -0
  88. package/examples/jsm/helpers/RapierHelper.js +59 -0
  89. package/examples/jsm/helpers/RectAreaLightHelper.js +118 -0
  90. package/examples/jsm/helpers/TextureHelper.js +265 -0
  91. package/examples/jsm/helpers/TextureHelperGPU.js +214 -0
  92. package/examples/jsm/helpers/VertexNormalsHelper.js +155 -0
  93. package/examples/jsm/helpers/VertexTangentsHelper.js +133 -0
  94. package/examples/jsm/helpers/ViewHelper.js +519 -0
  95. package/examples/jsm/inspector/Extension.js +13 -0
  96. package/examples/jsm/inspector/Inspector.js +542 -0
  97. package/examples/jsm/inspector/RendererInspector.js +425 -0
  98. package/examples/jsm/inspector/extensions/extensions.json +6 -0
  99. package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphEditor.js +916 -0
  100. package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphLoader.js +281 -0
  101. package/examples/jsm/inspector/tabs/Console.js +238 -0
  102. package/examples/jsm/inspector/tabs/Memory.js +128 -0
  103. package/examples/jsm/inspector/tabs/Parameters.js +380 -0
  104. package/examples/jsm/inspector/tabs/Performance.js +268 -0
  105. package/examples/jsm/inspector/tabs/Settings.js +264 -0
  106. package/examples/jsm/inspector/tabs/Timeline.js +1611 -0
  107. package/examples/jsm/inspector/tabs/Viewer.js +268 -0
  108. package/examples/jsm/inspector/ui/Graph.js +95 -0
  109. package/examples/jsm/inspector/ui/Item.js +170 -0
  110. package/examples/jsm/inspector/ui/List.js +75 -0
  111. package/examples/jsm/inspector/ui/Profiler.js +2072 -0
  112. package/examples/jsm/inspector/ui/Style.js +1667 -0
  113. package/examples/jsm/inspector/ui/Tab.js +265 -0
  114. package/examples/jsm/inspector/ui/Values.js +476 -0
  115. package/examples/jsm/inspector/ui/utils.js +69 -0
  116. package/examples/jsm/interaction/InteractionManager.js +226 -0
  117. package/examples/jsm/interactive/HTMLMesh.js +601 -0
  118. package/examples/jsm/interactive/InteractiveGroup.js +224 -0
  119. package/examples/jsm/interactive/SelectionBox.js +324 -0
  120. package/examples/jsm/interactive/SelectionHelper.js +150 -0
  121. package/examples/jsm/libs/ammo.wasm.js +822 -0
  122. package/examples/jsm/libs/ammo.wasm.wasm +0 -0
  123. package/examples/jsm/libs/basis/README.md +46 -0
  124. package/examples/jsm/libs/basis/basis_transcoder.js +19 -0
  125. package/examples/jsm/libs/basis/basis_transcoder.wasm +0 -0
  126. package/examples/jsm/libs/chevrotain.module.min.js +141 -0
  127. package/examples/jsm/libs/demuxer_mp4.js +109 -0
  128. package/examples/jsm/libs/draco/README.md +32 -0
  129. package/examples/jsm/libs/draco/draco_decoder.js +34 -0
  130. package/examples/jsm/libs/draco/draco_decoder.wasm +0 -0
  131. package/examples/jsm/libs/draco/draco_encoder.js +33 -0
  132. package/examples/jsm/libs/draco/draco_wasm_wrapper.js +117 -0
  133. package/examples/jsm/libs/draco/gltf/draco_decoder.js +33 -0
  134. package/examples/jsm/libs/draco/gltf/draco_decoder.wasm +0 -0
  135. package/examples/jsm/libs/draco/gltf/draco_encoder.js +33 -0
  136. package/examples/jsm/libs/draco/gltf/draco_wasm_wrapper.js +116 -0
  137. package/examples/jsm/libs/ecsy.module.js +1792 -0
  138. package/examples/jsm/libs/fflate.module.js +2672 -0
  139. package/examples/jsm/libs/ktx-parse.module.js +1 -0
  140. package/examples/jsm/libs/lil-gui.module.min.js +8 -0
  141. package/examples/jsm/libs/lottie_canvas.module.js +14849 -0
  142. package/examples/jsm/libs/meshopt_decoder.module.js +196 -0
  143. package/examples/jsm/libs/mikktspace.module.js +128 -0
  144. package/examples/jsm/libs/motion-controllers.module.js +397 -0
  145. package/examples/jsm/libs/opentype.module.js +14506 -0
  146. package/examples/jsm/libs/potpack.module.js +125 -0
  147. package/examples/jsm/libs/rhino3dm/rhino3dm.js +21 -0
  148. package/examples/jsm/libs/rhino3dm/rhino3dm.module.js +16 -0
  149. package/examples/jsm/libs/rhino3dm/rhino3dm.wasm +0 -0
  150. package/examples/jsm/libs/stats.module.js +167 -0
  151. package/examples/jsm/libs/surfaceNet.js +201 -0
  152. package/examples/jsm/libs/tween.module.js +876 -0
  153. package/examples/jsm/libs/utif.module.js +1665 -0
  154. package/examples/jsm/libs/zstddec.module.js +1 -0
  155. package/examples/jsm/lighting/DynamicLighting.js +82 -0
  156. package/examples/jsm/lighting/LightProbeGrid.js +651 -0
  157. package/examples/jsm/lighting/TiledLighting.js +42 -0
  158. package/examples/jsm/lights/LightProbeGenerator.js +337 -0
  159. package/examples/jsm/lights/RectAreaLightTexturesLib.js +127 -0
  160. package/examples/jsm/lights/RectAreaLightUniformsLib.js +40 -0
  161. package/examples/jsm/lines/Line2.js +56 -0
  162. package/examples/jsm/lines/LineGeometry.js +157 -0
  163. package/examples/jsm/lines/LineMaterial.js +703 -0
  164. package/examples/jsm/lines/LineSegments2.js +426 -0
  165. package/examples/jsm/lines/LineSegmentsGeometry.js +298 -0
  166. package/examples/jsm/lines/Wireframe.js +108 -0
  167. package/examples/jsm/lines/WireframeGeometry2.js +49 -0
  168. package/examples/jsm/lines/webgpu/Line2.js +46 -0
  169. package/examples/jsm/lines/webgpu/LineSegments2.js +411 -0
  170. package/examples/jsm/lines/webgpu/Wireframe.js +86 -0
  171. package/examples/jsm/loaders/3DMLoader.js +1836 -0
  172. package/examples/jsm/loaders/3MFLoader.js +1621 -0
  173. package/examples/jsm/loaders/AMFLoader.js +541 -0
  174. package/examples/jsm/loaders/BVHLoader.js +484 -0
  175. package/examples/jsm/loaders/ColladaLoader.js +153 -0
  176. package/examples/jsm/loaders/DDSLoader.js +385 -0
  177. package/examples/jsm/loaders/DRACOLoader.js +739 -0
  178. package/examples/jsm/loaders/EXRLoader.js +3423 -0
  179. package/examples/jsm/loaders/FBXLoader.js +4580 -0
  180. package/examples/jsm/loaders/FontLoader.js +260 -0
  181. package/examples/jsm/loaders/GCodeLoader.js +318 -0
  182. package/examples/jsm/loaders/GLTFLoader.js +4860 -0
  183. package/examples/jsm/loaders/HDRCubeTextureLoader.js +164 -0
  184. package/examples/jsm/loaders/HDRLoader.js +485 -0
  185. package/examples/jsm/loaders/IESLoader.js +379 -0
  186. package/examples/jsm/loaders/KMZLoader.js +163 -0
  187. package/examples/jsm/loaders/KTX2Loader.js +1257 -0
  188. package/examples/jsm/loaders/KTXLoader.js +197 -0
  189. package/examples/jsm/loaders/LDrawLoader.js +2510 -0
  190. package/examples/jsm/loaders/LUT3dlLoader.js +205 -0
  191. package/examples/jsm/loaders/LUTCubeLoader.js +190 -0
  192. package/examples/jsm/loaders/LUTImageLoader.js +190 -0
  193. package/examples/jsm/loaders/LWOLoader.js +1047 -0
  194. package/examples/jsm/loaders/LottieLoader.js +130 -0
  195. package/examples/jsm/loaders/MD2Loader.js +435 -0
  196. package/examples/jsm/loaders/MDDLoader.js +147 -0
  197. package/examples/jsm/loaders/MTLLoader.js +593 -0
  198. package/examples/jsm/loaders/MaterialXLoader.js +1104 -0
  199. package/examples/jsm/loaders/NRRDLoader.js +718 -0
  200. package/examples/jsm/loaders/OBJLoader.js +955 -0
  201. package/examples/jsm/loaders/PCDLoader.js +620 -0
  202. package/examples/jsm/loaders/PDBLoader.js +272 -0
  203. package/examples/jsm/loaders/PLYLoader.js +805 -0
  204. package/examples/jsm/loaders/PVRLoader.js +270 -0
  205. package/examples/jsm/loaders/RGBELoader.js +18 -0
  206. package/examples/jsm/loaders/STLLoader.js +421 -0
  207. package/examples/jsm/loaders/SVGLoader.js +3267 -0
  208. package/examples/jsm/loaders/TDSLoader.js +1142 -0
  209. package/examples/jsm/loaders/TGALoader.js +538 -0
  210. package/examples/jsm/loaders/TIFFLoader.js +59 -0
  211. package/examples/jsm/loaders/TTFLoader.js +261 -0
  212. package/examples/jsm/loaders/USDLoader.js +279 -0
  213. package/examples/jsm/loaders/USDZLoader.js +16 -0
  214. package/examples/jsm/loaders/UltraHDRLoader.js +755 -0
  215. package/examples/jsm/loaders/VOXLoader.js +919 -0
  216. package/examples/jsm/loaders/VRMLLoader.js +3646 -0
  217. package/examples/jsm/loaders/VTKLoader.js +1293 -0
  218. package/examples/jsm/loaders/XYZLoader.js +143 -0
  219. package/examples/jsm/loaders/collada/ColladaComposer.js +3044 -0
  220. package/examples/jsm/loaders/collada/ColladaParser.js +1977 -0
  221. package/examples/jsm/loaders/lwo/IFFParser.js +1217 -0
  222. package/examples/jsm/loaders/lwo/LWO2Parser.js +414 -0
  223. package/examples/jsm/loaders/lwo/LWO3Parser.js +373 -0
  224. package/examples/jsm/loaders/usd/USDAParser.js +828 -0
  225. package/examples/jsm/loaders/usd/USDCParser.js +1878 -0
  226. package/examples/jsm/loaders/usd/USDComposer.js +4594 -0
  227. package/examples/jsm/materials/LDrawConditionalLineMaterial.js +183 -0
  228. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +154 -0
  229. package/examples/jsm/materials/WoodNodeMaterial.js +533 -0
  230. package/examples/jsm/math/Capsule.js +159 -0
  231. package/examples/jsm/math/ColorConverter.js +58 -0
  232. package/examples/jsm/math/ColorSpaces.js +147 -0
  233. package/examples/jsm/math/ConvexHull.js +1695 -0
  234. package/examples/jsm/math/ImprovedNoise.js +88 -0
  235. package/examples/jsm/math/Lut.js +317 -0
  236. package/examples/jsm/math/MeshSurfaceSampler.js +315 -0
  237. package/examples/jsm/math/OBB.js +535 -0
  238. package/examples/jsm/math/Octree.js +822 -0
  239. package/examples/jsm/math/SimplexNoise.js +470 -0
  240. package/examples/jsm/misc/ConvexObjectBreaker.js +539 -0
  241. package/examples/jsm/misc/GPUComputationRenderer.js +508 -0
  242. package/examples/jsm/misc/Gyroscope.js +78 -0
  243. package/examples/jsm/misc/MD2Character.js +391 -0
  244. package/examples/jsm/misc/MD2CharacterComplex.js +740 -0
  245. package/examples/jsm/misc/MorphAnimMesh.js +119 -0
  246. package/examples/jsm/misc/MorphBlendMesh.js +425 -0
  247. package/examples/jsm/misc/ProgressiveLightMap.js +370 -0
  248. package/examples/jsm/misc/ProgressiveLightMapGPU.js +322 -0
  249. package/examples/jsm/misc/RollerCoaster.js +661 -0
  250. package/examples/jsm/misc/TubePainter.js +599 -0
  251. package/examples/jsm/misc/Volume.js +520 -0
  252. package/examples/jsm/misc/VolumeSlice.js +275 -0
  253. package/examples/jsm/modifiers/CurveModifier.js +374 -0
  254. package/examples/jsm/modifiers/CurveModifierGPU.js +256 -0
  255. package/examples/jsm/modifiers/EdgeSplitModifier.js +299 -0
  256. package/examples/jsm/modifiers/SimplifyModifier.js +632 -0
  257. package/examples/jsm/modifiers/TessellateModifier.js +340 -0
  258. package/examples/jsm/objects/GroundedSkybox.js +69 -0
  259. package/examples/jsm/objects/Lensflare.js +489 -0
  260. package/examples/jsm/objects/LensflareMesh.js +376 -0
  261. package/examples/jsm/objects/MarchingCubes.js +1261 -0
  262. package/examples/jsm/objects/Reflector.js +386 -0
  263. package/examples/jsm/objects/ReflectorForSSRPass.js +393 -0
  264. package/examples/jsm/objects/Refractor.js +389 -0
  265. package/examples/jsm/objects/ShadowMesh.js +130 -0
  266. package/examples/jsm/objects/Sky.js +321 -0
  267. package/examples/jsm/objects/SkyMesh.js +377 -0
  268. package/examples/jsm/objects/Water.js +374 -0
  269. package/examples/jsm/objects/Water2.js +403 -0
  270. package/examples/jsm/objects/Water2Mesh.js +199 -0
  271. package/examples/jsm/objects/WaterMesh.js +194 -0
  272. package/examples/jsm/offscreen/jank.js +45 -0
  273. package/examples/jsm/offscreen/offscreen.js +8 -0
  274. package/examples/jsm/offscreen/scene.js +86 -0
  275. package/examples/jsm/physics/AmmoPhysics.js +359 -0
  276. package/examples/jsm/physics/JoltPhysics.js +334 -0
  277. package/examples/jsm/physics/RapierPhysics.js +436 -0
  278. package/examples/jsm/postprocessing/AfterimagePass.js +185 -0
  279. package/examples/jsm/postprocessing/BloomPass.js +274 -0
  280. package/examples/jsm/postprocessing/BokehPass.js +218 -0
  281. package/examples/jsm/postprocessing/ClearPass.js +97 -0
  282. package/examples/jsm/postprocessing/CubeTexturePass.js +146 -0
  283. package/examples/jsm/postprocessing/DotScreenPass.js +114 -0
  284. package/examples/jsm/postprocessing/EffectComposer.js +365 -0
  285. package/examples/jsm/postprocessing/FXAAPass.js +40 -0
  286. package/examples/jsm/postprocessing/FilmPass.js +113 -0
  287. package/examples/jsm/postprocessing/GTAOPass.js +727 -0
  288. package/examples/jsm/postprocessing/GlitchPass.js +177 -0
  289. package/examples/jsm/postprocessing/HalftonePass.js +134 -0
  290. package/examples/jsm/postprocessing/LUTPass.js +138 -0
  291. package/examples/jsm/postprocessing/MaskPass.js +195 -0
  292. package/examples/jsm/postprocessing/OutlinePass.js +776 -0
  293. package/examples/jsm/postprocessing/OutputPass.js +148 -0
  294. package/examples/jsm/postprocessing/Pass.js +191 -0
  295. package/examples/jsm/postprocessing/RenderPass.js +193 -0
  296. package/examples/jsm/postprocessing/RenderPixelatedPass.js +314 -0
  297. package/examples/jsm/postprocessing/RenderTransitionPass.js +267 -0
  298. package/examples/jsm/postprocessing/SAOPass.js +407 -0
  299. package/examples/jsm/postprocessing/SMAAPass.js +230 -0
  300. package/examples/jsm/postprocessing/SSAARenderPass.js +313 -0
  301. package/examples/jsm/postprocessing/SSAOPass.js +527 -0
  302. package/examples/jsm/postprocessing/SSRPass.js +856 -0
  303. package/examples/jsm/postprocessing/SavePass.js +132 -0
  304. package/examples/jsm/postprocessing/ShaderPass.js +135 -0
  305. package/examples/jsm/postprocessing/TAARenderPass.js +243 -0
  306. package/examples/jsm/postprocessing/TexturePass.js +131 -0
  307. package/examples/jsm/postprocessing/UnrealBloomPass.js +524 -0
  308. package/examples/jsm/renderers/CSS2DRenderer.js +328 -0
  309. package/examples/jsm/renderers/CSS3DRenderer.js +454 -0
  310. package/examples/jsm/renderers/Projector.js +1154 -0
  311. package/examples/jsm/renderers/SVGRenderer.js +799 -0
  312. package/examples/jsm/shaders/ACESFilmicToneMappingShader.js +96 -0
  313. package/examples/jsm/shaders/AfterimageShader.js +63 -0
  314. package/examples/jsm/shaders/BasicShader.js +36 -0
  315. package/examples/jsm/shaders/BleachBypassShader.js +68 -0
  316. package/examples/jsm/shaders/BlendShader.js +56 -0
  317. package/examples/jsm/shaders/BokehShader.js +151 -0
  318. package/examples/jsm/shaders/BokehShader2.js +404 -0
  319. package/examples/jsm/shaders/BrightnessContrastShader.js +62 -0
  320. package/examples/jsm/shaders/ColorCorrectionShader.js +59 -0
  321. package/examples/jsm/shaders/ColorifyShader.js +57 -0
  322. package/examples/jsm/shaders/ConvolutionShader.js +74 -0
  323. package/examples/jsm/shaders/CopyShader.js +52 -0
  324. package/examples/jsm/shaders/DOFMipMapShader.js +63 -0
  325. package/examples/jsm/shaders/DepthLimitedBlurShader.js +180 -0
  326. package/examples/jsm/shaders/DigitalGlitch.js +104 -0
  327. package/examples/jsm/shaders/DotScreenShader.js +75 -0
  328. package/examples/jsm/shaders/ExposureShader.js +51 -0
  329. package/examples/jsm/shaders/FXAAShader.js +298 -0
  330. package/examples/jsm/shaders/FilmShader.js +72 -0
  331. package/examples/jsm/shaders/FocusShader.js +94 -0
  332. package/examples/jsm/shaders/FreiChenShader.js +103 -0
  333. package/examples/jsm/shaders/GTAOShader.js +434 -0
  334. package/examples/jsm/shaders/GammaCorrectionShader.js +52 -0
  335. package/examples/jsm/shaders/HalftoneShader.js +332 -0
  336. package/examples/jsm/shaders/HorizontalBlurShader.js +68 -0
  337. package/examples/jsm/shaders/HorizontalTiltShiftShader.js +70 -0
  338. package/examples/jsm/shaders/HueSaturationShader.js +74 -0
  339. package/examples/jsm/shaders/KaleidoShader.js +65 -0
  340. package/examples/jsm/shaders/LuminosityHighPassShader.js +68 -0
  341. package/examples/jsm/shaders/LuminosityShader.js +54 -0
  342. package/examples/jsm/shaders/MirrorShader.js +62 -0
  343. package/examples/jsm/shaders/NormalMapShader.js +60 -0
  344. package/examples/jsm/shaders/OutputShader.js +103 -0
  345. package/examples/jsm/shaders/PoissonDenoiseShader.js +239 -0
  346. package/examples/jsm/shaders/RGBShiftShader.js +61 -0
  347. package/examples/jsm/shaders/SAOShader.js +201 -0
  348. package/examples/jsm/shaders/SMAAShader.js +489 -0
  349. package/examples/jsm/shaders/SSAOShader.js +331 -0
  350. package/examples/jsm/shaders/SSRShader.js +396 -0
  351. package/examples/jsm/shaders/SepiaShader.js +57 -0
  352. package/examples/jsm/shaders/SobelOperatorShader.js +98 -0
  353. package/examples/jsm/shaders/SubsurfaceScatteringShader.js +95 -0
  354. package/examples/jsm/shaders/TechnicolorShader.js +51 -0
  355. package/examples/jsm/shaders/ToonShader.js +349 -0
  356. package/examples/jsm/shaders/TriangleBlurShader.js +79 -0
  357. package/examples/jsm/shaders/UnpackDepthRGBAShader.js +60 -0
  358. package/examples/jsm/shaders/VelocityShader.js +137 -0
  359. package/examples/jsm/shaders/VerticalBlurShader.js +66 -0
  360. package/examples/jsm/shaders/VerticalTiltShiftShader.js +70 -0
  361. package/examples/jsm/shaders/VignetteShader.js +56 -0
  362. package/examples/jsm/shaders/VolumeShader.js +298 -0
  363. package/examples/jsm/shaders/WaterRefractionShader.js +106 -0
  364. package/examples/jsm/textures/FlakesTexture.js +54 -0
  365. package/examples/jsm/transpiler/AST.js +675 -0
  366. package/examples/jsm/transpiler/GLSLDecoder.js +1228 -0
  367. package/examples/jsm/transpiler/Linker.js +327 -0
  368. package/examples/jsm/transpiler/ShaderToyDecoder.js +51 -0
  369. package/examples/jsm/transpiler/TSLEncoder.js +983 -0
  370. package/examples/jsm/transpiler/Transpiler.js +67 -0
  371. package/examples/jsm/transpiler/TranspilerUtils.js +29 -0
  372. package/examples/jsm/transpiler/WGSLEncoder.js +839 -0
  373. package/examples/jsm/tsl/WebGLNodesHandler.js +605 -0
  374. package/examples/jsm/tsl/display/AfterImageNode.js +254 -0
  375. package/examples/jsm/tsl/display/AnaglyphPassNode.js +549 -0
  376. package/examples/jsm/tsl/display/AnamorphicNode.js +293 -0
  377. package/examples/jsm/tsl/display/BilateralBlurNode.js +374 -0
  378. package/examples/jsm/tsl/display/BleachBypass.js +33 -0
  379. package/examples/jsm/tsl/display/BloomNode.js +534 -0
  380. package/examples/jsm/tsl/display/CRT.js +150 -0
  381. package/examples/jsm/tsl/display/ChromaticAberrationNode.js +174 -0
  382. package/examples/jsm/tsl/display/DenoiseNode.js +334 -0
  383. package/examples/jsm/tsl/display/DepthOfFieldNode.js +554 -0
  384. package/examples/jsm/tsl/display/DotScreenNode.js +104 -0
  385. package/examples/jsm/tsl/display/FSR1Node.js +477 -0
  386. package/examples/jsm/tsl/display/FXAANode.js +365 -0
  387. package/examples/jsm/tsl/display/FilmNode.js +101 -0
  388. package/examples/jsm/tsl/display/GTAONode.js +572 -0
  389. package/examples/jsm/tsl/display/GaussianBlurNode.js +399 -0
  390. package/examples/jsm/tsl/display/GodraysNode.js +615 -0
  391. package/examples/jsm/tsl/display/LensflareNode.js +279 -0
  392. package/examples/jsm/tsl/display/Lut3DNode.js +109 -0
  393. package/examples/jsm/tsl/display/MotionBlur.js +33 -0
  394. package/examples/jsm/tsl/display/OutlineNode.js +812 -0
  395. package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +89 -0
  396. package/examples/jsm/tsl/display/PixelationPassNode.js +335 -0
  397. package/examples/jsm/tsl/display/RGBShiftNode.js +96 -0
  398. package/examples/jsm/tsl/display/RetroPassNode.js +263 -0
  399. package/examples/jsm/tsl/display/SMAANode.js +768 -0
  400. package/examples/jsm/tsl/display/SSAAPassNode.js +358 -0
  401. package/examples/jsm/tsl/display/SSGINode.js +638 -0
  402. package/examples/jsm/tsl/display/SSRNode.js +656 -0
  403. package/examples/jsm/tsl/display/SSSNode.js +490 -0
  404. package/examples/jsm/tsl/display/Sepia.js +24 -0
  405. package/examples/jsm/tsl/display/Shape.js +29 -0
  406. package/examples/jsm/tsl/display/SharpenNode.js +283 -0
  407. package/examples/jsm/tsl/display/SobelOperatorNode.js +168 -0
  408. package/examples/jsm/tsl/display/StereoCompositePassNode.js +192 -0
  409. package/examples/jsm/tsl/display/StereoPassNode.js +119 -0
  410. package/examples/jsm/tsl/display/TAAUNode.js +835 -0
  411. package/examples/jsm/tsl/display/TRAANode.js +767 -0
  412. package/examples/jsm/tsl/display/TransitionNode.js +141 -0
  413. package/examples/jsm/tsl/display/boxBlur.js +65 -0
  414. package/examples/jsm/tsl/display/depthAwareBlend.js +80 -0
  415. package/examples/jsm/tsl/display/hashBlur.js +54 -0
  416. package/examples/jsm/tsl/display/radialBlur.js +68 -0
  417. package/examples/jsm/tsl/lighting/DynamicLightsNode.js +300 -0
  418. package/examples/jsm/tsl/lighting/TiledLightsNode.js +442 -0
  419. package/examples/jsm/tsl/lighting/data/AmbientLightDataNode.js +61 -0
  420. package/examples/jsm/tsl/lighting/data/DirectionalLightDataNode.js +111 -0
  421. package/examples/jsm/tsl/lighting/data/HemisphereLightDataNode.js +99 -0
  422. package/examples/jsm/tsl/lighting/data/PointLightDataNode.js +134 -0
  423. package/examples/jsm/tsl/lighting/data/SpotLightDataNode.js +161 -0
  424. package/examples/jsm/tsl/math/Bayer.js +84 -0
  425. package/examples/jsm/tsl/shadows/TileShadowNode.js +456 -0
  426. package/examples/jsm/tsl/shadows/TileShadowNodeHelper.js +212 -0
  427. package/examples/jsm/tsl/utils/Raymarching.js +70 -0
  428. package/examples/jsm/utils/BufferGeometryUtils.js +1434 -0
  429. package/examples/jsm/utils/CameraUtils.js +82 -0
  430. package/examples/jsm/utils/ColorUtils.js +76 -0
  431. package/examples/jsm/utils/GeometryCompressionUtils.js +547 -0
  432. package/examples/jsm/utils/GeometryUtils.js +226 -0
  433. package/examples/jsm/utils/LDrawUtils.js +211 -0
  434. package/examples/jsm/utils/SceneOptimizer.js +458 -0
  435. package/examples/jsm/utils/SceneUtils.js +363 -0
  436. package/examples/jsm/utils/ShadowMapViewer.js +244 -0
  437. package/examples/jsm/utils/ShadowMapViewerGPU.js +233 -0
  438. package/examples/jsm/utils/SkeletonUtils.js +496 -0
  439. package/examples/jsm/utils/SortUtils.js +175 -0
  440. package/examples/jsm/utils/UVsDebug.js +173 -0
  441. package/examples/jsm/utils/WebGLTextureUtils.js +115 -0
  442. package/examples/jsm/utils/WebGPUTextureUtils.js +81 -0
  443. package/examples/jsm/utils/WorkerPool.js +167 -0
  444. package/examples/jsm/webxr/ARButton.js +251 -0
  445. package/examples/jsm/webxr/OculusHandModel.js +194 -0
  446. package/examples/jsm/webxr/OculusHandPointerModel.js +539 -0
  447. package/examples/jsm/webxr/Text2D.js +52 -0
  448. package/examples/jsm/webxr/VRButton.js +264 -0
  449. package/examples/jsm/webxr/XRButton.js +246 -0
  450. package/examples/jsm/webxr/XRControllerModelFactory.js +403 -0
  451. package/examples/jsm/webxr/XREstimatedLight.js +254 -0
  452. package/examples/jsm/webxr/XRHandMeshModel.js +177 -0
  453. package/examples/jsm/webxr/XRHandModelFactory.js +198 -0
  454. package/examples/jsm/webxr/XRHandPrimitiveModel.js +147 -0
  455. package/examples/jsm/webxr/XRPlanes.js +118 -0
  456. package/package.json +123 -0
  457. package/src/Three.Core.js +187 -0
  458. package/src/Three.Legacy.js +0 -0
  459. package/src/Three.TSL.js +647 -0
  460. package/src/Three.WebGPU.Nodes.js +31 -0
  461. package/src/Three.WebGPU.js +37 -0
  462. package/src/Three.js +10 -0
  463. package/src/animation/AnimationAction.js +942 -0
  464. package/src/animation/AnimationClip.js +628 -0
  465. package/src/animation/AnimationMixer.js +860 -0
  466. package/src/animation/AnimationObjectGroup.js +411 -0
  467. package/src/animation/AnimationUtils.js +495 -0
  468. package/src/animation/KeyframeTrack.js +636 -0
  469. package/src/animation/PropertyBinding.js +794 -0
  470. package/src/animation/PropertyMixer.js +385 -0
  471. package/src/animation/tracks/BooleanKeyframeTrack.js +55 -0
  472. package/src/animation/tracks/ColorKeyframeTrack.js +36 -0
  473. package/src/animation/tracks/NumberKeyframeTrack.js +36 -0
  474. package/src/animation/tracks/QuaternionKeyframeTrack.js +51 -0
  475. package/src/animation/tracks/StringKeyframeTrack.js +55 -0
  476. package/src/animation/tracks/VectorKeyframeTrack.js +36 -0
  477. package/src/audio/Audio.js +778 -0
  478. package/src/audio/AudioAnalyser.js +97 -0
  479. package/src/audio/AudioContext.js +40 -0
  480. package/src/audio/AudioListener.js +218 -0
  481. package/src/audio/PositionalAudio.js +253 -0
  482. package/src/cameras/ArrayCamera.js +54 -0
  483. package/src/cameras/Camera.js +160 -0
  484. package/src/cameras/CubeCamera.js +259 -0
  485. package/src/cameras/OrthographicCamera.js +245 -0
  486. package/src/cameras/PerspectiveCamera.js +407 -0
  487. package/src/cameras/StereoCamera.js +146 -0
  488. package/src/constants.js +1760 -0
  489. package/src/core/BufferAttribute.js +1056 -0
  490. package/src/core/BufferGeometry.js +1458 -0
  491. package/src/core/Clock.js +135 -0
  492. package/src/core/EventDispatcher.js +131 -0
  493. package/src/core/GLBufferAttribute.js +171 -0
  494. package/src/core/InstancedBufferAttribute.js +68 -0
  495. package/src/core/InstancedBufferGeometry.js +60 -0
  496. package/src/core/InstancedInterleavedBuffer.js +74 -0
  497. package/src/core/InterleavedBuffer.js +291 -0
  498. package/src/core/InterleavedBufferAttribute.js +549 -0
  499. package/src/core/Layers.js +121 -0
  500. package/src/core/Object3D.js +1667 -0
  501. package/src/core/Raycaster.js +262 -0
  502. package/src/core/RenderTarget.js +392 -0
  503. package/src/core/RenderTarget3D.js +48 -0
  504. package/src/core/Timer.js +184 -0
  505. package/src/core/Uniform.js +46 -0
  506. package/src/core/UniformsGroup.js +180 -0
  507. package/src/extras/Controls.js +120 -0
  508. package/src/extras/DataUtils.js +217 -0
  509. package/src/extras/Earcut.js +28 -0
  510. package/src/extras/ImageUtils.js +137 -0
  511. package/src/extras/PMREMGenerator.js +1167 -0
  512. package/src/extras/ShapeUtils.js +114 -0
  513. package/src/extras/TextureUtils.js +297 -0
  514. package/src/extras/core/Curve.js +517 -0
  515. package/src/extras/core/CurvePath.js +296 -0
  516. package/src/extras/core/Interpolations.js +111 -0
  517. package/src/extras/core/Path.js +329 -0
  518. package/src/extras/core/Shape.js +165 -0
  519. package/src/extras/core/ShapePath.js +367 -0
  520. package/src/extras/curves/ArcCurve.js +39 -0
  521. package/src/extras/curves/CatmullRomCurve3.js +327 -0
  522. package/src/extras/curves/CubicBezierCurve.js +145 -0
  523. package/src/extras/curves/CubicBezierCurve3.js +129 -0
  524. package/src/extras/curves/Curves.js +10 -0
  525. package/src/extras/curves/EllipseCurve.js +258 -0
  526. package/src/extras/curves/LineCurve.js +128 -0
  527. package/src/extras/curves/LineCurve3.js +128 -0
  528. package/src/extras/curves/QuadraticBezierCurve.js +133 -0
  529. package/src/extras/curves/QuadraticBezierCurve3.js +118 -0
  530. package/src/extras/curves/SplineCurve.js +145 -0
  531. package/src/extras/lib/earcut.js +685 -0
  532. package/src/geometries/BoxGeometry.js +219 -0
  533. package/src/geometries/CapsuleGeometry.js +218 -0
  534. package/src/geometries/CircleGeometry.js +142 -0
  535. package/src/geometries/ConeGeometry.js +70 -0
  536. package/src/geometries/CylinderGeometry.js +333 -0
  537. package/src/geometries/DodecahedronGeometry.js +99 -0
  538. package/src/geometries/EdgesGeometry.js +180 -0
  539. package/src/geometries/ExtrudeGeometry.js +910 -0
  540. package/src/geometries/Geometries.js +21 -0
  541. package/src/geometries/IcosahedronGeometry.js +75 -0
  542. package/src/geometries/LatheGeometry.js +230 -0
  543. package/src/geometries/OctahedronGeometry.js +70 -0
  544. package/src/geometries/PlaneGeometry.js +133 -0
  545. package/src/geometries/PolyhedronGeometry.js +348 -0
  546. package/src/geometries/RingGeometry.js +165 -0
  547. package/src/geometries/ShapeGeometry.js +233 -0
  548. package/src/geometries/SphereGeometry.js +175 -0
  549. package/src/geometries/TetrahedronGeometry.js +67 -0
  550. package/src/geometries/TorusGeometry.js +161 -0
  551. package/src/geometries/TorusKnotGeometry.js +206 -0
  552. package/src/geometries/TubeGeometry.js +253 -0
  553. package/src/geometries/WireframeGeometry.js +179 -0
  554. package/src/helpers/ArrowHelper.js +171 -0
  555. package/src/helpers/AxesHelper.js +96 -0
  556. package/src/helpers/Box3Helper.js +83 -0
  557. package/src/helpers/BoxHelper.js +149 -0
  558. package/src/helpers/CameraHelper.js +345 -0
  559. package/src/helpers/DirectionalLightHelper.js +148 -0
  560. package/src/helpers/GridHelper.js +82 -0
  561. package/src/helpers/HemisphereLightHelper.js +130 -0
  562. package/src/helpers/PlaneHelper.js +96 -0
  563. package/src/helpers/PointLightHelper.js +111 -0
  564. package/src/helpers/PolarGridHelper.js +126 -0
  565. package/src/helpers/SkeletonHelper.js +194 -0
  566. package/src/helpers/SpotLightHelper.js +154 -0
  567. package/src/lights/AmbientLight.js +42 -0
  568. package/src/lights/DirectionalLight.js +113 -0
  569. package/src/lights/DirectionalLightShadow.js +31 -0
  570. package/src/lights/HemisphereLight.js +76 -0
  571. package/src/lights/Light.js +85 -0
  572. package/src/lights/LightProbe.js +75 -0
  573. package/src/lights/LightShadow.js +347 -0
  574. package/src/lights/PointLight.js +131 -0
  575. package/src/lights/PointLightShadow.js +31 -0
  576. package/src/lights/RectAreaLight.js +115 -0
  577. package/src/lights/SpotLight.js +194 -0
  578. package/src/lights/SpotLightShadow.js +80 -0
  579. package/src/lights/webgpu/IESSpotLight.js +47 -0
  580. package/src/lights/webgpu/ProjectorLight.js +46 -0
  581. package/src/loaders/AnimationLoader.js +98 -0
  582. package/src/loaders/AudioLoader.js +108 -0
  583. package/src/loaders/BufferGeometryLoader.js +242 -0
  584. package/src/loaders/Cache.js +115 -0
  585. package/src/loaders/CompressedTextureLoader.js +167 -0
  586. package/src/loaders/CubeTextureLoader.js +103 -0
  587. package/src/loaders/DataTextureLoader.js +174 -0
  588. package/src/loaders/FileLoader.js +367 -0
  589. package/src/loaders/ImageBitmapLoader.js +223 -0
  590. package/src/loaders/ImageLoader.js +168 -0
  591. package/src/loaders/Loader.js +222 -0
  592. package/src/loaders/LoaderUtils.js +59 -0
  593. package/src/loaders/LoadingManager.js +329 -0
  594. package/src/loaders/MaterialLoader.js +439 -0
  595. package/src/loaders/ObjectLoader.js +1304 -0
  596. package/src/loaders/TextureLoader.js +74 -0
  597. package/src/loaders/nodes/NodeLoader.js +194 -0
  598. package/src/loaders/nodes/NodeMaterialLoader.js +108 -0
  599. package/src/loaders/nodes/NodeObjectLoader.js +169 -0
  600. package/src/materials/LineBasicMaterial.js +122 -0
  601. package/src/materials/LineDashedMaterial.js +86 -0
  602. package/src/materials/Material.js +1017 -0
  603. package/src/materials/Materials.js +39 -0
  604. package/src/materials/MeshBasicMaterial.js +250 -0
  605. package/src/materials/MeshDepthMaterial.js +148 -0
  606. package/src/materials/MeshDistanceMaterial.js +119 -0
  607. package/src/materials/MeshLambertMaterial.js +402 -0
  608. package/src/materials/MeshMatcapMaterial.js +245 -0
  609. package/src/materials/MeshNormalMaterial.js +175 -0
  610. package/src/materials/MeshPhongMaterial.js +421 -0
  611. package/src/materials/MeshPhysicalMaterial.js +536 -0
  612. package/src/materials/MeshStandardMaterial.js +425 -0
  613. package/src/materials/MeshToonMaterial.js +321 -0
  614. package/src/materials/PointsMaterial.js +139 -0
  615. package/src/materials/RawShaderMaterial.js +42 -0
  616. package/src/materials/ShaderMaterial.js +413 -0
  617. package/src/materials/ShadowMaterial.js +91 -0
  618. package/src/materials/SpriteMaterial.js +136 -0
  619. package/src/materials/nodes/Line2NodeMaterial.js +569 -0
  620. package/src/materials/nodes/LineBasicNodeMaterial.js +46 -0
  621. package/src/materials/nodes/LineDashedNodeMaterial.js +132 -0
  622. package/src/materials/nodes/MeshBasicNodeMaterial.js +134 -0
  623. package/src/materials/nodes/MeshLambertNodeMaterial.js +82 -0
  624. package/src/materials/nodes/MeshMatcapNodeMaterial.js +77 -0
  625. package/src/materials/nodes/MeshNormalNodeMaterial.js +67 -0
  626. package/src/materials/nodes/MeshPhongNodeMaterial.js +141 -0
  627. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +521 -0
  628. package/src/materials/nodes/MeshSSSNodeMaterial.js +175 -0
  629. package/src/materials/nodes/MeshStandardNodeMaterial.js +187 -0
  630. package/src/materials/nodes/MeshToonNodeMaterial.js +66 -0
  631. package/src/materials/nodes/NodeMaterial.js +1330 -0
  632. package/src/materials/nodes/NodeMaterials.js +21 -0
  633. package/src/materials/nodes/PointsNodeMaterial.js +211 -0
  634. package/src/materials/nodes/ShadowNodeMaterial.js +76 -0
  635. package/src/materials/nodes/SpriteNodeMaterial.js +186 -0
  636. package/src/materials/nodes/VolumeNodeMaterial.js +81 -0
  637. package/src/materials/nodes/manager/NodeMaterialObserver.js +718 -0
  638. package/src/math/Box2.js +381 -0
  639. package/src/math/Box3.js +805 -0
  640. package/src/math/Color.js +967 -0
  641. package/src/math/ColorManagement.js +215 -0
  642. package/src/math/Cylindrical.js +120 -0
  643. package/src/math/Euler.js +449 -0
  644. package/src/math/Frustum.js +285 -0
  645. package/src/math/FrustumArray.js +258 -0
  646. package/src/math/Interpolant.js +320 -0
  647. package/src/math/Line3.js +337 -0
  648. package/src/math/MathUtils.js +751 -0
  649. package/src/math/Matrix2.js +128 -0
  650. package/src/math/Matrix3.js +617 -0
  651. package/src/math/Matrix4.js +1314 -0
  652. package/src/math/Plane.js +368 -0
  653. package/src/math/Quaternion.js +918 -0
  654. package/src/math/Ray.js +655 -0
  655. package/src/math/Sphere.js +420 -0
  656. package/src/math/Spherical.js +147 -0
  657. package/src/math/SphericalHarmonics3.js +341 -0
  658. package/src/math/Triangle.js +539 -0
  659. package/src/math/Vector2.js +870 -0
  660. package/src/math/Vector3.js +1263 -0
  661. package/src/math/Vector4.js +1067 -0
  662. package/src/math/interpolants/BezierInterpolant.js +108 -0
  663. package/src/math/interpolants/CubicInterpolant.js +159 -0
  664. package/src/math/interpolants/DiscreteInterpolant.js +34 -0
  665. package/src/math/interpolants/LinearInterpolant.js +51 -0
  666. package/src/math/interpolants/QuaternionLinearInterpolant.js +48 -0
  667. package/src/nodes/Nodes.js +166 -0
  668. package/src/nodes/TSL.js +173 -0
  669. package/src/nodes/accessors/AccessorsUtils.js +53 -0
  670. package/src/nodes/accessors/Arrays.js +68 -0
  671. package/src/nodes/accessors/BatchNode.js +163 -0
  672. package/src/nodes/accessors/Bitangent.js +82 -0
  673. package/src/nodes/accessors/BufferAttributeNode.js +432 -0
  674. package/src/nodes/accessors/BufferNode.js +128 -0
  675. package/src/nodes/accessors/BuiltinNode.js +63 -0
  676. package/src/nodes/accessors/Camera.js +403 -0
  677. package/src/nodes/accessors/ClippingNode.js +255 -0
  678. package/src/nodes/accessors/CubeTextureNode.js +215 -0
  679. package/src/nodes/accessors/InstanceNode.js +349 -0
  680. package/src/nodes/accessors/InstancedMeshNode.js +50 -0
  681. package/src/nodes/accessors/Lights.js +139 -0
  682. package/src/nodes/accessors/MaterialNode.js +783 -0
  683. package/src/nodes/accessors/MaterialProperties.js +56 -0
  684. package/src/nodes/accessors/MaterialReferenceNode.js +84 -0
  685. package/src/nodes/accessors/ModelNode.js +184 -0
  686. package/src/nodes/accessors/ModelViewProjectionNode.js +13 -0
  687. package/src/nodes/accessors/MorphNode.js +310 -0
  688. package/src/nodes/accessors/Normal.js +243 -0
  689. package/src/nodes/accessors/Object3DNode.js +268 -0
  690. package/src/nodes/accessors/PointUVNode.js +55 -0
  691. package/src/nodes/accessors/Position.js +122 -0
  692. package/src/nodes/accessors/ReferenceBaseNode.js +357 -0
  693. package/src/nodes/accessors/ReferenceNode.js +424 -0
  694. package/src/nodes/accessors/ReflectVector.js +36 -0
  695. package/src/nodes/accessors/RendererReferenceNode.js +78 -0
  696. package/src/nodes/accessors/SceneProperties.js +47 -0
  697. package/src/nodes/accessors/SkinningNode.js +328 -0
  698. package/src/nodes/accessors/StorageBufferNode.js +405 -0
  699. package/src/nodes/accessors/StorageTextureNode.js +295 -0
  700. package/src/nodes/accessors/Tangent.js +60 -0
  701. package/src/nodes/accessors/TangentUtils.js +46 -0
  702. package/src/nodes/accessors/Texture3DNode.js +196 -0
  703. package/src/nodes/accessors/TextureBicubic.js +92 -0
  704. package/src/nodes/accessors/TextureNode.js +971 -0
  705. package/src/nodes/accessors/TextureSizeNode.js +77 -0
  706. package/src/nodes/accessors/UV.js +11 -0
  707. package/src/nodes/accessors/UniformArrayNode.js +350 -0
  708. package/src/nodes/accessors/UserDataNode.js +76 -0
  709. package/src/nodes/accessors/VelocityNode.js +224 -0
  710. package/src/nodes/accessors/VertexColorNode.js +109 -0
  711. package/src/nodes/code/CodeNode.js +181 -0
  712. package/src/nodes/code/ExpressionNode.js +68 -0
  713. package/src/nodes/code/FunctionCallNode.js +187 -0
  714. package/src/nodes/code/FunctionNode.js +182 -0
  715. package/src/nodes/core/ArrayNode.js +174 -0
  716. package/src/nodes/core/AssignNode.js +202 -0
  717. package/src/nodes/core/AttributeNode.js +168 -0
  718. package/src/nodes/core/BypassNode.js +93 -0
  719. package/src/nodes/core/ConstNode.js +67 -0
  720. package/src/nodes/core/ContextNode.js +283 -0
  721. package/src/nodes/core/IndexNode.js +165 -0
  722. package/src/nodes/core/InputNode.js +136 -0
  723. package/src/nodes/core/InspectorNode.js +128 -0
  724. package/src/nodes/core/IsolateNode.js +133 -0
  725. package/src/nodes/core/LightingModel.js +77 -0
  726. package/src/nodes/core/MRTNode.js +196 -0
  727. package/src/nodes/core/Node.js +1180 -0
  728. package/src/nodes/core/NodeAttribute.js +53 -0
  729. package/src/nodes/core/NodeBuilder.js +3299 -0
  730. package/src/nodes/core/NodeCache.js +75 -0
  731. package/src/nodes/core/NodeCode.js +46 -0
  732. package/src/nodes/core/NodeError.js +28 -0
  733. package/src/nodes/core/NodeFrame.js +314 -0
  734. package/src/nodes/core/NodeFunction.js +69 -0
  735. package/src/nodes/core/NodeFunctionInput.js +61 -0
  736. package/src/nodes/core/NodeParser.js +23 -0
  737. package/src/nodes/core/NodeUniform.js +91 -0
  738. package/src/nodes/core/NodeUtils.js +408 -0
  739. package/src/nodes/core/NodeVar.js +60 -0
  740. package/src/nodes/core/NodeVarying.js +63 -0
  741. package/src/nodes/core/OutputStructNode.js +105 -0
  742. package/src/nodes/core/ParameterNode.js +94 -0
  743. package/src/nodes/core/PropertyNode.js +367 -0
  744. package/src/nodes/core/StackNode.js +426 -0
  745. package/src/nodes/core/StackTrace.js +139 -0
  746. package/src/nodes/core/StructNode.js +134 -0
  747. package/src/nodes/core/StructType.js +13 -0
  748. package/src/nodes/core/StructTypeNode.js +148 -0
  749. package/src/nodes/core/SubBuildNode.js +89 -0
  750. package/src/nodes/core/TempNode.js +88 -0
  751. package/src/nodes/core/UniformGroupNode.js +167 -0
  752. package/src/nodes/core/UniformNode.js +259 -0
  753. package/src/nodes/core/VarNode.js +367 -0
  754. package/src/nodes/core/VaryingNode.js +210 -0
  755. package/src/nodes/core/constants.js +68 -0
  756. package/src/nodes/display/BlendModes.js +171 -0
  757. package/src/nodes/display/BumpMapNode.js +117 -0
  758. package/src/nodes/display/ColorAdjustment.js +158 -0
  759. package/src/nodes/display/ColorSpaceFunctions.js +54 -0
  760. package/src/nodes/display/ColorSpaceNode.js +164 -0
  761. package/src/nodes/display/FrontFacingNode.js +102 -0
  762. package/src/nodes/display/NormalMapNode.js +153 -0
  763. package/src/nodes/display/PassNode.js +1055 -0
  764. package/src/nodes/display/RenderOutputNode.js +150 -0
  765. package/src/nodes/display/ScreenNode.js +292 -0
  766. package/src/nodes/display/ToneMappingFunctions.js +242 -0
  767. package/src/nodes/display/ToneMappingNode.js +147 -0
  768. package/src/nodes/display/ToonOutlinePassNode.js +191 -0
  769. package/src/nodes/display/ViewportDepthNode.js +342 -0
  770. package/src/nodes/display/ViewportDepthTextureNode.js +63 -0
  771. package/src/nodes/display/ViewportSharedTextureNode.js +73 -0
  772. package/src/nodes/display/ViewportTextureNode.js +256 -0
  773. package/src/nodes/fog/Fog.js +97 -0
  774. package/src/nodes/functions/BSDF/BRDF_GGX.js +55 -0
  775. package/src/nodes/functions/BSDF/BRDF_GGX_Multiscatter.js +52 -0
  776. package/src/nodes/functions/BSDF/BRDF_Lambert.js +9 -0
  777. package/src/nodes/functions/BSDF/BRDF_Sheen.js +57 -0
  778. package/src/nodes/functions/BSDF/DFGLUT.js +56 -0
  779. package/src/nodes/functions/BSDF/D_GGX.js +23 -0
  780. package/src/nodes/functions/BSDF/D_GGX_Anisotropic.js +28 -0
  781. package/src/nodes/functions/BSDF/EnvironmentBRDF.js +13 -0
  782. package/src/nodes/functions/BSDF/F_Schlick.js +16 -0
  783. package/src/nodes/functions/BSDF/LTC.js +175 -0
  784. package/src/nodes/functions/BSDF/Schlick_to_F0.js +21 -0
  785. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +26 -0
  786. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +29 -0
  787. package/src/nodes/functions/BasicLightingModel.js +100 -0
  788. package/src/nodes/functions/PhongLightingModel.js +99 -0
  789. package/src/nodes/functions/PhysicalLightingModel.js +878 -0
  790. package/src/nodes/functions/ShadowMaskModel.js +58 -0
  791. package/src/nodes/functions/ToonLightingModel.js +70 -0
  792. package/src/nodes/functions/VolumetricLightingModel.js +183 -0
  793. package/src/nodes/functions/material/getAlphaHashThreshold.js +68 -0
  794. package/src/nodes/functions/material/getGeometryRoughness.js +19 -0
  795. package/src/nodes/functions/material/getParallaxCorrectNormal.js +37 -0
  796. package/src/nodes/functions/material/getRoughness.js +18 -0
  797. package/src/nodes/functions/material/getShIrradianceAt.js +28 -0
  798. package/src/nodes/geometry/RangeNode.js +210 -0
  799. package/src/nodes/gpgpu/AtomicFunctionNode.js +274 -0
  800. package/src/nodes/gpgpu/BarrierNode.js +98 -0
  801. package/src/nodes/gpgpu/ComputeBuiltinNode.js +227 -0
  802. package/src/nodes/gpgpu/ComputeNode.js +310 -0
  803. package/src/nodes/gpgpu/SubgroupFunctionNode.js +455 -0
  804. package/src/nodes/gpgpu/WorkgroupInfoNode.js +234 -0
  805. package/src/nodes/lighting/AONode.js +45 -0
  806. package/src/nodes/lighting/AmbientLightNode.js +35 -0
  807. package/src/nodes/lighting/AnalyticLightNode.js +309 -0
  808. package/src/nodes/lighting/BasicEnvironmentNode.js +49 -0
  809. package/src/nodes/lighting/BasicLightMapNode.js +49 -0
  810. package/src/nodes/lighting/DirectionalLightNode.js +39 -0
  811. package/src/nodes/lighting/EnvironmentNode.js +178 -0
  812. package/src/nodes/lighting/HemisphereLightNode.js +87 -0
  813. package/src/nodes/lighting/IESSpotLightNode.js +49 -0
  814. package/src/nodes/lighting/IrradianceNode.js +44 -0
  815. package/src/nodes/lighting/LightProbeNode.js +73 -0
  816. package/src/nodes/lighting/LightUtils.js +25 -0
  817. package/src/nodes/lighting/LightingContextNode.js +115 -0
  818. package/src/nodes/lighting/LightingNode.js +36 -0
  819. package/src/nodes/lighting/LightsNode.js +432 -0
  820. package/src/nodes/lighting/PointLightNode.js +102 -0
  821. package/src/nodes/lighting/PointShadowNode.js +325 -0
  822. package/src/nodes/lighting/ProjectorLightNode.js +91 -0
  823. package/src/nodes/lighting/RectAreaLightNode.js +133 -0
  824. package/src/nodes/lighting/ShadowBaseNode.js +81 -0
  825. package/src/nodes/lighting/ShadowFilterNode.js +264 -0
  826. package/src/nodes/lighting/ShadowNode.js +889 -0
  827. package/src/nodes/lighting/SpotLightNode.js +168 -0
  828. package/src/nodes/materialx/DISCLAIMER.md +199 -0
  829. package/src/nodes/materialx/MaterialXNodes.js +197 -0
  830. package/src/nodes/materialx/lib/mx_hsv.js +127 -0
  831. package/src/nodes/materialx/lib/mx_noise.js +1491 -0
  832. package/src/nodes/materialx/lib/mx_transform_color.js +23 -0
  833. package/src/nodes/math/BitcastNode.js +156 -0
  834. package/src/nodes/math/BitcountNode.js +433 -0
  835. package/src/nodes/math/ConditionalNode.js +245 -0
  836. package/src/nodes/math/Hash.js +21 -0
  837. package/src/nodes/math/MathNode.js +1202 -0
  838. package/src/nodes/math/MathUtils.js +54 -0
  839. package/src/nodes/math/OperatorNode.js +752 -0
  840. package/src/nodes/math/PackFloatNode.js +98 -0
  841. package/src/nodes/math/TriNoise3D.js +71 -0
  842. package/src/nodes/math/UnpackFloatNode.js +96 -0
  843. package/src/nodes/parsers/GLSLNodeFunction.js +168 -0
  844. package/src/nodes/parsers/GLSLNodeParser.js +25 -0
  845. package/src/nodes/pmrem/PMREMNode.js +397 -0
  846. package/src/nodes/pmrem/PMREMUtils.js +397 -0
  847. package/src/nodes/procedural/Checker.js +22 -0
  848. package/src/nodes/shapes/Shapes.js +33 -0
  849. package/src/nodes/tsl/TSLBase.js +36 -0
  850. package/src/nodes/tsl/TSLCore.js +1250 -0
  851. package/src/nodes/utils/ArrayElementNode.js +90 -0
  852. package/src/nodes/utils/ConvertNode.js +100 -0
  853. package/src/nodes/utils/CubeMapNode.js +237 -0
  854. package/src/nodes/utils/DebugNode.js +83 -0
  855. package/src/nodes/utils/Discard.js +24 -0
  856. package/src/nodes/utils/EquirectUV.js +27 -0
  857. package/src/nodes/utils/EventNode.js +148 -0
  858. package/src/nodes/utils/FlipNode.js +106 -0
  859. package/src/nodes/utils/FunctionOverloadingNode.js +170 -0
  860. package/src/nodes/utils/JoinNode.js +117 -0
  861. package/src/nodes/utils/LoopNode.js +349 -0
  862. package/src/nodes/utils/MatcapUV.js +22 -0
  863. package/src/nodes/utils/MaxMipLevelNode.js +103 -0
  864. package/src/nodes/utils/MemberNode.js +120 -0
  865. package/src/nodes/utils/Oscillators.js +41 -0
  866. package/src/nodes/utils/Packing.js +33 -0
  867. package/src/nodes/utils/PostProcessingUtils.js +154 -0
  868. package/src/nodes/utils/RTTNode.js +289 -0
  869. package/src/nodes/utils/ReflectorNode.js +629 -0
  870. package/src/nodes/utils/Remap.js +48 -0
  871. package/src/nodes/utils/RotateNode.js +103 -0
  872. package/src/nodes/utils/SampleNode.js +91 -0
  873. package/src/nodes/utils/SetNode.js +108 -0
  874. package/src/nodes/utils/SplitNode.js +179 -0
  875. package/src/nodes/utils/SpriteSheetUV.js +35 -0
  876. package/src/nodes/utils/SpriteUtils.js +63 -0
  877. package/src/nodes/utils/StorageArrayElementNode.js +143 -0
  878. package/src/nodes/utils/Timer.js +26 -0
  879. package/src/nodes/utils/TriplanarTextures.js +65 -0
  880. package/src/nodes/utils/UVUtils.js +67 -0
  881. package/src/nodes/utils/ViewportUtils.js +26 -0
  882. package/src/objects/BatchedMesh.js +1682 -0
  883. package/src/objects/Bone.js +41 -0
  884. package/src/objects/ClippingGroup.js +68 -0
  885. package/src/objects/Group.js +41 -0
  886. package/src/objects/InstancedMesh.js +422 -0
  887. package/src/objects/LOD.js +329 -0
  888. package/src/objects/Line.js +329 -0
  889. package/src/objects/LineLoop.js +37 -0
  890. package/src/objects/LineSegments.js +74 -0
  891. package/src/objects/Mesh.js +496 -0
  892. package/src/objects/Points.js +228 -0
  893. package/src/objects/Skeleton.js +392 -0
  894. package/src/objects/SkinnedMesh.js +370 -0
  895. package/src/objects/Sprite.js +245 -0
  896. package/src/renderers/WebGL3DRenderTarget.js +48 -0
  897. package/src/renderers/WebGLArrayRenderTarget.js +48 -0
  898. package/src/renderers/WebGLCubeRenderTarget.js +182 -0
  899. package/src/renderers/WebGLRenderTarget.js +34 -0
  900. package/src/renderers/WebGLRenderer.js +3699 -0
  901. package/src/renderers/common/Animation.js +159 -0
  902. package/src/renderers/common/Attributes.js +132 -0
  903. package/src/renderers/common/Backend.js +769 -0
  904. package/src/renderers/common/Background.js +225 -0
  905. package/src/renderers/common/BindGroup.js +46 -0
  906. package/src/renderers/common/Binding.js +71 -0
  907. package/src/renderers/common/Bindings.js +394 -0
  908. package/src/renderers/common/BlendMode.js +143 -0
  909. package/src/renderers/common/Buffer.js +127 -0
  910. package/src/renderers/common/BufferUtils.js +58 -0
  911. package/src/renderers/common/BundleGroup.js +83 -0
  912. package/src/renderers/common/CanvasTarget.js +341 -0
  913. package/src/renderers/common/ChainMap.js +122 -0
  914. package/src/renderers/common/ClippingContext.js +262 -0
  915. package/src/renderers/common/Color4.js +77 -0
  916. package/src/renderers/common/ComputePipeline.js +41 -0
  917. package/src/renderers/common/Constants.js +15 -0
  918. package/src/renderers/common/CubeRenderTarget.js +147 -0
  919. package/src/renderers/common/DataMap.js +90 -0
  920. package/src/renderers/common/Geometries.js +396 -0
  921. package/src/renderers/common/IndirectStorageBufferAttribute.js +38 -0
  922. package/src/renderers/common/Info.js +501 -0
  923. package/src/renderers/common/InspectorBase.js +151 -0
  924. package/src/renderers/common/Lighting.js +57 -0
  925. package/src/renderers/common/Pipeline.js +35 -0
  926. package/src/renderers/common/Pipelines.js +498 -0
  927. package/src/renderers/common/PostProcessing.js +28 -0
  928. package/src/renderers/common/ProgrammableStage.js +78 -0
  929. package/src/renderers/common/QuadMesh.js +112 -0
  930. package/src/renderers/common/ReadbackBuffer.js +78 -0
  931. package/src/renderers/common/RenderBundle.js +26 -0
  932. package/src/renderers/common/RenderBundles.js +71 -0
  933. package/src/renderers/common/RenderContext.js +281 -0
  934. package/src/renderers/common/RenderContexts.js +100 -0
  935. package/src/renderers/common/RenderList.js +404 -0
  936. package/src/renderers/common/RenderLists.js +78 -0
  937. package/src/renderers/common/RenderObject.js +915 -0
  938. package/src/renderers/common/RenderObjectPipeline.js +40 -0
  939. package/src/renderers/common/RenderObjects.js +218 -0
  940. package/src/renderers/common/RenderPipeline.js +255 -0
  941. package/src/renderers/common/Renderer.js +3654 -0
  942. package/src/renderers/common/RendererUtils.js +200 -0
  943. package/src/renderers/common/SampledTexture.js +152 -0
  944. package/src/renderers/common/Sampler.js +165 -0
  945. package/src/renderers/common/Storage3DTexture.js +100 -0
  946. package/src/renderers/common/StorageArrayTexture.js +84 -0
  947. package/src/renderers/common/StorageBuffer.js +53 -0
  948. package/src/renderers/common/StorageBufferAttribute.js +46 -0
  949. package/src/renderers/common/StorageInstancedBufferAttribute.js +46 -0
  950. package/src/renderers/common/StorageTexture.js +86 -0
  951. package/src/renderers/common/Textures.js +629 -0
  952. package/src/renderers/common/TimestampQueryPool.js +163 -0
  953. package/src/renderers/common/Uniform.js +375 -0
  954. package/src/renderers/common/UniformBuffer.js +34 -0
  955. package/src/renderers/common/UniformsGroup.js +548 -0
  956. package/src/renderers/common/XRManager.js +1684 -0
  957. package/src/renderers/common/XRRenderTarget.js +91 -0
  958. package/src/renderers/common/extras/PMREMGenerator.js +1042 -0
  959. package/src/renderers/common/nodes/NodeBuilderState.js +152 -0
  960. package/src/renderers/common/nodes/NodeLibrary.js +196 -0
  961. package/src/renderers/common/nodes/NodeManager.js +983 -0
  962. package/src/renderers/common/nodes/NodeSampledTexture.js +140 -0
  963. package/src/renderers/common/nodes/NodeSampler.js +62 -0
  964. package/src/renderers/common/nodes/NodeStorageBuffer.js +72 -0
  965. package/src/renderers/common/nodes/NodeUniform.js +418 -0
  966. package/src/renderers/common/nodes/NodeUniformBuffer.js +105 -0
  967. package/src/renderers/common/nodes/NodeUniformsGroup.js +51 -0
  968. package/src/renderers/shaders/DFGLUTData.js +49 -0
  969. package/src/renderers/shaders/ShaderChunk/alphahash_fragment.glsl.js +7 -0
  970. package/src/renderers/shaders/ShaderChunk/alphahash_pars_fragment.glsl.js +68 -0
  971. package/src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl.js +7 -0
  972. package/src/renderers/shaders/ShaderChunk/alphamap_pars_fragment.glsl.js +7 -0
  973. package/src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl.js +16 -0
  974. package/src/renderers/shaders/ShaderChunk/alphatest_pars_fragment.glsl.js +5 -0
  975. package/src/renderers/shaders/ShaderChunk/aomap_fragment.glsl.js +26 -0
  976. package/src/renderers/shaders/ShaderChunk/aomap_pars_fragment.glsl.js +8 -0
  977. package/src/renderers/shaders/ShaderChunk/batching_pars_vertex.glsl.js +49 -0
  978. package/src/renderers/shaders/ShaderChunk/batching_vertex.glsl.js +5 -0
  979. package/src/renderers/shaders/ShaderChunk/begin_vertex.glsl.js +9 -0
  980. package/src/renderers/shaders/ShaderChunk/beginnormal_vertex.glsl.js +9 -0
  981. package/src/renderers/shaders/ShaderChunk/bsdfs.glsl.js +33 -0
  982. package/src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl.js +43 -0
  983. package/src/renderers/shaders/ShaderChunk/clearcoat_normal_fragment_begin.glsl.js +7 -0
  984. package/src/renderers/shaders/ShaderChunk/clearcoat_normal_fragment_maps.glsl.js +10 -0
  985. package/src/renderers/shaders/ShaderChunk/clearcoat_pars_fragment.glsl.js +21 -0
  986. package/src/renderers/shaders/ShaderChunk/clipping_planes_fragment.glsl.js +78 -0
  987. package/src/renderers/shaders/ShaderChunk/clipping_planes_pars_fragment.glsl.js +9 -0
  988. package/src/renderers/shaders/ShaderChunk/clipping_planes_pars_vertex.glsl.js +7 -0
  989. package/src/renderers/shaders/ShaderChunk/clipping_planes_vertex.glsl.js +7 -0
  990. package/src/renderers/shaders/ShaderChunk/color_fragment.glsl.js +7 -0
  991. package/src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl.js +7 -0
  992. package/src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl.js +7 -0
  993. package/src/renderers/shaders/ShaderChunk/color_vertex.glsl.js +29 -0
  994. package/src/renderers/shaders/ShaderChunk/colorspace_fragment.glsl.js +3 -0
  995. package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +15 -0
  996. package/src/renderers/shaders/ShaderChunk/common.glsl.js +125 -0
  997. package/src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl.js +186 -0
  998. package/src/renderers/shaders/ShaderChunk/default_fragment.glsl.js +5 -0
  999. package/src/renderers/shaders/ShaderChunk/default_vertex.glsl.js +5 -0
  1000. package/src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl.js +63 -0
  1001. package/src/renderers/shaders/ShaderChunk/displacementmap_pars_vertex.glsl.js +9 -0
  1002. package/src/renderers/shaders/ShaderChunk/displacementmap_vertex.glsl.js +7 -0
  1003. package/src/renderers/shaders/ShaderChunk/dithering_fragment.glsl.js +7 -0
  1004. package/src/renderers/shaders/ShaderChunk/dithering_pars_fragment.glsl.js +20 -0
  1005. package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +17 -0
  1006. package/src/renderers/shaders/ShaderChunk/emissivemap_pars_fragment.glsl.js +7 -0
  1007. package/src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js +14 -0
  1008. package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +58 -0
  1009. package/src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl.js +21 -0
  1010. package/src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl.js +22 -0
  1011. package/src/renderers/shaders/ShaderChunk/envmap_physical_pars_fragment.glsl.js +69 -0
  1012. package/src/renderers/shaders/ShaderChunk/envmap_vertex.glsl.js +37 -0
  1013. package/src/renderers/shaders/ShaderChunk/fog_fragment.glsl.js +17 -0
  1014. package/src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl.js +19 -0
  1015. package/src/renderers/shaders/ShaderChunk/fog_pars_vertex.glsl.js +7 -0
  1016. package/src/renderers/shaders/ShaderChunk/fog_vertex.glsl.js +7 -0
  1017. package/src/renderers/shaders/ShaderChunk/gradientmap_pars_fragment.glsl.js +27 -0
  1018. package/src/renderers/shaders/ShaderChunk/iridescence_fragment.glsl.js +120 -0
  1019. package/src/renderers/shaders/ShaderChunk/iridescence_pars_fragment.glsl.js +14 -0
  1020. package/src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl.js +8 -0
  1021. package/src/renderers/shaders/ShaderChunk/lightprobes_pars_fragment.glsl.js +80 -0
  1022. package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +213 -0
  1023. package/src/renderers/shaders/ShaderChunk/lights_fragment_end.glsl.js +19 -0
  1024. package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +44 -0
  1025. package/src/renderers/shaders/ShaderChunk/lights_lambert_fragment.glsl.js +5 -0
  1026. package/src/renderers/shaders/ShaderChunk/lights_lambert_pars_fragment.glsl.js +28 -0
  1027. package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +216 -0
  1028. package/src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl.js +7 -0
  1029. package/src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl.js +32 -0
  1030. package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +161 -0
  1031. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +656 -0
  1032. package/src/renderers/shaders/ShaderChunk/lights_toon_fragment.glsl.js +4 -0
  1033. package/src/renderers/shaders/ShaderChunk/lights_toon_pars_fragment.glsl.js +26 -0
  1034. package/src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl.js +9 -0
  1035. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl.js +9 -0
  1036. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl.js +8 -0
  1037. package/src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js +8 -0
  1038. package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +17 -0
  1039. package/src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl.js +7 -0
  1040. package/src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl.js +27 -0
  1041. package/src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl.js +27 -0
  1042. package/src/renderers/shaders/ShaderChunk/metalnessmap_fragment.glsl.js +12 -0
  1043. package/src/renderers/shaders/ShaderChunk/metalnessmap_pars_fragment.glsl.js +7 -0
  1044. package/src/renderers/shaders/ShaderChunk/morphcolor_vertex.glsl.js +24 -0
  1045. package/src/renderers/shaders/ShaderChunk/morphinstance_vertex.glsl.js +14 -0
  1046. package/src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl.js +16 -0
  1047. package/src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl.js +26 -0
  1048. package/src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl.js +16 -0
  1049. package/src/renderers/shaders/ShaderChunk/normal_fragment_begin.glsl.js +76 -0
  1050. package/src/renderers/shaders/ShaderChunk/normal_fragment_maps.glsl.js +40 -0
  1051. package/src/renderers/shaders/ShaderChunk/normal_pars_fragment.glsl.js +14 -0
  1052. package/src/renderers/shaders/ShaderChunk/normal_pars_vertex.glsl.js +14 -0
  1053. package/src/renderers/shaders/ShaderChunk/normal_vertex.glsl.js +14 -0
  1054. package/src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl.js +43 -0
  1055. package/src/renderers/shaders/ShaderChunk/opaque_fragment.glsl.js +11 -0
  1056. package/src/renderers/shaders/ShaderChunk/packing.glsl.js +116 -0
  1057. package/src/renderers/shaders/ShaderChunk/premultiplied_alpha_fragment.glsl.js +7 -0
  1058. package/src/renderers/shaders/ShaderChunk/project_vertex.glsl.js +19 -0
  1059. package/src/renderers/shaders/ShaderChunk/roughnessmap_fragment.glsl.js +12 -0
  1060. package/src/renderers/shaders/ShaderChunk/roughnessmap_pars_fragment.glsl.js +7 -0
  1061. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +376 -0
  1062. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl.js +71 -0
  1063. package/src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl.js +78 -0
  1064. package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +66 -0
  1065. package/src/renderers/shaders/ShaderChunk/skinbase_vertex.glsl.js +10 -0
  1066. package/src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl.js +25 -0
  1067. package/src/renderers/shaders/ShaderChunk/skinning_vertex.glsl.js +15 -0
  1068. package/src/renderers/shaders/ShaderChunk/skinnormal_vertex.glsl.js +20 -0
  1069. package/src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl.js +14 -0
  1070. package/src/renderers/shaders/ShaderChunk/specularmap_pars_fragment.glsl.js +7 -0
  1071. package/src/renderers/shaders/ShaderChunk/tonemapping_fragment.glsl.js +7 -0
  1072. package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +200 -0
  1073. package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +36 -0
  1074. package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +235 -0
  1075. package/src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl.js +119 -0
  1076. package/src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl.js +145 -0
  1077. package/src/renderers/shaders/ShaderChunk/uv_vertex.glsl.js +122 -0
  1078. package/src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl.js +21 -0
  1079. package/src/renderers/shaders/ShaderChunk.js +272 -0
  1080. package/src/renderers/shaders/ShaderLib/background.glsl.js +40 -0
  1081. package/src/renderers/shaders/ShaderLib/backgroundCube.glsl.js +62 -0
  1082. package/src/renderers/shaders/ShaderLib/cube.glsl.js +36 -0
  1083. package/src/renderers/shaders/ShaderLib/depth.glsl.js +117 -0
  1084. package/src/renderers/shaders/ShaderLib/distance.glsl.js +77 -0
  1085. package/src/renderers/shaders/ShaderLib/equirect.glsl.js +35 -0
  1086. package/src/renderers/shaders/ShaderLib/linedashed.glsl.js +76 -0
  1087. package/src/renderers/shaders/ShaderLib/meshbasic.glsl.js +116 -0
  1088. package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +126 -0
  1089. package/src/renderers/shaders/ShaderLib/meshmatcap.glsl.js +112 -0
  1090. package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +86 -0
  1091. package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +128 -0
  1092. package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +224 -0
  1093. package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +118 -0
  1094. package/src/renderers/shaders/ShaderLib/points.glsl.js +87 -0
  1095. package/src/renderers/shaders/ShaderLib/shadow.glsl.js +58 -0
  1096. package/src/renderers/shaders/ShaderLib/sprite.glsl.js +79 -0
  1097. package/src/renderers/shaders/ShaderLib/vsm.glsl.js +51 -0
  1098. package/src/renderers/shaders/ShaderLib.js +362 -0
  1099. package/src/renderers/shaders/UniformsLib.js +234 -0
  1100. package/src/renderers/shaders/UniformsUtils.js +154 -0
  1101. package/src/renderers/webgl/WebGLAnimation.js +54 -0
  1102. package/src/renderers/webgl/WebGLAttributes.js +237 -0
  1103. package/src/renderers/webgl/WebGLBackground.js +303 -0
  1104. package/src/renderers/webgl/WebGLBindingStates.js +666 -0
  1105. package/src/renderers/webgl/WebGLBufferRenderer.js +57 -0
  1106. package/src/renderers/webgl/WebGLCapabilities.js +150 -0
  1107. package/src/renderers/webgl/WebGLClipping.js +171 -0
  1108. package/src/renderers/webgl/WebGLEnvironments.js +228 -0
  1109. package/src/renderers/webgl/WebGLExtensions.js +61 -0
  1110. package/src/renderers/webgl/WebGLGeometries.js +186 -0
  1111. package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +68 -0
  1112. package/src/renderers/webgl/WebGLInfo.js +73 -0
  1113. package/src/renderers/webgl/WebGLLights.js +584 -0
  1114. package/src/renderers/webgl/WebGLMaterials.js +602 -0
  1115. package/src/renderers/webgl/WebGLMorphtargets.js +168 -0
  1116. package/src/renderers/webgl/WebGLObjects.js +94 -0
  1117. package/src/renderers/webgl/WebGLOutput.js +270 -0
  1118. package/src/renderers/webgl/WebGLProgram.js +1031 -0
  1119. package/src/renderers/webgl/WebGLPrograms.js +679 -0
  1120. package/src/renderers/webgl/WebGLProperties.js +55 -0
  1121. package/src/renderers/webgl/WebGLRenderLists.js +253 -0
  1122. package/src/renderers/webgl/WebGLRenderStates.js +124 -0
  1123. package/src/renderers/webgl/WebGLShader.js +12 -0
  1124. package/src/renderers/webgl/WebGLShaderCache.js +124 -0
  1125. package/src/renderers/webgl/WebGLShadowMap.js +600 -0
  1126. package/src/renderers/webgl/WebGLState.js +1370 -0
  1127. package/src/renderers/webgl/WebGLTextures.js +2506 -0
  1128. package/src/renderers/webgl/WebGLUniforms.js +1203 -0
  1129. package/src/renderers/webgl/WebGLUniformsGroups.js +413 -0
  1130. package/src/renderers/webgl/WebGLUtils.js +217 -0
  1131. package/src/renderers/webgl-fallback/WebGLBackend.js +2783 -0
  1132. package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +99 -0
  1133. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +1676 -0
  1134. package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +359 -0
  1135. package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +89 -0
  1136. package/src/renderers/webgl-fallback/utils/WebGLConstants.js +13 -0
  1137. package/src/renderers/webgl-fallback/utils/WebGLExtensions.js +83 -0
  1138. package/src/renderers/webgl-fallback/utils/WebGLState.js +1361 -0
  1139. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +1324 -0
  1140. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +396 -0
  1141. package/src/renderers/webgl-fallback/utils/WebGLUtils.js +317 -0
  1142. package/src/renderers/webgpu/WebGPUBackend.js +2602 -0
  1143. package/src/renderers/webgpu/WebGPURenderer.Nodes.js +69 -0
  1144. package/src/renderers/webgpu/WebGPURenderer.js +107 -0
  1145. package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +66 -0
  1146. package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +100 -0
  1147. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +2523 -0
  1148. package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +187 -0
  1149. package/src/renderers/webgpu/nodes/WGSLNodeParser.js +25 -0
  1150. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +522 -0
  1151. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +642 -0
  1152. package/src/renderers/webgpu/utils/WebGPUCapabilities.js +48 -0
  1153. package/src/renderers/webgpu/utils/WebGPUConstants.js +354 -0
  1154. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +846 -0
  1155. package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +389 -0
  1156. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +1673 -0
  1157. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +310 -0
  1158. package/src/renderers/webgpu/utils/WebGPUUtils.js +269 -0
  1159. package/src/renderers/webxr/WebXRController.js +440 -0
  1160. package/src/renderers/webxr/WebXRDepthSensing.js +155 -0
  1161. package/src/renderers/webxr/WebXRManager.js +1103 -0
  1162. package/src/scenes/Fog.js +98 -0
  1163. package/src/scenes/FogExp2.js +86 -0
  1164. package/src/scenes/Scene.js +165 -0
  1165. package/src/textures/CanvasTexture.js +45 -0
  1166. package/src/textures/CompressedArrayTexture.js +89 -0
  1167. package/src/textures/CompressedCubeTexture.js +48 -0
  1168. package/src/textures/CompressedTexture.js +86 -0
  1169. package/src/textures/CubeDepthTexture.js +76 -0
  1170. package/src/textures/CubeTexture.js +81 -0
  1171. package/src/textures/Data3DTexture.js +112 -0
  1172. package/src/textures/DataArrayTexture.js +134 -0
  1173. package/src/textures/DataTexture.js +87 -0
  1174. package/src/textures/DepthTexture.js +104 -0
  1175. package/src/textures/ExternalTexture.js +56 -0
  1176. package/src/textures/FramebufferTexture.js +85 -0
  1177. package/src/textures/HTMLTexture.js +74 -0
  1178. package/src/textures/Source.js +230 -0
  1179. package/src/textures/Texture.js +812 -0
  1180. package/src/textures/VideoFrameTexture.js +72 -0
  1181. package/src/textures/VideoTexture.js +127 -0
  1182. package/src/utils.js +493 -0
@@ -0,0 +1,3539 @@
1
+ import {
2
+ Controls,
3
+ GridHelper,
4
+ EllipseCurve,
5
+ BufferGeometry,
6
+ Line,
7
+ LineBasicMaterial,
8
+ Raycaster,
9
+ Group,
10
+ Box3,
11
+ Sphere,
12
+ Quaternion,
13
+ Vector2,
14
+ Vector3,
15
+ Matrix4,
16
+ MathUtils
17
+ } from 'three';
18
+
19
+ //trackball state
20
+ const STATE = {
21
+
22
+ IDLE: Symbol(),
23
+ ROTATE: Symbol(),
24
+ PAN: Symbol(),
25
+ SCALE: Symbol(),
26
+ FOV: Symbol(),
27
+ FOCUS: Symbol(),
28
+ ZROTATE: Symbol(),
29
+ TOUCH_MULTI: Symbol(),
30
+ ANIMATION_FOCUS: Symbol(),
31
+ ANIMATION_ROTATE: Symbol()
32
+
33
+ };
34
+
35
+ const INPUT = {
36
+
37
+ NONE: Symbol(),
38
+ ONE_FINGER: Symbol(),
39
+ ONE_FINGER_SWITCHED: Symbol(),
40
+ TWO_FINGER: Symbol(),
41
+ MULT_FINGER: Symbol(),
42
+ CURSOR: Symbol()
43
+
44
+ };
45
+
46
+ //cursor center coordinates
47
+ const _center = {
48
+
49
+ x: 0,
50
+ y: 0
51
+
52
+ };
53
+
54
+ //transformation matrices for gizmos and camera
55
+ const _transformation = {
56
+
57
+ camera: new Matrix4(),
58
+ gizmos: new Matrix4()
59
+
60
+ };
61
+
62
+ /**
63
+ * Fires when the camera has been transformed by the controls.
64
+ *
65
+ * @event ArcballControls#change
66
+ * @type {Object}
67
+ */
68
+ const _changeEvent = { type: 'change' };
69
+
70
+ /**
71
+ * Fires when an interaction was initiated.
72
+ *
73
+ * @event ArcballControls#start
74
+ * @type {Object}
75
+ */
76
+ const _startEvent = { type: 'start' };
77
+
78
+ /**
79
+ * Fires when an interaction has finished.
80
+ *
81
+ * @event ArcballControls#end
82
+ * @type {Object}
83
+ */
84
+ const _endEvent = { type: 'end' };
85
+
86
+ const _raycaster = new Raycaster();
87
+ const _offset = new Vector3();
88
+
89
+ const _gizmoMatrixStateTemp = new Matrix4();
90
+ const _cameraMatrixStateTemp = new Matrix4();
91
+ const _scalePointTemp = new Vector3();
92
+
93
+ const _EPS = 0.000001;
94
+
95
+ /**
96
+ * Arcball controls allow the camera to be controlled by a virtual trackball with full touch support and advanced navigation functionality.
97
+ * Cursor/finger positions and movements are mapped over a virtual trackball surface represented by a gizmo and mapped in intuitive and
98
+ * consistent camera movements. Dragging cursor/fingers will cause camera to orbit around the center of the trackball in a conservative
99
+ * way (returning to the starting point will make the camera return to its starting orientation).
100
+ *
101
+ * In addition to supporting pan, zoom and pinch gestures, double clicking/tapping focuses on a point, intuitively moving the object's
102
+ * point of interest to the center of the virtual trackball. Focus allows a much better inspection and navigation in complex environment.
103
+ * Moreover Arcball controls allow FOV manipulation (in a vertigo-style method) and z-rotation. Saving and restoring of Camera State
104
+ * is supported also through clipboard (use ctrl+c and ctrl+v shortcuts for copy and paste the state).
105
+ *
106
+ * Unlike {@link OrbitControls} and {@link TrackballControls}, `ArcballControls` doesn't require `update()` to be called externally in an
107
+ * animation loop when animations are on.
108
+ *
109
+ * @augments Controls
110
+ * @three_import import { ArcballControls } from 'three/addons/controls/ArcballControls.js';
111
+ */
112
+ class ArcballControls extends Controls {
113
+
114
+ /**
115
+ * Constructs a new controls instance.
116
+ *
117
+ * @param {Camera} camera - The camera to be controlled. The camera must not be a child of another object, unless that object is the scene itself.
118
+ * @param {?HTMLElement} [domElement=null] - The HTML element used for event listeners.
119
+ * @param {?Scene} [scene=null] The scene rendered by the camera. If not given, gizmos cannot be shown.
120
+ */
121
+ constructor( camera, domElement = null, scene = null ) {
122
+
123
+ super( camera, domElement );
124
+
125
+ /**
126
+ * The scene rendered by the camera. If not given, gizmos cannot be shown.
127
+ *
128
+ * @type {?Scene}
129
+ * @default null
130
+ */
131
+ this.scene = scene;
132
+
133
+ /**
134
+ * The control's focus point.
135
+ *
136
+ * @type {Vector3}
137
+ */
138
+ this.target = new Vector3();
139
+ this._currentTarget = new Vector3();
140
+
141
+ /**
142
+ * The size of the gizmo relative to the screen width and height.
143
+ *
144
+ * @type {number}
145
+ * @default 0.67
146
+ */
147
+ this.radiusFactor = 0.67;
148
+
149
+ /**
150
+ * Holds the mouse actions of this controls. This property is maintained by the methods
151
+ * `setMouseAction()` and `unsetMouseAction()`.
152
+ *
153
+ * @type {Array<Object>}
154
+ */
155
+ this.mouseActions = [];
156
+ this._mouseOp = null;
157
+
158
+
159
+ //global vectors and matrices that are used in some operations to avoid creating new objects every time (e.g. every time cursor moves)
160
+ this._v2_1 = new Vector2();
161
+ this._v3_1 = new Vector3();
162
+ this._v3_2 = new Vector3();
163
+
164
+ this._m4_1 = new Matrix4();
165
+ this._m4_2 = new Matrix4();
166
+
167
+ this._quat = new Quaternion();
168
+
169
+ //transformation matrices
170
+ this._translationMatrix = new Matrix4(); //matrix for translation operation
171
+ this._rotationMatrix = new Matrix4(); //matrix for rotation operation
172
+ this._scaleMatrix = new Matrix4(); //matrix for scaling operation
173
+
174
+ this._rotationAxis = new Vector3(); //axis for rotate operation
175
+
176
+
177
+ //camera state
178
+ this._cameraMatrixState = new Matrix4();
179
+ this._cameraProjectionState = new Matrix4();
180
+
181
+ this._fovState = 1;
182
+ this._upState = new Vector3();
183
+ this._zoomState = 1;
184
+ this._nearPos = 0;
185
+ this._farPos = 0;
186
+
187
+ this._gizmoMatrixState = new Matrix4();
188
+
189
+ //initial values
190
+ this._up0 = new Vector3();
191
+ this._zoom0 = 1;
192
+ this._fov0 = 0;
193
+ this._initialNear = 0;
194
+ this._nearPos0 = 0;
195
+ this._initialFar = 0;
196
+ this._farPos0 = 0;
197
+ this._cameraMatrixState0 = new Matrix4();
198
+ this._gizmoMatrixState0 = new Matrix4();
199
+ this._target0 = new Vector3();
200
+
201
+ //pointers array
202
+ this._button = - 1;
203
+ this._touchStart = [];
204
+ this._touchCurrent = [];
205
+ this._input = INPUT.NONE;
206
+
207
+ //two fingers touch interaction
208
+ this._switchSensibility = 32; //minimum movement to be performed to fire single pan start after the second finger has been released
209
+ this._startFingerDistance = 0; //distance between two fingers
210
+ this._currentFingerDistance = 0;
211
+ this._startFingerRotation = 0; //amount of rotation performed with two fingers
212
+ this._currentFingerRotation = 0;
213
+
214
+ //double tap
215
+ this._devPxRatio = 0;
216
+ this._downValid = true;
217
+ this._nclicks = 0;
218
+ this._downEvents = [];
219
+ this._downStart = 0; //pointerDown time
220
+ this._clickStart = 0; //first click time
221
+ this._maxDownTime = 250;
222
+ this._maxInterval = 300;
223
+ this._posThreshold = 24;
224
+ this._movementThreshold = 24;
225
+
226
+ //cursor positions
227
+ this._currentCursorPosition = new Vector3();
228
+ this._startCursorPosition = new Vector3();
229
+
230
+ //grid
231
+ this._grid = null; //grid to be visualized during pan operation
232
+ this._gridPosition = new Vector3();
233
+
234
+ //gizmos
235
+ this._gizmos = new Group();
236
+ this._curvePts = 128;
237
+
238
+
239
+ //animations
240
+ this._timeStart = - 1; //initial time
241
+ this._animationId = - 1;
242
+
243
+ /**
244
+ * Duration of focus animations in ms.
245
+ *
246
+ * @type {number}
247
+ * @default 500
248
+ */
249
+ this.focusAnimationTime = 500;
250
+
251
+ //rotate animation
252
+ this._timePrev = 0; //time at which previous rotate operation has been detected
253
+ this._timeCurrent = 0; //time at which current rotate operation has been detected
254
+ this._anglePrev = 0; //angle of previous rotation
255
+ this._angleCurrent = 0; //angle of current rotation
256
+ this._cursorPosPrev = new Vector3(); //cursor position when previous rotate operation has been detected
257
+ this._cursorPosCurr = new Vector3();//cursor position when current rotate operation has been detected
258
+ this._wPrev = 0; //angular velocity of the previous rotate operation
259
+ this._wCurr = 0; //angular velocity of the current rotate operation
260
+
261
+ //parameters
262
+
263
+ /**
264
+ * If set to `true`, the camera's near and far values will be adjusted every time zoom is
265
+ * performed trying to maintain the same visible portion given by initial near and far
266
+ * values. Only works with perspective cameras.
267
+ *
268
+ * @type {boolean}
269
+ * @default false
270
+ */
271
+ this.adjustNearFar = false;
272
+
273
+ /**
274
+ * The scaling factor used when performing zoom operation.
275
+ *
276
+ * @type {number}
277
+ * @default 1.1
278
+ */
279
+ this.scaleFactor = 1.1;
280
+
281
+ /**
282
+ * The damping inertia used if 'enableAnimations` is set to `true`.
283
+ *
284
+ * @type {number}
285
+ * @default 25
286
+ */
287
+ this.dampingFactor = 25;
288
+
289
+ /**
290
+ * Maximum angular velocity allowed on rotation animation start.
291
+ *
292
+ * @type {number}
293
+ * @default 20
294
+ */
295
+ this.wMax = 20;
296
+
297
+ /**
298
+ * Set to `true` to enable animations for rotation (damping) and focus operation.
299
+ *
300
+ * @type {boolean}
301
+ * @default true
302
+ */
303
+ this.enableAnimations = true;
304
+
305
+ /**
306
+ * If set to `true`, a grid will appear when panning operation is being performed
307
+ * (desktop interaction only).
308
+ *
309
+ * @type {boolean}
310
+ * @default false
311
+ */
312
+ this.enableGrid = false;
313
+
314
+ /**
315
+ * Set to `true` to make zoom become cursor centered.
316
+ *
317
+ * @type {boolean}
318
+ * @default false
319
+ */
320
+ this.cursorZoom = false;
321
+
322
+ /**
323
+ * The minimum FOV in degrees.
324
+ *
325
+ * @type {number}
326
+ * @default 5
327
+ */
328
+ this.minFov = 5;
329
+
330
+ /**
331
+ * The maximum FOV in degrees.
332
+ *
333
+ * @type {number}
334
+ * @default 90
335
+ */
336
+ this.maxFov = 90;
337
+
338
+ /**
339
+ * Speed of rotation.
340
+ *
341
+ * @type {number}
342
+ * @default 1
343
+ */
344
+ this.rotateSpeed = 1;
345
+
346
+ /**
347
+ * Enable or disable camera panning.
348
+ *
349
+ * @type {boolean}
350
+ * @default true
351
+ */
352
+ this.enablePan = true;
353
+
354
+ /**
355
+ * Enable or disable camera rotation.
356
+ *
357
+ * @type {boolean}
358
+ * @default true
359
+ */
360
+ this.enableRotate = true;
361
+
362
+ /**
363
+ * Enable or disable camera zoom.
364
+ *
365
+ * @type {boolean}
366
+ * @default true
367
+ */
368
+ this.enableZoom = true;
369
+
370
+ /**
371
+ * Enable or disable gizmos.
372
+ *
373
+ * @type {boolean}
374
+ * @default true
375
+ */
376
+ this.enableGizmos = true;
377
+
378
+ /**
379
+ * Enable or disable camera focusing on double-tap (or click) operations.
380
+ *
381
+ * @type {boolean}
382
+ * @default true
383
+ */
384
+ this.enableFocus = true;
385
+
386
+ /**
387
+ * How far you can dolly in. For perspective cameras only.
388
+ *
389
+ * @type {number}
390
+ * @default 0
391
+ */
392
+ this.minDistance = 0;
393
+
394
+ /**
395
+ * How far you can dolly out. For perspective cameras only.
396
+ *
397
+ * @type {number}
398
+ * @default Infinity
399
+ */
400
+ this.maxDistance = Infinity;
401
+
402
+ /**
403
+ * How far you can zoom in. For orthographic cameras only.
404
+ *
405
+ * @type {number}
406
+ * @default 0
407
+ */
408
+ this.minZoom = 0;
409
+
410
+ /**
411
+ * How far you can zoom out. For orthographic cameras only.
412
+ *
413
+ * @type {number}
414
+ * @default Infinity
415
+ */
416
+ this.maxZoom = Infinity;
417
+
418
+ //trackball parameters
419
+ this._tbRadius = 1;
420
+
421
+ //FSA
422
+ this._state = STATE.IDLE;
423
+
424
+ this.setCamera( camera );
425
+
426
+ if ( this.scene != null ) {
427
+
428
+ this.scene.add( this._gizmos );
429
+
430
+ }
431
+
432
+ this.initializeMouseActions();
433
+
434
+ // event listeners
435
+
436
+ this._onContextMenu = onContextMenu.bind( this );
437
+ this._onWheel = onWheel.bind( this );
438
+ this._onPointerUp = onPointerUp.bind( this );
439
+ this._onPointerMove = onPointerMove.bind( this );
440
+ this._onPointerDown = onPointerDown.bind( this );
441
+ this._onPointerCancel = onPointerCancel.bind( this );
442
+ this._onWindowResize = onWindowResize.bind( this );
443
+
444
+ if ( domElement !== null ) {
445
+
446
+ this.connect( domElement );
447
+
448
+ }
449
+
450
+ }
451
+
452
+ connect( element ) {
453
+
454
+ super.connect( element );
455
+
456
+ this._devPxRatio = window.devicePixelRatio;
457
+
458
+ this.domElement.addEventListener( 'contextmenu', this._onContextMenu );
459
+ this.domElement.addEventListener( 'wheel', this._onWheel, { passive: false } );
460
+ this.domElement.addEventListener( 'pointerdown', this._onPointerDown );
461
+ this.domElement.addEventListener( 'pointercancel', this._onPointerCancel );
462
+
463
+ window.addEventListener( 'resize', this._onWindowResize );
464
+
465
+ this.domElement.style.touchAction = 'none'; // Disable touch scroll
466
+
467
+ }
468
+
469
+ disconnect() {
470
+
471
+ this.domElement.removeEventListener( 'pointerdown', this._onPointerDown );
472
+ this.domElement.removeEventListener( 'pointercancel', this._onPointerCancel );
473
+ this.domElement.removeEventListener( 'wheel', this._onWheel );
474
+ this.domElement.removeEventListener( 'contextmenu', this._onContextMenu );
475
+
476
+ window.removeEventListener( 'pointermove', this._onPointerMove );
477
+ window.removeEventListener( 'pointerup', this._onPointerUp );
478
+
479
+ window.removeEventListener( 'resize', this._onWindowResize );
480
+
481
+ this.domElement.style.touchAction = ''; // Restore touch scroll
482
+
483
+ }
484
+
485
+ onSinglePanStart( event, operation ) {
486
+
487
+ if ( this.enabled ) {
488
+
489
+ this.dispatchEvent( _startEvent );
490
+
491
+ this.setCenter( event.clientX, event.clientY );
492
+
493
+ switch ( operation ) {
494
+
495
+ case 'PAN':
496
+
497
+ if ( ! this.enablePan ) {
498
+
499
+ return;
500
+
501
+ }
502
+
503
+ if ( this._animationId != - 1 ) {
504
+
505
+ cancelAnimationFrame( this._animationId );
506
+ this._animationId = - 1;
507
+ this._timeStart = - 1;
508
+
509
+ this.activateGizmos( false );
510
+ this.dispatchEvent( _changeEvent );
511
+
512
+ }
513
+
514
+ this.updateTbState( STATE.PAN, true );
515
+ this._startCursorPosition.copy( this.unprojectOnTbPlane( this.object, _center.x, _center.y, this.domElement ) );
516
+ if ( this.enableGrid ) {
517
+
518
+ this.drawGrid();
519
+ this.dispatchEvent( _changeEvent );
520
+
521
+ }
522
+
523
+ break;
524
+
525
+ case 'ROTATE':
526
+
527
+ if ( ! this.enableRotate ) {
528
+
529
+ return;
530
+
531
+ }
532
+
533
+ if ( this._animationId != - 1 ) {
534
+
535
+ cancelAnimationFrame( this._animationId );
536
+ this._animationId = - 1;
537
+ this._timeStart = - 1;
538
+
539
+ }
540
+
541
+ this.updateTbState( STATE.ROTATE, true );
542
+ this._startCursorPosition.copy( this.unprojectOnTbSurface( this.object, _center.x, _center.y, this.domElement, this._tbRadius ) );
543
+ this.activateGizmos( true );
544
+ if ( this.enableAnimations ) {
545
+
546
+ this._timePrev = this._timeCurrent = performance.now();
547
+ this._angleCurrent = this._anglePrev = 0;
548
+ this._cursorPosPrev.copy( this._startCursorPosition );
549
+ this._cursorPosCurr.copy( this._cursorPosPrev );
550
+ this._wCurr = 0;
551
+ this._wPrev = this._wCurr;
552
+
553
+ }
554
+
555
+ this.dispatchEvent( _changeEvent );
556
+ break;
557
+
558
+ case 'FOV':
559
+
560
+ if ( ! this.object.isPerspectiveCamera || ! this.enableZoom ) {
561
+
562
+ return;
563
+
564
+ }
565
+
566
+ if ( this._animationId != - 1 ) {
567
+
568
+ cancelAnimationFrame( this._animationId );
569
+ this._animationId = - 1;
570
+ this._timeStart = - 1;
571
+
572
+ this.activateGizmos( false );
573
+ this.dispatchEvent( _changeEvent );
574
+
575
+ }
576
+
577
+ this.updateTbState( STATE.FOV, true );
578
+ this._startCursorPosition.setY( this.getCursorNDC( _center.x, _center.y, this.domElement ).y * 0.5 );
579
+ this._currentCursorPosition.copy( this._startCursorPosition );
580
+ break;
581
+
582
+ case 'ZOOM':
583
+
584
+ if ( ! this.enableZoom ) {
585
+
586
+ return;
587
+
588
+ }
589
+
590
+ if ( this._animationId != - 1 ) {
591
+
592
+ cancelAnimationFrame( this._animationId );
593
+ this._animationId = - 1;
594
+ this._timeStart = - 1;
595
+
596
+ this.activateGizmos( false );
597
+ this.dispatchEvent( _changeEvent );
598
+
599
+ }
600
+
601
+ this.updateTbState( STATE.SCALE, true );
602
+ this._startCursorPosition.setY( this.getCursorNDC( _center.x, _center.y, this.domElement ).y * 0.5 );
603
+ this._currentCursorPosition.copy( this._startCursorPosition );
604
+ break;
605
+
606
+ }
607
+
608
+ }
609
+
610
+ }
611
+
612
+ onSinglePanMove( event, opState ) {
613
+
614
+ if ( this.enabled ) {
615
+
616
+ const restart = opState != this._state;
617
+ this.setCenter( event.clientX, event.clientY );
618
+
619
+ switch ( opState ) {
620
+
621
+ case STATE.PAN:
622
+
623
+ if ( this.enablePan ) {
624
+
625
+ if ( restart ) {
626
+
627
+ //switch to pan operation
628
+
629
+ this.dispatchEvent( _endEvent );
630
+ this.dispatchEvent( _startEvent );
631
+
632
+ this.updateTbState( opState, true );
633
+ this._startCursorPosition.copy( this.unprojectOnTbPlane( this.object, _center.x, _center.y, this.domElement ) );
634
+ if ( this.enableGrid ) {
635
+
636
+ this.drawGrid();
637
+
638
+ }
639
+
640
+ this.activateGizmos( false );
641
+
642
+ } else {
643
+
644
+ //continue with pan operation
645
+ this._currentCursorPosition.copy( this.unprojectOnTbPlane( this.object, _center.x, _center.y, this.domElement ) );
646
+ this.applyTransformMatrix( this.pan( this._startCursorPosition, this._currentCursorPosition ) );
647
+
648
+ }
649
+
650
+ }
651
+
652
+ break;
653
+
654
+ case STATE.ROTATE:
655
+
656
+ if ( this.enableRotate ) {
657
+
658
+ if ( restart ) {
659
+
660
+ //switch to rotate operation
661
+
662
+ this.dispatchEvent( _endEvent );
663
+ this.dispatchEvent( _startEvent );
664
+
665
+ this.updateTbState( opState, true );
666
+ this._startCursorPosition.copy( this.unprojectOnTbSurface( this.object, _center.x, _center.y, this.domElement, this._tbRadius ) );
667
+
668
+ if ( this.enableGrid ) {
669
+
670
+ this.disposeGrid();
671
+
672
+ }
673
+
674
+ this.activateGizmos( true );
675
+
676
+ } else {
677
+
678
+ //continue with rotate operation
679
+ this._currentCursorPosition.copy( this.unprojectOnTbSurface( this.object, _center.x, _center.y, this.domElement, this._tbRadius ) );
680
+
681
+ const distance = this._startCursorPosition.distanceTo( this._currentCursorPosition );
682
+ const angle = this._startCursorPosition.angleTo( this._currentCursorPosition );
683
+ const amount = Math.max( distance / this._tbRadius, angle ) * this.rotateSpeed; //effective rotation angle
684
+
685
+ this.applyTransformMatrix( this.rotate( this.calculateRotationAxis( this._startCursorPosition, this._currentCursorPosition ), amount ) );
686
+
687
+ if ( this.enableAnimations ) {
688
+
689
+ this._timePrev = this._timeCurrent;
690
+ this._timeCurrent = performance.now();
691
+ this._anglePrev = this._angleCurrent;
692
+ this._angleCurrent = amount;
693
+ this._cursorPosPrev.copy( this._cursorPosCurr );
694
+ this._cursorPosCurr.copy( this._currentCursorPosition );
695
+ this._wPrev = this._wCurr;
696
+ this._wCurr = this.calculateAngularSpeed( this._anglePrev, this._angleCurrent, this._timePrev, this._timeCurrent );
697
+
698
+ }
699
+
700
+ }
701
+
702
+ }
703
+
704
+ break;
705
+
706
+ case STATE.SCALE:
707
+
708
+ if ( this.enableZoom ) {
709
+
710
+ if ( restart ) {
711
+
712
+ //switch to zoom operation
713
+
714
+ this.dispatchEvent( _endEvent );
715
+ this.dispatchEvent( _startEvent );
716
+
717
+ this.updateTbState( opState, true );
718
+ this._startCursorPosition.setY( this.getCursorNDC( _center.x, _center.y, this.domElement ).y * 0.5 );
719
+ this._currentCursorPosition.copy( this._startCursorPosition );
720
+
721
+ if ( this.enableGrid ) {
722
+
723
+ this.disposeGrid();
724
+
725
+ }
726
+
727
+ this.activateGizmos( false );
728
+
729
+ } else {
730
+
731
+ //continue with zoom operation
732
+ const screenNotches = 8; //how many wheel notches corresponds to a full screen pan
733
+ this._currentCursorPosition.setY( this.getCursorNDC( _center.x, _center.y, this.domElement ).y * 0.5 );
734
+
735
+ const movement = this._currentCursorPosition.y - this._startCursorPosition.y;
736
+
737
+ let size = 1;
738
+
739
+ if ( movement < 0 ) {
740
+
741
+ size = 1 / ( Math.pow( this.scaleFactor, - movement * screenNotches ) );
742
+
743
+ } else if ( movement > 0 ) {
744
+
745
+ size = Math.pow( this.scaleFactor, movement * screenNotches );
746
+
747
+ }
748
+
749
+ this._v3_1.setFromMatrixPosition( this._gizmoMatrixState );
750
+
751
+ this.applyTransformMatrix( this.scale( size, this._v3_1 ) );
752
+
753
+ }
754
+
755
+ }
756
+
757
+ break;
758
+
759
+ case STATE.FOV:
760
+
761
+ if ( this.enableZoom && this.object.isPerspectiveCamera ) {
762
+
763
+ if ( restart ) {
764
+
765
+ //switch to fov operation
766
+
767
+ this.dispatchEvent( _endEvent );
768
+ this.dispatchEvent( _startEvent );
769
+
770
+ this.updateTbState( opState, true );
771
+ this._startCursorPosition.setY( this.getCursorNDC( _center.x, _center.y, this.domElement ).y * 0.5 );
772
+ this._currentCursorPosition.copy( this._startCursorPosition );
773
+
774
+ if ( this.enableGrid ) {
775
+
776
+ this.disposeGrid();
777
+
778
+ }
779
+
780
+ this.activateGizmos( false );
781
+
782
+ } else {
783
+
784
+ //continue with fov operation
785
+ const screenNotches = 8; //how many wheel notches corresponds to a full screen pan
786
+ this._currentCursorPosition.setY( this.getCursorNDC( _center.x, _center.y, this.domElement ).y * 0.5 );
787
+
788
+ const movement = this._currentCursorPosition.y - this._startCursorPosition.y;
789
+
790
+ let size = 1;
791
+
792
+ if ( movement < 0 ) {
793
+
794
+ size = 1 / ( Math.pow( this.scaleFactor, - movement * screenNotches ) );
795
+
796
+ } else if ( movement > 0 ) {
797
+
798
+ size = Math.pow( this.scaleFactor, movement * screenNotches );
799
+
800
+ }
801
+
802
+ this._v3_1.setFromMatrixPosition( this._cameraMatrixState );
803
+ const x = this._v3_1.distanceTo( this._gizmos.position );
804
+ let xNew = x / size; //distance between camera and gizmos if scale(size, scalepoint) would be performed
805
+
806
+ //check min and max distance
807
+ xNew = MathUtils.clamp( xNew, this.minDistance, this.maxDistance );
808
+
809
+ const y = x * Math.tan( MathUtils.DEG2RAD * this._fovState * 0.5 );
810
+
811
+ //calculate new fov
812
+ let newFov = MathUtils.RAD2DEG * ( Math.atan( y / xNew ) * 2 );
813
+
814
+ //check min and max fov
815
+ newFov = MathUtils.clamp( newFov, this.minFov, this.maxFov );
816
+
817
+ const newDistance = y / Math.tan( MathUtils.DEG2RAD * ( newFov / 2 ) );
818
+ size = x / newDistance;
819
+ this._v3_2.setFromMatrixPosition( this._gizmoMatrixState );
820
+
821
+ this.setFov( newFov );
822
+ this.applyTransformMatrix( this.scale( size, this._v3_2, false ) );
823
+
824
+ //adjusting distance
825
+ _offset.copy( this._gizmos.position ).sub( this.object.position ).normalize().multiplyScalar( newDistance / x );
826
+ this._m4_1.makeTranslation( _offset.x, _offset.y, _offset.z );
827
+
828
+ }
829
+
830
+ }
831
+
832
+ break;
833
+
834
+ }
835
+
836
+ this.dispatchEvent( _changeEvent );
837
+
838
+ }
839
+
840
+ }
841
+
842
+ onSinglePanEnd() {
843
+
844
+ if ( this._state == STATE.ROTATE ) {
845
+
846
+
847
+ if ( ! this.enableRotate ) {
848
+
849
+ return;
850
+
851
+ }
852
+
853
+ if ( this.enableAnimations ) {
854
+
855
+ //perform rotation animation
856
+ const deltaTime = ( performance.now() - this._timeCurrent );
857
+ if ( deltaTime < 120 ) {
858
+
859
+ const w = Math.abs( ( this._wPrev + this._wCurr ) / 2 );
860
+
861
+ const self = this;
862
+ this._animationId = window.requestAnimationFrame( function ( t ) {
863
+
864
+ self.updateTbState( STATE.ANIMATION_ROTATE, true );
865
+ const rotationAxis = self.calculateRotationAxis( self._cursorPosPrev, self._cursorPosCurr );
866
+
867
+ self.onRotationAnim( t, rotationAxis, Math.min( w, self.wMax ) );
868
+
869
+ } );
870
+
871
+ } else {
872
+
873
+ //cursor has been standing still for over 120 ms since last movement
874
+ this.updateTbState( STATE.IDLE, false );
875
+ this.activateGizmos( false );
876
+ this.dispatchEvent( _changeEvent );
877
+
878
+ }
879
+
880
+ } else {
881
+
882
+ this.updateTbState( STATE.IDLE, false );
883
+ this.activateGizmos( false );
884
+ this.dispatchEvent( _changeEvent );
885
+
886
+ }
887
+
888
+ } else if ( this._state == STATE.PAN || this._state == STATE.IDLE ) {
889
+
890
+ this.updateTbState( STATE.IDLE, false );
891
+
892
+ if ( this.enableGrid ) {
893
+
894
+ this.disposeGrid();
895
+
896
+ }
897
+
898
+ this.activateGizmos( false );
899
+ this.dispatchEvent( _changeEvent );
900
+
901
+
902
+ }
903
+
904
+ this.dispatchEvent( _endEvent );
905
+
906
+ }
907
+
908
+ onDoubleTap( event ) {
909
+
910
+ if ( this.enabled && this.enablePan && this.enableFocus && this.scene != null ) {
911
+
912
+ this.dispatchEvent( _startEvent );
913
+
914
+ this.setCenter( event.clientX, event.clientY );
915
+ const hitP = this.unprojectOnObj( this.getCursorNDC( _center.x, _center.y, this.domElement ), this.object );
916
+
917
+ if ( hitP != null && this.enableAnimations ) {
918
+
919
+ const self = this;
920
+ if ( this._animationId != - 1 ) {
921
+
922
+ window.cancelAnimationFrame( this._animationId );
923
+
924
+ }
925
+
926
+ this._timeStart = - 1;
927
+ this._animationId = window.requestAnimationFrame( function ( t ) {
928
+
929
+ self.updateTbState( STATE.ANIMATION_FOCUS, true );
930
+ self.onFocusAnim( t, hitP, self._cameraMatrixState, self._gizmoMatrixState );
931
+
932
+ } );
933
+
934
+ } else if ( hitP != null && ! this.enableAnimations ) {
935
+
936
+ this.updateTbState( STATE.FOCUS, true );
937
+ this.focus( hitP, this.scaleFactor );
938
+ this.updateTbState( STATE.IDLE, false );
939
+ this.dispatchEvent( _changeEvent );
940
+
941
+ }
942
+
943
+ }
944
+
945
+ this.dispatchEvent( _endEvent );
946
+
947
+ }
948
+
949
+ onDoublePanStart() {
950
+
951
+ if ( this.enabled && this.enablePan ) {
952
+
953
+ this.dispatchEvent( _startEvent );
954
+
955
+ this.updateTbState( STATE.PAN, true );
956
+
957
+ this.setCenter( ( this._touchCurrent[ 0 ].clientX + this._touchCurrent[ 1 ].clientX ) / 2, ( this._touchCurrent[ 0 ].clientY + this._touchCurrent[ 1 ].clientY ) / 2 );
958
+ this._startCursorPosition.copy( this.unprojectOnTbPlane( this.object, _center.x, _center.y, this.domElement, true ) );
959
+ this._currentCursorPosition.copy( this._startCursorPosition );
960
+
961
+ this.activateGizmos( false );
962
+
963
+ }
964
+
965
+ }
966
+
967
+ onDoublePanMove() {
968
+
969
+ if ( this.enabled && this.enablePan ) {
970
+
971
+ this.setCenter( ( this._touchCurrent[ 0 ].clientX + this._touchCurrent[ 1 ].clientX ) / 2, ( this._touchCurrent[ 0 ].clientY + this._touchCurrent[ 1 ].clientY ) / 2 );
972
+
973
+ if ( this._state != STATE.PAN ) {
974
+
975
+ this.updateTbState( STATE.PAN, true );
976
+ this._startCursorPosition.copy( this._currentCursorPosition );
977
+
978
+ }
979
+
980
+ this._currentCursorPosition.copy( this.unprojectOnTbPlane( this.object, _center.x, _center.y, this.domElement, true ) );
981
+ this.applyTransformMatrix( this.pan( this._startCursorPosition, this._currentCursorPosition, true ) );
982
+ this.dispatchEvent( _changeEvent );
983
+
984
+ }
985
+
986
+ }
987
+
988
+ onDoublePanEnd() {
989
+
990
+ this.updateTbState( STATE.IDLE, false );
991
+ this.dispatchEvent( _endEvent );
992
+
993
+ }
994
+
995
+ onRotateStart() {
996
+
997
+ if ( this.enabled && this.enableRotate ) {
998
+
999
+ this.dispatchEvent( _startEvent );
1000
+
1001
+ this.updateTbState( STATE.ZROTATE, true );
1002
+
1003
+ //this._startFingerRotation = event.rotation;
1004
+
1005
+ this._startFingerRotation = this.getAngle( this._touchCurrent[ 1 ], this._touchCurrent[ 0 ] ) + this.getAngle( this._touchStart[ 1 ], this._touchStart[ 0 ] );
1006
+ this._currentFingerRotation = this._startFingerRotation;
1007
+
1008
+ this.object.getWorldDirection( this._rotationAxis ); //rotation axis
1009
+
1010
+ if ( ! this.enablePan && ! this.enableZoom ) {
1011
+
1012
+ this.activateGizmos( true );
1013
+
1014
+ }
1015
+
1016
+ }
1017
+
1018
+ }
1019
+
1020
+ onRotateMove() {
1021
+
1022
+ if ( this.enabled && this.enableRotate ) {
1023
+
1024
+ this.setCenter( ( this._touchCurrent[ 0 ].clientX + this._touchCurrent[ 1 ].clientX ) / 2, ( this._touchCurrent[ 0 ].clientY + this._touchCurrent[ 1 ].clientY ) / 2 );
1025
+ let rotationPoint;
1026
+
1027
+ if ( this._state != STATE.ZROTATE ) {
1028
+
1029
+ this.updateTbState( STATE.ZROTATE, true );
1030
+ this._startFingerRotation = this._currentFingerRotation;
1031
+
1032
+ }
1033
+
1034
+ //this._currentFingerRotation = event.rotation;
1035
+ this._currentFingerRotation = this.getAngle( this._touchCurrent[ 1 ], this._touchCurrent[ 0 ] ) + this.getAngle( this._touchStart[ 1 ], this._touchStart[ 0 ] );
1036
+
1037
+ if ( ! this.enablePan ) {
1038
+
1039
+ rotationPoint = new Vector3().setFromMatrixPosition( this._gizmoMatrixState );
1040
+
1041
+ } else {
1042
+
1043
+ this._v3_2.setFromMatrixPosition( this._gizmoMatrixState );
1044
+ rotationPoint = this.unprojectOnTbPlane( this.object, _center.x, _center.y, this.domElement ).applyQuaternion( this.object.quaternion ).multiplyScalar( 1 / this.object.zoom ).add( this._v3_2 );
1045
+
1046
+ }
1047
+
1048
+ const amount = MathUtils.DEG2RAD * ( this._startFingerRotation - this._currentFingerRotation );
1049
+
1050
+ this.applyTransformMatrix( this.zRotate( rotationPoint, amount ) );
1051
+ this.dispatchEvent( _changeEvent );
1052
+
1053
+ }
1054
+
1055
+ }
1056
+
1057
+ onRotateEnd() {
1058
+
1059
+ this.updateTbState( STATE.IDLE, false );
1060
+ this.activateGizmos( false );
1061
+ this.dispatchEvent( _endEvent );
1062
+
1063
+ }
1064
+
1065
+ onPinchStart() {
1066
+
1067
+ if ( this.enabled && this.enableZoom ) {
1068
+
1069
+ this.dispatchEvent( _startEvent );
1070
+ this.updateTbState( STATE.SCALE, true );
1071
+
1072
+ this._startFingerDistance = this.calculatePointersDistance( this._touchCurrent[ 0 ], this._touchCurrent[ 1 ] );
1073
+ this._currentFingerDistance = this._startFingerDistance;
1074
+
1075
+ this.activateGizmos( false );
1076
+
1077
+ }
1078
+
1079
+ }
1080
+
1081
+ onPinchMove() {
1082
+
1083
+ if ( this.enabled && this.enableZoom ) {
1084
+
1085
+ this.setCenter( ( this._touchCurrent[ 0 ].clientX + this._touchCurrent[ 1 ].clientX ) / 2, ( this._touchCurrent[ 0 ].clientY + this._touchCurrent[ 1 ].clientY ) / 2 );
1086
+ const minDistance = 12; //minimum distance between fingers (in css pixels)
1087
+
1088
+ if ( this._state != STATE.SCALE ) {
1089
+
1090
+ this._startFingerDistance = this._currentFingerDistance;
1091
+ this.updateTbState( STATE.SCALE, true );
1092
+
1093
+ }
1094
+
1095
+ this._currentFingerDistance = Math.max( this.calculatePointersDistance( this._touchCurrent[ 0 ], this._touchCurrent[ 1 ] ), minDistance * this._devPxRatio );
1096
+ const amount = this._currentFingerDistance / this._startFingerDistance;
1097
+
1098
+ let scalePoint;
1099
+
1100
+ if ( ! this.enablePan ) {
1101
+
1102
+ scalePoint = this._gizmos.position;
1103
+
1104
+ } else {
1105
+
1106
+ if ( this.object.isOrthographicCamera ) {
1107
+
1108
+ scalePoint = this.unprojectOnTbPlane( this.object, _center.x, _center.y, this.domElement )
1109
+ .applyQuaternion( this.object.quaternion )
1110
+ .multiplyScalar( 1 / this.object.zoom )
1111
+ .add( this._gizmos.position );
1112
+
1113
+ } else if ( this.object.isPerspectiveCamera ) {
1114
+
1115
+ scalePoint = this.unprojectOnTbPlane( this.object, _center.x, _center.y, this.domElement )
1116
+ .applyQuaternion( this.object.quaternion )
1117
+ .add( this._gizmos.position );
1118
+
1119
+ }
1120
+
1121
+ }
1122
+
1123
+ this.applyTransformMatrix( this.scale( amount, scalePoint ) );
1124
+ this.dispatchEvent( _changeEvent );
1125
+
1126
+ }
1127
+
1128
+ }
1129
+
1130
+ onPinchEnd() {
1131
+
1132
+ this.updateTbState( STATE.IDLE, false );
1133
+ this.dispatchEvent( _endEvent );
1134
+
1135
+ }
1136
+
1137
+ onTriplePanStart() {
1138
+
1139
+ if ( this.enabled && this.enableZoom ) {
1140
+
1141
+ this.dispatchEvent( _startEvent );
1142
+
1143
+ this.updateTbState( STATE.SCALE, true );
1144
+
1145
+ //const center = event.center;
1146
+ let clientX = 0;
1147
+ let clientY = 0;
1148
+ const nFingers = this._touchCurrent.length;
1149
+
1150
+ for ( let i = 0; i < nFingers; i ++ ) {
1151
+
1152
+ clientX += this._touchCurrent[ i ].clientX;
1153
+ clientY += this._touchCurrent[ i ].clientY;
1154
+
1155
+ }
1156
+
1157
+ this.setCenter( clientX / nFingers, clientY / nFingers );
1158
+
1159
+ this._startCursorPosition.setY( this.getCursorNDC( _center.x, _center.y, this.domElement ).y * 0.5 );
1160
+ this._currentCursorPosition.copy( this._startCursorPosition );
1161
+
1162
+ }
1163
+
1164
+ }
1165
+
1166
+ onTriplePanMove() {
1167
+
1168
+ if ( this.enabled && this.enableZoom ) {
1169
+
1170
+ // fov / 2
1171
+ // |\
1172
+ // | \
1173
+ // | \
1174
+ // x | \
1175
+ // | \
1176
+ // | \
1177
+ // | _ _ _\
1178
+ // y
1179
+
1180
+ //const center = event.center;
1181
+ let clientX = 0;
1182
+ let clientY = 0;
1183
+ const nFingers = this._touchCurrent.length;
1184
+
1185
+ for ( let i = 0; i < nFingers; i ++ ) {
1186
+
1187
+ clientX += this._touchCurrent[ i ].clientX;
1188
+ clientY += this._touchCurrent[ i ].clientY;
1189
+
1190
+ }
1191
+
1192
+ this.setCenter( clientX / nFingers, clientY / nFingers );
1193
+
1194
+ const screenNotches = 8; //how many wheel notches corresponds to a full screen pan
1195
+ this._currentCursorPosition.setY( this.getCursorNDC( _center.x, _center.y, this.domElement ).y * 0.5 );
1196
+
1197
+ const movement = this._currentCursorPosition.y - this._startCursorPosition.y;
1198
+
1199
+ let size = 1;
1200
+
1201
+ if ( movement < 0 ) {
1202
+
1203
+ size = 1 / ( Math.pow( this.scaleFactor, - movement * screenNotches ) );
1204
+
1205
+ } else if ( movement > 0 ) {
1206
+
1207
+ size = Math.pow( this.scaleFactor, movement * screenNotches );
1208
+
1209
+ }
1210
+
1211
+ this._v3_1.setFromMatrixPosition( this._cameraMatrixState );
1212
+ const x = this._v3_1.distanceTo( this._gizmos.position );
1213
+ let xNew = x / size; //distance between camera and gizmos if scale(size, scalepoint) would be performed
1214
+
1215
+ //check min and max distance
1216
+ xNew = MathUtils.clamp( xNew, this.minDistance, this.maxDistance );
1217
+
1218
+ const y = x * Math.tan( MathUtils.DEG2RAD * this._fovState * 0.5 );
1219
+
1220
+ //calculate new fov
1221
+ let newFov = MathUtils.RAD2DEG * ( Math.atan( y / xNew ) * 2 );
1222
+
1223
+ //check min and max fov
1224
+ newFov = MathUtils.clamp( newFov, this.minFov, this.maxFov );
1225
+
1226
+ const newDistance = y / Math.tan( MathUtils.DEG2RAD * ( newFov / 2 ) );
1227
+ size = x / newDistance;
1228
+ this._v3_2.setFromMatrixPosition( this._gizmoMatrixState );
1229
+
1230
+ this.setFov( newFov );
1231
+ this.applyTransformMatrix( this.scale( size, this._v3_2, false ) );
1232
+
1233
+ //adjusting distance
1234
+ _offset.copy( this._gizmos.position ).sub( this.object.position ).normalize().multiplyScalar( newDistance / x );
1235
+ this._m4_1.makeTranslation( _offset.x, _offset.y, _offset.z );
1236
+
1237
+ this.dispatchEvent( _changeEvent );
1238
+
1239
+ }
1240
+
1241
+ }
1242
+
1243
+ onTriplePanEnd() {
1244
+
1245
+ this.updateTbState( STATE.IDLE, false );
1246
+ this.dispatchEvent( _endEvent );
1247
+ //this.dispatchEvent( _changeEvent );
1248
+
1249
+ }
1250
+
1251
+ /**
1252
+ * Set _center's x/y coordinates.
1253
+ *
1254
+ * @private
1255
+ * @param {number} clientX - The x coordinate.
1256
+ * @param {number} clientY - The y coordinate.
1257
+ */
1258
+ setCenter( clientX, clientY ) {
1259
+
1260
+ _center.x = clientX;
1261
+ _center.y = clientY;
1262
+
1263
+ }
1264
+
1265
+ /**
1266
+ * Set default mouse actions.
1267
+ *
1268
+ * @private
1269
+ */
1270
+ initializeMouseActions() {
1271
+
1272
+ this.setMouseAction( 'PAN', 0, 'CTRL' );
1273
+ this.setMouseAction( 'PAN', 2 );
1274
+
1275
+ this.setMouseAction( 'ROTATE', 0 );
1276
+
1277
+ this.setMouseAction( 'ZOOM', 'WHEEL' );
1278
+ this.setMouseAction( 'ZOOM', 1 );
1279
+
1280
+ this.setMouseAction( 'FOV', 'WHEEL', 'SHIFT' );
1281
+ this.setMouseAction( 'FOV', 1, 'SHIFT' );
1282
+
1283
+
1284
+ }
1285
+
1286
+ /**
1287
+ * Compare two mouse actions.
1288
+ *
1289
+ * @private
1290
+ * @param {Object} action1 - The first mouse action.
1291
+ * @param {Object} action2 - The second mouse action.
1292
+ * @returns {boolean} `true` if action1 and action 2 are the same mouse action, `false` otherwise.
1293
+ */
1294
+ compareMouseAction( action1, action2 ) {
1295
+
1296
+ if ( action1.operation == action2.operation ) {
1297
+
1298
+ if ( action1.mouse == action2.mouse && action1.key == action2.key ) {
1299
+
1300
+ return true;
1301
+
1302
+ } else {
1303
+
1304
+ return false;
1305
+
1306
+ }
1307
+
1308
+ } else {
1309
+
1310
+ return false;
1311
+
1312
+ }
1313
+
1314
+ }
1315
+
1316
+ /**
1317
+ * Set a new mouse action by specifying the operation to be performed and a mouse/key combination. In case of conflict, replaces the existing one.
1318
+ *
1319
+ * @param {'PAN'|'ROTATE'|'ZOOM'|'FOV'} operation - The operation to be performed ('PAN', 'ROTATE', 'ZOOM', 'FOV').
1320
+ * @param {0|1|2|'WHEEL'} mouse - A mouse button (0, 1, 2) or 'WHEEL' for wheel notches.
1321
+ * @param {?('CTRL'|'SHIFT')} [key=null] - The keyboard modifier ('CTRL', 'SHIFT') or null if key is not needed.
1322
+ * @returns {boolean} `true` if the mouse action has been successfully added, `false` otherwise.
1323
+ */
1324
+ setMouseAction( operation, mouse, key = null ) {
1325
+
1326
+ const operationInput = [ 'PAN', 'ROTATE', 'ZOOM', 'FOV' ];
1327
+ const mouseInput = [ 0, 1, 2, 'WHEEL' ];
1328
+ const keyInput = [ 'CTRL', 'SHIFT', null ];
1329
+ let state;
1330
+
1331
+ if ( ! operationInput.includes( operation ) || ! mouseInput.includes( mouse ) || ! keyInput.includes( key ) ) {
1332
+
1333
+ //invalid parameters
1334
+ return false;
1335
+
1336
+ }
1337
+
1338
+ if ( mouse == 'WHEEL' ) {
1339
+
1340
+ if ( operation != 'ZOOM' && operation != 'FOV' ) {
1341
+
1342
+ //cannot associate 2D operation to 1D input
1343
+ return false;
1344
+
1345
+ }
1346
+
1347
+ }
1348
+
1349
+ switch ( operation ) {
1350
+
1351
+ case 'PAN':
1352
+
1353
+ state = STATE.PAN;
1354
+ break;
1355
+
1356
+ case 'ROTATE':
1357
+
1358
+ state = STATE.ROTATE;
1359
+ break;
1360
+
1361
+ case 'ZOOM':
1362
+
1363
+ state = STATE.SCALE;
1364
+ break;
1365
+
1366
+ case 'FOV':
1367
+
1368
+ state = STATE.FOV;
1369
+ break;
1370
+
1371
+ }
1372
+
1373
+ const action = {
1374
+
1375
+ operation: operation,
1376
+ mouse: mouse,
1377
+ key: key,
1378
+ state: state
1379
+
1380
+ };
1381
+
1382
+ for ( let i = 0; i < this.mouseActions.length; i ++ ) {
1383
+
1384
+ if ( this.mouseActions[ i ].mouse == action.mouse && this.mouseActions[ i ].key == action.key ) {
1385
+
1386
+ this.mouseActions.splice( i, 1, action );
1387
+ return true;
1388
+
1389
+ }
1390
+
1391
+ }
1392
+
1393
+ this.mouseActions.push( action );
1394
+ return true;
1395
+
1396
+ }
1397
+
1398
+ /**
1399
+ * Remove a mouse action by specifying its mouse/key combination.
1400
+ *
1401
+ * @param {0|1|2|'WHEEL'} mouse - A mouse button (0, 1, 2) or 'WHEEL' for wheel notches.
1402
+ * @param {?('CTRL'|'SHIFT')} key - The keyboard modifier ('CTRL', 'SHIFT') or null if key is not needed.
1403
+ * @returns {boolean} `true` if the operation has been successfully removed, `false` otherwise.
1404
+ */
1405
+ unsetMouseAction( mouse, key = null ) {
1406
+
1407
+ for ( let i = 0; i < this.mouseActions.length; i ++ ) {
1408
+
1409
+ if ( this.mouseActions[ i ].mouse == mouse && this.mouseActions[ i ].key == key ) {
1410
+
1411
+ this.mouseActions.splice( i, 1 );
1412
+ return true;
1413
+
1414
+ }
1415
+
1416
+ }
1417
+
1418
+ return false;
1419
+
1420
+ }
1421
+
1422
+ /**
1423
+ * Return the operation associated to a mouse/keyboard combination.
1424
+ *
1425
+ * @private
1426
+ * @param {0|1|2|'WHEEL'} mouse - Mouse button index (0, 1, 2) or 'WHEEL' for wheel notches.
1427
+ * @param {?('CTRL'|'SHIFT')} key - Keyboard modifier.
1428
+ * @returns {?('PAN'|'ROTATE'|'ZOOM'|'FOV')} The operation if it has been found, `null` otherwise.
1429
+ */
1430
+ getOpFromAction( mouse, key ) {
1431
+
1432
+ let action;
1433
+
1434
+ for ( let i = 0; i < this.mouseActions.length; i ++ ) {
1435
+
1436
+ action = this.mouseActions[ i ];
1437
+ if ( action.mouse == mouse && action.key == key ) {
1438
+
1439
+ return action.operation;
1440
+
1441
+ }
1442
+
1443
+ }
1444
+
1445
+ if ( key != null ) {
1446
+
1447
+ for ( let i = 0; i < this.mouseActions.length; i ++ ) {
1448
+
1449
+ action = this.mouseActions[ i ];
1450
+ if ( action.mouse == mouse && action.key == null ) {
1451
+
1452
+ return action.operation;
1453
+
1454
+ }
1455
+
1456
+ }
1457
+
1458
+ }
1459
+
1460
+ return null;
1461
+
1462
+ }
1463
+
1464
+ /**
1465
+ * Get the operation associated to mouse and key combination and returns the corresponding FSA state.
1466
+ *
1467
+ * @private
1468
+ * @param {0|1|2} mouse - Mouse button index (0, 1, 2)
1469
+ * @param {?('CTRL'|'SHIFT')} key - Keyboard modifier
1470
+ * @returns {?STATE} The FSA state obtained from the operation associated to mouse/keyboard combination.
1471
+ */
1472
+ getOpStateFromAction( mouse, key ) {
1473
+
1474
+ let action;
1475
+
1476
+ for ( let i = 0; i < this.mouseActions.length; i ++ ) {
1477
+
1478
+ action = this.mouseActions[ i ];
1479
+ if ( action.mouse == mouse && action.key == key ) {
1480
+
1481
+ return action.state;
1482
+
1483
+ }
1484
+
1485
+ }
1486
+
1487
+ if ( key != null ) {
1488
+
1489
+ for ( let i = 0; i < this.mouseActions.length; i ++ ) {
1490
+
1491
+ action = this.mouseActions[ i ];
1492
+ if ( action.mouse == mouse && action.key == null ) {
1493
+
1494
+ return action.state;
1495
+
1496
+ }
1497
+
1498
+ }
1499
+
1500
+ }
1501
+
1502
+ return null;
1503
+
1504
+ }
1505
+
1506
+ /**
1507
+ * Calculate the angle between two pointers.
1508
+ *
1509
+ * @private
1510
+ * @param {PointerEvent} p1 - The first pointer event.
1511
+ * @param {PointerEvent} p2 - The second pointer event.
1512
+ * @returns {number} The angle between two pointers in degrees.
1513
+ */
1514
+ getAngle( p1, p2 ) {
1515
+
1516
+ return Math.atan2( p2.clientY - p1.clientY, p2.clientX - p1.clientX ) * 180 / Math.PI;
1517
+
1518
+ }
1519
+
1520
+ /**
1521
+ * Updates a PointerEvent inside current pointerevents array.
1522
+ *
1523
+ * @private
1524
+ * @param {PointerEvent} event - The pointer event.
1525
+ */
1526
+ updateTouchEvent( event ) {
1527
+
1528
+ for ( let i = 0; i < this._touchCurrent.length; i ++ ) {
1529
+
1530
+ if ( this._touchCurrent[ i ].pointerId == event.pointerId ) {
1531
+
1532
+ this._touchCurrent.splice( i, 1, event );
1533
+ break;
1534
+
1535
+ }
1536
+
1537
+ }
1538
+
1539
+ }
1540
+
1541
+ /**
1542
+ * Applies a transformation matrix, to the camera and gizmos.
1543
+ *
1544
+ * @private
1545
+ * @param {Object} transformation - Object containing matrices to apply to camera and gizmos.
1546
+ */
1547
+ applyTransformMatrix( transformation ) {
1548
+
1549
+ if ( transformation.camera != null ) {
1550
+
1551
+ this._m4_1.copy( this._cameraMatrixState ).premultiply( transformation.camera );
1552
+ this._m4_1.decompose( this.object.position, this.object.quaternion, this.object.scale );
1553
+ this.object.updateMatrix();
1554
+
1555
+ //update camera up vector
1556
+ if ( this._state == STATE.ROTATE || this._state == STATE.ZROTATE || this._state == STATE.ANIMATION_ROTATE ) {
1557
+
1558
+ this.object.up.copy( this._upState ).applyQuaternion( this.object.quaternion );
1559
+
1560
+ }
1561
+
1562
+ }
1563
+
1564
+ if ( transformation.gizmos != null ) {
1565
+
1566
+ this._m4_1.copy( this._gizmoMatrixState ).premultiply( transformation.gizmos );
1567
+ this._m4_1.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale );
1568
+ this._gizmos.updateMatrix();
1569
+
1570
+ }
1571
+
1572
+ if ( this._state == STATE.SCALE || this._state == STATE.FOCUS || this._state == STATE.ANIMATION_FOCUS ) {
1573
+
1574
+ this._tbRadius = this.calculateTbRadius( this.object );
1575
+
1576
+ if ( this.adjustNearFar ) {
1577
+
1578
+ const cameraDistance = this.object.position.distanceTo( this._gizmos.position );
1579
+
1580
+ const bb = new Box3();
1581
+ bb.setFromObject( this._gizmos );
1582
+ const sphere = new Sphere();
1583
+ bb.getBoundingSphere( sphere );
1584
+
1585
+ const adjustedNearPosition = Math.max( this._nearPos0, sphere.radius + sphere.center.length() );
1586
+ const regularNearPosition = cameraDistance - this._initialNear;
1587
+
1588
+ const minNearPos = Math.min( adjustedNearPosition, regularNearPosition );
1589
+ this.object.near = cameraDistance - minNearPos;
1590
+
1591
+
1592
+ const adjustedFarPosition = Math.min( this._farPos0, - sphere.radius + sphere.center.length() );
1593
+ const regularFarPosition = cameraDistance - this._initialFar;
1594
+
1595
+ const minFarPos = Math.min( adjustedFarPosition, regularFarPosition );
1596
+ this.object.far = cameraDistance - minFarPos;
1597
+
1598
+ this.object.updateProjectionMatrix();
1599
+
1600
+ } else {
1601
+
1602
+ let update = false;
1603
+
1604
+ if ( this.object.near != this._initialNear ) {
1605
+
1606
+ this.object.near = this._initialNear;
1607
+ update = true;
1608
+
1609
+ }
1610
+
1611
+ if ( this.object.far != this._initialFar ) {
1612
+
1613
+ this.object.far = this._initialFar;
1614
+ update = true;
1615
+
1616
+ }
1617
+
1618
+ if ( update ) {
1619
+
1620
+ this.object.updateProjectionMatrix();
1621
+
1622
+ }
1623
+
1624
+ }
1625
+
1626
+ }
1627
+
1628
+ }
1629
+
1630
+ /**
1631
+ * Calculates the angular speed.
1632
+ *
1633
+ * @private
1634
+ * @param {number} p0 - Position at t0.
1635
+ * @param {number} p1 - Position at t1.
1636
+ * @param {number} t0 - Initial time in milliseconds.
1637
+ * @param {number} t1 - Ending time in milliseconds.
1638
+ * @returns {number} The angular speed.
1639
+ */
1640
+ calculateAngularSpeed( p0, p1, t0, t1 ) {
1641
+
1642
+ const s = p1 - p0;
1643
+ const t = ( t1 - t0 ) / 1000;
1644
+ if ( t == 0 ) {
1645
+
1646
+ return 0;
1647
+
1648
+ }
1649
+
1650
+ return s / t;
1651
+
1652
+ }
1653
+
1654
+ /**
1655
+ * Calculates the distance between two pointers.
1656
+ *
1657
+ * @private
1658
+ * @param {PointerEvent} p0 - The first pointer.
1659
+ * @param {PointerEvent} p1 - The second pointer.
1660
+ * @returns {number} The distance between the two pointers.
1661
+ */
1662
+ calculatePointersDistance( p0, p1 ) {
1663
+
1664
+ return Math.sqrt( Math.pow( p1.clientX - p0.clientX, 2 ) + Math.pow( p1.clientY - p0.clientY, 2 ) );
1665
+
1666
+ }
1667
+
1668
+ /**
1669
+ * Calculates the rotation axis as the vector perpendicular between two vectors.
1670
+ *
1671
+ * @private
1672
+ * @param {Vector3} vec1 - The first vector.
1673
+ * @param {Vector3} vec2 - The second vector.
1674
+ * @returns {Vector3} The normalized rotation axis.
1675
+ */
1676
+ calculateRotationAxis( vec1, vec2 ) {
1677
+
1678
+ this._rotationMatrix.extractRotation( this._cameraMatrixState );
1679
+ this._quat.setFromRotationMatrix( this._rotationMatrix );
1680
+
1681
+ this._rotationAxis.crossVectors( vec1, vec2 ).applyQuaternion( this._quat );
1682
+ return this._rotationAxis.normalize().clone();
1683
+
1684
+ }
1685
+
1686
+ /**
1687
+ * Calculates the trackball radius so that gizmo's diameter will be 2/3 of the minimum side of the camera frustum.
1688
+ *
1689
+ * @private
1690
+ * @param {Camera} camera - The camera.
1691
+ * @returns {number} The trackball radius.
1692
+ */
1693
+ calculateTbRadius( camera ) {
1694
+
1695
+ const distance = camera.position.distanceTo( this._gizmos.position );
1696
+
1697
+ if ( camera.type == 'PerspectiveCamera' ) {
1698
+
1699
+ const halfFovV = MathUtils.DEG2RAD * camera.fov * 0.5; //vertical fov/2 in radians
1700
+ const halfFovH = Math.atan( ( camera.aspect ) * Math.tan( halfFovV ) ); //horizontal fov/2 in radians
1701
+ return Math.tan( Math.min( halfFovV, halfFovH ) ) * distance * this.radiusFactor;
1702
+
1703
+ } else if ( camera.type == 'OrthographicCamera' ) {
1704
+
1705
+ return Math.min( camera.top, camera.right ) * this.radiusFactor;
1706
+
1707
+ }
1708
+
1709
+ }
1710
+
1711
+ /**
1712
+ * Focus operation consist of positioning the point of interest in front of the camera and a slightly zoom in.
1713
+ *
1714
+ * @private
1715
+ * @param {Vector3} point - The point of interest.
1716
+ * @param {number} size - Scale factor.
1717
+ * @param {number} [amount=1] - Amount of operation to be completed (used for focus animations, default is complete full operation).
1718
+ */
1719
+ focus( point, size, amount = 1 ) {
1720
+
1721
+ //move center of camera (along with gizmos) towards point of interest
1722
+ _offset.copy( point ).sub( this._gizmos.position ).multiplyScalar( amount );
1723
+ this._translationMatrix.makeTranslation( _offset.x, _offset.y, _offset.z );
1724
+
1725
+ _gizmoMatrixStateTemp.copy( this._gizmoMatrixState );
1726
+ this._gizmoMatrixState.premultiply( this._translationMatrix );
1727
+ this._gizmoMatrixState.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale );
1728
+
1729
+ _cameraMatrixStateTemp.copy( this._cameraMatrixState );
1730
+ this._cameraMatrixState.premultiply( this._translationMatrix );
1731
+ this._cameraMatrixState.decompose( this.object.position, this.object.quaternion, this.object.scale );
1732
+
1733
+ //apply zoom
1734
+ if ( this.enableZoom ) {
1735
+
1736
+ this.applyTransformMatrix( this.scale( size, this._gizmos.position ) );
1737
+
1738
+ }
1739
+
1740
+ this._gizmoMatrixState.copy( _gizmoMatrixStateTemp );
1741
+ this._cameraMatrixState.copy( _cameraMatrixStateTemp );
1742
+
1743
+ }
1744
+
1745
+ /**
1746
+ * Creates a grid if necessary and adds it to the scene.
1747
+ *
1748
+ * @private
1749
+ */
1750
+ drawGrid() {
1751
+
1752
+ if ( this.scene != null ) {
1753
+
1754
+ const color = 0x888888;
1755
+ const multiplier = 3;
1756
+ let size, divisions, maxLength, tick;
1757
+
1758
+ if ( this.object.isOrthographicCamera ) {
1759
+
1760
+ const width = this.object.right - this.object.left;
1761
+ const height = this.object.bottom - this.object.top;
1762
+
1763
+ maxLength = Math.max( width, height );
1764
+ tick = maxLength / 20;
1765
+
1766
+ size = maxLength / this.object.zoom * multiplier;
1767
+ divisions = size / tick * this.object.zoom;
1768
+
1769
+ } else if ( this.object.isPerspectiveCamera ) {
1770
+
1771
+ const distance = this.object.position.distanceTo( this._gizmos.position );
1772
+ const halfFovV = MathUtils.DEG2RAD * this.object.fov * 0.5;
1773
+ const halfFovH = Math.atan( ( this.object.aspect ) * Math.tan( halfFovV ) );
1774
+
1775
+ maxLength = Math.tan( Math.max( halfFovV, halfFovH ) ) * distance * 2;
1776
+ tick = maxLength / 20;
1777
+
1778
+ size = maxLength * multiplier;
1779
+ divisions = size / tick;
1780
+
1781
+ }
1782
+
1783
+ if ( this._grid == null ) {
1784
+
1785
+ this._grid = new GridHelper( size, divisions, color, color );
1786
+ this._grid.position.copy( this._gizmos.position );
1787
+ this._gridPosition.copy( this._grid.position );
1788
+ this._grid.quaternion.copy( this.object.quaternion );
1789
+ this._grid.rotateX( Math.PI * 0.5 );
1790
+
1791
+ this.scene.add( this._grid );
1792
+
1793
+ }
1794
+
1795
+ }
1796
+
1797
+ }
1798
+
1799
+ dispose() {
1800
+
1801
+ if ( this._animationId != - 1 ) {
1802
+
1803
+ window.cancelAnimationFrame( this._animationId );
1804
+
1805
+ }
1806
+
1807
+ this.disconnect();
1808
+
1809
+ if ( this.scene !== null ) this.scene.remove( this._gizmos );
1810
+ this.disposeGrid();
1811
+
1812
+ }
1813
+
1814
+ /**
1815
+ * Removes the grid from the scene.
1816
+ */
1817
+ disposeGrid() {
1818
+
1819
+ if ( this._grid != null && this.scene != null ) {
1820
+
1821
+ this.scene.remove( this._grid );
1822
+ this._grid = null;
1823
+
1824
+ }
1825
+
1826
+ }
1827
+
1828
+ /**
1829
+ * Computes the easing out cubic function for ease out effect in animation.
1830
+ *
1831
+ * @private
1832
+ * @param {number} t - The absolute progress of the animation in the bound of `0` (beginning of the) and `1` (ending of animation).
1833
+ * @returns {number} Result of easing out cubic at time `t`.
1834
+ */
1835
+ easeOutCubic( t ) {
1836
+
1837
+ return 1 - Math.pow( 1 - t, 3 );
1838
+
1839
+ }
1840
+
1841
+ /**
1842
+ * Makes rotation gizmos more or less visible.
1843
+ *
1844
+ * @param {boolean} isActive - If set to `true`, gizmos are more visible.
1845
+ */
1846
+ activateGizmos( isActive ) {
1847
+
1848
+ const gizmoX = this._gizmos.children[ 0 ];
1849
+ const gizmoY = this._gizmos.children[ 1 ];
1850
+ const gizmoZ = this._gizmos.children[ 2 ];
1851
+
1852
+ if ( isActive ) {
1853
+
1854
+ gizmoX.material.setValues( { opacity: 1 } );
1855
+ gizmoY.material.setValues( { opacity: 1 } );
1856
+ gizmoZ.material.setValues( { opacity: 1 } );
1857
+
1858
+ } else {
1859
+
1860
+ gizmoX.material.setValues( { opacity: 0.6 } );
1861
+ gizmoY.material.setValues( { opacity: 0.6 } );
1862
+ gizmoZ.material.setValues( { opacity: 0.6 } );
1863
+
1864
+ }
1865
+
1866
+ }
1867
+
1868
+ /**
1869
+ * Calculates the cursor position in NDC.
1870
+ *
1871
+ * @private
1872
+ * @param {number} cursorX - Cursor horizontal coordinate within the canvas.
1873
+ * @param {number} cursorY - Cursor vertical coordinate within the canvas.
1874
+ * @param {HTMLElement} canvas - The canvas where the renderer draws its output.
1875
+ * @returns {Vector2} Cursor normalized position inside the canvas.
1876
+ */
1877
+ getCursorNDC( cursorX, cursorY, canvas ) {
1878
+
1879
+ const canvasRect = canvas.getBoundingClientRect();
1880
+ this._v2_1.setX( ( ( cursorX - canvasRect.left ) / canvasRect.width ) * 2 - 1 );
1881
+ this._v2_1.setY( ( ( canvasRect.bottom - cursorY ) / canvasRect.height ) * 2 - 1 );
1882
+ return this._v2_1.clone();
1883
+
1884
+ }
1885
+
1886
+ /**
1887
+ * Calculates the cursor position inside the canvas x/y coordinates with the origin being in the center of the canvas.
1888
+ *
1889
+ * @private
1890
+ * @param {number} cursorX - Cursor horizontal coordinate within the canvas.
1891
+ * @param {number} cursorY - Cursor vertical coordinate within the canvas.
1892
+ * @param {HTMLElement} canvas - The canvas where the renderer draws its output.
1893
+ * @returns {Vector2} Cursor position inside the canvas.
1894
+ */
1895
+ getCursorPosition( cursorX, cursorY, canvas ) {
1896
+
1897
+ this._v2_1.copy( this.getCursorNDC( cursorX, cursorY, canvas ) );
1898
+ this._v2_1.x *= ( this.object.right - this.object.left ) * 0.5;
1899
+ this._v2_1.y *= ( this.object.top - this.object.bottom ) * 0.5;
1900
+ return this._v2_1.clone();
1901
+
1902
+ }
1903
+
1904
+ /**
1905
+ * Sets the camera to be controlled. Must be called in order to set a new camera to be controlled.
1906
+ *
1907
+ * @param {Camera} camera - The camera to be controlled.
1908
+ */
1909
+ setCamera( camera ) {
1910
+
1911
+ camera.lookAt( this.target );
1912
+ camera.updateMatrix();
1913
+
1914
+ //setting state
1915
+ if ( camera.type == 'PerspectiveCamera' ) {
1916
+
1917
+ this._fov0 = camera.fov;
1918
+ this._fovState = camera.fov;
1919
+
1920
+ }
1921
+
1922
+ this._cameraMatrixState0.copy( camera.matrix );
1923
+ this._cameraMatrixState.copy( this._cameraMatrixState0 );
1924
+ this._cameraProjectionState.copy( camera.projectionMatrix );
1925
+ this._zoom0 = camera.zoom;
1926
+ this._zoomState = this._zoom0;
1927
+
1928
+ this._initialNear = camera.near;
1929
+ this._nearPos0 = camera.position.distanceTo( this.target ) - camera.near;
1930
+ this._nearPos = this._initialNear;
1931
+
1932
+ this._initialFar = camera.far;
1933
+ this._farPos0 = camera.position.distanceTo( this.target ) - camera.far;
1934
+ this._farPos = this._initialFar;
1935
+
1936
+ this._up0.copy( camera.up );
1937
+ this._upState.copy( camera.up );
1938
+
1939
+ this.object = camera;
1940
+ this.object.updateProjectionMatrix();
1941
+
1942
+ //making gizmos
1943
+ this._tbRadius = this.calculateTbRadius( camera );
1944
+ this.makeGizmos( this.target, this._tbRadius );
1945
+
1946
+ }
1947
+
1948
+ /**
1949
+ * Sets gizmos visibility.
1950
+ *
1951
+ * @param {boolean} value - Value of gizmos visibility.
1952
+ */
1953
+ setGizmosVisible( value ) {
1954
+
1955
+ this._gizmos.visible = value;
1956
+ this.dispatchEvent( _changeEvent );
1957
+
1958
+ }
1959
+
1960
+ /**
1961
+ * Sets gizmos radius factor and redraws gizmos.
1962
+ *
1963
+ * @param {number} value - Value of radius factor.
1964
+ */
1965
+ setTbRadius( value ) {
1966
+
1967
+ this.radiusFactor = value;
1968
+ this._tbRadius = this.calculateTbRadius( this.object );
1969
+
1970
+ const curve = new EllipseCurve( 0, 0, this._tbRadius, this._tbRadius );
1971
+ const points = curve.getPoints( this._curvePts );
1972
+ const curveGeometry = new BufferGeometry().setFromPoints( points );
1973
+
1974
+
1975
+ for ( const gizmo in this._gizmos.children ) {
1976
+
1977
+ this._gizmos.children[ gizmo ].geometry = curveGeometry;
1978
+
1979
+ }
1980
+
1981
+ this.dispatchEvent( _changeEvent );
1982
+
1983
+ }
1984
+
1985
+ /**
1986
+ * Creates the rotation gizmos matching trackball center and radius.
1987
+ *
1988
+ * @private
1989
+ * @param {Vector3} tbCenter - The trackball center.
1990
+ * @param {number} tbRadius - The trackball radius.
1991
+ */
1992
+ makeGizmos( tbCenter, tbRadius ) {
1993
+
1994
+ const curve = new EllipseCurve( 0, 0, tbRadius, tbRadius );
1995
+ const points = curve.getPoints( this._curvePts );
1996
+
1997
+ //geometry
1998
+ const curveGeometry = new BufferGeometry().setFromPoints( points );
1999
+
2000
+ //material
2001
+ const curveMaterialX = new LineBasicMaterial( { color: 0xff8080, fog: false, transparent: true, opacity: 0.6 } );
2002
+ const curveMaterialY = new LineBasicMaterial( { color: 0x80ff80, fog: false, transparent: true, opacity: 0.6 } );
2003
+ const curveMaterialZ = new LineBasicMaterial( { color: 0x8080ff, fog: false, transparent: true, opacity: 0.6 } );
2004
+
2005
+ //line
2006
+ const gizmoX = new Line( curveGeometry, curveMaterialX );
2007
+ const gizmoY = new Line( curveGeometry, curveMaterialY );
2008
+ const gizmoZ = new Line( curveGeometry, curveMaterialZ );
2009
+
2010
+ const rotation = Math.PI * 0.5;
2011
+ gizmoX.rotation.x = rotation;
2012
+ gizmoY.rotation.y = rotation;
2013
+
2014
+
2015
+ //setting state
2016
+ this._gizmoMatrixState0.identity().setPosition( tbCenter );
2017
+ this._gizmoMatrixState.copy( this._gizmoMatrixState0 );
2018
+
2019
+ if ( this.object.zoom !== 1 ) {
2020
+
2021
+ //adapt gizmos size to camera zoom
2022
+ const size = 1 / this.object.zoom;
2023
+ this._scaleMatrix.makeScale( size, size, size );
2024
+ this._translationMatrix.makeTranslation( - tbCenter.x, - tbCenter.y, - tbCenter.z );
2025
+
2026
+ this._gizmoMatrixState.premultiply( this._translationMatrix ).premultiply( this._scaleMatrix );
2027
+ this._translationMatrix.makeTranslation( tbCenter.x, tbCenter.y, tbCenter.z );
2028
+ this._gizmoMatrixState.premultiply( this._translationMatrix );
2029
+
2030
+ }
2031
+
2032
+ this._gizmoMatrixState.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale );
2033
+
2034
+ //
2035
+
2036
+ this._gizmos.traverse( function ( object ) {
2037
+
2038
+ if ( object.isLine ) {
2039
+
2040
+ object.geometry.dispose();
2041
+ object.material.dispose();
2042
+
2043
+ }
2044
+
2045
+ } );
2046
+
2047
+ this._gizmos.clear();
2048
+
2049
+ //
2050
+
2051
+ this._gizmos.add( gizmoX );
2052
+ this._gizmos.add( gizmoY );
2053
+ this._gizmos.add( gizmoZ );
2054
+
2055
+ }
2056
+
2057
+ /**
2058
+ * Performs animation for focus operation.
2059
+ *
2060
+ * @private
2061
+ * @param {number} time - Instant in which this function is called as performance.now().
2062
+ * @param {Vector3} point - Point of interest for focus operation.
2063
+ * @param {Matrix4} cameraMatrix - Camera matrix.
2064
+ * @param {Matrix4} gizmoMatrix - Gizmos matrix.
2065
+ */
2066
+ onFocusAnim( time, point, cameraMatrix, gizmoMatrix ) {
2067
+
2068
+ if ( this._timeStart == - 1 ) {
2069
+
2070
+ //animation start
2071
+ this._timeStart = time;
2072
+
2073
+ }
2074
+
2075
+ if ( this._state == STATE.ANIMATION_FOCUS ) {
2076
+
2077
+ const deltaTime = time - this._timeStart;
2078
+ const animTime = deltaTime / this.focusAnimationTime;
2079
+
2080
+ this._gizmoMatrixState.copy( gizmoMatrix );
2081
+
2082
+ if ( animTime >= 1 ) {
2083
+
2084
+ //animation end
2085
+
2086
+ this._gizmoMatrixState.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale );
2087
+
2088
+ this.focus( point, this.scaleFactor );
2089
+
2090
+ this._timeStart = - 1;
2091
+ this.updateTbState( STATE.IDLE, false );
2092
+ this.activateGizmos( false );
2093
+
2094
+ this.dispatchEvent( _changeEvent );
2095
+
2096
+ } else {
2097
+
2098
+ const amount = this.easeOutCubic( animTime );
2099
+ const size = ( ( 1 - amount ) + ( this.scaleFactor * amount ) );
2100
+
2101
+ this._gizmoMatrixState.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale );
2102
+ this.focus( point, size, amount );
2103
+
2104
+ this.dispatchEvent( _changeEvent );
2105
+ const self = this;
2106
+ this._animationId = window.requestAnimationFrame( function ( t ) {
2107
+
2108
+ self.onFocusAnim( t, point, cameraMatrix, gizmoMatrix.clone() );
2109
+
2110
+ } );
2111
+
2112
+ }
2113
+
2114
+ } else {
2115
+
2116
+ //interrupt animation
2117
+
2118
+ this._animationId = - 1;
2119
+ this._timeStart = - 1;
2120
+
2121
+ }
2122
+
2123
+ }
2124
+
2125
+ /**
2126
+ * Performs animation for rotation operation.
2127
+ *
2128
+ * @private
2129
+ * @param {number} time - Instant in which this function is called as performance.now().
2130
+ * @param {Vector3} rotationAxis - Rotation axis.
2131
+ * @param {number} w0 - Initial angular velocity.
2132
+ */
2133
+ onRotationAnim( time, rotationAxis, w0 ) {
2134
+
2135
+ if ( this._timeStart == - 1 ) {
2136
+
2137
+ //animation start
2138
+ this._anglePrev = 0;
2139
+ this._angleCurrent = 0;
2140
+ this._timeStart = time;
2141
+
2142
+ }
2143
+
2144
+ if ( this._state == STATE.ANIMATION_ROTATE ) {
2145
+
2146
+ //w = w0 + alpha * t
2147
+ const deltaTime = ( time - this._timeStart ) / 1000;
2148
+ const w = w0 + ( ( - this.dampingFactor ) * deltaTime );
2149
+
2150
+ if ( w > 0 ) {
2151
+
2152
+ //tetha = 0.5 * alpha * t^2 + w0 * t + tetha0
2153
+ this._angleCurrent = 0.5 * ( - this.dampingFactor ) * Math.pow( deltaTime, 2 ) + w0 * deltaTime + 0;
2154
+ this.applyTransformMatrix( this.rotate( rotationAxis, this._angleCurrent ) );
2155
+ this.dispatchEvent( _changeEvent );
2156
+ const self = this;
2157
+ this._animationId = window.requestAnimationFrame( function ( t ) {
2158
+
2159
+ self.onRotationAnim( t, rotationAxis, w0 );
2160
+
2161
+ } );
2162
+
2163
+ } else {
2164
+
2165
+ this._animationId = - 1;
2166
+ this._timeStart = - 1;
2167
+
2168
+ this.updateTbState( STATE.IDLE, false );
2169
+ this.activateGizmos( false );
2170
+
2171
+ this.dispatchEvent( _changeEvent );
2172
+
2173
+ }
2174
+
2175
+ } else {
2176
+
2177
+ //interrupt animation
2178
+
2179
+ this._animationId = - 1;
2180
+ this._timeStart = - 1;
2181
+
2182
+ if ( this._state != STATE.ROTATE ) {
2183
+
2184
+ this.activateGizmos( false );
2185
+ this.dispatchEvent( _changeEvent );
2186
+
2187
+ }
2188
+
2189
+ }
2190
+
2191
+ }
2192
+
2193
+
2194
+ /**
2195
+ * Performs pan operation moving camera between two points.
2196
+ *
2197
+ * @private
2198
+ * @param {Vector3} p0 - Initial point.
2199
+ * @param {Vector3} p1 - Ending point.
2200
+ * @param {boolean} [adjust=false] - If movement should be adjusted considering camera distance (Perspective only).
2201
+ * @returns {Object}
2202
+ */
2203
+ pan( p0, p1, adjust = false ) {
2204
+
2205
+ const movement = p0.clone().sub( p1 );
2206
+
2207
+ if ( this.object.isOrthographicCamera ) {
2208
+
2209
+ //adjust movement amount
2210
+ movement.multiplyScalar( 1 / this.object.zoom );
2211
+
2212
+ } else if ( this.object.isPerspectiveCamera && adjust ) {
2213
+
2214
+ //adjust movement amount
2215
+ this._v3_1.setFromMatrixPosition( this._cameraMatrixState0 ); //camera's initial position
2216
+ this._v3_2.setFromMatrixPosition( this._gizmoMatrixState0 ); //gizmo's initial position
2217
+ const distanceFactor = this._v3_1.distanceTo( this._v3_2 ) / this.object.position.distanceTo( this._gizmos.position );
2218
+ movement.multiplyScalar( 1 / distanceFactor );
2219
+
2220
+ }
2221
+
2222
+ this._v3_1.set( movement.x, movement.y, 0 ).applyQuaternion( this.object.quaternion );
2223
+
2224
+ this._m4_1.makeTranslation( this._v3_1.x, this._v3_1.y, this._v3_1.z );
2225
+
2226
+ this.setTransformationMatrices( this._m4_1, this._m4_1 );
2227
+ return _transformation;
2228
+
2229
+ }
2230
+
2231
+ /**
2232
+ * Resets the controls.
2233
+ */
2234
+ reset() {
2235
+
2236
+ this.target.copy( this._target0 );
2237
+ this.object.zoom = this._zoom0;
2238
+
2239
+ if ( this.object.isPerspectiveCamera ) {
2240
+
2241
+ this.object.fov = this._fov0;
2242
+
2243
+ }
2244
+
2245
+ this.object.near = this._nearPos;
2246
+ this.object.far = this._farPos;
2247
+ this._cameraMatrixState.copy( this._cameraMatrixState0 );
2248
+ this._cameraMatrixState.decompose( this.object.position, this.object.quaternion, this.object.scale );
2249
+ this.object.up.copy( this._up0 );
2250
+
2251
+ this.object.updateMatrix();
2252
+ this.object.updateProjectionMatrix();
2253
+
2254
+ this._gizmoMatrixState.copy( this._gizmoMatrixState0 );
2255
+ this._gizmoMatrixState0.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale );
2256
+ this._gizmos.updateMatrix();
2257
+
2258
+ this._tbRadius = this.calculateTbRadius( this.object );
2259
+ this.makeGizmos( this._gizmos.position, this._tbRadius );
2260
+
2261
+ this.object.lookAt( this._gizmos.position );
2262
+
2263
+ this.updateTbState( STATE.IDLE, false );
2264
+
2265
+ this.dispatchEvent( _changeEvent );
2266
+
2267
+ }
2268
+
2269
+ /**
2270
+ * Rotates the camera around an axis passing by trackball's center.
2271
+ *
2272
+ * @private
2273
+ * @param {Vector3} axis - Rotation axis.
2274
+ * @param {number} angle - Angle in radians.
2275
+ * @returns {Object} Object with 'camera' field containing transformation matrix resulting from the operation to be applied to the camera.
2276
+ */
2277
+ rotate( axis, angle ) {
2278
+
2279
+ const point = this._gizmos.position; //rotation center
2280
+ this._translationMatrix.makeTranslation( - point.x, - point.y, - point.z );
2281
+ this._rotationMatrix.makeRotationAxis( axis, - angle );
2282
+
2283
+ //rotate camera
2284
+ this._m4_1.makeTranslation( point.x, point.y, point.z );
2285
+ this._m4_1.multiply( this._rotationMatrix );
2286
+ this._m4_1.multiply( this._translationMatrix );
2287
+
2288
+ this.setTransformationMatrices( this._m4_1 );
2289
+
2290
+ return _transformation;
2291
+
2292
+ }
2293
+
2294
+ /**
2295
+ * Copy the current state to clipboard (as a readable JSON text).
2296
+ */
2297
+ copyState() {
2298
+
2299
+ let state;
2300
+ if ( this.object.isOrthographicCamera ) {
2301
+
2302
+ state = JSON.stringify( {
2303
+ arcballState: {
2304
+ cameraFar: this.object.far,
2305
+ cameraMatrix: this.object.matrix,
2306
+ cameraNear: this.object.near,
2307
+ cameraUp: this.object.up,
2308
+ cameraZoom: this.object.zoom,
2309
+ gizmoMatrix: this._gizmos.matrix,
2310
+ target: this.target
2311
+
2312
+ }
2313
+ } );
2314
+
2315
+ } else if ( this.object.isPerspectiveCamera ) {
2316
+
2317
+ state = JSON.stringify( {
2318
+ arcballState: {
2319
+ cameraFar: this.object.far,
2320
+ cameraFov: this.object.fov,
2321
+ cameraMatrix: this.object.matrix,
2322
+ cameraNear: this.object.near,
2323
+ cameraUp: this.object.up,
2324
+ cameraZoom: this.object.zoom,
2325
+ gizmoMatrix: this._gizmos.matrix,
2326
+ target: this.target
2327
+
2328
+ }
2329
+ } );
2330
+
2331
+ }
2332
+
2333
+ navigator.clipboard.writeText( state );
2334
+
2335
+ }
2336
+
2337
+ /**
2338
+ * Set the controls state from the clipboard, assumes that the clipboard stores a JSON
2339
+ * text as saved from `copyState()`.
2340
+ */
2341
+ pasteState() {
2342
+
2343
+ const self = this;
2344
+ navigator.clipboard.readText().then( function resolved( value ) {
2345
+
2346
+ self.setStateFromJSON( value );
2347
+
2348
+ } );
2349
+
2350
+ }
2351
+
2352
+ /**
2353
+ * Saves the current state of the control. This can later be recover with `reset()`.
2354
+ */
2355
+ saveState() {
2356
+
2357
+ this.object.updateMatrix();
2358
+ this._gizmos.updateMatrix();
2359
+
2360
+ this._target0.copy( this.target );
2361
+ this._cameraMatrixState0.copy( this.object.matrix );
2362
+ this._gizmoMatrixState0.copy( this._gizmos.matrix );
2363
+ this._nearPos = this.object.near;
2364
+ this._farPos = this.object.far;
2365
+ this._zoom0 = this.object.zoom;
2366
+ this._up0.copy( this.object.up );
2367
+
2368
+ if ( this.object.isPerspectiveCamera ) {
2369
+
2370
+ this._fov0 = this.object.fov;
2371
+
2372
+ }
2373
+
2374
+ }
2375
+
2376
+ /**
2377
+ * Performs uniform scale operation around a given point.
2378
+ *
2379
+ * @private
2380
+ * @param {number} size - Scale factor.
2381
+ * @param {Vector3} point - Point around which scale.
2382
+ * @param {boolean} scaleGizmos - If gizmos should be scaled (Perspective only).
2383
+ * @returns {Object} Object with 'camera' and 'gizmo' fields containing transformation matrices resulting from the operation to be applied to the camera and gizmos.
2384
+ */
2385
+ scale( size, point, scaleGizmos = true ) {
2386
+
2387
+ _scalePointTemp.copy( point );
2388
+ let sizeInverse = 1 / size;
2389
+
2390
+ if ( this.object.isOrthographicCamera ) {
2391
+
2392
+ //camera zoom
2393
+ this.object.zoom = this._zoomState;
2394
+ this.object.zoom *= size;
2395
+
2396
+ //check min and max zoom
2397
+ if ( this.object.zoom > this.maxZoom ) {
2398
+
2399
+ this.object.zoom = this.maxZoom;
2400
+ sizeInverse = this._zoomState / this.maxZoom;
2401
+
2402
+ } else if ( this.object.zoom < this.minZoom ) {
2403
+
2404
+ this.object.zoom = this.minZoom;
2405
+ sizeInverse = this._zoomState / this.minZoom;
2406
+
2407
+ }
2408
+
2409
+ this.object.updateProjectionMatrix();
2410
+
2411
+ this._v3_1.setFromMatrixPosition( this._gizmoMatrixState ); //gizmos position
2412
+
2413
+ //scale gizmos so they appear in the same spot having the same dimension
2414
+ this._scaleMatrix.makeScale( sizeInverse, sizeInverse, sizeInverse );
2415
+ this._translationMatrix.makeTranslation( - this._v3_1.x, - this._v3_1.y, - this._v3_1.z );
2416
+
2417
+ this._m4_2.makeTranslation( this._v3_1.x, this._v3_1.y, this._v3_1.z ).multiply( this._scaleMatrix );
2418
+ this._m4_2.multiply( this._translationMatrix );
2419
+
2420
+
2421
+ //move camera and gizmos to obtain pinch effect
2422
+ _scalePointTemp.sub( this._v3_1 );
2423
+
2424
+ const amount = _scalePointTemp.clone().multiplyScalar( sizeInverse );
2425
+ _scalePointTemp.sub( amount );
2426
+
2427
+ this._m4_1.makeTranslation( _scalePointTemp.x, _scalePointTemp.y, _scalePointTemp.z );
2428
+ this._m4_2.premultiply( this._m4_1 );
2429
+
2430
+ this.setTransformationMatrices( this._m4_1, this._m4_2 );
2431
+ return _transformation;
2432
+
2433
+ } else if ( this.object.isPerspectiveCamera ) {
2434
+
2435
+ this._v3_1.setFromMatrixPosition( this._cameraMatrixState );
2436
+ this._v3_2.setFromMatrixPosition( this._gizmoMatrixState );
2437
+
2438
+ //move camera
2439
+ let distance = this._v3_1.distanceTo( _scalePointTemp );
2440
+ let amount = distance - ( distance * sizeInverse );
2441
+
2442
+ //check min and max distance
2443
+ const newDistance = distance - amount;
2444
+ if ( newDistance < this.minDistance ) {
2445
+
2446
+ sizeInverse = this.minDistance / distance;
2447
+ amount = distance - ( distance * sizeInverse );
2448
+
2449
+ } else if ( newDistance > this.maxDistance ) {
2450
+
2451
+ sizeInverse = this.maxDistance / distance;
2452
+ amount = distance - ( distance * sizeInverse );
2453
+
2454
+ }
2455
+
2456
+ _offset.copy( _scalePointTemp ).sub( this._v3_1 ).normalize().multiplyScalar( amount );
2457
+
2458
+ this._m4_1.makeTranslation( _offset.x, _offset.y, _offset.z );
2459
+
2460
+
2461
+ if ( scaleGizmos ) {
2462
+
2463
+ //scale gizmos so they appear in the same spot having the same dimension
2464
+ const pos = this._v3_2;
2465
+
2466
+ distance = pos.distanceTo( _scalePointTemp );
2467
+ amount = distance - ( distance * sizeInverse );
2468
+ _offset.copy( _scalePointTemp ).sub( this._v3_2 ).normalize().multiplyScalar( amount );
2469
+
2470
+ this._translationMatrix.makeTranslation( pos.x, pos.y, pos.z );
2471
+ this._scaleMatrix.makeScale( sizeInverse, sizeInverse, sizeInverse );
2472
+
2473
+ this._m4_2.makeTranslation( _offset.x, _offset.y, _offset.z ).multiply( this._translationMatrix );
2474
+ this._m4_2.multiply( this._scaleMatrix );
2475
+
2476
+ this._translationMatrix.makeTranslation( - pos.x, - pos.y, - pos.z );
2477
+
2478
+ this._m4_2.multiply( this._translationMatrix );
2479
+ this.setTransformationMatrices( this._m4_1, this._m4_2 );
2480
+
2481
+
2482
+ } else {
2483
+
2484
+ this.setTransformationMatrices( this._m4_1 );
2485
+
2486
+ }
2487
+
2488
+ return _transformation;
2489
+
2490
+ }
2491
+
2492
+ }
2493
+
2494
+ /**
2495
+ * Sets camera fov.
2496
+ *
2497
+ * @private
2498
+ * @param {number} value - The FOV to be set.
2499
+ */
2500
+ setFov( value ) {
2501
+
2502
+ if ( this.object.isPerspectiveCamera ) {
2503
+
2504
+ this.object.fov = MathUtils.clamp( value, this.minFov, this.maxFov );
2505
+ this.object.updateProjectionMatrix();
2506
+
2507
+ }
2508
+
2509
+ }
2510
+
2511
+ /**
2512
+ * Sets values in transformation object.
2513
+ *
2514
+ * @private
2515
+ * @param {?Matrix4} [camera=null] - Transformation to be applied to the camera.
2516
+ * @param {?Matrix4} [gizmos=null] - Transformation to be applied to gizmos.
2517
+ */
2518
+ setTransformationMatrices( camera = null, gizmos = null ) {
2519
+
2520
+ if ( camera != null ) {
2521
+
2522
+ if ( _transformation.camera != null ) {
2523
+
2524
+ _transformation.camera.copy( camera );
2525
+
2526
+ } else {
2527
+
2528
+ _transformation.camera = camera.clone();
2529
+
2530
+ }
2531
+
2532
+ } else {
2533
+
2534
+ _transformation.camera = null;
2535
+
2536
+ }
2537
+
2538
+ if ( gizmos != null ) {
2539
+
2540
+ if ( _transformation.gizmos != null ) {
2541
+
2542
+ _transformation.gizmos.copy( gizmos );
2543
+
2544
+ } else {
2545
+
2546
+ _transformation.gizmos = gizmos.clone();
2547
+
2548
+ }
2549
+
2550
+ } else {
2551
+
2552
+ _transformation.gizmos = null;
2553
+
2554
+ }
2555
+
2556
+ }
2557
+
2558
+ /**
2559
+ * Rotates camera around its direction axis passing by a given point by a given angle.
2560
+ *
2561
+ * @private
2562
+ * @param {Vector3} point - The point where the rotation axis is passing trough.
2563
+ * @param {number} angle - Angle in radians.
2564
+ * @returns {Object} The computed transformation matrix.
2565
+ */
2566
+ zRotate( point, angle ) {
2567
+
2568
+ this._rotationMatrix.makeRotationAxis( this._rotationAxis, angle );
2569
+ this._translationMatrix.makeTranslation( - point.x, - point.y, - point.z );
2570
+
2571
+ this._m4_1.makeTranslation( point.x, point.y, point.z );
2572
+ this._m4_1.multiply( this._rotationMatrix );
2573
+ this._m4_1.multiply( this._translationMatrix );
2574
+
2575
+ this._v3_1.setFromMatrixPosition( this._gizmoMatrixState ).sub( point ); //vector from rotation center to gizmos position
2576
+ this._v3_2.copy( this._v3_1 ).applyAxisAngle( this._rotationAxis, angle ); //apply rotation
2577
+ this._v3_2.sub( this._v3_1 );
2578
+
2579
+ this._m4_2.makeTranslation( this._v3_2.x, this._v3_2.y, this._v3_2.z );
2580
+
2581
+ this.setTransformationMatrices( this._m4_1, this._m4_2 );
2582
+ return _transformation;
2583
+
2584
+ }
2585
+
2586
+ /**
2587
+ * Returns the raycaster that is used for user interaction. This object is shared between all
2588
+ * instances of `ArcballControls`.
2589
+ *
2590
+ * @returns {Raycaster} The internal raycaster.
2591
+ */
2592
+ getRaycaster() {
2593
+
2594
+ return _raycaster;
2595
+
2596
+ }
2597
+
2598
+
2599
+ /**
2600
+ * Unprojects the cursor on the 3D object surface.
2601
+ *
2602
+ * @private
2603
+ * @param {Vector2} cursor - Cursor coordinates in NDC.
2604
+ * @param {Camera} camera - Virtual camera.
2605
+ * @returns {?Vector3} The point of intersection with the model, if exist, null otherwise.
2606
+ */
2607
+ unprojectOnObj( cursor, camera ) {
2608
+
2609
+ const raycaster = this.getRaycaster();
2610
+ raycaster.near = camera.near;
2611
+ raycaster.far = camera.far;
2612
+ raycaster.setFromCamera( cursor, camera );
2613
+
2614
+ const intersect = raycaster.intersectObjects( this.scene.children, true );
2615
+
2616
+ for ( let i = 0; i < intersect.length; i ++ ) {
2617
+
2618
+ if ( intersect[ i ].object.uuid != this._gizmos.uuid && intersect[ i ].face != null ) {
2619
+
2620
+ return intersect[ i ].point.clone();
2621
+
2622
+ }
2623
+
2624
+ }
2625
+
2626
+ return null;
2627
+
2628
+ }
2629
+
2630
+ /**
2631
+ * Unproject the cursor on the trackball surface.
2632
+ *
2633
+ * @private
2634
+ * @param {Camera} camera - The virtual camera.
2635
+ * @param {number} cursorX - Cursor horizontal coordinate on screen.
2636
+ * @param {number} cursorY - Cursor vertical coordinate on screen.
2637
+ * @param {HTMLElement} canvas - The canvas where the renderer draws its output.
2638
+ * @param {number} tbRadius - The trackball radius.
2639
+ * @returns {Vector3} The unprojected point on the trackball surface.
2640
+ */
2641
+ unprojectOnTbSurface( camera, cursorX, cursorY, canvas, tbRadius ) {
2642
+
2643
+ if ( camera.type == 'OrthographicCamera' ) {
2644
+
2645
+ this._v2_1.copy( this.getCursorPosition( cursorX, cursorY, canvas ) );
2646
+ this._v3_1.set( this._v2_1.x, this._v2_1.y, 0 );
2647
+
2648
+ const x2 = Math.pow( this._v2_1.x, 2 );
2649
+ const y2 = Math.pow( this._v2_1.y, 2 );
2650
+ const r2 = Math.pow( this._tbRadius, 2 );
2651
+
2652
+ if ( x2 + y2 <= r2 * 0.5 ) {
2653
+
2654
+ //intersection with sphere
2655
+ this._v3_1.setZ( Math.sqrt( r2 - ( x2 + y2 ) ) );
2656
+
2657
+ } else {
2658
+
2659
+ //intersection with hyperboloid
2660
+ this._v3_1.setZ( ( r2 * 0.5 ) / ( Math.sqrt( x2 + y2 ) ) );
2661
+
2662
+ }
2663
+
2664
+ return this._v3_1;
2665
+
2666
+ } else if ( camera.type == 'PerspectiveCamera' ) {
2667
+
2668
+ //unproject cursor on the near plane
2669
+ this._v2_1.copy( this.getCursorNDC( cursorX, cursorY, canvas ) );
2670
+
2671
+ this._v3_1.set( this._v2_1.x, this._v2_1.y, - 1 );
2672
+ this._v3_1.applyMatrix4( camera.projectionMatrixInverse );
2673
+
2674
+ const rayDir = this._v3_1.clone().normalize(); //unprojected ray direction
2675
+ const cameraGizmoDistance = camera.position.distanceTo( this._gizmos.position );
2676
+ const radius2 = Math.pow( tbRadius, 2 );
2677
+
2678
+ // camera
2679
+ // |\
2680
+ // | \
2681
+ // | \
2682
+ // h | \
2683
+ // | \
2684
+ // | \
2685
+ // _ _ | _ _ _\ _ _ near plane
2686
+ // l
2687
+
2688
+ const h = this._v3_1.z;
2689
+ const l = Math.sqrt( Math.pow( this._v3_1.x, 2 ) + Math.pow( this._v3_1.y, 2 ) );
2690
+
2691
+ if ( l == 0 ) {
2692
+
2693
+ //ray aligned with camera
2694
+ rayDir.set( this._v3_1.x, this._v3_1.y, tbRadius );
2695
+ return rayDir;
2696
+
2697
+ }
2698
+
2699
+ const m = h / l;
2700
+ const q = cameraGizmoDistance;
2701
+
2702
+ /*
2703
+ * calculate intersection point between unprojected ray and trackball surface
2704
+ *|y = m * x + q
2705
+ *|x^2 + y^2 = r^2
2706
+ *
2707
+ * (m^2 + 1) * x^2 + (2 * m * q) * x + q^2 - r^2 = 0
2708
+ */
2709
+ let a = Math.pow( m, 2 ) + 1;
2710
+ let b = 2 * m * q;
2711
+ let c = Math.pow( q, 2 ) - radius2;
2712
+ let delta = Math.pow( b, 2 ) - ( 4 * a * c );
2713
+
2714
+ if ( delta >= 0 ) {
2715
+
2716
+ //intersection with sphere
2717
+ this._v2_1.setX( ( - b - Math.sqrt( delta ) ) / ( 2 * a ) );
2718
+ this._v2_1.setY( m * this._v2_1.x + q );
2719
+
2720
+ const angle = MathUtils.RAD2DEG * this._v2_1.angle();
2721
+
2722
+ if ( angle >= 45 ) {
2723
+
2724
+ //if angle between intersection point and X' axis is >= 45°, return that point
2725
+ //otherwise, calculate intersection point with hyperboloid
2726
+
2727
+ const rayLength = Math.sqrt( Math.pow( this._v2_1.x, 2 ) + Math.pow( ( cameraGizmoDistance - this._v2_1.y ), 2 ) );
2728
+ rayDir.multiplyScalar( rayLength );
2729
+ rayDir.z += cameraGizmoDistance;
2730
+ return rayDir;
2731
+
2732
+ }
2733
+
2734
+ }
2735
+
2736
+ //intersection with hyperboloid
2737
+ /*
2738
+ *|y = m * x + q
2739
+ *|y = (1 / x) * (r^2 / 2)
2740
+ *
2741
+ * m * x^2 + q * x - r^2 / 2 = 0
2742
+ */
2743
+
2744
+ a = m;
2745
+ b = q;
2746
+ c = - radius2 * 0.5;
2747
+ delta = Math.pow( b, 2 ) - ( 4 * a * c );
2748
+ this._v2_1.setX( ( - b - Math.sqrt( delta ) ) / ( 2 * a ) );
2749
+ this._v2_1.setY( m * this._v2_1.x + q );
2750
+
2751
+ const rayLength = Math.sqrt( Math.pow( this._v2_1.x, 2 ) + Math.pow( ( cameraGizmoDistance - this._v2_1.y ), 2 ) );
2752
+
2753
+ rayDir.multiplyScalar( rayLength );
2754
+ rayDir.z += cameraGizmoDistance;
2755
+ return rayDir;
2756
+
2757
+ }
2758
+
2759
+ }
2760
+
2761
+
2762
+ /**
2763
+ * Unprojects the cursor on the plane passing through the center of the trackball orthogonal to the camera.
2764
+ *
2765
+ * @private
2766
+ * @param {Camera} camera - The virtual camera.
2767
+ * @param {number} cursorX - Cursor horizontal coordinate on screen.
2768
+ * @param {number} cursorY - Cursor vertical coordinate on screen.
2769
+ * @param {HTMLElement} canvas - The canvas where the renderer draws its output.
2770
+ * @param {boolean} [initialDistance=false] - If initial distance between camera and gizmos should be used for calculations instead of current (Perspective only).
2771
+ * @returns {Vector3} The unprojected point on the trackball plane.
2772
+ */
2773
+ unprojectOnTbPlane( camera, cursorX, cursorY, canvas, initialDistance = false ) {
2774
+
2775
+ if ( camera.type == 'OrthographicCamera' ) {
2776
+
2777
+ this._v2_1.copy( this.getCursorPosition( cursorX, cursorY, canvas ) );
2778
+ this._v3_1.set( this._v2_1.x, this._v2_1.y, 0 );
2779
+
2780
+ return this._v3_1.clone();
2781
+
2782
+ } else if ( camera.type == 'PerspectiveCamera' ) {
2783
+
2784
+ this._v2_1.copy( this.getCursorNDC( cursorX, cursorY, canvas ) );
2785
+
2786
+ //unproject cursor on the near plane
2787
+ this._v3_1.set( this._v2_1.x, this._v2_1.y, - 1 );
2788
+ this._v3_1.applyMatrix4( camera.projectionMatrixInverse );
2789
+
2790
+ const rayDir = this._v3_1.clone().normalize(); //unprojected ray direction
2791
+
2792
+ // camera
2793
+ // |\
2794
+ // | \
2795
+ // | \
2796
+ // h | \
2797
+ // | \
2798
+ // | \
2799
+ // _ _ | _ _ _\ _ _ near plane
2800
+ // l
2801
+
2802
+ const h = this._v3_1.z;
2803
+ const l = Math.sqrt( Math.pow( this._v3_1.x, 2 ) + Math.pow( this._v3_1.y, 2 ) );
2804
+ let cameraGizmoDistance;
2805
+
2806
+ if ( initialDistance ) {
2807
+
2808
+ cameraGizmoDistance = this._v3_1.setFromMatrixPosition( this._cameraMatrixState0 ).distanceTo( this._v3_2.setFromMatrixPosition( this._gizmoMatrixState0 ) );
2809
+
2810
+ } else {
2811
+
2812
+ cameraGizmoDistance = camera.position.distanceTo( this._gizmos.position );
2813
+
2814
+ }
2815
+
2816
+ /*
2817
+ * calculate intersection point between unprojected ray and the plane
2818
+ *|y = mx + q
2819
+ *|y = 0
2820
+ *
2821
+ * x = -q/m
2822
+ */
2823
+ if ( l == 0 ) {
2824
+
2825
+ //ray aligned with camera
2826
+ rayDir.set( 0, 0, 0 );
2827
+ return rayDir;
2828
+
2829
+ }
2830
+
2831
+ const m = h / l;
2832
+ const q = cameraGizmoDistance;
2833
+ const x = - q / m;
2834
+
2835
+ const rayLength = Math.sqrt( Math.pow( q, 2 ) + Math.pow( x, 2 ) );
2836
+ rayDir.multiplyScalar( rayLength );
2837
+ rayDir.z = 0;
2838
+ return rayDir;
2839
+
2840
+ }
2841
+
2842
+ }
2843
+
2844
+ /**
2845
+ * Updates camera and gizmos state.
2846
+ *
2847
+ * @private
2848
+ */
2849
+ updateMatrixState() {
2850
+
2851
+ //update camera and gizmos state
2852
+ this._cameraMatrixState.copy( this.object.matrix );
2853
+ this._gizmoMatrixState.copy( this._gizmos.matrix );
2854
+
2855
+ if ( this.object.isOrthographicCamera ) {
2856
+
2857
+ this._cameraProjectionState.copy( this.object.projectionMatrix );
2858
+ this.object.updateProjectionMatrix();
2859
+ this._zoomState = this.object.zoom;
2860
+
2861
+ } else if ( this.object.isPerspectiveCamera ) {
2862
+
2863
+ this._fovState = this.object.fov;
2864
+
2865
+ }
2866
+
2867
+ }
2868
+
2869
+ /**
2870
+ * Updates the trackball FSA.
2871
+ *
2872
+ * @private
2873
+ * @param {STATE} newState - New state of the FSA.
2874
+ * @param {boolean} updateMatrices - If matrices state should be updated.
2875
+ */
2876
+ updateTbState( newState, updateMatrices ) {
2877
+
2878
+ this._state = newState;
2879
+ if ( updateMatrices ) {
2880
+
2881
+ this.updateMatrixState();
2882
+
2883
+ }
2884
+
2885
+ }
2886
+
2887
+ update() {
2888
+
2889
+ if ( this.target.equals( this._currentTarget ) === false ) {
2890
+
2891
+ this._gizmos.position.copy( this.target ); //for correct radius calculation
2892
+ this._tbRadius = this.calculateTbRadius( this.object );
2893
+ this.makeGizmos( this.target, this._tbRadius );
2894
+ this._currentTarget.copy( this.target );
2895
+
2896
+ }
2897
+
2898
+ //check min/max parameters
2899
+ if ( this.object.isOrthographicCamera ) {
2900
+
2901
+ //check zoom
2902
+ if ( this.object.zoom > this.maxZoom || this.object.zoom < this.minZoom ) {
2903
+
2904
+ const newZoom = MathUtils.clamp( this.object.zoom, this.minZoom, this.maxZoom );
2905
+ this.applyTransformMatrix( this.scale( newZoom / this.object.zoom, this._gizmos.position, true ) );
2906
+
2907
+ }
2908
+
2909
+ } else if ( this.object.isPerspectiveCamera ) {
2910
+
2911
+ //check distance
2912
+ const distance = this.object.position.distanceTo( this._gizmos.position );
2913
+
2914
+ if ( distance > this.maxDistance + _EPS || distance < this.minDistance - _EPS ) {
2915
+
2916
+ const newDistance = MathUtils.clamp( distance, this.minDistance, this.maxDistance );
2917
+ this.applyTransformMatrix( this.scale( newDistance / distance, this._gizmos.position ) );
2918
+ this.updateMatrixState();
2919
+
2920
+ }
2921
+
2922
+ //check fov
2923
+ if ( this.object.fov < this.minFov || this.object.fov > this.maxFov ) {
2924
+
2925
+ this.object.fov = MathUtils.clamp( this.object.fov, this.minFov, this.maxFov );
2926
+ this.object.updateProjectionMatrix();
2927
+
2928
+ }
2929
+
2930
+ const oldRadius = this._tbRadius;
2931
+ this._tbRadius = this.calculateTbRadius( this.object );
2932
+
2933
+ if ( oldRadius < this._tbRadius - _EPS || oldRadius > this._tbRadius + _EPS ) {
2934
+
2935
+ const scale = ( this._gizmos.scale.x + this._gizmos.scale.y + this._gizmos.scale.z ) / 3;
2936
+ const newRadius = this._tbRadius / scale;
2937
+ const curve = new EllipseCurve( 0, 0, newRadius, newRadius );
2938
+ const points = curve.getPoints( this._curvePts );
2939
+ const curveGeometry = new BufferGeometry().setFromPoints( points );
2940
+
2941
+ for ( const gizmo in this._gizmos.children ) {
2942
+
2943
+ this._gizmos.children[ gizmo ].geometry = curveGeometry;
2944
+
2945
+ }
2946
+
2947
+ }
2948
+
2949
+ }
2950
+
2951
+ this.object.lookAt( this._gizmos.position );
2952
+
2953
+ }
2954
+
2955
+ setStateFromJSON( json ) {
2956
+
2957
+ const state = JSON.parse( json );
2958
+
2959
+ if ( state.arcballState != undefined ) {
2960
+
2961
+ this.target.fromArray( state.arcballState.target );
2962
+
2963
+ this._cameraMatrixState.fromArray( state.arcballState.cameraMatrix.elements );
2964
+ this._cameraMatrixState.decompose( this.object.position, this.object.quaternion, this.object.scale );
2965
+
2966
+ this.object.up.copy( state.arcballState.cameraUp );
2967
+ this.object.near = state.arcballState.cameraNear;
2968
+ this.object.far = state.arcballState.cameraFar;
2969
+
2970
+ this.object.zoom = state.arcballState.cameraZoom;
2971
+
2972
+ if ( this.object.isPerspectiveCamera ) {
2973
+
2974
+ this.object.fov = state.arcballState.cameraFov;
2975
+
2976
+ }
2977
+
2978
+ this._gizmoMatrixState.fromArray( state.arcballState.gizmoMatrix.elements );
2979
+ this._gizmoMatrixState.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale );
2980
+
2981
+ this.object.updateMatrix();
2982
+ this.object.updateProjectionMatrix();
2983
+
2984
+ this._gizmos.updateMatrix();
2985
+
2986
+ this._tbRadius = this.calculateTbRadius( this.object );
2987
+ const gizmoTmp = new Matrix4().copy( this._gizmoMatrixState0 );
2988
+ this.makeGizmos( this._gizmos.position, this._tbRadius );
2989
+ this._gizmoMatrixState0.copy( gizmoTmp );
2990
+
2991
+ this.object.lookAt( this._gizmos.position );
2992
+ this.updateTbState( STATE.IDLE, false );
2993
+
2994
+ this.dispatchEvent( _changeEvent );
2995
+
2996
+ }
2997
+
2998
+ }
2999
+
3000
+ }
3001
+
3002
+ //listeners
3003
+
3004
+ function onWindowResize() {
3005
+
3006
+ const scale = ( this._gizmos.scale.x + this._gizmos.scale.y + this._gizmos.scale.z ) / 3;
3007
+ this._tbRadius = this.calculateTbRadius( this.object );
3008
+
3009
+ const newRadius = this._tbRadius / scale;
3010
+ const curve = new EllipseCurve( 0, 0, newRadius, newRadius );
3011
+ const points = curve.getPoints( this._curvePts );
3012
+ const curveGeometry = new BufferGeometry().setFromPoints( points );
3013
+
3014
+
3015
+ for ( const gizmo in this._gizmos.children ) {
3016
+
3017
+ this._gizmos.children[ gizmo ].geometry = curveGeometry;
3018
+
3019
+ }
3020
+
3021
+ this.dispatchEvent( _changeEvent );
3022
+
3023
+ }
3024
+
3025
+ function onContextMenu( event ) {
3026
+
3027
+ if ( ! this.enabled ) {
3028
+
3029
+ return;
3030
+
3031
+ }
3032
+
3033
+ for ( let i = 0; i < this.mouseActions.length; i ++ ) {
3034
+
3035
+ if ( this.mouseActions[ i ].mouse == 2 ) {
3036
+
3037
+ //prevent only if button 2 is actually used
3038
+ event.preventDefault();
3039
+ break;
3040
+
3041
+ }
3042
+
3043
+ }
3044
+
3045
+ }
3046
+
3047
+ function onPointerCancel() {
3048
+
3049
+ this._touchStart.splice( 0, this._touchStart.length );
3050
+ this._touchCurrent.splice( 0, this._touchCurrent.length );
3051
+ this._input = INPUT.NONE;
3052
+
3053
+ }
3054
+
3055
+ function onPointerDown( event ) {
3056
+
3057
+ if ( event.button == 0 && event.isPrimary ) {
3058
+
3059
+ this._downValid = true;
3060
+ this._downEvents.push( event );
3061
+ this._downStart = performance.now();
3062
+
3063
+ } else {
3064
+
3065
+ this._downValid = false;
3066
+
3067
+ }
3068
+
3069
+ if ( event.pointerType == 'touch' && this._input != INPUT.CURSOR ) {
3070
+
3071
+ this._touchStart.push( event );
3072
+ this._touchCurrent.push( event );
3073
+
3074
+ switch ( this._input ) {
3075
+
3076
+ case INPUT.NONE:
3077
+
3078
+ //singleStart
3079
+ this._input = INPUT.ONE_FINGER;
3080
+ this.onSinglePanStart( event, 'ROTATE' );
3081
+
3082
+ window.addEventListener( 'pointermove', this._onPointerMove );
3083
+ window.addEventListener( 'pointerup', this._onPointerUp );
3084
+
3085
+ break;
3086
+
3087
+ case INPUT.ONE_FINGER:
3088
+ case INPUT.ONE_FINGER_SWITCHED:
3089
+
3090
+ //doubleStart
3091
+ this._input = INPUT.TWO_FINGER;
3092
+
3093
+ this.onRotateStart();
3094
+ this.onPinchStart();
3095
+ this.onDoublePanStart();
3096
+
3097
+ break;
3098
+
3099
+ case INPUT.TWO_FINGER:
3100
+
3101
+ //multipleStart
3102
+ this._input = INPUT.MULT_FINGER;
3103
+ this.onTriplePanStart( event );
3104
+ break;
3105
+
3106
+ }
3107
+
3108
+ } else if ( event.pointerType != 'touch' && this._input == INPUT.NONE ) {
3109
+
3110
+ let modifier = null;
3111
+
3112
+ if ( event.ctrlKey || event.metaKey ) {
3113
+
3114
+ modifier = 'CTRL';
3115
+
3116
+ } else if ( event.shiftKey ) {
3117
+
3118
+ modifier = 'SHIFT';
3119
+
3120
+ }
3121
+
3122
+ this._mouseOp = this.getOpFromAction( event.button, modifier );
3123
+ if ( this._mouseOp != null ) {
3124
+
3125
+ window.addEventListener( 'pointermove', this._onPointerMove );
3126
+ window.addEventListener( 'pointerup', this._onPointerUp );
3127
+
3128
+ //singleStart
3129
+ this._input = INPUT.CURSOR;
3130
+ this._button = event.button;
3131
+ this.onSinglePanStart( event, this._mouseOp );
3132
+
3133
+ }
3134
+
3135
+ }
3136
+
3137
+ }
3138
+
3139
+ function onPointerMove( event ) {
3140
+
3141
+ if ( event.pointerType == 'touch' && this._input != INPUT.CURSOR ) {
3142
+
3143
+ switch ( this._input ) {
3144
+
3145
+ case INPUT.ONE_FINGER:
3146
+
3147
+ //singleMove
3148
+ this.updateTouchEvent( event );
3149
+
3150
+ this.onSinglePanMove( event, STATE.ROTATE );
3151
+ break;
3152
+
3153
+ case INPUT.ONE_FINGER_SWITCHED:
3154
+
3155
+ const movement = this.calculatePointersDistance( this._touchCurrent[ 0 ], event ) * this._devPxRatio;
3156
+
3157
+ if ( movement >= this._switchSensibility ) {
3158
+
3159
+ //singleMove
3160
+ this._input = INPUT.ONE_FINGER;
3161
+ this.updateTouchEvent( event );
3162
+
3163
+ this.onSinglePanStart( event, 'ROTATE' );
3164
+ break;
3165
+
3166
+ }
3167
+
3168
+ break;
3169
+
3170
+ case INPUT.TWO_FINGER:
3171
+
3172
+ //rotate/pan/pinchMove
3173
+ this.updateTouchEvent( event );
3174
+
3175
+ this.onRotateMove();
3176
+ this.onPinchMove();
3177
+ this.onDoublePanMove();
3178
+
3179
+ break;
3180
+
3181
+ case INPUT.MULT_FINGER:
3182
+
3183
+ //multMove
3184
+ this.updateTouchEvent( event );
3185
+
3186
+ this.onTriplePanMove( event );
3187
+ break;
3188
+
3189
+ }
3190
+
3191
+ } else if ( event.pointerType != 'touch' && this._input == INPUT.CURSOR ) {
3192
+
3193
+ let modifier = null;
3194
+
3195
+ if ( event.ctrlKey || event.metaKey ) {
3196
+
3197
+ modifier = 'CTRL';
3198
+
3199
+ } else if ( event.shiftKey ) {
3200
+
3201
+ modifier = 'SHIFT';
3202
+
3203
+ }
3204
+
3205
+ const mouseOpState = this.getOpStateFromAction( this._button, modifier );
3206
+
3207
+ if ( mouseOpState != null ) {
3208
+
3209
+ this.onSinglePanMove( event, mouseOpState );
3210
+
3211
+ }
3212
+
3213
+ }
3214
+
3215
+ //checkDistance
3216
+ if ( this._downValid ) {
3217
+
3218
+ const movement = this.calculatePointersDistance( this._downEvents[ this._downEvents.length - 1 ], event ) * this._devPxRatio;
3219
+ if ( movement > this._movementThreshold ) {
3220
+
3221
+ this._downValid = false;
3222
+
3223
+ }
3224
+
3225
+ }
3226
+
3227
+ }
3228
+
3229
+ function onPointerUp( event ) {
3230
+
3231
+ if ( event.pointerType == 'touch' && this._input != INPUT.CURSOR ) {
3232
+
3233
+ const nTouch = this._touchCurrent.length;
3234
+
3235
+ for ( let i = 0; i < nTouch; i ++ ) {
3236
+
3237
+ if ( this._touchCurrent[ i ].pointerId == event.pointerId ) {
3238
+
3239
+ this._touchCurrent.splice( i, 1 );
3240
+ this._touchStart.splice( i, 1 );
3241
+ break;
3242
+
3243
+ }
3244
+
3245
+ }
3246
+
3247
+ switch ( this._input ) {
3248
+
3249
+ case INPUT.ONE_FINGER:
3250
+ case INPUT.ONE_FINGER_SWITCHED:
3251
+
3252
+ //singleEnd
3253
+ window.removeEventListener( 'pointermove', this._onPointerMove );
3254
+ window.removeEventListener( 'pointerup', this._onPointerUp );
3255
+
3256
+ this._input = INPUT.NONE;
3257
+ this.onSinglePanEnd();
3258
+
3259
+ break;
3260
+
3261
+ case INPUT.TWO_FINGER:
3262
+
3263
+ //doubleEnd
3264
+ this.onDoublePanEnd( event );
3265
+ this.onPinchEnd( event );
3266
+ this.onRotateEnd( event );
3267
+
3268
+ //switching to singleStart
3269
+ this._input = INPUT.ONE_FINGER_SWITCHED;
3270
+
3271
+ break;
3272
+
3273
+ case INPUT.MULT_FINGER:
3274
+
3275
+ if ( this._touchCurrent.length == 0 ) {
3276
+
3277
+ window.removeEventListener( 'pointermove', this._onPointerMove );
3278
+ window.removeEventListener( 'pointerup', this._onPointerUp );
3279
+
3280
+ //multCancel
3281
+ this._input = INPUT.NONE;
3282
+ this.onTriplePanEnd();
3283
+
3284
+ }
3285
+
3286
+ break;
3287
+
3288
+ }
3289
+
3290
+ } else if ( event.pointerType != 'touch' && this._input == INPUT.CURSOR ) {
3291
+
3292
+ window.removeEventListener( 'pointermove', this._onPointerMove );
3293
+ window.removeEventListener( 'pointerup', this._onPointerUp );
3294
+
3295
+ this._input = INPUT.NONE;
3296
+ this.onSinglePanEnd();
3297
+ this._button = - 1;
3298
+
3299
+ }
3300
+
3301
+ if ( event.isPrimary ) {
3302
+
3303
+ if ( this._downValid ) {
3304
+
3305
+ const downTime = event.timeStamp - this._downEvents[ this._downEvents.length - 1 ].timeStamp;
3306
+
3307
+ if ( downTime <= this._maxDownTime ) {
3308
+
3309
+ if ( this._nclicks == 0 ) {
3310
+
3311
+ //first valid click detected
3312
+ this._nclicks = 1;
3313
+ this._clickStart = performance.now();
3314
+
3315
+ } else {
3316
+
3317
+ const clickInterval = event.timeStamp - this._clickStart;
3318
+ const movement = this.calculatePointersDistance( this._downEvents[ 1 ], this._downEvents[ 0 ] ) * this._devPxRatio;
3319
+
3320
+ if ( clickInterval <= this._maxInterval && movement <= this._posThreshold ) {
3321
+
3322
+ //second valid click detected
3323
+ //fire double tap and reset values
3324
+ this._nclicks = 0;
3325
+ this._downEvents.splice( 0, this._downEvents.length );
3326
+ this.onDoubleTap( event );
3327
+
3328
+ } else {
3329
+
3330
+ //new 'first click'
3331
+ this._nclicks = 1;
3332
+ this._downEvents.shift();
3333
+ this._clickStart = performance.now();
3334
+
3335
+ }
3336
+
3337
+ }
3338
+
3339
+ } else {
3340
+
3341
+ this._downValid = false;
3342
+ this._nclicks = 0;
3343
+ this._downEvents.splice( 0, this._downEvents.length );
3344
+
3345
+ }
3346
+
3347
+ } else {
3348
+
3349
+ this._nclicks = 0;
3350
+ this._downEvents.splice( 0, this._downEvents.length );
3351
+
3352
+ }
3353
+
3354
+ }
3355
+
3356
+ }
3357
+
3358
+ function onWheel( event ) {
3359
+
3360
+ if ( this.enabled && this.enableZoom ) {
3361
+
3362
+ let modifier = null;
3363
+
3364
+ if ( event.ctrlKey || event.metaKey ) {
3365
+
3366
+ modifier = 'CTRL';
3367
+
3368
+ } else if ( event.shiftKey ) {
3369
+
3370
+ modifier = 'SHIFT';
3371
+
3372
+ }
3373
+
3374
+ const mouseOp = this.getOpFromAction( 'WHEEL', modifier );
3375
+
3376
+ if ( mouseOp != null ) {
3377
+
3378
+ event.preventDefault();
3379
+ this.dispatchEvent( _startEvent );
3380
+
3381
+ const notchDeltaY = 125; //distance of one notch of mouse wheel
3382
+ let sgn = event.deltaY / notchDeltaY;
3383
+
3384
+ let size = 1;
3385
+
3386
+ if ( sgn > 0 ) {
3387
+
3388
+ size = 1 / this.scaleFactor;
3389
+
3390
+ } else if ( sgn < 0 ) {
3391
+
3392
+ size = this.scaleFactor;
3393
+
3394
+ }
3395
+
3396
+ switch ( mouseOp ) {
3397
+
3398
+ case 'ZOOM':
3399
+
3400
+ this.updateTbState( STATE.SCALE, true );
3401
+
3402
+ if ( sgn > 0 ) {
3403
+
3404
+ size = 1 / ( Math.pow( this.scaleFactor, sgn ) );
3405
+
3406
+ } else if ( sgn < 0 ) {
3407
+
3408
+ size = Math.pow( this.scaleFactor, - sgn );
3409
+
3410
+ }
3411
+
3412
+ if ( this.cursorZoom && this.enablePan ) {
3413
+
3414
+ let scalePoint;
3415
+
3416
+ if ( this.object.isOrthographicCamera ) {
3417
+
3418
+ scalePoint = this.unprojectOnTbPlane( this.object, event.clientX, event.clientY, this.domElement ).applyQuaternion( this.object.quaternion ).multiplyScalar( 1 / this.object.zoom ).add( this._gizmos.position );
3419
+
3420
+ } else if ( this.object.isPerspectiveCamera ) {
3421
+
3422
+ scalePoint = this.unprojectOnTbPlane( this.object, event.clientX, event.clientY, this.domElement ).applyQuaternion( this.object.quaternion ).add( this._gizmos.position );
3423
+
3424
+ }
3425
+
3426
+ this.applyTransformMatrix( this.scale( size, scalePoint ) );
3427
+
3428
+ } else {
3429
+
3430
+ this.applyTransformMatrix( this.scale( size, this._gizmos.position ) );
3431
+
3432
+ }
3433
+
3434
+ if ( this._grid != null ) {
3435
+
3436
+ this.disposeGrid();
3437
+ this.drawGrid();
3438
+
3439
+ }
3440
+
3441
+ this.updateTbState( STATE.IDLE, false );
3442
+
3443
+ this.dispatchEvent( _changeEvent );
3444
+ this.dispatchEvent( _endEvent );
3445
+
3446
+ break;
3447
+
3448
+ case 'FOV':
3449
+
3450
+ if ( this.object.isPerspectiveCamera ) {
3451
+
3452
+ this.updateTbState( STATE.FOV, true );
3453
+
3454
+
3455
+ //Vertigo effect
3456
+
3457
+ // fov / 2
3458
+ // |\
3459
+ // | \
3460
+ // | \
3461
+ // x | \
3462
+ // | \
3463
+ // | \
3464
+ // | _ _ _\
3465
+ // y
3466
+
3467
+ //check for iOs shift shortcut
3468
+ if ( event.deltaX != 0 ) {
3469
+
3470
+ sgn = event.deltaX / notchDeltaY;
3471
+
3472
+ size = 1;
3473
+
3474
+ if ( sgn > 0 ) {
3475
+
3476
+ size = 1 / ( Math.pow( this.scaleFactor, sgn ) );
3477
+
3478
+ } else if ( sgn < 0 ) {
3479
+
3480
+ size = Math.pow( this.scaleFactor, - sgn );
3481
+
3482
+ }
3483
+
3484
+ }
3485
+
3486
+ this._v3_1.setFromMatrixPosition( this._cameraMatrixState );
3487
+ const x = this._v3_1.distanceTo( this._gizmos.position );
3488
+ let xNew = x / size; //distance between camera and gizmos if scale(size, scalepoint) would be performed
3489
+
3490
+ //check min and max distance
3491
+ xNew = MathUtils.clamp( xNew, this.minDistance, this.maxDistance );
3492
+
3493
+ const y = x * Math.tan( MathUtils.DEG2RAD * this.object.fov * 0.5 );
3494
+
3495
+ //calculate new fov
3496
+ let newFov = MathUtils.RAD2DEG * ( Math.atan( y / xNew ) * 2 );
3497
+
3498
+ //check min and max fov
3499
+ if ( newFov > this.maxFov ) {
3500
+
3501
+ newFov = this.maxFov;
3502
+
3503
+ } else if ( newFov < this.minFov ) {
3504
+
3505
+ newFov = this.minFov;
3506
+
3507
+ }
3508
+
3509
+ const newDistance = y / Math.tan( MathUtils.DEG2RAD * ( newFov / 2 ) );
3510
+ size = x / newDistance;
3511
+
3512
+ this.setFov( newFov );
3513
+ this.applyTransformMatrix( this.scale( size, this._gizmos.position, false ) );
3514
+
3515
+ }
3516
+
3517
+ if ( this._grid != null ) {
3518
+
3519
+ this.disposeGrid();
3520
+ this.drawGrid();
3521
+
3522
+ }
3523
+
3524
+ this.updateTbState( STATE.IDLE, false );
3525
+
3526
+ this.dispatchEvent( _changeEvent );
3527
+ this.dispatchEvent( _endEvent );
3528
+
3529
+ break;
3530
+
3531
+ }
3532
+
3533
+ }
3534
+
3535
+ }
3536
+
3537
+ }
3538
+
3539
+ export { ArcballControls };