Skip to content

Commit 0d9a468

Browse files
➕ Add static frictiont o orbit controls.
1 parent f7fe1af commit 0d9a468

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
"homepage": "https://github.com/pmndrs/three-stdlib",
2020
"repository": "https://github.com/pmndrs/three-stdlib",
2121
"license": "MIT",
22-
"types": "./index.d.ts",
23-
"main": "./index.cjs",
24-
"module": "./index.js",
22+
"types": "./dist/index.d.ts",
23+
"main": "./dist/index.cjs",
24+
"module": "./dist/index.js",
2525
"exports": {
26-
"types": "./index.d.ts",
27-
"require": "./index.cjs",
28-
"import": "./index.js"
26+
"types": "./dist/index.d.ts",
27+
"require": "./dist/index.cjs",
28+
"import": "./dist/index.js"
2929
},
3030
"sideEffects": false,
3131
"devDependencies": {

src/controls/OrbitControls.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ class OrbitControls extends EventDispatcher<StandardControlsEventMap> {
5252
// If damping is enabled, you must call controls.update() in your animation loop
5353
enableDamping = false
5454
dampingFactor = 0.05
55+
/**
56+
* The static friction force applied to the movement.
57+
* This is a constant force that opposes movement, independent of speed.
58+
*
59+
* @type {number}
60+
* @default 0
61+
*/
62+
staticMovingFriction = 0
5563
// This option actually enables dollying in and out; left as "zoom" for backwards compatibility.
5664
// Set to false to disable zooming
5765
enableZoom = true
@@ -307,6 +315,33 @@ class OrbitControls extends EventDispatcher<StandardControlsEventMap> {
307315
sphericalDelta.phi *= 1 - scope.dampingFactor
308316

309317
panOffset.multiplyScalar(1 - scope.dampingFactor)
318+
319+
if (scope.staticMovingFriction > 0) {
320+
const thetaSign = Math.sign(sphericalDelta.theta)
321+
if (thetaSign !== 0) {
322+
sphericalDelta.theta -= thetaSign * scope.staticMovingFriction
323+
if (Math.sign(sphericalDelta.theta) !== thetaSign) {
324+
sphericalDelta.theta = 0
325+
}
326+
}
327+
328+
const phiSign = Math.sign(sphericalDelta.phi)
329+
if (phiSign !== 0) {
330+
sphericalDelta.phi -= phiSign * scope.staticMovingFriction
331+
if (Math.sign(sphericalDelta.phi) !== phiSign) {
332+
sphericalDelta.phi = 0
333+
}
334+
}
335+
336+
const panLen = panOffset.length()
337+
if (panLen > 0) {
338+
if (panLen > scope.staticMovingFriction) {
339+
panOffset.multiplyScalar((panLen - scope.staticMovingFriction) / panLen)
340+
} else {
341+
panOffset.set(0, 0, 0)
342+
}
343+
}
344+
}
310345
} else {
311346
sphericalDelta.set(0, 0, 0)
312347

0 commit comments

Comments
 (0)