]> gitweb.ps.run Git - cloth_sim/blobdiff - Scripts/main.js
uv mapping, add texture to flag
[cloth_sim] / Scripts / main.js
index 4d873377ca96cc4f6c5609b54bb723330d2553ff..5e68a4f322020e8baea4bbd6ffdc44b94235f024 100644 (file)
@@ -1,5 +1,4 @@
-//import {  } from './cloth.js';\r
-//import { OrbitControls } from './OrbitControls.js';\r
+\r
 \r
 function addLights(scene){\r
   scene.add( new THREE.AmbientLight( 0x222222 ) );\r
@@ -75,13 +74,26 @@ function init() {
   const canvasSpace = 200;\r
 \r
   /** Constant Frame Time */\r
-  const frameTime = 1000.0 / 60.0;\r
+  const frameTime = 1000.0 / 200.0;\r
 \r
   /** Setup scene */\r
   let [scene, camera, renderer] = setup_scene(canvasSpace);\r
-\r
-  // Add Cloth Initialization\r
   \r
+  const loader = new THREE.TextureLoader();\r
+  //Red color: 0xC70039\r
+\r
+  const cloth = new Cloth(1, 0.5, 20, 20);\r
+  const clothGeometry = cloth.generateGeometry();\r
+  const clothMaterial = new THREE.MeshStandardMaterial({ map: loader.load('Textures/hsrm.jpg'), color: 0xffffff, side: THREE.DoubleSide, flatShading: false});\r
+  //const clothMaterial = new THREE.MeshStandardMaterial({ color: 0xC70039, side: THREE.DoubleSide, flatShading: false });\r
+  const clothMesh = new THREE.Mesh(clothGeometry, clothMaterial);\r
+  scene.add(clothMesh);\r
+  \r
+  document.getElementById("windToggle").checked = options.wind;\r
+  document.getElementById("windToggle").onchange = (e) => {\r
+    options.wind = e.target.checked;\r
+  };\r
+\r
   let raycaster = new THREE.Raycaster();\r
   let intersects;\r
   let rightMousePressed;\r
@@ -90,7 +102,9 @@ function init() {
    * @param {number} dt - time passed since last frame in ms\r
    */\r
   function animate(dt) {\r
-    // simulate cloth\r
+    cloth.simulate(dt / 1000);\r
+\r
+    cloth.updateGeometry(clothGeometry);\r
     \r
     raycaster.setFromCamera( new THREE.Vector2((mousePos.x / w) * 2 - 1, ((h - mousePos.y) / h) * 2 - 1), camera );\r
 \r