]> gitweb.ps.run Git - cloth_sim/commitdiff
fix spring force calculation
authorPatrick Schönberger <patrick.schoenberger@posteo.de>
Fri, 22 Jan 2021 15:57:38 +0000 (16:57 +0100)
committerPatrick Schönberger <patrick.schoenberger@posteo.de>
Fri, 22 Jan 2021 15:57:38 +0000 (16:57 +0100)
Scripts/cloth.js
Scripts/main.js

index 266af16a3f1236417b7efd8c0c8805508d508bca..e39b95b9850400cf98cbd7c20f5f3aa1b5d73fbb 100644 (file)
@@ -112,6 +112,9 @@ export class Cloth {
     let vertices = [];\r
     let faces = [];\r
 \r
+    this.numPointsWidth = numPointsWidth;\r
+    this.numPointsHeight = numPointsHeight;\r
+\r
     /**\r
      * distance between two vertices horizontally/vertically\r
      * divide by the number of points minus one\r
@@ -403,8 +406,8 @@ getAcceleration(vertexIndex, dt) {
   // Get the bounding springs and add them to the needed springs\r
   // TODO: optimize\r
 \r
-  const numPointsX = 10;\r
-  const numPointsY = 10;\r
+  const numPointsX = this.numPointsWidth;\r
+  const numPointsY = this.numPointsHeight;\r
   const numFacesX = numPointsX - 1;\r
   const numFacesY = numPointsY - 1;\r
 \r
index 20a6e923be73f7f3c03f1a0d6a03d9d6237e6a91..4c57ff972420a68b22f0e7b0d1f3be70a8621939 100644 (file)
@@ -52,11 +52,11 @@ function init() {
   \r
   /** setup cloth and generate debug mesh */\r
   let cloth = new Cloth();\r
-  cloth.createBasic(10, 10, 10, 10);\r
+  cloth.createBasic(10, 10, 50, 50);\r
   //cloth.createDebugMesh(scene);\r
 \r
   //const material = new THREE.MeshBasicMaterial({ color: 0x0000ff, side: THREE.DoubleSide });\r
-  const material = new THREE.MeshPhongMaterial({ color: 0x0000ff, side: THREE.DoubleSide });\r
+  const material = new THREE.MeshStandardMaterial({ color: 0x0000ff, side: THREE.DoubleSide, flatShading: false });\r
   const mesh = new THREE.Mesh(cloth.geometry, material);\r
   //const mesh = new THREE.WireframeGeometry(cloth.geometry);\r
   //const line = new THREE.LineSegments(mesh);\r
@@ -65,11 +65,17 @@ function init() {
   //line.material.transparent = true;\r
   scene.add(mesh);\r
 \r
-  scene.add( new THREE.AmbientLight( 0x666666 ) );\r
-\r
-  const light = new THREE.DirectionalLight( 0xffffff, 0.5 );\r
-  light.position.set( 0, 1, 0.5 );\r
-  scene.add( light );\r
+  scene.add( new THREE.AmbientLight( 0x222222 ) );\r
+\r
+  const light1 = new THREE.PointLight( 0xffffff, 1, 100 );\r
+  light1.position.set( 2, 1, 80 );\r
+  scene.add( light1 );\r
+  const light2 = new THREE.PointLight( 0xffffff, 1, 100 );\r
+  light2.position.set( -2, 1, 80 );\r
+  scene.add( light2 );\r
+  const light3 = new THREE.PointLight( 0xffffff, 1, 100 );\r
+  light3.position.set( 0, -1, 80 );\r
+  scene.add( light3 );\r
   \r
   let raycaster = new THREE.Raycaster();\r
 \r