Skip to content

Commit b2e7c0c

Browse files
committed
feat: reduce sphere radius to 1.3 and add stable surface friction to prevent sliding off
1 parent 527ff9a commit b2e7c0c

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

‎src/cloth.js‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export class ClothParticle {
1515
this.mass = mass;
1616
this.pinned = false;
1717
this.pinPosition = { x, y, z };
18+
this.onSphere = false;
1819
}
1920

2021
addForce(fx, fy, fz) {
@@ -32,9 +33,11 @@ export class ClothParticle {
3233
return;
3334
}
3435

35-
const vx = (this.x - this.oldX) * damping;
36-
const vy = (this.y - this.oldY) * damping;
37-
const vz = (this.z - this.oldZ) * damping;
36+
const effectiveDamping = this.onSphere ? damping * 0.7 : damping;
37+
38+
const vx = (this.x - this.oldX) * effectiveDamping;
39+
const vy = (this.y - this.oldY) * effectiveDamping;
40+
const vz = (this.z - this.oldZ) * effectiveDamping;
3841

3942
this.oldX = this.x;
4043
this.oldY = this.y;
@@ -120,7 +123,7 @@ export class ClothSimulator {
120123
this.mouseWind = { x: 0, y: 0, z: 0 };
121124

122125
this.sphereEnabled = true;
123-
this.sphereRadius = 1.8;
126+
this.sphereRadius = 1.3;
124127
this.spherePos = { x: 0, y: -1.2, z: 1.2 };
125128

126129
this.floorEnabled = true;
@@ -285,6 +288,7 @@ export class ClothSimulator {
285288
particle.x = currentSpherePos.x + nx * effectiveRadius;
286289
particle.y = currentSpherePos.y + ny * effectiveRadius;
287290
particle.z = currentSpherePos.z + nz * effectiveRadius;
291+
particle.onSphere = true;
288292
}
289293
}
290294

@@ -304,6 +308,10 @@ export class ClothSimulator {
304308
}
305309

306310
step(dt, timeSec = 0) {
311+
for (let p of this.particles) {
312+
p.onSphere = false;
313+
}
314+
307315
const rad = (this.windAngle * Math.PI) / 180;
308316
const windDirX = Math.cos(rad);
309317
const windDirZ = Math.sin(rad);

‎src/main.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ function updatePinVisuals() {
209209
}
210210
updatePinVisuals();
211211

212-
const sphereGeo = new THREE.SphereGeometry(1.8, 32, 32);
212+
const sphereGeo = new THREE.SphereGeometry(1.3, 32, 32);
213213
const sphereMat = new THREE.MeshStandardMaterial({
214214
color: 0xe11d48,
215215
roughness: 0.2,
@@ -221,7 +221,7 @@ sphereMesh.castShadow = true;
221221
sphereMesh.receiveShadow = true;
222222
scene.add(sphereMesh);
223223

224-
clothSim.sphereRadius = 1.8;
224+
clothSim.sphereRadius = 1.3;
225225
clothSim.spherePos.x = sphereMesh.position.x;
226226
clothSim.spherePos.y = sphereMesh.position.y;
227227
clothSim.spherePos.z = sphereMesh.position.z;

0 commit comments

Comments
 (0)