add focus. improve bounds with arrays
This commit is contained in:
parent
af6ae4ed32
commit
86b60cc715
4 changed files with 73 additions and 18 deletions
|
|
@ -81,20 +81,26 @@ broker.subscribe('space_init', data => {
|
||||||
platform.setColor(platcolor);
|
platform.setColor(platcolor);
|
||||||
},
|
},
|
||||||
'keypress', evt => {
|
'keypress', evt => {
|
||||||
|
switch (evt.code) {
|
||||||
|
case 'KeyV':
|
||||||
|
api.selection.focus();
|
||||||
|
break;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
'keydown', evt => {
|
'keydown', evt => {
|
||||||
|
let rv = Math.PI / 16;
|
||||||
switch (evt.code) {
|
switch (evt.code) {
|
||||||
case 'ArrowUp':
|
case 'ArrowUp':
|
||||||
api.selection.rotate(-0.2,0,0).floor();
|
api.selection.rotate(-rv,0,0).floor();
|
||||||
break;
|
break;
|
||||||
case 'ArrowDown':
|
case 'ArrowDown':
|
||||||
api.selection.rotate(0.2,0,0).floor();
|
api.selection.rotate(rv,0,0).floor();
|
||||||
break;
|
break;
|
||||||
case 'ArrowLeft':
|
case 'ArrowLeft':
|
||||||
api.selection.rotate(0,0,0.2).floor();
|
api.selection.rotate(0,0,rv).floor();
|
||||||
break;
|
break;
|
||||||
case 'ArrowRight':
|
case 'ArrowRight':
|
||||||
api.selection.rotate(0,0,-0.2).floor();
|
api.selection.rotate(0,0,-rv).floor();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -106,7 +112,8 @@ broker.subscribe('space_load', data => {
|
||||||
mesh.api.group.new(data.flat().map(el => new mesh.model(el)))
|
mesh.api.group.new(data.flat().map(el => new mesh.model(el)))
|
||||||
.centerModels()
|
.centerModels()
|
||||||
.centerXY()
|
.centerXY()
|
||||||
.floor();
|
.floor()
|
||||||
|
.focus();
|
||||||
});
|
});
|
||||||
|
|
||||||
// remove version cache bust from url
|
// remove version cache bust from url
|
||||||
|
|
|
||||||
|
|
@ -73,13 +73,21 @@ let selection = {
|
||||||
|
|
||||||
centerXY() {
|
centerXY() {
|
||||||
for (let s of selected) {
|
for (let s of selected) {
|
||||||
s.floor(...arguments);
|
s.centerXY(...arguments);
|
||||||
}
|
}
|
||||||
return selection;
|
return selection;
|
||||||
},
|
},
|
||||||
|
|
||||||
home() {
|
home() {
|
||||||
return selection.centerXY().floor();
|
return selection.centerXY().floor();
|
||||||
|
},
|
||||||
|
|
||||||
|
focus() {
|
||||||
|
api.focus(selected);
|
||||||
|
},
|
||||||
|
|
||||||
|
bounds() {
|
||||||
|
return util.bounds(selected.map(s => s.object()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -118,6 +126,18 @@ let api = mesh.api = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// @param object {THREE.Object3D | THREE.Object3D[]}
|
||||||
|
focus: (object) => {
|
||||||
|
let { center } = util.bounds(object);
|
||||||
|
// when no objects supplied
|
||||||
|
if (isNaN(center.x * center.y * center.z)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
space.view.setFocus(new THREE.Vector3(
|
||||||
|
center.x, center.z, center.y
|
||||||
|
));
|
||||||
|
},
|
||||||
|
|
||||||
selection,
|
selection,
|
||||||
|
|
||||||
group,
|
group,
|
||||||
|
|
@ -137,10 +157,22 @@ let api = mesh.api = {
|
||||||
|
|
||||||
let util = mesh.util = {
|
let util = mesh.util = {
|
||||||
|
|
||||||
// @param object {THREE.Object3D}
|
// @param object {THREE.Object3D | THREE.Object3D[]}
|
||||||
// @returns bounds modified for moto.Space
|
// @returns bounds modified for moto.Space
|
||||||
bounds: (object) => {
|
bounds: (object) => {
|
||||||
let box = new THREE.Box3().setFromObject(object);
|
let box = new THREE.Box3();
|
||||||
|
if (Array.isArray(object)) {
|
||||||
|
for (let o of object) {
|
||||||
|
box.union(new THREE.Box3().setFromObject(
|
||||||
|
o instanceof mesh.object ? o.object() : o
|
||||||
|
));
|
||||||
|
}
|
||||||
|
} else if (object) {
|
||||||
|
box.setFromObject(
|
||||||
|
object instanceof mesh.object ? object.object() : object);
|
||||||
|
} else {
|
||||||
|
return box;
|
||||||
|
}
|
||||||
let bnd = {
|
let bnd = {
|
||||||
min: {
|
min: {
|
||||||
x: box.min.x,
|
x: box.min.x,
|
||||||
|
|
|
||||||
|
|
@ -27,16 +27,6 @@ mesh.group = class MeshGroup extends mesh.object {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// center objects to group bounds
|
|
||||||
// dependent on first being added to world/scene
|
|
||||||
centerModels() {
|
|
||||||
let bounds = this.bounds();
|
|
||||||
for (let model of this.models) {
|
|
||||||
model.center(bounds);
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
object() {
|
object() {
|
||||||
return this.group;
|
return this.group;
|
||||||
}
|
}
|
||||||
|
|
@ -62,6 +52,28 @@ mesh.group = class MeshGroup extends mesh.object {
|
||||||
moto.Space.update();
|
moto.Space.update();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// center objects to group bounds
|
||||||
|
// dependent on first being added to world/scene
|
||||||
|
centerModels() {
|
||||||
|
let bounds = this.bounds();
|
||||||
|
for (let model of this.models) {
|
||||||
|
model.center(bounds);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
opacity() {
|
||||||
|
for (let model of this.models) {
|
||||||
|
model.opacity(...arguments);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wireframe() {
|
||||||
|
for (let model of this.models) {
|
||||||
|
model.wireframe(...arguments);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,10 @@ mesh.object = class MeshObject {
|
||||||
return mesh.util.bounds(this.object());
|
return mesh.util.bounds(this.object());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
focus() {
|
||||||
|
mesh.api.focus(this.object());
|
||||||
|
}
|
||||||
|
|
||||||
floor() {
|
floor() {
|
||||||
let b = this.bounds();
|
let b = this.bounds();
|
||||||
this.move(0, 0, -b.min.z);
|
this.move(0, 0, -b.min.z);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue