prepare to sync models to worker(s)
This commit is contained in:
parent
ef4dace758
commit
2f2cb85349
6 changed files with 41 additions and 33 deletions
|
|
@ -18,15 +18,12 @@ function init() {
|
||||||
platform = space.platform;
|
platform = space.platform;
|
||||||
|
|
||||||
// setup default workspace
|
// setup default workspace
|
||||||
|
space.useDefaultKeys(false);
|
||||||
space.sky.set({
|
space.sky.set({
|
||||||
grid: sky,
|
grid: sky,
|
||||||
color: dark ? 0 : 0xffffff
|
color: dark ? 0 : 0xffffff
|
||||||
});
|
});
|
||||||
space.init($('container'), delta => { }, ortho);
|
space.init($('container'), delta => { }, ortho);
|
||||||
platform.onClick(click => {
|
|
||||||
// api.selection.clear();
|
|
||||||
});
|
|
||||||
platform.onMove(delta => { });
|
|
||||||
platform.set({
|
platform.set({
|
||||||
volume: false,
|
volume: false,
|
||||||
round: false,
|
round: false,
|
||||||
|
|
@ -38,7 +35,6 @@ function init() {
|
||||||
grid: { major: 25, minor: 5, majorColor: 0x999999, minorColor: 0xcccccc },
|
grid: { major: 25, minor: 5, majorColor: 0x999999, minorColor: 0xcccccc },
|
||||||
});
|
});
|
||||||
space.view.setZoom(zoomrev, zoomspd);
|
space.view.setZoom(zoomrev, zoomspd);
|
||||||
space.useDefaultKeys(false);
|
|
||||||
|
|
||||||
// trigger space event binding
|
// trigger space event binding
|
||||||
broker.send.space_init({ space, platform });
|
broker.send.space_init({ space, platform });
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
// dep: ext.three
|
// dep: ext.three
|
||||||
// dep: ext.three-bgu
|
// dep: ext.three-bgu
|
||||||
gapp.load(bind, "mesh.api", [
|
gapp.register("mesh.api", [
|
||||||
"moto.license", // dep: moto.license
|
"moto.license", // dep: moto.license
|
||||||
"moto.client", // dep: moto.client
|
"moto.client", // dep: moto.client
|
||||||
"moto.broker", // dep: moto.broker
|
"moto.broker", // dep: moto.broker
|
||||||
|
|
@ -15,21 +15,12 @@ gapp.load(bind, "mesh.api", [
|
||||||
"add.array", // dep: add.array
|
"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 || {};
|
let mesh = self.mesh = self.mesh || {};
|
||||||
if (mesh.api) return;
|
if (mesh.api) return;
|
||||||
|
|
||||||
let space = moto.Space;
|
let space = moto.Space;
|
||||||
let groups = [];
|
let groups = [];
|
||||||
let selected = [];
|
let selected = [];
|
||||||
let broker;
|
|
||||||
|
|
||||||
let selection = {
|
let selection = {
|
||||||
// @returns {MeshObject[]}
|
// @returns {MeshObject[]}
|
||||||
|
|
@ -194,6 +185,18 @@ let group = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let model = {
|
||||||
|
// @returns {MeshModel[]}
|
||||||
|
list() {
|
||||||
|
return groups.map(g => g.models).flat();
|
||||||
|
},
|
||||||
|
|
||||||
|
// @param group {MeshModel}
|
||||||
|
remove: (model) => {
|
||||||
|
model.group.remove(model);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let api = mesh.api = {
|
let api = mesh.api = {
|
||||||
clear: () => {
|
clear: () => {
|
||||||
for (let group of group.list()) {
|
for (let group of group.list()) {
|
||||||
|
|
@ -220,17 +223,7 @@ let api = mesh.api = {
|
||||||
|
|
||||||
group,
|
group,
|
||||||
|
|
||||||
model: {
|
model,
|
||||||
// @returns {MeshModel[]}
|
|
||||||
list() {
|
|
||||||
return groups.map(g => g.models).flat();
|
|
||||||
},
|
|
||||||
|
|
||||||
// @param group {MeshModel}
|
|
||||||
remove: (model) => {
|
|
||||||
model.group.remove(model);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
objects: () => {
|
objects: () => {
|
||||||
// return models, not groups
|
// return models, not groups
|
||||||
|
|
@ -240,6 +233,14 @@ let api = mesh.api = {
|
||||||
|
|
||||||
let util = mesh.util = {
|
let util = mesh.util = {
|
||||||
|
|
||||||
|
uuid: (segs = 1) => {
|
||||||
|
let uid = [];
|
||||||
|
while (segs-- > 0) {
|
||||||
|
uid.push(Math.round(Math.random() * 0xffffffff).toString(36));
|
||||||
|
}
|
||||||
|
return uid.join('-');
|
||||||
|
},
|
||||||
|
|
||||||
// @param object {THREE.Object3D | THREE.Object3D[] | MeshObject | MeshObject[]}
|
// @param object {THREE.Object3D | THREE.Object3D[] | MeshObject | MeshObject[]}
|
||||||
// @returns bounds modified for moto.Space
|
// @returns bounds modified for moto.Space
|
||||||
bounds: (object) => {
|
bounds: (object) => {
|
||||||
|
|
@ -341,4 +342,12 @@ let util = mesh.util = {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let 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);
|
||||||
|
model.remove = broker.wrap('model.remove', model.remove);
|
||||||
|
group.remove = broker.wrap('group.remove', group.remove);
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ gapp.register("mesh.group", [
|
||||||
"moto.license", // dep: moto.license
|
"moto.license", // dep: moto.license
|
||||||
"mesh.object", // dep: mesh.object
|
"mesh.object", // dep: mesh.object
|
||||||
"mesh.model", // dep: mesh.model
|
"mesh.model", // dep: mesh.model
|
||||||
|
"mesh.api", // dep: mesh.api
|
||||||
]);
|
]);
|
||||||
|
|
||||||
let mesh = self.mesh = self.mesh || {};
|
let mesh = self.mesh = self.mesh || {};
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,8 @@ mesh.model = class MeshModel extends mesh.object {
|
||||||
sync() {
|
sync() {
|
||||||
moto.client.fn.model_sync({
|
moto.client.fn.model_sync({
|
||||||
vertices: this.mesh.geometry.attributes.position.array,
|
vertices: this.mesh.geometry.attributes.position.array,
|
||||||
matrix: this.mesh.matrixWorld.elements
|
matrix: this.mesh.matrixWorld.elements,
|
||||||
|
id: this.id
|
||||||
}).then(data => {
|
}).then(data => {
|
||||||
if (data && data.length)
|
if (data && data.length)
|
||||||
// for debugging matrix ops
|
// for debugging matrix ops
|
||||||
|
|
@ -71,9 +72,7 @@ mesh.model = class MeshModel extends mesh.object {
|
||||||
let geo = new THREE.BufferGeometry();
|
let geo = new THREE.BufferGeometry();
|
||||||
if (indices) geo.setIndex(new THREE.BufferAttribute(indices, 1));
|
if (indices) geo.setIndex(new THREE.BufferAttribute(indices, 1));
|
||||||
geo.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
|
geo.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
|
||||||
geo.setAttribute('normal', undefined);
|
|
||||||
let meh = new THREE.Mesh(geo, materials.unselected);
|
let meh = new THREE.Mesh(geo, materials.unselected);
|
||||||
geo.computeFaceNormals();
|
|
||||||
geo.computeVertexNormals();
|
geo.computeVertexNormals();
|
||||||
meh.material.side = THREE.DoubleSide;
|
meh.material.side = THREE.DoubleSide;
|
||||||
meh.receiveShadow = true;
|
meh.receiveShadow = true;
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,10 @@ if (mesh.object) return;
|
||||||
|
|
||||||
mesh.object = class MeshObject {
|
mesh.object = class MeshObject {
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.id = mesh.util.uuid();
|
||||||
|
}
|
||||||
|
|
||||||
// @returns {THREE.Object3D}
|
// @returns {THREE.Object3D}
|
||||||
object() {
|
object() {
|
||||||
throw "object() requires implementation";
|
throw "object() requires implementation";
|
||||||
|
|
|
||||||
|
|
@ -20,14 +20,13 @@ gapp.finalize("mesh.work", [
|
||||||
// compensation for space/world/platform rotation
|
// compensation for space/world/platform rotation
|
||||||
let space_rotation = new THREE.Matrix4().makeRotationX(Math.PI / 2);
|
let space_rotation = new THREE.Matrix4().makeRotationX(Math.PI / 2);
|
||||||
|
|
||||||
|
let cache = {};
|
||||||
|
|
||||||
moto.worker.bind("model_sync", (data, send) => {
|
moto.worker.bind("model_sync", (data, send) => {
|
||||||
let { vertices, matrix } = data;
|
let { vertices, matrix, id } = data;
|
||||||
// return send.done(vertices);
|
// return send.done(vertices);
|
||||||
let geo = new THREE.BufferGeometry();
|
let geo = new THREE.BufferGeometry();
|
||||||
geo.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
|
geo.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
|
||||||
geo.setAttribute('normal', undefined);
|
|
||||||
geo.computeFaceNormals();
|
|
||||||
geo.computeVertexNormals();
|
|
||||||
let m4 = space_rotation.clone().multiply( new THREE.Matrix4().fromArray(matrix) );
|
let m4 = space_rotation.clone().multiply( new THREE.Matrix4().fromArray(matrix) );
|
||||||
geo.applyMatrix4(m4);
|
geo.applyMatrix4(m4);
|
||||||
// for debugging matrix ops
|
// for debugging matrix ops
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue