@needle-tools/three 0.146.10 → 0.153.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (865) hide show
  1. package/LICENSE +1 -1
  2. package/build/three.cjs +39486 -20286
  3. package/build/three.js +39471 -20270
  4. package/build/three.min.js +3 -2
  5. package/build/three.module.js +6717 -5427
  6. package/build/three.module.min.js +6 -0
  7. package/examples/jsm/animation/AnimationClipCreator.js +5 -3
  8. package/examples/jsm/cameras/CinematicCamera.js +1 -2
  9. package/examples/jsm/capabilities/WebGPU.js +17 -5
  10. package/examples/jsm/controls/ArcballControls.js +1828 -1821
  11. package/examples/jsm/controls/MapControls.js +28 -0
  12. package/examples/jsm/controls/OrbitControls.js +26 -53
  13. package/examples/jsm/controls/PointerLockControls.js +70 -65
  14. package/examples/jsm/controls/TrackballControls.js +18 -4
  15. package/examples/jsm/controls/TransformControls.js +0 -1
  16. package/examples/jsm/csm/CSM.js +11 -5
  17. package/examples/jsm/csm/CSMShader.js +7 -6
  18. package/examples/jsm/effects/AnaglyphEffect.js +6 -20
  19. package/examples/jsm/effects/AsciiEffect.js +3 -6
  20. package/examples/jsm/effects/OutlineEffect.js +1 -15
  21. package/examples/jsm/effects/ParallaxBarrierEffect.js +3 -0
  22. package/examples/jsm/exporters/DRACOExporter.js +53 -11
  23. package/examples/jsm/exporters/EXRExporter.js +3 -9
  24. package/examples/jsm/exporters/GLTFExporter.js +561 -154
  25. package/examples/jsm/exporters/KTX2Exporter.js +34 -23
  26. package/examples/jsm/exporters/MMDExporter.js +1 -1
  27. package/examples/jsm/exporters/PLYExporter.js +8 -1
  28. package/examples/jsm/exporters/STLExporter.js +8 -4
  29. package/examples/jsm/exporters/USDZExporter.js +305 -792
  30. package/examples/jsm/geometries/ConvexGeometry.js +0 -6
  31. package/examples/jsm/geometries/ParametricGeometry.js +10 -0
  32. package/examples/jsm/helpers/OctreeHelper.js +1 -0
  33. package/examples/jsm/helpers/ViewHelper.js +71 -57
  34. package/examples/jsm/interactive/HTMLMesh.js +16 -3
  35. package/examples/jsm/interactive/InteractiveGroup.js +1 -1
  36. package/examples/{js → jsm}/libs/basis/README.md +4 -4
  37. package/examples/jsm/libs/draco/draco_decoder.js +34 -0
  38. package/examples/jsm/libs/draco/draco_decoder.wasm +0 -0
  39. package/examples/jsm/libs/draco/draco_wasm_wrapper.js +117 -0
  40. package/examples/jsm/libs/draco/gltf/draco_decoder.js +33 -0
  41. package/examples/jsm/libs/draco/gltf/draco_decoder.wasm +0 -0
  42. package/examples/jsm/libs/draco/gltf/draco_wasm_wrapper.js +116 -0
  43. package/examples/jsm/libs/lil-gui.module.min.js +2 -2
  44. package/examples/jsm/libs/tween.module.js +803 -0
  45. package/examples/jsm/lights/IESSpotLight.js +25 -0
  46. package/examples/jsm/lights/LightProbeGenerator.js +11 -9
  47. package/examples/jsm/lines/LineSegments2.js +16 -10
  48. package/examples/jsm/loaders/3DMLoader.js +8 -5
  49. package/examples/jsm/loaders/3MFLoader.js +12 -11
  50. package/examples/jsm/loaders/AMFLoader.js +2 -3
  51. package/examples/jsm/loaders/BVHLoader.js +2 -2
  52. package/examples/jsm/loaders/ColladaLoader.js +15 -16
  53. package/examples/jsm/loaders/DRACOLoader.js +69 -18
  54. package/examples/jsm/loaders/EXRLoader.js +23 -24
  55. package/examples/jsm/loaders/FBXLoader.js +34 -50
  56. package/examples/jsm/loaders/GCodeLoader.js +1 -2
  57. package/examples/jsm/loaders/GLTFLoader.js +417 -895
  58. package/examples/jsm/loaders/GLTFLoaderAnimationPointer.js +684 -0
  59. package/examples/jsm/loaders/HDRCubeTextureLoader.js +4 -4
  60. package/examples/jsm/loaders/IESLoader.js +337 -0
  61. package/examples/jsm/loaders/KMZLoader.js +4 -4
  62. package/examples/jsm/loaders/KTX2Loader.js +145 -69
  63. package/examples/jsm/loaders/LDrawLoader.js +20 -18
  64. package/examples/jsm/loaders/LWOLoader.js +12 -29
  65. package/examples/jsm/loaders/LottieLoader.js +3 -1
  66. package/examples/jsm/loaders/MMDLoader.js +49 -18
  67. package/examples/jsm/loaders/MTLLoader.js +2 -2
  68. package/examples/jsm/loaders/MaterialXLoader.js +9 -3
  69. package/examples/jsm/loaders/NRRDLoader.js +33 -5
  70. package/examples/jsm/loaders/OBJLoader.js +1 -1
  71. package/examples/jsm/loaders/PCDLoader.js +26 -12
  72. package/examples/jsm/loaders/PDBLoader.js +7 -2
  73. package/examples/jsm/loaders/PLYLoader.js +254 -109
  74. package/examples/jsm/loaders/RGBELoader.js +3 -3
  75. package/examples/jsm/loaders/STLLoader.js +9 -5
  76. package/examples/jsm/loaders/SVGLoader.js +36 -27
  77. package/examples/jsm/loaders/TTFLoader.js +1 -8
  78. package/examples/jsm/loaders/TiltLoader.js +13 -7
  79. package/examples/jsm/loaders/USDZLoader.js +6 -6
  80. package/examples/jsm/loaders/VOXLoader.js +8 -2
  81. package/examples/jsm/loaders/VRMLLoader.js +44 -16
  82. package/examples/jsm/loaders/VTKLoader.js +19 -10
  83. package/examples/jsm/loaders/XYZLoader.js +9 -3
  84. package/examples/jsm/loaders/lwo/IFFParser.js +19 -19
  85. package/examples/jsm/materials/MeshGouraudMaterial.js +0 -3
  86. package/examples/jsm/math/ConvexHull.js +3 -3
  87. package/examples/jsm/math/Lut.js +5 -4
  88. package/examples/jsm/math/MeshSurfaceSampler.js +7 -9
  89. package/examples/jsm/math/Octree.js +1 -1
  90. package/examples/jsm/misc/ConvexObjectBreaker.js +2 -8
  91. package/examples/jsm/misc/GPUComputationRenderer.js +6 -5
  92. package/examples/jsm/misc/MD2Character.js +2 -2
  93. package/examples/jsm/misc/MD2CharacterComplex.js +2 -2
  94. package/examples/jsm/misc/ProgressiveLightMap.js +12 -10
  95. package/examples/jsm/misc/RollerCoaster.js +7 -1
  96. package/examples/jsm/misc/Volume.js +20 -5
  97. package/examples/jsm/misc/VolumeSlice.js +3 -1
  98. package/examples/jsm/modifiers/CurveModifier.js +1 -0
  99. package/examples/jsm/modifiers/TessellateModifier.js +19 -19
  100. package/examples/jsm/nodes/Nodes.js +144 -335
  101. package/examples/jsm/nodes/accessors/BitangentNode.js +43 -16
  102. package/examples/jsm/nodes/accessors/BufferAttributeNode.js +86 -0
  103. package/examples/jsm/nodes/accessors/BufferNode.js +6 -0
  104. package/examples/jsm/nodes/accessors/CameraNode.js +12 -2
  105. package/examples/jsm/nodes/accessors/CubeTextureNode.js +27 -33
  106. package/examples/jsm/nodes/accessors/ExtendedMaterialNode.js +58 -0
  107. package/examples/jsm/nodes/accessors/InstanceNode.js +41 -26
  108. package/examples/jsm/nodes/accessors/MaterialNode.js +155 -38
  109. package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +16 -0
  110. package/examples/jsm/nodes/accessors/ModelNode.js +11 -0
  111. package/examples/jsm/nodes/accessors/ModelViewProjectionNode.js +13 -14
  112. package/examples/jsm/nodes/accessors/NormalNode.js +35 -19
  113. package/examples/jsm/nodes/accessors/Object3DNode.js +32 -12
  114. package/examples/jsm/nodes/accessors/PointUVNode.js +6 -1
  115. package/examples/jsm/nodes/accessors/PositionNode.js +38 -23
  116. package/examples/jsm/nodes/accessors/ReferenceNode.js +21 -14
  117. package/examples/jsm/nodes/accessors/ReflectVectorNode.js +11 -7
  118. package/examples/jsm/nodes/accessors/SkinningNode.js +43 -40
  119. package/examples/jsm/nodes/accessors/StorageBufferNode.js +6 -0
  120. package/examples/jsm/nodes/accessors/TangentNode.js +28 -20
  121. package/examples/jsm/nodes/accessors/TextureNode.js +80 -12
  122. package/examples/jsm/nodes/accessors/UVNode.js +6 -0
  123. package/examples/jsm/nodes/accessors/UserDataNode.js +6 -0
  124. package/examples/jsm/nodes/code/CodeNode.js +75 -0
  125. package/examples/jsm/nodes/code/ExpressionNode.js +37 -0
  126. package/examples/jsm/nodes/{core → code}/FunctionCallNode.js +15 -1
  127. package/examples/jsm/nodes/{core → code}/FunctionNode.js +8 -7
  128. package/examples/jsm/nodes/code/ScriptableNode.js +488 -0
  129. package/examples/jsm/nodes/code/ScriptableValueNode.js +167 -0
  130. package/examples/jsm/nodes/core/ArrayUniformNode.js +3 -0
  131. package/examples/jsm/nodes/core/AttributeNode.js +17 -9
  132. package/examples/jsm/nodes/core/BypassNode.js +9 -2
  133. package/examples/jsm/nodes/core/CacheNode.js +46 -0
  134. package/examples/jsm/nodes/core/ConstNode.js +3 -0
  135. package/examples/jsm/nodes/core/ContextNode.js +8 -1
  136. package/examples/jsm/nodes/core/InputNode.js +26 -5
  137. package/examples/jsm/nodes/core/InstanceIndexNode.js +26 -2
  138. package/examples/jsm/nodes/core/LightingModel.js +16 -0
  139. package/examples/jsm/nodes/core/Node.js +129 -35
  140. package/examples/jsm/nodes/core/NodeAttribute.js +2 -1
  141. package/examples/jsm/nodes/core/NodeBuilder.js +271 -121
  142. package/examples/jsm/nodes/core/NodeCache.js +26 -0
  143. package/examples/jsm/nodes/core/NodeFrame.js +56 -5
  144. package/examples/jsm/nodes/core/NodeUtils.js +115 -28
  145. package/examples/jsm/nodes/core/PropertyNode.js +19 -2
  146. package/examples/jsm/nodes/core/StackNode.js +99 -0
  147. package/examples/jsm/nodes/core/TempNode.js +11 -3
  148. package/examples/jsm/nodes/core/UniformNode.js +16 -1
  149. package/examples/jsm/nodes/core/VarNode.js +21 -29
  150. package/examples/jsm/nodes/core/VaryingNode.js +15 -2
  151. package/examples/jsm/nodes/core/constants.js +6 -0
  152. package/examples/jsm/nodes/display/BlendModeNode.js +25 -11
  153. package/examples/jsm/nodes/display/ColorAdjustmentNode.js +30 -14
  154. package/examples/jsm/nodes/display/ColorSpaceNode.js +39 -27
  155. package/examples/jsm/nodes/display/FrontFacingNode.js +7 -1
  156. package/examples/jsm/nodes/display/NormalMapNode.js +31 -18
  157. package/examples/jsm/nodes/display/PosterizeNode.js +10 -3
  158. package/examples/jsm/nodes/display/ToneMappingNode.js +101 -11
  159. package/examples/jsm/nodes/display/ViewportNode.js +27 -18
  160. package/examples/jsm/nodes/display/ViewportSharedTextureNode.js +30 -0
  161. package/examples/jsm/nodes/display/ViewportTextureNode.js +67 -0
  162. package/examples/jsm/nodes/fog/FogExp2Node.js +35 -0
  163. package/examples/jsm/nodes/fog/FogNode.js +12 -6
  164. package/examples/jsm/nodes/fog/FogRangeNode.js +12 -5
  165. package/examples/jsm/nodes/functions/BSDF/BRDF_BlinnPhong.js +30 -0
  166. package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +10 -13
  167. package/examples/jsm/nodes/functions/BSDF/BRDF_Lambert.js +2 -2
  168. package/examples/jsm/nodes/functions/BSDF/DFGApprox.js +8 -6
  169. package/examples/jsm/nodes/functions/BSDF/D_GGX.js +4 -4
  170. package/examples/jsm/nodes/functions/BSDF/F_Schlick.js +3 -3
  171. package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +7 -5
  172. package/examples/jsm/nodes/functions/PhongLightingModel.js +28 -0
  173. package/examples/jsm/nodes/functions/PhysicalLightingModel.js +35 -36
  174. package/examples/jsm/nodes/functions/material/getGeometryRoughness.js +4 -3
  175. package/examples/jsm/nodes/functions/material/getRoughness.js +4 -4
  176. package/examples/jsm/nodes/geometry/RangeNode.js +50 -55
  177. package/examples/jsm/nodes/gpgpu/ComputeNode.js +9 -2
  178. package/examples/jsm/nodes/lighting/AONode.js +5 -3
  179. package/examples/jsm/nodes/lighting/AmbientLightNode.js +27 -0
  180. package/examples/jsm/nodes/lighting/AnalyticLightNode.js +114 -5
  181. package/examples/jsm/nodes/lighting/DirectionalLightNode.js +43 -0
  182. package/examples/jsm/nodes/lighting/EnvironmentNode.js +121 -35
  183. package/examples/jsm/nodes/lighting/HemisphereLightNode.js +15 -10
  184. package/examples/jsm/nodes/lighting/IESSpotLightNode.js +39 -0
  185. package/examples/jsm/nodes/lighting/LightNode.js +57 -0
  186. package/examples/jsm/nodes/lighting/LightUtils.js +17 -0
  187. package/examples/jsm/nodes/lighting/LightingContextNode.js +30 -8
  188. package/examples/jsm/nodes/lighting/LightingNode.js +3 -1
  189. package/examples/jsm/nodes/lighting/LightsNode.js +18 -10
  190. package/examples/jsm/nodes/lighting/PointLightNode.js +71 -0
  191. package/examples/jsm/nodes/lighting/SpotLightNode.js +92 -0
  192. package/examples/jsm/nodes/loaders/NodeLoader.js +5 -4
  193. package/examples/jsm/nodes/loaders/NodeMaterialLoader.js +4 -20
  194. package/examples/jsm/nodes/materials/LineBasicNodeMaterial.js +6 -9
  195. package/examples/jsm/nodes/materials/Materials.js +11 -55
  196. package/examples/jsm/nodes/materials/MeshBasicNodeMaterial.js +5 -11
  197. package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +48 -0
  198. package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +74 -0
  199. package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +6 -6
  200. package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +21 -96
  201. package/examples/jsm/nodes/materials/NodeMaterial.js +284 -62
  202. package/examples/jsm/nodes/materials/PointsNodeMaterial.js +7 -1
  203. package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +29 -25
  204. package/examples/jsm/nodes/materialx/MaterialXNodes.js +31 -22
  205. package/examples/jsm/nodes/materialx/lib/mx_hsv.js +1 -1
  206. package/examples/jsm/nodes/materialx/lib/mx_noise.js +2 -1
  207. package/examples/jsm/nodes/materialx/lib/mx_transform_color.js +2 -1
  208. package/examples/jsm/nodes/math/CondNode.js +43 -17
  209. package/examples/jsm/nodes/math/MathNode.js +178 -73
  210. package/examples/jsm/nodes/math/OperatorNode.js +52 -2
  211. package/examples/jsm/nodes/procedural/CheckerNode.js +14 -6
  212. package/examples/jsm/nodes/shadernode/ShaderNode.js +186 -63
  213. package/examples/jsm/nodes/utils/ArrayElementNode.js +4 -2
  214. package/examples/jsm/nodes/utils/ConvertNode.js +19 -1
  215. package/examples/jsm/nodes/utils/DiscardNode.js +26 -0
  216. package/examples/jsm/nodes/utils/EquirectUVNode.js +10 -4
  217. package/examples/jsm/nodes/utils/JoinNode.js +4 -1
  218. package/examples/jsm/nodes/utils/LoopNode.js +186 -0
  219. package/examples/jsm/nodes/utils/MatcapUVNode.js +11 -4
  220. package/examples/jsm/nodes/utils/MaxMipLevelNode.js +18 -5
  221. package/examples/jsm/nodes/utils/OscNode.js +21 -14
  222. package/examples/jsm/nodes/utils/PackingNode.js +55 -0
  223. package/examples/jsm/nodes/utils/RemapNode.js +13 -5
  224. package/examples/jsm/nodes/utils/RotateUVNode.js +18 -7
  225. package/examples/jsm/nodes/utils/SpecularMIPLevelNode.js +37 -0
  226. package/examples/jsm/nodes/utils/SplitNode.js +7 -5
  227. package/examples/jsm/nodes/utils/SpriteSheetUVNode.js +15 -30
  228. package/examples/jsm/nodes/utils/TimerNode.js +16 -6
  229. package/examples/jsm/nodes/utils/TriplanarTexturesNode.js +21 -10
  230. package/examples/jsm/objects/GroundProjectedSkybox.js +172 -0
  231. package/examples/jsm/objects/Lensflare.js +3 -4
  232. package/examples/jsm/objects/MarchingCubes.js +5 -1
  233. package/examples/jsm/objects/Reflector.js +7 -4
  234. package/examples/jsm/objects/Refractor.js +4 -4
  235. package/examples/jsm/objects/ShadowMesh.js +3 -3
  236. package/examples/jsm/objects/Water.js +2 -1
  237. package/examples/jsm/physics/AmmoPhysics.js +27 -28
  238. package/examples/jsm/physics/RapierPhysics.js +199 -0
  239. package/examples/jsm/postprocessing/AfterimagePass.js +3 -2
  240. package/examples/jsm/postprocessing/BloomPass.js +7 -4
  241. package/examples/jsm/postprocessing/BokehPass.js +3 -8
  242. package/examples/jsm/postprocessing/DotScreenPass.js +1 -2
  243. package/examples/jsm/postprocessing/EffectComposer.js +5 -95
  244. package/examples/jsm/postprocessing/FilmPass.js +1 -2
  245. package/examples/jsm/postprocessing/GlitchPass.js +0 -2
  246. package/examples/jsm/postprocessing/HalftonePass.js +0 -6
  247. package/examples/jsm/postprocessing/OutlinePass.js +7 -7
  248. package/examples/jsm/postprocessing/OutputPass.js +72 -0
  249. package/examples/jsm/postprocessing/Pass.js +2 -0
  250. package/examples/jsm/postprocessing/RenderPixelatedPass.js +4 -3
  251. package/examples/jsm/postprocessing/SAOPass.js +4 -26
  252. package/examples/jsm/postprocessing/SMAAPass.js +5 -8
  253. package/examples/jsm/postprocessing/SSAARenderPass.js +15 -6
  254. package/examples/jsm/postprocessing/SSAOPass.js +4 -14
  255. package/examples/jsm/postprocessing/SSRPass.js +3 -7
  256. package/examples/jsm/postprocessing/SavePass.js +2 -3
  257. package/examples/jsm/postprocessing/ShaderPass.js +1 -0
  258. package/examples/jsm/postprocessing/TAARenderPass.js +3 -2
  259. package/examples/jsm/postprocessing/TexturePass.js +0 -2
  260. package/examples/jsm/postprocessing/UnrealBloomPass.js +4 -11
  261. package/examples/jsm/renderers/CSS2DRenderer.js +6 -1
  262. package/examples/jsm/renderers/CSS3DRenderer.js +27 -5
  263. package/examples/jsm/renderers/{webgpu/WebGPUAnimation.js → common/Animation.js} +4 -4
  264. package/examples/jsm/renderers/common/Attributes.js +75 -0
  265. package/examples/jsm/renderers/common/Backend.js +160 -0
  266. package/examples/jsm/renderers/common/Background.js +133 -0
  267. package/examples/jsm/renderers/common/Binding.js +11 -0
  268. package/examples/jsm/renderers/common/Bindings.js +169 -0
  269. package/examples/jsm/renderers/common/Buffer.js +38 -0
  270. package/examples/jsm/renderers/{webgpu/WebGPUBufferUtils.js → common/BufferUtils.js} +2 -2
  271. package/examples/jsm/renderers/common/ChainMap.js +89 -0
  272. package/examples/jsm/renderers/common/ComputePipeline.js +17 -0
  273. package/examples/jsm/renderers/common/Constants.js +14 -0
  274. package/examples/jsm/renderers/common/CubeRenderTarget.js +65 -0
  275. package/examples/jsm/renderers/common/DataMap.js +54 -0
  276. package/examples/jsm/renderers/common/Geometries.js +215 -0
  277. package/examples/jsm/renderers/{webgpu/WebGPUInfo.js → common/Info.js} +2 -3
  278. package/examples/jsm/renderers/common/Pipeline.js +13 -0
  279. package/examples/jsm/renderers/common/Pipelines.js +309 -0
  280. package/examples/jsm/renderers/common/ProgrammableStage.js +18 -0
  281. package/examples/jsm/renderers/common/RenderContext.js +37 -0
  282. package/examples/jsm/renderers/common/RenderContexts.js +38 -0
  283. package/examples/jsm/renderers/{webgpu/WebGPURenderLists.js → common/RenderList.js} +26 -47
  284. package/examples/jsm/renderers/common/RenderLists.js +38 -0
  285. package/examples/jsm/renderers/common/RenderObject.js +95 -0
  286. package/examples/jsm/renderers/common/RenderObjects.js +92 -0
  287. package/examples/jsm/renderers/common/RenderPipeline.js +16 -0
  288. package/examples/jsm/renderers/common/RenderTarget.js +15 -0
  289. package/examples/jsm/renderers/common/Renderer.js +822 -0
  290. package/examples/jsm/renderers/common/SampledTexture.js +80 -0
  291. package/examples/jsm/renderers/common/Sampler.js +18 -0
  292. package/examples/jsm/renderers/common/StorageBuffer.js +17 -0
  293. package/examples/jsm/renderers/common/Textures.js +206 -0
  294. package/examples/jsm/renderers/{webgpu/WebGPUUniform.js → common/Uniform.js} +13 -9
  295. package/examples/jsm/renderers/common/UniformBuffer.js +15 -0
  296. package/examples/jsm/renderers/{webgpu/WebGPUUniformsGroup.js → common/UniformsGroup.js} +13 -13
  297. package/examples/jsm/renderers/common/nodes/NodeRender.js +302 -0
  298. package/examples/jsm/renderers/{webgpu/nodes/WebGPUNodeSampledTexture.js → common/nodes/NodeSampledTexture.js} +4 -4
  299. package/examples/jsm/renderers/{webgpu/nodes/WebGPUNodeSampler.js → common/nodes/NodeSampler.js} +3 -3
  300. package/examples/jsm/renderers/{webgpu/nodes/WebGPUNodeUniform.js → common/nodes/NodeUniform.js} +1 -1
  301. package/examples/jsm/renderers/common/nodes/Nodes.js +319 -0
  302. package/examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js +35 -31
  303. package/examples/jsm/renderers/webgpu/WebGPUBackend.js +765 -0
  304. package/examples/jsm/renderers/webgpu/WebGPURenderer.js +15 -987
  305. package/examples/jsm/renderers/webgpu/nodes/{WebGPUNodeBuilder.js → WGSLNodeBuilder.js} +117 -90
  306. package/examples/jsm/{nodes/parsers → renderers/webgpu/nodes}/WGSLNodeFunction.js +2 -2
  307. package/examples/jsm/{nodes/parsers → renderers/webgpu/nodes}/WGSLNodeParser.js +1 -1
  308. package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +251 -0
  309. package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +145 -0
  310. package/examples/jsm/renderers/webgpu/{constants.js → utils/WebGPUConstants.js} +73 -12
  311. package/examples/jsm/renderers/webgpu/{WebGPURenderPipeline.js → utils/WebGPUPipelineUtils.js} +135 -285
  312. package/examples/jsm/renderers/webgpu/{WebGPUTextureUtils.js → utils/WebGPUTextureMipmapUtils.js} +5 -25
  313. package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +855 -0
  314. package/examples/jsm/renderers/webgpu/utils/WebGPUUtils.js +88 -0
  315. package/examples/jsm/shaders/BleachBypassShader.js +2 -0
  316. package/examples/jsm/shaders/BokehShader2.js +3 -0
  317. package/examples/jsm/shaders/ColorifyShader.js +2 -0
  318. package/examples/jsm/shaders/ConvolutionShader.js +2 -0
  319. package/examples/jsm/shaders/CopyShader.js +2 -0
  320. package/examples/jsm/shaders/DotScreenShader.js +2 -0
  321. package/examples/jsm/shaders/ExposureShader.js +44 -0
  322. package/examples/jsm/shaders/FilmShader.js +2 -0
  323. package/examples/jsm/shaders/GammaCorrectionShader.js +2 -0
  324. package/examples/jsm/shaders/HorizontalBlurShader.js +2 -0
  325. package/examples/jsm/shaders/MMDToonShader.js +15 -4
  326. package/examples/jsm/shaders/OutputShader.js +61 -0
  327. package/examples/jsm/shaders/RGBShiftShader.js +4 -2
  328. package/examples/jsm/shaders/SepiaShader.js +2 -0
  329. package/examples/jsm/shaders/ToonShader.js +13 -5
  330. package/examples/jsm/shaders/VelocityShader.js +1 -1
  331. package/examples/jsm/shaders/VerticalBlurShader.js +2 -0
  332. package/examples/jsm/shaders/VignetteShader.js +2 -0
  333. package/examples/jsm/shaders/WaterRefractionShader.js +5 -2
  334. package/examples/jsm/utils/BufferGeometryUtils.js +54 -36
  335. package/examples/jsm/utils/LDrawUtils.js +4 -4
  336. package/examples/jsm/utils/PackedPhongMaterial.js +5 -78
  337. package/examples/jsm/utils/SceneUtils.js +8 -4
  338. package/examples/jsm/utils/SkeletonUtils.js +27 -210
  339. package/examples/jsm/utils/TextureUtils.js +41 -40
  340. package/examples/jsm/webxr/VRButton.js +1 -2
  341. package/examples/jsm/webxr/XRButton.js +198 -0
  342. package/examples/jsm/webxr/XRHandPrimitiveModel.js +1 -0
  343. package/examples/jsm/webxr/XRPlanes.js +100 -0
  344. package/package.json +34 -87
  345. package/src/Three.Legacy.js +19 -110
  346. package/src/Three.js +4 -3
  347. package/src/animation/AnimationUtils.js +13 -1
  348. package/src/audio/Audio.js +7 -2
  349. package/src/audio/PositionalAudio.js +8 -0
  350. package/src/cameras/Camera.js +5 -0
  351. package/src/cameras/CubeCamera.js +76 -13
  352. package/src/cameras/OrthographicCamera.js +1 -1
  353. package/src/cameras/PerspectiveCamera.js +1 -1
  354. package/src/constants.js +22 -2
  355. package/src/core/BufferAttribute.js +150 -9
  356. package/src/core/BufferGeometry.js +4 -10
  357. package/src/core/GLBufferAttribute.js +2 -0
  358. package/src/core/InterleavedBufferAttribute.js +5 -5
  359. package/src/core/Object3D.js +37 -8
  360. package/src/extras/DataUtils.js +7 -1
  361. package/src/extras/ImageUtils.js +2 -2
  362. package/src/extras/PMREMGenerator.js +5 -5
  363. package/src/extras/core/Curve.js +1 -1
  364. package/src/extras/curves/LineCurve.js +6 -4
  365. package/src/extras/curves/LineCurve3.js +13 -0
  366. package/src/geometries/BoxGeometry.js +10 -0
  367. package/src/geometries/CircleGeometry.js +11 -1
  368. package/src/geometries/ConeGeometry.js +1 -1
  369. package/src/geometries/CylinderGeometry.js +11 -1
  370. package/src/geometries/EdgesGeometry.js +10 -0
  371. package/src/geometries/ExtrudeGeometry.js +11 -1
  372. package/src/geometries/LatheGeometry.js +10 -0
  373. package/src/geometries/PlaneGeometry.js +10 -0
  374. package/src/geometries/PolyhedronGeometry.js +11 -1
  375. package/src/geometries/RingGeometry.js +11 -1
  376. package/src/geometries/ShapeGeometry.js +11 -1
  377. package/src/geometries/SphereGeometry.js +12 -2
  378. package/src/geometries/TorusGeometry.js +11 -1
  379. package/src/geometries/TorusKnotGeometry.js +10 -0
  380. package/src/geometries/TubeGeometry.js +10 -0
  381. package/src/geometries/WireframeGeometry.js +10 -0
  382. package/src/helpers/Box3Helper.js +1 -2
  383. package/src/lights/DirectionalLight.js +1 -1
  384. package/src/lights/HemisphereLight.js +1 -1
  385. package/src/lights/SpotLight.js +1 -1
  386. package/src/loaders/AudioLoader.js +14 -8
  387. package/src/loaders/CubeTextureLoader.js +2 -0
  388. package/src/loaders/DataTextureLoader.js +5 -1
  389. package/src/loaders/MaterialLoader.js +8 -0
  390. package/src/loaders/ObjectLoader.js +10 -2
  391. package/src/materials/LineBasicMaterial.js +4 -0
  392. package/src/materials/Material.js +16 -4
  393. package/src/materials/MeshDistanceMaterial.js +0 -9
  394. package/src/materials/MeshPhysicalMaterial.js +32 -6
  395. package/src/materials/ShaderMaterial.js +6 -1
  396. package/src/math/Box2.js +3 -2
  397. package/src/math/Box3.js +49 -64
  398. package/src/math/Color.js +88 -66
  399. package/src/math/ColorManagement.js +75 -16
  400. package/src/math/Euler.js +2 -11
  401. package/src/math/Frustum.js +29 -5
  402. package/src/math/MathUtils.js +43 -1
  403. package/src/math/Matrix3.js +26 -6
  404. package/src/math/Matrix4.js +74 -19
  405. package/src/math/Plane.js +2 -2
  406. package/src/math/Quaternion.js +6 -0
  407. package/src/math/Ray.js +7 -7
  408. package/src/math/Triangle.js +37 -7
  409. package/src/math/Vector2.js +16 -0
  410. package/src/math/Vector3.js +10 -0
  411. package/src/math/interpolants/CubicInterpolant.js +1 -2
  412. package/src/objects/InstancedMesh.js +82 -1
  413. package/src/objects/Mesh.js +108 -76
  414. package/src/objects/Skeleton.js +1 -1
  415. package/src/objects/SkinnedMesh.js +123 -8
  416. package/src/objects/Sprite.js +1 -1
  417. package/src/renderers/WebGLCubeRenderTarget.js +12 -3
  418. package/src/renderers/WebGLMultipleRenderTargets.js +4 -2
  419. package/src/renderers/WebGLRenderTarget.js +14 -2
  420. package/src/renderers/WebGLRenderer.js +1433 -1236
  421. package/src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl.js +1 -1
  422. package/src/renderers/shaders/ShaderChunk/aomap_fragment.glsl.js +1 -1
  423. package/src/renderers/shaders/ShaderChunk/bsdfs.glsl.js +0 -271
  424. package/src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl.js +5 -5
  425. package/src/renderers/shaders/ShaderChunk/clearcoat_normal_fragment_maps.glsl.js +2 -10
  426. package/src/renderers/shaders/ShaderChunk/clearcoat_pars_fragment.glsl.js +5 -5
  427. package/src/renderers/shaders/ShaderChunk/common.glsl.js +32 -0
  428. package/src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl.js +1 -1
  429. package/src/renderers/shaders/ShaderChunk/displacementmap_vertex.glsl.js +1 -1
  430. package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +1 -1
  431. package/src/renderers/shaders/ShaderChunk/envmap_physical_pars_fragment.glsl.js +26 -3
  432. package/src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl.js +1 -1
  433. package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +3 -3
  434. package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +10 -2
  435. package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +11 -11
  436. package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +39 -13
  437. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +306 -10
  438. package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +2 -10
  439. package/src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl.js +9 -1
  440. package/src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl.js +10 -2
  441. package/src/renderers/shaders/ShaderChunk/metalnessmap_fragment.glsl.js +1 -1
  442. package/src/renderers/shaders/ShaderChunk/normal_fragment_begin.glsl.js +32 -10
  443. package/src/renderers/shaders/ShaderChunk/normal_fragment_maps.glsl.js +5 -13
  444. package/src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl.js +7 -7
  445. package/src/renderers/shaders/ShaderChunk/output_fragment.glsl.js +1 -2
  446. package/src/renderers/shaders/ShaderChunk/packing.glsl.js +11 -5
  447. package/src/renderers/shaders/ShaderChunk/roughnessmap_fragment.glsl.js +1 -1
  448. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +4 -11
  449. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl.js +2 -2
  450. package/src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl.js +39 -34
  451. package/src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl.js +1 -1
  452. package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +1 -1
  453. package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +5 -5
  454. package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +101 -16
  455. package/src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl.js +113 -1
  456. package/src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl.js +134 -6
  457. package/src/renderers/shaders/ShaderChunk/uv_vertex.glsl.js +116 -1
  458. package/src/renderers/shaders/ShaderChunk.js +0 -6
  459. package/src/renderers/shaders/ShaderLib/background.glsl.js +0 -8
  460. package/src/renderers/shaders/ShaderLib/linedashed.glsl.js +5 -0
  461. package/src/renderers/shaders/ShaderLib/meshbasic.glsl.js +1 -4
  462. package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +0 -3
  463. package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +3 -3
  464. package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +0 -3
  465. package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +16 -12
  466. package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +0 -3
  467. package/src/renderers/shaders/ShaderLib/points.glsl.js +13 -0
  468. package/src/renderers/shaders/ShaderLib/shadow.glsl.js +5 -0
  469. package/src/renderers/shaders/ShaderLib.js +18 -4
  470. package/src/renderers/shaders/UniformsLib.js +27 -15
  471. package/src/renderers/shaders/UniformsUtils.js +12 -3
  472. package/src/renderers/webgl/WebGLBackground.js +23 -12
  473. package/src/renderers/webgl/WebGLBindingStates.js +13 -5
  474. package/src/renderers/webgl/WebGLCapabilities.js +1 -2
  475. package/src/renderers/webgl/WebGLClipping.js +7 -3
  476. package/src/renderers/webgl/WebGLGeometries.js +12 -0
  477. package/src/renderers/webgl/WebGLInfo.js +0 -1
  478. package/src/renderers/webgl/WebGLLights.js +2 -2
  479. package/src/renderers/webgl/WebGLMaterials.js +123 -234
  480. package/src/renderers/webgl/WebGLMorphtargets.js +1 -1
  481. package/src/renderers/webgl/WebGLProgram.js +130 -48
  482. package/src/renderers/webgl/WebGLPrograms.js +210 -130
  483. package/src/renderers/webgl/WebGLRenderStates.js +2 -2
  484. package/src/renderers/webgl/WebGLShadowMap.js +40 -27
  485. package/src/renderers/webgl/WebGLState.js +23 -9
  486. package/src/renderers/webgl/WebGLTextures.js +39 -19
  487. package/src/renderers/webgl/WebGLUniformsGroups.js +74 -33
  488. package/src/renderers/webgl/WebGLUtils.js +41 -29
  489. package/src/renderers/webxr/WebXRController.js +3 -0
  490. package/src/renderers/webxr/WebXRManager.js +85 -141
  491. package/src/scenes/Scene.js +4 -6
  492. package/src/textures/CompressedTexture.js +2 -2
  493. package/src/textures/CubeTexture.js +2 -2
  494. package/src/textures/DataTexture.js +2 -2
  495. package/src/textures/DepthTexture.js +22 -0
  496. package/src/textures/FramebufferTexture.js +1 -3
  497. package/src/textures/Source.js +4 -0
  498. package/src/textures/Texture.js +43 -13
  499. package/src/utils.js +13 -1
  500. package/examples/fonts/open-sans/open-sans-v15-cyrillic-ext_greek_greek-ext_cyrillic_latin_latin-ext_vietnamese-regular.woff +0 -0
  501. package/examples/fonts/open-sans/open-sans-v15-cyrillic-ext_greek_greek-ext_cyrillic_latin_latin-ext_vietnamese-regular.woff2 +0 -0
  502. package/examples/fonts/open-sans/open-sans.css +0 -9
  503. package/examples/fonts/tabler-icons/fonts/tabler-icons.eot +0 -0
  504. package/examples/fonts/tabler-icons/fonts/tabler-icons.svg +0 -3966
  505. package/examples/fonts/tabler-icons/fonts/tabler-icons.ttf +0 -0
  506. package/examples/fonts/tabler-icons/fonts/tabler-icons.woff +0 -0
  507. package/examples/fonts/tabler-icons/fonts/tabler-icons.woff2 +0 -0
  508. package/examples/fonts/tabler-icons/tabler-icons.min.css +0 -4
  509. package/examples/js/animation/AnimationClipCreator.js +0 -89
  510. package/examples/js/animation/CCDIKSolver.js +0 -416
  511. package/examples/js/animation/MMDAnimationHelper.js +0 -1046
  512. package/examples/js/animation/MMDPhysics.js +0 -1174
  513. package/examples/js/cameras/CinematicCamera.js +0 -168
  514. package/examples/js/controls/ArcballControls.js +0 -2770
  515. package/examples/js/controls/DragControls.js +0 -205
  516. package/examples/js/controls/FirstPersonControls.js +0 -312
  517. package/examples/js/controls/FlyControls.js +0 -321
  518. package/examples/js/controls/OrbitControls.js +0 -1065
  519. package/examples/js/controls/PointerLockControls.js +0 -144
  520. package/examples/js/controls/TrackballControls.js +0 -729
  521. package/examples/js/controls/TransformControls.js +0 -1301
  522. package/examples/js/csm/CSM.js +0 -347
  523. package/examples/js/csm/CSMFrustum.js +0 -127
  524. package/examples/js/csm/CSMHelper.js +0 -165
  525. package/examples/js/csm/CSMShader.js +0 -253
  526. package/examples/js/curves/CurveExtras.js +0 -348
  527. package/examples/js/curves/NURBSCurve.js +0 -63
  528. package/examples/js/curves/NURBSSurface.js +0 -48
  529. package/examples/js/curves/NURBSUtils.js +0 -439
  530. package/examples/js/effects/AnaglyphEffect.js +0 -86
  531. package/examples/js/effects/AsciiEffect.js +0 -260
  532. package/examples/js/effects/OutlineEffect.js +0 -450
  533. package/examples/js/effects/ParallaxBarrierEffect.js +0 -62
  534. package/examples/js/effects/PeppersGhostEffect.js +0 -139
  535. package/examples/js/effects/StereoEffect.js +0 -46
  536. package/examples/js/environments/DebugEnvironment.js +0 -53
  537. package/examples/js/environments/RoomEnvironment.js +0 -124
  538. package/examples/js/exporters/ColladaExporter.js +0 -487
  539. package/examples/js/exporters/DRACOExporter.js +0 -212
  540. package/examples/js/exporters/EXRExporter.js +0 -455
  541. package/examples/js/exporters/GLTFExporter.js +0 -2425
  542. package/examples/js/exporters/MMDExporter.js +0 -187
  543. package/examples/js/exporters/OBJExporter.js +0 -260
  544. package/examples/js/exporters/PLYExporter.js +0 -427
  545. package/examples/js/exporters/STLExporter.js +0 -188
  546. package/examples/js/exporters/USDZExporter.js +0 -608
  547. package/examples/js/geometries/BoxLineGeometry.js +0 -59
  548. package/examples/js/geometries/ConvexGeometry.js +0 -53
  549. package/examples/js/geometries/DecalGeometry.js +0 -324
  550. package/examples/js/geometries/LightningStrike.js +0 -861
  551. package/examples/js/geometries/ParametricGeometries.js +0 -216
  552. package/examples/js/geometries/ParametricGeometry.js +0 -121
  553. package/examples/js/geometries/RoundedBoxGeometry.js +0 -142
  554. package/examples/js/geometries/TeapotGeometry.js +0 -335
  555. package/examples/js/geometries/TextGeometry.js +0 -53
  556. package/examples/js/helpers/LightProbeHelper.js +0 -48
  557. package/examples/js/helpers/OctreeHelper.js +0 -76
  558. package/examples/js/helpers/PositionalAudioHelper.js +0 -91
  559. package/examples/js/helpers/RectAreaLightHelper.js +0 -73
  560. package/examples/js/helpers/VertexNormalsHelper.js +0 -74
  561. package/examples/js/helpers/VertexTangentsHelper.js +0 -68
  562. package/examples/js/helpers/ViewHelper.js +0 -281
  563. package/examples/js/interactive/HTMLMesh.js +0 -497
  564. package/examples/js/interactive/InteractiveGroup.js +0 -95
  565. package/examples/js/interactive/SelectionBox.js +0 -195
  566. package/examples/js/interactive/SelectionHelper.js +0 -83
  567. package/examples/js/libs/chevrotain.min.js +0 -3
  568. package/examples/js/libs/draco/draco_decoder.js +0 -52
  569. package/examples/js/libs/draco/draco_decoder.wasm +0 -0
  570. package/examples/js/libs/draco/draco_wasm_wrapper.js +0 -104
  571. package/examples/js/libs/draco/gltf/draco_decoder.js +0 -48
  572. package/examples/js/libs/draco/gltf/draco_decoder.wasm +0 -0
  573. package/examples/js/libs/draco/gltf/draco_wasm_wrapper.js +0 -104
  574. package/examples/js/libs/fflate.min.js +0 -7
  575. package/examples/js/libs/ktx-parse.umd.js +0 -1
  576. package/examples/js/libs/meshopt_decoder.js +0 -188
  577. package/examples/js/libs/opentype.min.js +0 -1
  578. package/examples/js/libs/stats.min.js +0 -5
  579. package/examples/js/lights/LightProbeGenerator.js +0 -221
  580. package/examples/js/lights/RectAreaLightUniformsLib.js +0 -60
  581. package/examples/js/lines/Line2.js +0 -19
  582. package/examples/js/lines/LineGeometry.js +0 -69
  583. package/examples/js/lines/LineMaterial.js +0 -635
  584. package/examples/js/lines/LineSegments2.js +0 -311
  585. package/examples/js/lines/LineSegmentsGeometry.js +0 -198
  586. package/examples/js/lines/Wireframe.js +0 -47
  587. package/examples/js/lines/WireframeGeometry2.js +0 -20
  588. package/examples/js/loaders/3DMLoader.js +0 -1273
  589. package/examples/js/loaders/3MFLoader.js +0 -1306
  590. package/examples/js/loaders/AMFLoader.js +0 -504
  591. package/examples/js/loaders/BVHLoader.js +0 -395
  592. package/examples/js/loaders/BasisTextureLoader.js +0 -706
  593. package/examples/js/loaders/ColladaLoader.js +0 -3663
  594. package/examples/js/loaders/DDSLoader.js +0 -244
  595. package/examples/js/loaders/DRACOLoader.js +0 -511
  596. package/examples/js/loaders/EXRLoader.js +0 -2039
  597. package/examples/js/loaders/FBXLoader.js +0 -3680
  598. package/examples/js/loaders/FontLoader.js +0 -160
  599. package/examples/js/loaders/GCodeLoader.js +0 -255
  600. package/examples/js/loaders/GLTFLoader.js +0 -4108
  601. package/examples/js/loaders/HDRCubeTextureLoader.js +0 -87
  602. package/examples/js/loaders/KMZLoader.js +0 -121
  603. package/examples/js/loaders/KTXLoader.js +0 -159
  604. package/examples/js/loaders/LDrawLoader.js +0 -2263
  605. package/examples/js/loaders/LUT3dlLoader.js +0 -135
  606. package/examples/js/loaders/LUTCubeLoader.js +0 -132
  607. package/examples/js/loaders/LWOLoader.js +0 -901
  608. package/examples/js/loaders/LogLuvLoader.js +0 -715
  609. package/examples/js/loaders/LottieLoader.js +0 -62
  610. package/examples/js/loaders/MD2Loader.js +0 -248
  611. package/examples/js/loaders/MDDLoader.js +0 -91
  612. package/examples/js/loaders/MMDLoader.js +0 -1915
  613. package/examples/js/loaders/MTLLoader.js +0 -472
  614. package/examples/js/loaders/MaterialXLoader.js +0 -392
  615. package/examples/js/loaders/NRRDLoader.js +0 -609
  616. package/examples/js/loaders/OBJLoader.js +0 -789
  617. package/examples/js/loaders/PCDLoader.js +0 -413
  618. package/examples/js/loaders/PDBLoader.js +0 -317
  619. package/examples/js/loaders/PLYLoader.js +0 -532
  620. package/examples/js/loaders/PRWMLoader.js +0 -249
  621. package/examples/js/loaders/PVRLoader.js +0 -218
  622. package/examples/js/loaders/RGBELoader.js +0 -442
  623. package/examples/js/loaders/RGBMLoader.js +0 -1354
  624. package/examples/js/loaders/STLLoader.js +0 -364
  625. package/examples/js/loaders/SVGLoader.js +0 -2783
  626. package/examples/js/loaders/TDSLoader.js +0 -992
  627. package/examples/js/loaders/TGALoader.js +0 -484
  628. package/examples/js/loaders/TIFFLoader.js +0 -30
  629. package/examples/js/loaders/TTFLoader.js +0 -203
  630. package/examples/js/loaders/TiltLoader.js +0 -459
  631. package/examples/js/loaders/VOXLoader.js +0 -240
  632. package/examples/js/loaders/VRMLLoader.js +0 -3140
  633. package/examples/js/loaders/VTKLoader.js +0 -1078
  634. package/examples/js/loaders/XYZLoader.js +0 -89
  635. package/examples/js/loaders/lwo/IFFParser.js +0 -1067
  636. package/examples/js/loaders/lwo/LWO2Parser.js +0 -397
  637. package/examples/js/loaders/lwo/LWO3Parser.js +0 -360
  638. package/examples/js/materials/MeshGouraudMaterial.js +0 -387
  639. package/examples/js/math/Capsule.js +0 -103
  640. package/examples/js/math/ColorConverter.js +0 -33
  641. package/examples/js/math/ConvexHull.js +0 -1154
  642. package/examples/js/math/ImprovedNoise.js +0 -66
  643. package/examples/js/math/Lut.js +0 -164
  644. package/examples/js/math/MeshSurfaceSampler.js +0 -171
  645. package/examples/js/math/OBB.js +0 -382
  646. package/examples/js/math/Octree.js +0 -410
  647. package/examples/js/math/SimplexNoise.js +0 -445
  648. package/examples/js/misc/ConvexObjectBreaker.js +0 -474
  649. package/examples/js/misc/GPUComputationRenderer.js +0 -393
  650. package/examples/js/misc/Gyroscope.js +0 -56
  651. package/examples/js/misc/MD2Character.js +0 -235
  652. package/examples/js/misc/MD2CharacterComplex.js +0 -513
  653. package/examples/js/misc/MorphAnimMesh.js +0 -63
  654. package/examples/js/misc/MorphBlendMesh.js +0 -265
  655. package/examples/js/misc/ProgressiveLightMap.js +0 -335
  656. package/examples/js/misc/RollerCoaster.js +0 -430
  657. package/examples/js/misc/TubePainter.js +0 -167
  658. package/examples/js/misc/Volume.js +0 -437
  659. package/examples/js/misc/VolumeSlice.js +0 -214
  660. package/examples/js/modifiers/CurveModifier.js +0 -309
  661. package/examples/js/modifiers/EdgeSplitModifier.js +0 -228
  662. package/examples/js/modifiers/SimplifyModifier.js +0 -465
  663. package/examples/js/modifiers/TessellateModifier.js +0 -276
  664. package/examples/js/objects/GroundProjectedEnv.js +0 -181
  665. package/examples/js/objects/Lensflare.js +0 -356
  666. package/examples/js/objects/LightningStorm.js +0 -206
  667. package/examples/js/objects/MarchingCubes.js +0 -759
  668. package/examples/js/objects/Reflector.js +0 -216
  669. package/examples/js/objects/ReflectorForSSRPass.js +0 -315
  670. package/examples/js/objects/Refractor.js +0 -283
  671. package/examples/js/objects/ShadowMesh.js +0 -59
  672. package/examples/js/objects/Sky.js +0 -218
  673. package/examples/js/objects/Water.js +0 -292
  674. package/examples/js/objects/Water2.js +0 -307
  675. package/examples/js/physics/AmmoPhysics.js +0 -259
  676. package/examples/js/physics/OimoPhysics.js +0 -217
  677. package/examples/js/postprocessing/AdaptiveToneMappingPass.js +0 -335
  678. package/examples/js/postprocessing/AfterimagePass.js +0 -77
  679. package/examples/js/postprocessing/BloomPass.js +0 -135
  680. package/examples/js/postprocessing/BokehPass.js +0 -120
  681. package/examples/js/postprocessing/ClearPass.js +0 -39
  682. package/examples/js/postprocessing/CubeTexturePass.js +0 -60
  683. package/examples/js/postprocessing/DotScreenPass.js +0 -51
  684. package/examples/js/postprocessing/EffectComposer.js +0 -272
  685. package/examples/js/postprocessing/FilmPass.js +0 -52
  686. package/examples/js/postprocessing/GlitchPass.js +0 -104
  687. package/examples/js/postprocessing/HalftonePass.js +0 -75
  688. package/examples/js/postprocessing/LUTPass.js +0 -171
  689. package/examples/js/postprocessing/MaskPass.js +0 -95
  690. package/examples/js/postprocessing/OutlinePass.js +0 -598
  691. package/examples/js/postprocessing/Pass.js +0 -72
  692. package/examples/js/postprocessing/RenderPass.js +0 -70
  693. package/examples/js/postprocessing/SAOPass.js +0 -374
  694. package/examples/js/postprocessing/SMAAPass.js +0 -170
  695. package/examples/js/postprocessing/SSAARenderPass.js +0 -156
  696. package/examples/js/postprocessing/SSAOPass.js +0 -365
  697. package/examples/js/postprocessing/SSRPass.js +0 -567
  698. package/examples/js/postprocessing/SavePass.js +0 -59
  699. package/examples/js/postprocessing/ShaderPass.js +0 -64
  700. package/examples/js/postprocessing/TAARenderPass.js +0 -130
  701. package/examples/js/postprocessing/TexturePass.js +0 -49
  702. package/examples/js/postprocessing/UnrealBloomPass.js +0 -375
  703. package/examples/js/renderers/CSS2DRenderer.js +0 -178
  704. package/examples/js/renderers/CSS3DRenderer.js +0 -237
  705. package/examples/js/renderers/Projector.js +0 -818
  706. package/examples/js/renderers/SVGRenderer.js +0 -491
  707. package/examples/js/shaders/ACESFilmicToneMappingShader.js +0 -89
  708. package/examples/js/shaders/AfterimageShader.js +0 -60
  709. package/examples/js/shaders/BasicShader.js +0 -27
  710. package/examples/js/shaders/BleachBypassShader.js +0 -62
  711. package/examples/js/shaders/BlendShader.js +0 -54
  712. package/examples/js/shaders/BokehShader.js +0 -156
  713. package/examples/js/shaders/BokehShader2.js +0 -419
  714. package/examples/js/shaders/BrightnessContrastShader.js +0 -58
  715. package/examples/js/shaders/ColorCorrectionShader.js +0 -52
  716. package/examples/js/shaders/ColorifyShader.js +0 -47
  717. package/examples/js/shaders/ConvolutionShader.js +0 -92
  718. package/examples/js/shaders/CopyShader.js +0 -45
  719. package/examples/js/shaders/DOFMipMapShader.js +0 -60
  720. package/examples/js/shaders/DepthLimitedBlurShader.js +0 -173
  721. package/examples/js/shaders/DigitalGlitch.js +0 -127
  722. package/examples/js/shaders/DotScreenShader.js +0 -72
  723. package/examples/js/shaders/FXAAShader.js +0 -284
  724. package/examples/js/shaders/FilmShader.js +0 -110
  725. package/examples/js/shaders/FocusShader.js +0 -95
  726. package/examples/js/shaders/FreiChenShader.js +0 -93
  727. package/examples/js/shaders/GammaCorrectionShader.js +0 -41
  728. package/examples/js/shaders/GodRaysShader.js +0 -284
  729. package/examples/js/shaders/HalftoneShader.js +0 -336
  730. package/examples/js/shaders/HorizontalBlurShader.js +0 -59
  731. package/examples/js/shaders/HorizontalTiltShiftShader.js +0 -65
  732. package/examples/js/shaders/HueSaturationShader.js +0 -69
  733. package/examples/js/shaders/KaleidoShader.js +0 -60
  734. package/examples/js/shaders/LuminosityHighPassShader.js +0 -67
  735. package/examples/js/shaders/LuminosityShader.js +0 -46
  736. package/examples/js/shaders/MMDToonShader.js +0 -96
  737. package/examples/js/shaders/MirrorShader.js +0 -56
  738. package/examples/js/shaders/NormalMapShader.js +0 -55
  739. package/examples/js/shaders/RGBShiftShader.js +0 -56
  740. package/examples/js/shaders/SAOShader.js +0 -209
  741. package/examples/js/shaders/SMAAShader.js +0 -454
  742. package/examples/js/shaders/SSAOShader.js +0 -295
  743. package/examples/js/shaders/SSRShader.js +0 -381
  744. package/examples/js/shaders/SepiaShader.js +0 -52
  745. package/examples/js/shaders/SobelOperatorShader.js +0 -88
  746. package/examples/js/shaders/SubsurfaceScatteringShader.js +0 -49
  747. package/examples/js/shaders/TechnicolorShader.js +0 -43
  748. package/examples/js/shaders/ToneMapShader.js +0 -84
  749. package/examples/js/shaders/ToonShader.js +0 -335
  750. package/examples/js/shaders/TriangleBlurShader.js +0 -70
  751. package/examples/js/shaders/UnpackDepthRGBAShader.js +0 -47
  752. package/examples/js/shaders/VelocityShader.js +0 -126
  753. package/examples/js/shaders/VerticalBlurShader.js +0 -59
  754. package/examples/js/shaders/VerticalTiltShiftShader.js +0 -65
  755. package/examples/js/shaders/VignetteShader.js +0 -53
  756. package/examples/js/shaders/VolumeShader.js +0 -296
  757. package/examples/js/shaders/WaterRefractionShader.js +0 -84
  758. package/examples/js/textures/FlakesTexture.js +0 -40
  759. package/examples/js/utils/BufferGeometryUtils.js +0 -1160
  760. package/examples/js/utils/CameraUtils.js +0 -71
  761. package/examples/js/utils/GPUStatsPanel.js +0 -125
  762. package/examples/js/utils/GeometryCompressionUtils.js +0 -549
  763. package/examples/js/utils/GeometryUtils.js +0 -168
  764. package/examples/js/utils/LDrawUtils.js +0 -179
  765. package/examples/js/utils/PackedPhongMaterial.js +0 -109
  766. package/examples/js/utils/SceneUtils.js +0 -214
  767. package/examples/js/utils/ShadowMapViewer.js +0 -183
  768. package/examples/js/utils/SkeletonUtils.js +0 -493
  769. package/examples/js/utils/UVsDebug.js +0 -143
  770. package/examples/js/utils/WorkerPool.js +0 -105
  771. package/examples/jsm/exporters/ColladaExporter.js +0 -713
  772. package/examples/jsm/geometries/LightningStrike.js +0 -1017
  773. package/examples/jsm/libs/OimoPhysics/OimoPhysics.js +0 -37071
  774. package/examples/jsm/libs/OimoPhysics/index.js +0 -43
  775. package/examples/jsm/libs/flow.module.js +0 -4552
  776. package/examples/jsm/libs/tween.module.min.js +0 -3
  777. package/examples/jsm/loaders/BasisTextureLoader.js +0 -790
  778. package/examples/jsm/loaders/IFCLoader.js +0 -2431
  779. package/examples/jsm/loaders/PRWMLoader.js +0 -299
  780. package/examples/jsm/loaders/ifc/web-ifc-api.js +0 -47504
  781. package/examples/jsm/loaders/ifc/web-ifc.wasm +0 -0
  782. package/examples/jsm/node-editor/NodeEditor.js +0 -857
  783. package/examples/jsm/node-editor/accessors/MatcapUVEditor.js +0 -14
  784. package/examples/jsm/node-editor/accessors/NormalEditor.js +0 -30
  785. package/examples/jsm/node-editor/accessors/PositionEditor.js +0 -30
  786. package/examples/jsm/node-editor/accessors/UVEditor.js +0 -25
  787. package/examples/jsm/node-editor/core/BaseNode.js +0 -96
  788. package/examples/jsm/node-editor/core/DataFile.js +0 -59
  789. package/examples/jsm/node-editor/core/FileEditor.js +0 -20
  790. package/examples/jsm/node-editor/core/FileURLEditor.js +0 -29
  791. package/examples/jsm/node-editor/display/BlendEditor.js +0 -44
  792. package/examples/jsm/node-editor/display/NormalMapEditor.js +0 -49
  793. package/examples/jsm/node-editor/examples/animate-uv.json +0 -1
  794. package/examples/jsm/node-editor/examples/fake-top-light.json +0 -1
  795. package/examples/jsm/node-editor/examples/matcap.json +0 -1
  796. package/examples/jsm/node-editor/examples/oscillator-color.json +0 -1
  797. package/examples/jsm/node-editor/examples/rim.json +0 -1
  798. package/examples/jsm/node-editor/inputs/ColorEditor.js +0 -96
  799. package/examples/jsm/node-editor/inputs/FloatEditor.js +0 -23
  800. package/examples/jsm/node-editor/inputs/SliderEditor.js +0 -67
  801. package/examples/jsm/node-editor/inputs/TextureEditor.js +0 -155
  802. package/examples/jsm/node-editor/inputs/Vector2Editor.js +0 -28
  803. package/examples/jsm/node-editor/inputs/Vector3Editor.js +0 -30
  804. package/examples/jsm/node-editor/inputs/Vector4Editor.js +0 -37
  805. package/examples/jsm/node-editor/materials/BasicMaterialEditor.js +0 -84
  806. package/examples/jsm/node-editor/materials/PointsMaterialEditor.js +0 -102
  807. package/examples/jsm/node-editor/materials/StandardMaterialEditor.js +0 -118
  808. package/examples/jsm/node-editor/math/AngleEditor.js +0 -40
  809. package/examples/jsm/node-editor/math/DotEditor.js +0 -35
  810. package/examples/jsm/node-editor/math/InvertEditor.js +0 -39
  811. package/examples/jsm/node-editor/math/LimiterEditor.js +0 -62
  812. package/examples/jsm/node-editor/math/NormalizeEditor.js +0 -28
  813. package/examples/jsm/node-editor/math/OperatorEditor.js +0 -63
  814. package/examples/jsm/node-editor/math/PowerEditor.js +0 -44
  815. package/examples/jsm/node-editor/math/TrigonometryEditor.js +0 -45
  816. package/examples/jsm/node-editor/procedural/CheckerEditor.js +0 -27
  817. package/examples/jsm/node-editor/scene/MeshEditor.js +0 -102
  818. package/examples/jsm/node-editor/scene/Object3DEditor.js +0 -160
  819. package/examples/jsm/node-editor/scene/PointsEditor.js +0 -99
  820. package/examples/jsm/node-editor/utils/JoinEditor.js +0 -58
  821. package/examples/jsm/node-editor/utils/OscillatorEditor.js +0 -43
  822. package/examples/jsm/node-editor/utils/PreviewEditor.js +0 -170
  823. package/examples/jsm/node-editor/utils/SplitEditor.js +0 -39
  824. package/examples/jsm/node-editor/utils/TimerEditor.js +0 -58
  825. package/examples/jsm/nodes/core/CodeNode.js +0 -50
  826. package/examples/jsm/nodes/core/ExpressionNode.js +0 -32
  827. package/examples/jsm/nodes/functions/light/getDistanceAttenuation.js +0 -22
  828. package/examples/jsm/nodes/lighting/PunctualLightNode.js +0 -68
  829. package/examples/jsm/nodes/shadernode/ShaderNodeBaseElements.js +0 -301
  830. package/examples/jsm/nodes/shadernode/ShaderNodeElements.js +0 -149
  831. package/examples/jsm/objects/GroundProjectedEnv.js +0 -186
  832. package/examples/jsm/objects/LightningStorm.js +0 -245
  833. package/examples/jsm/physics/OimoPhysics.js +0 -231
  834. package/examples/jsm/postprocessing/AdaptiveToneMappingPass.js +0 -369
  835. package/examples/jsm/renderers/webgpu/WebGPUAttributes.js +0 -187
  836. package/examples/jsm/renderers/webgpu/WebGPUBackground.js +0 -173
  837. package/examples/jsm/renderers/webgpu/WebGPUBinding.js +0 -22
  838. package/examples/jsm/renderers/webgpu/WebGPUBindings.js +0 -255
  839. package/examples/jsm/renderers/webgpu/WebGPUBuffer.js +0 -43
  840. package/examples/jsm/renderers/webgpu/WebGPUComputePipelines.js +0 -78
  841. package/examples/jsm/renderers/webgpu/WebGPUGeometries.js +0 -82
  842. package/examples/jsm/renderers/webgpu/WebGPUObjects.js +0 -36
  843. package/examples/jsm/renderers/webgpu/WebGPUProgrammableStage.js +0 -22
  844. package/examples/jsm/renderers/webgpu/WebGPUProperties.js +0 -38
  845. package/examples/jsm/renderers/webgpu/WebGPURenderPipelines.js +0 -296
  846. package/examples/jsm/renderers/webgpu/WebGPURenderStates.js +0 -66
  847. package/examples/jsm/renderers/webgpu/WebGPUSampledTexture.js +0 -73
  848. package/examples/jsm/renderers/webgpu/WebGPUSampler.js +0 -29
  849. package/examples/jsm/renderers/webgpu/WebGPUStorageBuffer.js +0 -20
  850. package/examples/jsm/renderers/webgpu/WebGPUTextureRenderer.js +0 -40
  851. package/examples/jsm/renderers/webgpu/WebGPUTextures.js +0 -794
  852. package/examples/jsm/renderers/webgpu/WebGPUUniformBuffer.js +0 -18
  853. package/examples/jsm/renderers/webgpu/WebGPUUtils.js +0 -81
  854. package/examples/jsm/renderers/webgpu/nodes/WebGPUNodes.js +0 -83
  855. package/examples/jsm/shaders/ToneMapShader.js +0 -73
  856. package/src/renderers/shaders/ShaderChunk/uv2_pars_fragment.glsl.js +0 -7
  857. package/src/renderers/shaders/ShaderChunk/uv2_pars_vertex.glsl.js +0 -10
  858. package/src/renderers/shaders/ShaderChunk/uv2_vertex.glsl.js +0 -7
  859. /package/examples/{js → jsm}/libs/ammo.wasm.js +0 -0
  860. /package/examples/{js → jsm}/libs/ammo.wasm.wasm +0 -0
  861. /package/examples/{js → jsm}/libs/basis/basis_transcoder.js +0 -0
  862. /package/examples/{js → jsm}/libs/basis/basis_transcoder.wasm +0 -0
  863. /package/examples/{js → jsm}/libs/draco/README.md +0 -0
  864. /package/examples/{js → jsm}/libs/draco/draco_encoder.js +0 -0
  865. /package/examples/{js → jsm}/libs/draco/gltf/draco_encoder.js +0 -0
