handle wasm files at other roots, preserve index on reload in mesh

This commit is contained in:
Stewart Allen 2022-10-22 11:02:02 -04:00
commit 376d9b2d67
4 changed files with 27 additions and 12 deletions

7
app.js
View file

@ -228,6 +228,7 @@ function init(mod) {
mod.add(handleSetup);
mod.add(handleOptions);
mod.add(handleWasm);
mod.add(fullpath({
"/kiri" : redir("/kiri/", 301),
"/mesh" : redir("/mesh/", 301),
@ -239,7 +240,7 @@ function init(mod) {
mod.add(handleVersion);
mod.add(prepath([
[ "/code/", handleCode ],
[ "/wasm/", handleWasm ]
// [ "/wasm/", handleWasm ]
]));
mod.add(fixedmap("/api/", api));
if (debug) {
@ -499,12 +500,12 @@ function handleOptions(req, res, next) {
}
function handleWasm(req, res, next) {
let [root, file] = req.app.path.split('/').slice(1);
let file = req.app.path.split('/').pop();
let ext = (file || '').split('.')[1];
let path = `${dir}/src/wasm/${file}`;
let mod = lastmod(path);
if (root === 'wasm' && ext === 'wasm' && mod) {
if (ext === 'wasm' && mod) {
let imd = ifModifiedDate(req);
if (imd && mod <= imd) {
res.writeHead(304, "Not Modified");

View file

@ -3,7 +3,9 @@
Full docs @ https://docs.grid.space/projects/kiri-moto
# Release 3.6
# Release 3.6 (2022-10-22)
## Kiri:Moto
* add new Carvera machine target in CAM mode with laser support
* add laser output operators and device settings in CAM mode
@ -26,7 +28,7 @@ Full docs @ https://docs.grid.space/projects/kiri-moto
# Release 3.5 (2022-10-07)
## Kiri:moto
## Kiri:Moto
* add optional service workers and manifest to support full PWA + install
* add support to run as Progressive Web Apps for installation and offline use
@ -56,7 +58,7 @@ Full docs @ https://docs.grid.space/projects/kiri-moto
# Release 3.4 (2022-05-14)
## Kiri:moto
## Kiri:Moto
* added batch processing to object adds/removes to speedup complex workspace restore
* substitute some prusa slicer [variables] with KM {variables} on import

View file

@ -156,6 +156,10 @@ AP.toFloat32 = function() {
return new Float32Array(this);
};
AP.toUint32 = function() {
return Uint32Array.from(this);
};
AP.forEachPair = function(fn, incr) {
let scope = this,
idx = 0,

View file

@ -121,25 +121,27 @@ mesh.model = class MeshModel extends mesh.object {
// override and translate mesh
move(x = 0, y = 0, z = 0) {
let arr = this.attributes.position.array;
let attr = this.attributes;
let arr = attr.position.array;
for (let i=0, l=arr.length; i<l; ) {
arr[i] = arr[i++] + x;
arr[i] = arr[i++] + y;
arr[i] = arr[i++] + z;
}
this.reload(arr);
this.reload(arr, attr.index ? attr.index.array : undefined);
return this;
}
// override and translate mesh
scale(x = 1, y = 1, z = 1) {
let arr = this.attributes.position.array;
let attr = this.attributes;
let arr = attr.position.array;
for (let i=0, l=arr.length; i<l; ) {
arr[i] = arr[i++] *= x;
arr[i] = arr[i++] *= y;
arr[i] = arr[i++] *= z;
}
this.reload(arr);
this.reload(arr, attr.index ? attr.index.array : undefined);
return this;
}
@ -198,7 +200,10 @@ mesh.model = class MeshModel extends mesh.object {
geo.setIndex(new BufferAttribute(indices, 1));
geo = geo.toNonIndexed();
}
if (!normals) geo.computeVertexNormals();
if (!normals) {
geo.computeVertexNormals();
}
let meh = this.mesh = new Mesh(geo, [
this.mats.normal,
this.mats.face
@ -217,11 +222,14 @@ mesh.model = class MeshModel extends mesh.object {
worker.model_load({id: this.id, name: this.file, vertices});
}
reload(vertices) {
reload(vertices, indices) {
let was = this.wireframe(false);
let geo = this.mesh.geometry;
geo.setAttribute('position', new BufferAttribute(vertices, 3));
geo.setAttribute('normal', undefined);
if (indices) {
geo.setIndex(new BufferAttribute(indices, 1));
}
// signal util.box3expand that geometry changed
geo._model_invalid = true;
geo.computeVertexNormals();