From: Patrick Schönberger Date: Fri, 22 Jan 2021 15:57:38 +0000 (+0100) Subject: fix spring force calculation X-Git-Url: https://gitweb.ps.run/cloth_sim/commitdiff_plain/79bcaf1ac3d8bc90b697c444ff5dfb694acb6962 fix spring force calculation --- diff --git a/Scripts/cloth.js b/Scripts/cloth.js index 266af16..e39b95b 100644 --- a/Scripts/cloth.js +++ b/Scripts/cloth.js @@ -112,6 +112,9 @@ export class Cloth { let vertices = []; let faces = []; + this.numPointsWidth = numPointsWidth; + this.numPointsHeight = numPointsHeight; + /** * distance between two vertices horizontally/vertically * divide by the number of points minus one @@ -403,8 +406,8 @@ getAcceleration(vertexIndex, dt) { // Get the bounding springs and add them to the needed springs // TODO: optimize - const numPointsX = 10; - const numPointsY = 10; + const numPointsX = this.numPointsWidth; + const numPointsY = this.numPointsHeight; const numFacesX = numPointsX - 1; const numFacesY = numPointsY - 1; diff --git a/Scripts/main.js b/Scripts/main.js index 20a6e92..4c57ff9 100644 --- a/Scripts/main.js +++ b/Scripts/main.js @@ -52,11 +52,11 @@ function init() { /** setup cloth and generate debug mesh */ let cloth = new Cloth(); - cloth.createBasic(10, 10, 10, 10); + cloth.createBasic(10, 10, 50, 50); //cloth.createDebugMesh(scene); //const material = new THREE.MeshBasicMaterial({ color: 0x0000ff, side: THREE.DoubleSide }); - const material = new THREE.MeshPhongMaterial({ color: 0x0000ff, side: THREE.DoubleSide }); + const material = new THREE.MeshStandardMaterial({ color: 0x0000ff, side: THREE.DoubleSide, flatShading: false }); const mesh = new THREE.Mesh(cloth.geometry, material); //const mesh = new THREE.WireframeGeometry(cloth.geometry); //const line = new THREE.LineSegments(mesh); @@ -65,11 +65,17 @@ function init() { //line.material.transparent = true; scene.add(mesh); - scene.add( new THREE.AmbientLight( 0x666666 ) ); - - const light = new THREE.DirectionalLight( 0xffffff, 0.5 ); - light.position.set( 0, 1, 0.5 ); - scene.add( light ); + scene.add( new THREE.AmbientLight( 0x222222 ) ); + + const light1 = new THREE.PointLight( 0xffffff, 1, 100 ); + light1.position.set( 2, 1, 80 ); + scene.add( light1 ); + const light2 = new THREE.PointLight( 0xffffff, 1, 100 ); + light2.position.set( -2, 1, 80 ); + scene.add( light2 ); + const light3 = new THREE.PointLight( 0xffffff, 1, 100 ); + light3.position.set( 0, -1, 80 ); + scene.add( light3 ); let raycaster = new THREE.Raycaster();