abouttreesummaryrefslogcommitdiff
path: root/Scripts/cloth.js
diff options
context:
space:
mode:
Diffstat (limited to 'Scripts/cloth.js')
-rw-r--r--Scripts/cloth.js44
1 files changed, 36 insertions, 8 deletions
diff --git a/Scripts/cloth.js b/Scripts/cloth.js
index 5a7a0f2..c77fb1c 100644
--- a/Scripts/cloth.js
+++ b/Scripts/cloth.js
@@ -3,8 +3,11 @@ const DRAG = 1 - DAMPING;
const MASS = 0.1;
const GRAVITY = new THREE.Vector3(0, -9.81 * MASS, 0);
const K = 1;
+const MAX_STRETCH = 1.5;
-// Flag Texture
+// Explosion am Anfang
+// Intersect mit Velocity?
+// Wind/Ziehen
const options = {
wind: true,
@@ -25,7 +28,10 @@ class Constraint {
//const correction = diff.multiplyScalar(1 - (this.restDist / currentDist));
const correction = diff.multiplyScalar((currentDist - this.restDist) / currentDist);
correction.multiplyScalar(K);
- correction.clampLength(0, 1);
+ if (currentDist >= this.restDist * MAX_STRETCH) {
+
+ }
+ //correction.clampLength(0, 1);
const correctionHalf = correction.multiplyScalar(0.5);
let p1movable = this.p1.movable && this.p1.movableTmp;
@@ -223,7 +229,7 @@ class Cloth {
constraint.satisfy();
}
- this.intersect();
+ //this.intersect();
}
intersect() {
@@ -239,20 +245,42 @@ class Cloth {
continue;
let dist = p1.position.distanceTo(p2.position);
- const collisionDistance = Math.min(this.width / this.numPointsWidth, this.height / this.numPointsHeight);
+ let collisionDistance = Math.min(this.width / this.numPointsWidth, this.height / this.numPointsHeight);
+ // collisionDistance /= 2;
if (dist < collisionDistance) {
// p1.movableTmp = false;
// p2.movableTmp = false;
- let diff = p1.position.clone().sub(p2.position).normalize();
- diff.multiplyScalar((collisionDistance - dist) * 1.001 / 2);
+ let diffP2P1 = p1.position.clone().sub(p2.position).normalize();
+ diffP2P1.multiplyScalar((collisionDistance - dist) * 1.001 / 2);
+ let diffP1P2 = diffP2P1.clone().multiplyScalar(-1);
+
+ // let v1 = p1.position.clone().sub(p1.previous).normalize();
+ // let v2 = p2.position.clone().sub(p2.previous).normalize();
+
+ // let factor1 = (Math.PI - Math.acos(v1.dot(diffP2P1))) / Math.PI * 2;
+ // let factor2 = (Math.PI - Math.acos(v2.dot(diffP1P2))) / Math.PI * 2;
+
if (p1.movable)
- p1.position.add(diff);
+ p1.position.add(diffP2P1);
+ //p1.position.add(diffP2P1.multiplyScalar(factor1));
if (p2.movable)
- p2.position.sub(diff);
+ p2.position.add(diffP1P2);
+ //p2.position.add(diffP1P2.multiplyScalar(factor2));
}
}
}
}
+ blow(camPos, intersects) {
+ let face = intersects[0].face;
+ let dir = intersects[0].point.clone().sub(camPos).multiplyScalar(100);
+ this.particles[face.a].addForce(dir);
+ this.particles[face.b].addForce(dir);
+ this.particles[face.c].addForce(dir);
+ }
+ drag(mousePosWorld, index) {
+ let dir = mousePosWorld.clone().sub(this.particles[index].position).multiplyScalar(200);
+ this.particles[index].addForce(dir);
+ }
/**
* helper function to calculate index of vertex