add util.defer() and add slight opacity in wireframe
This commit is contained in:
parent
cd5688972a
commit
5541e680ce
3 changed files with 32 additions and 9 deletions
|
|
@ -32,7 +32,7 @@ function init() {
|
|||
opacity: 0.1,
|
||||
color: 0xdddddd,
|
||||
zoom: { reverse: true, speed: 1 },
|
||||
size: { width: 300, depth: 300, height: 1, maxz: 300 },
|
||||
size: { width: 2000, depth: 2000, height: 1, maxz: 300 },
|
||||
grid: { major: 25, minor: 5, colorMajor: 0xcccccc, colorMinor: 0xeeeeee, colorX: 0xffaaaa, colorY: 0xaaaaff },
|
||||
});
|
||||
space.view.setZoom(zoomrev, zoomspd);
|
||||
|
|
@ -99,6 +99,7 @@ function ui_build() {
|
|||
}
|
||||
|
||||
// listen for api calls
|
||||
// todo: switch to util.defer(fn)
|
||||
broker.listeners({
|
||||
model_add: maker.update,
|
||||
group_add: maker.update,
|
||||
|
|
@ -150,7 +151,7 @@ function space_init(data) {
|
|||
selection.focus();
|
||||
break;
|
||||
case 'KeyW':
|
||||
selection.wireframe({toggle:true});
|
||||
selection.wireframe({toggle:true}, {opacity:0.15});
|
||||
break;
|
||||
case 'KeyB':
|
||||
selection.boundsBox({toggle:true});
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue