Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
35 changes: 35 additions & 0 deletions src/controls/OrbitControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ class OrbitControls extends EventDispatcher<StandardControlsEventMap> {
// 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
Expand Down Expand Up @@ -307,6 +315,33 @@ class OrbitControls extends EventDispatcher<StandardControlsEventMap> {
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)

Expand Down