add object bounding box visualization, broker function wrappers
This commit is contained in:
parent
8cd2a22a54
commit
a64ef24dbe
6 changed files with 57 additions and 8 deletions
|
|
@ -33,7 +33,7 @@
|
|||
"moment": "^2.24.0",
|
||||
"pixi.js": "^4.8.9",
|
||||
"serve-static": "^1.14.1",
|
||||
"three": "^0.126.0",
|
||||
"three": "^0.128.0",
|
||||
"uglify-es": "3.3.9",
|
||||
"validator": ">=13.7.0",
|
||||
"ws": "^7.5.5"
|
||||
|
|
|
|||
|
|
@ -113,7 +113,6 @@ broker.subscribe('space_init', data => {
|
|||
|
||||
// mouse hover/click handlers
|
||||
space.mouse.downSelect((int, event) => {
|
||||
// mesh array including platform
|
||||
return api.objects();
|
||||
});
|
||||
|
||||
|
|
@ -127,11 +126,11 @@ broker.subscribe('space_init', data => {
|
|||
let q = new THREE.Quaternion();
|
||||
// find intersecting point, look "up" on Z and rotate to face that
|
||||
q.setFromUnitVectors(int.face.normal, new THREE.Vector3(0,0,-1));
|
||||
// let e = new THREE.Euler().setFromQuaternion(q);
|
||||
// let n = int.face.normal;
|
||||
// group.qrotate(q);
|
||||
let e = new THREE.Euler().setFromQuaternion(q);
|
||||
let n = int.face.normal;
|
||||
// console.log({n,q,e});
|
||||
// group.rotation(e.x, e.y, e.z);
|
||||
group.qrotate(q);
|
||||
group.rotation(e.x, e.y, e.z);
|
||||
group.floor();
|
||||
} else {
|
||||
api.selection.toggle(model.group);
|
||||
|
|
|
|||
|
|
@ -6,20 +6,30 @@
|
|||
|
||||
// dep: ext.three
|
||||
// dep: ext.three-bgu
|
||||
gapp.register("mesh.api", [
|
||||
gapp.load(bind, "mesh.api", [
|
||||
"moto.license", // dep: moto.license
|
||||
"moto.client", // dep: moto.client
|
||||
"moto.broker", // dep: moto.broker
|
||||
"moto.space", // dep: moto.space
|
||||
"mesh.tool", // dep: mesh.tool
|
||||
"add.array", // dep: add.array
|
||||
]);
|
||||
|
||||
function bind() {
|
||||
broker = gapp.broker;
|
||||
// publish messages with results of function call
|
||||
// selection.move = broker.wrap('selection.move', selection.move);
|
||||
// selection.rotate = broker.wrap('selection.rotate', selection.rotate);
|
||||
// selection.update = broker.wrap('selection.update', selection.update);
|
||||
}
|
||||
|
||||
let mesh = self.mesh = self.mesh || {};
|
||||
if (mesh.api) return;
|
||||
|
||||
let space = moto.Space;
|
||||
let groups = [];
|
||||
let selected = [];
|
||||
let broker;
|
||||
|
||||
let selection = {
|
||||
// @returns {MeshObject[]}
|
||||
|
|
@ -58,10 +68,13 @@ 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;
|
||||
},
|
||||
|
||||
move(dx = 0, dy = 0, dz = 0) {
|
||||
|
|
@ -231,7 +244,7 @@ let util = mesh.util = {
|
|||
};
|
||||
bnd.center = {
|
||||
x: (bnd.max.x + bnd.min.x) / 2,
|
||||
y: (bnd.max.y + bnd.min.y) / 2,
|
||||
y: -(bnd.max.y + bnd.min.y) / 2,
|
||||
z: (bnd.max.z + bnd.min.z) / 2
|
||||
};
|
||||
return bnd;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ gapp.register("mesh.model", [
|
|||
"moto.license", // dep: moto.license
|
||||
"mesh.object", // dep: mesh.object
|
||||
"mesh.group", // dep: mesh.group
|
||||
"mesh.api", // dep: mesh.api
|
||||
]);
|
||||
|
||||
let mesh = self.mesh = self.mesh || {};
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
gapp.register("mesh.object", [
|
||||
"add.three", // dep: add.three
|
||||
"moto.license", // dep: moto.license
|
||||
"mesh.api", // dep: mesh.api
|
||||
]);
|
||||
|
||||
let mesh = self.mesh = self.mesh || {};
|
||||
|
|
@ -48,6 +49,7 @@ mesh.object = class MeshObject {
|
|||
move(x = 0, y = 0, z = 0) {
|
||||
let pos = this.position();
|
||||
pos.set(pos.x + x, pos.y + y, pos.z + z);
|
||||
this.updateBoundsBox();
|
||||
moto.Space.update();
|
||||
return this;
|
||||
}
|
||||
|
|
@ -58,6 +60,7 @@ mesh.object = class MeshObject {
|
|||
return scale;
|
||||
}
|
||||
scale.set(...arguments);
|
||||
this.updateBoundsBox();
|
||||
moto.Space.update();
|
||||
}
|
||||
|
||||
|
|
@ -68,6 +71,7 @@ mesh.object = class MeshObject {
|
|||
return rot;
|
||||
}
|
||||
rot.set(...arguments);
|
||||
this.updateBoundsBox();
|
||||
moto.Space.update();
|
||||
return this;
|
||||
}
|
||||
|
|
@ -76,12 +80,14 @@ mesh.object = class MeshObject {
|
|||
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;
|
||||
}
|
||||
|
||||
qrotate(quaternion) {
|
||||
this.object().setRotationFromQuaternion(quaternion);
|
||||
this.updateBoundsBox();
|
||||
moto.Space.update();
|
||||
return this;
|
||||
}
|
||||
|
|
@ -94,6 +100,27 @@ mesh.object = class MeshObject {
|
|||
pos.set(...arguments);
|
||||
moto.Space.update();
|
||||
}
|
||||
|
||||
showBounds(bool) {
|
||||
this._showBounds = bool;
|
||||
}
|
||||
|
||||
updateBoundsBox() {
|
||||
let helper = this._boundsBox;
|
||||
let world = moto.Space.world;
|
||||
if (helper) {
|
||||
world.remove(helper);
|
||||
}
|
||||
if (this._showBounds) {
|
||||
let { center, size } = this.bounds();
|
||||
let b3 = new THREE.Box3().setFromCenterAndSize(
|
||||
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);
|
||||
world.add(helper);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -82,6 +82,7 @@ gapp.broker = new class Broker {
|
|||
} else if (topic.indexOf(".topic.") < 0) {
|
||||
dbug.debug(`undelivered '${topic}'`, message);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
// return function bound to a topic
|
||||
|
|
@ -91,6 +92,14 @@ gapp.broker = new class Broker {
|
|||
broker.publish(topic, message || msg, options || opt);
|
||||
}
|
||||
}
|
||||
|
||||
// return function wrapper that publishes a message to a topic
|
||||
wrap(topic, fn) {
|
||||
let broker = this;
|
||||
return function() {
|
||||
return broker.publish(topic, fn(...arguments));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
})();
|
||||
|
|
|
|||
Loading…
Reference in a new issue