X-Git-Url: https://gitweb.ps.run/cloth_sim/blobdiff_plain/60b7eb713036545e4046a16cfd3d312b8837938c..590349d576668595128e2d15bbd72e9391a97fc1:/Scripts/cloth.js diff --git a/Scripts/cloth.js b/Scripts/cloth.js index 038b235..266af16 100644 --- a/Scripts/cloth.js +++ b/Scripts/cloth.js @@ -373,7 +373,7 @@ getAcceleration(vertexIndex, dt) { // constant gravity let g = new THREE.Vector3(0, -9.8, 0); // stiffness - let k = 500; + let k = 1000; // Wind vector let fWind = new THREE.Vector3( @@ -381,13 +381,12 @@ getAcceleration(vertexIndex, dt) { Math.cos(vertex.z * this.time), Math.sin(Math.cos(5 * vertex.x * vertex.y * vertex.z)) ); - fWind.set(0, 0, 0); /** * constant determined by the properties of the surrounding fluids (air) * achievement of cloth effects through try out * */ - let a = 0.01; + let a = 0.1; let velocity = new THREE.Vector3( (this.previousPositions[vertexIndex].x - vertex.x) / dt, @@ -490,13 +489,19 @@ verlet(currentPosition, previousPosition, acceleration, passedTime) { // next position = 2 * current Position - previous position + acceleration * (passed time)^2 // acceleration (dv/dt) = F(net) // Dependency for one vertex: gravity, fluids/air, springs - + const DRAG = 0.97; let nextPosition = new THREE.Vector3( - (2 * currentPosition.x) - previousPosition.x + acceleration.x * (passedTime * passedTime), - (2 * currentPosition.y) - previousPosition.y + acceleration.y * (passedTime * passedTime), - (2 * currentPosition.z) - previousPosition.z + acceleration.z * (passedTime * passedTime), + (currentPosition.x - previousPosition.x) * DRAG + currentPosition.x + acceleration.x * (passedTime * passedTime), + (currentPosition.y - previousPosition.y) * DRAG + currentPosition.y + acceleration.y * (passedTime * passedTime), + (currentPosition.z - previousPosition.z) * DRAG + currentPosition.z + acceleration.z * (passedTime * passedTime), ); + // let nextPosition = new THREE.Vector3( + // (2 * currentPosition.x) - previousPosition.x + acceleration.x * (passedTime * passedTime), + // (2 * currentPosition.y) - previousPosition.y + acceleration.y * (passedTime * passedTime), + // (2 * currentPosition.z) - previousPosition.z + acceleration.z * (passedTime * passedTime), + // ); + return nextPosition; } @@ -510,5 +515,12 @@ euler(currentPosition, acceleration, passedTime) { return nextPosition; } +wind(intersects) { + let intersect = intersects[0]; + this.geometry.vertices[intersect.face.a].z -= 0.05; + this.geometry.vertices[intersect.face.b].z -= 0.05; + this.geometry.vertices[intersect.face.c].z -= 0.05; +} + }