add client/worker sync test
This commit is contained in:
parent
ab48fae65a
commit
650a9b4d68
2 changed files with 31 additions and 0 deletions
|
|
@ -52,6 +52,20 @@ mesh.model = class MeshModel extends mesh.object {
|
||||||
return this.mesh;
|
return this.mesh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sync() {
|
||||||
|
moto.client.fn.model_sync({
|
||||||
|
vertices: this.mesh.geometry.attributes.position.array,
|
||||||
|
matrix: this.mesh.matrixWorld.elements
|
||||||
|
}).then(data => {
|
||||||
|
console.log({data: data[0]});
|
||||||
|
// mesh.api.group.new([new mesh.model({
|
||||||
|
// file: "synth",
|
||||||
|
// mesh: data[0]
|
||||||
|
// })]);
|
||||||
|
this.load(data[0]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
load(vertices, indices) {
|
load(vertices, indices) {
|
||||||
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));
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,23 @@ gapp.finalize("mesh.work", [
|
||||||
"moto.client", // dep: moto.client
|
"moto.client", // dep: moto.client
|
||||||
"moto.worker", // dep: moto.worker
|
"moto.worker", // dep: moto.worker
|
||||||
"mesh.tool", // dep: mesh.tool
|
"mesh.tool", // dep: mesh.tool
|
||||||
|
"add.three", // dep: add.three
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// compensation for space/world/platform rotation
|
||||||
|
let space_rotation = new THREE.Matrix4().makeRotationX(Math.PI / 2);
|
||||||
|
|
||||||
|
moto.worker.bind("model_sync", (data, send) => {
|
||||||
|
let { vertices, matrix } = data;
|
||||||
|
console.log('model_sync', {vertices, matrix, send});
|
||||||
|
let geo = new THREE.BufferGeometry();
|
||||||
|
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) );
|
||||||
|
geo.applyMatrix4(m4);
|
||||||
|
send.done(geo.attributes.position.array);
|
||||||
|
});
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue