add option to load normals with model
This commit is contained in:
parent
4916a055eb
commit
098fd9bb7e
4 changed files with 11 additions and 18 deletions
|
|
@ -49,7 +49,7 @@ let materials = mesh.material = {
|
|||
mesh.model = class MeshModel extends mesh.object {
|
||||
constructor(data, id) {
|
||||
super(id);
|
||||
let { file, mesh, index, vertices, indices } = data;
|
||||
let { file, mesh, vertices, indices, normals } = data;
|
||||
|
||||
if (!mesh) {
|
||||
dbug.error(`'${file}' missing mesh data`);
|
||||
|
|
@ -62,7 +62,7 @@ mesh.model = class MeshModel extends mesh.object {
|
|||
if (dot > 0) file = text.substring(0, dot);
|
||||
|
||||
this.file = file || 'unnamed';
|
||||
this.load(mesh || vertices, index || indices);
|
||||
this.load(mesh || vertices, indices, normals);
|
||||
|
||||
// persist in db so it can be restored on page load
|
||||
mapp.db.space.put(this.id, { file, mesh });
|
||||
|
|
@ -89,11 +89,11 @@ mesh.model = class MeshModel extends mesh.object {
|
|||
});
|
||||
}
|
||||
|
||||
load(vertices, indices) {
|
||||
load(vertices, indices, normals) {
|
||||
let geo = new THREE.BufferGeometry();
|
||||
geo.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
|
||||
if (indices) geo.setIndex(new THREE.BufferAttribute(indices, 1));
|
||||
geo.computeVertexNormals();
|
||||
if (!normals) geo.computeVertexNormals();
|
||||
let meh = this.mesh = new THREE.Mesh(geo, materials.unselected);
|
||||
meh.receiveShadow = true;
|
||||
meh.castShadow = true;
|
||||
|
|
@ -104,14 +104,14 @@ mesh.model = class MeshModel extends mesh.object {
|
|||
worker.model_load({id: this.id, name: this.file, vertices, indices});
|
||||
}
|
||||
|
||||
reload(vertices, indices) {
|
||||
reload(vertices, indices, normals) {
|
||||
this.wireframe(false);
|
||||
let geo = this.mesh.geometry;
|
||||
geo.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
|
||||
geo.setAttribute('normal', undefined);
|
||||
if (indices) geo.setIndex(new THREE.BufferAttribute(indices, 1));
|
||||
geo.attributes.position.needsUpdate = true;
|
||||
geo.computeVertexNormals();
|
||||
if (!normals) geo.computeVertexNormals();
|
||||
// sync data to worker
|
||||
worker.model_load({id: this.id, name: this.name, vertices, indices});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue