diff --git a/src/add/three.js b/src/add/three.js index e9c99413..02113411 100644 --- a/src/add/three.js +++ b/src/add/three.js @@ -111,6 +111,14 @@ return this; }; + BP.shallowClone = function() { + let geo = new THREE.BufferGeometry(); + for (let [k, v] of Object.entries(this.attributes)) { + geo.setAttribute(k, new THREE.BufferAttribute(v.array, v.itemSize)); + } + return geo; + }; + THREE.Object3D.prototype.newGroup = function() { var group = new THREE.Group(); this.add(group); diff --git a/src/mesh/group.js b/src/mesh/group.js index 2469c249..83c04044 100644 --- a/src/mesh/group.js +++ b/src/mesh/group.js @@ -89,11 +89,6 @@ mesh.group = class MeshGroup extends mesh.object { return this; } - // update(oldmesh, newmesh) { - // this.group.remove(oldmesh); - // this.group.add(newmesh); - // } - // center objects to group bounds // dependent on first being added to world/scene centerModels() { diff --git a/src/mesh/model.js b/src/mesh/model.js index ba98c0e6..127fe452 100644 --- a/src/mesh/model.js +++ b/src/mesh/model.js @@ -104,19 +104,15 @@ mesh.model = class MeshModel extends mesh.object { worker.model_load({id: this.id, name: this.file, vertices, indices}); } - optimize(geo) { - let ind = THREE.BufferGeometryUtils.mergeVertices(geo || this.mesh.geometry); - console.log({geo: geo || this.mesh.geometry.clone(), ind}); - return ind; - } - reload(vertices, indices) { 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(); + // sync data to worker worker.model_load({id: this.id, name: this.name, vertices, indices}); } @@ -141,7 +137,7 @@ mesh.model = class MeshModel extends mesh.object { mat.opacity = 1; mat.visible = false; } else { - mat.transparent = ov < 1.0; + mat.transparent = true; mat.opacity = ov; mat.visible = true; } @@ -167,9 +163,8 @@ mesh.model = class MeshModel extends mesh.object { this.opacity(this._wireo); } if (bool) { - this.material({clone:true}); this._wireo = this.opacity(); - this._wire = new THREE.Mesh(this.mesh.geometry, materials.wireframe); + this._wire = new THREE.Mesh(this.mesh.geometry.shallowClone(), materials.wireframe); this.mesh.add(this._wire); this.opacity(opt.opacity || 0); } @@ -177,10 +172,8 @@ mesh.model = class MeshModel extends mesh.object { } material(mat) { - this.mesh.material = mat.clone === true ? this.mesh.material.clone() : mat; - if (this._wire) { - this.wireframe(false); - } + this.wireframe(false); + this.mesh.material = mat; } remove() {