This commit is contained in:
2021-01-21 08:35:09 +01:00
parent d9a198079b
commit b03e8f55db
5 changed files with 1044 additions and 4 deletions

View File

@@ -27,7 +27,7 @@ function fetchData(path, start, end, callback) {
xhr.send();
}
function parseLine(line) {
function parseLine(line, number) {
let element = {};
let split = line.split(/[ \t]+/);
@@ -54,6 +54,16 @@ function parseLine(line) {
);
return element;
case "fc":
element.type = Element.SetFaceColor;
element.id = parseInt(split[1], 10) - 1;
element.value = new THREE.Color(
parseFloat(split[2]),
parseFloat(split[3]),
parseFloat(split[4]),
);
return element;
case "ts":
element.type = Element.AddTriangleStrip;
element.value = [];
@@ -134,7 +144,8 @@ function parseLine(line) {
return;
default:
throw new Error(split[0] + " is not a defined macro");
return;
// throw new Error(split[0] + " is not a defined macro in line " + number);
}
}
@@ -149,6 +160,7 @@ Element.EditFace = "EditFace";
Element.EditFaceVertex = "EditFaceVertex";
Element.TranslateVertex = "TranslateVertex";
Element.DeleteFace = "DeleteFace";
Element.SetFaceColor = "SetFaceColor";
Element.PredictVertex = "PredictVertex";
class Loader {
@@ -197,8 +209,8 @@ class Loader {
split[0] = this.remainder + split[0];
this.remainder = split.pop();
for (let line of split) {
elements.push(parseLine(line));
for (let i = 0; i < split.length; i++) {
elements.push(parseLine(split[i], i));
}
callback(elements);

View File

@@ -5,6 +5,7 @@ class Model extends THREE.Mesh {
new THREE.MeshLambertMaterial( { color: 0xffffff, side: THREE.DoubleSide } ),
new THREE.MeshBasicMaterial( { transparent: true, opacity: 0 } )
];
materials[0].vertexColors = true;
super(geometry, materials);
this.frustumCulled = false;
this.path = path;
@@ -161,6 +162,13 @@ class Model extends THREE.Mesh {
this.geometry.elementsNeedUpdate = true;
break;
case Element.SetFaceColor:
this.geometry.faces[element.id].color.r = element.value.r;
this.geometry.faces[element.id].color.g = element.value.g;
this.geometry.faces[element.id].color.b = element.value.b;
this.geometry.colorsNeedUpdate = true;
break;
case Element.PredictVertex:
this.checkVertexPrediction(element.value);
vertices.push(vertices[element.value.a].clone()