- /**\r
- * Generate THREE JS Geometry\r
- * (list of vertices and list of indices representing triangles)\r
- * and calculate the weight of each face and split it between\r
- * surrounding vertices\r
- * @param {Array<Vector3>} vertices \r
- * @param {Array<Face>} faces \r
- */\r
- createExplicit(vertices, faces) {\r
-\r
- /**\r
- * Copy vertices and initialize vertex weights to 0\r
- */\r
- for (let i in vertices) {\r
- this.geometry.vertices.push(vertices[i].clone());\r
- this.previousPositions.push(vertices[i].clone());\r
- // this.geometry.vertices.push(vertices[i]);\r
- // this.previousPositions.push(vertices[i]);\r
- this.vertexWeights.push(0);\r
- this.vertexRigidness.push(false);\r
- this.externalForces.push(new THREE.Vector3(0,0,0));\r
- }\r
- /**\r
- * copy faces,\r
- * generate two triangles per face,\r
- * calculate weight of face as its area\r
- * and split between the 4 vertices\r
- */\r
- for (let i in faces) {\r
- let face = faces[i];\r
-\r
- /** copy faces to class member */\r
- this.faces.push(face);\r
-\r
- /** generate triangles */\r
- this.geometry.faces.push(new THREE.Face3(\r
- face.a, face.b, face.c\r
- ));\r
- this.geometry.faces.push(new THREE.Face3(\r
- face.c, face.b, face.d\r
- ));\r
-\r
- /**\r
- * calculate area of face as combined area of\r
- * its two composing triangles\r
- */\r
- let xLength = vectorLength(this.geometry.vertices[face.b], this.geometry.vertices[face.a]);\r
- let yLength = vectorLength(this.geometry.vertices[face.c], this.geometry.vertices[face.a]);\r
- let weight = xLength * yLength / 2;\r
-\r
- xLength = vectorLength(this.geometry.vertices[face.b], this.geometry.vertices[face.d]);\r
- yLength = vectorLength(this.geometry.vertices[face.c], this.geometry.vertices[face.d]);\r
- weight += xLength * yLength / 2;\r
-\r
- /**\r
- * split weight equally between four surrounding vertices\r
- */\r
- this.vertexWeights[face.a] += weight / 4;\r
- this.vertexWeights[face.b] += weight / 4;\r
- this.vertexWeights[face.c] += weight / 4;\r
- this.vertexWeights[face.d] += weight / 4;\r
- }\r
-\r
- /**\r
- * let THREE JS compute bounding sphere around generated mesh\r
- * needed for View Frustum Culling internally\r
- */\r
- this.geometry.computeBoundingSphere();\r
- this.geometry.computeFaceNormals();\r
- this.geometry.computeVertexNormals();\r
- }\r