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