grid-apps-cmms/src/mesh/work.js

103 lines
2.1 KiB
JavaScript
Raw Normal View History

/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
"use strict";
(function() {
// start worker pool (disabled for now with *0)
moto.client.start(`/code/mesh_pool?${gapp.version}`, moto.client.max() * 0);
// dep: ext.three
// dep: ext.three-bgu
gapp.finalize("mesh.work", [
"moto.license", // dep: moto.license
2021-12-29 17:20:17 -05:00
"moto.client", // dep: moto.client
"moto.worker", // dep: moto.worker
"mesh.tool", // dep: mesh.tool
2021-12-31 22:11:20 -05:00
"add.three", // dep: add.three
]);
2021-12-27 18:13:11 -05:00
2021-12-31 22:11:20 -05:00
// compensation for space/world/platform rotation
2022-01-02 16:30:05 -05:00
let core_matrix = new THREE.Matrix4().makeRotationX(Math.PI / 2);
2021-12-31 22:11:20 -05:00
let { client, worker } = moto;
2022-01-01 22:39:49 -05:00
let cache = {};
function cacheUpdate(id, data) {
Object.assign(cache[id], data);
}
let model = {
load(data) {
let { vertices, name, id } = data;
let geo = new THREE.BufferGeometry();
geo.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
geo.computeVertexNormals();
2022-01-02 16:30:05 -05:00
cacheUpdate(id, { name, geo, matrix: core_matrix.clone() });
},
debug(data) {
let { matrix, id } = data;
let rec = cache[id];
let geo = rec.geo.clone();
2022-01-02 16:30:05 -05:00
let m4 = core_matrix.clone().multiply( new THREE.Matrix4().fromArray(matrix) );
geo.applyMatrix4(m4);
// for debugging state / matrix ops
return geo.attributes.position.array;
}
};
let group = {
add(data) {
let { id, model } = data;
},
remove(data) {
let { id, model } = data;
}
};
let object = {
create(data) {
let { id, type } = data;
cache[id] = { id, type };
},
destroy(data) {
delete cache[data.id];
},
move(data) {
2022-01-02 16:30:05 -05:00
let { id, x, y, z } = data;
},
position(data) {
2022-01-02 16:30:05 -05:00
let { id, x, y, z } = data;
},
rotate(data) {
2022-01-02 16:30:05 -05:00
let { id, x, y, z } = data;
},
rotation(data) {
2022-01-02 16:30:05 -05:00
let { id, x, y, z } = data;
},
qrotation(data) {
2022-01-02 16:30:05 -05:00
let { id, w, x, y, z } = data;
}
};
worker.bind("debug", (data, send) => {
console.log({work_cache: cache});
});
worker.bindObject({
model,
group,
object
2021-12-31 22:11:20 -05:00
});
worker.ready();
2021-12-27 18:13:11 -05:00
})();