super-three 0.167.0 → 0.169.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.
- package/build/three.cjs +532 -173
- package/build/three.module.js +532 -174
- package/build/three.module.min.js +1 -1
- package/build/three.webgpu.js +18173 -14266
- package/build/three.webgpu.min.js +1 -1
- package/build/three.webgpu.nodes.js +79941 -0
- package/build/three.webgpu.nodes.min.js +6 -0
- package/examples/jsm/Addons.js +0 -4
- package/examples/jsm/animation/AnimationClipCreator.js +1 -1
- package/examples/jsm/capabilities/WebGL.js +27 -21
- package/examples/jsm/controls/ArcballControls.js +174 -158
- package/examples/jsm/controls/DragControls.js +260 -132
- package/examples/jsm/controls/FirstPersonControls.js +175 -163
- package/examples/jsm/controls/FlyControls.js +194 -188
- package/examples/jsm/controls/OrbitControls.js +777 -786
- package/examples/jsm/controls/PointerLockControls.js +24 -15
- package/examples/jsm/controls/TrackballControls.js +469 -448
- package/examples/jsm/controls/TransformControls.js +97 -62
- package/examples/jsm/effects/AnaglyphEffect.js +6 -13
- package/examples/jsm/effects/ParallaxBarrierEffect.js +17 -11
- package/examples/jsm/effects/StereoEffect.js +6 -1
- package/examples/jsm/environments/RoomEnvironment.js +1 -1
- package/examples/jsm/exporters/DRACOExporter.js +4 -2
- package/examples/jsm/exporters/EXRExporter.js +19 -11
- package/examples/jsm/exporters/GLTFExporter.js +6 -1
- package/examples/jsm/exporters/KTX2Exporter.js +21 -13
- package/examples/jsm/exporters/OBJExporter.js +5 -1
- package/examples/jsm/exporters/PLYExporter.js +9 -7
- package/examples/jsm/exporters/USDZExporter.js +29 -8
- package/examples/jsm/geometries/DecalGeometry.js +4 -1
- package/examples/jsm/geometries/InstancedPointsGeometry.js +1 -1
- package/examples/jsm/helpers/LightProbeHelper.js +43 -44
- package/examples/jsm/helpers/LightProbeHelperGPU.js +65 -0
- package/examples/jsm/libs/basis/basis_transcoder.js +8 -10
- package/examples/jsm/libs/basis/basis_transcoder.wasm +0 -0
- package/examples/jsm/libs/ktx-parse.module.js +1 -1
- package/examples/jsm/lights/LightProbeGenerator.js +24 -10
- package/examples/jsm/loaders/ColladaLoader.js +9 -6
- package/examples/jsm/loaders/DRACOLoader.js +3 -1
- package/examples/jsm/loaders/FBXLoader.js +30 -20
- package/examples/jsm/loaders/GLTFLoader.js +5 -10
- package/examples/jsm/loaders/KTX2Loader.js +27 -12
- package/examples/jsm/loaders/MTLLoader.js +4 -3
- package/examples/jsm/loaders/MaterialXLoader.js +40 -14
- package/examples/jsm/loaders/OBJLoader.js +5 -3
- package/examples/jsm/loaders/PCDLoader.js +14 -13
- package/examples/jsm/loaders/PDBLoader.js +3 -2
- package/examples/jsm/loaders/PLYLoader.js +8 -5
- package/examples/jsm/loaders/STLLoader.js +3 -2
- package/examples/jsm/loaders/VRMLLoader.js +10 -10
- package/examples/jsm/loaders/VTKLoader.js +4 -3
- package/examples/jsm/loaders/XYZLoader.js +3 -2
- package/examples/jsm/misc/Timer.js +1 -1
- package/examples/jsm/modifiers/CurveModifierGPU.js +233 -0
- package/examples/jsm/objects/LensflareMesh.js +322 -0
- package/examples/jsm/objects/SkyMesh.js +187 -0
- package/examples/jsm/objects/Water2Mesh.js +158 -0
- package/examples/jsm/objects/WaterMesh.js +101 -0
- package/examples/jsm/physics/JoltPhysics.js +1 -1
- package/examples/jsm/physics/RapierPhysics.js +21 -1
- package/examples/jsm/postprocessing/OutlinePass.js +31 -46
- package/examples/jsm/postprocessing/SSAARenderPass.js +3 -1
- package/examples/jsm/shaders/BleachBypassShader.js +1 -2
- package/examples/jsm/shaders/OutputShader.js +1 -1
- package/examples/jsm/transpiler/GLSLDecoder.js +1 -1
- package/examples/jsm/transpiler/ShaderToyDecoder.js +2 -2
- package/examples/jsm/transpiler/TSLEncoder.js +8 -8
- package/examples/jsm/utils/GeometryCompressionUtils.js +37 -122
- package/examples/jsm/utils/ShadowMapViewer.js +3 -8
- package/examples/jsm/utils/ShadowMapViewerGPU.js +201 -0
- package/examples/jsm/utils/SkeletonUtils.js +84 -66
- package/examples/jsm/utils/TextureUtils.js +2 -1
- package/examples/jsm/utils/TextureUtilsGPU.js +63 -0
- package/examples/jsm/webxr/XRControllerModelFactory.js +1 -1
- package/package.json +3 -2
- package/src/Three.WebGPU.Nodes.js +200 -0
- package/src/Three.WebGPU.js +7 -0
- package/src/Three.js +1 -0
- package/src/audio/Audio.js +2 -2
- package/src/constants.js +1 -1
- package/src/core/BufferAttribute.js +0 -9
- package/src/core/Clock.js +1 -1
- package/src/core/InterleavedBuffer.js +0 -9
- package/src/extras/Controls.js +32 -0
- package/src/geometries/CylinderGeometry.js +11 -4
- package/src/loaders/MaterialLoader.js +7 -1
- package/src/loaders/ObjectLoader.js +3 -3
- package/src/{nodes/loaders → loaders/nodes}/NodeLoader.js +25 -5
- package/src/{nodes/loaders → loaders/nodes}/NodeMaterialLoader.js +21 -18
- package/src/{nodes/loaders → loaders/nodes}/NodeObjectLoader.js +19 -0
- package/src/materials/Material.js +4 -7
- package/src/materials/nodes/InstancedPointsNodeMaterial.js +156 -0
- package/src/{nodes/materials → materials/nodes}/Line2NodeMaterial.js +56 -59
- package/src/{nodes/materials → materials/nodes}/LineBasicNodeMaterial.js +8 -5
- package/src/{nodes/materials → materials/nodes}/LineDashedNodeMaterial.js +12 -10
- package/src/{nodes/materials → materials/nodes}/MeshBasicNodeMaterial.js +16 -12
- package/src/{nodes/materials → materials/nodes}/MeshLambertNodeMaterial.js +10 -6
- package/src/{nodes/materials → materials/nodes}/MeshMatcapNodeMaterial.js +13 -9
- package/src/{nodes/materials → materials/nodes}/MeshNormalNodeMaterial.js +13 -9
- package/src/{nodes/materials → materials/nodes}/MeshPhongNodeMaterial.js +14 -9
- package/src/{nodes/materials → materials/nodes}/MeshPhysicalNodeMaterial.js +22 -18
- package/src/{nodes/materials → materials/nodes}/MeshSSSNodeMaterial.js +10 -7
- package/src/{nodes/materials → materials/nodes}/MeshStandardNodeMaterial.js +22 -12
- package/src/{nodes/materials → materials/nodes}/MeshToonNodeMaterial.js +9 -5
- package/src/{nodes/materials → materials/nodes}/NodeMaterial.js +71 -115
- package/src/{nodes/materials/Materials.js → materials/nodes/NodeMaterials.js} +3 -1
- package/src/{nodes/materials → materials/nodes}/PointsNodeMaterial.js +8 -5
- package/src/{nodes/materials → materials/nodes}/ShadowNodeMaterial.js +9 -5
- package/src/{nodes/materials → materials/nodes}/SpriteNodeMaterial.js +47 -14
- package/src/{nodes/materials → materials/nodes}/VolumeNodeMaterial.js +24 -22
- package/src/materials/nodes/manager/NodeMaterialObserver.js +302 -0
- package/src/math/Triangle.js +24 -0
- package/src/nodes/Nodes.js +103 -159
- package/src/nodes/TSL.js +179 -0
- package/src/nodes/accessors/AccessorsUtils.js +8 -8
- package/src/nodes/accessors/BatchNode.js +53 -21
- package/src/nodes/accessors/{BitangentNode.js → Bitangent.js} +9 -9
- package/src/nodes/accessors/BufferAttributeNode.js +8 -5
- package/src/nodes/accessors/BufferNode.js +7 -4
- package/src/nodes/accessors/Camera.js +13 -0
- package/src/nodes/accessors/ClippingNode.js +19 -13
- package/src/nodes/accessors/CubeTextureNode.js +9 -8
- package/src/nodes/accessors/InstanceNode.js +19 -15
- package/src/nodes/accessors/InstancedPointsMaterialNode.js +8 -5
- package/src/nodes/accessors/Lights.js +51 -0
- package/src/nodes/accessors/MaterialNode.js +56 -55
- package/src/nodes/accessors/MaterialProperties.js +3 -0
- package/src/nodes/accessors/MaterialReferenceNode.js +9 -4
- package/src/nodes/accessors/ModelNode.js +47 -12
- package/src/nodes/accessors/ModelViewProjectionNode.js +12 -9
- package/src/nodes/accessors/MorphNode.js +17 -13
- package/src/nodes/accessors/Normal.js +88 -0
- package/src/nodes/accessors/Object3DNode.js +17 -33
- package/src/nodes/accessors/PointUVNode.js +9 -5
- package/src/nodes/accessors/Position.js +10 -0
- package/src/nodes/accessors/ReferenceBaseNode.js +171 -0
- package/src/nodes/accessors/ReferenceNode.js +50 -7
- package/src/nodes/accessors/ReflectVector.js +10 -0
- package/src/nodes/accessors/RendererReferenceNode.js +12 -6
- package/src/nodes/accessors/SceneNode.js +9 -6
- package/src/nodes/accessors/SkinningNode.js +88 -21
- package/src/nodes/accessors/StorageBufferNode.js +22 -5
- package/src/nodes/accessors/StorageTextureNode.js +9 -6
- package/src/nodes/accessors/Tangent.js +22 -0
- package/src/nodes/accessors/Texture3DNode.js +16 -13
- package/src/nodes/accessors/{TextureBicubicNode.js → TextureBicubic.js} +3 -32
- package/src/nodes/accessors/TextureNode.js +29 -23
- package/src/nodes/accessors/TextureSizeNode.js +10 -9
- package/src/nodes/accessors/{UniformsNode.js → UniformArrayNode.js} +26 -14
- package/src/nodes/accessors/UserDataNode.js +10 -7
- package/src/nodes/accessors/VelocityNode.js +134 -0
- package/src/nodes/accessors/VertexColorNode.js +7 -4
- package/src/nodes/code/CodeNode.js +9 -5
- package/src/nodes/code/ExpressionNode.js +10 -6
- package/src/nodes/code/FunctionCallNode.js +8 -5
- package/src/nodes/code/FunctionNode.js +8 -23
- package/src/nodes/code/ScriptableNode.js +13 -10
- package/src/nodes/code/ScriptableValueNode.js +9 -7
- package/src/nodes/core/AssignNode.js +12 -9
- package/src/nodes/core/AttributeNode.js +12 -21
- package/src/nodes/core/BypassNode.js +11 -7
- package/src/nodes/core/CacheNode.js +10 -6
- package/src/nodes/core/ConstNode.js +6 -3
- package/src/nodes/core/ContextNode.js +21 -11
- package/src/nodes/core/IndexNode.js +35 -8
- package/src/nodes/core/InputNode.js +7 -3
- package/src/nodes/core/MRTNode.js +16 -7
- package/src/nodes/core/Node.js +19 -40
- package/src/nodes/core/NodeBuilder.js +117 -38
- package/src/nodes/core/NodeUtils.js +49 -6
- package/src/nodes/core/OutputStructNode.js +10 -6
- package/src/nodes/core/ParameterNode.js +7 -4
- package/src/nodes/core/PropertyNode.js +36 -32
- package/src/nodes/core/StackNode.js +31 -11
- package/src/nodes/core/StructTypeNode.js +7 -3
- package/src/nodes/core/TempNode.js +8 -4
- package/src/nodes/core/UniformGroupNode.js +14 -11
- package/src/nodes/core/UniformNode.js +7 -4
- package/src/nodes/core/VarNode.js +12 -8
- package/src/nodes/core/VaryingNode.js +10 -6
- package/src/nodes/display/AfterImageNode.js +15 -9
- package/src/nodes/display/AnaglyphPassNode.js +67 -0
- package/src/nodes/display/AnamorphicNode.js +17 -11
- package/src/nodes/display/BleachBypass.js +26 -0
- package/src/nodes/display/BlendMode.js +54 -0
- package/src/nodes/display/BloomNode.js +27 -19
- package/src/nodes/display/BumpMapNode.js +13 -12
- package/src/nodes/display/ColorAdjustment.js +46 -0
- package/src/nodes/display/ColorSpaceFunctions.js +38 -0
- package/src/nodes/display/ColorSpaceNode.js +67 -61
- package/src/nodes/display/DenoiseNode.js +23 -17
- package/src/nodes/display/DepthOfFieldNode.js +12 -7
- package/src/nodes/display/DotScreenNode.js +13 -22
- package/src/nodes/display/FXAANode.js +21 -16
- package/src/nodes/display/FilmNode.js +11 -7
- package/src/nodes/display/FrontFacingNode.js +10 -6
- package/src/nodes/display/GTAONode.js +22 -15
- package/src/nodes/display/GaussianBlurNode.js +14 -8
- package/src/nodes/display/Lut3DNode.js +10 -6
- package/src/nodes/display/MotionBlur.js +25 -0
- package/src/nodes/display/NormalMapNode.js +13 -13
- package/src/nodes/display/ParallaxBarrierPassNode.js +58 -0
- package/src/nodes/display/PassNode.js +95 -8
- package/src/nodes/display/PixelationPassNode.js +20 -8
- package/src/nodes/display/PosterizeNode.js +8 -7
- package/src/nodes/display/RGBShiftNode.js +11 -7
- package/src/nodes/display/RenderOutputNode.js +15 -11
- package/src/nodes/display/SSAAPassNode.js +287 -0
- package/src/nodes/display/ScreenNode.js +181 -0
- package/src/nodes/display/Sepia.js +17 -0
- package/src/nodes/display/SobelOperatorNode.js +13 -8
- package/src/nodes/display/StereoCompositePassNode.js +110 -0
- package/src/nodes/display/StereoPassNode.js +83 -0
- package/src/nodes/display/ToneMappingFunctions.js +190 -0
- package/src/nodes/display/ToneMappingNode.js +15 -175
- package/src/nodes/display/ToonOutlinePassNode.js +111 -0
- package/src/nodes/display/TransitionNode.js +12 -8
- package/src/nodes/display/ViewportDepthNode.js +34 -29
- package/src/nodes/display/ViewportDepthTextureNode.js +10 -9
- package/src/nodes/display/ViewportSharedTextureNode.js +10 -9
- package/src/nodes/display/ViewportTextureNode.js +11 -11
- package/src/nodes/fog/FogExp2Node.js +8 -7
- package/src/nodes/fog/FogNode.js +10 -8
- package/src/nodes/fog/FogRangeNode.js +8 -7
- package/src/nodes/functions/BSDF/BRDF_GGX.js +4 -4
- package/src/nodes/functions/BSDF/BRDF_Lambert.js +2 -2
- package/src/nodes/functions/BSDF/BRDF_Sheen.js +6 -6
- package/src/nodes/functions/BSDF/DFGApprox.js +2 -2
- package/src/nodes/functions/BSDF/D_GGX.js +2 -2
- package/src/nodes/functions/BSDF/D_GGX_Anisotropic.js +3 -3
- package/src/nodes/functions/BSDF/EnvironmentBRDF.js +2 -2
- package/src/nodes/functions/BSDF/F_Schlick.js +2 -2
- package/src/nodes/functions/BSDF/LTC.js +6 -6
- package/src/nodes/functions/BSDF/Schlick_to_F0.js +2 -2
- package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +2 -2
- package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +2 -2
- package/src/nodes/functions/BasicLightingModel.js +1 -1
- package/src/nodes/functions/PhongLightingModel.js +5 -5
- package/src/nodes/functions/PhysicalLightingModel.js +34 -33
- package/src/nodes/functions/ShadowMaskModel.js +1 -1
- package/src/nodes/functions/ToonLightingModel.js +3 -3
- package/src/nodes/functions/material/getGeometryRoughness.js +4 -4
- package/src/nodes/functions/material/getRoughness.js +2 -2
- package/src/nodes/functions/material/getShIrradianceAt.js +28 -0
- package/src/nodes/geometry/RangeNode.js +9 -5
- package/src/nodes/gpgpu/AtomicFunctionNode.js +99 -0
- package/src/nodes/gpgpu/BarrierNode.js +40 -0
- package/src/nodes/gpgpu/ComputeBuiltinNode.js +98 -0
- package/src/nodes/gpgpu/ComputeNode.js +10 -6
- package/src/nodes/gpgpu/WorkgroupInfoNode.js +100 -0
- package/src/nodes/lighting/AONode.js +6 -3
- package/src/nodes/lighting/AmbientLightNode.js +6 -8
- package/src/nodes/lighting/AnalyticLightNode.js +225 -36
- package/src/nodes/lighting/BasicEnvironmentNode.js +8 -4
- package/src/nodes/lighting/BasicLightMapNode.js +7 -4
- package/src/nodes/lighting/DirectionalLightNode.js +7 -9
- package/src/nodes/lighting/EnvironmentNode.js +23 -19
- package/src/nodes/lighting/HemisphereLightNode.js +11 -11
- package/src/nodes/lighting/IESSpotLightNode.js +7 -9
- package/src/nodes/lighting/IrradianceNode.js +6 -3
- package/src/nodes/lighting/LightProbeNode.js +53 -0
- package/src/nodes/lighting/LightUtils.js +3 -3
- package/src/nodes/lighting/LightingContextNode.js +19 -18
- package/src/nodes/lighting/LightingNode.js +7 -3
- package/src/nodes/lighting/LightsNode.js +112 -75
- package/src/nodes/lighting/PointLightNode.js +12 -13
- package/src/nodes/lighting/RectAreaLightNode.js +11 -11
- package/src/nodes/lighting/SpotLightNode.js +14 -16
- package/src/nodes/materialx/MaterialXNodes.js +2 -2
- package/src/nodes/materialx/lib/mx_hsv.js +36 -31
- package/src/nodes/materialx/lib/mx_noise.js +96 -96
- package/src/nodes/materialx/lib/mx_transform_color.js +2 -2
- package/src/nodes/math/{CondNode.js → ConditionalNode.js} +38 -10
- package/src/nodes/math/Hash.js +13 -0
- package/src/nodes/math/MathNode.js +127 -124
- package/src/nodes/math/MathUtils.js +0 -7
- package/src/nodes/math/OperatorNode.js +97 -52
- package/src/nodes/math/TriNoise3D.js +19 -29
- package/src/nodes/pmrem/PMREMNode.js +61 -15
- package/src/nodes/pmrem/PMREMUtils.js +46 -46
- package/src/nodes/procedural/Checker.js +14 -0
- package/src/nodes/tsl/TSLBase.js +30 -0
- package/src/nodes/{shadernode/ShaderNode.js → tsl/TSLCore.js} +105 -97
- package/src/nodes/utils/ArrayElementNode.js +8 -4
- package/src/nodes/utils/ConvertNode.js +7 -3
- package/src/nodes/utils/CubeMapNode.js +160 -0
- package/src/nodes/utils/Discard.js +8 -0
- package/src/nodes/utils/EquirectUVNode.js +9 -6
- package/src/nodes/utils/FlipNode.js +68 -0
- package/src/nodes/utils/FunctionOverloadingNode.js +9 -5
- package/src/nodes/utils/JoinNode.js +6 -3
- package/src/nodes/utils/LoopNode.js +16 -6
- package/src/nodes/utils/MatcapUVNode.js +10 -7
- package/src/nodes/utils/MaxMipLevelNode.js +8 -5
- package/src/nodes/utils/OscNode.js +12 -8
- package/src/nodes/utils/Packing.js +4 -0
- package/src/nodes/utils/RTTNode.js +11 -8
- package/src/nodes/utils/ReflectorNode.js +12 -4
- package/src/nodes/utils/RemapNode.js +12 -8
- package/src/nodes/utils/RotateNode.js +8 -13
- package/src/nodes/utils/SetNode.js +7 -4
- package/src/nodes/utils/SplitNode.js +7 -3
- package/src/nodes/utils/SpriteSheetUVNode.js +10 -6
- package/src/nodes/utils/SpriteUtils.js +47 -0
- package/src/nodes/utils/StorageArrayElementNode.js +11 -12
- package/src/nodes/utils/TimerNode.js +8 -5
- package/src/nodes/utils/TriplanarTexturesNode.js +11 -9
- package/src/nodes/utils/UVUtils.js +19 -0
- package/src/nodes/utils/ViewportUtils.js +14 -0
- package/src/objects/BatchedMesh.js +78 -13
- package/src/objects/LOD.js +21 -0
- package/src/objects/Line.js +1 -0
- package/src/objects/Mesh.js +7 -23
- package/src/objects/Points.js +2 -0
- package/src/renderers/WebGLRenderer.js +88 -41
- package/src/renderers/common/Backend.js +2 -2
- package/src/renderers/common/Background.js +3 -1
- package/src/renderers/common/BindGroup.js +3 -1
- package/src/renderers/common/Bindings.js +13 -15
- package/src/renderers/common/BundleGroup.js +26 -0
- package/src/renderers/common/ClippingContext.js +15 -5
- package/src/renderers/common/CubeRenderTarget.js +9 -3
- package/src/renderers/common/PostProcessing.js +4 -1
- package/src/renderers/common/QuadMesh.js +2 -0
- package/src/renderers/common/RenderContext.js +23 -0
- package/src/renderers/common/RenderList.js +1 -1
- package/src/renderers/common/RenderObject.js +117 -6
- package/src/renderers/common/RenderObjects.js +8 -1
- package/src/renderers/common/Renderer.js +128 -94
- package/src/renderers/common/SampledTexture.js +12 -3
- package/src/renderers/common/Textures.js +8 -12
- package/src/renderers/common/extras/PMREMGenerator.js +19 -22
- package/src/renderers/common/nodes/NodeBuilderState.js +4 -4
- package/src/renderers/common/nodes/NodeLibrary.js +118 -0
- package/src/renderers/common/nodes/NodeSampledTexture.js +2 -2
- package/src/renderers/common/nodes/Nodes.js +65 -19
- package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +2 -2
- package/src/renderers/shaders/ShaderLib/sprite.glsl.js +2 -4
- package/src/renderers/webgl/WebGLAttributes.js +45 -14
- package/src/renderers/webgl/WebGLCapabilities.js +9 -0
- package/src/renderers/webgl/WebGLProgram.js +3 -1
- package/src/renderers/webgl/WebGLPrograms.js +21 -17
- package/src/renderers/webgl/WebGLProperties.js +7 -0
- package/src/renderers/webgl/WebGLState.js +21 -0
- package/src/renderers/webgl/WebGLTextures.js +83 -4
- package/src/renderers/webgl-fallback/WebGLBackend.js +135 -110
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +60 -12
- package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +6 -0
- package/src/renderers/webgl-fallback/utils/WebGLState.js +20 -2
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +89 -37
- package/src/renderers/webgpu/WebGPUBackend.js +112 -86
- package/src/renderers/webgpu/WebGPURenderer.Nodes.js +42 -0
- package/src/renderers/webgpu/WebGPURenderer.js +9 -6
- package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +59 -0
- package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +105 -0
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +189 -73
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +6 -16
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +45 -21
- package/src/renderers/webgpu/utils/WebGPUConstants.js +2 -1
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +7 -16
- package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +62 -5
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +43 -26
- package/src/renderers/webgpu/utils/WebGPUUtils.js +19 -2
- package/src/renderers/webxr/WebXRManager.js +32 -25
- package/src/utils.js +33 -1
- package/examples/jsm/geometries/SDFGeometryGenerator.js +0 -144
- package/examples/jsm/loaders/LogLuvLoader.js +0 -606
- package/examples/jsm/loaders/TiltLoader.js +0 -520
- package/examples/jsm/utils/GPUStatsPanel.js +0 -95
- package/examples/jsm/utils/PackedPhongMaterial.js +0 -178
- package/src/nodes/accessors/CameraNode.js +0 -19
- package/src/nodes/accessors/NormalNode.js +0 -14
- package/src/nodes/accessors/PositionNode.js +0 -10
- package/src/nodes/accessors/ReflectVectorNode.js +0 -10
- package/src/nodes/accessors/TangentNode.js +0 -23
- package/src/nodes/core/NodeKeywords.js +0 -80
- package/src/nodes/display/BlendModeNode.js +0 -128
- package/src/nodes/display/ColorAdjustmentNode.js +0 -104
- package/src/nodes/display/ViewportNode.js +0 -137
- package/src/nodes/lighting/LightNode.js +0 -57
- package/src/nodes/materials/InstancedPointsNodeMaterial.js +0 -162
- package/src/nodes/math/HashNode.js +0 -34
- package/src/nodes/procedural/CheckerNode.js +0 -42
- package/src/nodes/utils/DiscardNode.js +0 -28
- package/src/nodes/utils/PackingNode.js +0 -55
- package/src/nodes/utils/RotateUVNode.js +0 -35
- /package/src/nodes/accessors/{UVNode.js → UV.js} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
Controls,
|
|
3
3
|
MOUSE,
|
|
4
4
|
Quaternion,
|
|
5
5
|
Spherical,
|
|
@@ -23,17 +23,30 @@ const _startEvent = { type: 'start' };
|
|
|
23
23
|
const _endEvent = { type: 'end' };
|
|
24
24
|
const _ray = new Ray();
|
|
25
25
|
const _plane = new Plane();
|
|
26
|
-
const
|
|
26
|
+
const _TILT_LIMIT = Math.cos( 70 * MathUtils.DEG2RAD );
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
const _v = new Vector3();
|
|
29
|
+
const _twoPI = 2 * Math.PI;
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
const _STATE = {
|
|
32
|
+
NONE: - 1,
|
|
33
|
+
ROTATE: 0,
|
|
34
|
+
DOLLY: 1,
|
|
35
|
+
PAN: 2,
|
|
36
|
+
TOUCH_ROTATE: 3,
|
|
37
|
+
TOUCH_PAN: 4,
|
|
38
|
+
TOUCH_DOLLY_PAN: 5,
|
|
39
|
+
TOUCH_DOLLY_ROTATE: 6
|
|
40
|
+
};
|
|
41
|
+
const _EPS = 0.000001;
|
|
31
42
|
|
|
32
|
-
|
|
43
|
+
class OrbitControls extends Controls {
|
|
33
44
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
45
|
+
constructor( object, domElement = null ) {
|
|
46
|
+
|
|
47
|
+
super( object, domElement );
|
|
48
|
+
|
|
49
|
+
this.state = _STATE.NONE;
|
|
37
50
|
|
|
38
51
|
// Set to false to disable this control
|
|
39
52
|
this.enabled = true;
|
|
@@ -109,1421 +122,1399 @@ class OrbitControls extends EventDispatcher {
|
|
|
109
122
|
// the target DOM element for key events
|
|
110
123
|
this._domElementKeyEvents = null;
|
|
111
124
|
|
|
112
|
-
//
|
|
113
|
-
// public methods
|
|
114
|
-
//
|
|
125
|
+
// internals
|
|
115
126
|
|
|
116
|
-
this.
|
|
127
|
+
this._lastPosition = new Vector3();
|
|
128
|
+
this._lastQuaternion = new Quaternion();
|
|
129
|
+
this._lastTargetPosition = new Vector3();
|
|
117
130
|
|
|
118
|
-
|
|
131
|
+
// so camera.up is the orbit axis
|
|
132
|
+
this._quat = new Quaternion().setFromUnitVectors( object.up, new Vector3( 0, 1, 0 ) );
|
|
133
|
+
this._quatInverse = this._quat.clone().invert();
|
|
119
134
|
|
|
120
|
-
|
|
135
|
+
// current position in spherical coordinates
|
|
136
|
+
this._spherical = new Spherical();
|
|
137
|
+
this._sphericalDelta = new Spherical();
|
|
121
138
|
|
|
122
|
-
this.
|
|
139
|
+
this._scale = 1;
|
|
140
|
+
this._panOffset = new Vector3();
|
|
123
141
|
|
|
124
|
-
|
|
142
|
+
this._rotateStart = new Vector2();
|
|
143
|
+
this._rotateEnd = new Vector2();
|
|
144
|
+
this._rotateDelta = new Vector2();
|
|
125
145
|
|
|
126
|
-
|
|
146
|
+
this._panStart = new Vector2();
|
|
147
|
+
this._panEnd = new Vector2();
|
|
148
|
+
this._panDelta = new Vector2();
|
|
127
149
|
|
|
128
|
-
this.
|
|
150
|
+
this._dollyStart = new Vector2();
|
|
151
|
+
this._dollyEnd = new Vector2();
|
|
152
|
+
this._dollyDelta = new Vector2();
|
|
129
153
|
|
|
130
|
-
|
|
154
|
+
this._dollyDirection = new Vector3();
|
|
155
|
+
this._mouse = new Vector2();
|
|
156
|
+
this._performCursorZoom = false;
|
|
131
157
|
|
|
132
|
-
|
|
158
|
+
this._pointers = [];
|
|
159
|
+
this._pointerPositions = {};
|
|
133
160
|
|
|
134
|
-
this.
|
|
161
|
+
this._controlActive = false;
|
|
135
162
|
|
|
136
|
-
|
|
137
|
-
this._domElementKeyEvents = domElement;
|
|
163
|
+
// event listeners
|
|
138
164
|
|
|
139
|
-
|
|
165
|
+
this._onPointerMove = onPointerMove.bind( this );
|
|
166
|
+
this._onPointerDown = onPointerDown.bind( this );
|
|
167
|
+
this._onPointerUp = onPointerUp.bind( this );
|
|
168
|
+
this._onContextMenu = onContextMenu.bind( this );
|
|
169
|
+
this._onMouseWheel = onMouseWheel.bind( this );
|
|
170
|
+
this._onKeyDown = onKeyDown.bind( this );
|
|
140
171
|
|
|
141
|
-
this.
|
|
172
|
+
this._onTouchStart = onTouchStart.bind( this );
|
|
173
|
+
this._onTouchMove = onTouchMove.bind( this );
|
|
142
174
|
|
|
143
|
-
|
|
144
|
-
|
|
175
|
+
this._onMouseDown = onMouseDown.bind( this );
|
|
176
|
+
this._onMouseMove = onMouseMove.bind( this );
|
|
145
177
|
|
|
146
|
-
|
|
178
|
+
this._interceptControlDown = interceptControlDown.bind( this );
|
|
179
|
+
this._interceptControlUp = interceptControlUp.bind( this );
|
|
147
180
|
|
|
148
|
-
|
|
181
|
+
//
|
|
149
182
|
|
|
150
|
-
|
|
151
|
-
scope.position0.copy( scope.object.position );
|
|
152
|
-
scope.zoom0 = scope.object.zoom;
|
|
183
|
+
if ( this.domElement !== null ) {
|
|
153
184
|
|
|
154
|
-
|
|
185
|
+
this.connect();
|
|
155
186
|
|
|
156
|
-
|
|
187
|
+
}
|
|
157
188
|
|
|
158
|
-
|
|
159
|
-
scope.object.position.copy( scope.position0 );
|
|
160
|
-
scope.object.zoom = scope.zoom0;
|
|
189
|
+
this.update();
|
|
161
190
|
|
|
162
|
-
|
|
163
|
-
scope.dispatchEvent( _changeEvent );
|
|
191
|
+
}
|
|
164
192
|
|
|
165
|
-
|
|
193
|
+
connect() {
|
|
166
194
|
|
|
167
|
-
|
|
195
|
+
this.domElement.addEventListener( 'pointerdown', this._onPointerDown );
|
|
196
|
+
this.domElement.addEventListener( 'pointercancel', this._onPointerUp );
|
|
168
197
|
|
|
169
|
-
|
|
198
|
+
this.domElement.addEventListener( 'contextmenu', this._onContextMenu );
|
|
199
|
+
this.domElement.addEventListener( 'wheel', this._onMouseWheel, { passive: false } );
|
|
170
200
|
|
|
171
|
-
|
|
172
|
-
this.
|
|
201
|
+
const document = this.domElement.getRootNode(); // offscreen canvas compatibility
|
|
202
|
+
document.addEventListener( 'keydown', this._interceptControlDown, { passive: true, capture: true } );
|
|
173
203
|
|
|
174
|
-
|
|
204
|
+
this.domElement.style.touchAction = 'none'; // disable touch scroll
|
|
175
205
|
|
|
176
|
-
|
|
177
|
-
const quat = new Quaternion().setFromUnitVectors( object.up, new Vector3( 0, 1, 0 ) );
|
|
178
|
-
const quatInverse = quat.clone().invert();
|
|
206
|
+
}
|
|
179
207
|
|
|
180
|
-
|
|
181
|
-
const lastQuaternion = new Quaternion();
|
|
182
|
-
const lastTargetPosition = new Vector3();
|
|
208
|
+
disconnect() {
|
|
183
209
|
|
|
184
|
-
|
|
210
|
+
this.domElement.removeEventListener( 'pointerdown', this._onPointerDown );
|
|
211
|
+
this.domElement.removeEventListener( 'pointermove', this._onPointerMove );
|
|
212
|
+
this.domElement.removeEventListener( 'pointerup', this._onPointerUp );
|
|
213
|
+
this.domElement.removeEventListener( 'pointercancel', this._onPointerUp );
|
|
185
214
|
|
|
186
|
-
|
|
215
|
+
this.domElement.removeEventListener( 'wheel', this._onMouseWheel );
|
|
216
|
+
this.domElement.removeEventListener( 'contextmenu', this._onContextMenu );
|
|
187
217
|
|
|
188
|
-
|
|
218
|
+
this.stopListenToKeyEvents();
|
|
189
219
|
|
|
190
|
-
|
|
220
|
+
const document = this.domElement.getRootNode(); // offscreen canvas compatibility
|
|
221
|
+
document.removeEventListener( 'keydown', this._interceptControlDown, { capture: true } );
|
|
191
222
|
|
|
192
|
-
|
|
193
|
-
offset.applyQuaternion( quat );
|
|
223
|
+
this.domElement.style.touchAction = 'auto';
|
|
194
224
|
|
|
195
|
-
|
|
196
|
-
spherical.setFromVector3( offset );
|
|
225
|
+
}
|
|
197
226
|
|
|
198
|
-
|
|
227
|
+
dispose() {
|
|
199
228
|
|
|
200
|
-
|
|
229
|
+
this.disconnect();
|
|
201
230
|
|
|
202
|
-
|
|
231
|
+
}
|
|
203
232
|
|
|
204
|
-
|
|
233
|
+
getPolarAngle() {
|
|
205
234
|
|
|
206
|
-
|
|
207
|
-
spherical.phi += sphericalDelta.phi * scope.dampingFactor;
|
|
235
|
+
return this._spherical.phi;
|
|
208
236
|
|
|
209
|
-
|
|
237
|
+
}
|
|
210
238
|
|
|
211
|
-
|
|
212
|
-
spherical.phi += sphericalDelta.phi;
|
|
239
|
+
getAzimuthalAngle() {
|
|
213
240
|
|
|
214
|
-
|
|
241
|
+
return this._spherical.theta;
|
|
215
242
|
|
|
216
|
-
|
|
243
|
+
}
|
|
217
244
|
|
|
218
|
-
|
|
219
|
-
let max = scope.maxAzimuthAngle;
|
|
245
|
+
getDistance() {
|
|
220
246
|
|
|
221
|
-
|
|
247
|
+
return this.object.position.distanceTo( this.target );
|
|
222
248
|
|
|
223
|
-
|
|
249
|
+
}
|
|
224
250
|
|
|
225
|
-
|
|
251
|
+
listenToKeyEvents( domElement ) {
|
|
226
252
|
|
|
227
|
-
|
|
253
|
+
domElement.addEventListener( 'keydown', this._onKeyDown );
|
|
254
|
+
this._domElementKeyEvents = domElement;
|
|
228
255
|
|
|
229
|
-
|
|
256
|
+
}
|
|
230
257
|
|
|
231
|
-
|
|
258
|
+
stopListenToKeyEvents() {
|
|
232
259
|
|
|
233
|
-
|
|
234
|
-
Math.max( min, spherical.theta ) :
|
|
235
|
-
Math.min( max, spherical.theta );
|
|
260
|
+
if ( this._domElementKeyEvents !== null ) {
|
|
236
261
|
|
|
237
|
-
|
|
262
|
+
this._domElementKeyEvents.removeEventListener( 'keydown', this._onKeyDown );
|
|
263
|
+
this._domElementKeyEvents = null;
|
|
238
264
|
|
|
239
|
-
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
}
|
|
240
268
|
|
|
241
|
-
|
|
242
|
-
spherical.phi = Math.max( scope.minPolarAngle, Math.min( scope.maxPolarAngle, spherical.phi ) );
|
|
269
|
+
saveState() {
|
|
243
270
|
|
|
244
|
-
|
|
271
|
+
this.target0.copy( this.target );
|
|
272
|
+
this.position0.copy( this.object.position );
|
|
273
|
+
this.zoom0 = this.object.zoom;
|
|
245
274
|
|
|
275
|
+
}
|
|
246
276
|
|
|
247
|
-
|
|
277
|
+
reset() {
|
|
248
278
|
|
|
249
|
-
|
|
279
|
+
this.target.copy( this.target0 );
|
|
280
|
+
this.object.position.copy( this.position0 );
|
|
281
|
+
this.object.zoom = this.zoom0;
|
|
250
282
|
|
|
251
|
-
|
|
283
|
+
this.object.updateProjectionMatrix();
|
|
284
|
+
this.dispatchEvent( _changeEvent );
|
|
252
285
|
|
|
253
|
-
|
|
286
|
+
this.update();
|
|
254
287
|
|
|
255
|
-
|
|
288
|
+
this.state = _STATE.NONE;
|
|
256
289
|
|
|
257
|
-
|
|
290
|
+
}
|
|
258
291
|
|
|
259
|
-
|
|
260
|
-
scope.target.sub( scope.cursor );
|
|
261
|
-
scope.target.clampLength( scope.minTargetRadius, scope.maxTargetRadius );
|
|
262
|
-
scope.target.add( scope.cursor );
|
|
292
|
+
update( deltaTime = null ) {
|
|
263
293
|
|
|
264
|
-
|
|
265
|
-
// adjust the camera position based on zoom only if we're not zooming to the cursor or if it's an ortho camera
|
|
266
|
-
// we adjust zoom later in these cases
|
|
267
|
-
if ( scope.zoomToCursor && performCursorZoom || scope.object.isOrthographicCamera ) {
|
|
294
|
+
const position = this.object.position;
|
|
268
295
|
|
|
269
|
-
|
|
296
|
+
_v.copy( position ).sub( this.target );
|
|
270
297
|
|
|
271
|
-
|
|
298
|
+
// rotate offset to "y-axis-is-up" space
|
|
299
|
+
_v.applyQuaternion( this._quat );
|
|
272
300
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
zoomChanged = prevRadius != spherical.radius;
|
|
301
|
+
// angle from z-axis around y-axis
|
|
302
|
+
this._spherical.setFromVector3( _v );
|
|
276
303
|
|
|
277
|
-
|
|
304
|
+
if ( this.autoRotate && this.state === _STATE.NONE ) {
|
|
278
305
|
|
|
279
|
-
|
|
306
|
+
this._rotateLeft( this._getAutoRotationAngle( deltaTime ) );
|
|
280
307
|
|
|
281
|
-
|
|
282
|
-
offset.applyQuaternion( quatInverse );
|
|
308
|
+
}
|
|
283
309
|
|
|
284
|
-
|
|
310
|
+
if ( this.enableDamping ) {
|
|
285
311
|
|
|
286
|
-
|
|
312
|
+
this._spherical.theta += this._sphericalDelta.theta * this.dampingFactor;
|
|
313
|
+
this._spherical.phi += this._sphericalDelta.phi * this.dampingFactor;
|
|
287
314
|
|
|
288
|
-
|
|
315
|
+
} else {
|
|
289
316
|
|
|
290
|
-
|
|
291
|
-
|
|
317
|
+
this._spherical.theta += this._sphericalDelta.theta;
|
|
318
|
+
this._spherical.phi += this._sphericalDelta.phi;
|
|
292
319
|
|
|
293
|
-
|
|
320
|
+
}
|
|
294
321
|
|
|
295
|
-
|
|
322
|
+
// restrict theta to be between desired limits
|
|
296
323
|
|
|
297
|
-
|
|
324
|
+
let min = this.minAzimuthAngle;
|
|
325
|
+
let max = this.maxAzimuthAngle;
|
|
298
326
|
|
|
299
|
-
|
|
327
|
+
if ( isFinite( min ) && isFinite( max ) ) {
|
|
300
328
|
|
|
301
|
-
|
|
329
|
+
if ( min < - Math.PI ) min += _twoPI; else if ( min > Math.PI ) min -= _twoPI;
|
|
302
330
|
|
|
303
|
-
|
|
304
|
-
if ( scope.zoomToCursor && performCursorZoom ) {
|
|
331
|
+
if ( max < - Math.PI ) max += _twoPI; else if ( max > Math.PI ) max -= _twoPI;
|
|
305
332
|
|
|
306
|
-
|
|
307
|
-
if ( scope.object.isPerspectiveCamera ) {
|
|
333
|
+
if ( min <= max ) {
|
|
308
334
|
|
|
309
|
-
|
|
310
|
-
// this method avoids floating point error
|
|
311
|
-
const prevRadius = offset.length();
|
|
312
|
-
newRadius = clampDistance( prevRadius * scale );
|
|
335
|
+
this._spherical.theta = Math.max( min, Math.min( max, this._spherical.theta ) );
|
|
313
336
|
|
|
314
|
-
|
|
315
|
-
scope.object.position.addScaledVector( dollyDirection, radiusDelta );
|
|
316
|
-
scope.object.updateMatrixWorld();
|
|
337
|
+
} else {
|
|
317
338
|
|
|
318
|
-
|
|
339
|
+
this._spherical.theta = ( this._spherical.theta > ( min + max ) / 2 ) ?
|
|
340
|
+
Math.max( min, this._spherical.theta ) :
|
|
341
|
+
Math.min( max, this._spherical.theta );
|
|
319
342
|
|
|
320
|
-
|
|
343
|
+
}
|
|
321
344
|
|
|
322
|
-
|
|
323
|
-
const mouseBefore = new Vector3( mouse.x, mouse.y, 0 );
|
|
324
|
-
mouseBefore.unproject( scope.object );
|
|
345
|
+
}
|
|
325
346
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
scope.object.updateProjectionMatrix();
|
|
347
|
+
// restrict phi to be between desired limits
|
|
348
|
+
this._spherical.phi = Math.max( this.minPolarAngle, Math.min( this.maxPolarAngle, this._spherical.phi ) );
|
|
329
349
|
|
|
330
|
-
|
|
350
|
+
this._spherical.makeSafe();
|
|
331
351
|
|
|
332
|
-
const mouseAfter = new Vector3( mouse.x, mouse.y, 0 );
|
|
333
|
-
mouseAfter.unproject( scope.object );
|
|
334
352
|
|
|
335
|
-
|
|
336
|
-
scope.object.updateMatrixWorld();
|
|
353
|
+
// move target to panned location
|
|
337
354
|
|
|
338
|
-
|
|
355
|
+
if ( this.enableDamping === true ) {
|
|
339
356
|
|
|
340
|
-
|
|
357
|
+
this.target.addScaledVector( this._panOffset, this.dampingFactor );
|
|
341
358
|
|
|
342
|
-
|
|
343
|
-
scope.zoomToCursor = false;
|
|
359
|
+
} else {
|
|
344
360
|
|
|
345
|
-
|
|
361
|
+
this.target.add( this._panOffset );
|
|
346
362
|
|
|
347
|
-
|
|
348
|
-
if ( newRadius !== null ) {
|
|
363
|
+
}
|
|
349
364
|
|
|
350
|
-
|
|
365
|
+
// Limit the target distance from the cursor to create a sphere around the center of interest
|
|
366
|
+
this.target.sub( this.cursor );
|
|
367
|
+
this.target.clampLength( this.minTargetRadius, this.maxTargetRadius );
|
|
368
|
+
this.target.add( this.cursor );
|
|
351
369
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
.add( scope.object.position );
|
|
370
|
+
let zoomChanged = false;
|
|
371
|
+
// adjust the camera position based on zoom only if we're not zooming to the cursor or if it's an ortho camera
|
|
372
|
+
// we adjust zoom later in these cases
|
|
373
|
+
if ( this.zoomToCursor && this._performCursorZoom || this.object.isOrthographicCamera ) {
|
|
357
374
|
|
|
358
|
-
|
|
375
|
+
this._spherical.radius = this._clampDistance( this._spherical.radius );
|
|
359
376
|
|
|
360
|
-
|
|
361
|
-
_ray.origin.copy( scope.object.position );
|
|
362
|
-
_ray.direction.set( 0, 0, - 1 ).transformDirection( scope.object.matrix );
|
|
377
|
+
} else {
|
|
363
378
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
379
|
+
const prevRadius = this._spherical.radius;
|
|
380
|
+
this._spherical.radius = this._clampDistance( this._spherical.radius * this._scale );
|
|
381
|
+
zoomChanged = prevRadius != this._spherical.radius;
|
|
367
382
|
|
|
368
|
-
|
|
383
|
+
}
|
|
369
384
|
|
|
370
|
-
|
|
385
|
+
_v.setFromSpherical( this._spherical );
|
|
371
386
|
|
|
372
|
-
|
|
373
|
-
|
|
387
|
+
// rotate offset back to "camera-up-vector-is-up" space
|
|
388
|
+
_v.applyQuaternion( this._quatInverse );
|
|
374
389
|
|
|
375
|
-
|
|
390
|
+
position.copy( this.target ).add( _v );
|
|
376
391
|
|
|
377
|
-
|
|
392
|
+
this.object.lookAt( this.target );
|
|
378
393
|
|
|
379
|
-
|
|
394
|
+
if ( this.enableDamping === true ) {
|
|
380
395
|
|
|
381
|
-
|
|
396
|
+
this._sphericalDelta.theta *= ( 1 - this.dampingFactor );
|
|
397
|
+
this._sphericalDelta.phi *= ( 1 - this.dampingFactor );
|
|
382
398
|
|
|
383
|
-
|
|
384
|
-
scope.object.zoom = Math.max( scope.minZoom, Math.min( scope.maxZoom, scope.object.zoom / scale ) );
|
|
399
|
+
this._panOffset.multiplyScalar( 1 - this.dampingFactor );
|
|
385
400
|
|
|
386
|
-
|
|
401
|
+
} else {
|
|
387
402
|
|
|
388
|
-
|
|
389
|
-
zoomChanged = true;
|
|
403
|
+
this._sphericalDelta.set( 0, 0, 0 );
|
|
390
404
|
|
|
391
|
-
|
|
405
|
+
this._panOffset.set( 0, 0, 0 );
|
|
392
406
|
|
|
393
|
-
|
|
407
|
+
}
|
|
394
408
|
|
|
395
|
-
|
|
396
|
-
|
|
409
|
+
// adjust camera position
|
|
410
|
+
if ( this.zoomToCursor && this._performCursorZoom ) {
|
|
397
411
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
// using small-angle approximation cos(x/2) = 1 - x^2 / 8
|
|
412
|
+
let newRadius = null;
|
|
413
|
+
if ( this.object.isPerspectiveCamera ) {
|
|
401
414
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
415
|
+
// move the camera down the pointer ray
|
|
416
|
+
// this method avoids floating point error
|
|
417
|
+
const prevRadius = _v.length();
|
|
418
|
+
newRadius = this._clampDistance( prevRadius * this._scale );
|
|
406
419
|
|
|
407
|
-
|
|
420
|
+
const radiusDelta = prevRadius - newRadius;
|
|
421
|
+
this.object.position.addScaledVector( this._dollyDirection, radiusDelta );
|
|
422
|
+
this.object.updateMatrixWorld();
|
|
408
423
|
|
|
409
|
-
|
|
410
|
-
lastQuaternion.copy( scope.object.quaternion );
|
|
411
|
-
lastTargetPosition.copy( scope.target );
|
|
424
|
+
zoomChanged = !! radiusDelta;
|
|
412
425
|
|
|
413
|
-
|
|
426
|
+
} else if ( this.object.isOrthographicCamera ) {
|
|
414
427
|
|
|
415
|
-
|
|
428
|
+
// adjust the ortho camera position based on zoom changes
|
|
429
|
+
const mouseBefore = new Vector3( this._mouse.x, this._mouse.y, 0 );
|
|
430
|
+
mouseBefore.unproject( this.object );
|
|
416
431
|
|
|
417
|
-
|
|
432
|
+
const prevZoom = this.object.zoom;
|
|
433
|
+
this.object.zoom = Math.max( this.minZoom, Math.min( this.maxZoom, this.object.zoom / this._scale ) );
|
|
434
|
+
this.object.updateProjectionMatrix();
|
|
418
435
|
|
|
419
|
-
|
|
436
|
+
zoomChanged = prevZoom !== this.object.zoom;
|
|
420
437
|
|
|
421
|
-
|
|
438
|
+
const mouseAfter = new Vector3( this._mouse.x, this._mouse.y, 0 );
|
|
439
|
+
mouseAfter.unproject( this.object );
|
|
422
440
|
|
|
423
|
-
|
|
441
|
+
this.object.position.sub( mouseAfter ).add( mouseBefore );
|
|
442
|
+
this.object.updateMatrixWorld();
|
|
424
443
|
|
|
425
|
-
|
|
444
|
+
newRadius = _v.length();
|
|
426
445
|
|
|
427
|
-
|
|
428
|
-
scope.domElement.removeEventListener( 'pointercancel', onPointerUp );
|
|
429
|
-
scope.domElement.removeEventListener( 'wheel', onMouseWheel );
|
|
446
|
+
} else {
|
|
430
447
|
|
|
431
|
-
|
|
432
|
-
|
|
448
|
+
console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled.' );
|
|
449
|
+
this.zoomToCursor = false;
|
|
433
450
|
|
|
434
|
-
|
|
451
|
+
}
|
|
435
452
|
|
|
436
|
-
|
|
453
|
+
// handle the placement of the target
|
|
454
|
+
if ( newRadius !== null ) {
|
|
437
455
|
|
|
438
|
-
|
|
456
|
+
if ( this.screenSpacePanning ) {
|
|
439
457
|
|
|
440
|
-
|
|
441
|
-
|
|
458
|
+
// position the orbit target in front of the new camera position
|
|
459
|
+
this.target.set( 0, 0, - 1 )
|
|
460
|
+
.transformDirection( this.object.matrix )
|
|
461
|
+
.multiplyScalar( newRadius )
|
|
462
|
+
.add( this.object.position );
|
|
442
463
|
|
|
443
|
-
|
|
464
|
+
} else {
|
|
444
465
|
|
|
445
|
-
|
|
466
|
+
// get the ray and translation plane to compute target
|
|
467
|
+
_ray.origin.copy( this.object.position );
|
|
468
|
+
_ray.direction.set( 0, 0, - 1 ).transformDirection( this.object.matrix );
|
|
446
469
|
|
|
447
|
-
|
|
470
|
+
// if the camera is 20 degrees above the horizon then don't adjust the focus target to avoid
|
|
471
|
+
// extremely large values
|
|
472
|
+
if ( Math.abs( this.object.up.dot( _ray.direction ) ) < _TILT_LIMIT ) {
|
|
448
473
|
|
|
449
|
-
|
|
450
|
-
// internals
|
|
451
|
-
//
|
|
474
|
+
this.object.lookAt( this.target );
|
|
452
475
|
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
const STATE = {
|
|
456
|
-
NONE: - 1,
|
|
457
|
-
ROTATE: 0,
|
|
458
|
-
DOLLY: 1,
|
|
459
|
-
PAN: 2,
|
|
460
|
-
TOUCH_ROTATE: 3,
|
|
461
|
-
TOUCH_PAN: 4,
|
|
462
|
-
TOUCH_DOLLY_PAN: 5,
|
|
463
|
-
TOUCH_DOLLY_ROTATE: 6
|
|
464
|
-
};
|
|
476
|
+
} else {
|
|
465
477
|
|
|
466
|
-
|
|
478
|
+
_plane.setFromNormalAndCoplanarPoint( this.object.up, this.target );
|
|
479
|
+
_ray.intersectPlane( _plane, this.target );
|
|
467
480
|
|
|
468
|
-
|
|
481
|
+
}
|
|
469
482
|
|
|
470
|
-
|
|
471
|
-
const spherical = new Spherical();
|
|
472
|
-
const sphericalDelta = new Spherical();
|
|
483
|
+
}
|
|
473
484
|
|
|
474
|
-
|
|
475
|
-
const panOffset = new Vector3();
|
|
485
|
+
}
|
|
476
486
|
|
|
477
|
-
|
|
478
|
-
const rotateEnd = new Vector2();
|
|
479
|
-
const rotateDelta = new Vector2();
|
|
487
|
+
} else if ( this.object.isOrthographicCamera ) {
|
|
480
488
|
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
const panDelta = new Vector2();
|
|
489
|
+
const prevZoom = this.object.zoom;
|
|
490
|
+
this.object.zoom = Math.max( this.minZoom, Math.min( this.maxZoom, this.object.zoom / this._scale ) );
|
|
484
491
|
|
|
485
|
-
|
|
486
|
-
const dollyEnd = new Vector2();
|
|
487
|
-
const dollyDelta = new Vector2();
|
|
492
|
+
if ( prevZoom !== this.object.zoom ) {
|
|
488
493
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
let performCursorZoom = false;
|
|
494
|
+
this.object.updateProjectionMatrix();
|
|
495
|
+
zoomChanged = true;
|
|
492
496
|
|
|
493
|
-
|
|
494
|
-
const pointerPositions = {};
|
|
497
|
+
}
|
|
495
498
|
|
|
496
|
-
|
|
499
|
+
}
|
|
497
500
|
|
|
498
|
-
|
|
501
|
+
this._scale = 1;
|
|
502
|
+
this._performCursorZoom = false;
|
|
499
503
|
|
|
500
|
-
|
|
504
|
+
// update condition is:
|
|
505
|
+
// min(camera displacement, camera rotation in radians)^2 > EPS
|
|
506
|
+
// using small-angle approximation cos(x/2) = 1 - x^2 / 8
|
|
501
507
|
|
|
502
|
-
|
|
508
|
+
if ( zoomChanged ||
|
|
509
|
+
this._lastPosition.distanceToSquared( this.object.position ) > _EPS ||
|
|
510
|
+
8 * ( 1 - this._lastQuaternion.dot( this.object.quaternion ) ) > _EPS ||
|
|
511
|
+
this._lastTargetPosition.distanceToSquared( this.target ) > _EPS ) {
|
|
503
512
|
|
|
504
|
-
|
|
513
|
+
this.dispatchEvent( _changeEvent );
|
|
505
514
|
|
|
506
|
-
|
|
515
|
+
this._lastPosition.copy( this.object.position );
|
|
516
|
+
this._lastQuaternion.copy( this.object.quaternion );
|
|
517
|
+
this._lastTargetPosition.copy( this.target );
|
|
507
518
|
|
|
508
|
-
|
|
519
|
+
return true;
|
|
509
520
|
|
|
510
521
|
}
|
|
511
522
|
|
|
512
|
-
|
|
523
|
+
return false;
|
|
513
524
|
|
|
514
|
-
|
|
515
|
-
return Math.pow( 0.95, scope.zoomSpeed * normalizedDelta );
|
|
516
|
-
|
|
517
|
-
}
|
|
525
|
+
}
|
|
518
526
|
|
|
519
|
-
|
|
527
|
+
_getAutoRotationAngle( deltaTime ) {
|
|
520
528
|
|
|
521
|
-
|
|
529
|
+
if ( deltaTime !== null ) {
|
|
522
530
|
|
|
523
|
-
|
|
531
|
+
return ( _twoPI / 60 * this.autoRotateSpeed ) * deltaTime;
|
|
524
532
|
|
|
525
|
-
|
|
533
|
+
} else {
|
|
526
534
|
|
|
527
|
-
|
|
535
|
+
return _twoPI / 60 / 60 * this.autoRotateSpeed;
|
|
528
536
|
|
|
529
537
|
}
|
|
530
538
|
|
|
531
|
-
|
|
539
|
+
}
|
|
532
540
|
|
|
533
|
-
|
|
541
|
+
_getZoomScale( delta ) {
|
|
534
542
|
|
|
535
|
-
|
|
543
|
+
const normalizedDelta = Math.abs( delta * 0.01 );
|
|
544
|
+
return Math.pow( 0.95, this.zoomSpeed * normalizedDelta );
|
|
536
545
|
|
|
537
|
-
|
|
538
|
-
v.multiplyScalar( - distance );
|
|
546
|
+
}
|
|
539
547
|
|
|
540
|
-
|
|
548
|
+
_rotateLeft( angle ) {
|
|
541
549
|
|
|
542
|
-
|
|
550
|
+
this._sphericalDelta.theta -= angle;
|
|
543
551
|
|
|
544
|
-
|
|
552
|
+
}
|
|
545
553
|
|
|
546
|
-
|
|
554
|
+
_rotateUp( angle ) {
|
|
547
555
|
|
|
548
|
-
|
|
556
|
+
this._sphericalDelta.phi -= angle;
|
|
549
557
|
|
|
550
|
-
|
|
558
|
+
}
|
|
551
559
|
|
|
552
|
-
|
|
560
|
+
_panLeft( distance, objectMatrix ) {
|
|
553
561
|
|
|
554
|
-
|
|
562
|
+
_v.setFromMatrixColumn( objectMatrix, 0 ); // get X column of objectMatrix
|
|
563
|
+
_v.multiplyScalar( - distance );
|
|
555
564
|
|
|
556
|
-
|
|
565
|
+
this._panOffset.add( _v );
|
|
557
566
|
|
|
558
|
-
|
|
559
|
-
v.crossVectors( scope.object.up, v );
|
|
567
|
+
}
|
|
560
568
|
|
|
561
|
-
|
|
569
|
+
_panUp( distance, objectMatrix ) {
|
|
562
570
|
|
|
563
|
-
|
|
571
|
+
if ( this.screenSpacePanning === true ) {
|
|
564
572
|
|
|
565
|
-
|
|
573
|
+
_v.setFromMatrixColumn( objectMatrix, 1 );
|
|
566
574
|
|
|
567
|
-
|
|
575
|
+
} else {
|
|
568
576
|
|
|
569
|
-
|
|
577
|
+
_v.setFromMatrixColumn( objectMatrix, 0 );
|
|
578
|
+
_v.crossVectors( this.object.up, _v );
|
|
570
579
|
|
|
571
|
-
|
|
572
|
-
const pan = function () {
|
|
580
|
+
}
|
|
573
581
|
|
|
574
|
-
|
|
582
|
+
_v.multiplyScalar( distance );
|
|
575
583
|
|
|
576
|
-
|
|
584
|
+
this._panOffset.add( _v );
|
|
577
585
|
|
|
578
|
-
|
|
586
|
+
}
|
|
579
587
|
|
|
580
|
-
|
|
588
|
+
// deltaX and deltaY are in pixels; right and down are positive
|
|
589
|
+
_pan( deltaX, deltaY ) {
|
|
581
590
|
|
|
582
|
-
|
|
583
|
-
const position = scope.object.position;
|
|
584
|
-
offset.copy( position ).sub( scope.target );
|
|
585
|
-
let targetDistance = offset.length();
|
|
591
|
+
const element = this.domElement;
|
|
586
592
|
|
|
587
|
-
|
|
588
|
-
targetDistance *= Math.tan( ( scope.object.fov / 2 ) * Math.PI / 180.0 );
|
|
593
|
+
if ( this.object.isPerspectiveCamera ) {
|
|
589
594
|
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
595
|
+
// perspective
|
|
596
|
+
const position = this.object.position;
|
|
597
|
+
_v.copy( position ).sub( this.target );
|
|
598
|
+
let targetDistance = _v.length();
|
|
593
599
|
|
|
594
|
-
|
|
600
|
+
// half of the fov is center to top of screen
|
|
601
|
+
targetDistance *= Math.tan( ( this.object.fov / 2 ) * Math.PI / 180.0 );
|
|
595
602
|
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
603
|
+
// we use only clientHeight here so aspect ratio does not distort speed
|
|
604
|
+
this._panLeft( 2 * deltaX * targetDistance / element.clientHeight, this.object.matrix );
|
|
605
|
+
this._panUp( 2 * deltaY * targetDistance / element.clientHeight, this.object.matrix );
|
|
599
606
|
|
|
600
|
-
|
|
607
|
+
} else if ( this.object.isOrthographicCamera ) {
|
|
601
608
|
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
609
|
+
// orthographic
|
|
610
|
+
this._panLeft( deltaX * ( this.object.right - this.object.left ) / this.object.zoom / element.clientWidth, this.object.matrix );
|
|
611
|
+
this._panUp( deltaY * ( this.object.top - this.object.bottom ) / this.object.zoom / element.clientHeight, this.object.matrix );
|
|
605
612
|
|
|
606
|
-
|
|
613
|
+
} else {
|
|
607
614
|
|
|
608
|
-
|
|
615
|
+
// camera neither orthographic nor perspective
|
|
616
|
+
console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.' );
|
|
617
|
+
this.enablePan = false;
|
|
609
618
|
|
|
610
|
-
}
|
|
619
|
+
}
|
|
611
620
|
|
|
612
|
-
|
|
621
|
+
}
|
|
613
622
|
|
|
614
|
-
|
|
623
|
+
_dollyOut( dollyScale ) {
|
|
615
624
|
|
|
616
|
-
|
|
625
|
+
if ( this.object.isPerspectiveCamera || this.object.isOrthographicCamera ) {
|
|
617
626
|
|
|
618
|
-
|
|
627
|
+
this._scale /= dollyScale;
|
|
619
628
|
|
|
620
|
-
|
|
621
|
-
scope.enableZoom = false;
|
|
629
|
+
} else {
|
|
622
630
|
|
|
623
|
-
|
|
631
|
+
console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
|
|
632
|
+
this.enableZoom = false;
|
|
624
633
|
|
|
625
634
|
}
|
|
626
635
|
|
|
627
|
-
|
|
636
|
+
}
|
|
628
637
|
|
|
629
|
-
|
|
638
|
+
_dollyIn( dollyScale ) {
|
|
630
639
|
|
|
631
|
-
|
|
640
|
+
if ( this.object.isPerspectiveCamera || this.object.isOrthographicCamera ) {
|
|
632
641
|
|
|
633
|
-
|
|
642
|
+
this._scale *= dollyScale;
|
|
634
643
|
|
|
635
|
-
|
|
636
|
-
scope.enableZoom = false;
|
|
644
|
+
} else {
|
|
637
645
|
|
|
638
|
-
|
|
646
|
+
console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
|
|
647
|
+
this.enableZoom = false;
|
|
639
648
|
|
|
640
649
|
}
|
|
641
650
|
|
|
642
|
-
|
|
651
|
+
}
|
|
643
652
|
|
|
644
|
-
|
|
653
|
+
_updateZoomParameters( x, y ) {
|
|
645
654
|
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
}
|
|
655
|
+
if ( ! this.zoomToCursor ) {
|
|
649
656
|
|
|
650
|
-
|
|
657
|
+
return;
|
|
651
658
|
|
|
652
|
-
|
|
653
|
-
const dx = x - rect.left;
|
|
654
|
-
const dy = y - rect.top;
|
|
655
|
-
const w = rect.width;
|
|
656
|
-
const h = rect.height;
|
|
659
|
+
}
|
|
657
660
|
|
|
658
|
-
|
|
659
|
-
mouse.y = - ( dy / h ) * 2 + 1;
|
|
661
|
+
this._performCursorZoom = true;
|
|
660
662
|
|
|
661
|
-
|
|
663
|
+
const rect = this.domElement.getBoundingClientRect();
|
|
664
|
+
const dx = x - rect.left;
|
|
665
|
+
const dy = y - rect.top;
|
|
666
|
+
const w = rect.width;
|
|
667
|
+
const h = rect.height;
|
|
662
668
|
|
|
663
|
-
|
|
669
|
+
this._mouse.x = ( dx / w ) * 2 - 1;
|
|
670
|
+
this._mouse.y = - ( dy / h ) * 2 + 1;
|
|
664
671
|
|
|
665
|
-
|
|
672
|
+
this._dollyDirection.set( this._mouse.x, this._mouse.y, 1 ).unproject( this.object ).sub( this.object.position ).normalize();
|
|
666
673
|
|
|
667
|
-
|
|
674
|
+
}
|
|
668
675
|
|
|
669
|
-
|
|
676
|
+
_clampDistance( dist ) {
|
|
670
677
|
|
|
671
|
-
|
|
672
|
-
// event callbacks - update the object state
|
|
673
|
-
//
|
|
674
|
-
|
|
675
|
-
function handleMouseDownRotate( event ) {
|
|
678
|
+
return Math.max( this.minDistance, Math.min( this.maxDistance, dist ) );
|
|
676
679
|
|
|
677
|
-
|
|
680
|
+
}
|
|
678
681
|
|
|
679
|
-
|
|
682
|
+
//
|
|
683
|
+
// event callbacks - update the object state
|
|
684
|
+
//
|
|
680
685
|
|
|
681
|
-
|
|
686
|
+
_handleMouseDownRotate( event ) {
|
|
682
687
|
|
|
683
|
-
|
|
684
|
-
dollyStart.set( event.clientX, event.clientY );
|
|
688
|
+
this._rotateStart.set( event.clientX, event.clientY );
|
|
685
689
|
|
|
686
|
-
|
|
690
|
+
}
|
|
687
691
|
|
|
688
|
-
|
|
692
|
+
_handleMouseDownDolly( event ) {
|
|
689
693
|
|
|
690
|
-
|
|
694
|
+
this._updateZoomParameters( event.clientX, event.clientX );
|
|
695
|
+
this._dollyStart.set( event.clientX, event.clientY );
|
|
691
696
|
|
|
692
|
-
|
|
697
|
+
}
|
|
693
698
|
|
|
694
|
-
|
|
699
|
+
_handleMouseDownPan( event ) {
|
|
695
700
|
|
|
696
|
-
|
|
701
|
+
this._panStart.set( event.clientX, event.clientY );
|
|
697
702
|
|
|
698
|
-
|
|
703
|
+
}
|
|
699
704
|
|
|
700
|
-
|
|
705
|
+
_handleMouseMoveRotate( event ) {
|
|
701
706
|
|
|
702
|
-
|
|
707
|
+
this._rotateEnd.set( event.clientX, event.clientY );
|
|
703
708
|
|
|
704
|
-
|
|
709
|
+
this._rotateDelta.subVectors( this._rotateEnd, this._rotateStart ).multiplyScalar( this.rotateSpeed );
|
|
705
710
|
|
|
706
|
-
|
|
711
|
+
const element = this.domElement;
|
|
707
712
|
|
|
708
|
-
|
|
713
|
+
this._rotateLeft( _twoPI * this._rotateDelta.x / element.clientHeight ); // yes, height
|
|
709
714
|
|
|
710
|
-
|
|
715
|
+
this._rotateUp( _twoPI * this._rotateDelta.y / element.clientHeight );
|
|
711
716
|
|
|
712
|
-
|
|
717
|
+
this._rotateStart.copy( this._rotateEnd );
|
|
713
718
|
|
|
714
|
-
|
|
719
|
+
this.update();
|
|
715
720
|
|
|
716
|
-
|
|
721
|
+
}
|
|
717
722
|
|
|
718
|
-
|
|
723
|
+
_handleMouseMoveDolly( event ) {
|
|
719
724
|
|
|
720
|
-
|
|
725
|
+
this._dollyEnd.set( event.clientX, event.clientY );
|
|
721
726
|
|
|
722
|
-
|
|
727
|
+
this._dollyDelta.subVectors( this._dollyEnd, this._dollyStart );
|
|
723
728
|
|
|
724
|
-
|
|
729
|
+
if ( this._dollyDelta.y > 0 ) {
|
|
725
730
|
|
|
726
|
-
|
|
731
|
+
this._dollyOut( this._getZoomScale( this._dollyDelta.y ) );
|
|
727
732
|
|
|
728
|
-
|
|
733
|
+
} else if ( this._dollyDelta.y < 0 ) {
|
|
729
734
|
|
|
730
|
-
|
|
735
|
+
this._dollyIn( this._getZoomScale( this._dollyDelta.y ) );
|
|
731
736
|
|
|
732
737
|
}
|
|
733
738
|
|
|
734
|
-
|
|
739
|
+
this._dollyStart.copy( this._dollyEnd );
|
|
735
740
|
|
|
736
|
-
|
|
741
|
+
this.update();
|
|
737
742
|
|
|
738
|
-
|
|
743
|
+
}
|
|
739
744
|
|
|
740
|
-
|
|
745
|
+
_handleMouseMovePan( event ) {
|
|
741
746
|
|
|
742
|
-
|
|
747
|
+
this._panEnd.set( event.clientX, event.clientY );
|
|
743
748
|
|
|
744
|
-
|
|
749
|
+
this._panDelta.subVectors( this._panEnd, this._panStart ).multiplyScalar( this.panSpeed );
|
|
745
750
|
|
|
746
|
-
|
|
751
|
+
this._pan( this._panDelta.x, this._panDelta.y );
|
|
747
752
|
|
|
748
|
-
|
|
753
|
+
this._panStart.copy( this._panEnd );
|
|
749
754
|
|
|
750
|
-
|
|
755
|
+
this.update();
|
|
751
756
|
|
|
752
|
-
|
|
757
|
+
}
|
|
753
758
|
|
|
754
|
-
|
|
759
|
+
_handleMouseWheel( event ) {
|
|
755
760
|
|
|
756
|
-
|
|
761
|
+
this._updateZoomParameters( event.clientX, event.clientY );
|
|
757
762
|
|
|
758
|
-
|
|
763
|
+
if ( event.deltaY < 0 ) {
|
|
759
764
|
|
|
760
|
-
|
|
765
|
+
this._dollyIn( this._getZoomScale( event.deltaY ) );
|
|
761
766
|
|
|
762
|
-
|
|
767
|
+
} else if ( event.deltaY > 0 ) {
|
|
768
|
+
|
|
769
|
+
this._dollyOut( this._getZoomScale( event.deltaY ) );
|
|
763
770
|
|
|
764
771
|
}
|
|
765
772
|
|
|
766
|
-
|
|
773
|
+
this.update();
|
|
767
774
|
|
|
768
|
-
|
|
775
|
+
}
|
|
769
776
|
|
|
770
|
-
|
|
777
|
+
_handleKeyDown( event ) {
|
|
771
778
|
|
|
772
|
-
|
|
779
|
+
let needsUpdate = false;
|
|
773
780
|
|
|
774
|
-
|
|
781
|
+
switch ( event.code ) {
|
|
775
782
|
|
|
776
|
-
|
|
783
|
+
case this.keys.UP:
|
|
777
784
|
|
|
778
|
-
|
|
785
|
+
if ( event.ctrlKey || event.metaKey || event.shiftKey ) {
|
|
779
786
|
|
|
780
|
-
|
|
787
|
+
this._rotateUp( _twoPI * this.rotateSpeed / this.domElement.clientHeight );
|
|
781
788
|
|
|
782
|
-
|
|
789
|
+
} else {
|
|
783
790
|
|
|
784
|
-
|
|
785
|
-
break;
|
|
791
|
+
this._pan( 0, this.keyPanSpeed );
|
|
786
792
|
|
|
787
|
-
|
|
793
|
+
}
|
|
788
794
|
|
|
789
|
-
|
|
795
|
+
needsUpdate = true;
|
|
796
|
+
break;
|
|
790
797
|
|
|
791
|
-
|
|
798
|
+
case this.keys.BOTTOM:
|
|
792
799
|
|
|
793
|
-
|
|
800
|
+
if ( event.ctrlKey || event.metaKey || event.shiftKey ) {
|
|
794
801
|
|
|
795
|
-
|
|
802
|
+
this._rotateUp( - _twoPI * this.rotateSpeed / this.domElement.clientHeight );
|
|
796
803
|
|
|
797
|
-
|
|
804
|
+
} else {
|
|
798
805
|
|
|
799
|
-
|
|
800
|
-
break;
|
|
806
|
+
this._pan( 0, - this.keyPanSpeed );
|
|
801
807
|
|
|
802
|
-
|
|
808
|
+
}
|
|
803
809
|
|
|
804
|
-
|
|
810
|
+
needsUpdate = true;
|
|
811
|
+
break;
|
|
805
812
|
|
|
806
|
-
|
|
813
|
+
case this.keys.LEFT:
|
|
807
814
|
|
|
808
|
-
|
|
815
|
+
if ( event.ctrlKey || event.metaKey || event.shiftKey ) {
|
|
809
816
|
|
|
810
|
-
|
|
817
|
+
this._rotateLeft( _twoPI * this.rotateSpeed / this.domElement.clientHeight );
|
|
811
818
|
|
|
812
|
-
|
|
819
|
+
} else {
|
|
813
820
|
|
|
814
|
-
|
|
815
|
-
break;
|
|
821
|
+
this._pan( this.keyPanSpeed, 0 );
|
|
816
822
|
|
|
817
|
-
|
|
823
|
+
}
|
|
818
824
|
|
|
819
|
-
|
|
825
|
+
needsUpdate = true;
|
|
826
|
+
break;
|
|
820
827
|
|
|
821
|
-
|
|
828
|
+
case this.keys.RIGHT:
|
|
822
829
|
|
|
823
|
-
|
|
830
|
+
if ( event.ctrlKey || event.metaKey || event.shiftKey ) {
|
|
824
831
|
|
|
825
|
-
|
|
832
|
+
this._rotateLeft( - _twoPI * this.rotateSpeed / this.domElement.clientHeight );
|
|
826
833
|
|
|
827
|
-
|
|
834
|
+
} else {
|
|
828
835
|
|
|
829
|
-
|
|
830
|
-
break;
|
|
836
|
+
this._pan( - this.keyPanSpeed, 0 );
|
|
831
837
|
|
|
832
|
-
|
|
838
|
+
}
|
|
833
839
|
|
|
834
|
-
|
|
840
|
+
needsUpdate = true;
|
|
841
|
+
break;
|
|
835
842
|
|
|
836
|
-
|
|
837
|
-
event.preventDefault();
|
|
843
|
+
}
|
|
838
844
|
|
|
839
|
-
|
|
845
|
+
if ( needsUpdate ) {
|
|
840
846
|
|
|
841
|
-
|
|
847
|
+
// prevent the browser from scrolling on cursor keys
|
|
848
|
+
event.preventDefault();
|
|
842
849
|
|
|
850
|
+
this.update();
|
|
843
851
|
|
|
844
852
|
}
|
|
845
853
|
|
|
846
|
-
function handleTouchStartRotate( event ) {
|
|
847
854
|
|
|
848
|
-
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
_handleTouchStartRotate( event ) {
|
|
849
858
|
|
|
850
|
-
|
|
859
|
+
if ( this._pointers.length === 1 ) {
|
|
851
860
|
|
|
852
|
-
|
|
861
|
+
this._rotateStart.set( event.pageX, event.pageY );
|
|
853
862
|
|
|
854
|
-
|
|
863
|
+
} else {
|
|
855
864
|
|
|
856
|
-
|
|
857
|
-
const y = 0.5 * ( event.pageY + position.y );
|
|
865
|
+
const position = this._getSecondPointerPosition( event );
|
|
858
866
|
|
|
859
|
-
|
|
867
|
+
const x = 0.5 * ( event.pageX + position.x );
|
|
868
|
+
const y = 0.5 * ( event.pageY + position.y );
|
|
860
869
|
|
|
861
|
-
|
|
870
|
+
this._rotateStart.set( x, y );
|
|
862
871
|
|
|
863
872
|
}
|
|
864
873
|
|
|
865
|
-
|
|
874
|
+
}
|
|
866
875
|
|
|
867
|
-
|
|
876
|
+
_handleTouchStartPan( event ) {
|
|
868
877
|
|
|
869
|
-
|
|
878
|
+
if ( this._pointers.length === 1 ) {
|
|
870
879
|
|
|
871
|
-
|
|
880
|
+
this._panStart.set( event.pageX, event.pageY );
|
|
872
881
|
|
|
873
|
-
|
|
882
|
+
} else {
|
|
874
883
|
|
|
875
|
-
|
|
876
|
-
const y = 0.5 * ( event.pageY + position.y );
|
|
884
|
+
const position = this._getSecondPointerPosition( event );
|
|
877
885
|
|
|
878
|
-
|
|
886
|
+
const x = 0.5 * ( event.pageX + position.x );
|
|
887
|
+
const y = 0.5 * ( event.pageY + position.y );
|
|
879
888
|
|
|
880
|
-
|
|
889
|
+
this._panStart.set( x, y );
|
|
881
890
|
|
|
882
891
|
}
|
|
883
892
|
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
const position = getSecondPointerPosition( event );
|
|
887
|
-
|
|
888
|
-
const dx = event.pageX - position.x;
|
|
889
|
-
const dy = event.pageY - position.y;
|
|
890
|
-
|
|
891
|
-
const distance = Math.sqrt( dx * dx + dy * dy );
|
|
892
|
-
|
|
893
|
-
dollyStart.set( 0, distance );
|
|
894
|
-
|
|
895
|
-
}
|
|
893
|
+
}
|
|
896
894
|
|
|
897
|
-
|
|
895
|
+
_handleTouchStartDolly( event ) {
|
|
898
896
|
|
|
899
|
-
|
|
897
|
+
const position = this._getSecondPointerPosition( event );
|
|
900
898
|
|
|
901
|
-
|
|
899
|
+
const dx = event.pageX - position.x;
|
|
900
|
+
const dy = event.pageY - position.y;
|
|
902
901
|
|
|
903
|
-
|
|
902
|
+
const distance = Math.sqrt( dx * dx + dy * dy );
|
|
904
903
|
|
|
905
|
-
|
|
904
|
+
this._dollyStart.set( 0, distance );
|
|
906
905
|
|
|
907
|
-
|
|
906
|
+
}
|
|
908
907
|
|
|
909
|
-
|
|
908
|
+
_handleTouchStartDollyPan( event ) {
|
|
910
909
|
|
|
911
|
-
|
|
910
|
+
if ( this.enableZoom ) this._handleTouchStartDolly( event );
|
|
912
911
|
|
|
913
|
-
|
|
912
|
+
if ( this.enablePan ) this._handleTouchStartPan( event );
|
|
914
913
|
|
|
915
|
-
|
|
914
|
+
}
|
|
916
915
|
|
|
917
|
-
|
|
916
|
+
_handleTouchStartDollyRotate( event ) {
|
|
918
917
|
|
|
919
|
-
|
|
918
|
+
if ( this.enableZoom ) this._handleTouchStartDolly( event );
|
|
920
919
|
|
|
921
|
-
|
|
920
|
+
if ( this.enableRotate ) this._handleTouchStartRotate( event );
|
|
922
921
|
|
|
923
|
-
|
|
924
|
-
const y = 0.5 * ( event.pageY + position.y );
|
|
922
|
+
}
|
|
925
923
|
|
|
926
|
-
|
|
924
|
+
_handleTouchMoveRotate( event ) {
|
|
927
925
|
|
|
928
|
-
|
|
926
|
+
if ( this._pointers.length == 1 ) {
|
|
929
927
|
|
|
930
|
-
|
|
928
|
+
this._rotateEnd.set( event.pageX, event.pageY );
|
|
931
929
|
|
|
932
|
-
|
|
930
|
+
} else {
|
|
933
931
|
|
|
934
|
-
|
|
932
|
+
const position = this._getSecondPointerPosition( event );
|
|
935
933
|
|
|
936
|
-
|
|
934
|
+
const x = 0.5 * ( event.pageX + position.x );
|
|
935
|
+
const y = 0.5 * ( event.pageY + position.y );
|
|
937
936
|
|
|
938
|
-
|
|
937
|
+
this._rotateEnd.set( x, y );
|
|
939
938
|
|
|
940
939
|
}
|
|
941
940
|
|
|
942
|
-
|
|
941
|
+
this._rotateDelta.subVectors( this._rotateEnd, this._rotateStart ).multiplyScalar( this.rotateSpeed );
|
|
943
942
|
|
|
944
|
-
|
|
943
|
+
const element = this.domElement;
|
|
945
944
|
|
|
946
|
-
|
|
945
|
+
this._rotateLeft( _twoPI * this._rotateDelta.x / element.clientHeight ); // yes, height
|
|
947
946
|
|
|
948
|
-
|
|
947
|
+
this._rotateUp( _twoPI * this._rotateDelta.y / element.clientHeight );
|
|
949
948
|
|
|
950
|
-
|
|
949
|
+
this._rotateStart.copy( this._rotateEnd );
|
|
951
950
|
|
|
952
|
-
|
|
953
|
-
const y = 0.5 * ( event.pageY + position.y );
|
|
951
|
+
}
|
|
954
952
|
|
|
955
|
-
|
|
953
|
+
_handleTouchMovePan( event ) {
|
|
956
954
|
|
|
957
|
-
|
|
955
|
+
if ( this._pointers.length === 1 ) {
|
|
958
956
|
|
|
959
|
-
|
|
957
|
+
this._panEnd.set( event.pageX, event.pageY );
|
|
960
958
|
|
|
961
|
-
|
|
959
|
+
} else {
|
|
962
960
|
|
|
963
|
-
|
|
961
|
+
const position = this._getSecondPointerPosition( event );
|
|
964
962
|
|
|
965
|
-
|
|
963
|
+
const x = 0.5 * ( event.pageX + position.x );
|
|
964
|
+
const y = 0.5 * ( event.pageY + position.y );
|
|
966
965
|
|
|
967
|
-
|
|
966
|
+
this._panEnd.set( x, y );
|
|
968
967
|
|
|
969
|
-
|
|
968
|
+
}
|
|
970
969
|
|
|
971
|
-
|
|
972
|
-
const dy = event.pageY - position.y;
|
|
970
|
+
this._panDelta.subVectors( this._panEnd, this._panStart ).multiplyScalar( this.panSpeed );
|
|
973
971
|
|
|
974
|
-
|
|
972
|
+
this._pan( this._panDelta.x, this._panDelta.y );
|
|
975
973
|
|
|
976
|
-
|
|
974
|
+
this._panStart.copy( this._panEnd );
|
|
977
975
|
|
|
978
|
-
|
|
976
|
+
}
|
|
979
977
|
|
|
980
|
-
|
|
978
|
+
_handleTouchMoveDolly( event ) {
|
|
981
979
|
|
|
982
|
-
|
|
980
|
+
const position = this._getSecondPointerPosition( event );
|
|
983
981
|
|
|
984
|
-
|
|
985
|
-
|
|
982
|
+
const dx = event.pageX - position.x;
|
|
983
|
+
const dy = event.pageY - position.y;
|
|
986
984
|
|
|
987
|
-
|
|
985
|
+
const distance = Math.sqrt( dx * dx + dy * dy );
|
|
988
986
|
|
|
989
|
-
|
|
987
|
+
this._dollyEnd.set( 0, distance );
|
|
990
988
|
|
|
991
|
-
|
|
989
|
+
this._dollyDelta.set( 0, Math.pow( this._dollyEnd.y / this._dollyStart.y, this.zoomSpeed ) );
|
|
992
990
|
|
|
993
|
-
|
|
991
|
+
this._dollyOut( this._dollyDelta.y );
|
|
994
992
|
|
|
995
|
-
|
|
993
|
+
this._dollyStart.copy( this._dollyEnd );
|
|
996
994
|
|
|
997
|
-
|
|
995
|
+
const centerX = ( event.pageX + position.x ) * 0.5;
|
|
996
|
+
const centerY = ( event.pageY + position.y ) * 0.5;
|
|
998
997
|
|
|
999
|
-
|
|
998
|
+
this._updateZoomParameters( centerX, centerY );
|
|
1000
999
|
|
|
1001
|
-
|
|
1000
|
+
}
|
|
1002
1001
|
|
|
1003
|
-
|
|
1002
|
+
_handleTouchMoveDollyPan( event ) {
|
|
1004
1003
|
|
|
1005
|
-
|
|
1004
|
+
if ( this.enableZoom ) this._handleTouchMoveDolly( event );
|
|
1006
1005
|
|
|
1007
|
-
|
|
1008
|
-
// event handlers - FSM: listen for events and reset state
|
|
1009
|
-
//
|
|
1006
|
+
if ( this.enablePan ) this._handleTouchMovePan( event );
|
|
1010
1007
|
|
|
1011
|
-
|
|
1008
|
+
}
|
|
1012
1009
|
|
|
1013
|
-
|
|
1010
|
+
_handleTouchMoveDollyRotate( event ) {
|
|
1014
1011
|
|
|
1015
|
-
|
|
1012
|
+
if ( this.enableZoom ) this._handleTouchMoveDolly( event );
|
|
1016
1013
|
|
|
1017
|
-
|
|
1014
|
+
if ( this.enableRotate ) this._handleTouchMoveRotate( event );
|
|
1018
1015
|
|
|
1019
|
-
|
|
1020
|
-
scope.domElement.addEventListener( 'pointerup', onPointerUp );
|
|
1016
|
+
}
|
|
1021
1017
|
|
|
1022
|
-
|
|
1018
|
+
// pointers
|
|
1023
1019
|
|
|
1024
|
-
|
|
1020
|
+
_addPointer( event ) {
|
|
1025
1021
|
|
|
1026
|
-
|
|
1022
|
+
this._pointers.push( event.pointerId );
|
|
1027
1023
|
|
|
1028
|
-
|
|
1024
|
+
}
|
|
1029
1025
|
|
|
1030
|
-
|
|
1026
|
+
_removePointer( event ) {
|
|
1031
1027
|
|
|
1032
|
-
|
|
1028
|
+
delete this._pointerPositions[ event.pointerId ];
|
|
1033
1029
|
|
|
1034
|
-
|
|
1030
|
+
for ( let i = 0; i < this._pointers.length; i ++ ) {
|
|
1035
1031
|
|
|
1036
|
-
|
|
1032
|
+
if ( this._pointers[ i ] == event.pointerId ) {
|
|
1037
1033
|
|
|
1038
|
-
|
|
1034
|
+
this._pointers.splice( i, 1 );
|
|
1035
|
+
return;
|
|
1039
1036
|
|
|
1040
1037
|
}
|
|
1041
1038
|
|
|
1042
1039
|
}
|
|
1043
1040
|
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
if ( scope.enabled === false ) return;
|
|
1041
|
+
}
|
|
1047
1042
|
|
|
1048
|
-
|
|
1043
|
+
_isTrackingPointer( event ) {
|
|
1049
1044
|
|
|
1050
|
-
|
|
1045
|
+
for ( let i = 0; i < this._pointers.length; i ++ ) {
|
|
1051
1046
|
|
|
1052
|
-
|
|
1047
|
+
if ( this._pointers[ i ] == event.pointerId ) return true;
|
|
1053
1048
|
|
|
1054
|
-
|
|
1049
|
+
}
|
|
1055
1050
|
|
|
1056
|
-
|
|
1051
|
+
return false;
|
|
1057
1052
|
|
|
1058
|
-
|
|
1053
|
+
}
|
|
1059
1054
|
|
|
1060
|
-
|
|
1055
|
+
_trackPointer( event ) {
|
|
1061
1056
|
|
|
1062
|
-
|
|
1057
|
+
let position = this._pointerPositions[ event.pointerId ];
|
|
1063
1058
|
|
|
1064
|
-
|
|
1059
|
+
if ( position === undefined ) {
|
|
1065
1060
|
|
|
1066
|
-
|
|
1061
|
+
position = new Vector2();
|
|
1062
|
+
this._pointerPositions[ event.pointerId ] = position;
|
|
1067
1063
|
|
|
1068
|
-
|
|
1064
|
+
}
|
|
1069
1065
|
|
|
1070
|
-
|
|
1071
|
-
scope.domElement.removeEventListener( 'pointerup', onPointerUp );
|
|
1066
|
+
position.set( event.pageX, event.pageY );
|
|
1072
1067
|
|
|
1073
|
-
|
|
1068
|
+
}
|
|
1074
1069
|
|
|
1075
|
-
|
|
1070
|
+
_getSecondPointerPosition( event ) {
|
|
1076
1071
|
|
|
1077
|
-
|
|
1072
|
+
const pointerId = ( event.pointerId === this._pointers[ 0 ] ) ? this._pointers[ 1 ] : this._pointers[ 0 ];
|
|
1078
1073
|
|
|
1079
|
-
|
|
1074
|
+
return this._pointerPositions[ pointerId ];
|
|
1080
1075
|
|
|
1081
|
-
|
|
1082
|
-
const position = pointerPositions[ pointerId ];
|
|
1076
|
+
}
|
|
1083
1077
|
|
|
1084
|
-
|
|
1085
|
-
onTouchStart( { pointerId: pointerId, pageX: position.x, pageY: position.y } );
|
|
1078
|
+
//
|
|
1086
1079
|
|
|
1087
|
-
|
|
1080
|
+
_customWheelEvent( event ) {
|
|
1088
1081
|
|
|
1089
|
-
|
|
1082
|
+
const mode = event.deltaMode;
|
|
1090
1083
|
|
|
1091
|
-
|
|
1084
|
+
// minimal wheel event altered to meet delta-zoom demand
|
|
1085
|
+
const newEvent = {
|
|
1086
|
+
clientX: event.clientX,
|
|
1087
|
+
clientY: event.clientY,
|
|
1088
|
+
deltaY: event.deltaY,
|
|
1089
|
+
};
|
|
1092
1090
|
|
|
1093
|
-
|
|
1091
|
+
switch ( mode ) {
|
|
1094
1092
|
|
|
1095
|
-
|
|
1093
|
+
case 1: // LINE_MODE
|
|
1094
|
+
newEvent.deltaY *= 16;
|
|
1095
|
+
break;
|
|
1096
1096
|
|
|
1097
|
-
|
|
1097
|
+
case 2: // PAGE_MODE
|
|
1098
|
+
newEvent.deltaY *= 100;
|
|
1099
|
+
break;
|
|
1098
1100
|
|
|
1099
|
-
|
|
1101
|
+
}
|
|
1100
1102
|
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
+
// detect if event was triggered by pinching
|
|
1104
|
+
if ( event.ctrlKey && ! this._controlActive ) {
|
|
1103
1105
|
|
|
1104
|
-
|
|
1106
|
+
newEvent.deltaY *= 10;
|
|
1105
1107
|
|
|
1106
|
-
|
|
1107
|
-
break;
|
|
1108
|
+
}
|
|
1108
1109
|
|
|
1109
|
-
|
|
1110
|
+
return newEvent;
|
|
1110
1111
|
|
|
1111
|
-
|
|
1112
|
-
break;
|
|
1112
|
+
}
|
|
1113
1113
|
|
|
1114
|
-
|
|
1114
|
+
}
|
|
1115
1115
|
|
|
1116
|
-
|
|
1116
|
+
function onPointerDown( event ) {
|
|
1117
1117
|
|
|
1118
|
-
|
|
1118
|
+
if ( this.enabled === false ) return;
|
|
1119
1119
|
|
|
1120
|
-
|
|
1120
|
+
if ( this._pointers.length === 0 ) {
|
|
1121
1121
|
|
|
1122
|
-
|
|
1122
|
+
this.domElement.setPointerCapture( event.pointerId );
|
|
1123
1123
|
|
|
1124
|
-
|
|
1124
|
+
this.domElement.addEventListener( 'pointermove', this._onPointerMove );
|
|
1125
|
+
this.domElement.addEventListener( 'pointerup', this._onPointerUp );
|
|
1125
1126
|
|
|
1126
|
-
|
|
1127
|
+
}
|
|
1127
1128
|
|
|
1128
|
-
|
|
1129
|
+
//
|
|
1129
1130
|
|
|
1130
|
-
|
|
1131
|
+
if ( this._isTrackingPointer( event ) ) return;
|
|
1131
1132
|
|
|
1132
|
-
|
|
1133
|
+
//
|
|
1133
1134
|
|
|
1134
|
-
|
|
1135
|
+
this._addPointer( event );
|
|
1135
1136
|
|
|
1136
|
-
|
|
1137
|
+
if ( event.pointerType === 'touch' ) {
|
|
1137
1138
|
|
|
1138
|
-
|
|
1139
|
+
this._onTouchStart( event );
|
|
1139
1140
|
|
|
1140
|
-
|
|
1141
|
+
} else {
|
|
1141
1142
|
|
|
1142
|
-
|
|
1143
|
+
this._onMouseDown( event );
|
|
1143
1144
|
|
|
1144
|
-
|
|
1145
|
+
}
|
|
1145
1146
|
|
|
1146
|
-
|
|
1147
|
+
}
|
|
1147
1148
|
|
|
1148
|
-
|
|
1149
|
+
function onPointerMove( event ) {
|
|
1149
1150
|
|
|
1150
|
-
|
|
1151
|
+
if ( this.enabled === false ) return;
|
|
1151
1152
|
|
|
1152
|
-
|
|
1153
|
+
if ( event.pointerType === 'touch' ) {
|
|
1153
1154
|
|
|
1154
|
-
|
|
1155
|
+
this._onTouchMove( event );
|
|
1155
1156
|
|
|
1156
|
-
|
|
1157
|
+
} else {
|
|
1157
1158
|
|
|
1158
|
-
|
|
1159
|
+
this._onMouseMove( event );
|
|
1159
1160
|
|
|
1160
|
-
|
|
1161
|
+
}
|
|
1161
1162
|
|
|
1162
|
-
|
|
1163
|
+
}
|
|
1163
1164
|
|
|
1164
|
-
|
|
1165
|
+
function onPointerUp( event ) {
|
|
1165
1166
|
|
|
1166
|
-
|
|
1167
|
+
this._removePointer( event );
|
|
1167
1168
|
|
|
1168
|
-
|
|
1169
|
+
switch ( this._pointers.length ) {
|
|
1169
1170
|
|
|
1170
|
-
|
|
1171
|
+
case 0:
|
|
1171
1172
|
|
|
1172
|
-
|
|
1173
|
+
this.domElement.releasePointerCapture( event.pointerId );
|
|
1173
1174
|
|
|
1174
|
-
|
|
1175
|
+
this.domElement.removeEventListener( 'pointermove', this._onPointerMove );
|
|
1176
|
+
this.domElement.removeEventListener( 'pointerup', this._onPointerUp );
|
|
1175
1177
|
|
|
1176
|
-
|
|
1178
|
+
this.dispatchEvent( _endEvent );
|
|
1177
1179
|
|
|
1178
|
-
|
|
1180
|
+
this.state = _STATE.NONE;
|
|
1179
1181
|
|
|
1180
|
-
|
|
1182
|
+
break;
|
|
1181
1183
|
|
|
1182
|
-
|
|
1184
|
+
case 1:
|
|
1183
1185
|
|
|
1184
|
-
|
|
1186
|
+
const pointerId = this._pointers[ 0 ];
|
|
1187
|
+
const position = this._pointerPositions[ pointerId ];
|
|
1185
1188
|
|
|
1186
|
-
|
|
1189
|
+
// minimal placeholder event - allows state correction on pointer-up
|
|
1190
|
+
this._onTouchStart( { pointerId: pointerId, pageX: position.x, pageY: position.y } );
|
|
1187
1191
|
|
|
1188
|
-
|
|
1192
|
+
break;
|
|
1189
1193
|
|
|
1190
|
-
|
|
1194
|
+
}
|
|
1191
1195
|
|
|
1192
|
-
|
|
1196
|
+
}
|
|
1193
1197
|
|
|
1194
|
-
|
|
1198
|
+
function onMouseDown( event ) {
|
|
1195
1199
|
|
|
1196
|
-
|
|
1200
|
+
let mouseAction;
|
|
1197
1201
|
|
|
1198
|
-
|
|
1202
|
+
switch ( event.button ) {
|
|
1199
1203
|
|
|
1200
|
-
|
|
1204
|
+
case 0:
|
|
1201
1205
|
|
|
1202
|
-
|
|
1206
|
+
mouseAction = this.mouseButtons.LEFT;
|
|
1207
|
+
break;
|
|
1203
1208
|
|
|
1204
|
-
|
|
1209
|
+
case 1:
|
|
1205
1210
|
|
|
1206
|
-
|
|
1211
|
+
mouseAction = this.mouseButtons.MIDDLE;
|
|
1212
|
+
break;
|
|
1207
1213
|
|
|
1208
|
-
|
|
1214
|
+
case 2:
|
|
1209
1215
|
|
|
1210
|
-
|
|
1216
|
+
mouseAction = this.mouseButtons.RIGHT;
|
|
1217
|
+
break;
|
|
1211
1218
|
|
|
1212
|
-
|
|
1219
|
+
default:
|
|
1213
1220
|
|
|
1214
|
-
|
|
1221
|
+
mouseAction = - 1;
|
|
1215
1222
|
|
|
1216
|
-
|
|
1223
|
+
}
|
|
1217
1224
|
|
|
1218
|
-
|
|
1225
|
+
switch ( mouseAction ) {
|
|
1219
1226
|
|
|
1220
|
-
|
|
1227
|
+
case MOUSE.DOLLY:
|
|
1221
1228
|
|
|
1222
|
-
|
|
1229
|
+
if ( this.enableZoom === false ) return;
|
|
1223
1230
|
|
|
1224
|
-
|
|
1231
|
+
this._handleMouseDownDolly( event );
|
|
1225
1232
|
|
|
1226
|
-
|
|
1233
|
+
this.state = _STATE.DOLLY;
|
|
1227
1234
|
|
|
1228
|
-
|
|
1235
|
+
break;
|
|
1229
1236
|
|
|
1230
|
-
|
|
1237
|
+
case MOUSE.ROTATE:
|
|
1231
1238
|
|
|
1232
|
-
|
|
1239
|
+
if ( event.ctrlKey || event.metaKey || event.shiftKey ) {
|
|
1233
1240
|
|
|
1234
|
-
|
|
1241
|
+
if ( this.enablePan === false ) return;
|
|
1235
1242
|
|
|
1236
|
-
|
|
1243
|
+
this._handleMouseDownPan( event );
|
|
1237
1244
|
|
|
1238
|
-
|
|
1245
|
+
this.state = _STATE.PAN;
|
|
1239
1246
|
|
|
1240
|
-
|
|
1241
|
-
const newEvent = {
|
|
1242
|
-
clientX: event.clientX,
|
|
1243
|
-
clientY: event.clientY,
|
|
1244
|
-
deltaY: event.deltaY,
|
|
1245
|
-
};
|
|
1247
|
+
} else {
|
|
1246
1248
|
|
|
1247
|
-
|
|
1249
|
+
if ( this.enableRotate === false ) return;
|
|
1248
1250
|
|
|
1249
|
-
|
|
1250
|
-
newEvent.deltaY *= 16;
|
|
1251
|
-
break;
|
|
1251
|
+
this._handleMouseDownRotate( event );
|
|
1252
1252
|
|
|
1253
|
-
|
|
1254
|
-
newEvent.deltaY *= 100;
|
|
1255
|
-
break;
|
|
1253
|
+
this.state = _STATE.ROTATE;
|
|
1256
1254
|
|
|
1257
1255
|
}
|
|
1258
1256
|
|
|
1259
|
-
|
|
1260
|
-
if ( event.ctrlKey && ! controlActive ) {
|
|
1257
|
+
break;
|
|
1261
1258
|
|
|
1262
|
-
|
|
1259
|
+
case MOUSE.PAN:
|
|
1263
1260
|
|
|
1264
|
-
|
|
1261
|
+
if ( event.ctrlKey || event.metaKey || event.shiftKey ) {
|
|
1265
1262
|
|
|
1266
|
-
|
|
1263
|
+
if ( this.enableRotate === false ) return;
|
|
1267
1264
|
|
|
1268
|
-
|
|
1265
|
+
this._handleMouseDownRotate( event );
|
|
1269
1266
|
|
|
1270
|
-
|
|
1267
|
+
this.state = _STATE.ROTATE;
|
|
1271
1268
|
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
controlActive = true;
|
|
1269
|
+
} else {
|
|
1275
1270
|
|
|
1271
|
+
if ( this.enablePan === false ) return;
|
|
1276
1272
|
|
|
1277
|
-
|
|
1273
|
+
this._handleMouseDownPan( event );
|
|
1278
1274
|
|
|
1279
|
-
|
|
1275
|
+
this.state = _STATE.PAN;
|
|
1280
1276
|
|
|
1281
1277
|
}
|
|
1282
1278
|
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
function interceptControlUp( event ) {
|
|
1279
|
+
break;
|
|
1286
1280
|
|
|
1287
|
-
|
|
1281
|
+
default:
|
|
1288
1282
|
|
|
1289
|
-
|
|
1283
|
+
this.state = _STATE.NONE;
|
|
1290
1284
|
|
|
1285
|
+
}
|
|
1291
1286
|
|
|
1292
|
-
|
|
1287
|
+
if ( this.state !== _STATE.NONE ) {
|
|
1293
1288
|
|
|
1294
|
-
|
|
1289
|
+
this.dispatchEvent( _startEvent );
|
|
1295
1290
|
|
|
1296
|
-
|
|
1291
|
+
}
|
|
1297
1292
|
|
|
1298
|
-
|
|
1293
|
+
}
|
|
1299
1294
|
|
|
1300
|
-
|
|
1295
|
+
function onMouseMove( event ) {
|
|
1301
1296
|
|
|
1302
|
-
|
|
1297
|
+
switch ( this.state ) {
|
|
1303
1298
|
|
|
1304
|
-
|
|
1299
|
+
case _STATE.ROTATE:
|
|
1305
1300
|
|
|
1306
|
-
|
|
1301
|
+
if ( this.enableRotate === false ) return;
|
|
1307
1302
|
|
|
1308
|
-
|
|
1303
|
+
this._handleMouseMoveRotate( event );
|
|
1309
1304
|
|
|
1310
|
-
|
|
1305
|
+
break;
|
|
1311
1306
|
|
|
1312
|
-
|
|
1307
|
+
case _STATE.DOLLY:
|
|
1313
1308
|
|
|
1314
|
-
|
|
1309
|
+
if ( this.enableZoom === false ) return;
|
|
1315
1310
|
|
|
1316
|
-
|
|
1311
|
+
this._handleMouseMoveDolly( event );
|
|
1317
1312
|
|
|
1318
|
-
|
|
1313
|
+
break;
|
|
1319
1314
|
|
|
1320
|
-
|
|
1315
|
+
case _STATE.PAN:
|
|
1321
1316
|
|
|
1322
|
-
|
|
1317
|
+
if ( this.enablePan === false ) return;
|
|
1323
1318
|
|
|
1324
|
-
|
|
1319
|
+
this._handleMouseMovePan( event );
|
|
1325
1320
|
|
|
1326
|
-
|
|
1321
|
+
break;
|
|
1327
1322
|
|
|
1328
|
-
|
|
1323
|
+
}
|
|
1329
1324
|
|
|
1330
|
-
|
|
1325
|
+
}
|
|
1331
1326
|
|
|
1332
|
-
|
|
1327
|
+
function onMouseWheel( event ) {
|
|
1333
1328
|
|
|
1334
|
-
|
|
1329
|
+
if ( this.enabled === false || this.enableZoom === false || this.state !== _STATE.NONE ) return;
|
|
1335
1330
|
|
|
1336
|
-
|
|
1331
|
+
event.preventDefault();
|
|
1337
1332
|
|
|
1338
|
-
|
|
1333
|
+
this.dispatchEvent( _startEvent );
|
|
1339
1334
|
|
|
1340
|
-
|
|
1335
|
+
this._handleMouseWheel( this._customWheelEvent( event ) );
|
|
1341
1336
|
|
|
1342
|
-
|
|
1337
|
+
this.dispatchEvent( _endEvent );
|
|
1343
1338
|
|
|
1344
|
-
|
|
1339
|
+
}
|
|
1345
1340
|
|
|
1346
|
-
|
|
1341
|
+
function onKeyDown( event ) {
|
|
1347
1342
|
|
|
1348
|
-
|
|
1343
|
+
if ( this.enabled === false || this.enablePan === false ) return;
|
|
1349
1344
|
|
|
1350
|
-
|
|
1345
|
+
this._handleKeyDown( event );
|
|
1351
1346
|
|
|
1352
|
-
|
|
1347
|
+
}
|
|
1353
1348
|
|
|
1354
|
-
|
|
1349
|
+
function onTouchStart( event ) {
|
|
1355
1350
|
|
|
1356
|
-
|
|
1351
|
+
this._trackPointer( event );
|
|
1357
1352
|
|
|
1358
|
-
|
|
1353
|
+
switch ( this._pointers.length ) {
|
|
1359
1354
|
|
|
1360
|
-
|
|
1355
|
+
case 1:
|
|
1361
1356
|
|
|
1362
|
-
|
|
1357
|
+
switch ( this.touches.ONE ) {
|
|
1363
1358
|
|
|
1364
|
-
|
|
1359
|
+
case TOUCH.ROTATE:
|
|
1365
1360
|
|
|
1366
|
-
|
|
1361
|
+
if ( this.enableRotate === false ) return;
|
|
1367
1362
|
|
|
1368
|
-
|
|
1363
|
+
this._handleTouchStartRotate( event );
|
|
1369
1364
|
|
|
1370
|
-
|
|
1365
|
+
this.state = _STATE.TOUCH_ROTATE;
|
|
1371
1366
|
|
|
1372
|
-
|
|
1367
|
+
break;
|
|
1373
1368
|
|
|
1374
|
-
|
|
1369
|
+
case TOUCH.PAN:
|
|
1375
1370
|
|
|
1376
|
-
|
|
1371
|
+
if ( this.enablePan === false ) return;
|
|
1377
1372
|
|
|
1378
|
-
|
|
1373
|
+
this._handleTouchStartPan( event );
|
|
1379
1374
|
|
|
1380
|
-
state =
|
|
1375
|
+
this.state = _STATE.TOUCH_PAN;
|
|
1381
1376
|
|
|
1382
|
-
|
|
1377
|
+
break;
|
|
1383
1378
|
|
|
1384
|
-
|
|
1379
|
+
default:
|
|
1385
1380
|
|
|
1386
|
-
|
|
1381
|
+
this.state = _STATE.NONE;
|
|
1387
1382
|
|
|
1388
1383
|
}
|
|
1389
1384
|
|
|
1390
|
-
|
|
1385
|
+
break;
|
|
1391
1386
|
|
|
1392
|
-
|
|
1387
|
+
case 2:
|
|
1393
1388
|
|
|
1394
|
-
|
|
1389
|
+
switch ( this.touches.TWO ) {
|
|
1395
1390
|
|
|
1396
|
-
|
|
1391
|
+
case TOUCH.DOLLY_PAN:
|
|
1397
1392
|
|
|
1398
|
-
|
|
1393
|
+
if ( this.enableZoom === false && this.enablePan === false ) return;
|
|
1399
1394
|
|
|
1400
|
-
|
|
1395
|
+
this._handleTouchStartDollyPan( event );
|
|
1401
1396
|
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
scope.update();
|
|
1397
|
+
this.state = _STATE.TOUCH_DOLLY_PAN;
|
|
1405
1398
|
|
|
1406
1399
|
break;
|
|
1407
1400
|
|
|
1408
|
-
case
|
|
1401
|
+
case TOUCH.DOLLY_ROTATE:
|
|
1409
1402
|
|
|
1410
|
-
if (
|
|
1403
|
+
if ( this.enableZoom === false && this.enableRotate === false ) return;
|
|
1411
1404
|
|
|
1412
|
-
|
|
1405
|
+
this._handleTouchStartDollyRotate( event );
|
|
1413
1406
|
|
|
1414
|
-
|
|
1407
|
+
this.state = _STATE.TOUCH_DOLLY_ROTATE;
|
|
1415
1408
|
|
|
1416
1409
|
break;
|
|
1417
1410
|
|
|
1418
|
-
|
|
1411
|
+
default:
|
|
1419
1412
|
|
|
1420
|
-
|
|
1413
|
+
this.state = _STATE.NONE;
|
|
1421
1414
|
|
|
1422
|
-
|
|
1415
|
+
}
|
|
1423
1416
|
|
|
1424
|
-
|
|
1417
|
+
break;
|
|
1425
1418
|
|
|
1426
|
-
|
|
1419
|
+
default:
|
|
1427
1420
|
|
|
1428
|
-
|
|
1421
|
+
this.state = _STATE.NONE;
|
|
1429
1422
|
|
|
1430
|
-
|
|
1423
|
+
}
|
|
1431
1424
|
|
|
1432
|
-
|
|
1425
|
+
if ( this.state !== _STATE.NONE ) {
|
|
1433
1426
|
|
|
1434
|
-
|
|
1427
|
+
this.dispatchEvent( _startEvent );
|
|
1435
1428
|
|
|
1436
|
-
|
|
1429
|
+
}
|
|
1437
1430
|
|
|
1438
|
-
|
|
1431
|
+
}
|
|
1439
1432
|
|
|
1440
|
-
|
|
1433
|
+
function onTouchMove( event ) {
|
|
1441
1434
|
|
|
1442
|
-
|
|
1435
|
+
this._trackPointer( event );
|
|
1443
1436
|
|
|
1444
|
-
|
|
1437
|
+
switch ( this.state ) {
|
|
1445
1438
|
|
|
1446
|
-
|
|
1439
|
+
case _STATE.TOUCH_ROTATE:
|
|
1447
1440
|
|
|
1448
|
-
if (
|
|
1441
|
+
if ( this.enableRotate === false ) return;
|
|
1449
1442
|
|
|
1450
|
-
|
|
1443
|
+
this._handleTouchMoveRotate( event );
|
|
1451
1444
|
|
|
1452
|
-
|
|
1445
|
+
this.update();
|
|
1453
1446
|
|
|
1454
|
-
|
|
1447
|
+
break;
|
|
1455
1448
|
|
|
1456
|
-
|
|
1449
|
+
case _STATE.TOUCH_PAN:
|
|
1457
1450
|
|
|
1458
|
-
|
|
1451
|
+
if ( this.enablePan === false ) return;
|
|
1459
1452
|
|
|
1460
|
-
|
|
1453
|
+
this._handleTouchMovePan( event );
|
|
1461
1454
|
|
|
1462
|
-
|
|
1455
|
+
this.update();
|
|
1463
1456
|
|
|
1464
|
-
|
|
1457
|
+
break;
|
|
1465
1458
|
|
|
1466
|
-
|
|
1459
|
+
case _STATE.TOUCH_DOLLY_PAN:
|
|
1467
1460
|
|
|
1468
|
-
|
|
1469
|
-
return;
|
|
1461
|
+
if ( this.enableZoom === false && this.enablePan === false ) return;
|
|
1470
1462
|
|
|
1471
|
-
|
|
1463
|
+
this._handleTouchMoveDollyPan( event );
|
|
1472
1464
|
|
|
1473
|
-
|
|
1465
|
+
this.update();
|
|
1474
1466
|
|
|
1475
|
-
|
|
1467
|
+
break;
|
|
1476
1468
|
|
|
1477
|
-
|
|
1469
|
+
case _STATE.TOUCH_DOLLY_ROTATE:
|
|
1478
1470
|
|
|
1479
|
-
|
|
1471
|
+
if ( this.enableZoom === false && this.enableRotate === false ) return;
|
|
1480
1472
|
|
|
1481
|
-
|
|
1473
|
+
this._handleTouchMoveDollyRotate( event );
|
|
1482
1474
|
|
|
1483
|
-
|
|
1475
|
+
this.update();
|
|
1484
1476
|
|
|
1485
|
-
|
|
1477
|
+
break;
|
|
1486
1478
|
|
|
1487
|
-
|
|
1479
|
+
default:
|
|
1488
1480
|
|
|
1489
|
-
|
|
1481
|
+
this.state = _STATE.NONE;
|
|
1490
1482
|
|
|
1491
|
-
|
|
1483
|
+
}
|
|
1492
1484
|
|
|
1493
|
-
|
|
1485
|
+
}
|
|
1494
1486
|
|
|
1495
|
-
|
|
1496
|
-
pointerPositions[ event.pointerId ] = position;
|
|
1487
|
+
function onContextMenu( event ) {
|
|
1497
1488
|
|
|
1498
|
-
|
|
1489
|
+
if ( this.enabled === false ) return;
|
|
1499
1490
|
|
|
1500
|
-
|
|
1491
|
+
event.preventDefault();
|
|
1501
1492
|
|
|
1502
|
-
|
|
1493
|
+
}
|
|
1503
1494
|
|
|
1504
|
-
|
|
1495
|
+
function interceptControlDown( event ) {
|
|
1505
1496
|
|
|
1506
|
-
|
|
1497
|
+
if ( event.key === 'Control' ) {
|
|
1507
1498
|
|
|
1508
|
-
|
|
1499
|
+
this._controlActive = true;
|
|
1509
1500
|
|
|
1510
|
-
|
|
1501
|
+
const document = this.domElement.getRootNode(); // offscreen canvas compatibility
|
|
1511
1502
|
|
|
1512
|
-
|
|
1503
|
+
document.addEventListener( 'keyup', this._interceptControlUp, { passive: true, capture: true } );
|
|
1513
1504
|
|
|
1514
|
-
|
|
1505
|
+
}
|
|
1506
|
+
|
|
1507
|
+
}
|
|
1515
1508
|
|
|
1516
|
-
|
|
1517
|
-
scope.domElement.addEventListener( 'pointercancel', onPointerUp );
|
|
1518
|
-
scope.domElement.addEventListener( 'wheel', onMouseWheel, { passive: false } );
|
|
1509
|
+
function interceptControlUp( event ) {
|
|
1519
1510
|
|
|
1520
|
-
|
|
1511
|
+
if ( event.key === 'Control' ) {
|
|
1521
1512
|
|
|
1522
|
-
|
|
1513
|
+
this._controlActive = false;
|
|
1523
1514
|
|
|
1524
|
-
|
|
1515
|
+
const document = this.domElement.getRootNode(); // offscreen canvas compatibility
|
|
1525
1516
|
|
|
1526
|
-
this.
|
|
1517
|
+
document.removeEventListener( 'keyup', this._interceptControlUp, { passive: true, capture: true } );
|
|
1527
1518
|
|
|
1528
1519
|
}
|
|
1529
1520
|
|