convert all meshes to non-indexed
This commit is contained in:
parent
f1ea39f786
commit
6993a339e7
4 changed files with 60 additions and 74 deletions
|
|
@ -182,7 +182,11 @@ mesh.model = class MeshModel extends mesh.object {
|
|||
load(vertices, indices, normals) {
|
||||
let geo = new BufferGeometry();
|
||||
geo.setAttribute('position', new BufferAttribute(vertices, 3));
|
||||
if (indices) geo.setIndex(new BufferAttribute(indices, 1));
|
||||
if (indices) {
|
||||
// unroll indexed geometries
|
||||
geo.setIndex(new BufferAttribute(indices, 1));
|
||||
geo = geo.toNonIndexed();
|
||||
}
|
||||
if (!normals) geo.computeVertexNormals();
|
||||
let meh = this.mesh = new Mesh(geo, [
|
||||
this.mats.normal,
|
||||
|
|
@ -199,24 +203,23 @@ mesh.model = class MeshModel extends mesh.object {
|
|||
// persist in db so it can be restored on page load
|
||||
mapp.db.space.put(this.id, { file: this.file, mesh: vertices });
|
||||
// sync data to worker
|
||||
worker.model_load({id: this.id, name: this.file, vertices, indices});
|
||||
worker.model_load({id: this.id, name: this.file, vertices});
|
||||
}
|
||||
|
||||
reload(vertices, indices, normals) {
|
||||
reload(vertices) {
|
||||
let was = this.wireframe(false);
|
||||
let geo = this.mesh.geometry;
|
||||
geo.setAttribute('position', new BufferAttribute(vertices, 3));
|
||||
geo.setAttribute('normal', undefined);
|
||||
// signal util.box3expand that geometry changed
|
||||
geo._model_invalid = true;
|
||||
if (indices) geo.setIndex(new BufferAttribute(indices, 1));
|
||||
if (!normals) geo.computeVertexNormals();
|
||||
geo.computeVertexNormals();
|
||||
// allows raycasting to work
|
||||
geo.computeBoundingSphere();
|
||||
// persist in db so it can be restored on page load
|
||||
mapp.db.space.put(this.id, { file: this.file, mesh: vertices });
|
||||
// sync data to worker
|
||||
worker.model_load({id: this.id, name: this.name, vertices, indices});
|
||||
worker.model_load({id: this.id, name: this.name, vertices});
|
||||
// restore wireframe state
|
||||
this.wireframe(was);
|
||||
// fixup normals
|
||||
|
|
|
|||
Loading…
Reference in a new issue