-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