diff --git a/src/Loader.js b/src/Loader.js index ec32534..3544e27 100644 --- a/src/Loader.js +++ b/src/Loader.js @@ -98,6 +98,15 @@ function parseLine(line) { ); return element; + case "pv": + element.type = Element.PredictVertex; + element.value = new THREE.Face3( + parseInt(split[2], 10) - 1, + parseInt(split[2], 10) - 1, + parseInt(split[2], 10) - 1, + ); + return element; + case "efv": element.type = Element.EditFaceVertex; element.id = parseInt(split[1], 10) - 1; @@ -140,6 +149,7 @@ Element.EditFace = "EditFace"; Element.EditFaceVertex = "EditFaceVertex"; Element.TranslateVertex = "TranslateVertex"; Element.DeleteFace = "DeleteFace"; +Element.PredictVertex = "PredictVertex"; class Loader { constructor(path, chunkSize = 1024, timeout = 20) { diff --git a/src/Model.js b/src/Model.js index 8555524..1dc2fc2 100644 --- a/src/Model.js +++ b/src/Model.js @@ -47,6 +47,25 @@ class Model extends THREE.Mesh { } + + checkVertexPrediction(f) { + let vertices = this.geometry.vertices; + + if (vertices[f.a] === undefined) { + this.throwError("Vertex prediction requires vertex " + (f.a + 1) + " but there is no such vertex"); + } + + if (vertices[f.b] === undefined) { + this.throwError("Vertex prediction requires vertex " + (f.b + 1) + " but there is no such vertex"); + } + + if (vertices[f.c] === undefined) { + this.throwError("Vertex prediction requires vertex " + (f.c + 1) + " but there is no such vertex"); + } + + } + + manageElement(element) { let vertices = this.geometry.vertices; @@ -142,6 +161,13 @@ class Model extends THREE.Mesh { this.geometry.elementsNeedUpdate = true; break; + case Element.PredictVertex: + this.checkVertexPrediction(element.value); + vertices.push(vertices[element.value.a].clone() + .add(vertices[element.value.c]) + .sub(vertices[element.value.b])); + this.geometry.verticesNeedUpdate = true; + break; default: throw new Error("unknown element type: " + element.type);