-\r
- /**\r
- * let THREE JS compute bounding sphere around generated mesh\r
- * needed for View Frustum Culling internally\r
- */\r
-\r
- this.geometry.verticesNeedUpdate = true;\r
- this.geometry.elementsNeedUpdate = true;\r
- this.geometry.computeBoundingSphere();\r
- this.geometry.computeFaceNormals();\r
-\r
- }\r
-\r
-\r
-\r
-/**\r
- * Equation of motion for each vertex which represents the acceleration \r
- * @param {number} vertexIndex The index of the current vertex whose acceleration should be calculated\r
- * @param {number} dt The time passed since last frame\r
- */\r
-getAcceleration(vertexIndex, dt) {\r
- if (this.vertexRigidness[vertexIndex])\r
- return new THREE.Vector3(0, 0, 0);\r
-\r
- let vertex = this.geometry.vertices[vertexIndex];\r
-\r
- // Mass of vertex\r
- let M = this.vertexWeights[vertexIndex];\r
- // constant gravity\r
- let g = new THREE.Vector3(0, -9.8, 0);\r
- // stiffness\r
- let k = 500;\r
-\r
- // Wind vector\r
- let fWind = new THREE.Vector3(\r
- Math.sin(vertex.x * vertex.y * this.time),\r
- Math.cos(vertex.z * this.time),\r
- Math.sin(Math.cos(5 * vertex.x * vertex.y * vertex.z))\r
- );\r
- fWind.set(0, 0, 0);\r
-\r
- /**\r
- * constant determined by the properties of the surrounding fluids (air)\r
- * achievement of cloth effects through try out\r
- * */\r
- let a = 0.01;\r
- \r
- let velocity = new THREE.Vector3(\r
- (this.previousPositions[vertexIndex].x - vertex.x) / dt,\r
- (this.previousPositions[vertexIndex].y - vertex.y) / dt,\r
- (this.previousPositions[vertexIndex].z - vertex.z) / dt\r
- );\r
-\r
- //console.log(velocity, vertex, this.previousPositions[vertexIndex]);\r
-\r
- let fAirResistance = velocity.multiply(velocity).multiplyScalar(-a);\r
- \r
- let springSum = new THREE.Vector3(0, 0, 0);\r
-\r
- // Get the bounding springs and add them to the needed springs\r
- // TODO: optimize\r
-\r
- const numPointsX = 10;\r
- const numPointsY = 10;\r
- const numFacesX = numPointsX - 1;\r
- const numFacesY = numPointsY - 1;\r
-\r
- function getFaceIndex(x, y) {\r
- return y * numFacesX + x;\r