diff options
| author | Patrick Schönberger | 2021-01-22 16:57:38 +0100 |
|---|---|---|
| committer | Patrick Schönberger | 2021-01-22 16:57:38 +0100 |
| commit | 79bcaf1ac3d8bc90b697c444ff5dfb694acb6962 (patch) | |
| tree | afbf9e9b3bdfd802775eacf873b1d5a493f64292 | |
| parent | 590349d576668595128e2d15bbd72e9391a97fc1 (diff) | |
| download | cloth_sim-79bcaf1ac3d8bc90b697c444ff5dfb694acb6962.tar.gz cloth_sim-79bcaf1ac3d8bc90b697c444ff5dfb694acb6962.zip | |
fix spring force calculation
| -rw-r--r-- | Scripts/cloth.js | 7 | ||||
| -rw-r--r-- | Scripts/main.js | 20 |
2 files changed, 18 insertions, 9 deletions
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();
|
