diff --git a/package.json b/package.json index 90fb4c29..f7f90055 100644 --- a/package.json +++ b/package.json @@ -19,13 +19,13 @@ "homepage": "https://github.com/pmndrs/three-stdlib", "repository": "https://github.com/pmndrs/three-stdlib", "license": "MIT", - "types": "./index.d.ts", - "main": "./index.cjs", - "module": "./index.js", + "types": "./dist/index.d.ts", + "main": "./dist/index.cjs", + "module": "./dist/index.js", "exports": { - "types": "./index.d.ts", - "require": "./index.cjs", - "import": "./index.js" + "types": "./dist/index.d.ts", + "require": "./dist/index.cjs", + "import": "./dist/index.js" }, "sideEffects": false, "devDependencies": { diff --git a/src/controls/OrbitControls.ts b/src/controls/OrbitControls.ts index cad6a154..a5169ddd 100644 --- a/src/controls/OrbitControls.ts +++ b/src/controls/OrbitControls.ts @@ -52,6 +52,14 @@ class OrbitControls extends EventDispatcher { // If damping is enabled, you must call controls.update() in your animation loop enableDamping = false dampingFactor = 0.05 + /** + * The static friction force applied to the movement. + * This is a constant force that opposes movement, independent of speed. + * + * @type {number} + * @default 0 + */ + staticMovingFriction = 0 // This option actually enables dollying in and out; left as "zoom" for backwards compatibility. // Set to false to disable zooming enableZoom = true @@ -307,6 +315,33 @@ class OrbitControls extends EventDispatcher { sphericalDelta.phi *= 1 - scope.dampingFactor panOffset.multiplyScalar(1 - scope.dampingFactor) + + if (scope.staticMovingFriction > 0) { + const thetaSign = Math.sign(sphericalDelta.theta) + if (thetaSign !== 0) { + sphericalDelta.theta -= thetaSign * scope.staticMovingFriction + if (Math.sign(sphericalDelta.theta) !== thetaSign) { + sphericalDelta.theta = 0 + } + } + + const phiSign = Math.sign(sphericalDelta.phi) + if (phiSign !== 0) { + sphericalDelta.phi -= phiSign * scope.staticMovingFriction + if (Math.sign(sphericalDelta.phi) !== phiSign) { + sphericalDelta.phi = 0 + } + } + + const panLen = panOffset.length() + if (panLen > 0) { + if (panLen > scope.staticMovingFriction) { + panOffset.multiplyScalar((panLen - scope.staticMovingFriction) / panLen) + } else { + panOffset.set(0, 0, 0) + } + } + } } else { sphericalDelta.set(0, 0, 0)