fix mesh gl errors with geometry shallow clone
This commit is contained in:
parent
027f75ef6d
commit
19721b0dcc
3 changed files with 14 additions and 18 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue