Adds face edition and removal
This commit is contained in:
parent
635e5fef01
commit
0490db4bb6
|
@ -50,6 +50,20 @@ function parseLine(line) {
|
||||||
);
|
);
|
||||||
return element;
|
return element;
|
||||||
|
|
||||||
|
case "ef":
|
||||||
|
element.type = Element.EditFace;
|
||||||
|
element.id = parseInt(split[1], 10) - 1;
|
||||||
|
element.value = new THREE.Face3(
|
||||||
|
parseInt(split[2], 10) - 1,
|
||||||
|
parseInt(split[3], 10) - 1,
|
||||||
|
parseInt(split[4], 10) - 1,
|
||||||
|
);
|
||||||
|
|
||||||
|
case "df":
|
||||||
|
element.type = Element.DeleteFace;
|
||||||
|
element.id = parseInt(split[1], 10) - 1;
|
||||||
|
return element;
|
||||||
|
|
||||||
case "":
|
case "":
|
||||||
case "#":
|
case "#":
|
||||||
return;
|
return;
|
||||||
|
@ -64,6 +78,8 @@ const Element = {};
|
||||||
Element.AddVertex = "AddVertex";
|
Element.AddVertex = "AddVertex";
|
||||||
Element.AddFace = "AddFace";
|
Element.AddFace = "AddFace";
|
||||||
Element.EditVertex = "EditVertex";
|
Element.EditVertex = "EditVertex";
|
||||||
|
Element.EditFace = "EditFace";
|
||||||
|
Element.DeleteFace = "DeleteFace";
|
||||||
|
|
||||||
class Loader {
|
class Loader {
|
||||||
constructor(path, chunkSize = 1024, timeout = 20) {
|
constructor(path, chunkSize = 1024, timeout = 20) {
|
||||||
|
|
30
src/Model.js
30
src/Model.js
|
@ -1,8 +1,11 @@
|
||||||
class Model extends THREE.Mesh {
|
class Model extends THREE.Mesh {
|
||||||
constructor() {
|
constructor() {
|
||||||
let geometry = new THREE.Geometry();
|
let geometry = new THREE.Geometry();
|
||||||
let material = new THREE.MeshLambertMaterial({color: 0xffffff});
|
let materials = [
|
||||||
super(geometry, material);
|
new THREE.MeshLambertMaterial( { color: 0xffffff, side: THREE.DoubleSide } ),
|
||||||
|
new THREE.MeshBasicMaterial( { transparent: true, opacity: 0 } )
|
||||||
|
];
|
||||||
|
super(geometry, materials);
|
||||||
this.frustumCulled = false;
|
this.frustumCulled = false;
|
||||||
this.vertices = [];
|
this.vertices = [];
|
||||||
}
|
}
|
||||||
|
@ -17,7 +20,6 @@ class Model extends THREE.Mesh {
|
||||||
case Element.EditVertex:
|
case Element.EditVertex:
|
||||||
this.geometry.vertices[element.id].copy(element.value);
|
this.geometry.vertices[element.id].copy(element.value);
|
||||||
this.geometry.verticesNeedUpdate = true;
|
this.geometry.verticesNeedUpdate = true;
|
||||||
this.geometry.elementsNeedUpdate = true;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Element.AddFace:
|
case Element.AddFace:
|
||||||
|
@ -30,10 +32,32 @@ class Model extends THREE.Mesh {
|
||||||
normal.normalize();
|
normal.normalize();
|
||||||
|
|
||||||
f.normal = normal;
|
f.normal = normal;
|
||||||
|
f.materialIndex = 0;
|
||||||
this.geometry.faces.push(f);
|
this.geometry.faces.push(f);
|
||||||
this.geometry.elementsNeedUpdate = true;
|
this.geometry.elementsNeedUpdate = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Element.EditFace:
|
||||||
|
|
||||||
|
vertices = this.geometry.vertices;
|
||||||
|
f = element.value;
|
||||||
|
normal =
|
||||||
|
vertices[f.b].clone().sub(vertices[f.a])
|
||||||
|
.cross(vertices[f.c].clone().sub(vertices[f.a]));
|
||||||
|
normal.normalize();
|
||||||
|
|
||||||
|
f.normal = normal;
|
||||||
|
this.geometry.faces[element.id] = f;
|
||||||
|
this.geometry.elementsNeedUpdate = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Element.DeleteFace:
|
||||||
|
this.geometry.faces[element.id].materialIndex = 1;
|
||||||
|
this.geometry.elementsNeedUpdate = true;
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new Error("unknown element type: " + element.type);
|
throw new Error("unknown element type: " + element.type);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ animate();
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
|
|
||||||
loader = new Loader('assets/bunny_translate.obj');
|
loader = new Loader('assets/bunny_remove.obj');
|
||||||
loader.start(function(elements) {
|
loader.start(function(elements) {
|
||||||
for (let element of elements) {
|
for (let element of elements) {
|
||||||
if (element !== undefined) {
|
if (element !== undefined) {
|
||||||
|
|
Loading…
Reference in New Issue