take over key bindings, add toggle for selection wireframe and bounding box
This commit is contained in:
parent
a64ef24dbe
commit
d73cf48d90
4 changed files with 77 additions and 17 deletions
|
|
@ -38,7 +38,7 @@ function init() {
|
|||
grid: { major: 25, minor: 5, majorColor: 0x999999, minorColor: 0xcccccc }
|
||||
});
|
||||
space.view.setZoom(zoomrev, zoomspd);
|
||||
space.useDefaultKeys(true);
|
||||
space.useDefaultKeys(false);
|
||||
|
||||
// trigger space event binding
|
||||
broker.send.space_init({ space, platform });
|
||||
|
|
@ -87,9 +87,27 @@ broker.subscribe('space_init', data => {
|
|||
},
|
||||
'keypress', evt => {
|
||||
switch (evt.code) {
|
||||
case 'KeyC':
|
||||
api.selection.centerXY();
|
||||
break;
|
||||
case 'KeyV':
|
||||
api.selection.focus();
|
||||
break;
|
||||
case 'KeyW':
|
||||
api.selection.wireframe({toggle:true});
|
||||
break;
|
||||
case 'KeyB':
|
||||
api.selection.boundsBox({toggle:true});
|
||||
break;
|
||||
case 'KeyH':
|
||||
space.view.home();
|
||||
break;
|
||||
case 'KeyT':
|
||||
space.view.top();
|
||||
break;
|
||||
case 'KeyZ':
|
||||
space.view.reset();
|
||||
break;
|
||||
}
|
||||
},
|
||||
'keydown', evt => {
|
||||
|
|
@ -129,7 +147,7 @@ broker.subscribe('space_init', data => {
|
|||
// group.qrotate(q);
|
||||
let e = new THREE.Euler().setFromQuaternion(q);
|
||||
let n = int.face.normal;
|
||||
// console.log({n,q,e});
|
||||
console.log({n,q,e});
|
||||
group.rotation(e.x, e.y, e.z);
|
||||
group.floor();
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -37,6 +37,28 @@ let selection = {
|
|||
return selected.slice();
|
||||
},
|
||||
|
||||
groups() {
|
||||
let all = selection.list();
|
||||
let grp = all.filter(s => s instanceof mesh.group);
|
||||
let mdl = all.filter(s => s instanceof mesh.model);
|
||||
for (let m of mdl) {
|
||||
grp.addOnce(m.group);
|
||||
}
|
||||
return grp;
|
||||
},
|
||||
|
||||
models() {
|
||||
let all = selection.list();
|
||||
let grp = all.filter(s => s instanceof mesh.group);
|
||||
let mdl = all.filter(s => s instanceof mesh.model);
|
||||
for (let g of grp) {
|
||||
for (let m of g.models) {
|
||||
mdl.addOnce(m);
|
||||
}
|
||||
}
|
||||
return mdl;
|
||||
},
|
||||
|
||||
// @param group {MeshObject[]}
|
||||
set(objects) {
|
||||
selected = objects;
|
||||
|
|
@ -68,11 +90,9 @@ let selection = {
|
|||
update() {
|
||||
for (let group of groups) {
|
||||
group.material(mesh.material.unselected);
|
||||
group.showBounds(true);
|
||||
}
|
||||
for (let object of selected) {
|
||||
object.material(mesh.material.selected);
|
||||
object.showBounds(true);
|
||||
}
|
||||
return selection;
|
||||
},
|
||||
|
|
@ -120,6 +140,20 @@ let selection = {
|
|||
return selection;
|
||||
},
|
||||
|
||||
wireframe() {
|
||||
for (let m of selection.models()) {
|
||||
m.wireframe(...arguments);
|
||||
}
|
||||
return selection;
|
||||
},
|
||||
|
||||
boundsBox() {
|
||||
for (let m of selection.groups()) {
|
||||
m.showBounds(...arguments);
|
||||
}
|
||||
return selection;
|
||||
},
|
||||
|
||||
home() {
|
||||
return selection.centerXY().floor();
|
||||
},
|
||||
|
|
@ -176,10 +210,10 @@ let api = mesh.api = {
|
|||
center = { x: 0, y: 0, z: 0 };
|
||||
}
|
||||
// sets "home" views (front, back, home, reset)
|
||||
space.platform.setCenter(center.x, center.y, center.z);
|
||||
space.platform.setCenter(center.x, -center.y, center.z);
|
||||
// sets camera focus
|
||||
space.view.setFocus(new THREE.Vector3(
|
||||
center.x, center.z, center.y
|
||||
center.x, center.z, -center.y
|
||||
));
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -135,6 +135,9 @@ mesh.model = class MeshModel extends mesh.object {
|
|||
enabled: false
|
||||
};
|
||||
}
|
||||
if (bool.toggle) {
|
||||
return this.wireframe(this._wire ? false : true);
|
||||
}
|
||||
if (this._wire) {
|
||||
this.mesh.remove(this._wire);
|
||||
this._wire = undefined;
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ mesh.object = class MeshObject {
|
|||
|
||||
centerXY(bounds) {
|
||||
let b = bounds || this.bounds();
|
||||
this.move(-b.center.x, b.center.y, 0);
|
||||
this.move(-b.center.x, -b.center.y, 0);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
@ -64,6 +64,15 @@ mesh.object = class MeshObject {
|
|||
moto.Space.update();
|
||||
}
|
||||
|
||||
rotate(x = 0, y = 0, z = 0) {
|
||||
if (x) this.object().rotateOnWorldAxis(new THREE.Vector3(1,0,0), x);
|
||||
if (y) this.object().rotateOnWorldAxis(new THREE.Vector3(0,1,0), y);
|
||||
if (z) this.object().rotateOnWorldAxis(new THREE.Vector3(0,0,1), z);
|
||||
this.updateBoundsBox();
|
||||
moto.Space.update();
|
||||
return this;
|
||||
}
|
||||
|
||||
// use with caution. frames of reference interfere.
|
||||
rotation() {
|
||||
let rot = this.object().rotation;
|
||||
|
|
@ -76,15 +85,7 @@ mesh.object = class MeshObject {
|
|||
return this;
|
||||
}
|
||||
|
||||
rotate(x = 0, y = 0, z = 0) {
|
||||
if (x) this.object().rotateOnWorldAxis(new THREE.Vector3(1,0,0), x);
|
||||
if (y) this.object().rotateOnWorldAxis(new THREE.Vector3(0,1,0), y);
|
||||
if (z) this.object().rotateOnWorldAxis(new THREE.Vector3(0,0,1), z);
|
||||
this.updateBoundsBox();
|
||||
moto.Space.update();
|
||||
return this;
|
||||
}
|
||||
|
||||
// use with caution. frames of reference interfere.
|
||||
qrotate(quaternion) {
|
||||
this.object().setRotationFromQuaternion(quaternion);
|
||||
this.updateBoundsBox();
|
||||
|
|
@ -102,7 +103,11 @@ mesh.object = class MeshObject {
|
|||
}
|
||||
|
||||
showBounds(bool) {
|
||||
if (bool && bool.toggle) {
|
||||
bool = !this._showBounds;
|
||||
}
|
||||
this._showBounds = bool;
|
||||
this.updateBoundsBox();
|
||||
}
|
||||
|
||||
updateBoundsBox() {
|
||||
|
|
@ -117,7 +122,7 @@ mesh.object = class MeshObject {
|
|||
new THREE.Vector3(center.x, center.y, center.z),
|
||||
new THREE.Vector3(size.x, size.y, size.z)
|
||||
);
|
||||
let helper = this._boundsBox = new THREE.Box3Helper(b3, 0xff00ff);
|
||||
let helper = this._boundsBox = new THREE.Box3Helper(b3, 0x1155aa);
|
||||
world.add(helper);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue