add util.defer() and add slight opacity in wireframe

This commit is contained in:
Stewart Allen 2022-01-02 23:47:28 -05:00
commit 5541e680ce
3 changed files with 32 additions and 9 deletions

View file

@ -57,7 +57,7 @@ let selection = {
// @param group {MeshObject[]}
set(objects) {
selected = objects;
selection.update();
util.defer(selection.update);
},
// @param group {MeshObject}
@ -77,13 +77,13 @@ let selection = {
}
}
selected.addOnce(object);
selection.update();
util.defer(selection.update);
},
// @param group {MeshObject}
remove(object) {
selected.remove(object);
selection.update();
util.defer(selection.update);
},
// @param group {MeshObject}
@ -96,8 +96,9 @@ let selection = {
},
clear() {
selected = [];
selection.update();
for (let s of selected) {
selection.remove(s);
}
},
update() {
@ -251,6 +252,8 @@ let api = mesh.api = {
}
};
let deferFn = [];
let util = mesh.util = {
uuid(segs = 1) {
@ -261,6 +264,24 @@ let util = mesh.util = {
return uid.join('-');
},
// merge repeated function calls like updates
// that importantly take no arguments
defer(fn, time = 50) {
for (let rec of deferFn) {
if (rec.fn === fn) {
clearTimeout(rec.timer);
deferFn.remove(rec);
break;
}
}
let rec = { fn };
rec.timer = setTimeout(() => {
deferFn.remove(rec);
fn();
});
deferFn.push(rec);
},
// @param object {THREE.Object3D | THREE.Object3D[] | MeshObject | MeshObject[]}
// @returns bounds modified for moto.Space
bounds(object) {

View file

@ -150,7 +150,7 @@ mesh.model = class MeshModel extends mesh.object {
};
}
if (bool.toggle) {
return this.wireframe(this._wire ? false : true);
return this.wireframe(this._wire ? false : true, opt);
}
if (this._wire) {
this.mesh.remove(this._wire);
@ -158,6 +158,7 @@ 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.LineSegments(
new THREE.WireframeGeometry(this.mesh.geometry),
@ -169,7 +170,7 @@ mesh.model = class MeshModel extends mesh.object {
}
material(mat) {
this.mesh.material = mat;
this.mesh.material = mat.clone === true ? this.mesh.material.clone() : mat;
}
remove() {