-function init() {\r
- class Point {\r
- constructor(x, y) {\r
- this.x = x;\r
- this.y = y;\r
- }\r
-\r
- add(that) {\r
- return new Point(\r
- this.x + that.x,\r
- this.y + that.y\r
- );\r
- }\r
-\r
- sub(that) {\r
- return new Point(\r
- this.x - that.x,\r
- this.y - that.y\r
- );\r
- }\r
-\r
- dist(that) {\r
- let a = this.x - that.x;\r
- let b = this.y - that.y;\r
- return Math.sqrt(a * a + b * b)\r
- }\r
- }\r
-\r
- class Cloth {\r
- geometry = new THREE.Geometry();\r
-\r
- \r
-\r
- static CreateBasic(width, height, numPointsWidth, numPointsHeight) {\r
- let vertices = [];\r
- let faces = [];\r
-\r
- let stepWidth = width / (numPointsWidth - 1);\r
- let stepHeight = height / (numPointsHeight - 1);\r
-\r
- for (let y = 0; y < numPointsHeight; y++) {\r
- for (let x = 0; x < numPointsWidth; x++) {\r
- vertices.push(\r
- new THREE.Vector3(x * stepWidth, height - y * stepHeight, 0)\r
- );\r
- }\r
- }\r
-\r
- function getVertexIndex(x, y) {\r
- return y * numPointsWidth + x;\r
- }\r
- \r
- for (let y = 0; y < numPointsHeight - 1; y++) {\r
- for (let x = 0; x < numPointsWidth - 1; x++) {\r
- faces.push(\r
- new THREE.Face3(\r
- getVertexIndex(x, y),\r
- getVertexIndex(x, y + 1),\r
- getVertexIndex(x + 1, y),\r
- )\r
- );\r
- faces.push(\r
- new THREE.Face3(\r
- getVertexIndex(x + 1, y),\r
- getVertexIndex(x, y + 1),\r
- getVertexIndex(x + 1, y + 1),\r
- )\r
- );\r
- }\r
- }\r
-\r
- return this.CreateExplicit(vertices, faces);\r
- }\r
-\r
- static CreateExplicit(vertices, faces) {\r
- let result = new Cloth();\r
-\r
- for (let i in vertices) {\r
- result.geometry.vertices.push(vertices[i]);\r
- }\r
- for (let i in faces) {\r
- result.geometry.faces.push(faces[i]);\r
- }\r
-\r
- result.geometry.computeBoundingSphere();\r
-\r
- return result;\r
- }\r
- }\r
-\r
- let mousePos = new Point();\r
-\r
- const canvasSpace = 200;\r
-\r
+import { Face, Spring, Cloth } from './cloth.js';\r
+\r
+function addLights(scene){\r
+ \r
+ scene.add( new THREE.AmbientLight( 0x222222 ) );\r
+\r
+ const light1 = new THREE.PointLight( 0xffffff, 1, 50 );\r
+ light1.position.set( 15, 1, 40 );\r
+ scene.add( light1 );\r
+\r
+ const light2 = new THREE.PointLight( 0xffffff, 1, 50 );\r
+ light2.position.set( -15, 0, 40 );\r
+ scene.add( light2 );\r
+\r
+ const light3 = new THREE.PointLight( 0xffffff, 1, 50 );\r
+ light3.position.set( 0, -1, 40 );\r
+ scene.add( light3 );\r
+ \r
+}\r
+\r
+/**\r
+ * setup THREE JS Scene, Camera and Renderer\r
+ */\r
+function setup_scene(canvasSpace) {\r