@needle-tools/three 0.145.4 → 0.146.2

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 (393) hide show
  1. package/README.md +1 -1
  2. package/build/three.cjs +32586 -35951
  3. package/build/three.js +32600 -35965
  4. package/build/three.min.js +6 -7
  5. package/build/three.module.js +1547 -1154
  6. package/examples/js/animation/AnimationClipCreator.js +0 -8
  7. package/examples/js/animation/CCDIKSolver.js +49 -66
  8. package/examples/js/animation/MMDAnimationHelper.js +66 -137
  9. package/examples/js/animation/MMDPhysics.js +70 -134
  10. package/examples/js/cameras/CinematicCamera.js +33 -22
  11. package/examples/js/controls/ArcballControls.js +138 -405
  12. package/examples/js/controls/DragControls.js +8 -33
  13. package/examples/js/controls/FirstPersonControls.js +32 -54
  14. package/examples/js/controls/FlyControls.js +29 -55
  15. package/examples/js/controls/OrbitControls.js +85 -95
  16. package/examples/js/controls/PointerLockControls.js +5 -14
  17. package/examples/js/controls/TrackballControls.js +33 -86
  18. package/examples/js/controls/TransformControls.js +84 -169
  19. package/examples/js/csm/CSM.js +4 -39
  20. package/examples/js/csm/CSMFrustum.js +3 -9
  21. package/examples/js/csm/CSMHelper.js +24 -4
  22. package/examples/js/csm/CSMShader.js +2 -6
  23. package/examples/js/curves/CurveExtras.js +27 -27
  24. package/examples/js/curves/NURBSCurve.js +4 -16
  25. package/examples/js/curves/NURBSSurface.js +3 -9
  26. package/examples/js/curves/NURBSUtils.js +8 -45
  27. package/examples/js/effects/AnaglyphEffect.js +4 -18
  28. package/examples/js/effects/AsciiEffect.js +32 -31
  29. package/examples/js/effects/OutlineEffect.js +26 -30
  30. package/examples/js/effects/ParallaxBarrierEffect.js +0 -13
  31. package/examples/js/effects/PeppersGhostEffect.js +12 -39
  32. package/examples/js/effects/StereoEffect.js +0 -4
  33. package/examples/js/environments/RoomEnvironment.js +12 -10
  34. package/examples/js/exporters/ColladaExporter.js +48 -65
  35. package/examples/js/exporters/DRACOExporter.js +22 -22
  36. package/examples/js/exporters/EXRExporter.js +15 -18
  37. package/examples/js/exporters/GLTFExporter.js +143 -261
  38. package/examples/js/exporters/MMDExporter.js +5 -12
  39. package/examples/js/exporters/OBJExporter.js +42 -33
  40. package/examples/js/exporters/PLYExporter.js +38 -33
  41. package/examples/js/exporters/STLExporter.js +5 -7
  42. package/examples/js/exporters/USDZExporter.js +110 -25
  43. package/examples/js/geometries/BoxLineGeometry.js +0 -1
  44. package/examples/js/geometries/ConvexGeometry.js +11 -6
  45. package/examples/js/geometries/DecalGeometry.js +53 -20
  46. package/examples/js/geometries/LightningStrike.js +54 -67
  47. package/examples/js/geometries/ParametricGeometries.js +8 -7
  48. package/examples/js/geometries/ParametricGeometry.js +25 -12
  49. package/examples/js/geometries/RoundedBoxGeometry.js +21 -19
  50. package/examples/js/geometries/TeapotGeometry.js +54 -50
  51. package/examples/js/geometries/TextGeometry.js +6 -4
  52. package/examples/js/helpers/LightProbeHelper.js +1 -2
  53. package/examples/js/helpers/OctreeHelper.js +22 -20
  54. package/examples/js/helpers/PositionalAudioHelper.js +8 -6
  55. package/examples/js/helpers/RectAreaLightHelper.js +6 -7
  56. package/examples/js/helpers/VertexNormalsHelper.js +15 -13
  57. package/examples/js/helpers/VertexTangentsHelper.js +15 -9
  58. package/examples/js/helpers/ViewHelper.js +31 -16
  59. package/examples/js/interactive/HTMLMesh.js +22 -33
  60. package/examples/js/interactive/InteractiveGroup.js +6 -12
  61. package/examples/js/interactive/SelectionBox.js +3 -70
  62. package/examples/js/interactive/SelectionHelper.js +0 -8
  63. package/examples/js/lights/LightProbeGenerator.js +32 -39
  64. package/examples/js/lights/RectAreaLightUniformsLib.js +5 -1
  65. package/examples/js/lines/LineGeometry.js +3 -5
  66. package/examples/js/lines/LineMaterial.js +4 -11
  67. package/examples/js/lines/LineSegments2.js +38 -89
  68. package/examples/js/lines/LineSegmentsGeometry.js +7 -28
  69. package/examples/js/lines/Wireframe.js +2 -7
  70. package/examples/js/lines/WireframeGeometry2.js +3 -1
  71. package/examples/js/loaders/3DMLoader.js +58 -155
  72. package/examples/js/loaders/3MFLoader.js +72 -106
  73. package/examples/js/loaders/AMFLoader.js +0 -25
  74. package/examples/js/loaders/BVHLoader.js +44 -43
  75. package/examples/js/loaders/BasisTextureLoader.js +16 -46
  76. package/examples/js/loaders/ColladaLoader.js +201 -359
  77. package/examples/js/loaders/DDSLoader.js +24 -25
  78. package/examples/js/loaders/DRACOLoader.js +29 -66
  79. package/examples/js/loaders/EXRLoader.js +67 -164
  80. package/examples/js/loaders/FBXLoader.js +286 -441
  81. package/examples/js/loaders/FontLoader.js +6 -15
  82. package/examples/js/loaders/GCodeLoader.js +15 -16
  83. package/examples/js/loaders/GLTFLoader.js +354 -405
  84. package/examples/js/loaders/HDRCubeTextureLoader.js +0 -6
  85. package/examples/js/loaders/KMZLoader.js +3 -7
  86. package/examples/js/loaders/KTXLoader.js +12 -30
  87. package/examples/js/loaders/LDrawLoader.js +178 -289
  88. package/examples/js/loaders/LUT3dlLoader.js +7 -11
  89. package/examples/js/loaders/LUTCubeLoader.js +0 -8
  90. package/examples/js/loaders/LWOLoader.js +59 -124
  91. package/examples/js/loaders/LogLuvLoader.js +27 -77
  92. package/examples/js/loaders/LottieLoader.js +4 -4
  93. package/examples/js/loaders/MD2Loader.js +26 -27
  94. package/examples/js/loaders/MDDLoader.js +6 -10
  95. package/examples/js/loaders/MMDLoader.js +180 -189
  96. package/examples/js/loaders/MTLLoader.js +18 -47
  97. package/examples/js/loaders/MaterialXLoader.js +392 -0
  98. package/examples/js/loaders/NRRDLoader.js +44 -84
  99. package/examples/js/loaders/OBJLoader.js +50 -65
  100. package/examples/js/loaders/PCDLoader.js +34 -29
  101. package/examples/js/loaders/PDBLoader.js +17 -13
  102. package/examples/js/loaders/PLYLoader.js +9 -39
  103. package/examples/js/loaders/PRWMLoader.js +11 -22
  104. package/examples/js/loaders/PVRLoader.js +7 -16
  105. package/examples/js/loaders/RGBELoader.js +36 -61
  106. package/examples/js/loaders/RGBMLoader.js +26 -87
  107. package/examples/js/loaders/STLLoader.js +20 -27
  108. package/examples/js/loaders/SVGLoader.js +361 -233
  109. package/examples/js/loaders/TDSLoader.js +81 -118
  110. package/examples/js/loaders/TGALoader.js +39 -41
  111. package/examples/js/loaders/TIFFLoader.js +0 -1
  112. package/examples/js/loaders/TTFLoader.js +0 -8
  113. package/examples/js/loaders/TiltLoader.js +14 -15
  114. package/examples/js/loaders/VOXLoader.js +8 -16
  115. package/examples/js/loaders/VRMLLoader.js +243 -340
  116. package/examples/js/loaders/VTKLoader.js +101 -118
  117. package/examples/js/loaders/XYZLoader.js +2 -4
  118. package/examples/js/loaders/lwo/IFFParser.js +55 -136
  119. package/examples/js/loaders/lwo/LWO2Parser.js +32 -83
  120. package/examples/js/loaders/lwo/LWO3Parser.js +31 -73
  121. package/examples/js/materials/MeshGouraudMaterial.js +15 -13
  122. package/examples/js/math/Capsule.js +0 -17
  123. package/examples/js/math/ColorConverter.js +3 -3
  124. package/examples/js/math/ConvexHull.js +183 -139
  125. package/examples/js/math/ImprovedNoise.js +1 -1
  126. package/examples/js/math/Lut.js +8 -15
  127. package/examples/js/math/MeshSurfaceSampler.js +6 -28
  128. package/examples/js/math/OBB.js +90 -49
  129. package/examples/js/math/Octree.js +2 -57
  130. package/examples/js/math/SimplexNoise.js +74 -88
  131. package/examples/js/misc/ConvexObjectBreaker.js +37 -48
  132. package/examples/js/misc/GPUComputationRenderer.js +14 -18
  133. package/examples/js/misc/Gyroscope.js +5 -9
  134. package/examples/js/misc/MD2Character.js +14 -23
  135. package/examples/js/misc/MD2CharacterComplex.js +73 -54
  136. package/examples/js/misc/MorphAnimMesh.js +0 -6
  137. package/examples/js/misc/MorphBlendMesh.js +3 -30
  138. package/examples/js/misc/ProgressiveLightMap.js +47 -43
  139. package/examples/js/misc/RollerCoaster.js +17 -24
  140. package/examples/js/misc/TubePainter.js +18 -12
  141. package/examples/js/misc/Volume.js +16 -45
  142. package/examples/js/misc/VolumeSlice.js +14 -24
  143. package/examples/js/modifiers/CurveModifier.js +19 -21
  144. package/examples/js/modifiers/EdgeSplitModifier.js +0 -30
  145. package/examples/js/modifiers/SimplifyModifier.js +56 -59
  146. package/examples/js/modifiers/TessellateModifier.js +2 -9
  147. package/examples/js/objects/GroundProjectedEnv.js +2 -14
  148. package/examples/js/objects/Lensflare.js +47 -38
  149. package/examples/js/objects/LightningStorm.js +10 -13
  150. package/examples/js/objects/MarchingCubes.js +80 -59
  151. package/examples/js/objects/Reflector.js +22 -20
  152. package/examples/js/objects/ReflectorForSSRPass.js +19 -23
  153. package/examples/js/objects/Refractor.js +52 -30
  154. package/examples/js/objects/ShadowMesh.js +1 -2
  155. package/examples/js/objects/Sky.js +2 -7
  156. package/examples/js/objects/Water.js +23 -18
  157. package/examples/js/objects/Water2.js +20 -19
  158. package/examples/js/physics/AmmoPhysics.js +23 -20
  159. package/examples/js/physics/OimoPhysics.js +19 -17
  160. package/examples/js/postprocessing/AdaptiveToneMappingPass.js +13 -20
  161. package/examples/js/postprocessing/AfterimagePass.js +19 -12
  162. package/examples/js/postprocessing/BloomPass.js +38 -17
  163. package/examples/js/postprocessing/BokehPass.js +29 -12
  164. package/examples/js/postprocessing/ClearPass.js +1 -6
  165. package/examples/js/postprocessing/CubeTexturePass.js +12 -9
  166. package/examples/js/postprocessing/DotScreenPass.js +7 -5
  167. package/examples/js/postprocessing/EffectComposer.js +25 -32
  168. package/examples/js/postprocessing/FilmPass.js +7 -5
  169. package/examples/js/postprocessing/GlitchPass.js +10 -11
  170. package/examples/js/postprocessing/HalftonePass.js +9 -9
  171. package/examples/js/postprocessing/LUTPass.js +2 -15
  172. package/examples/js/postprocessing/MaskPass.js +20 -17
  173. package/examples/js/postprocessing/OutlinePass.js +45 -36
  174. package/examples/js/postprocessing/Pass.js +11 -14
  175. package/examples/js/postprocessing/RenderPass.js +3 -7
  176. package/examples/js/postprocessing/SAOPass.js +40 -32
  177. package/examples/js/postprocessing/SMAAPass.js +34 -17
  178. package/examples/js/postprocessing/SSAARenderPass.js +14 -14
  179. package/examples/js/postprocessing/SSAOPass.js +56 -42
  180. package/examples/js/postprocessing/SSRPass.js +78 -61
  181. package/examples/js/postprocessing/SavePass.js +14 -6
  182. package/examples/js/postprocessing/ShaderPass.js +9 -8
  183. package/examples/js/postprocessing/TAARenderPass.js +11 -9
  184. package/examples/js/postprocessing/TexturePass.js +7 -4
  185. package/examples/js/postprocessing/UnrealBloomPass.js +43 -25
  186. package/examples/js/renderers/CSS2DRenderer.js +2 -21
  187. package/examples/js/renderers/CSS3DRenderer.js +3 -24
  188. package/examples/js/renderers/Projector.js +29 -85
  189. package/examples/js/renderers/SVGRenderer.js +4 -50
  190. package/examples/js/shaders/ACESFilmicToneMappingShader.js +3 -6
  191. package/examples/js/shaders/AfterimageShader.js +3 -6
  192. package/examples/js/shaders/BasicShader.js +3 -6
  193. package/examples/js/shaders/BleachBypassShader.js +3 -6
  194. package/examples/js/shaders/BlendShader.js +3 -6
  195. package/examples/js/shaders/BokehShader.js +3 -6
  196. package/examples/js/shaders/BokehShader2.js +4 -13
  197. package/examples/js/shaders/BrightnessContrastShader.js +3 -6
  198. package/examples/js/shaders/ColorCorrectionShader.js +2 -6
  199. package/examples/js/shaders/ColorifyShader.js +2 -6
  200. package/examples/js/shaders/ConvolutionShader.js +5 -10
  201. package/examples/js/shaders/CopyShader.js +3 -6
  202. package/examples/js/shaders/DOFMipMapShader.js +3 -6
  203. package/examples/js/shaders/DepthLimitedBlurShader.js +2 -9
  204. package/examples/js/shaders/DigitalGlitch.js +3 -6
  205. package/examples/js/shaders/DotScreenShader.js +2 -6
  206. package/examples/js/shaders/FXAAShader.js +1 -3
  207. package/examples/js/shaders/FilmShader.js +3 -6
  208. package/examples/js/shaders/FocusShader.js +3 -6
  209. package/examples/js/shaders/FreiChenShader.js +2 -6
  210. package/examples/js/shaders/GammaCorrectionShader.js +3 -6
  211. package/examples/js/shaders/GodRaysShader.js +11 -24
  212. package/examples/js/shaders/HalftoneShader.js +3 -6
  213. package/examples/js/shaders/HorizontalBlurShader.js +3 -6
  214. package/examples/js/shaders/HorizontalTiltShiftShader.js +3 -6
  215. package/examples/js/shaders/HueSaturationShader.js +3 -6
  216. package/examples/js/shaders/KaleidoShader.js +3 -6
  217. package/examples/js/shaders/LuminosityHighPassShader.js +2 -6
  218. package/examples/js/shaders/LuminosityShader.js +3 -6
  219. package/examples/js/shaders/MMDToonShader.js +2 -6
  220. package/examples/js/shaders/MirrorShader.js +3 -6
  221. package/examples/js/shaders/NormalMapShader.js +2 -6
  222. package/examples/js/shaders/RGBShiftShader.js +3 -6
  223. package/examples/js/shaders/SAOShader.js +2 -6
  224. package/examples/js/shaders/SMAAShader.js +6 -18
  225. package/examples/js/shaders/SSAOShader.js +2 -6
  226. package/examples/js/shaders/SSRShader.js +6 -18
  227. package/examples/js/shaders/SepiaShader.js +3 -6
  228. package/examples/js/shaders/SobelOperatorShader.js +2 -6
  229. package/examples/js/shaders/TechnicolorShader.js +3 -6
  230. package/examples/js/shaders/ToneMapShader.js +3 -6
  231. package/examples/js/shaders/ToonShader.js +8 -24
  232. package/examples/js/shaders/TriangleBlurShader.js +2 -6
  233. package/examples/js/shaders/UnpackDepthRGBAShader.js +3 -6
  234. package/examples/js/shaders/VelocityShader.js +126 -0
  235. package/examples/js/shaders/VerticalBlurShader.js +3 -6
  236. package/examples/js/shaders/VerticalTiltShiftShader.js +3 -6
  237. package/examples/js/shaders/VignetteShader.js +3 -6
  238. package/examples/js/shaders/VolumeShader.js +2 -6
  239. package/examples/js/shaders/WaterRefractionShader.js +2 -6
  240. package/examples/js/textures/FlakesTexture.js +0 -1
  241. package/examples/js/utils/BufferGeometryUtils.js +234 -168
  242. package/examples/js/utils/CameraUtils.js +5 -20
  243. package/examples/js/utils/GPUStatsPanel.js +3 -12
  244. package/examples/js/utils/GeometryCompressionUtils.js +19 -44
  245. package/examples/js/utils/GeometryUtils.js +13 -18
  246. package/examples/js/utils/LDrawUtils.js +8 -11
  247. package/examples/js/utils/PackedPhongMaterial.js +6 -4
  248. package/examples/js/utils/SceneUtils.js +117 -6
  249. package/examples/js/utils/ShadowMapViewer.js +17 -14
  250. package/examples/js/utils/SkeletonUtils.js +13 -27
  251. package/examples/js/utils/UVsDebug.js +20 -12
  252. package/examples/js/utils/WorkerPool.js +1 -11
  253. package/examples/jsm/animation/CCDIKSolver.js +1 -1
  254. package/examples/jsm/capabilities/WebGPU.js +3 -1
  255. package/examples/jsm/controls/OrbitControls.js +44 -4
  256. package/examples/jsm/exporters/GLTFExporter.js +17 -131
  257. package/examples/jsm/exporters/USDZExporter.js +75 -19
  258. package/examples/jsm/interactive/HTMLMesh.js +2 -0
  259. package/examples/jsm/libs/lottie_canvas.module.js +14844 -0
  260. package/examples/jsm/loaders/3DMLoader.js +1 -2
  261. package/examples/jsm/loaders/ColladaLoader.js +28 -0
  262. package/examples/jsm/loaders/FBXLoader.js +16 -2
  263. package/examples/jsm/loaders/GLTFLoader.js +204 -377
  264. package/examples/jsm/loaders/KTX2Loader.js +68 -29
  265. package/examples/jsm/loaders/LDrawLoader.js +14 -13
  266. package/examples/jsm/loaders/LottieLoader.js +4 -2
  267. package/examples/jsm/loaders/MaterialXLoader.js +728 -0
  268. package/examples/jsm/loaders/PCDLoader.js +1 -1
  269. package/examples/jsm/loaders/PLYLoader.js +68 -16
  270. package/examples/jsm/loaders/SVGLoader.js +227 -14
  271. package/examples/jsm/loaders/USDZLoader.js +31 -16
  272. package/examples/jsm/nodes/Nodes.js +14 -2
  273. package/examples/jsm/nodes/accessors/Object3DNode.js +1 -1
  274. package/examples/jsm/nodes/accessors/PositionNode.js +6 -0
  275. package/examples/jsm/nodes/accessors/ReferenceNode.js +1 -1
  276. package/examples/jsm/nodes/accessors/SkinningNode.js +1 -1
  277. package/examples/jsm/nodes/core/Node.js +1 -1
  278. package/examples/jsm/nodes/core/NodeBuilder.js +36 -4
  279. package/examples/jsm/nodes/core/NodeFrame.js +2 -2
  280. package/examples/jsm/nodes/core/NodeVarying.js +7 -4
  281. package/examples/jsm/nodes/core/VaryingNode.js +6 -4
  282. package/examples/jsm/nodes/core/constants.js +13 -13
  283. package/examples/jsm/nodes/display/PosterizeNode.js +25 -0
  284. package/examples/jsm/nodes/display/ViewportNode.js +106 -0
  285. package/examples/jsm/nodes/gpgpu/ComputeNode.js +1 -1
  286. package/examples/jsm/nodes/lighting/AnalyticLightNode.js +1 -1
  287. package/examples/jsm/nodes/loaders/NodeMaterialLoader.js +3 -1
  288. package/examples/jsm/nodes/materials/Materials.js +9 -7
  289. package/examples/jsm/nodes/materials/NodeMaterial.js +9 -1
  290. package/examples/jsm/nodes/materialx/MaterialXNodes.js +6 -2
  291. package/examples/jsm/nodes/materialx/lib/mx_transform_color.js +18 -0
  292. package/examples/jsm/nodes/math/MathNode.js +5 -0
  293. package/examples/jsm/nodes/math/OperatorNode.js +6 -1
  294. package/examples/jsm/nodes/shadernode/ShaderNode.js +26 -13
  295. package/examples/jsm/nodes/shadernode/ShaderNodeBaseElements.js +2 -0
  296. package/examples/jsm/nodes/shadernode/ShaderNodeElements.js +18 -0
  297. package/examples/jsm/nodes/utils/EquirectUVNode.js +27 -0
  298. package/examples/jsm/nodes/utils/JoinNode.js +8 -2
  299. package/examples/jsm/nodes/utils/MatcapUVNode.js +2 -4
  300. package/examples/jsm/nodes/utils/MaxMipLevelNode.js +1 -1
  301. package/examples/jsm/nodes/utils/SpriteSheetUVNode.js +8 -10
  302. package/examples/jsm/nodes/utils/TimerNode.js +1 -1
  303. package/examples/jsm/nodes/utils/TriplanarTexturesNode.js +51 -0
  304. package/examples/jsm/postprocessing/AfterimagePass.js +17 -4
  305. package/examples/jsm/postprocessing/BloomPass.js +22 -3
  306. package/examples/jsm/postprocessing/BokehPass.js +18 -4
  307. package/examples/jsm/postprocessing/CubeTexturePass.js +12 -5
  308. package/examples/jsm/postprocessing/DotScreenPass.js +8 -0
  309. package/examples/jsm/postprocessing/EffectComposer.js +9 -0
  310. package/examples/jsm/postprocessing/FilmPass.js +8 -0
  311. package/examples/jsm/postprocessing/GlitchPass.js +13 -1
  312. package/examples/jsm/postprocessing/HalftonePass.js +8 -0
  313. package/examples/jsm/postprocessing/OutlinePass.js +10 -0
  314. package/examples/jsm/postprocessing/Pass.js +2 -0
  315. package/examples/jsm/postprocessing/RenderPixelatedPass.js +234 -0
  316. package/examples/jsm/postprocessing/SAOPass.js +20 -0
  317. package/examples/jsm/postprocessing/SMAAPass.js +16 -0
  318. package/examples/jsm/postprocessing/SSAARenderPass.js +4 -0
  319. package/examples/jsm/postprocessing/SavePass.js +17 -1
  320. package/examples/jsm/postprocessing/ShaderPass.js +8 -0
  321. package/examples/jsm/postprocessing/TAARenderPass.js +9 -0
  322. package/examples/jsm/postprocessing/TexturePass.js +8 -0
  323. package/examples/jsm/postprocessing/UnrealBloomPass.js +16 -0
  324. package/examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js +39 -16
  325. package/examples/jsm/renderers/webgpu/WebGPUAnimation.js +58 -0
  326. package/examples/jsm/renderers/webgpu/WebGPUAttributes.js +63 -5
  327. package/examples/jsm/renderers/webgpu/WebGPUBackground.js +36 -7
  328. package/examples/jsm/renderers/webgpu/WebGPURenderer.js +47 -12
  329. package/examples/jsm/renderers/webgpu/nodes/WebGPUNodeBuilder.js +35 -5
  330. package/examples/jsm/shaders/MMDToonShader.js +0 -2
  331. package/examples/jsm/shaders/VelocityShader.js +128 -0
  332. package/examples/jsm/utils/BufferGeometryUtils.js +130 -6
  333. package/examples/jsm/utils/SceneUtils.js +129 -4
  334. package/examples/jsm/utils/TextureUtils.js +85 -0
  335. package/examples/jsm/webxr/OculusHandModel.js +1 -1
  336. package/examples/jsm/webxr/XRHandMeshModel.js +6 -3
  337. package/package.json +11 -12
  338. package/src/Three.js +1 -0
  339. package/src/audio/AudioContext.js +5 -5
  340. package/src/cameras/CubeCamera.js +14 -14
  341. package/src/constants.js +1 -1
  342. package/src/core/InstancedBufferGeometry.js +1 -7
  343. package/src/extras/Earcut.js +67 -67
  344. package/src/helpers/DirectionalLightHelper.js +5 -1
  345. package/src/helpers/HemisphereLightHelper.js +4 -1
  346. package/src/helpers/PointLightHelper.js +2 -1
  347. package/src/helpers/SpotLightHelper.js +4 -2
  348. package/src/lights/PointLight.js +2 -2
  349. package/src/lights/SpotLight.js +2 -2
  350. package/src/loaders/FileLoader.js +4 -1
  351. package/src/loaders/ObjectLoader.js +5 -1
  352. package/src/materials/Material.js +1 -1
  353. package/src/math/Color.js +5 -5
  354. package/src/math/Matrix3.js +53 -18
  355. package/src/math/Ray.js +2 -5
  356. package/src/math/Sphere.js +19 -26
  357. package/src/objects/InstancedMesh.js +7 -0
  358. package/src/objects/LOD.js +25 -6
  359. package/src/renderers/WebGL3DRenderTarget.js +1 -1
  360. package/src/renderers/WebGLArrayRenderTarget.js +1 -1
  361. package/src/renderers/WebGLCubeRenderTarget.js +1 -1
  362. package/src/renderers/WebGLMultipleRenderTargets.js +1 -1
  363. package/src/renderers/WebGLRenderTarget.js +1 -1
  364. package/src/renderers/WebGLRenderer.js +36 -62
  365. package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +0 -4
  366. package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +0 -1
  367. package/src/renderers/shaders/ShaderChunk/lights_lambert_pars_fragment.glsl.js +0 -2
  368. package/src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl.js +0 -2
  369. package/src/renderers/shaders/ShaderChunk/lights_toon_pars_fragment.glsl.js +0 -2
  370. package/src/renderers/shaders/ShaderChunk/packing.glsl.js +8 -0
  371. package/src/renderers/shaders/ShaderChunk.js +3 -0
  372. package/src/renderers/shaders/ShaderLib/background.glsl.js +7 -2
  373. package/src/renderers/shaders/ShaderLib/backgroundCube.glsl.js +62 -0
  374. package/src/renderers/shaders/ShaderLib/cube.glsl.js +4 -6
  375. package/src/renderers/shaders/ShaderLib.js +20 -6
  376. package/src/renderers/shaders/UniformsLib.js +1 -1
  377. package/src/renderers/shaders/UniformsUtils.js +15 -0
  378. package/src/renderers/webgl/WebGLAttributes.js +2 -0
  379. package/src/renderers/webgl/WebGLBackground.js +15 -7
  380. package/src/renderers/webgl/WebGLLights.js +0 -4
  381. package/src/renderers/webgl/WebGLMaterials.js +2 -1
  382. package/src/renderers/webgl/WebGLShadowMap.js +3 -1
  383. package/src/renderers/webgl/WebGLState.js +31 -1
  384. package/src/renderers/webgl/WebGLTextures.js +71 -18
  385. package/src/renderers/webgl/WebGLUniforms.js +116 -20
  386. package/src/renderers/webgl/WebGLUtils.js +1 -1
  387. package/src/renderers/webxr/WebXRController.js +46 -13
  388. package/src/renderers/webxr/WebXRManager.js +85 -3
  389. package/src/scenes/Scene.js +8 -0
  390. package/src/textures/CompressedArrayTexture.js +18 -0
  391. package/examples/js/libs/lottie_canvas.js +0 -12751
  392. package/examples/js/shaders/PixelShader.js +0 -51
  393. package/examples/jsm/shaders/PixelShader.js +0 -44
