X-Git-Url: https://gitweb.ps.run/cloth_sim/blobdiff_plain/e05a5c0a7aa891179af219eff0df34647acc8eb3..60b7eb713036545e4046a16cfd3d312b8837938c:/Scripts/main.js diff --git a/Scripts/main.js b/Scripts/main.js index 5ed1866..4e7c2ef 100644 --- a/Scripts/main.js +++ b/Scripts/main.js @@ -1,6 +1,14 @@ import { Face, Spring, Cloth } from './cloth.js'; +/** + * rendering + * Einheiten konsistent + * Wind + * evtl. an Stoff ziehen + */ + + class Point { constructor(x, y) { this.x = x; @@ -65,15 +73,19 @@ function init() { */ const canvasSpace = 200; + /** Constant Frame Time */ + const frameTime = 1000.0 / 60.0; + /** Setup scene */ let [scene, camera, renderer] = setup_scene(canvasSpace); /** setup cloth and generate debug mesh */ let cloth = new Cloth(); - cloth.createBasic(10, 10, 5, 5); - cloth.createDebugMesh(scene); + cloth.createBasic(10, 10, 10, 10); + //cloth.createDebugMesh(scene); - const material = new THREE.MeshBasicMaterial({ color: 0x0000ff }); + //const material = new THREE.MeshBasicMaterial({ color: 0x0000ff, side: THREE.DoubleSide }); + const material = new THREE.MeshPhongMaterial({ color: 0x0000ff, side: THREE.DoubleSide }); const mesh = new THREE.Mesh(cloth.geometry, material); //const mesh = new THREE.WireframeGeometry(cloth.geometry); //const line = new THREE.LineSegments(mesh); @@ -82,17 +94,22 @@ 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 ); + /** * function called every frame - * @param {number} dt - time passed since last frame + * @param {number} dt - time passed since last frame in ms */ function animate(dt) { - - cloth.simulate(dt); + cloth.simulate(dt/1000); setTimeout(() => { - animate(2000); - }, 2000); + animate(frameTime); + }, frameTime); renderer.render(scene, camera); }