2021-12-27 16:24:39 -05:00
|
|
|
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
|
|
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
2021-12-29 16:49:15 -05:00
|
|
|
// start worker pool (disabled for now with *0)
|
|
|
|
|
moto.client.start(`/code/mesh_pool?${gapp.version}`, moto.client.max() * 0);
|
2021-12-29 00:19:22 -05:00
|
|
|
|
2021-12-29 16:49:15 -05:00
|
|
|
// 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-29 16:49:15 -05:00
|
|
|
]);
|
2021-12-27 18:13:11 -05:00
|
|
|
|
2021-12-31 22:11:20 -05:00
|
|
|
// compensation for space/world/platform rotation
|
|
|
|
|
let space_rotation = new THREE.Matrix4().makeRotationX(Math.PI / 2);
|
|
|
|
|
|
2022-01-02 00:40:43 -05:00
|
|
|
let { client, worker } = moto;
|
2022-01-01 22:39:49 -05:00
|
|
|
let cache = {};
|
|
|
|
|
|
2022-01-02 00:40:43 -05:00
|
|
|
worker.bind("debug", (data, send) => {
|
|
|
|
|
console.log({cache});
|
|
|
|
|
send.done();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
worker.bind("model_load", (data, send) => {
|
|
|
|
|
let { vertices, name, id } = data;
|
2021-12-31 22:11:20 -05:00
|
|
|
let geo = new THREE.BufferGeometry();
|
|
|
|
|
geo.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
|
2022-01-02 00:40:43 -05:00
|
|
|
geo.computeVertexNormals();
|
|
|
|
|
cache[id] = { id, name, geo };
|
|
|
|
|
send.done();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
worker.bind("model_remove", (data, send) => {
|
|
|
|
|
delete cache[data.id];
|
|
|
|
|
send.done();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
worker.bind("model_sync", (data, send) => {
|
|
|
|
|
let { matrix, id } = data;
|
|
|
|
|
let rec = cache[id];
|
|
|
|
|
let geo = rec.geo.clone();
|
2021-12-31 22:11:20 -05:00
|
|
|
let m4 = space_rotation.clone().multiply( new THREE.Matrix4().fromArray(matrix) );
|
|
|
|
|
geo.applyMatrix4(m4);
|
2022-01-01 00:04:35 -05:00
|
|
|
// for debugging matrix ops
|
2021-12-31 22:11:20 -05:00
|
|
|
send.done(geo.attributes.position.array);
|
|
|
|
|
});
|
|
|
|
|
|
2021-12-27 18:13:11 -05:00
|
|
|
})();
|