Adds vertex prediction

This commit is contained in:
Thomas Forgione 2019-12-12 12:05:09 +01:00
parent 46363f19c9
commit 5281616922
No known key found for this signature in database
GPG Key ID: BFD17A2D71B3B5E7
2 changed files with 36 additions and 0 deletions

View File

@ -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) {

View File

@ -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);