@@ -1,5 +1,6 @@
1
1
  ( function () {
2
2
 
3
+ //trackball state
3
4
  const STATE = {
4
5
  IDLE: Symbol(),
5
6
  ROTATE: Symbol(),
@@ -19,18 +20,21 @@
19
20
  TWO_FINGER: Symbol(),
20
21
  MULT_FINGER: Symbol(),
21
22
  CURSOR: Symbol()
22
- }; //cursor center coordinates
23
+ };
23
24
 
25
+ //cursor center coordinates
24
26
  const _center = {
25
27
  x: 0,
26
28
  y: 0
27
- }; //transformation matrices for gizmos and camera
29
+ };
28
30
 
31
+ //transformation matrices for gizmos and camera
29
32
  const _transformation = {
30
33
  camera: new THREE.Matrix4(),
31
34
  gizmos: new THREE.Matrix4()
32
- }; //events
35
+ };
33
36
 
37
+ //events
34
38
  const _changeEvent = {
35
39
  type: 'change'
36
40
  };
@@ -40,15 +44,10 @@
40
44
  const _endEvent = {
41
45
  type: 'end'
42
46
  };
43
-
44
47
  const _raycaster = new THREE.Raycaster();
45
-
46
48
  const _offset = new THREE.Vector3();
47
-
48
49
  const _gizmoMatrixStateTemp = new THREE.Matrix4();
49
-
50
50
  const _cameraMatrixStateTemp = new THREE.Matrix4();
51
-
52
51
  const _scalePointTemp = new THREE.Vector3();
