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