X-Git-Url: https://gitweb.ps.run/cloth_sim/blobdiff_plain/4079007a1ed290280e228b93432129c4a262dae9..a30256db1a628e1fd7f9a1537bebb9bdea8f3719:/Scripts/main.js?ds=inline diff --git a/Scripts/main.js b/Scripts/main.js index a0387ac..ececd6a 100644 --- a/Scripts/main.js +++ b/Scripts/main.js @@ -57,23 +57,32 @@ 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); /** @@ -81,7 +90,11 @@ function init() { * @param {number} dt - time passed since last frame */ function animate(dt) { - requestAnimationFrame(animate); + cloth.simulate(dt); + + setTimeout(() => { + animate(frameTime); + }, frameTime); renderer.render(scene, camera); }