X-Git-Url: https://gitweb.ps.run/cloth_sim/blobdiff_plain/4079007a1ed290280e228b93432129c4a262dae9..14881afe547086f68764e27bd65c794b21271c63:/Scripts/main.js diff --git a/Scripts/main.js b/Scripts/main.js index a0387ac..8c61f82 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; @@ -57,31 +65,44 @@ document.body.onload = init; function init() { let mousePos = new Point(); - + let previousClothSimulation; + /** * Space left empty under canvas * for UI elements */ 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 mesh = new THREE.Mesh(cloth.geometry, material); + //const mesh = new THREE.WireframeGeometry(cloth.geometry); + //const line = new THREE.LineSegments(mesh); + //line.material.depthTest = false; + //line.material.opacity = 0.25; + //line.material.transparent = true; scene.add(mesh); /** * 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) { - requestAnimationFrame(animate); + cloth.simulate(dt/1000); + + setTimeout(() => { + animate(frameTime); + }, frameTime); renderer.render(scene, camera); }