53
52
  /**
54
53
  *
@@ -56,14 +55,11 @@
56
55
  * @param {HTMLElement} domElement Renderer's dom element
57
56
  * @param {Scene} scene The scene to be rendered
58
57
  */
59
-
60
-
61
58
  class ArcballControls extends THREE.EventDispatcher {
62
59
 
63
60
  constructor( _camera, domElement, scene = null ) {
64
61
 
65
62
  super();
66
-
67
63
  this.onWindowResize = () => {
68
64
 
69
65
  const scale = ( this._gizmos.scale.x + this._gizmos.scale.y + this._gizmos.scale.z ) / 3;
@@ -72,7 +68,6 @@
72
68
  const curve = new THREE.EllipseCurve( 0, 0, newRadius, newRadius );
73
69
  const points = curve.getPoints( this._curvePts );
74
70
  const curveGeometry = new THREE.BufferGeometry().setFromPoints( points );
75
-
76
71
  for ( const gizmo in this._gizmos.children ) {
77
72
 
78
73
  this._gizmos.children[ gizmo ].geometry = curveGeometry;
@@ -108,9 +103,7 @@
108
103
  this.onPointerCancel = () => {
109
104
 
110
105
  this._touchStart.splice( 0, this._touchStart.length );
111
-
112
106
  this._touchCurrent.splice( 0, this._touchCurrent.length );
113
-
114
107
  this._input = INPUT.NONE;
115
108
 
116
109
  };
@@ -120,9 +113,7 @@
120
113
  if ( event.button == 0 && event.isPrimary ) {
121
114
 
122
115
  this._downValid = true;
123
-
124
116
  this._downEvents.push( event );
125
-
126
117
  this._downStart = performance.now();
127
118
 
128
119
  } else {
@@ -134,9 +125,7 @@
134
125
  if ( event.pointerType == 'touch' && this._input != INPUT.CURSOR ) {
135
126
 
136
127
  this._touchStart.push( event );
137
-
138
128
  this._touchCurrent.push( event );
139
-
140
129
  switch ( this._input ) {
141
130
 
142
131
  case INPUT.NONE:
@@ -146,7 +135,6 @@
146
135
  window.addEventListener( 'pointermove', this.onPointerMove );
147
136
  window.addEventListener( 'pointerup', this.onPointerUp );
148
137
  break;
149
-
150
138
  case INPUT.ONE_FINGER:
151
139
  case INPUT.ONE_FINGER_SWITCHED:
152
140
  //doubleStart
@@ -155,7 +143,6 @@
155
143
  this.onPinchStart();
156
144
  this.onDoublePanStart();
157
145
  break;
158
-
159
146
  case INPUT.TWO_FINGER:
160
147
  //multipleStart
161
148
  this._input = INPUT.MULT_FINGER;
@@ -167,7 +154,6 @@
167
154
  } else if ( event.pointerType != 'touch' && this._input == INPUT.NONE ) {
168
155
 
169
156
  let modifier = null;
170
-
171
157
  if ( event.ctrlKey || event.metaKey ) {
172
158
 
173
159
  modifier = 'CTRL';
@@ -179,12 +165,12 @@
179
165
  }
180
166
 
181
167
  this._mouseOp = this.getOpFromAction( event.button, modifier );
182
-
183
168
  if ( this._mouseOp != null ) {
184
169
 
185
170
  window.addEventListener( 'pointermove', this.onPointerMove );
186
- window.addEventListener( 'pointerup', this.onPointerUp ); //singleStart
171
+ window.addEventListener( 'pointerup', this.onPointerUp );
187
172
 
173
+ //singleStart
188
174
  this._input = INPUT.CURSOR;
189
175
  this._button = event.button;
190
176
  this.onSinglePanStart( event, this._mouseOp );
@@ -206,10 +192,8 @@
206
192
  this.updateTouchEvent( event );
207
193
  this.onSinglePanMove( event, STATE.ROTATE );
208
194
  break;
209
-
210
195
  case INPUT.ONE_FINGER_SWITCHED:
211
196
  const movement = this.calculatePointersDistance( this._touchCurrent[ 0 ], event ) * this._devPxRatio;
212
-
213
197
  if ( movement >= this._switchSensibility ) {
214
198
 
215
199
  //singleMove
@@ -221,7 +205,6 @@
221
205
  }
222
206
 
223
207
  break;
224
-
225
208
  case INPUT.TWO_FINGER:
226
209
  //rotate/pan/pinchMove
227
210
  this.updateTouchEvent( event );
@@ -229,7 +212,6 @@
229
212
  this.onPinchMove();
230
213
  this.onDoublePanMove();
231
214
  break;
232
-
233
215
  case INPUT.MULT_FINGER:
234
216
  //multMove
235
217
  this.updateTouchEvent( event );
@@ -241,7 +223,6 @@
241
223
  } else if ( event.pointerType != 'touch' && this._input == INPUT.CURSOR ) {
242
224
 
243
225
  let modifier = null;
244
-
245
226
  if ( event.ctrlKey || event.metaKey ) {
246
227
 
247
228
  modifier = 'CTRL';
@@ -253,20 +234,18 @@
253
234
  }
254
235
 
255
236
  const mouseOpState = this.getOpStateFromAction( this._button, modifier );
256
-
257
237
  if ( mouseOpState != null ) {
258
238
 
259
239
  this.onSinglePanMove( event, mouseOpState );
260
240
 
261
241
  }
262
242
 
263
- } //checkDistance
264
-
243
+ }
265
244
 
245
+ //checkDistance
266
246
  if ( this._downValid ) {
267
247
 
268
248
  const movement = this.calculatePointersDistance( this._downEvents[ this._downEvents.length - 1 ], event ) * this._devPxRatio;
269
-
270
249
  if ( movement > this._movementThreshold ) {
271
250
 
272
251
  this._downValid = false;
@@ -282,15 +261,12 @@
282
261
  if ( event.pointerType == 'touch' && this._input != INPUT.CURSOR ) {
283
262
 
284
263
  const nTouch = this._touchCurrent.length;
285
-
286
264
  for ( let i = 0; i < nTouch; i ++ ) {
287
265
 
288
266
  if ( this._touchCurrent[ i ].pointerId == event.pointerId ) {
289
267
 
290
268
  this._touchCurrent.splice( i, 1 );
291
-
292
269
  this._touchStart.splice( i, 1 );
293
-
294
270
  break;
295
271
 
296
272
  }
@@ -307,22 +283,22 @@
307
283
  this._input = INPUT.NONE;
308
284
  this.onSinglePanEnd();
309
285
  break;
310
-
311
286
  case INPUT.TWO_FINGER:
312
287
  //doubleEnd
313
288
  this.onDoublePanEnd( event );
314
289
  this.onPinchEnd( event );
315
- this.onRotateEnd( event ); //switching to singleStart
290
+ this.onRotateEnd( event );
316
291
 
292
+ //switching to singleStart
317
293
  this._input = INPUT.ONE_FINGER_SWITCHED;
318
294
  break;
319
-
320
295
  case INPUT.MULT_FINGER:
321
296
  if ( this._touchCurrent.length == 0 ) {
322
297
 
323
298
  window.removeEventListener( 'pointermove', this.onPointerMove );
324
- window.removeEventListener( 'pointerup', this.onPointerUp ); //multCancel
299
+ window.removeEventListener( 'pointerup', this.onPointerUp );
325
300
 
301
+ //multCancel
326
302
  this._input = INPUT.NONE;
327
303
  this.onTriplePanEnd();
328
304
 
@@ -347,7 +323,6 @@
347
323
  if ( this._downValid ) {
348
324
 
349
325
  const downTime = event.timeStamp - this._downEvents[ this._downEvents.length - 1 ].timeStamp;
350
-
351
326
  if ( downTime <= this._maxDownTime ) {
352
327
 
353
328
  if ( this._nclicks == 0 ) {
@@ -359,26 +334,20 @@
359
334
  } else {
360
335
 
361
336
  const clickInterval = event.timeStamp - this._clickStart;
362
-
363
337
  const movement = this.calculatePointersDistance( this._downEvents[ 1 ], this._downEvents[ 0 ] ) * this._devPxRatio;
364
-
365
338
  if ( clickInterval <= this._maxInterval && movement <= this._posThreshold ) {
366
339
 
367
340
  //second valid click detected
368
341
  //fire double tap and reset values
369
342
  this._nclicks = 0;
370
-
371
343
  this._downEvents.splice( 0, this._downEvents.length );
372
-
373
344
  this.onDoubleTap( event );
374
345
 
375
346
  } else {
376
347
 
377
348
  //new 'first click'
378
349
  this._nclicks = 1;
379
-
380
350
  this._downEvents.shift();
381
-
382
351
  this._clickStart = performance.now();
383
352
 
384
353
  }
@@ -389,7 +358,6 @@
389
358
 
390
359
  this._downValid = false;
391
360
  this._nclicks = 0;
392
-
393
361
  this._downEvents.splice( 0, this._downEvents.length );
394
362
 
395
363
  }
@@ -397,7 +365,6 @@
397
365
  } else {
398
366
 
399
367
  this._nclicks = 0;
400
-
401
368
  this._downEvents.splice( 0, this._downEvents.length );
402
369
 
403
370
  }
@@ -411,7 +378,6 @@
411
378
  if ( this.enabled && this.enableZoom ) {
412
379
 
413
380
  let modifier = null;
414
-
415
381
  if ( event.ctrlKey || event.metaKey ) {
416
382
 
417
383
  modifier = 'CTRL';
@@ -423,16 +389,13 @@
423
389
  }
424
390
 
425
391
  const mouseOp = this.getOpFromAction( 'WHEEL', modifier );
426
-
427
392
  if ( mouseOp != null ) {
428
393
 
429
394
  event.preventDefault();
430
395
  this.dispatchEvent( _startEvent );
431
396
  const notchDeltaY = 125; //distance of one notch of mouse wheel
432
-
433
397
  let sgn = event.deltaY / notchDeltaY;
434
398
  let size = 1;
435
-
436
399
  if ( sgn > 0 ) {
437
400
 
438
401
  size = 1 / this.scaleFactor;
@@ -447,7 +410,6 @@
447
410
 
448
411
  case 'ZOOM':
449
412
  this.updateTbState( STATE.SCALE, true );
450
-
451
413
  if ( sgn > 0 ) {
452
414
 
453
415
  size = 1 / Math.pow( this.scaleFactor, sgn );
@@ -461,7 +423,6 @@
461
423
  if ( this.cursorZoom && this.enablePan ) {
462
424
 
463
425
  let scalePoint;
464
-
465
426
  if ( this.camera.isOrthographicCamera ) {
466
427
 
467
428
  scalePoint = this.unprojectOnTbPlane( this.camera, event.clientX, event.clientY, this.domElement ).applyQuaternion( this.camera.quaternion ).multiplyScalar( 1 / this.camera.zoom ).add( this._gizmos.position );
@@ -491,11 +452,13 @@
491
452
  this.dispatchEvent( _changeEvent );
492
453
  this.dispatchEvent( _endEvent );
493
454
  break;
494
-
495
455
  case 'FOV':
496
456
  if ( this.camera.isPerspectiveCamera ) {
497
457
 
498
- this.updateTbState( STATE.FOV, true ); //Vertigo effect
458
+ this.updateTbState( STATE.FOV, true );
459
+
460
+ //Vertigo effect
461
+
499
462
  // fov / 2
500
463
  // |\
501
464
  // | \
@@ -505,13 +468,12 @@
505
468
  // | \
506
469
  // | _ _ _\
507
470
  // y
508
- //check for iOs shift shortcut
509
471
 
472
+ //check for iOs shift shortcut
510
473
  if ( event.deltaX != 0 ) {
511
474
 
512
475
  sgn = event.deltaX / notchDeltaY;
513
476
  size = 1;
514
-
515
477
  if ( sgn > 0 ) {
516
478
 
517
479
  size = 1 / Math.pow( this.scaleFactor, sgn );
@@ -525,17 +487,17 @@
525
487
  }
526
488
 
527
489
  this._v3_1.setFromMatrixPosition( this._cameraMatrixState );
528
-
529
490
  const x = this._v3_1.distanceTo( this._gizmos.position );
530
-
531
491
  let xNew = x / size; //distance between camera and gizmos if scale(size, scalepoint) would be performed
532
- //check min and max distance
533
492
 
493
+ //check min and max distance
534
494
  xNew = THREE.MathUtils.clamp( xNew, this.minDistance, this.maxDistance );
535
- const y = x * Math.tan( THREE.MathUtils.DEG2RAD * this.camera.fov * 0.5 ); //calculate new fov
495
+ const y = x * Math.tan( THREE.MathUtils.DEG2RAD * this.camera.fov * 0.5 );
536
496
 
537
- let newFov = THREE.MathUtils.RAD2DEG * ( Math.atan( y / xNew ) * 2 ); //check min and max fov
497
+ //calculate new fov
498
+ let newFov = THREE.MathUtils.RAD2DEG * ( Math.atan( y / xNew ) * 2 );
538
499
 
500
+ //check min and max fov
539
501
  if ( newFov > this.maxFov ) {
540
502
 
541
503
  newFov = this.maxFov;
@@ -579,7 +541,6 @@
579
541
 
580
542
  this.dispatchEvent( _startEvent );
581
543
  this.setCenter( event.clientX, event.clientY );
582
-
583
544
  switch ( operation ) {
584
545
 
585
546
  case 'PAN':
@@ -600,9 +561,7 @@
600
561
  }
601
562
 
602
563
  this.updateTbState( STATE.PAN, true );
603
-
604
564
  this._startCursorPosition.copy( this.unprojectOnTbPlane( this.camera, _center.x, _center.y, this.domElement ) );
605
-
606
565
  if ( this.enableGrid ) {
607
566
 
608
567
  this.drawGrid();
@@ -611,7 +570,6 @@
611
570
  }
612
571
 
613
572
  break;
614
-
615
573
  case 'ROTATE':
616
574
  if ( ! this.enableRotate ) {
617
575
 
@@ -628,20 +586,14 @@
628
586
  }
629
587
 
630
588
  this.updateTbState( STATE.ROTATE, true );
631
-
632
589
  this._startCursorPosition.copy( this.unprojectOnTbSurface( this.camera, _center.x, _center.y, this.domElement, this._tbRadius ) );
633
-
634
590
  this.activateGizmos( true );
635
-
636
591
  if ( this.enableAnimations ) {
637
592
 
638
593
  this._timePrev = this._timeCurrent = performance.now();
639
594
  this._angleCurrent = this._anglePrev = 0;
640
-
641
595
  this._cursorPosPrev.copy( this._startCursorPosition );
642
-
643
596
  this._cursorPosCurr.copy( this._cursorPosPrev );
644
-
645
597
  this._wCurr = 0;
646
598
  this._wPrev = this._wCurr;
647
599
 
@@ -649,7 +601,6 @@
649
601
 
650
602
  this.dispatchEvent( _changeEvent );
651
603
  break;
652
-
653
604
  case 'FOV':
654
605
  if ( ! this.camera.isPerspectiveCamera || ! this.enableZoom ) {
655
606
 
@@ -668,13 +619,9 @@
668
619
  }
669
620
 
670
621
  this.updateTbState( STATE.FOV, true );
671
-
672
622
  this._startCursorPosition.setY( this.getCursorNDC( _center.x, _center.y, this.domElement ).y * 0.5 );
673
-
674
623
  this._currentCursorPosition.copy( this._startCursorPosition );
675
-
676
624
  break;
677
-
678
625
  case 'ZOOM':
679
626
  if ( ! this.enableZoom ) {
680
627
 
@@ -693,11 +640,8 @@
693
640
  }
694
641
 
695
642
  this.updateTbState( STATE.SCALE, true );
696
-
697
643
  this._startCursorPosition.setY( this.getCursorNDC( _center.x, _center.y, this.domElement ).y * 0.5 );
698
-
699
644
  this._currentCursorPosition.copy( this._startCursorPosition );
700
-
701
645
  break;
702
646
 
703
647
  }
@@ -712,7 +656,6 @@
712
656
 
713
657
  const restart = opState != this._state;
714
658
  this.setCenter( event.clientX, event.clientY );
715
-
716
659
  switch ( opState ) {
717
660
 
718
661
  case STATE.PAN:
@@ -721,12 +664,11 @@
721
664
  if ( restart ) {
722
665
 
723
666
  //switch to pan operation
667
+
724
668
  this.dispatchEvent( _endEvent );
725
669
  this.dispatchEvent( _startEvent );
726
670
  this.updateTbState( opState, true );
727
-
728
671
  this._startCursorPosition.copy( this.unprojectOnTbPlane( this.camera, _center.x, _center.y, this.domElement ) );
729
-
730
672
  if ( this.enableGrid ) {
731
673
 
732
674
  this.drawGrid();
@@ -739,7 +681,6 @@
739
681
 
740
682
  //continue with pan operation
741
683
  this._currentCursorPosition.copy( this.unprojectOnTbPlane( this.camera, _center.x, _center.y, this.domElement ) );
742
-
743
684
  this.applyTransformMatrix( this.pan( this._startCursorPosition, this._currentCursorPosition ) );
744
685
 
745
686
  }
@@ -747,19 +688,17 @@
747
688
  }
748
689
 
749
690
  break;
750
-
751
691
  case STATE.ROTATE:
752
692
  if ( this.enableRotate ) {
753
693
 
754
694
  if ( restart ) {
755
695
 
756
696
  //switch to rotate operation
697
+
757
698
  this.dispatchEvent( _endEvent );
758
699
  this.dispatchEvent( _startEvent );
759
700
  this.updateTbState( opState, true );
760
-
761
701
  this._startCursorPosition.copy( this.unprojectOnTbSurface( this.camera, _center.x, _center.y, this.domElement, this._tbRadius ) );
762
-
763
702
  if ( this.enableGrid ) {
764
703
 
765
704
  this.disposeGrid();
@@ -772,26 +711,19 @@
772
711
 
773
712
  //continue with rotate operation
774
713
  this._currentCursorPosition.copy( this.unprojectOnTbSurface( this.camera, _center.x, _center.y, this.domElement, this._tbRadius ) );
775
-
776
714
  const distance = this._startCursorPosition.distanceTo( this._currentCursorPosition );
777
-
778
715
  const angle = this._startCursorPosition.angleTo( this._currentCursorPosition );
779
-
780
716
  const amount = Math.max( distance / this._tbRadius, angle ); //effective rotation angle
781
717
 
782
718
  this.applyTransformMatrix( this.rotate( this.calculateRotationAxis( this._startCursorPosition, this._currentCursorPosition ), amount ) );
783
-
784
719
  if ( this.enableAnimations ) {
785
720
 
786
721
  this._timePrev = this._timeCurrent;
787
722
  this._timeCurrent = performance.now();
788
723
  this._anglePrev = this._angleCurrent;
789
724
  this._angleCurrent = amount;
790
-
791
725
  this._cursorPosPrev.copy( this._cursorPosCurr );
792
-
793
726
  this._cursorPosCurr.copy( this._currentCursorPosition );
794
-
795
727
  this._wPrev = this._wCurr;
796
728
  this._wCurr = this.calculateAngularSpeed( this._anglePrev, this._angleCurrent, this._timePrev, this._timeCurrent );
797
729
 
@@ -802,21 +734,18 @@
802
734
  }
803
735
 
804
736
  break;
805
-
806
737
  case STATE.SCALE:
807
738
  if ( this.enableZoom ) {
808
739
 
809
740
  if ( restart ) {
810
741
 
811
742
  //switch to zoom operation
743
+
812
744
  this.dispatchEvent( _endEvent );
813
745
  this.dispatchEvent( _startEvent );
814
746
  this.updateTbState( opState, true );
815
-
816
747
  this._startCursorPosition.setY( this.getCursorNDC( _center.x, _center.y, this.domElement ).y * 0.5 );
817
-
818
748
  this._currentCursorPosition.copy( this._startCursorPosition );
819
-
820
749
  if ( this.enableGrid ) {
821
750
 
822
751
  this.disposeGrid();
@@ -829,12 +758,9 @@
829
758
 
830
759
  //continue with zoom operation
831
760
  const screenNotches = 8; //how many wheel notches corresponds to a full screen pan
832
-
833
761
  this._currentCursorPosition.setY( this.getCursorNDC( _center.x, _center.y, this.domElement ).y * 0.5 );
834
-
835
762
  const movement = this._currentCursorPosition.y - this._startCursorPosition.y;
836
763
  let size = 1;
837
-
838
764
  if ( movement < 0 ) {
839
765
 
840
766
  size = 1 / Math.pow( this.scaleFactor, - movement * screenNotches );
@@ -846,7 +772,6 @@
846
772
  }
847
773
 
848
774
  this._v3_1.setFromMatrixPosition( this._gizmoMatrixState );
849
-
850
775
  this.applyTransformMatrix( this.scale( size, this._v3_1 ) );
851
776
 
852
777
  }
@@ -854,21 +779,18 @@
854
779
  }
855
780
 
856
781
  break;
857
-
858
782
  case STATE.FOV:
859
783
  if ( this.enableZoom && this.camera.isPerspectiveCamera ) {
860
784
 
861
785
  if ( restart ) {
862
786
 
863
787
  //switch to fov operation
788
+
864
789
  this.dispatchEvent( _endEvent );
865
790
  this.dispatchEvent( _startEvent );
866
791
  this.updateTbState( opState, true );
867
-
868
792
  this._startCursorPosition.setY( this.getCursorNDC( _center.x, _center.y, this.domElement ).y * 0.5 );
869
-
870
793
  this._currentCursorPosition.copy( this._startCursorPosition );
871
-
872
794
  if ( this.enableGrid ) {
873
795
 
874
796
  this.disposeGrid();
@@ -881,12 +803,9 @@
881
803
 
882
804
  //continue with fov operation
883
805
  const screenNotches = 8; //how many wheel notches corresponds to a full screen pan
884
-
885
806
  this._currentCursorPosition.setY( this.getCursorNDC( _center.x, _center.y, this.domElement ).y * 0.5 );
886
-
887
807
  const movement = this._currentCursorPosition.y - this._startCursorPosition.y;
888
808
  let size = 1;
889
-
890
809
  if ( movement < 0 ) {
891
810
 
892
811
  size = 1 / Math.pow( this.scaleFactor, - movement * screenNotches );
@@ -898,28 +817,26 @@
898
817
  }
899
818
 
900
819
  this._v3_1.setFromMatrixPosition( this._cameraMatrixState );
901
-
902
820
  const x = this._v3_1.distanceTo( this._gizmos.position );
903
-
904
821
  let xNew = x / size; //distance between camera and gizmos if scale(size, scalepoint) would be performed
905
- //check min and max distance
906
822
 
823
+ //check min and max distance
907
824
  xNew = THREE.MathUtils.clamp( xNew, this.minDistance, this.maxDistance );
908
- const y = x * Math.tan( THREE.MathUtils.DEG2RAD * this._fovState * 0.5 ); //calculate new fov
825
+ const y = x * Math.tan( THREE.MathUtils.DEG2RAD * this._fovState * 0.5 );
909
826
 
910
- let newFov = THREE.MathUtils.RAD2DEG * ( Math.atan( y / xNew ) * 2 ); //check min and max fov
827
+ //calculate new fov
828
+ let newFov = THREE.MathUtils.RAD2DEG * ( Math.atan( y / xNew ) * 2 );
911
829
 
830
+ //check min and max fov
912
831
  newFov = THREE.MathUtils.clamp( newFov, this.minFov, this.maxFov );
913
832
  const newDistance = y / Math.tan( THREE.MathUtils.DEG2RAD * ( newFov / 2 ) );
914
833
  size = x / newDistance;
915
-
916
834
  this._v3_2.setFromMatrixPosition( this._gizmoMatrixState );
917
-
918
835
  this.setFov( newFov );
919
- this.applyTransformMatrix( this.scale( size, this._v3_2, false ) ); //adjusting distance
836
+ this.applyTransformMatrix( this.scale( size, this._v3_2, false ) );
920
837
 
838
+ //adjusting distance
921
839
  _offset.copy( this._gizmos.position ).sub( this.camera.position ).normalize().multiplyScalar( newDistance / x );
922
-
923
840
  this._m4_1.makeTranslation( _offset.x, _offset.y, _offset.z );
924
841
 
925
842
  }
@@ -950,7 +867,6 @@
950
867
 
951
868
  //perform rotation animation
952
869
  const deltaTime = performance.now() - this._timeCurrent;
953
-
954
870
  if ( deltaTime < 120 ) {
955
871
 
956
872
  const w = Math.abs( ( this._wPrev + this._wCurr ) / 2 );
@@ -983,7 +899,6 @@
983
899
  } else if ( this._state == STATE.PAN || this._state == STATE.IDLE ) {
984
900
 
985
901
  this.updateTbState( STATE.IDLE, false );
986
-
987
902
  if ( this.enableGrid ) {
988
903
 
989
904
  this.disposeGrid();
@@ -1006,11 +921,9 @@
1006
921
  this.dispatchEvent( _startEvent );
1007
922
  this.setCenter( event.clientX, event.clientY );
1008
923
  const hitP = this.unprojectOnObj( this.getCursorNDC( _center.x, _center.y, this.domElement ), this.camera );
1009
-
1010
924
  if ( hitP != null && this.enableAnimations ) {
1011
925
 
1012
926
  const self = this;
1013
-
1014
927
  if ( this._animationId != - 1 ) {
1015
928
 
1016
929
  window.cancelAnimationFrame( this._animationId );
@@ -1047,11 +960,8 @@
1047
960
  this.dispatchEvent( _startEvent );
1048
961
  this.updateTbState( STATE.PAN, true );
1049
962
  this.setCenter( ( this._touchCurrent[ 0 ].clientX + this._touchCurrent[ 1 ].clientX ) / 2, ( this._touchCurrent[ 0 ].clientY + this._touchCurrent[ 1 ].clientY ) / 2 );
1050
-
1051
963
  this._startCursorPosition.copy( this.unprojectOnTbPlane( this.camera, _center.x, _center.y, this.domElement, true ) );
1052
-
1053
964
  this._currentCursorPosition.copy( this._startCursorPosition );
1054
-
1055
965
  this.activateGizmos( false );
1056
966
 
1057
967
  }
@@ -1063,17 +973,14 @@
1063
973
  if ( this.enabled && this.enablePan ) {
1064
974
 
1065
975
  this.setCenter( ( this._touchCurrent[ 0 ].clientX + this._touchCurrent[ 1 ].clientX ) / 2, ( this._touchCurrent[ 0 ].clientY + this._touchCurrent[ 1 ].clientY ) / 2 );
1066
-
1067
976
  if ( this._state != STATE.PAN ) {
1068
977
 
1069
978
  this.updateTbState( STATE.PAN, true );
1070
-
1071
979
  this._startCursorPosition.copy( this._currentCursorPosition );
1072
980
 
1073
981
  }
1074
982
 
1075
983
  this._currentCursorPosition.copy( this.unprojectOnTbPlane( this.camera, _center.x, _center.y, this.domElement, true ) );
1076
-
1077
984
  this.applyTransformMatrix( this.pan( this._startCursorPosition, this._currentCursorPosition, true ) );
1078
985
  this.dispatchEvent( _changeEvent );
1079
986
 
@@ -1093,7 +1000,9 @@
1093
1000
  if ( this.enabled && this.enableRotate ) {
1094
1001
 
1095
1002
  this.dispatchEvent( _startEvent );
1096
- this.updateTbState( STATE.ZROTATE, true ); //this._startFingerRotation = event.rotation;
1003
+ this.updateTbState( STATE.ZROTATE, true );
1004
+
1005
+ //this._startFingerRotation = event.rotation;
1097
1006
 
1098
1007
  this._startFingerRotation = this.getAngle( this._touchCurrent[ 1 ], this._touchCurrent[ 0 ] ) + this.getAngle( this._touchStart[ 1 ], this._touchStart[ 0 ] );
1099
1008
  this._currentFingerRotation = this._startFingerRotation;
@@ -1115,17 +1024,15 @@
1115
1024
 
1116
1025
  this.setCenter( ( this._touchCurrent[ 0 ].clientX + this._touchCurrent[ 1 ].clientX ) / 2, ( this._touchCurrent[ 0 ].clientY + this._touchCurrent[ 1 ].clientY ) / 2 );
1117
1026
  let rotationPoint;
1118
-
1119
1027
  if ( this._state != STATE.ZROTATE ) {
1120
1028
 
1121
1029
  this.updateTbState( STATE.ZROTATE, true );
1122
1030
  this._startFingerRotation = this._currentFingerRotation;
1123
1031
 
1124
- } //this._currentFingerRotation = event.rotation;
1125
-
1032
+ }
1126
1033
 
1034
+ //this._currentFingerRotation = event.rotation;
1127
1035
  this._currentFingerRotation = this.getAngle( this._touchCurrent[ 1 ], this._touchCurrent[ 0 ] ) + this.getAngle( this._touchStart[ 1 ], this._touchStart[ 0 ] );
1128
-
1129
1036
  if ( ! this.enablePan ) {
1130
1037
 
1131
1038
  rotationPoint = new THREE.Vector3().setFromMatrixPosition( this._gizmoMatrixState );
@@ -1133,7 +1040,6 @@
1133
1040
  } else {
1134
1041
 
1135
1042
  this._v3_2.setFromMatrixPosition( this._gizmoMatrixState );
1136
-
1137
1043
  rotationPoint = this.unprojectOnTbPlane( this.camera, _center.x, _center.y, this.domElement ).applyQuaternion( this.camera.quaternion ).multiplyScalar( 1 / this.camera.zoom ).add( this._v3_2 );
1138
1044
 
1139
1045
  }
@@ -1185,7 +1091,6 @@
1185
1091
  this._currentFingerDistance = Math.max( this.calculatePointersDistance( this._touchCurrent[ 0 ], this._touchCurrent[ 1 ] ), minDistance * this._devPxRatio );
1186
1092
  const amount = this._currentFingerDistance / this._startFingerDistance;
1187
1093
  let scalePoint;
1188
-
1189
1094
  if ( ! this.enablePan ) {
1190
1095
 
1191
1096
  scalePoint = this._gizmos.position;
@@ -1223,12 +1128,12 @@
1223
1128
  if ( this.enabled && this.enableZoom ) {
1224
1129
 
1225
1130
  this.dispatchEvent( _startEvent );
1226
- this.updateTbState( STATE.SCALE, true ); //const center = event.center;
1131
+ this.updateTbState( STATE.SCALE, true );
1227
1132
 
1133
+ //const center = event.center;
1228
1134
  let clientX = 0;
1229
1135
  let clientY = 0;
1230
1136
  const nFingers = this._touchCurrent.length;
1231
-
1232
1137
  for ( let i = 0; i < nFingers; i ++ ) {
1233
1138
 
1234
1139
  clientX += this._touchCurrent[ i ].clientX;
@@ -1237,9 +1142,7 @@
1237
1142
  }
1238
1143
 
1239
1144
  this.setCenter( clientX / nFingers, clientY / nFingers );
1240
-
1241
1145
  this._startCursorPosition.setY( this.getCursorNDC( _center.x, _center.y, this.domElement ).y * 0.5 );
1242
-
1243
1146
  this._currentCursorPosition.copy( this._startCursorPosition );
1244
1147
 
1245
1148
  }
@@ -1259,11 +1162,11 @@
1259
1162
  // | \
1260
1163
  // | _ _ _\
1261
1164
  // y
1165
+
1262
1166
  //const center = event.center;
1263
1167
  let clientX = 0;
1264
1168
  let clientY = 0;
1265
1169
  const nFingers = this._touchCurrent.length;
1266
-
1267
1170
  for ( let i = 0; i < nFingers; i ++ ) {
1268
1171
 
1269
1172
  clientX += this._touchCurrent[ i ].clientX;
@@ -1273,12 +1176,9 @@
1273
1176
 
1274
1177
  this.setCenter( clientX / nFingers, clientY / nFingers );
1275
1178
  const screenNotches = 8; //how many wheel notches corresponds to a full screen pan
1276
-
1277
1179
  this._currentCursorPosition.setY( this.getCursorNDC( _center.x, _center.y, this.domElement ).y * 0.5 );
1278
-
1279
1180
  const movement = this._currentCursorPosition.y - this._startCursorPosition.y;
1280
1181
  let size = 1;
1281
-
1282
1182
  if ( movement < 0 ) {
1283
1183
 
1284
1184
  size = 1 / Math.pow( this.scaleFactor, - movement * screenNotches );
@@ -1290,30 +1190,27 @@
1290
1190
  }
1291
1191
 
1292
1192
  this._v3_1.setFromMatrixPosition( this._cameraMatrixState );
1293
-
1294
1193
  const x = this._v3_1.distanceTo( this._gizmos.position );
1295
-
1296
1194
  let xNew = x / size; //distance between camera and gizmos if scale(size, scalepoint) would be performed
1297
- //check min and max distance
1298
1195
 
1196
+ //check min and max distance
1299
1197
  xNew = THREE.MathUtils.clamp( xNew, this.minDistance, this.maxDistance );
1300
- const y = x * Math.tan( THREE.MathUtils.DEG2RAD * this._fovState * 0.5 ); //calculate new fov
1198
+ const y = x * Math.tan( THREE.MathUtils.DEG2RAD * this._fovState * 0.5 );
1301
1199
 
1302
- let newFov = THREE.MathUtils.RAD2DEG * ( Math.atan( y / xNew ) * 2 ); //check min and max fov
1200
+ //calculate new fov
1201
+ let newFov = THREE.MathUtils.RAD2DEG * ( Math.atan( y / xNew ) * 2 );
1303
1202
 
1203
+ //check min and max fov
1304
1204
  newFov = THREE.MathUtils.clamp( newFov, this.minFov, this.maxFov );
1305
1205
  const newDistance = y / Math.tan( THREE.MathUtils.DEG2RAD * ( newFov / 2 ) );
1306
1206
  size = x / newDistance;
1307
-
1308
1207
  this._v3_2.setFromMatrixPosition( this._gizmoMatrixState );
1309
-
1310
1208
  this.setFov( newFov );
1311
- this.applyTransformMatrix( this.scale( size, this._v3_2, false ) ); //adjusting distance
1209
+ this.applyTransformMatrix( this.scale( size, this._v3_2, false ) );
1312
1210
 
1211
+ //adjusting distance
1313
1212
  _offset.copy( this._gizmos.position ).sub( this.camera.position ).normalize().multiplyScalar( newDistance / x );
1314
-
1315
1213
  this._m4_1.makeTranslation( _offset.x, _offset.y, _offset.z );
1316
-
1317
1214
  this.dispatchEvent( _changeEvent );
1318
1215
 
1319
1216
  }
@@ -1323,7 +1220,8 @@
1323
1220
  this.onTriplePanEnd = () => {
1324
1221
 
1325
1222
  this.updateTbState( STATE.IDLE, false );
1326
- this.dispatchEvent( _endEvent ); //this.dispatchEvent( _changeEvent );
1223
+ this.dispatchEvent( _endEvent );
1224
+ //this.dispatchEvent( _changeEvent );
1327
1225
 
1328
1226
  };
1329
1227
 
@@ -1374,7 +1272,6 @@
1374
1272
  const mouseInput = [ 0, 1, 2, 'WHEEL' ];
1375
1273
  const keyInput = [ 'CTRL', 'SHIFT', null ];
1376
1274
  let state;
1377
-
1378
1275
  if ( ! operationInput.includes( operation ) || ! mouseInput.includes( mouse ) || ! keyInput.includes( key ) ) {
1379
1276
 
1380
1277
  //invalid parameters
@@ -1398,15 +1295,12 @@
1398
1295
  case 'PAN':
1399
1296
  state = STATE.PAN;
1400
1297
  break;
1401
-
1402
1298
  case 'ROTATE':
1403
1299
  state = STATE.ROTATE;
1404
1300
  break;
1405
-
1406
1301
  case 'ZOOM':
1407
1302
  state = STATE.SCALE;
1408
1303
  break;
1409
-
1410
1304
  case 'FOV':
1411
1305
  state = STATE.FOV;
1412
1306
  break;
@@ -1419,7 +1313,6 @@
1419
1313
  key: key,
1420
1314
  state: state
1421
1315
  };
1422
-
1423
1316
  for ( let i = 0; i < this.mouseActions.length; i ++ ) {
1424
1317
 
1425
1318
  if ( this.mouseActions[ i ].mouse == action.mouse && this.mouseActions[ i ].key == action.key ) {
@@ -1456,11 +1349,9 @@
1456
1349
  this.getOpFromAction = ( mouse, key ) => {
1457
1350
 
1458
1351
  let action;
1459
-
1460
1352
  for ( let i = 0; i < this.mouseActions.length; i ++ ) {
1461
1353
 
1462
1354
  action = this.mouseActions[ i ];
1463
-
1464
1355
  if ( action.mouse == mouse && action.key == key ) {
1465
1356
 
1466
1357
  return action.operation;
@@ -1474,7 +1365,6 @@
1474
1365
  for ( let i = 0; i < this.mouseActions.length; i ++ ) {
1475
1366
 
1476
1367
  action = this.mouseActions[ i ];
1477
-
1478
1368
  if ( action.mouse == mouse && action.key == null ) {
1479
1369
 
1480
1370
  return action.operation;
@@ -1492,11 +1382,9 @@
1492
1382
  this.getOpStateFromAction = ( mouse, key ) => {
1493
1383
 
1494
1384
  let action;
1495
-
1496
1385
  for ( let i = 0; i < this.mouseActions.length; i ++ ) {
1497
1386
 
1498
1387
  action = this.mouseActions[ i ];
1499
-
1500
1388
  if ( action.mouse == mouse && action.key == key ) {
1501
1389
 
1502
1390
  return action.state;
@@ -1510,7 +1398,6 @@
1510
1398
  for ( let i = 0; i < this.mouseActions.length; i ++ ) {
1511
1399
 
1512
1400
  action = this.mouseActions[ i ];
1513
-
1514
1401
  if ( action.mouse == mouse && action.key == null ) {
1515
1402
 
1516
1403
  return action.state;
@@ -1538,7 +1425,6 @@
1538
1425
  if ( this._touchCurrent[ i ].pointerId == event.pointerId ) {
1539
1426
 
1540
1427
  this._touchCurrent.splice( i, 1, event );
1541
-
1542
1428
  break;
1543
1429
 
1544
1430
  }
@@ -1551,7 +1437,6 @@
1551
1437
 
1552
1438
  const s = p1 - p0;
1553
1439
  const t = ( t1 - t0 ) / 1000;
1554
-
1555
1440
  if ( t == 0 ) {
1556
1441
 
1557
1442
  return 0;
@@ -1571,11 +1456,8 @@
1571
1456
  this.calculateRotationAxis = ( vec1, vec2 ) => {
1572
1457
 
1573
1458
  this._rotationMatrix.extractRotation( this._cameraMatrixState );
1574
-
1575
1459
  this._quat.setFromRotationMatrix( this._rotationMatrix );
1576
-
1577
1460
  this._rotationAxis.crossVectors( vec1, vec2 ).applyQuaternion( this._quat );
1578
-
1579
1461
  return this._rotationAxis.normalize().clone();
1580
1462
 
1581
1463
  };
@@ -1583,13 +1465,10 @@
1583
1465
  this.calculateTbRadius = camera => {
1584
1466
 
1585
1467
  const distance = camera.position.distanceTo( this._gizmos.position );
1586
-
1587
1468
  if ( camera.type == 'PerspectiveCamera' ) {
1588
1469
 
1589
1470
  const halfFovV = THREE.MathUtils.DEG2RAD * camera.fov * 0.5; //vertical fov/2 in radians
1590
-
1591
1471
  const halfFovH = Math.atan( camera.aspect * Math.tan( halfFovV ) ); //horizontal fov/2 in radians
1592
-
1593
1472
  return Math.tan( Math.min( halfFovV, halfFovH ) ) * distance * this.radiusFactor;
1594
1473
 
1595
1474
  } else if ( camera.type == 'OrthographicCamera' ) {
@@ -1604,22 +1483,15 @@
1604
1483
 
1605
1484
  //move center of camera (along with gizmos) towards point of interest
1606
1485
  _offset.copy( point ).sub( this._gizmos.position ).multiplyScalar( amount );
1607
-
1608
1486
  this._translationMatrix.makeTranslation( _offset.x, _offset.y, _offset.z );
1609
-
1610
1487
  _gizmoMatrixStateTemp.copy( this._gizmoMatrixState );
1611
-
1612
1488
  this._gizmoMatrixState.premultiply( this._translationMatrix );
1613
-
1614
1489
  this._gizmoMatrixState.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale );
1615
-
1616
1490
  _cameraMatrixStateTemp.copy( this._cameraMatrixState );
1617
-
1618
1491
  this._cameraMatrixState.premultiply( this._translationMatrix );
1492
+ this._cameraMatrixState.decompose( this.camera.position, this.camera.quaternion, this.camera.scale );
1619
1493
 
1620
- this._cameraMatrixState.decompose( this.camera.position, this.camera.quaternion, this.camera.scale ); //apply zoom
1621
-
1622
-
1494
+ //apply zoom
1623
1495
  if ( this.enableZoom ) {
1624
1496
 
1625
1497
  this.applyTransformMatrix( this.scale( size, this._gizmos.position ) );
@@ -1627,7 +1499,6 @@
1627
1499
  }
1628
1500
 
1629
1501
  this._gizmoMatrixState.copy( _gizmoMatrixStateTemp );
1630
-
1631
1502
  this._cameraMatrixState.copy( _cameraMatrixStateTemp );
1632
1503
 
1633
1504
  };
@@ -1639,7 +1510,6 @@
1639
1510
  const color = 0x888888;
1640
1511
  const multiplier = 3;
1641
1512
  let size, divisions, maxLength, tick;
1642
-
1643
1513
  if ( this.camera.isOrthographicCamera ) {
1644
1514
 
1645
1515
  const width = this.camera.right - this.camera.left;
@@ -1664,15 +1534,10 @@
1664
1534
  if ( this._grid == null ) {
1665
1535
 
1666
1536
  this._grid = new THREE.GridHelper( size, divisions, color, color );
1667
-
1668
1537
  this._grid.position.copy( this._gizmos.position );
1669
-
1670
1538
  this._gridPosition.copy( this._grid.position );
1671
-
1672
1539
  this._grid.quaternion.copy( this.camera.quaternion );
1673
-
1674
1540
  this._grid.rotateX( Math.PI * 0.5 );
1675
-
1676
1541
  this.scene.add( this._grid );
1677
1542
 
1678
1543
  }
@@ -1723,7 +1588,6 @@
1723
1588
  const gizmoX = this._gizmos.children[ 0 ];
1724
1589
  const gizmoY = this._gizmos.children[ 1 ];
1725
1590
  const gizmoZ = this._gizmos.children[ 2 ];
1726
-
1727
1591
  if ( isActive ) {
1728
1592
 
1729
1593
  gizmoX.material.setValues( {
@@ -1755,11 +1619,8 @@
1755
1619
  this.getCursorNDC = ( cursorX, cursorY, canvas ) => {
1756
1620
 
1757
1621
  const canvasRect = canvas.getBoundingClientRect();
1758
-
1759
1622
  this._v2_1.setX( ( cursorX - canvasRect.left ) / canvasRect.width * 2 - 1 );
1760
-
1761
1623
  this._v2_1.setY( ( canvasRect.bottom - cursorY ) / canvasRect.height * 2 - 1 );
1762
-
1763
1624
  return this._v2_1.clone();
1764
1625
 
1765
1626
  };
@@ -1767,7 +1628,6 @@
1767
1628
  this.getCursorPosition = ( cursorX, cursorY, canvas ) => {
1768
1629
 
1769
1630
  this._v2_1.copy( this.getCursorNDC( cursorX, cursorY, canvas ) );
1770
-
1771
1631
  this._v2_1.x *= ( this.camera.right - this.camera.left ) * 0.5;
1772
1632
  this._v2_1.y *= ( this.camera.top - this.camera.bottom ) * 0.5;
1773
1633
  return this._v2_1.clone();
@@ -1777,8 +1637,9 @@
1777
1637
  this.setCamera = camera => {
1778
1638
 
1779
1639
  camera.lookAt( this.target );
1780
- camera.updateMatrix(); //setting state
1640
+ camera.updateMatrix();
1781
1641
 
1642
+ //setting state
1782
1643
  if ( camera.type == 'PerspectiveCamera' ) {
1783
1644
 
1784
1645
  this._fov0 = camera.fov;
@@ -1787,11 +1648,8 @@
1787
1648
  }
1788
1649
 
1789
1650
  this._cameraMatrixState0.copy( camera.matrix );
1790
-
1791
1651
  this._cameraMatrixState.copy( this._cameraMatrixState0 );
1792
-
1793
1652
  this._cameraProjectionState.copy( camera.projectionMatrix );
1794
-
1795
1653
  this._zoom0 = camera.zoom;
1796
1654
  this._zoomState = this._zoom0;
1797
1655
  this._initialNear = camera.near;
@@ -1800,14 +1658,12 @@
1800
1658
  this._initialFar = camera.far;
1801
1659
  this._farPos0 = camera.position.distanceTo( this.target ) - camera.far;
1802
1660
  this._farPos = this._initialFar;
1803
-
1804
1661
  this._up0.copy( camera.up );
1805
-
1806
1662
  this._upState.copy( camera.up );
1807
-
1808
1663
  this.camera = camera;
1809
- this.camera.updateProjectionMatrix(); //making gizmos
1664
+ this.camera.updateProjectionMatrix();
1810
1665
 
1666
+ //making gizmos
1811
1667
  this._tbRadius = this.calculateTbRadius( camera );
1812
1668
  this.makeGizmos( this.target, this._tbRadius );
1813
1669
 
@@ -1816,10 +1672,12 @@
1816
1672
  this.makeGizmos = ( tbCenter, tbRadius ) => {
1817
1673
 
1818
1674
  const curve = new THREE.EllipseCurve( 0, 0, tbRadius, tbRadius );
1819
- const points = curve.getPoints( this._curvePts ); //geometry
1675
+ const points = curve.getPoints( this._curvePts );
1820
1676
 
1821
- const curveGeometry = new THREE.BufferGeometry().setFromPoints( points ); //material
1677
+ //geometry
1678
+ const curveGeometry = new THREE.BufferGeometry().setFromPoints( points );
1822
1679
 
1680
+ //material
1823
1681
  const curveMaterialX = new THREE.LineBasicMaterial( {
1824
1682
  color: 0xff8080,
1825
1683
  fog: false,
@@ -1837,38 +1695,34 @@
1837
1695
  fog: false,
1838
1696
  transparent: true,
1839
1697
  opacity: 0.6
1840
- } ); //line
1698
+ } );
1841
1699
 
1700
+ //line
1842
1701
  const gizmoX = new THREE.Line( curveGeometry, curveMaterialX );
1843
1702
  const gizmoY = new THREE.Line( curveGeometry, curveMaterialY );
1844
1703
  const gizmoZ = new THREE.Line( curveGeometry, curveMaterialZ );
1845
1704
  const rotation = Math.PI * 0.5;
1846
1705
  gizmoX.rotation.x = rotation;
1847
- gizmoY.rotation.y = rotation; //setting state
1706
+ gizmoY.rotation.y = rotation;
1848
1707
 
1708
+ //setting state
1849
1709
  this._gizmoMatrixState0.identity().setPosition( tbCenter );
1850
-
1851
1710
  this._gizmoMatrixState.copy( this._gizmoMatrixState0 );
1852
-
1853
1711
  if ( this.camera.zoom !== 1 ) {
1854
1712
 
1855
1713
  //adapt gizmos size to camera zoom
1856
1714
  const size = 1 / this.camera.zoom;
1857
-
1858
1715
  this._scaleMatrix.makeScale( size, size, size );
1859
-
1860
1716
  this._translationMatrix.makeTranslation( - tbCenter.x, - tbCenter.y, - tbCenter.z );
1861
-
1862
1717
  this._gizmoMatrixState.premultiply( this._translationMatrix ).premultiply( this._scaleMatrix );
1863
-
1864
1718
  this._translationMatrix.makeTranslation( tbCenter.x, tbCenter.y, tbCenter.z );
1865
-
1866
1719
  this._gizmoMatrixState.premultiply( this._translationMatrix );
1867
1720
 
1868
1721
  }
1869
1722
 
1870
- this._gizmoMatrixState.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale ); //
1723
+ this._gizmoMatrixState.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale );
1871
1724
 
1725
+ //
1872
1726
 
1873
1727
  this._gizmos.traverse( function ( object ) {
1874
1728
 
@@ -1880,14 +1734,12 @@
1880
1734
  }
1881
1735
 
1882
1736
  } );
1737
+ this._gizmos.clear();
1883
1738
 
1884
- this._gizmos.clear(); //
1885
-
1739
+ //
1886
1740
 
1887
1741
  this._gizmos.add( gizmoX );
1888
-
1889
1742
  this._gizmos.add( gizmoY );
1890
-
1891
1743
  this._gizmos.add( gizmoZ );
1892
1744
 
1893
1745
  };
@@ -1905,14 +1757,12 @@
1905
1757
 
1906
1758
  const deltaTime = time - this._timeStart;
1907
1759
  const animTime = deltaTime / this.focusAnimationTime;
1908
-
1909
1760
  this._gizmoMatrixState.copy( gizmoMatrix );
1910
-
1911
1761
  if ( animTime >= 1 ) {
1912
1762
 
1913
1763
  //animation end
1914
- this._gizmoMatrixState.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale );
1915
1764
 
1765
+ this._gizmoMatrixState.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale );
1916
1766
  this.focus( point, this.scaleFactor );
1917
1767
  this._timeStart = - 1;
1918
1768
  this.updateTbState( STATE.IDLE, false );
@@ -1923,9 +1773,7 @@
1923
1773
 
1924
1774
  const amount = this.easeOutCubic( animTime );
1925
1775
  const size = 1 - amount + this.scaleFactor * amount;
1926
-
1927
1776
  this._gizmoMatrixState.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale );
1928
-
1929
1777
  this.focus( point, size, amount );
1930
1778
  this.dispatchEvent( _changeEvent );
1931
1779
  const self = this;
@@ -1940,6 +1788,7 @@
1940
1788
  } else {
1941
1789
 
1942
1790
  //interrupt animation
1791
+
1943
1792
  this._animationId = - 1;
1944
1793
  this._timeStart = - 1;
1945
1794
 
@@ -1963,7 +1812,6 @@
1963
1812
  //w = w0 + alpha * t
1964
1813
  const deltaTime = ( time - this._timeStart ) / 1000;
1965
1814
  const w = w0 + - this.dampingFactor * deltaTime;
1966
-
1967
1815
  if ( w > 0 ) {
1968
1816
 
1969
1817
  //tetha = 0.5 * alpha * t^2 + w0 * t + tetha0
@@ -1990,9 +1838,9 @@
1990
1838
  } else {
1991
1839
 
1992
1840
  //interrupt animation
1841
+
1993
1842
  this._animationId = - 1;
1994
1843
  this._timeStart = - 1;
1995
-
1996
1844
  if ( this._state != STATE.ROTATE ) {
1997
1845
 
1998
1846
  this.activateGizmos( false );
@@ -2007,7 +1855,6 @@
2007
1855
  this.pan = ( p0, p1, adjust = false ) => {
2008
1856
 
2009
1857
  const movement = p0.clone().sub( p1 );
2010
-
2011
1858
  if ( this.camera.isOrthographicCamera ) {
2012
1859
 
2013
1860
  //adjust movement amount
@@ -2017,20 +1864,14 @@
2017
1864
 
2018
1865
  //adjust movement amount
2019
1866
  this._v3_1.setFromMatrixPosition( this._cameraMatrixState0 ); //camera's initial position
2020
-
2021
-
2022
1867
  this._v3_2.setFromMatrixPosition( this._gizmoMatrixState0 ); //gizmo's initial position
2023
-
2024
-
2025
1868
  const distanceFactor = this._v3_1.distanceTo( this._v3_2 ) / this.camera.position.distanceTo( this._gizmos.position );
2026
1869
  movement.multiplyScalar( 1 / distanceFactor );
2027
1870
 
2028
1871
  }
2029
1872
 
2030
1873
  this._v3_1.set( movement.x, movement.y, 0 ).applyQuaternion( this.camera.quaternion );
2031
-
2032
1874
  this._m4_1.makeTranslation( this._v3_1.x, this._v3_1.y, this._v3_1.z );
2033
-
2034
1875
  this.setTransformationMatrices( this._m4_1, this._m4_1 );
2035
1876
  return _transformation;
2036
1877
 
@@ -2039,7 +1880,6 @@
2039
1880
  this.reset = () => {
2040
1881
 
2041
1882
  this.camera.zoom = this._zoom0;
2042
-
2043
1883
  if ( this.camera.isPerspectiveCamera ) {
2044
1884
 
2045
1885
  this.camera.fov = this._fov0;
@@ -2048,21 +1888,14 @@
2048
1888
 
2049
1889
  this.camera.near = this._nearPos;
2050
1890
  this.camera.far = this._farPos;
2051
-
2052
1891
  this._cameraMatrixState.copy( this._cameraMatrixState0 );
2053
-
2054
1892
  this._cameraMatrixState.decompose( this.camera.position, this.camera.quaternion, this.camera.scale );
2055
-
2056
1893
  this.camera.up.copy( this._up0 );
2057
1894
  this.camera.updateMatrix();
2058
1895
  this.camera.updateProjectionMatrix();
2059
-
2060
1896
  this._gizmoMatrixState.copy( this._gizmoMatrixState0 );
2061
-
2062
1897
  this._gizmoMatrixState0.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale );
2063
-
2064
1898
  this._gizmos.updateMatrix();
2065
-
2066
1899
  this._tbRadius = this.calculateTbRadius( this.camera );
2067
1900
  this.makeGizmos( this._gizmos.position, this._tbRadius );
2068
1901
  this.camera.lookAt( this._gizmos.position );
@@ -2074,18 +1907,13 @@
2074
1907
  this.rotate = ( axis, angle ) => {
2075
1908
 
2076
1909
  const point = this._gizmos.position; //rotation center
2077
-
2078
1910
  this._translationMatrix.makeTranslation( - point.x, - point.y, - point.z );
1911
+ this._rotationMatrix.makeRotationAxis( axis, - angle );
2079
1912
 
2080
- this._rotationMatrix.makeRotationAxis( axis, - angle ); //rotate camera
2081
-
2082
-
1913
+ //rotate camera
2083
1914
  this._m4_1.makeTranslation( point.x, point.y, point.z );
2084
-
2085
1915
  this._m4_1.multiply( this._rotationMatrix );
2086
-
2087
1916
  this._m4_1.multiply( this._translationMatrix );
2088
-
2089
1917
  this.setTransformationMatrices( this._m4_1 );
2090
1918
  return _transformation;
2091
1919
 
@@ -2094,7 +1922,6 @@
2094
1922
  this.copyState = () => {
2095
1923
 
2096
1924
  let state;
2097
-
2098
1925
  if ( this.camera.isOrthographicCamera ) {
2099
1926
 
2100
1927
  state = JSON.stringify( {
@@ -2142,15 +1969,11 @@
2142
1969
  this.saveState = () => {
2143
1970
 
2144
1971
  this._cameraMatrixState0.copy( this.camera.matrix );
2145
-
2146
1972
  this._gizmoMatrixState0.copy( this._gizmos.matrix );
2147
-
2148
1973
  this._nearPos = this.camera.near;
2149
1974
  this._farPos = this.camera.far;
2150
1975
  this._zoom0 = this.camera.zoom;
2151
-
2152
1976
  this._up0.copy( this.camera.up );
2153
-
2154
1977
  if ( this.camera.isPerspectiveCamera ) {
2155
1978
 
2156
1979
  this._fov0 = this.camera.fov;
@@ -2162,15 +1985,14 @@
2162
1985
  this.scale = ( size, point, scaleGizmos = true ) => {
2163
1986
 
2164
1987
  _scalePointTemp.copy( point );
2165
-
2166
1988
  let sizeInverse = 1 / size;
2167
-
2168
1989
  if ( this.camera.isOrthographicCamera ) {
2169
1990
 
2170
1991
  //camera zoom
2171
1992
  this.camera.zoom = this._zoomState;
2172
- this.camera.zoom *= size; //check min and max zoom
1993
+ this.camera.zoom *= size;
2173
1994
 
1995
+ //check min and max zoom
2174
1996
  if ( this.camera.zoom > this.maxZoom ) {
2175
1997
 
2176
1998
  this.camera.zoom = this.maxZoom;
@@ -2184,46 +2006,34 @@
2184
2006
  }
2185
2007
 
2186
2008
  this.camera.updateProjectionMatrix();
2187
-
2188
2009
  this._v3_1.setFromMatrixPosition( this._gizmoMatrixState ); //gizmos position
2189
- //scale gizmos so they appear in the same spot having the same dimension
2190
-
2191
2010
 
2011
+ //scale gizmos so they appear in the same spot having the same dimension
2192
2012
  this._scaleMatrix.makeScale( sizeInverse, sizeInverse, sizeInverse );
2193
-
2194
2013
  this._translationMatrix.makeTranslation( - this._v3_1.x, - this._v3_1.y, - this._v3_1.z );
2195
-
2196
2014
  this._m4_2.makeTranslation( this._v3_1.x, this._v3_1.y, this._v3_1.z ).multiply( this._scaleMatrix );
2015
+ this._m4_2.multiply( this._translationMatrix );
2197
2016
 
2198
- this._m4_2.multiply( this._translationMatrix ); //move camera and gizmos to obtain pinch effect
2199
-
2200
-
2017
+ //move camera and gizmos to obtain pinch effect
2201
2018
  _scalePointTemp.sub( this._v3_1 );
2202
-
2203
2019
  const amount = _scalePointTemp.clone().multiplyScalar( sizeInverse );
2204
-
2205
2020
  _scalePointTemp.sub( amount );
2206
-
2207
2021
  this._m4_1.makeTranslation( _scalePointTemp.x, _scalePointTemp.y, _scalePointTemp.z );
2208
-
2209
2022
  this._m4_2.premultiply( this._m4_1 );
2210
-
2211
2023
  this.setTransformationMatrices( this._m4_1, this._m4_2 );
2212
2024
  return _transformation;
2213
2025
 
2214
2026
  } else if ( this.camera.isPerspectiveCamera ) {
2215
2027
 
2216
2028
  this._v3_1.setFromMatrixPosition( this._cameraMatrixState );
2029
+ this._v3_2.setFromMatrixPosition( this._gizmoMatrixState );
2217
2030
 
2218
- this._v3_2.setFromMatrixPosition( this._gizmoMatrixState ); //move camera
2219
-
2220
-
2031
+ //move camera
2221
2032
  let distance = this._v3_1.distanceTo( _scalePointTemp );
2033
+ let amount = distance - distance * sizeInverse;
2222
2034
 
2223
- let amount = distance - distance * sizeInverse; //check min and max distance
2224
-
2035
+ //check min and max distance
2225
2036
  const newDistance = distance - amount;
2226
-
2227
2037
  if ( newDistance < this.minDistance ) {
2228
2038
 
2229
2039
  sizeInverse = this.minDistance / distance;
@@ -2237,30 +2047,20 @@
2237
2047
  }
2238
2048
 
2239
2049
  _offset.copy( _scalePointTemp ).sub( this._v3_1 ).normalize().multiplyScalar( amount );
2240
-
2241
2050
  this._m4_1.makeTranslation( _offset.x, _offset.y, _offset.z );
2242
-
2243
2051
  if ( scaleGizmos ) {
2244
2052
 
2245
2053
  //scale gizmos so they appear in the same spot having the same dimension
2246
2054
  const pos = this._v3_2;
2247
2055
  distance = pos.distanceTo( _scalePointTemp );
2248
2056
  amount = distance - distance * sizeInverse;
2249
-
2250
2057
  _offset.copy( _scalePointTemp ).sub( this._v3_2 ).normalize().multiplyScalar( amount );
2251
-
2252
2058
  this._translationMatrix.makeTranslation( pos.x, pos.y, pos.z );
2253
-
2254
2059
  this._scaleMatrix.makeScale( sizeInverse, sizeInverse, sizeInverse );
2255
-
2256
2060
  this._m4_2.makeTranslation( _offset.x, _offset.y, _offset.z ).multiply( this._translationMatrix );
2257
-
2258
2061
  this._m4_2.multiply( this._scaleMatrix );
2259
-
2260
2062
  this._translationMatrix.makeTranslation( - pos.x, - pos.y, - pos.z );
2261
-
2262
2063
  this._m4_2.multiply( this._translationMatrix );
2263
-
2264
2064
  this.setTransformationMatrices( this._m4_1, this._m4_2 );
2265
2065
 
2266
2066
  } else {
@@ -2289,25 +2089,14 @@
2289
2089
  this.zRotate = ( point, angle ) => {
2290
2090
 
2291
2091
  this._rotationMatrix.makeRotationAxis( this._rotationAxis, angle );
2292
-
2293
2092
  this._translationMatrix.makeTranslation( - point.x, - point.y, - point.z );
2294
-
2295
2093
  this._m4_1.makeTranslation( point.x, point.y, point.z );
2296
-
2297
2094
  this._m4_1.multiply( this._rotationMatrix );
2298
-
2299
2095
  this._m4_1.multiply( this._translationMatrix );
2300
-
2301
2096
  this._v3_1.setFromMatrixPosition( this._gizmoMatrixState ).sub( point ); //vector from rotation center to gizmos position
2302
-
2303
-
2304
2097
  this._v3_2.copy( this._v3_1 ).applyAxisAngle( this._rotationAxis, angle ); //apply rotation
2305
-
2306
-
2307
2098
  this._v3_2.sub( this._v3_1 );
2308
-
2309
2099
  this._m4_2.makeTranslation( this._v3_2.x, this._v3_2.y, this._v3_2.z );
2310
-
2311
2100
  this.setTransformationMatrices( this._m4_1, this._m4_2 );
2312
2101
  return _transformation;
2313
2102
 
@@ -2320,7 +2109,6 @@
2320
2109
  raycaster.far = camera.far;
2321
2110
  raycaster.setFromCamera( cursor, camera );
2322
2111
  const intersect = raycaster.intersectObjects( this.scene.children, true );
2323
-
2324
2112
  for ( let i = 0; i < intersect.length; i ++ ) {
2325
2113
 
2326
2114
  if ( intersect[ i ].object.uuid != this._gizmos.uuid && intersect[ i ].face != null ) {
@@ -2340,13 +2128,10 @@
2340
2128
  if ( camera.type == 'OrthographicCamera' ) {
2341
2129
 
2342
2130
  this._v2_1.copy( this.getCursorPosition( cursorX, cursorY, canvas ) );
2343
-
2344
2131
  this._v3_1.set( this._v2_1.x, this._v2_1.y, 0 );
2345
-
2346
2132
  const x2 = Math.pow( this._v2_1.x, 2 );
2347
2133
  const y2 = Math.pow( this._v2_1.y, 2 );
2348
2134
  const r2 = Math.pow( this._tbRadius, 2 );
2349
-
2350
2135
  if ( x2 + y2 <= r2 * 0.5 ) {
2351
2136
 
2352
2137
  //intersection with sphere
@@ -2365,16 +2150,13 @@
2365
2150
 
2366
2151
  //unproject cursor on the near plane
2367
2152
  this._v2_1.copy( this.getCursorNDC( cursorX, cursorY, canvas ) );
2368
-
2369
2153
  this._v3_1.set( this._v2_1.x, this._v2_1.y, - 1 );
2370
-
2371
2154
  this._v3_1.applyMatrix4( camera.projectionMatrixInverse );
2372
-
2373
2155
  const rayDir = this._v3_1.clone().normalize(); //unprojected ray direction
2374
-
2375
-
2376
2156
  const cameraGizmoDistance = camera.position.distanceTo( this._gizmos.position );
2377
- const radius2 = Math.pow( tbRadius, 2 ); // camera
2157
+ const radius2 = Math.pow( tbRadius, 2 );
2158
+
2159
+ // camera
2378
2160
  // |\
2379
2161
  // | \
2380
2162
  // | \
@@ -2386,7 +2168,6 @@
2386
2168
 
2387
2169
  const h = this._v3_1.z;
2388
2170
  const l = Math.sqrt( Math.pow( this._v3_1.x, 2 ) + Math.pow( this._v3_1.y, 2 ) );
2389
-
2390
2171
  if ( l == 0 ) {
2391
2172
 
2392
2173
  //ray aligned with camera
@@ -2397,6 +2178,7 @@
2397
2178
 
2398
2179
  const m = h / l;
2399
2180
  const q = cameraGizmoDistance;
2181
+
2400
2182
  /*
2401
2183
  * calculate intersection point between unprojected ray and trackball surface
2402
2184
  *|y = m * x + q
@@ -2404,25 +2186,21 @@
2404
2186
  *
2405
2187
  * (m^2 + 1) * x^2 + (2 * m * q) * x + q^2 - r^2 = 0
2406
2188
  */
2407
-
2408
2189
  let a = Math.pow( m, 2 ) + 1;
2409
2190
  let b = 2 * m * q;
2410
2191
  let c = Math.pow( q, 2 ) - radius2;
2411
2192
  let delta = Math.pow( b, 2 ) - 4 * a * c;
2412
-
2413
2193
  if ( delta >= 0 ) {
2414
2194
 
2415
2195
  //intersection with sphere
2416
2196
  this._v2_1.setX( ( - b - Math.sqrt( delta ) ) / ( 2 * a ) );
2417
-
2418
2197
  this._v2_1.setY( m * this._v2_1.x + q );
2419
-
2420
2198
  const angle = THREE.MathUtils.RAD2DEG * this._v2_1.angle();
2421
-
2422
2199
  if ( angle >= 45 ) {
2423
2200
 
2424
2201
  //if angle between intersection point and X' axis is >= 45°, return that point
2425
2202
  //otherwise, calculate intersection point with hyperboloid
2203
+
2426
2204
  const rayLength = Math.sqrt( Math.pow( this._v2_1.x, 2 ) + Math.pow( cameraGizmoDistance - this._v2_1.y, 2 ) );
2427
2205
  rayDir.multiplyScalar( rayLength );
2428
2206
  rayDir.z += cameraGizmoDistance;
@@ -2430,8 +2208,9 @@
2430
2208
 
2431
2209
  }
2432
2210
 
2433
- } //intersection with hyperboloid
2211
+ }
2434
2212
 
2213
+ //intersection with hyperboloid
2435
2214
  /*
2436
2215
  *|y = m * x + q
2437
2216
  *|y = (1 / x) * (r^2 / 2)
@@ -2439,16 +2218,12 @@
2439
2218
  * m * x^2 + q * x - r^2 / 2 = 0
2440
2219
  */
2441
2220
 
2442
-
2443
2221
  a = m;
2444
2222
  b = q;
2445
2223
  c = - radius2 * 0.5;
2446
2224
  delta = Math.pow( b, 2 ) - 4 * a * c;
2447
-
2448
2225
  this._v2_1.setX( ( - b - Math.sqrt( delta ) ) / ( 2 * a ) );
2449
-
2450
2226
  this._v2_1.setY( m * this._v2_1.x + q );
2451
-
2452
2227
  const rayLength = Math.sqrt( Math.pow( this._v2_1.x, 2 ) + Math.pow( cameraGizmoDistance - this._v2_1.y, 2 ) );
2453
2228
  rayDir.multiplyScalar( rayLength );
2454
2229
  rayDir.z += cameraGizmoDistance;
@@ -2463,21 +2238,18 @@
2463
2238
  if ( camera.type == 'OrthographicCamera' ) {
2464
2239
 
2465
2240
  this._v2_1.copy( this.getCursorPosition( cursorX, cursorY, canvas ) );
2466
-
2467
2241
  this._v3_1.set( this._v2_1.x, this._v2_1.y, 0 );
2468
-
2469
2242
  return this._v3_1.clone();
2470
2243
 
2471
2244
  } else if ( camera.type == 'PerspectiveCamera' ) {
2472
2245
 
2473
- this._v2_1.copy( this.getCursorNDC( cursorX, cursorY, canvas ) ); //unproject cursor on the near plane
2474
-
2246
+ this._v2_1.copy( this.getCursorNDC( cursorX, cursorY, canvas ) );
2475
2247
 
2248
+ //unproject cursor on the near plane
2476
2249
  this._v3_1.set( this._v2_1.x, this._v2_1.y, - 1 );
2477
-
2478
2250
  this._v3_1.applyMatrix4( camera.projectionMatrixInverse );
2479
-
2480
2251
  const rayDir = this._v3_1.clone().normalize(); //unprojected ray direction
2252
+
2481
2253
  // camera
2482
2254
  // |\
2483
2255
  // | \
@@ -2488,11 +2260,9 @@
2488
2260
  // _ _ | _ _ _\ _ _ near plane
2489
2261
  // l
2490
2262
 
2491
-
2492
2263
  const h = this._v3_1.z;
2493
2264
  const l = Math.sqrt( Math.pow( this._v3_1.x, 2 ) + Math.pow( this._v3_1.y, 2 ) );
2494
2265
  let cameraGizmoDistance;
2495
-
2496
2266
  if ( initialDistance ) {
2497
2267
 
2498
2268
  cameraGizmoDistance = this._v3_1.setFromMatrixPosition( this._cameraMatrixState0 ).distanceTo( this._v3_2.setFromMatrixPosition( this._gizmoMatrixState0 ) );
@@ -2502,6 +2272,7 @@
2502
2272
  cameraGizmoDistance = camera.position.distanceTo( this._gizmos.position );
2503
2273
 
2504
2274
  }
2275
+
2505
2276
  /*
2506
2277
  * calculate intersection point between unprojected ray and the plane
2507
2278
  *|y = mx + q
@@ -2509,8 +2280,6 @@
2509
2280
  *
2510
2281
  * x = -q/m
2511
2282
  */
2512
-
2513
-
2514
2283
  if ( l == 0 ) {
2515
2284
 
2516
2285
  //ray aligned with camera
@@ -2535,13 +2304,10 @@
2535
2304
 
2536
2305
  //update camera and gizmos state
2537
2306
  this._cameraMatrixState.copy( this.camera.matrix );
2538
-
2539
2307
  this._gizmoMatrixState.copy( this._gizmos.matrix );
2540
-
2541
2308
  if ( this.camera.isOrthographicCamera ) {
2542
2309
 
2543
2310
  this._cameraProjectionState.copy( this.camera.projectionMatrix );
2544
-
2545
2311
  this.camera.updateProjectionMatrix();
2546
2312
  this._zoomState = this.camera.zoom;
2547
2313
 
@@ -2556,7 +2322,6 @@
2556
2322
  this.updateTbState = ( newState, updateMatrices ) => {
2557
2323
 
2558
2324
  this._state = newState;
2559
-
2560
2325
  if ( updateMatrices ) {
2561
2326
 
2562
2327
  this.updateMatrixState();
@@ -2568,20 +2333,16 @@
2568
2333
  this.update = () => {
2569
2334
 
2570
2335
  const EPS = 0.000001;
2571
-
2572
2336
  if ( this.target.equals( this._currentTarget ) === false ) {
2573
2337
 
2574
2338
  this._gizmos.position.copy( this.target ); //for correct radius calculation
2575
-
2576
-
2577
2339
  this._tbRadius = this.calculateTbRadius( this.camera );
2578
2340
  this.makeGizmos( this.target, this._tbRadius );
2579
-
2580
2341
  this._currentTarget.copy( this.target );
2581
2342
 
2582
- } //check min/max parameters
2583
-
2343
+ }
2584
2344
 
2345
+ //check min/max parameters
2585
2346
  if ( this.camera.isOrthographicCamera ) {
2586
2347
 
2587
2348
  //check zoom
@@ -2596,16 +2357,15 @@
2596
2357
 
2597
2358
  //check distance
2598
2359
  const distance = this.camera.position.distanceTo( this._gizmos.position );
2599
-
2600
2360
  if ( distance > this.maxDistance + EPS || distance < this.minDistance - EPS ) {
2601
2361
 
2602
2362
  const newDistance = THREE.MathUtils.clamp( distance, this.minDistance, this.maxDistance );
2603
2363
  this.applyTransformMatrix( this.scale( newDistance / distance, this._gizmos.position ) );
2604
2364
  this.updateMatrixState();
2605
2365
 
2606
- } //check fov
2607
-
2366
+ }
2608
2367
 
2368
+ //check fov
2609
2369
  if ( this.camera.fov < this.minFov || this.camera.fov > this.maxFov ) {
2610
2370
 
2611
2371
  this.camera.fov = THREE.MathUtils.clamp( this.camera.fov, this.minFov, this.maxFov );
@@ -2615,7 +2375,6 @@
2615
2375
 
2616
2376
  const oldRadius = this._tbRadius;
2617
2377
  this._tbRadius = this.calculateTbRadius( this.camera );
2618
-
2619
2378
  if ( oldRadius < this._tbRadius - EPS || oldRadius > this._tbRadius + EPS ) {
2620
2379
 
2621
2380
  const scale = ( this._gizmos.scale.x + this._gizmos.scale.y + this._gizmos.scale.z ) / 3;
@@ -2623,7 +2382,6 @@
2623
2382
  const curve = new THREE.EllipseCurve( 0, 0, newRadius, newRadius );
2624
2383
  const points = curve.getPoints( this._curvePts );
2625
2384
  const curveGeometry = new THREE.BufferGeometry().setFromPoints( points );
2626
-
2627
2385
  for ( const gizmo in this._gizmos.children ) {
2628
2386
 
2629
2387
  this._gizmos.children[ gizmo ].geometry = curveGeometry;
@@ -2641,18 +2399,14 @@
2641
2399
  this.setStateFromJSON = json => {
2642
2400
 
2643
2401
  const state = JSON.parse( json );
2644
-
2645
2402
  if ( state.arcballState != undefined ) {
2646
2403
 
2647
2404
  this._cameraMatrixState.fromArray( state.arcballState.cameraMatrix.elements );
2648
-
2649
2405
  this._cameraMatrixState.decompose( this.camera.position, this.camera.quaternion, this.camera.scale );
2650
-
2651
2406
  this.camera.up.copy( state.arcballState.cameraUp );
2652
2407
  this.camera.near = state.arcballState.cameraNear;
2653
2408
  this.camera.far = state.arcballState.cameraFar;
2654
2409
  this.camera.zoom = state.arcballState.cameraZoom;
2655
-
2656
2410
  if ( this.camera.isPerspectiveCamera ) {
2657
2411
 
2658
2412
  this.camera.fov = state.arcballState.cameraFov;
@@ -2660,20 +2414,14 @@
2660
2414
  }
2661
2415
 
2662
2416
  this._gizmoMatrixState.fromArray( state.arcballState.gizmoMatrix.elements );
2663
-
2664
2417
  this._gizmoMatrixState.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale );
2665
-
2666
2418
  this.camera.updateMatrix();
2667
2419
  this.camera.updateProjectionMatrix();
2668
-
2669
2420
  this._gizmos.updateMatrix();
2670
-
2671
2421
  this._tbRadius = this.calculateTbRadius( this.camera );
2672
2422
  const gizmoTmp = new THREE.Matrix4().copy( this._gizmoMatrixState0 );
2673
2423
  this.makeGizmos( this._gizmos.position, this._tbRadius );
2674
-
2675
2424
  this._gizmoMatrixState0.copy( gizmoTmp );
2676
-
2677
2425
  this.camera.lookAt( this._gizmos.position );
2678
2426
  this.updateTbState( STATE.IDLE, false );
2679
2427
  this.dispatchEvent( _changeEvent );
@@ -2689,24 +2437,24 @@
2689
2437
  this._currentTarget = new THREE.Vector3();
2690
2438
  this.radiusFactor = 0.67;
2691
2439
  this.mouseActions = [];
2692
- this._mouseOp = null; //global vectors and matrices that are used in some operations to avoid creating new objects every time (e.g. every time cursor moves)
2440
+ this._mouseOp = null;
2693
2441
 
2442
+ //global vectors and matrices that are used in some operations to avoid creating new objects every time (e.g. every time cursor moves)
2694
2443
  this._v2_1 = new THREE.Vector2();
2695
2444
  this._v3_1 = new THREE.Vector3();
2696
2445
  this._v3_2 = new THREE.Vector3();
2697
2446
  this._m4_1 = new THREE.Matrix4();
2698
2447
  this._m4_2 = new THREE.Matrix4();
2699
- this._quat = new THREE.Quaternion(); //transformation matrices
2448
+ this._quat = new THREE.Quaternion();
2700
2449
 
2450
+ //transformation matrices
2701
2451
  this._translationMatrix = new THREE.Matrix4(); //matrix for translation operation
2702
-
2703
2452
  this._rotationMatrix = new THREE.Matrix4(); //matrix for rotation operation
2704
-
2705
2453
  this._scaleMatrix = new THREE.Matrix4(); //matrix for scaling operation
2706
2454
 
2707
2455
  this._rotationAxis = new THREE.Vector3(); //axis for rotate operation
2708
- //camera state
2709
2456
 
2457
+ //camera state
2710
2458
  this._cameraMatrixState = new THREE.Matrix4();
2711
2459
  this._cameraProjectionState = new THREE.Matrix4();
2712
2460
  this._fovState = 1;
@@ -2714,8 +2462,9 @@
2714
2462
  this._zoomState = 1;
2715
2463
  this._nearPos = 0;
2716
2464
  this._farPos = 0;
2717
- this._gizmoMatrixState = new THREE.Matrix4(); //initial values
2465
+ this._gizmoMatrixState = new THREE.Matrix4();
2718
2466
 
2467
+ //initial values
2719
2468
  this._up0 = new THREE.Vector3();
2720
2469
  this._zoom0 = 1;
2721
2470
  this._fov0 = 0;
@@ -2724,81 +2473,70 @@
2724
2473
  this._initialFar = 0;
2725
2474
  this._farPos0 = 0;
2726
2475
  this._cameraMatrixState0 = new THREE.Matrix4();
2727
- this._gizmoMatrixState0 = new THREE.Matrix4(); //pointers array
2476
+ this._gizmoMatrixState0 = new THREE.Matrix4();
2728
2477
 
2478
+ //pointers array
2729
2479
  this._button = - 1;
2730
2480
  this._touchStart = [];
2731
2481
  this._touchCurrent = [];
2732
- this._input = INPUT.NONE; //two fingers touch interaction
2482
+ this._input = INPUT.NONE;
2733
2483
 
2484
+ //two fingers touch interaction
2734
2485
  this._switchSensibility = 32; //minimum movement to be performed to fire single pan start after the second finger has been released
2735
-
2736
2486
  this._startFingerDistance = 0; //distance between two fingers
2737
-
2738
2487
  this._currentFingerDistance = 0;
2739
2488
  this._startFingerRotation = 0; //amount of rotation performed with two fingers
2489
+ this._currentFingerRotation = 0;
2740
2490
 
2741
- this._currentFingerRotation = 0; //double tap
2742
-
2491
+ //double tap
2743
2492
  this._devPxRatio = 0;
2744
2493
  this._downValid = true;
2745
2494
  this._nclicks = 0;
2746
2495
  this._downEvents = [];
2747
2496
  this._downStart = 0; //pointerDown time
2748
-
2749
2497
  this._clickStart = 0; //first click time
2750
-
2751
2498
  this._maxDownTime = 250;
2752
2499
  this._maxInterval = 300;
2753
2500
  this._posThreshold = 24;
2754
- this._movementThreshold = 24; //cursor positions
2501
+ this._movementThreshold = 24;
2755
2502
 
2503
+ //cursor positions
2756
2504
  this._currentCursorPosition = new THREE.Vector3();
2757
- this._startCursorPosition = new THREE.Vector3(); //grid
2505
+ this._startCursorPosition = new THREE.Vector3();
2758
2506
 
2507
+ //grid
2759
2508
  this._grid = null; //grid to be visualized during pan operation
2509
+ this._gridPosition = new THREE.Vector3();
2760
2510
 
2761
- this._gridPosition = new THREE.Vector3(); //gizmos
2762
-
2511
+ //gizmos
2763
2512
  this._gizmos = new THREE.Group();
2764
- this._curvePts = 128; //animations
2513
+ this._curvePts = 128;
2765
2514
 
2515
+ //animations
2766
2516
  this._timeStart = - 1; //initial time
2517
+ this._animationId = - 1;
2767
2518
 
2768
- this._animationId = - 1; //focus animation
2769
-
2519
+ //focus animation
2770
2520
  this.focusAnimationTime = 500; //duration of focus animation in ms
2771
- //rotate animation
2772
2521
 
2522
+ //rotate animation
2773
2523
  this._timePrev = 0; //time at which previous rotate operation has been detected
2774
-
2775
2524
  this._timeCurrent = 0; //time at which current rotate operation has been detected
2776
-
2777
2525
  this._anglePrev = 0; //angle of previous rotation
2778
-
2779
2526
  this._angleCurrent = 0; //angle of current rotation
2780
-
2781
2527
  this._cursorPosPrev = new THREE.Vector3(); //cursor position when previous rotate operation has been detected
2782
-
2783
2528
  this._cursorPosCurr = new THREE.Vector3(); //cursor position when current rotate operation has been detected
2784
-
2785
2529
  this._wPrev = 0; //angular velocity of the previous rotate operation
2786
-
2787
2530
  this._wCurr = 0; //angular velocity of the current rotate operation
2788
- //parameters
2789
2531
 
2532
+ //parameters
2790
2533
  this.adjustNearFar = false;
2791
2534
  this.scaleFactor = 1.1; //zoom/distance multiplier
2792
-
2793
2535
  this.dampingFactor = 25;
2794
2536
  this.wMax = 20; //maximum angular velocity allowed
2795
-
2796
2537
  this.enableAnimations = true; //if animations should be performed
2797
-
2798
2538
  this.enableGrid = false; //if grid should be showed during pan operation
2799
-
2800
2539
  this.cursorZoom = false; //if wheel zoom should be cursor centered
2801
-
2802
2540
  this.minFov = 5;
2803
2541
  this.maxFov = 90;
2804
2542
  this.enabled = true;
@@ -2809,13 +2547,14 @@
2809
2547
  this.minDistance = 0;
2810
2548
  this.maxDistance = Infinity;
2811
2549
  this.minZoom = 0;
2812
- this.maxZoom = Infinity; //trackball parameters
2550
+ this.maxZoom = Infinity;
2813
2551
 
2814
- this._tbRadius = 1; //FSA
2552
+ //trackball parameters
2553
+ this._tbRadius = 1;
2815
2554
 
2555
+ //FSA
2816
2556
  this._state = STATE.IDLE;
2817
2557
  this.setCamera( _camera );
2818
-
2819
2558
  if ( this.scene != null ) {
2820
2559
 
2821
2560
  this.scene.add( this._gizmos );
@@ -2831,8 +2570,9 @@
2831
2570
  this.domElement.addEventListener( 'pointercancel', this.onPointerCancel );
2832
2571
  window.addEventListener( 'resize', this.onWindowResize );
2833
2572
 
2834
- } //listeners
2573
+ }
2835
2574
 
2575
+ //listeners
2836
2576
 
2837
2577
  /**
2838
2578
  * Apply a transformation matrix, to the camera and gizmos
@@ -2843,11 +2583,10 @@
2843
2583
  if ( transformation.camera != null ) {
2844
2584
 
2845
2585
  this._m4_1.copy( this._cameraMatrixState ).premultiply( transformation.camera );
2846
-
2847
2586
  this._m4_1.decompose( this.camera.position, this.camera.quaternion, this.camera.scale );
2587
+ this.camera.updateMatrix();
2848
2588
 
2849
- this.camera.updateMatrix(); //update camera up vector
2850
-
2589
+ //update camera up vector
2851
2590
  if ( this._state == STATE.ROTATE || this._state == STATE.ZROTATE || this._state == STATE.ANIMATION_ROTATE ) {
2852
2591
 
2853
2592
  this.camera.up.copy( this._upState ).applyQuaternion( this.camera.quaternion );
@@ -2859,9 +2598,7 @@
2859
2598
  if ( transformation.gizmos != null ) {
2860
2599
 
2861
2600
  this._m4_1.copy( this._gizmoMatrixState ).premultiply( transformation.gizmos );
2862
-
2863
2601
  this._m4_1.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale );
2864
-
2865
2602
  this._gizmos.updateMatrix();
2866
2603
 
2867
2604
  }
@@ -2869,7 +2606,6 @@
2869
2606
  if ( this._state == STATE.SCALE || this._state == STATE.FOCUS || this._state == STATE.ANIMATION_FOCUS ) {
2870
2607
 
2871
2608
  this._tbRadius = this.calculateTbRadius( this.camera );
2872
-
2873
2609
  if ( this.adjustNearFar ) {
2874
2610
 
2875
2611
  const cameraDistance = this.camera.position.distanceTo( this._gizmos.position );
@@ -2890,7 +2626,6 @@
2890
2626
  } else {
2891
2627
 
2892
2628
  let update = false;
2893
-
2894
2629
  if ( this.camera.near != this._initialNear ) {
2895
2630
 
2896
2631
  this.camera.near = this._initialNear;
@@ -2916,6 +2651,7 @@
2916
2651
  }
2917
2652
 
2918
2653
  }
2654
+
2919
2655
  /**
2920
2656
  * Calculate the angular speed
2921
2657
  * @param {Number} p0 Position at t0
@@ -2924,7 +2660,6 @@
2924
2660
  * @param {Number} t1 Ending time in milliseconds
2925
2661
  */
2926
2662
 
2927
-
2928
2663
  /**
2929
2664
  * Set gizmos visibility
2930
2665
  * @param {Boolean} value Value of gizmos visibility
@@ -2935,12 +2670,11 @@
2935
2670
  this.dispatchEvent( _changeEvent );
2936
2671
 
2937
2672
  }
2673
+
2938
2674
  /**
2939
2675
  * Set gizmos radius factor and redraws gizmos
2940
2676
  * @param {Float} value Value of radius factor
2941
2677
  */
2942
-
2943
-
2944
2678
  setTbRadius( value ) {
2945
2679
 
2946
2680
  this.radiusFactor = value;
@@ -2948,7 +2682,6 @@
2948
2682
  const curve = new THREE.EllipseCurve( 0, 0, this._tbRadius, this._tbRadius );
2949
2683
  const points = curve.getPoints( this._curvePts );
2950
2684
  const curveGeometry = new THREE.BufferGeometry().setFromPoints( points );
2951
-
2952
2685
  for ( const gizmo in this._gizmos.children ) {
2953
2686
 
2954
2687
  this._gizmos.children[ gizmo ].geometry = curveGeometry;
@@ -2958,13 +2691,13 @@
2958
2691
  this.dispatchEvent( _changeEvent );
2959
2692
 
2960
2693
  }
2694
+
2961
2695
  /**
2962
2696
  * Creates the rotation gizmos matching trackball center and radius
2963
2697
  * @param {Vector3} tbCenter The trackball center
2964
2698
  * @param {number} tbRadius The trackball radius
2965
2699
  */
2966
2700
 
2967
-
2968
2701
  /**
2969
2702
  * Set values in transformation object
2970
2703
  * @param {Matrix4} camera Transformation to be applied to the camera
@@ -3009,6 +2742,7 @@
3009
2742
  }
3010
2743
 
3011
2744
  }
2745
+
3012
2746
  /**
3013
2747
  * Rotate camera around its direction axis passing by a given point by a given angle
3014
2748
  * @param {Vector3} point The point where the rotation axis is passing trough
@@ -3016,12 +2750,12 @@
3016
2750
  * @returns The computed transormation matix
3017
2751
  */
3018
2752
 
3019
-
3020
2753
  getRaycaster() {
3021
2754
 
3022
2755
  return _raycaster;
3023
2756
 
3024
2757
  }
2758
+
3025
2759
  /**
3026
2760
  * Unproject the cursor on the 3D object surface
3027
2761
  * @param {Vector2} cursor Cursor coordinates in NDC
@@ -3029,7 +2763,6 @@
3029
2763
  * @returns {Vector3} The point of intersection with the model, if exist, null otherwise
3030
2764
  */
3031
2765
 
3032
-
3033
2766
  }
3034
2767
 
3035
2768
  THREE.ArcballControls = ArcballControls;