@@ -1,2770 +0,0 @@
1
- ( function () {
2
-
3
- //trackball state
4
- const STATE = {
5
- IDLE: Symbol(),
6
- ROTATE: Symbol(),
7
- PAN: Symbol(),
8
- SCALE: Symbol(),
9
- FOV: Symbol(),
10
- FOCUS: Symbol(),
11
- ZROTATE: Symbol(),
12
- TOUCH_MULTI: Symbol(),
13
- ANIMATION_FOCUS: Symbol(),
14
- ANIMATION_ROTATE: Symbol()
15
- };
16
- const INPUT = {
17
- NONE: Symbol(),
18
- ONE_FINGER: Symbol(),
19
- ONE_FINGER_SWITCHED: Symbol(),
20
- TWO_FINGER: Symbol(),
21
- MULT_FINGER: Symbol(),
22
- CURSOR: Symbol()
23
- };
24
-
25
- //cursor center coordinates
26
- const _center = {
27
- x: 0,
28
- y: 0
29
- };
30
-
31
- //transformation matrices for gizmos and camera
32
- const _transformation = {
33
- camera: new THREE.Matrix4(),
34
- gizmos: new THREE.Matrix4()
35
- };
36
-
37
- //events
38
- const _changeEvent = {
39
- type: 'change'
40
- };
41
- const _startEvent = {
42
- type: 'start'
43
- };
44
- const _endEvent = {
45
- type: 'end'
46
- };
47
- const _raycaster = new THREE.Raycaster();
48
- const _offset = new THREE.Vector3();
49
- const _gizmoMatrixStateTemp = new THREE.Matrix4();
50
- const _cameraMatrixStateTemp = new THREE.Matrix4();
51
- const _scalePointTemp = new THREE.Vector3();
52
- /**
53
- *
54
- * @param {Camera} camera Virtual camera used in the scene
55
- * @param {HTMLElement} domElement Renderer's dom element
56
- * @param {Scene} scene The scene to be rendered
57
- */
58
- class ArcballControls extends THREE.EventDispatcher {
59
-
60
- constructor( _camera, domElement, scene = null ) {
61
-
62
- super();
63
- this.onWindowResize = () => {
64
-
65
- const scale = ( this._gizmos.scale.x + this._gizmos.scale.y + this._gizmos.scale.z ) / 3;
66
- this._tbRadius = this.calculateTbRadius( this.camera );
67
- const newRadius = this._tbRadius / scale;
68
- const curve = new THREE.EllipseCurve( 0, 0, newRadius, newRadius );
69
- const points = curve.getPoints( this._curvePts );
70
- const curveGeometry = new THREE.BufferGeometry().setFromPoints( points );
71
- for ( const gizmo in this._gizmos.children ) {
72
-
73
- this._gizmos.children[ gizmo ].geometry = curveGeometry;
74
-
75
- }
76
-
77
- this.dispatchEvent( _changeEvent );
78
-
79
- };
80
-
81
- this.onContextMenu = event => {
82
-
83
- if ( ! this.enabled ) {
84
-
85
- return;
86
-
87
- }
88
-
89
- for ( let i = 0; i < this.mouseActions.length; i ++ ) {
90
-
91
- if ( this.mouseActions[ i ].mouse == 2 ) {
92
-
93
- //prevent only if button 2 is actually used
94
- event.preventDefault();
95
- break;
96
-
97
- }
98
-
99
- }
100
-
101
- };
102
-
103
- this.onPointerCancel = () => {
104
-
105
- this._touchStart.splice( 0, this._touchStart.length );
106
- this._touchCurrent.splice( 0, this._touchCurrent.length );
107
- this._input = INPUT.NONE;
108
-
109
- };
110
-
111
- this.onPointerDown = event => {
112
-
113
- if ( event.button == 0 && event.isPrimary ) {
114
-
115
- this._downValid = true;
116
- this._downEvents.push( event );
117
- this._downStart = performance.now();
118
-
119
- } else {
120
-
121
- this._downValid = false;
122
-
123
- }
124
-
125
- if ( event.pointerType == 'touch' && this._input != INPUT.CURSOR ) {
126
-
127
- this._touchStart.push( event );
128
- this._touchCurrent.push( event );
129
- switch ( this._input ) {
130
-
131
- case INPUT.NONE:
132
- //singleStart
133
- this._input = INPUT.ONE_FINGER;
134
- this.onSinglePanStart( event, 'ROTATE' );
135
- window.addEventListener( 'pointermove', this.onPointerMove );
136
- window.addEventListener( 'pointerup', this.onPointerUp );
137
- break;
138
- case INPUT.ONE_FINGER:
139
- case INPUT.ONE_FINGER_SWITCHED:
140
- //doubleStart
141
- this._input = INPUT.TWO_FINGER;
142
- this.onRotateStart();
143
- this.onPinchStart();
144
- this.onDoublePanStart();
145
- break;
146
- case INPUT.TWO_FINGER:
147
- //multipleStart
148
- this._input = INPUT.MULT_FINGER;
149
- this.onTriplePanStart( event );
150
- break;
151
-
152
- }
153
-
154
- } else if ( event.pointerType != 'touch' && this._input == INPUT.NONE ) {
155
-
156
- let modifier = null;
157
- if ( event.ctrlKey || event.metaKey ) {
158
-
159
- modifier = 'CTRL';
160
-
161
- } else if ( event.shiftKey ) {
162
-
163
- modifier = 'SHIFT';
164
-
165
- }
166
-
167
- this._mouseOp = this.getOpFromAction( event.button, modifier );
168
- if ( this._mouseOp != null ) {
169
-
170
- window.addEventListener( 'pointermove', this.onPointerMove );
171
- window.addEventListener( 'pointerup', this.onPointerUp );
172
-
173
- //singleStart
174
- this._input = INPUT.CURSOR;
175
- this._button = event.button;
176
- this.onSinglePanStart( event, this._mouseOp );
177
-
178
- }
179
-
180
- }
181
-
182
- };
183
-
184
- this.onPointerMove = event => {
185
-
186
- if ( event.pointerType == 'touch' && this._input != INPUT.CURSOR ) {
187
-
188
- switch ( this._input ) {
189
-
190
- case INPUT.ONE_FINGER:
191
- //singleMove
192
- this.updateTouchEvent( event );
193
- this.onSinglePanMove( event, STATE.ROTATE );
194
- break;
195
- case INPUT.ONE_FINGER_SWITCHED:
196
- const movement = this.calculatePointersDistance( this._touchCurrent[ 0 ], event ) * this._devPxRatio;
197
- if ( movement >= this._switchSensibility ) {
198
-
199
- //singleMove
200
- this._input = INPUT.ONE_FINGER;
201
- this.updateTouchEvent( event );
202
- this.onSinglePanStart( event, 'ROTATE' );
203
- break;
204
-
205
- }
206
-
207
- break;
208
- case INPUT.TWO_FINGER:
209
- //rotate/pan/pinchMove
210
- this.updateTouchEvent( event );
211
- this.onRotateMove();
212
- this.onPinchMove();
213
- this.onDoublePanMove();
214
- break;
215
- case INPUT.MULT_FINGER:
216
- //multMove
217
- this.updateTouchEvent( event );
218
- this.onTriplePanMove( event );
219
- break;
220
-
221
- }
222
-
223
- } else if ( event.pointerType != 'touch' && this._input == INPUT.CURSOR ) {
224
-
225
- let modifier = null;
226
- if ( event.ctrlKey || event.metaKey ) {
227
-
228
- modifier = 'CTRL';
229
-
230
- } else if ( event.shiftKey ) {
231
-
232
- modifier = 'SHIFT';
233
-
234
- }
235
-
236
- const mouseOpState = this.getOpStateFromAction( this._button, modifier );
237
- if ( mouseOpState != null ) {
238
-
239
- this.onSinglePanMove( event, mouseOpState );
240
-
241
- }
242
-
243
- }
244
-
245
- //checkDistance
246
- if ( this._downValid ) {
247
-
248
- const movement = this.calculatePointersDistance( this._downEvents[ this._downEvents.length - 1 ], event ) * this._devPxRatio;
249
- if ( movement > this._movementThreshold ) {
250
-
251
- this._downValid = false;
252
-
253
- }
254
-
255
- }
256
-
257
- };
258
-
259
- this.onPointerUp = event => {
260
-
261
- if ( event.pointerType == 'touch' && this._input != INPUT.CURSOR ) {
262
-
263
- const nTouch = this._touchCurrent.length;
264
- for ( let i = 0; i < nTouch; i ++ ) {
265
-
266
- if ( this._touchCurrent[ i ].pointerId == event.pointerId ) {
267
-
268
- this._touchCurrent.splice( i, 1 );
269
- this._touchStart.splice( i, 1 );
270
- break;
271
-
272
- }
273
-
274
- }
275
-
276
- switch ( this._input ) {
277
-
278
- case INPUT.ONE_FINGER:
279
- case INPUT.ONE_FINGER_SWITCHED:
280
- //singleEnd
281
- window.removeEventListener( 'pointermove', this.onPointerMove );
282
- window.removeEventListener( 'pointerup', this.onPointerUp );
283
- this._input = INPUT.NONE;
284
- this.onSinglePanEnd();
285
- break;
286
- case INPUT.TWO_FINGER:
287
- //doubleEnd
288
- this.onDoublePanEnd( event );
289
- this.onPinchEnd( event );
290
- this.onRotateEnd( event );
291
-
292
- //switching to singleStart
293
- this._input = INPUT.ONE_FINGER_SWITCHED;
294
- break;
295
- case INPUT.MULT_FINGER:
296
- if ( this._touchCurrent.length == 0 ) {
297
-
298
- window.removeEventListener( 'pointermove', this.onPointerMove );
299
- window.removeEventListener( 'pointerup', this.onPointerUp );
300
-
301
- //multCancel
302
- this._input = INPUT.NONE;
303
- this.onTriplePanEnd();
304
-
305
- }
306
-
307
- break;
308
-
309
- }
310
-
311
- } else if ( event.pointerType != 'touch' && this._input == INPUT.CURSOR ) {
312
-
313
- window.removeEventListener( 'pointermove', this.onPointerMove );
314
- window.removeEventListener( 'pointerup', this.onPointerUp );
315
- this._input = INPUT.NONE;
316
- this.onSinglePanEnd();
317
- this._button = - 1;
318
-
319
- }
320
-
321
- if ( event.isPrimary ) {
322
-
323
- if ( this._downValid ) {
324
-
325
- const downTime = event.timeStamp - this._downEvents[ this._downEvents.length - 1 ].timeStamp;
326
- if ( downTime <= this._maxDownTime ) {
327
-
328
- if ( this._nclicks == 0 ) {
329
-
330
- //first valid click detected
331
- this._nclicks = 1;
332
- this._clickStart = performance.now();
333
-
334
- } else {
335
-
336
- const clickInterval = event.timeStamp - this._clickStart;
337
- const movement = this.calculatePointersDistance( this._downEvents[ 1 ], this._downEvents[ 0 ] ) * this._devPxRatio;
338
- if ( clickInterval <= this._maxInterval && movement <= this._posThreshold ) {
339
-
340
- //second valid click detected
341
- //fire double tap and reset values
342
- this._nclicks = 0;
343
- this._downEvents.splice( 0, this._downEvents.length );
344
- this.onDoubleTap( event );
345
-
346
- } else {
347
-
348
- //new 'first click'
349
- this._nclicks = 1;
350
- this._downEvents.shift();
351
- this._clickStart = performance.now();
352
-
353
- }
354
-
355
- }
356
-
357
- } else {
358
-
359
- this._downValid = false;
360
- this._nclicks = 0;
361
- this._downEvents.splice( 0, this._downEvents.length );
362
-
363
- }
364
-
365
- } else {
366
-
367
- this._nclicks = 0;
368
- this._downEvents.splice( 0, this._downEvents.length );
369
-
370
- }
371
-
372
- }
373
-
374
- };
375
-
376
- this.onWheel = event => {
377
-
378
- if ( this.enabled && this.enableZoom ) {
379
-
380
- let modifier = null;
381
- if ( event.ctrlKey || event.metaKey ) {
382
-
383
- modifier = 'CTRL';
384
-
385
- } else if ( event.shiftKey ) {
386
-
387
- modifier = 'SHIFT';
388
-
389
- }
390
-
391
- const mouseOp = this.getOpFromAction( 'WHEEL', modifier );
392
- if ( mouseOp != null ) {
393
-
394
- event.preventDefault();
395
- this.dispatchEvent( _startEvent );
396
- const notchDeltaY = 125; //distance of one notch of mouse wheel
397
- let sgn = event.deltaY / notchDeltaY;
398
- let size = 1;
399
- if ( sgn > 0 ) {
400
-
401
- size = 1 / this.scaleFactor;
402
-
403
- } else if ( sgn < 0 ) {
404
-
405
- size = this.scaleFactor;
406
-
407
- }
408
-
409
- switch ( mouseOp ) {
410
-
411
- case 'ZOOM':
412
- this.updateTbState( STATE.SCALE, true );
413
- if ( sgn > 0 ) {
414
-
415
- size = 1 / Math.pow( this.scaleFactor, sgn );
416
-
417
- } else if ( sgn < 0 ) {
418
-
419
- size = Math.pow( this.scaleFactor, - sgn );
420
-
421
- }
422
-
423
- if ( this.cursorZoom && this.enablePan ) {
424
-
425
- let scalePoint;
426
- if ( this.camera.isOrthographicCamera ) {
427
-
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 );
429
-
430
- } else if ( this.camera.isPerspectiveCamera ) {
431
-
432
- scalePoint = this.unprojectOnTbPlane( this.camera, event.clientX, event.clientY, this.domElement ).applyQuaternion( this.camera.quaternion ).add( this._gizmos.position );
433
-
434
- }
435
-
436
- this.applyTransformMatrix( this.scale( size, scalePoint ) );
437
-
438
- } else {
439
-
440
- this.applyTransformMatrix( this.scale( size, this._gizmos.position ) );
441
-
442
- }
443
-
444
- if ( this._grid != null ) {
445
-
446
- this.disposeGrid();
447
- this.drawGrid();
448
-
449
- }
450
-
451
- this.updateTbState( STATE.IDLE, false );
452
- this.dispatchEvent( _changeEvent );
453
- this.dispatchEvent( _endEvent );
454
- break;
455
- case 'FOV':
456
- if ( this.camera.isPerspectiveCamera ) {
457
-
458
- this.updateTbState( STATE.FOV, true );
459
-
460
- //Vertigo effect
461
-
462
- // fov / 2
463
- // |\
464
- // | \
465
- // | \
466
- // x | \
467
- // | \
468
- // | \
469
- // | _ _ _\
470
- // y
471
-
472
- //check for iOs shift shortcut
473
- if ( event.deltaX != 0 ) {
474
-
475
- sgn = event.deltaX / notchDeltaY;
476
- size = 1;
477
- if ( sgn > 0 ) {
478
-
479
- size = 1 / Math.pow( this.scaleFactor, sgn );
480
-
481
- } else if ( sgn < 0 ) {
482
-
483
- size = Math.pow( this.scaleFactor, - sgn );
484
-
485
- }
486
-
487
- }
488
-
489
- this._v3_1.setFromMatrixPosition( this._cameraMatrixState );
490
- const x = this._v3_1.distanceTo( this._gizmos.position );
491
- let xNew = x / size; //distance between camera and gizmos if scale(size, scalepoint) would be performed
492
-
493
- //check min and max distance
494
- xNew = THREE.MathUtils.clamp( xNew, this.minDistance, this.maxDistance );
495
- const y = x * Math.tan( THREE.MathUtils.DEG2RAD * this.camera.fov * 0.5 );
496
-
497
- //calculate new fov
498
- let newFov = THREE.MathUtils.RAD2DEG * ( Math.atan( y / xNew ) * 2 );
499
-
500
- //check min and max fov
501
- if ( newFov > this.maxFov ) {
502
-
503
- newFov = this.maxFov;
504
-
505
- } else if ( newFov < this.minFov ) {
506
-
507
- newFov = this.minFov;
508
-
509
- }
510
-
511
- const newDistance = y / Math.tan( THREE.MathUtils.DEG2RAD * ( newFov / 2 ) );
512
- size = x / newDistance;
513
- this.setFov( newFov );
514
- this.applyTransformMatrix( this.scale( size, this._gizmos.position, false ) );
515
-
516
- }
517
-
518
- if ( this._grid != null ) {
519
-
520
- this.disposeGrid();
521
- this.drawGrid();
522
-
523
- }
524
-
525
- this.updateTbState( STATE.IDLE, false );
526
- this.dispatchEvent( _changeEvent );
527
- this.dispatchEvent( _endEvent );
528
- break;
529
-
530
- }
531
-
532
- }
533
-
534
- }
535
-
536
- };
537
-
538
- this.onSinglePanStart = ( event, operation ) => {
539
-
540
- if ( this.enabled ) {
541
-
542
- this.dispatchEvent( _startEvent );
543
- this.setCenter( event.clientX, event.clientY );
544
- switch ( operation ) {
545
-
546
- case 'PAN':
547
- if ( ! this.enablePan ) {
548
-
549
- return;
550
-
551
- }
552
-
553
- if ( this._animationId != - 1 ) {
554
-
555
- cancelAnimationFrame( this._animationId );
556
- this._animationId = - 1;
557
- this._timeStart = - 1;
558
- this.activateGizmos( false );
559
- this.dispatchEvent( _changeEvent );
560
-
561
- }
562
-
563
- this.updateTbState( STATE.PAN, true );
564
- this._startCursorPosition.copy( this.unprojectOnTbPlane( this.camera, _center.x, _center.y, this.domElement ) );
565
- if ( this.enableGrid ) {
566
-
567
- this.drawGrid();
568
- this.dispatchEvent( _changeEvent );
569
-
570
- }
571
-
572
- break;
573
- case 'ROTATE':
574
- if ( ! this.enableRotate ) {
575
-
576
- return;
577
-
578
- }
579
-
580
- if ( this._animationId != - 1 ) {
581
-
582
- cancelAnimationFrame( this._animationId );
583
- this._animationId = - 1;
584
- this._timeStart = - 1;
585
-
586
- }
587
-
588
- this.updateTbState( STATE.ROTATE, true );
589
- this._startCursorPosition.copy( this.unprojectOnTbSurface( this.camera, _center.x, _center.y, this.domElement, this._tbRadius ) );
590
- this.activateGizmos( true );
591
- if ( this.enableAnimations ) {
592
-
593
- this._timePrev = this._timeCurrent = performance.now();
594
- this._angleCurrent = this._anglePrev = 0;
595
- this._cursorPosPrev.copy( this._startCursorPosition );
596
- this._cursorPosCurr.copy( this._cursorPosPrev );
597
- this._wCurr = 0;
598
- this._wPrev = this._wCurr;
599
-
600
- }
601
-
602
- this.dispatchEvent( _changeEvent );
603
- break;
604
- case 'FOV':
605
- if ( ! this.camera.isPerspectiveCamera || ! this.enableZoom ) {
606
-
607
- return;
608
-
609
- }
610
-
611
- if ( this._animationId != - 1 ) {
612
-
613
- cancelAnimationFrame( this._animationId );
614
- this._animationId = - 1;
615
- this._timeStart = - 1;
616
- this.activateGizmos( false );
617
- this.dispatchEvent( _changeEvent );
618
-
619
- }
620
-
621
- this.updateTbState( STATE.FOV, true );
622
- this._startCursorPosition.setY( this.getCursorNDC( _center.x, _center.y, this.domElement ).y * 0.5 );
623
- this._currentCursorPosition.copy( this._startCursorPosition );
624
- break;
625
- case 'ZOOM':
626
- if ( ! this.enableZoom ) {
627
-
628
- return;
629
-
630
- }
631
-
632
- if ( this._animationId != - 1 ) {
633
-
634
- cancelAnimationFrame( this._animationId );
635
- this._animationId = - 1;
636
- this._timeStart = - 1;
637
- this.activateGizmos( false );
638
- this.dispatchEvent( _changeEvent );
639
-
640
- }
641
-
642
- this.updateTbState( STATE.SCALE, true );
643
- this._startCursorPosition.setY( this.getCursorNDC( _center.x, _center.y, this.domElement ).y * 0.5 );
644
- this._currentCursorPosition.copy( this._startCursorPosition );
645
- break;
646
-
647
- }
648
-
649
- }
650
-
651
- };
652
-
653
- this.onSinglePanMove = ( event, opState ) => {
654
-
655
- if ( this.enabled ) {
656
-
657
- const restart = opState != this._state;
658
- this.setCenter( event.clientX, event.clientY );
659
- switch ( opState ) {
660
-
661
- case STATE.PAN:
662
- if ( this.enablePan ) {
663
-
664
- if ( restart ) {
665
-
666
- //switch to pan operation
667
-
668
- this.dispatchEvent( _endEvent );
669
- this.dispatchEvent( _startEvent );
670
- this.updateTbState( opState, true );
671
- this._startCursorPosition.copy( this.unprojectOnTbPlane( this.camera, _center.x, _center.y, this.domElement ) );
672
- if ( this.enableGrid ) {
673
-
674
- this.drawGrid();
675
-
676
- }
677
-
678
- this.activateGizmos( false );
679
-
680
- } else {
681
-
682
- //continue with pan operation
683
- this._currentCursorPosition.copy( this.unprojectOnTbPlane( this.camera, _center.x, _center.y, this.domElement ) );
684
- this.applyTransformMatrix( this.pan( this._startCursorPosition, this._currentCursorPosition ) );
685
-
686
- }
687
-
688
- }
689
-
690
- break;
691
- case STATE.ROTATE:
692
- if ( this.enableRotate ) {
693
-
694
- if ( restart ) {
695
-
696
- //switch to rotate operation
697
-
698
- this.dispatchEvent( _endEvent );
699
- this.dispatchEvent( _startEvent );
700
- this.updateTbState( opState, true );
701
- this._startCursorPosition.copy( this.unprojectOnTbSurface( this.camera, _center.x, _center.y, this.domElement, this._tbRadius ) );
702
- if ( this.enableGrid ) {
703
-
704
- this.disposeGrid();
705
-
706
- }
707
-
708
- this.activateGizmos( true );
709
-
710
- } else {
711
-
712
- //continue with rotate operation
713
- this._currentCursorPosition.copy( this.unprojectOnTbSurface( this.camera, _center.x, _center.y, this.domElement, this._tbRadius ) );
714
- const distance = this._startCursorPosition.distanceTo( this._currentCursorPosition );
715
- const angle = this._startCursorPosition.angleTo( this._currentCursorPosition );
716
- const amount = Math.max( distance / this._tbRadius, angle ); //effective rotation angle
717
-
718
- this.applyTransformMatrix( this.rotate( this.calculateRotationAxis( this._startCursorPosition, this._currentCursorPosition ), amount ) );
719
- if ( this.enableAnimations ) {
720
-
721
- this._timePrev = this._timeCurrent;
722
- this._timeCurrent = performance.now();
723
- this._anglePrev = this._angleCurrent;
724
- this._angleCurrent = amount;
725
- this._cursorPosPrev.copy( this._cursorPosCurr );
726
- this._cursorPosCurr.copy( this._currentCursorPosition );
727
- this._wPrev = this._wCurr;
728
- this._wCurr = this.calculateAngularSpeed( this._anglePrev, this._angleCurrent, this._timePrev, this._timeCurrent );
729
-
730
- }
731
-
732
- }
733
-
734
- }
735
-
736
- break;
737
- case STATE.SCALE:
738
- if ( this.enableZoom ) {
739
-
740
- if ( restart ) {
741
-
742
- //switch to zoom operation
743
-
744
- this.dispatchEvent( _endEvent );
745
- this.dispatchEvent( _startEvent );
746
- this.updateTbState( opState, true );
747
- this._startCursorPosition.setY( this.getCursorNDC( _center.x, _center.y, this.domElement ).y * 0.5 );
748
- this._currentCursorPosition.copy( this._startCursorPosition );
749
- if ( this.enableGrid ) {
750
-
751
- this.disposeGrid();
752
-
753
- }
754
-
755
- this.activateGizmos( false );
756
-
757
- } else {
758
-
759
- //continue with zoom operation
760
- const screenNotches = 8; //how many wheel notches corresponds to a full screen pan
761
- this._currentCursorPosition.setY( this.getCursorNDC( _center.x, _center.y, this.domElement ).y * 0.5 );
762
- const movement = this._currentCursorPosition.y - this._startCursorPosition.y;
763
- let size = 1;
764
- if ( movement < 0 ) {
765
-
766
- size = 1 / Math.pow( this.scaleFactor, - movement * screenNotches );
767
-
768
- } else if ( movement > 0 ) {
769
-
770
- size = Math.pow( this.scaleFactor, movement * screenNotches );
771
-
772
- }
773
-
774
- this._v3_1.setFromMatrixPosition( this._gizmoMatrixState );
775
- this.applyTransformMatrix( this.scale( size, this._v3_1 ) );
776
-
777
- }
778
-
779
- }
780
-
781
- break;
782
- case STATE.FOV:
783
- if ( this.enableZoom && this.camera.isPerspectiveCamera ) {
784
-
785
- if ( restart ) {
786
-
787
- //switch to fov operation
788
-
789
- this.dispatchEvent( _endEvent );
790
- this.dispatchEvent( _startEvent );
791
- this.updateTbState( opState, true );
792
- this._startCursorPosition.setY( this.getCursorNDC( _center.x, _center.y, this.domElement ).y * 0.5 );
793
- this._currentCursorPosition.copy( this._startCursorPosition );
794
- if ( this.enableGrid ) {
795
-
796
- this.disposeGrid();
797
-
798
- }
799
-
800
- this.activateGizmos( false );
801
-
802
- } else {
803
-
804
- //continue with fov operation
805
- const screenNotches = 8; //how many wheel notches corresponds to a full screen pan
806
- this._currentCursorPosition.setY( this.getCursorNDC( _center.x, _center.y, this.domElement ).y * 0.5 );
807
- const movement = this._currentCursorPosition.y - this._startCursorPosition.y;
808
- let size = 1;
809
- if ( movement < 0 ) {
810
-
811
- size = 1 / Math.pow( this.scaleFactor, - movement * screenNotches );
812
-
813
- } else if ( movement > 0 ) {
814
-
815
- size = Math.pow( this.scaleFactor, movement * screenNotches );
816
-
817
- }
818
-
819
- this._v3_1.setFromMatrixPosition( this._cameraMatrixState );
820
- const x = this._v3_1.distanceTo( this._gizmos.position );
821
- let xNew = x / size; //distance between camera and gizmos if scale(size, scalepoint) would be performed
822
-
823
- //check min and max distance
824
- xNew = THREE.MathUtils.clamp( xNew, this.minDistance, this.maxDistance );
825
- const y = x * Math.tan( THREE.MathUtils.DEG2RAD * this._fovState * 0.5 );
826
-
827
- //calculate new fov
828
- let newFov = THREE.MathUtils.RAD2DEG * ( Math.atan( y / xNew ) * 2 );
829
-
830
- //check min and max fov
831
- newFov = THREE.MathUtils.clamp( newFov, this.minFov, this.maxFov );
832
- const newDistance = y / Math.tan( THREE.MathUtils.DEG2RAD * ( newFov / 2 ) );
833
- size = x / newDistance;
834
- this._v3_2.setFromMatrixPosition( this._gizmoMatrixState );
835
- this.setFov( newFov );
836
- this.applyTransformMatrix( this.scale( size, this._v3_2, false ) );
837
-
838
- //adjusting distance
839
- _offset.copy( this._gizmos.position ).sub( this.camera.position ).normalize().multiplyScalar( newDistance / x );
840
- this._m4_1.makeTranslation( _offset.x, _offset.y, _offset.z );
841
-
842
- }
843
-
844
- }
845
-
846
- break;
847
-
848
- }
849
-
850
- this.dispatchEvent( _changeEvent );
851
-
852
- }
853
-
854
- };
855
-
856
- this.onSinglePanEnd = () => {
857
-
858
- if ( this._state == STATE.ROTATE ) {
859
-
860
- if ( ! this.enableRotate ) {
861
-
862
- return;
863
-
864
- }
865
-
866
- if ( this.enableAnimations ) {
867
-
868
- //perform rotation animation
869
- const deltaTime = performance.now() - this._timeCurrent;
870
- if ( deltaTime < 120 ) {
871
-
872
- const w = Math.abs( ( this._wPrev + this._wCurr ) / 2 );
873
- const self = this;
874
- this._animationId = window.requestAnimationFrame( function ( t ) {
875
-
876
- self.updateTbState( STATE.ANIMATION_ROTATE, true );
877
- const rotationAxis = self.calculateRotationAxis( self._cursorPosPrev, self._cursorPosCurr );
878
- self.onRotationAnim( t, rotationAxis, Math.min( w, self.wMax ) );
879
-
880
- } );
881
-
882
- } else {
883
-
884
- //cursor has been standing still for over 120 ms since last movement
885
- this.updateTbState( STATE.IDLE, false );
886
- this.activateGizmos( false );
887
- this.dispatchEvent( _changeEvent );
888
-
889
- }
890
-
891
- } else {
892
-
893
- this.updateTbState( STATE.IDLE, false );
894
- this.activateGizmos( false );
895
- this.dispatchEvent( _changeEvent );
896
-
897
- }
898
-
899
- } else if ( this._state == STATE.PAN || this._state == STATE.IDLE ) {
900
-
901
- this.updateTbState( STATE.IDLE, false );
902
- if ( this.enableGrid ) {
903
-
904
- this.disposeGrid();
905
-
906
- }
907
-
908
- this.activateGizmos( false );
909
- this.dispatchEvent( _changeEvent );
910
-
911
- }
912
-
913
- this.dispatchEvent( _endEvent );
914
-
915
- };
916
-
917
- this.onDoubleTap = event => {
918
-
919
- if ( this.enabled && this.enablePan && this.scene != null ) {
920
-
921
- this.dispatchEvent( _startEvent );
922
- this.setCenter( event.clientX, event.clientY );
923
- const hitP = this.unprojectOnObj( this.getCursorNDC( _center.x, _center.y, this.domElement ), this.camera );
924
- if ( hitP != null && this.enableAnimations ) {
925
-
926
- const self = this;
927
- if ( this._animationId != - 1 ) {
928
-
929
- window.cancelAnimationFrame( this._animationId );
930
-
931
- }
932
-
933
- this._timeStart = - 1;
934
- this._animationId = window.requestAnimationFrame( function ( t ) {
935
-
936
- self.updateTbState( STATE.ANIMATION_FOCUS, true );
937
- self.onFocusAnim( t, hitP, self._cameraMatrixState, self._gizmoMatrixState );
938
-
939
- } );
940
-
941
- } else if ( hitP != null && ! this.enableAnimations ) {
942
-
943
- this.updateTbState( STATE.FOCUS, true );
944
- this.focus( hitP, this.scaleFactor );
945
- this.updateTbState( STATE.IDLE, false );
946
- this.dispatchEvent( _changeEvent );
947
-
948
- }
949
-
950
- }
951
-
952
- this.dispatchEvent( _endEvent );
953
-
954
- };
955
-
956
- this.onDoublePanStart = () => {
957
-
958
- if ( this.enabled && this.enablePan ) {
959
-
960
- this.dispatchEvent( _startEvent );
961
- this.updateTbState( STATE.PAN, true );
962
- this.setCenter( ( this._touchCurrent[ 0 ].clientX + this._touchCurrent[ 1 ].clientX ) / 2, ( this._touchCurrent[ 0 ].clientY + this._touchCurrent[ 1 ].clientY ) / 2 );
963
- this._startCursorPosition.copy( this.unprojectOnTbPlane( this.camera, _center.x, _center.y, this.domElement, true ) );
964
- this._currentCursorPosition.copy( this._startCursorPosition );
965
- this.activateGizmos( false );
966
-
967
- }
968
-
969
- };
970
-
971
- this.onDoublePanMove = () => {
972
-
973
- if ( this.enabled && this.enablePan ) {
974
-
975
- this.setCenter( ( this._touchCurrent[ 0 ].clientX + this._touchCurrent[ 1 ].clientX ) / 2, ( this._touchCurrent[ 0 ].clientY + this._touchCurrent[ 1 ].clientY ) / 2 );
976
- if ( this._state != STATE.PAN ) {
977
-
978
- this.updateTbState( STATE.PAN, true );
979
- this._startCursorPosition.copy( this._currentCursorPosition );
980
-
981
- }
982
-
983
- this._currentCursorPosition.copy( this.unprojectOnTbPlane( this.camera, _center.x, _center.y, this.domElement, true ) );
984
- this.applyTransformMatrix( this.pan( this._startCursorPosition, this._currentCursorPosition, true ) );
985
- this.dispatchEvent( _changeEvent );
986
-
987
- }
988
-
989
- };
990
-
991
- this.onDoublePanEnd = () => {
992
-
993
- this.updateTbState( STATE.IDLE, false );
994
- this.dispatchEvent( _endEvent );
995
-
996
- };
997
-
998
- this.onRotateStart = () => {
999
-
1000
- if ( this.enabled && this.enableRotate ) {
1001
-
1002
- this.dispatchEvent( _startEvent );
1003
- this.updateTbState( STATE.ZROTATE, true );
1004
-
1005
- //this._startFingerRotation = event.rotation;
1006
-
1007
- this._startFingerRotation = this.getAngle( this._touchCurrent[ 1 ], this._touchCurrent[ 0 ] ) + this.getAngle( this._touchStart[ 1 ], this._touchStart[ 0 ] );
1008
- this._currentFingerRotation = this._startFingerRotation;
1009
- this.camera.getWorldDirection( this._rotationAxis ); //rotation axis
1010
-
1011
- if ( ! this.enablePan && ! this.enableZoom ) {
1012
-
1013
- this.activateGizmos( true );
1014
-
1015
- }
1016
-
1017
- }
1018
-
1019
- };
1020
-
1021
- this.onRotateMove = () => {
1022
-
1023
- if ( this.enabled && this.enableRotate ) {
1024
-
1025
- this.setCenter( ( this._touchCurrent[ 0 ].clientX + this._touchCurrent[ 1 ].clientX ) / 2, ( this._touchCurrent[ 0 ].clientY + this._touchCurrent[ 1 ].clientY ) / 2 );
1026
- let rotationPoint;
1027
- if ( this._state != STATE.ZROTATE ) {
1028
-
1029
- this.updateTbState( STATE.ZROTATE, true );
1030
- this._startFingerRotation = this._currentFingerRotation;
1031
-
1032
- }
1033
-
1034
- //this._currentFingerRotation = event.rotation;
1035
- this._currentFingerRotation = this.getAngle( this._touchCurrent[ 1 ], this._touchCurrent[ 0 ] ) + this.getAngle( this._touchStart[ 1 ], this._touchStart[ 0 ] );
1036
- if ( ! this.enablePan ) {
1037
-
1038
- rotationPoint = new THREE.Vector3().setFromMatrixPosition( this._gizmoMatrixState );
1039
-
1040
- } else {
1041
-
1042
- this._v3_2.setFromMatrixPosition( this._gizmoMatrixState );
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 );
1044
-
1045
- }
1046
-
1047
- const amount = THREE.MathUtils.DEG2RAD * ( this._startFingerRotation - this._currentFingerRotation );
1048
- this.applyTransformMatrix( this.zRotate( rotationPoint, amount ) );
1049
- this.dispatchEvent( _changeEvent );
1050
-
1051
- }
1052
-
1053
- };
1054
-
1055
- this.onRotateEnd = () => {
1056
-
1057
- this.updateTbState( STATE.IDLE, false );
1058
- this.activateGizmos( false );
1059
- this.dispatchEvent( _endEvent );
1060
-
1061
- };
1062
-
1063
- this.onPinchStart = () => {
1064
-
1065
- if ( this.enabled && this.enableZoom ) {
1066
-
1067
- this.dispatchEvent( _startEvent );
1068
- this.updateTbState( STATE.SCALE, true );
1069
- this._startFingerDistance = this.calculatePointersDistance( this._touchCurrent[ 0 ], this._touchCurrent[ 1 ] );
1070
- this._currentFingerDistance = this._startFingerDistance;
1071
- this.activateGizmos( false );
1072
-
1073
- }
1074
-
1075
- };
1076
-
1077
- this.onPinchMove = () => {
1078
-
1079
- if ( this.enabled && this.enableZoom ) {
1080
-
1081
- this.setCenter( ( this._touchCurrent[ 0 ].clientX + this._touchCurrent[ 1 ].clientX ) / 2, ( this._touchCurrent[ 0 ].clientY + this._touchCurrent[ 1 ].clientY ) / 2 );
1082
- const minDistance = 12; //minimum distance between fingers (in css pixels)
1083
-
1084
- if ( this._state != STATE.SCALE ) {
1085
-
1086
- this._startFingerDistance = this._currentFingerDistance;
1087
- this.updateTbState( STATE.SCALE, true );
1088
-
1089
- }
1090
-
1091
- this._currentFingerDistance = Math.max( this.calculatePointersDistance( this._touchCurrent[ 0 ], this._touchCurrent[ 1 ] ), minDistance * this._devPxRatio );
1092
- const amount = this._currentFingerDistance / this._startFingerDistance;
1093
- let scalePoint;
1094
- if ( ! this.enablePan ) {
1095
-
1096
- scalePoint = this._gizmos.position;
1097
-
1098
- } else {
1099
-
1100
- if ( this.camera.isOrthographicCamera ) {
1101
-
1102
- scalePoint = this.unprojectOnTbPlane( this.camera, _center.x, _center.y, this.domElement ).applyQuaternion( this.camera.quaternion ).multiplyScalar( 1 / this.camera.zoom ).add( this._gizmos.position );
1103
-
1104
- } else if ( this.camera.isPerspectiveCamera ) {
1105
-
1106
- scalePoint = this.unprojectOnTbPlane( this.camera, _center.x, _center.y, this.domElement ).applyQuaternion( this.camera.quaternion ).add( this._gizmos.position );
1107
-
1108
- }
1109
-
1110
- }
1111
-
1112
- this.applyTransformMatrix( this.scale( amount, scalePoint ) );
1113
- this.dispatchEvent( _changeEvent );
1114
-
1115
- }
1116
-
1117
- };
1118
-
1119
- this.onPinchEnd = () => {
1120
-
1121
- this.updateTbState( STATE.IDLE, false );
1122
- this.dispatchEvent( _endEvent );
1123
-
1124
- };
1125
-
1126
- this.onTriplePanStart = () => {
1127
-
1128
- if ( this.enabled && this.enableZoom ) {
1129
-
1130
- this.dispatchEvent( _startEvent );
1131
- this.updateTbState( STATE.SCALE, true );
1132
-
1133
- //const center = event.center;
1134
- let clientX = 0;
1135
- let clientY = 0;
1136
- const nFingers = this._touchCurrent.length;
1137
- for ( let i = 0; i < nFingers; i ++ ) {
1138
-
1139
- clientX += this._touchCurrent[ i ].clientX;
1140
- clientY += this._touchCurrent[ i ].clientY;
1141
-
1142
- }
1143
-
1144
- this.setCenter( clientX / nFingers, clientY / nFingers );
1145
- this._startCursorPosition.setY( this.getCursorNDC( _center.x, _center.y, this.domElement ).y * 0.5 );
1146
- this._currentCursorPosition.copy( this._startCursorPosition );
1147
-
1148
- }
1149
-
1150
- };
1151
-
1152
- this.onTriplePanMove = () => {
1153
-
1154
- if ( this.enabled && this.enableZoom ) {
1155
-
1156
- // fov / 2
1157
- // |\
1158
- // | \
1159
- // | \
1160
- // x | \
1161
- // | \
1162
- // | \
1163
- // | _ _ _\
1164
- // y
1165
-
1166
- //const center = event.center;
1167
- let clientX = 0;
1168
- let clientY = 0;
1169
- const nFingers = this._touchCurrent.length;
1170
- for ( let i = 0; i < nFingers; i ++ ) {
1171
-
1172
- clientX += this._touchCurrent[ i ].clientX;
1173
- clientY += this._touchCurrent[ i ].clientY;
1174
-
1175
- }
1176
-
1177
- this.setCenter( clientX / nFingers, clientY / nFingers );
1178
- const screenNotches = 8; //how many wheel notches corresponds to a full screen pan
1179
- this._currentCursorPosition.setY( this.getCursorNDC( _center.x, _center.y, this.domElement ).y * 0.5 );
1180
- const movement = this._currentCursorPosition.y - this._startCursorPosition.y;
1181
- let size = 1;
1182
- if ( movement < 0 ) {
1183
-
1184
- size = 1 / Math.pow( this.scaleFactor, - movement * screenNotches );
1185
-
1186
- } else if ( movement > 0 ) {
1187
-
1188
- size = Math.pow( this.scaleFactor, movement * screenNotches );
1189
-
1190
- }
1191
-
1192
- this._v3_1.setFromMatrixPosition( this._cameraMatrixState );
1193
- const x = this._v3_1.distanceTo( this._gizmos.position );
1194
- let xNew = x / size; //distance between camera and gizmos if scale(size, scalepoint) would be performed
1195
-
1196
- //check min and max distance
1197
- xNew = THREE.MathUtils.clamp( xNew, this.minDistance, this.maxDistance );
1198
- const y = x * Math.tan( THREE.MathUtils.DEG2RAD * this._fovState * 0.5 );
1199
-
1200
- //calculate new fov
1201
- let newFov = THREE.MathUtils.RAD2DEG * ( Math.atan( y / xNew ) * 2 );
1202
-
1203
- //check min and max fov
1204
- newFov = THREE.MathUtils.clamp( newFov, this.minFov, this.maxFov );
1205
- const newDistance = y / Math.tan( THREE.MathUtils.DEG2RAD * ( newFov / 2 ) );
1206
- size = x / newDistance;
1207
- this._v3_2.setFromMatrixPosition( this._gizmoMatrixState );
1208
- this.setFov( newFov );
1209
- this.applyTransformMatrix( this.scale( size, this._v3_2, false ) );
1210
-
1211
- //adjusting distance
1212
- _offset.copy( this._gizmos.position ).sub( this.camera.position ).normalize().multiplyScalar( newDistance / x );
1213
- this._m4_1.makeTranslation( _offset.x, _offset.y, _offset.z );
1214
- this.dispatchEvent( _changeEvent );
1215
-
1216
- }
1217
-
1218
- };
1219
-
1220
- this.onTriplePanEnd = () => {
1221
-
1222
- this.updateTbState( STATE.IDLE, false );
1223
- this.dispatchEvent( _endEvent );
1224
- //this.dispatchEvent( _changeEvent );
1225
-
1226
- };
1227
-
1228
- this.setCenter = ( clientX, clientY ) => {
1229
-
1230
- _center.x = clientX;
1231
- _center.y = clientY;
1232
-
1233
- };
1234
-
1235
- this.initializeMouseActions = () => {
1236
-
1237
- this.setMouseAction( 'PAN', 0, 'CTRL' );
1238
- this.setMouseAction( 'PAN', 2 );
1239
- this.setMouseAction( 'ROTATE', 0 );
1240
- this.setMouseAction( 'ZOOM', 'WHEEL' );
1241
- this.setMouseAction( 'ZOOM', 1 );
1242
- this.setMouseAction( 'FOV', 'WHEEL', 'SHIFT' );
1243
- this.setMouseAction( 'FOV', 1, 'SHIFT' );
1244
-
1245
- };
1246
-
1247
- this.compareMouseAction = ( action1, action2 ) => {
1248
-
1249
- if ( action1.operation == action2.operation ) {
1250
-
1251
- if ( action1.mouse == action2.mouse && action1.key == action2.key ) {
1252
-
1253
- return true;
1254
-
1255
- } else {
1256
-
1257
- return false;
1258
-
1259
- }
1260
-
1261
- } else {
1262
-
1263
- return false;
1264
-
1265
- }
1266
-
1267
- };
1268
-
1269
- this.setMouseAction = ( operation, mouse, key = null ) => {
1270
-
1271
- const operationInput = [ 'PAN', 'ROTATE', 'ZOOM', 'FOV' ];
1272
- const mouseInput = [ 0, 1, 2, 'WHEEL' ];
1273
- const keyInput = [ 'CTRL', 'SHIFT', null ];
1274
- let state;
1275
- if ( ! operationInput.includes( operation ) || ! mouseInput.includes( mouse ) || ! keyInput.includes( key ) ) {
1276
-
1277
- //invalid parameters
1278
- return false;
1279
-
1280
- }
1281
-
1282
- if ( mouse == 'WHEEL' ) {
1283
-
1284
- if ( operation != 'ZOOM' && operation != 'FOV' ) {
1285
-
1286
- //cannot associate 2D operation to 1D input
1287
- return false;
1288
-
1289
- }
1290
-
1291
- }
1292
-
1293
- switch ( operation ) {
1294
-
1295
- case 'PAN':
1296
- state = STATE.PAN;
1297
- break;
1298
- case 'ROTATE':
1299
- state = STATE.ROTATE;
1300
- break;
1301
- case 'ZOOM':
1302
- state = STATE.SCALE;
1303
- break;
1304
- case 'FOV':
1305
- state = STATE.FOV;
1306
- break;
1307
-
1308
- }
1309
-
1310
- const action = {
1311
- operation: operation,
1312
- mouse: mouse,
1313
- key: key,
1314
- state: state
1315
- };
1316
- for ( let i = 0; i < this.mouseActions.length; i ++ ) {
1317
-
1318
- if ( this.mouseActions[ i ].mouse == action.mouse && this.mouseActions[ i ].key == action.key ) {
1319
-
1320
- this.mouseActions.splice( i, 1, action );
1321
- return true;
1322
-
1323
- }
1324
-
1325
- }
1326
-
1327
- this.mouseActions.push( action );
1328
- return true;
1329
-
1330
- };
1331
-
1332
- this.unsetMouseAction = ( mouse, key = null ) => {
1333
-
1334
- for ( let i = 0; i < this.mouseActions.length; i ++ ) {
1335
-
1336
- if ( this.mouseActions[ i ].mouse == mouse && this.mouseActions[ i ].key == key ) {
1337
-
1338
- this.mouseActions.splice( i, 1 );
1339
- return true;
1340
-
1341
- }
1342
-
1343
- }
1344
-
1345
- return false;
1346
-
1347
- };
1348
-
1349
- this.getOpFromAction = ( mouse, key ) => {
1350
-
1351
- let action;
1352
- for ( let i = 0; i < this.mouseActions.length; i ++ ) {
1353
-
1354
- action = this.mouseActions[ i ];
1355
- if ( action.mouse == mouse && action.key == key ) {
1356
-
1357
- return action.operation;
1358
-
1359
- }
1360
-
1361
- }
1362
-
1363
- if ( key != null ) {
1364
-
1365
- for ( let i = 0; i < this.mouseActions.length; i ++ ) {
1366
-
1367
- action = this.mouseActions[ i ];
1368
- if ( action.mouse == mouse && action.key == null ) {
1369
-
1370
- return action.operation;
1371
-
1372
- }
1373
-
1374
- }
1375
-
1376
- }
1377
-
1378
- return null;
1379
-
1380
- };
1381
-
1382
- this.getOpStateFromAction = ( mouse, key ) => {
1383
-
1384
- let action;
1385
- for ( let i = 0; i < this.mouseActions.length; i ++ ) {
1386
-
1387
- action = this.mouseActions[ i ];
1388
- if ( action.mouse == mouse && action.key == key ) {
1389
-
1390
- return action.state;
1391
-
1392
- }
1393
-
1394
- }
1395
-
1396
- if ( key != null ) {
1397
-
1398
- for ( let i = 0; i < this.mouseActions.length; i ++ ) {
1399
-
1400
- action = this.mouseActions[ i ];
1401
- if ( action.mouse == mouse && action.key == null ) {
1402
-
1403
- return action.state;
1404
-
1405
- }
1406
-
1407
- }
1408
-
1409
- }
1410
-
1411
- return null;
1412
-
1413
- };
1414
-
1415
- this.getAngle = ( p1, p2 ) => {
1416
-
1417
- return Math.atan2( p2.clientY - p1.clientY, p2.clientX - p1.clientX ) * 180 / Math.PI;
1418
-
1419
- };
1420
-
1421
- this.updateTouchEvent = event => {
1422
-
1423
- for ( let i = 0; i < this._touchCurrent.length; i ++ ) {
1424
-
1425
- if ( this._touchCurrent[ i ].pointerId == event.pointerId ) {
1426
-
1427
- this._touchCurrent.splice( i, 1, event );
1428
- break;
1429
-
1430
- }
1431
-
1432
- }
1433
-
1434
- };
1435
-
1436
- this.calculateAngularSpeed = ( p0, p1, t0, t1 ) => {
1437
-
1438
- const s = p1 - p0;
1439
- const t = ( t1 - t0 ) / 1000;
1440
- if ( t == 0 ) {
1441
-
1442
- return 0;
1443
-
1444
- }
1445
-
1446
- return s / t;
1447
-
1448
- };
1449
-
1450
- this.calculatePointersDistance = ( p0, p1 ) => {
1451
-
1452
- return Math.sqrt( Math.pow( p1.clientX - p0.clientX, 2 ) + Math.pow( p1.clientY - p0.clientY, 2 ) );
1453
-
1454
- };
1455
-
1456
- this.calculateRotationAxis = ( vec1, vec2 ) => {
1457
-
1458
- this._rotationMatrix.extractRotation( this._cameraMatrixState );
1459
- this._quat.setFromRotationMatrix( this._rotationMatrix );
1460
- this._rotationAxis.crossVectors( vec1, vec2 ).applyQuaternion( this._quat );
1461
- return this._rotationAxis.normalize().clone();
1462
-
1463
- };
1464
-
1465
- this.calculateTbRadius = camera => {
1466
-
1467
- const distance = camera.position.distanceTo( this._gizmos.position );
1468
- if ( camera.type == 'PerspectiveCamera' ) {
1469
-
1470
- const halfFovV = THREE.MathUtils.DEG2RAD * camera.fov * 0.5; //vertical fov/2 in radians
1471
- const halfFovH = Math.atan( camera.aspect * Math.tan( halfFovV ) ); //horizontal fov/2 in radians
1472
- return Math.tan( Math.min( halfFovV, halfFovH ) ) * distance * this.radiusFactor;
1473
-
1474
- } else if ( camera.type == 'OrthographicCamera' ) {
1475
-
1476
- return Math.min( camera.top, camera.right ) * this.radiusFactor;
1477
-
1478
- }
1479
-
1480
- };
1481
-
1482
- this.focus = ( point, size, amount = 1 ) => {
1483
-
1484
- //move center of camera (along with gizmos) towards point of interest
1485
- _offset.copy( point ).sub( this._gizmos.position ).multiplyScalar( amount );
1486
- this._translationMatrix.makeTranslation( _offset.x, _offset.y, _offset.z );
1487
- _gizmoMatrixStateTemp.copy( this._gizmoMatrixState );
1488
- this._gizmoMatrixState.premultiply( this._translationMatrix );
1489
- this._gizmoMatrixState.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale );
1490
- _cameraMatrixStateTemp.copy( this._cameraMatrixState );
1491
- this._cameraMatrixState.premultiply( this._translationMatrix );
1492
- this._cameraMatrixState.decompose( this.camera.position, this.camera.quaternion, this.camera.scale );
1493
-
1494
- //apply zoom
1495
- if ( this.enableZoom ) {
1496
-
1497
- this.applyTransformMatrix( this.scale( size, this._gizmos.position ) );
1498
-
1499
- }
1500
-
1501
- this._gizmoMatrixState.copy( _gizmoMatrixStateTemp );
1502
- this._cameraMatrixState.copy( _cameraMatrixStateTemp );
1503
-
1504
- };
1505
-
1506
- this.drawGrid = () => {
1507
-
1508
- if ( this.scene != null ) {
1509
-
1510
- const color = 0x888888;
1511
- const multiplier = 3;
1512
- let size, divisions, maxLength, tick;
1513
- if ( this.camera.isOrthographicCamera ) {
1514
-
1515
- const width = this.camera.right - this.camera.left;
1516
- const height = this.camera.bottom - this.camera.top;
1517
- maxLength = Math.max( width, height );
1518
- tick = maxLength / 20;
1519
- size = maxLength / this.camera.zoom * multiplier;
1520
- divisions = size / tick * this.camera.zoom;
1521
-
1522
- } else if ( this.camera.isPerspectiveCamera ) {
1523
-
1524
- const distance = this.camera.position.distanceTo( this._gizmos.position );
1525
- const halfFovV = THREE.MathUtils.DEG2RAD * this.camera.fov * 0.5;
1526
- const halfFovH = Math.atan( this.camera.aspect * Math.tan( halfFovV ) );
1527
- maxLength = Math.tan( Math.max( halfFovV, halfFovH ) ) * distance * 2;
1528
- tick = maxLength / 20;
1529
- size = maxLength * multiplier;
1530
- divisions = size / tick;
1531
-
1532
- }
1533
-
1534
- if ( this._grid == null ) {
1535
-
1536
- this._grid = new THREE.GridHelper( size, divisions, color, color );
1537
- this._grid.position.copy( this._gizmos.position );
1538
- this._gridPosition.copy( this._grid.position );
1539
- this._grid.quaternion.copy( this.camera.quaternion );
1540
- this._grid.rotateX( Math.PI * 0.5 );
1541
- this.scene.add( this._grid );
1542
-
1543
- }
1544
-
1545
- }
1546
-
1547
- };
1548
-
1549
- this.dispose = () => {
1550
-
1551
- if ( this._animationId != - 1 ) {
1552
-
1553
- window.cancelAnimationFrame( this._animationId );
1554
-
1555
- }
1556
-
1557
- this.domElement.removeEventListener( 'pointerdown', this.onPointerDown );
1558
- this.domElement.removeEventListener( 'pointercancel', this.onPointerCancel );
1559
- this.domElement.removeEventListener( 'wheel', this.onWheel );
1560
- this.domElement.removeEventListener( 'contextmenu', this.onContextMenu );
1561
- window.removeEventListener( 'pointermove', this.onPointerMove );
1562
- window.removeEventListener( 'pointerup', this.onPointerUp );
1563
- window.removeEventListener( 'resize', this.onWindowResize );
1564
- if ( this.scene !== null ) this.scene.remove( this._gizmos );
1565
- this.disposeGrid();
1566
-
1567
- };
1568
-
1569
- this.disposeGrid = () => {
1570
-
1571
- if ( this._grid != null && this.scene != null ) {
1572
-
1573
- this.scene.remove( this._grid );
1574
- this._grid = null;
1575
-
1576
- }
1577
-
1578
- };
1579
-
1580
- this.easeOutCubic = t => {
1581
-
1582
- return 1 - Math.pow( 1 - t, 3 );
1583
-
1584
- };
1585
-
1586
- this.activateGizmos = isActive => {
1587
-
1588
- const gizmoX = this._gizmos.children[ 0 ];
1589
- const gizmoY = this._gizmos.children[ 1 ];
1590
- const gizmoZ = this._gizmos.children[ 2 ];
1591
- if ( isActive ) {
1592
-
1593
- gizmoX.material.setValues( {
1594
- opacity: 1
1595
- } );
1596
- gizmoY.material.setValues( {
1597
- opacity: 1
1598
- } );
1599
- gizmoZ.material.setValues( {
1600
- opacity: 1
1601
- } );
1602
-
1603
- } else {
1604
-
1605
- gizmoX.material.setValues( {
1606
- opacity: 0.6
1607
- } );
1608
- gizmoY.material.setValues( {
1609
- opacity: 0.6
1610
- } );
1611
- gizmoZ.material.setValues( {
1612
- opacity: 0.6
1613
- } );
1614
-
1615
- }
1616
-
1617
- };
1618
-
1619
- this.getCursorNDC = ( cursorX, cursorY, canvas ) => {
1620
-
1621
- const canvasRect = canvas.getBoundingClientRect();
1622
- this._v2_1.setX( ( cursorX - canvasRect.left ) / canvasRect.width * 2 - 1 );
1623
- this._v2_1.setY( ( canvasRect.bottom - cursorY ) / canvasRect.height * 2 - 1 );
1624
- return this._v2_1.clone();
1625
-
1626
- };
1627
-
1628
- this.getCursorPosition = ( cursorX, cursorY, canvas ) => {
1629
-
1630
- this._v2_1.copy( this.getCursorNDC( cursorX, cursorY, canvas ) );
1631
- this._v2_1.x *= ( this.camera.right - this.camera.left ) * 0.5;
1632
- this._v2_1.y *= ( this.camera.top - this.camera.bottom ) * 0.5;
1633
- return this._v2_1.clone();
1634
-
1635
- };
1636
-
1637
- this.setCamera = camera => {
1638
-
1639
- camera.lookAt( this.target );
1640
- camera.updateMatrix();
1641
-
1642
- //setting state
1643
- if ( camera.type == 'PerspectiveCamera' ) {
1644
-
1645
- this._fov0 = camera.fov;
1646
- this._fovState = camera.fov;
1647
-
1648
- }
1649
-
1650
- this._cameraMatrixState0.copy( camera.matrix );
1651
- this._cameraMatrixState.copy( this._cameraMatrixState0 );
1652
- this._cameraProjectionState.copy( camera.projectionMatrix );
1653
- this._zoom0 = camera.zoom;
1654
- this._zoomState = this._zoom0;
1655
- this._initialNear = camera.near;
1656
- this._nearPos0 = camera.position.distanceTo( this.target ) - camera.near;
1657
- this._nearPos = this._initialNear;
1658
- this._initialFar = camera.far;
1659
- this._farPos0 = camera.position.distanceTo( this.target ) - camera.far;
1660
- this._farPos = this._initialFar;
1661
- this._up0.copy( camera.up );
1662
- this._upState.copy( camera.up );
1663
- this.camera = camera;
1664
- this.camera.updateProjectionMatrix();
1665
-
1666
- //making gizmos
1667
- this._tbRadius = this.calculateTbRadius( camera );
1668
- this.makeGizmos( this.target, this._tbRadius );
1669
-
1670
- };
1671
-
1672
- this.makeGizmos = ( tbCenter, tbRadius ) => {
1673
-
1674
- const curve = new THREE.EllipseCurve( 0, 0, tbRadius, tbRadius );
1675
- const points = curve.getPoints( this._curvePts );
1676
-
1677
- //geometry
1678
- const curveGeometry = new THREE.BufferGeometry().setFromPoints( points );
1679
-
1680
- //material
1681
- const curveMaterialX = new THREE.LineBasicMaterial( {
1682
- color: 0xff8080,
1683
- fog: false,
1684
- transparent: true,
1685
- opacity: 0.6
1686
- } );
1687
- const curveMaterialY = new THREE.LineBasicMaterial( {
1688
- color: 0x80ff80,
1689
- fog: false,
1690
- transparent: true,
1691
- opacity: 0.6
1692
- } );
1693
- const curveMaterialZ = new THREE.LineBasicMaterial( {
1694
- color: 0x8080ff,
1695
- fog: false,
1696
- transparent: true,
1697
- opacity: 0.6
1698
- } );
1699
-
1700
- //line
1701
- const gizmoX = new THREE.Line( curveGeometry, curveMaterialX );
1702
- const gizmoY = new THREE.Line( curveGeometry, curveMaterialY );
1703
- const gizmoZ = new THREE.Line( curveGeometry, curveMaterialZ );
1704
- const rotation = Math.PI * 0.5;
1705
- gizmoX.rotation.x = rotation;
1706
- gizmoY.rotation.y = rotation;
1707
-
1708
- //setting state
1709
- this._gizmoMatrixState0.identity().setPosition( tbCenter );
1710
- this._gizmoMatrixState.copy( this._gizmoMatrixState0 );
1711
- if ( this.camera.zoom !== 1 ) {
1712
-
1713
- //adapt gizmos size to camera zoom
1714
- const size = 1 / this.camera.zoom;
1715
- this._scaleMatrix.makeScale( size, size, size );
1716
- this._translationMatrix.makeTranslation( - tbCenter.x, - tbCenter.y, - tbCenter.z );
1717
- this._gizmoMatrixState.premultiply( this._translationMatrix ).premultiply( this._scaleMatrix );
1718
- this._translationMatrix.makeTranslation( tbCenter.x, tbCenter.y, tbCenter.z );
1719
- this._gizmoMatrixState.premultiply( this._translationMatrix );
1720
-
1721
- }
1722
-
1723
- this._gizmoMatrixState.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale );
1724
-
1725
- //
1726
-
1727
- this._gizmos.traverse( function ( object ) {
1728
-
1729
- if ( object.isLine ) {
1730
-
1731
- object.geometry.dispose();
1732
- object.material.dispose();
1733
-
1734
- }
1735
-
1736
- } );
1737
- this._gizmos.clear();
1738
-
1739
- //
1740
-
1741
- this._gizmos.add( gizmoX );
1742
- this._gizmos.add( gizmoY );
1743
- this._gizmos.add( gizmoZ );
1744
-
1745
- };
1746
-
1747
- this.onFocusAnim = ( time, point, cameraMatrix, gizmoMatrix ) => {
1748
-
1749
- if ( this._timeStart == - 1 ) {
1750
-
1751
- //animation start
1752
- this._timeStart = time;
1753
-
1754
- }
1755
-
1756
- if ( this._state == STATE.ANIMATION_FOCUS ) {
1757
-
1758
- const deltaTime = time - this._timeStart;
1759
- const animTime = deltaTime / this.focusAnimationTime;
1760
- this._gizmoMatrixState.copy( gizmoMatrix );
1761
- if ( animTime >= 1 ) {
1762
-
1763
- //animation end
1764
-
1765
- this._gizmoMatrixState.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale );
1766
- this.focus( point, this.scaleFactor );
1767
- this._timeStart = - 1;
1768
- this.updateTbState( STATE.IDLE, false );
1769
- this.activateGizmos( false );
1770
- this.dispatchEvent( _changeEvent );
1771
-
1772
- } else {
1773
-
1774
- const amount = this.easeOutCubic( animTime );
1775
- const size = 1 - amount + this.scaleFactor * amount;
1776
- this._gizmoMatrixState.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale );
1777
- this.focus( point, size, amount );
1778
- this.dispatchEvent( _changeEvent );
1779
- const self = this;
1780
- this._animationId = window.requestAnimationFrame( function ( t ) {
1781
-
1782
- self.onFocusAnim( t, point, cameraMatrix, gizmoMatrix.clone() );
1783
-
1784
- } );
1785
-
1786
- }
1787
-
1788
- } else {
1789
-
1790
- //interrupt animation
1791
-
1792
- this._animationId = - 1;
1793
- this._timeStart = - 1;
1794
-
1795
- }
1796
-
1797
- };
1798
-
1799
- this.onRotationAnim = ( time, rotationAxis, w0 ) => {
1800
-
1801
- if ( this._timeStart == - 1 ) {
1802
-
1803
- //animation start
1804
- this._anglePrev = 0;
1805
- this._angleCurrent = 0;
1806
- this._timeStart = time;
1807
-
1808
- }
1809
-
1810
- if ( this._state == STATE.ANIMATION_ROTATE ) {
1811
-
1812
- //w = w0 + alpha * t
1813
- const deltaTime = ( time - this._timeStart ) / 1000;
1814
- const w = w0 + - this.dampingFactor * deltaTime;
1815
- if ( w > 0 ) {
1816
-
1817
- //tetha = 0.5 * alpha * t^2 + w0 * t + tetha0
1818
- this._angleCurrent = 0.5 * - this.dampingFactor * Math.pow( deltaTime, 2 ) + w0 * deltaTime + 0;
1819
- this.applyTransformMatrix( this.rotate( rotationAxis, this._angleCurrent ) );
1820
- this.dispatchEvent( _changeEvent );
1821
- const self = this;
1822
- this._animationId = window.requestAnimationFrame( function ( t ) {
1823
-
1824
- self.onRotationAnim( t, rotationAxis, w0 );
1825
-
1826
- } );
1827
-
1828
- } else {
1829
-
1830
- this._animationId = - 1;
1831
- this._timeStart = - 1;
1832
- this.updateTbState( STATE.IDLE, false );
1833
- this.activateGizmos( false );
1834
- this.dispatchEvent( _changeEvent );
1835
-
1836
- }
1837
-
1838
- } else {
1839
-
1840
- //interrupt animation
1841
-
1842
- this._animationId = - 1;
1843
- this._timeStart = - 1;
1844
- if ( this._state != STATE.ROTATE ) {
1845
-
1846
- this.activateGizmos( false );
1847
- this.dispatchEvent( _changeEvent );
1848
-
1849
- }
1850
-
1851
- }
1852
-
1853
- };
1854
-
1855
- this.pan = ( p0, p1, adjust = false ) => {
1856
-
1857
- const movement = p0.clone().sub( p1 );
1858
- if ( this.camera.isOrthographicCamera ) {
1859
-
1860
- //adjust movement amount
1861
- movement.multiplyScalar( 1 / this.camera.zoom );
1862
-
1863
- } else if ( this.camera.isPerspectiveCamera && adjust ) {
1864
-
1865
- //adjust movement amount
1866
- this._v3_1.setFromMatrixPosition( this._cameraMatrixState0 ); //camera's initial position
1867
- this._v3_2.setFromMatrixPosition( this._gizmoMatrixState0 ); //gizmo's initial position
1868
- const distanceFactor = this._v3_1.distanceTo( this._v3_2 ) / this.camera.position.distanceTo( this._gizmos.position );
1869
- movement.multiplyScalar( 1 / distanceFactor );
1870
-
1871
- }
1872
-
1873
- this._v3_1.set( movement.x, movement.y, 0 ).applyQuaternion( this.camera.quaternion );
1874
- this._m4_1.makeTranslation( this._v3_1.x, this._v3_1.y, this._v3_1.z );
1875
- this.setTransformationMatrices( this._m4_1, this._m4_1 );
1876
- return _transformation;
1877
-
1878
- };
1879
-
1880
- this.reset = () => {
1881
-
1882
- this.camera.zoom = this._zoom0;
1883
- if ( this.camera.isPerspectiveCamera ) {
1884
-
1885
- this.camera.fov = this._fov0;
1886
-
1887
- }
1888
-
1889
- this.camera.near = this._nearPos;
1890
- this.camera.far = this._farPos;
1891
- this._cameraMatrixState.copy( this._cameraMatrixState0 );
1892
- this._cameraMatrixState.decompose( this.camera.position, this.camera.quaternion, this.camera.scale );
1893
- this.camera.up.copy( this._up0 );
1894
- this.camera.updateMatrix();
1895
- this.camera.updateProjectionMatrix();
1896
- this._gizmoMatrixState.copy( this._gizmoMatrixState0 );
1897
- this._gizmoMatrixState0.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale );
1898
- this._gizmos.updateMatrix();
1899
- this._tbRadius = this.calculateTbRadius( this.camera );
1900
- this.makeGizmos( this._gizmos.position, this._tbRadius );
1901
- this.camera.lookAt( this._gizmos.position );
1902
- this.updateTbState( STATE.IDLE, false );
1903
- this.dispatchEvent( _changeEvent );
1904
-
1905
- };
1906
-
1907
- this.rotate = ( axis, angle ) => {
1908
-
1909
- const point = this._gizmos.position; //rotation center
1910
- this._translationMatrix.makeTranslation( - point.x, - point.y, - point.z );
1911
- this._rotationMatrix.makeRotationAxis( axis, - angle );
1912
-
1913
- //rotate camera
1914
- this._m4_1.makeTranslation( point.x, point.y, point.z );
1915
- this._m4_1.multiply( this._rotationMatrix );
1916
- this._m4_1.multiply( this._translationMatrix );
1917
- this.setTransformationMatrices( this._m4_1 );
1918
- return _transformation;
1919
-
1920
- };
1921
-
1922
- this.copyState = () => {
1923
-
1924
- let state;
1925
- if ( this.camera.isOrthographicCamera ) {
1926
-
1927
- state = JSON.stringify( {
1928
- arcballState: {
1929
- cameraFar: this.camera.far,
1930
- cameraMatrix: this.camera.matrix,
1931
- cameraNear: this.camera.near,
1932
- cameraUp: this.camera.up,
1933
- cameraZoom: this.camera.zoom,
1934
- gizmoMatrix: this._gizmos.matrix
1935
- }
1936
- } );
1937
-
1938
- } else if ( this.camera.isPerspectiveCamera ) {
1939
-
1940
- state = JSON.stringify( {
1941
- arcballState: {
1942
- cameraFar: this.camera.far,
1943
- cameraFov: this.camera.fov,
1944
- cameraMatrix: this.camera.matrix,
1945
- cameraNear: this.camera.near,
1946
- cameraUp: this.camera.up,
1947
- cameraZoom: this.camera.zoom,
1948
- gizmoMatrix: this._gizmos.matrix
1949
- }
1950
- } );
1951
-
1952
- }
1953
-
1954
- navigator.clipboard.writeText( state );
1955
-
1956
- };
1957
-
1958
- this.pasteState = () => {
1959
-
1960
- const self = this;
1961
- navigator.clipboard.readText().then( function resolved( value ) {
1962
-
1963
- self.setStateFromJSON( value );
1964
-
1965
- } );
1966
-
1967
- };
1968
-
1969
- this.saveState = () => {
1970
-
1971
- this._cameraMatrixState0.copy( this.camera.matrix );
1972
- this._gizmoMatrixState0.copy( this._gizmos.matrix );
1973
- this._nearPos = this.camera.near;
1974
- this._farPos = this.camera.far;
1975
- this._zoom0 = this.camera.zoom;
1976
- this._up0.copy( this.camera.up );
1977
- if ( this.camera.isPerspectiveCamera ) {
1978
-
1979
- this._fov0 = this.camera.fov;
1980
-
1981
- }
1982
-
1983
- };
1984
-
1985
- this.scale = ( size, point, scaleGizmos = true ) => {
1986
-
1987
- _scalePointTemp.copy( point );
1988
- let sizeInverse = 1 / size;
1989
- if ( this.camera.isOrthographicCamera ) {
1990
-
1991
- //camera zoom
1992
- this.camera.zoom = this._zoomState;
1993
- this.camera.zoom *= size;
1994
-
1995
- //check min and max zoom
1996
- if ( this.camera.zoom > this.maxZoom ) {
1997
-
1998
- this.camera.zoom = this.maxZoom;
1999
- sizeInverse = this._zoomState / this.maxZoom;
2000
-
2001
- } else if ( this.camera.zoom < this.minZoom ) {
2002
-
2003
- this.camera.zoom = this.minZoom;
2004
- sizeInverse = this._zoomState / this.minZoom;
2005
-
2006
- }
2007
-
2008
- this.camera.updateProjectionMatrix();
2009
- this._v3_1.setFromMatrixPosition( this._gizmoMatrixState ); //gizmos position
2010
-
2011
- //scale gizmos so they appear in the same spot having the same dimension
2012
- this._scaleMatrix.makeScale( sizeInverse, sizeInverse, sizeInverse );
2013
- this._translationMatrix.makeTranslation( - this._v3_1.x, - this._v3_1.y, - this._v3_1.z );
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 );
2016
-
2017
- //move camera and gizmos to obtain pinch effect
2018
- _scalePointTemp.sub( this._v3_1 );
2019
- const amount = _scalePointTemp.clone().multiplyScalar( sizeInverse );
2020
- _scalePointTemp.sub( amount );
2021
- this._m4_1.makeTranslation( _scalePointTemp.x, _scalePointTemp.y, _scalePointTemp.z );
2022
- this._m4_2.premultiply( this._m4_1 );
2023
- this.setTransformationMatrices( this._m4_1, this._m4_2 );
2024
- return _transformation;
2025
-
2026
- } else if ( this.camera.isPerspectiveCamera ) {
2027
-
2028
- this._v3_1.setFromMatrixPosition( this._cameraMatrixState );
2029
- this._v3_2.setFromMatrixPosition( this._gizmoMatrixState );
2030
-
2031
- //move camera
2032
- let distance = this._v3_1.distanceTo( _scalePointTemp );
2033
- let amount = distance - distance * sizeInverse;
2034
-
2035
- //check min and max distance
2036
- const newDistance = distance - amount;
2037
- if ( newDistance < this.minDistance ) {
2038
-
2039
- sizeInverse = this.minDistance / distance;
2040
- amount = distance - distance * sizeInverse;
2041
-
2042
- } else if ( newDistance > this.maxDistance ) {
2043
-
2044
- sizeInverse = this.maxDistance / distance;
2045
- amount = distance - distance * sizeInverse;
2046
-
2047
- }
2048
-
2049
- _offset.copy( _scalePointTemp ).sub( this._v3_1 ).normalize().multiplyScalar( amount );
2050
- this._m4_1.makeTranslation( _offset.x, _offset.y, _offset.z );
2051
- if ( scaleGizmos ) {
2052
-
2053
- //scale gizmos so they appear in the same spot having the same dimension
2054
- const pos = this._v3_2;
2055
- distance = pos.distanceTo( _scalePointTemp );
2056
- amount = distance - distance * sizeInverse;
2057
- _offset.copy( _scalePointTemp ).sub( this._v3_2 ).normalize().multiplyScalar( amount );
2058
- this._translationMatrix.makeTranslation( pos.x, pos.y, pos.z );
2059
- this._scaleMatrix.makeScale( sizeInverse, sizeInverse, sizeInverse );
2060
- this._m4_2.makeTranslation( _offset.x, _offset.y, _offset.z ).multiply( this._translationMatrix );
2061
- this._m4_2.multiply( this._scaleMatrix );
2062
- this._translationMatrix.makeTranslation( - pos.x, - pos.y, - pos.z );
2063
- this._m4_2.multiply( this._translationMatrix );
2064
- this.setTransformationMatrices( this._m4_1, this._m4_2 );
2065
-
2066
- } else {
2067
-
2068
- this.setTransformationMatrices( this._m4_1 );
2069
-
2070
- }
2071
-
2072
- return _transformation;
2073
-
2074
- }
2075
-
2076
- };
2077
-
2078
- this.setFov = value => {
2079
-
2080
- if ( this.camera.isPerspectiveCamera ) {
2081
-
2082
- this.camera.fov = THREE.MathUtils.clamp( value, this.minFov, this.maxFov );
2083
- this.camera.updateProjectionMatrix();
2084
-
2085
- }
2086
-
2087
- };
2088
-
2089
- this.zRotate = ( point, angle ) => {
2090
-
2091
- this._rotationMatrix.makeRotationAxis( this._rotationAxis, angle );
2092
- this._translationMatrix.makeTranslation( - point.x, - point.y, - point.z );
2093
- this._m4_1.makeTranslation( point.x, point.y, point.z );
2094
- this._m4_1.multiply( this._rotationMatrix );
2095
- this._m4_1.multiply( this._translationMatrix );
2096
- this._v3_1.setFromMatrixPosition( this._gizmoMatrixState ).sub( point ); //vector from rotation center to gizmos position
2097
- this._v3_2.copy( this._v3_1 ).applyAxisAngle( this._rotationAxis, angle ); //apply rotation
2098
- this._v3_2.sub( this._v3_1 );
2099
- this._m4_2.makeTranslation( this._v3_2.x, this._v3_2.y, this._v3_2.z );
2100
- this.setTransformationMatrices( this._m4_1, this._m4_2 );
2101
- return _transformation;
2102
-
2103
- };
2104
-
2105
- this.unprojectOnObj = ( cursor, camera ) => {
2106
-
2107
- const raycaster = this.getRaycaster();
2108
- raycaster.near = camera.near;
2109
- raycaster.far = camera.far;
2110
- raycaster.setFromCamera( cursor, camera );
2111
- const intersect = raycaster.intersectObjects( this.scene.children, true );
2112
- for ( let i = 0; i < intersect.length; i ++ ) {
2113
-
2114
- if ( intersect[ i ].object.uuid != this._gizmos.uuid && intersect[ i ].face != null ) {
2115
-
2116
- return intersect[ i ].point.clone();
2117
-
2118
- }
2119
-
2120
- }
2121
-
2122
- return null;
2123
-
2124
- };
2125
-
2126
- this.unprojectOnTbSurface = ( camera, cursorX, cursorY, canvas, tbRadius ) => {
2127
-
2128
- if ( camera.type == 'OrthographicCamera' ) {
2129
-
2130
- this._v2_1.copy( this.getCursorPosition( cursorX, cursorY, canvas ) );
2131
- this._v3_1.set( this._v2_1.x, this._v2_1.y, 0 );
2132
- const x2 = Math.pow( this._v2_1.x, 2 );
2133
- const y2 = Math.pow( this._v2_1.y, 2 );
2134
- const r2 = Math.pow( this._tbRadius, 2 );
2135
- if ( x2 + y2 <= r2 * 0.5 ) {
2136
-
2137
- //intersection with sphere
2138
- this._v3_1.setZ( Math.sqrt( r2 - ( x2 + y2 ) ) );
2139
-
2140
- } else {
2141
-
2142
- //intersection with hyperboloid
2143
- this._v3_1.setZ( r2 * 0.5 / Math.sqrt( x2 + y2 ) );
2144
-
2145
- }
2146
-
2147
- return this._v3_1;
2148
-
2149
- } else if ( camera.type == 'PerspectiveCamera' ) {
2150
-
2151
- //unproject cursor on the near plane
2152
- this._v2_1.copy( this.getCursorNDC( cursorX, cursorY, canvas ) );
2153
- this._v3_1.set( this._v2_1.x, this._v2_1.y, - 1 );
2154
- this._v3_1.applyMatrix4( camera.projectionMatrixInverse );
2155
- const rayDir = this._v3_1.clone().normalize(); //unprojected ray direction
2156
- const cameraGizmoDistance = camera.position.distanceTo( this._gizmos.position );
2157
- const radius2 = Math.pow( tbRadius, 2 );
2158
-
2159
- // camera
2160
- // |\
2161
- // | \
2162
- // | \
2163
- // h | \
2164
- // | \
2165
- // | \
2166
- // _ _ | _ _ _\ _ _ near plane
2167
- // l
2168
-
2169
- const h = this._v3_1.z;
2170
- const l = Math.sqrt( Math.pow( this._v3_1.x, 2 ) + Math.pow( this._v3_1.y, 2 ) );
2171
- if ( l == 0 ) {
2172
-
2173
- //ray aligned with camera
2174
- rayDir.set( this._v3_1.x, this._v3_1.y, tbRadius );
2175
- return rayDir;
2176
-
2177
- }
2178
-
2179
- const m = h / l;
2180
- const q = cameraGizmoDistance;
2181
-
2182
- /*
2183
- * calculate intersection point between unprojected ray and trackball surface
2184
- *|y = m * x + q
2185
- *|x^2 + y^2 = r^2
2186
- *
2187
- * (m^2 + 1) * x^2 + (2 * m * q) * x + q^2 - r^2 = 0
2188
- */
2189
- let a = Math.pow( m, 2 ) + 1;
2190
- let b = 2 * m * q;
2191
- let c = Math.pow( q, 2 ) - radius2;
2192
- let delta = Math.pow( b, 2 ) - 4 * a * c;
2193
- if ( delta >= 0 ) {
2194
-
2195
- //intersection with sphere
2196
- this._v2_1.setX( ( - b - Math.sqrt( delta ) ) / ( 2 * a ) );
2197
- this._v2_1.setY( m * this._v2_1.x + q );
2198
- const angle = THREE.MathUtils.RAD2DEG * this._v2_1.angle();
2199
- if ( angle >= 45 ) {
2200
-
2201
- //if angle between intersection point and X' axis is >= 45°, return that point
2202
- //otherwise, calculate intersection point with hyperboloid
2203
-
2204
- const rayLength = Math.sqrt( Math.pow( this._v2_1.x, 2 ) + Math.pow( cameraGizmoDistance - this._v2_1.y, 2 ) );
2205
- rayDir.multiplyScalar( rayLength );
2206
- rayDir.z += cameraGizmoDistance;
2207
- return rayDir;
2208
-
2209
- }
2210
-
2211
- }
2212
-
2213
- //intersection with hyperboloid
2214
- /*
2215
- *|y = m * x + q
2216
- *|y = (1 / x) * (r^2 / 2)
2217
- *
2218
- * m * x^2 + q * x - r^2 / 2 = 0
2219
- */
2220
-
2221
- a = m;
2222
- b = q;
2223
- c = - radius2 * 0.5;
2224
- delta = Math.pow( b, 2 ) - 4 * a * c;
2225
- this._v2_1.setX( ( - b - Math.sqrt( delta ) ) / ( 2 * a ) );
2226
- this._v2_1.setY( m * this._v2_1.x + q );
2227
- const rayLength = Math.sqrt( Math.pow( this._v2_1.x, 2 ) + Math.pow( cameraGizmoDistance - this._v2_1.y, 2 ) );
2228
- rayDir.multiplyScalar( rayLength );
2229
- rayDir.z += cameraGizmoDistance;
2230
- return rayDir;
2231
-
2232
- }
2233
-
2234
- };
2235
-
2236
- this.unprojectOnTbPlane = ( camera, cursorX, cursorY, canvas, initialDistance = false ) => {
2237
-
2238
- if ( camera.type == 'OrthographicCamera' ) {
2239
-
2240
- this._v2_1.copy( this.getCursorPosition( cursorX, cursorY, canvas ) );
2241
- this._v3_1.set( this._v2_1.x, this._v2_1.y, 0 );
2242
- return this._v3_1.clone();
2243
-
2244
- } else if ( camera.type == 'PerspectiveCamera' ) {
2245
-
2246
- this._v2_1.copy( this.getCursorNDC( cursorX, cursorY, canvas ) );
2247
-
2248
- //unproject cursor on the near plane
2249
- this._v3_1.set( this._v2_1.x, this._v2_1.y, - 1 );
2250
- this._v3_1.applyMatrix4( camera.projectionMatrixInverse );
2251
- const rayDir = this._v3_1.clone().normalize(); //unprojected ray direction
2252
-
2253
- // camera
2254
- // |\
2255
- // | \
2256
- // | \
2257
- // h | \
2258
- // | \
2259
- // | \
2260
- // _ _ | _ _ _\ _ _ near plane
2261
- // l
2262
-
2263
- const h = this._v3_1.z;
2264
- const l = Math.sqrt( Math.pow( this._v3_1.x, 2 ) + Math.pow( this._v3_1.y, 2 ) );
2265
- let cameraGizmoDistance;
2266
- if ( initialDistance ) {
2267
-
2268
- cameraGizmoDistance = this._v3_1.setFromMatrixPosition( this._cameraMatrixState0 ).distanceTo( this._v3_2.setFromMatrixPosition( this._gizmoMatrixState0 ) );
2269
-
2270
- } else {
2271
-
2272
- cameraGizmoDistance = camera.position.distanceTo( this._gizmos.position );
2273
-
2274
- }
2275
-
2276
- /*
2277
- * calculate intersection point between unprojected ray and the plane
2278
- *|y = mx + q
2279
- *|y = 0
2280
- *
2281
- * x = -q/m
2282
- */
2283
- if ( l == 0 ) {
2284
-
2285
- //ray aligned with camera
2286
- rayDir.set( 0, 0, 0 );
2287
- return rayDir;
2288
-
2289
- }
2290
-
2291
- const m = h / l;
2292
- const q = cameraGizmoDistance;
2293
- const x = - q / m;
2294
- const rayLength = Math.sqrt( Math.pow( q, 2 ) + Math.pow( x, 2 ) );
2295
- rayDir.multiplyScalar( rayLength );
2296
- rayDir.z = 0;
2297
- return rayDir;
2298
-
2299
- }
2300
-
2301
- };
2302
-
2303
- this.updateMatrixState = () => {
2304
-
2305
- //update camera and gizmos state
2306
- this._cameraMatrixState.copy( this.camera.matrix );
2307
- this._gizmoMatrixState.copy( this._gizmos.matrix );
2308
- if ( this.camera.isOrthographicCamera ) {
2309
-
2310
- this._cameraProjectionState.copy( this.camera.projectionMatrix );
2311
- this.camera.updateProjectionMatrix();
2312
- this._zoomState = this.camera.zoom;
2313
-
2314
- } else if ( this.camera.isPerspectiveCamera ) {
2315
-
2316
- this._fovState = this.camera.fov;
2317
-
2318
- }
2319
-
2320
- };
2321
-
2322
- this.updateTbState = ( newState, updateMatrices ) => {
2323
-
2324
- this._state = newState;
2325
- if ( updateMatrices ) {
2326
-
2327
- this.updateMatrixState();
2328
-
2329
- }
2330
-
2331
- };
2332
-
2333
- this.update = () => {
2334
-
2335
- const EPS = 0.000001;
2336
- if ( this.target.equals( this._currentTarget ) === false ) {
2337
-
2338
- this._gizmos.position.copy( this.target ); //for correct radius calculation
2339
- this._tbRadius = this.calculateTbRadius( this.camera );
2340
- this.makeGizmos( this.target, this._tbRadius );
2341
- this._currentTarget.copy( this.target );
2342
-
2343
- }
2344
-
2345
- //check min/max parameters
2346
- if ( this.camera.isOrthographicCamera ) {
2347
-
2348
- //check zoom
2349
- if ( this.camera.zoom > this.maxZoom || this.camera.zoom < this.minZoom ) {
2350
-
2351
- const newZoom = THREE.MathUtils.clamp( this.camera.zoom, this.minZoom, this.maxZoom );
2352
- this.applyTransformMatrix( this.scale( newZoom / this.camera.zoom, this._gizmos.position, true ) );
2353
-
2354
- }
2355
-
2356
- } else if ( this.camera.isPerspectiveCamera ) {
2357
-
2358
- //check distance
2359
- const distance = this.camera.position.distanceTo( this._gizmos.position );
2360
- if ( distance > this.maxDistance + EPS || distance < this.minDistance - EPS ) {
2361
-
2362
- const newDistance = THREE.MathUtils.clamp( distance, this.minDistance, this.maxDistance );
2363
- this.applyTransformMatrix( this.scale( newDistance / distance, this._gizmos.position ) );
2364
- this.updateMatrixState();
2365
-
2366
- }
2367
-
2368
- //check fov
2369
- if ( this.camera.fov < this.minFov || this.camera.fov > this.maxFov ) {
2370
-
2371
- this.camera.fov = THREE.MathUtils.clamp( this.camera.fov, this.minFov, this.maxFov );
2372
- this.camera.updateProjectionMatrix();
2373
-
2374
- }
2375
-
2376
- const oldRadius = this._tbRadius;
2377
- this._tbRadius = this.calculateTbRadius( this.camera );
2378
- if ( oldRadius < this._tbRadius - EPS || oldRadius > this._tbRadius + EPS ) {
2379
-
2380
- const scale = ( this._gizmos.scale.x + this._gizmos.scale.y + this._gizmos.scale.z ) / 3;
2381
- const newRadius = this._tbRadius / scale;
2382
- const curve = new THREE.EllipseCurve( 0, 0, newRadius, newRadius );
2383
- const points = curve.getPoints( this._curvePts );
2384
- const curveGeometry = new THREE.BufferGeometry().setFromPoints( points );
2385
- for ( const gizmo in this._gizmos.children ) {
2386
-
2387
- this._gizmos.children[ gizmo ].geometry = curveGeometry;
2388
-
2389
- }
2390
-
2391
- }
2392
-
2393
- }
2394
-
2395
- this.camera.lookAt( this._gizmos.position );
2396
-
2397
- };
2398
-
2399
- this.setStateFromJSON = json => {
2400
-
2401
- const state = JSON.parse( json );
2402
- if ( state.arcballState != undefined ) {
2403
-
2404
- this._cameraMatrixState.fromArray( state.arcballState.cameraMatrix.elements );
2405
- this._cameraMatrixState.decompose( this.camera.position, this.camera.quaternion, this.camera.scale );
2406
- this.camera.up.copy( state.arcballState.cameraUp );
2407
- this.camera.near = state.arcballState.cameraNear;
2408
- this.camera.far = state.arcballState.cameraFar;
2409
- this.camera.zoom = state.arcballState.cameraZoom;
2410
- if ( this.camera.isPerspectiveCamera ) {
2411
-
2412
- this.camera.fov = state.arcballState.cameraFov;
2413
-
2414
- }
2415
-
2416
- this._gizmoMatrixState.fromArray( state.arcballState.gizmoMatrix.elements );
2417
- this._gizmoMatrixState.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale );
2418
- this.camera.updateMatrix();
2419
- this.camera.updateProjectionMatrix();
2420
- this._gizmos.updateMatrix();
2421
- this._tbRadius = this.calculateTbRadius( this.camera );
2422
- const gizmoTmp = new THREE.Matrix4().copy( this._gizmoMatrixState0 );
2423
- this.makeGizmos( this._gizmos.position, this._tbRadius );
2424
- this._gizmoMatrixState0.copy( gizmoTmp );
2425
- this.camera.lookAt( this._gizmos.position );
2426
- this.updateTbState( STATE.IDLE, false );
2427
- this.dispatchEvent( _changeEvent );
2428
-
2429
- }
2430
-
2431
- };
2432
-
2433
- this.camera = null;
2434
- this.domElement = domElement;
2435
- this.scene = scene;
2436
- this.target = new THREE.Vector3();
2437
- this._currentTarget = new THREE.Vector3();
2438
- this.radiusFactor = 0.67;
2439
- this.mouseActions = [];
2440
- this._mouseOp = null;
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)
2443
- this._v2_1 = new THREE.Vector2();
2444
- this._v3_1 = new THREE.Vector3();
2445
- this._v3_2 = new THREE.Vector3();
2446
- this._m4_1 = new THREE.Matrix4();
2447
- this._m4_2 = new THREE.Matrix4();
2448
- this._quat = new THREE.Quaternion();
2449
-
2450
- //transformation matrices
2451
- this._translationMatrix = new THREE.Matrix4(); //matrix for translation operation
2452
- this._rotationMatrix = new THREE.Matrix4(); //matrix for rotation operation
2453
- this._scaleMatrix = new THREE.Matrix4(); //matrix for scaling operation
2454
-
2455
- this._rotationAxis = new THREE.Vector3(); //axis for rotate operation
2456
-
2457
- //camera state
2458
- this._cameraMatrixState = new THREE.Matrix4();
2459
- this._cameraProjectionState = new THREE.Matrix4();
2460
- this._fovState = 1;
2461
- this._upState = new THREE.Vector3();
2462
- this._zoomState = 1;
2463
- this._nearPos = 0;
2464
- this._farPos = 0;
2465
- this._gizmoMatrixState = new THREE.Matrix4();
2466
-
2467
- //initial values
2468
- this._up0 = new THREE.Vector3();
2469
- this._zoom0 = 1;
2470
- this._fov0 = 0;
2471
- this._initialNear = 0;
2472
- this._nearPos0 = 0;
2473
- this._initialFar = 0;
2474
- this._farPos0 = 0;
2475
- this._cameraMatrixState0 = new THREE.Matrix4();
2476
- this._gizmoMatrixState0 = new THREE.Matrix4();
2477
-
2478
- //pointers array
2479
- this._button = - 1;
2480
- this._touchStart = [];
2481
- this._touchCurrent = [];
2482
- this._input = INPUT.NONE;
2483
-
2484
- //two fingers touch interaction
2485
- this._switchSensibility = 32; //minimum movement to be performed to fire single pan start after the second finger has been released
2486
- this._startFingerDistance = 0; //distance between two fingers
2487
- this._currentFingerDistance = 0;
2488
- this._startFingerRotation = 0; //amount of rotation performed with two fingers
2489
- this._currentFingerRotation = 0;
2490
-
2491
- //double tap
2492
- this._devPxRatio = 0;
2493
- this._downValid = true;
2494
- this._nclicks = 0;
2495
- this._downEvents = [];
2496
- this._downStart = 0; //pointerDown time
2497
- this._clickStart = 0; //first click time
2498
- this._maxDownTime = 250;
2499
- this._maxInterval = 300;
2500
- this._posThreshold = 24;
2501
- this._movementThreshold = 24;
2502
-
2503
- //cursor positions
2504
- this._currentCursorPosition = new THREE.Vector3();
2505
- this._startCursorPosition = new THREE.Vector3();
2506
-
2507
- //grid
2508
- this._grid = null; //grid to be visualized during pan operation
2509
- this._gridPosition = new THREE.Vector3();
2510
-
2511
- //gizmos
2512
- this._gizmos = new THREE.Group();
2513
- this._curvePts = 128;
2514
-
2515
- //animations
2516
- this._timeStart = - 1; //initial time
2517
- this._animationId = - 1;
2518
-
2519
- //focus animation
2520
- this.focusAnimationTime = 500; //duration of focus animation in ms
2521
-
2522
- //rotate animation
2523
- this._timePrev = 0; //time at which previous rotate operation has been detected
2524
- this._timeCurrent = 0; //time at which current rotate operation has been detected
2525
- this._anglePrev = 0; //angle of previous rotation
2526
- this._angleCurrent = 0; //angle of current rotation
2527
- this._cursorPosPrev = new THREE.Vector3(); //cursor position when previous rotate operation has been detected
2528
- this._cursorPosCurr = new THREE.Vector3(); //cursor position when current rotate operation has been detected
2529
- this._wPrev = 0; //angular velocity of the previous rotate operation
2530
- this._wCurr = 0; //angular velocity of the current rotate operation
2531
-
2532
- //parameters
2533
- this.adjustNearFar = false;
2534
- this.scaleFactor = 1.1; //zoom/distance multiplier
2535
- this.dampingFactor = 25;
2536
- this.wMax = 20; //maximum angular velocity allowed
2537
- this.enableAnimations = true; //if animations should be performed
2538
- this.enableGrid = false; //if grid should be showed during pan operation
2539
- this.cursorZoom = false; //if wheel zoom should be cursor centered
2540
- this.minFov = 5;
2541
- this.maxFov = 90;
2542
- this.enabled = true;
2543
- this.enablePan = true;
2544
- this.enableRotate = true;
2545
- this.enableZoom = true;
2546
- this.enableGizmos = true;
2547
- this.minDistance = 0;
2548
- this.maxDistance = Infinity;
2549
- this.minZoom = 0;
2550
- this.maxZoom = Infinity;
2551
-
2552
- //trackball parameters
2553
- this._tbRadius = 1;
2554
-
2555
- //FSA
2556
- this._state = STATE.IDLE;
2557
- this.setCamera( _camera );
2558
- if ( this.scene != null ) {
2559
-
2560
- this.scene.add( this._gizmos );
2561
-
2562
- }
2563
-
2564
- this.domElement.style.touchAction = 'none';
2565
- this._devPxRatio = window.devicePixelRatio;
2566
- this.initializeMouseActions();
2567
- this.domElement.addEventListener( 'contextmenu', this.onContextMenu );
2568
- this.domElement.addEventListener( 'wheel', this.onWheel );
2569
- this.domElement.addEventListener( 'pointerdown', this.onPointerDown );
2570
- this.domElement.addEventListener( 'pointercancel', this.onPointerCancel );
2571
- window.addEventListener( 'resize', this.onWindowResize );
2572
-
2573
- }
2574
-
2575
- //listeners
2576
-
2577
- /**
2578
- * Apply a transformation matrix, to the camera and gizmos
2579
- * @param {Object} transformation Object containing matrices to apply to camera and gizmos
2580
- */
2581
- applyTransformMatrix( transformation ) {
2582
-
2583
- if ( transformation.camera != null ) {
2584
-
2585
- this._m4_1.copy( this._cameraMatrixState ).premultiply( transformation.camera );
2586
- this._m4_1.decompose( this.camera.position, this.camera.quaternion, this.camera.scale );
2587
- this.camera.updateMatrix();
2588
-
2589
- //update camera up vector
2590
- if ( this._state == STATE.ROTATE || this._state == STATE.ZROTATE || this._state == STATE.ANIMATION_ROTATE ) {
2591
-
2592
- this.camera.up.copy( this._upState ).applyQuaternion( this.camera.quaternion );
2593
-
2594
- }
2595
-
2596
- }
2597
-
2598
- if ( transformation.gizmos != null ) {
2599
-
2600
- this._m4_1.copy( this._gizmoMatrixState ).premultiply( transformation.gizmos );
2601
- this._m4_1.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale );
2602
- this._gizmos.updateMatrix();
2603
-
2604
- }
2605
-
2606
- if ( this._state == STATE.SCALE || this._state == STATE.FOCUS || this._state == STATE.ANIMATION_FOCUS ) {
2607
-
2608
- this._tbRadius = this.calculateTbRadius( this.camera );
2609
- if ( this.adjustNearFar ) {
2610
-
2611
- const cameraDistance = this.camera.position.distanceTo( this._gizmos.position );
2612
- const bb = new THREE.Box3();
2613
- bb.setFromObject( this._gizmos );
2614
- const sphere = new THREE.Sphere();
2615
- bb.getBoundingSphere( sphere );
2616
- const adjustedNearPosition = Math.max( this._nearPos0, sphere.radius + sphere.center.length() );
2617
- const regularNearPosition = cameraDistance - this._initialNear;
2618
- const minNearPos = Math.min( adjustedNearPosition, regularNearPosition );
2619
- this.camera.near = cameraDistance - minNearPos;
2620
- const adjustedFarPosition = Math.min( this._farPos0, - sphere.radius + sphere.center.length() );
2621
- const regularFarPosition = cameraDistance - this._initialFar;
2622
- const minFarPos = Math.min( adjustedFarPosition, regularFarPosition );
2623
- this.camera.far = cameraDistance - minFarPos;
2624
- this.camera.updateProjectionMatrix();
2625
-
2626
- } else {
2627
-
2628
- let update = false;
2629
- if ( this.camera.near != this._initialNear ) {
2630
-
2631
- this.camera.near = this._initialNear;
2632
- update = true;
2633
-
2634
- }
2635
-
2636
- if ( this.camera.far != this._initialFar ) {
2637
-
2638
- this.camera.far = this._initialFar;
2639
- update = true;
2640
-
2641
- }
2642
-
2643
- if ( update ) {
2644
-
2645
- this.camera.updateProjectionMatrix();
2646
-
2647
- }
2648
-
2649
- }
2650
-
2651
- }
2652
-
2653
- }
2654
-
2655
- /**
2656
- * Calculate the angular speed
2657
- * @param {Number} p0 Position at t0
2658
- * @param {Number} p1 Position at t1
2659
- * @param {Number} t0 Initial time in milliseconds
2660
- * @param {Number} t1 Ending time in milliseconds
2661
- */
2662
-
2663
- /**
2664
- * Set gizmos visibility
2665
- * @param {Boolean} value Value of gizmos visibility
2666
- */
2667
- setGizmosVisible( value ) {
2668
-
2669
- this._gizmos.visible = value;
2670
- this.dispatchEvent( _changeEvent );
2671
-
2672
- }
2673
-
2674
- /**
2675
- * Set gizmos radius factor and redraws gizmos
2676
- * @param {Float} value Value of radius factor
2677
- */
2678
- setTbRadius( value ) {
2679
-
2680
- this.radiusFactor = value;
2681
- this._tbRadius = this.calculateTbRadius( this.camera );
2682
- const curve = new THREE.EllipseCurve( 0, 0, this._tbRadius, this._tbRadius );
2683
- const points = curve.getPoints( this._curvePts );
2684
- const curveGeometry = new THREE.BufferGeometry().setFromPoints( points );
2685
- for ( const gizmo in this._gizmos.children ) {
2686
-
2687
- this._gizmos.children[ gizmo ].geometry = curveGeometry;
2688
-
2689
- }
2690
-
2691
- this.dispatchEvent( _changeEvent );
2692
-
2693
- }
2694
-
2695
- /**
2696
- * Creates the rotation gizmos matching trackball center and radius
2697
- * @param {Vector3} tbCenter The trackball center
2698
- * @param {number} tbRadius The trackball radius
2699
- */
2700
-
2701
- /**
2702
- * Set values in transformation object
2703
- * @param {Matrix4} camera Transformation to be applied to the camera
2704
- * @param {Matrix4} gizmos Transformation to be applied to gizmos
2705
- */
2706
- setTransformationMatrices( camera = null, gizmos = null ) {
2707
-
2708
- if ( camera != null ) {
2709
-
2710
- if ( _transformation.camera != null ) {
2711
-
2712
- _transformation.camera.copy( camera );
2713
-
2714
- } else {
2715
-
2716
- _transformation.camera = camera.clone();
2717
-
2718
- }
2719
-
2720
- } else {
2721
-
2722
- _transformation.camera = null;
2723
-
2724
- }
2725
-
2726
- if ( gizmos != null ) {
2727
-
2728
- if ( _transformation.gizmos != null ) {
2729
-
2730
- _transformation.gizmos.copy( gizmos );
2731
-
2732
- } else {
2733
-
2734
- _transformation.gizmos = gizmos.clone();
2735
-
2736
- }
2737
-
2738
- } else {
2739
-
2740
- _transformation.gizmos = null;
2741
-
2742
- }
2743
-
2744
- }
2745
-
2746
- /**
2747
- * Rotate camera around its direction axis passing by a given point by a given angle
2748
- * @param {Vector3} point The point where the rotation axis is passing trough
2749
- * @param {Number} angle Angle in radians
2750
- * @returns The computed transormation matix
2751
- */
2752
-
2753
- getRaycaster() {
2754
-
2755
- return _raycaster;
2756
-
2757
- }
2758
-
2759
- /**
2760
- * Unproject the cursor on the 3D object surface
2761
- * @param {Vector2} cursor Cursor coordinates in NDC
2762
- * @param {Camera} camera Virtual camera
2763
- * @returns {Vector3} The point of intersection with the model, if exist, null otherwise
2764
- */
2765
-
2766
- }
2767
-
2768
- THREE.ArcballControls = ArcballControls;
2769
-
2770
- } )();