complete es module wrappers
update manifold to current npm update csg to use new manifold remove manifold npm pre install download from static
This commit is contained in:
parent
b4ad2bef61
commit
e26e57e193
7 changed files with 63 additions and 52 deletions
43
app.js
43
app.js
|
|
@ -58,10 +58,15 @@ netdb.create = async function(map = {}) {
|
|||
return client;
|
||||
};
|
||||
|
||||
function wrapdata(path, buf) {
|
||||
// experimental wrapping of esm modules using embedded data urls
|
||||
function wrap_module(buf, as) {
|
||||
const base64 = buf.toString('base64');
|
||||
const path = as.split('.');
|
||||
const exp = path.pop();
|
||||
return [
|
||||
`gapp.register("${path}", [], (root, exports) => {`,
|
||||
buf.toString(),
|
||||
`gapp.register("${path.join('.')}", [], (root, exports) => {`,
|
||||
`const url = "data:text/javascript;base64,${base64}";`,
|
||||
`exports({ ["${exp}"]: import(url) });`,
|
||||
"});"
|
||||
].join('\n');
|
||||
}
|
||||
|
|
@ -98,7 +103,7 @@ function init(mod) {
|
|||
const callstack = [];
|
||||
let xxxx = false;
|
||||
|
||||
function find_refs(cache, path) {
|
||||
function find_refs(cache, path, ismod) {
|
||||
let rec = refcache[path];
|
||||
if (rec) {
|
||||
let crec = cache[path];
|
||||
|
|
@ -121,6 +126,11 @@ function init(mod) {
|
|||
console.log({missing: full, callstack});
|
||||
throw e;
|
||||
}
|
||||
// skip interrogating file if it's a module (external compacted)
|
||||
if (ismod) {
|
||||
wrap[`src/${path}.js`] = path.replaceAll('/','.');
|
||||
return;
|
||||
}
|
||||
let lines = fs.readFileSync(full)
|
||||
.toString()
|
||||
.split('\n');
|
||||
|
|
@ -136,6 +146,11 @@ function init(mod) {
|
|||
arr = rec.deps;
|
||||
pos = dpos + 7;
|
||||
}
|
||||
let mpos = line.indexOf('// mod:');
|
||||
if (mpos >= 0) {
|
||||
arr = rec.deps;
|
||||
pos = mpos + 7;
|
||||
}
|
||||
if (upos >= 0 && dpos >= 0) {
|
||||
console.log(`invalid line: ${line}`);
|
||||
process.exit();
|
||||
|
|
@ -143,7 +158,7 @@ function init(mod) {
|
|||
if (arr && pos >= 0) {
|
||||
let path = line.substring(pos).trim().replace(/\./g,'/').trim();
|
||||
addonce(arr, path);
|
||||
find_refs(cache, path);
|
||||
find_refs(cache, path, mpos >= 0);
|
||||
}
|
||||
}
|
||||
// if (xxxx) console.log({path, ...rec});
|
||||
|
|
@ -163,7 +178,7 @@ function init(mod) {
|
|||
return i;
|
||||
}
|
||||
}
|
||||
console.log(`not found: ${path}`);
|
||||
console.trace(`not found: ${path}`);
|
||||
process.exit();
|
||||
}
|
||||
|
||||
|
|
@ -227,7 +242,7 @@ function init(mod) {
|
|||
}
|
||||
find_refs(cache, path);
|
||||
}
|
||||
if (xxxx) console.log({processing: key, val});
|
||||
if (xxxx) console.log({ processing: key, val });
|
||||
let refs = order_refs(cache).filter(p => roots.indexOf(p) < 0);
|
||||
// remove paths that are in refs
|
||||
let paths = list.filter(p => {
|
||||
|
|
@ -246,8 +261,9 @@ function init(mod) {
|
|||
let fc = p.charAt(0);
|
||||
if (fc === '@') return p;
|
||||
if (fc === '#') {
|
||||
let nupath = `src/${p.substring(1)}.js`;
|
||||
wrap[nupath] = true;
|
||||
fc = p.split('#');
|
||||
let nupath = `src/${fc[1]}.js`;
|
||||
wrap[nupath] = fc[1].replaceAll('/','.');
|
||||
return nupath;
|
||||
}
|
||||
return `src/${p}.js`;
|
||||
|
|
@ -295,10 +311,10 @@ function init(mod) {
|
|||
mod.add((req, res, next) => {
|
||||
const path = req.gs.path.substring(1);
|
||||
if (wrap[path]) {
|
||||
const data = getCachedFile(path, data => {
|
||||
console.log({ do_not_min: data });
|
||||
return data;
|
||||
const data = getCachedFile(path, file => {
|
||||
return fs.readFileSync(file);
|
||||
});
|
||||
res.setHeader('Content-Type', 'application/javascript; charset=UTF-8');
|
||||
return res.end(data);
|
||||
}
|
||||
next();
|
||||
|
|
@ -459,6 +475,7 @@ const script = {
|
|||
"&kiri/lang-en"
|
||||
],
|
||||
kiri_work : [
|
||||
// "#ext/manifold2",
|
||||
"kiri-run/worker",
|
||||
"&main/kiri",
|
||||
],
|
||||
|
|
@ -757,7 +774,7 @@ function getCachedFile(file, fn) {
|
|||
}
|
||||
|
||||
if (wrap[file]) {
|
||||
cacheData = wrapdata(file, cacheData);
|
||||
cacheData = wrap_module(cacheData, wrap[file]);
|
||||
}
|
||||
|
||||
cached = {
|
||||
|
|
|
|||
14
bin/build-upload
Executable file
14
bin/build-upload
Executable file
|
|
@ -0,0 +1,14 @@
|
|||
#!/bin/bash
|
||||
target=$1
|
||||
tag=${2:-latest}
|
||||
echo "build and release target=$target tag=$tag"
|
||||
[ -z "$target" ] && echo "missing target" && exit
|
||||
[ -z "$tag" ] && echo "missing tag" && exit
|
||||
rm -rf dist && npm run build-${target} && for i in dist/*{exe,dmg,AppImage}; do
|
||||
if [ -f "$i" ]; then
|
||||
bn=$(basename $i)
|
||||
gh release delete-asset ${tag} ${bn} -y
|
||||
gh release upload ${tag} ${i}
|
||||
fi
|
||||
done
|
||||
|
||||
|
|
@ -29,16 +29,6 @@ async function download(url, filePath) {
|
|||
async function main() {
|
||||
console.log('npm pre running');
|
||||
|
||||
await download(
|
||||
"https://static.grid.space/gapp/manifold.js",
|
||||
path.join("src", "ext", "manifold.js")
|
||||
);
|
||||
|
||||
await download(
|
||||
"https://static.grid.space/gapp/manifold.wasm",
|
||||
path.join("src", "wasm", "manifold.wasm")
|
||||
);
|
||||
|
||||
const links = fs.readFileSync("links.csv")
|
||||
.toString()
|
||||
.trim()
|
||||
|
|
@ -47,32 +37,14 @@ async function main() {
|
|||
.map(line => line.split(',').map(v => v.trim()));
|
||||
|
||||
if (os.platform() === 'win32')
|
||||
// convert links to the contents of the files/directories they reference
|
||||
for (let [link, target] of links) {
|
||||
const absoluteTarget = path.resolve(path.dirname(link), target);
|
||||
// console.log({ link, target, absoluteTarget });
|
||||
try {
|
||||
// Remove existing link if it exists
|
||||
// if (fs.existsSync(link)) {
|
||||
// console.log({ unlink: link });
|
||||
// fs.unlinkSync(link);
|
||||
// } else {
|
||||
// console.log('no file', link);
|
||||
// }
|
||||
|
||||
console.log({ win32_replace: link });
|
||||
await fs.remove(link).catch(error => console.log({ remove_error: error }));
|
||||
|
||||
// console.log({ copy: absoluteTarget, to: link });
|
||||
await fs.copy(absoluteTarget, link, { dereference: true }).catch(error => console.log({ copy_error: error }));
|
||||
|
||||
// const targetStats = fs.lstatSync(absoluteTarget);
|
||||
// let type = targetStats.isDirectory() ? 'junction' : 'file';
|
||||
|
||||
// // Create the symlink
|
||||
// console.log(`relink: ${link} as ${type}`);
|
||||
// fs.symlinkSync(absoluteTarget, link, type);
|
||||
} catch (err) {
|
||||
// console.error(`Error creating symlink: ${link} -> ${target}`, err);
|
||||
console.error(`Error creating symlink: ${link} -> ${absoluteTarget}`, err);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@
|
|||
"earcut": "^2.2.3",
|
||||
"express-useragent": "^1.0.13",
|
||||
"jszip": "^3.7.1",
|
||||
"manifold-3d": "^2.5.1",
|
||||
"moment": "^2.29.4",
|
||||
"serve-static": "^1.14.1",
|
||||
"three": "^0.147.0",
|
||||
|
|
|
|||
1
src/ext/manifold.js
Symbolic link
1
src/ext/manifold.js
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../../node_modules/manifold-3d/manifold.js
|
||||
|
|
@ -3,14 +3,13 @@
|
|||
"use strict";
|
||||
|
||||
// dep: geo.base
|
||||
// dep: ext.manifold
|
||||
// mod: ext.manifold
|
||||
gapp.register("geo.csg", [], (root, exports) => {
|
||||
|
||||
const { base } = root;
|
||||
const { base, ext } = root;
|
||||
const debug = true;
|
||||
|
||||
const CSG = {
|
||||
|
||||
// accepts 2 or more arguments with threejs vertex position arrays
|
||||
union() {
|
||||
return CSG.moduleOp('manifold.union', 'union', ...arguments);
|
||||
|
|
@ -33,7 +32,7 @@ const CSG = {
|
|||
if (args.length < 2) {
|
||||
throw "missing one or more meshes";
|
||||
}
|
||||
const result = Instance[op](...args);
|
||||
const result = Instance.Manifold[op](...args);
|
||||
const output = result.getMesh();
|
||||
const errors = [ ...args, result ].map(m => m.status().value);
|
||||
for (let m of [ ...args, result ]) {
|
||||
|
|
@ -46,7 +45,8 @@ const CSG = {
|
|||
},
|
||||
|
||||
toPositionArray(mesh) {
|
||||
let { vertPos, triVerts } = mesh;
|
||||
let { vertProperties, triVerts } = mesh;
|
||||
let vertPos = vertProperties;
|
||||
if (vertPos && triVerts) {
|
||||
const vertices = new Float32Array(triVerts.length * 3);
|
||||
for (let p=0, i=0, l=triVerts.length; i<l; i++) {
|
||||
|
|
@ -63,7 +63,7 @@ const CSG = {
|
|||
fromPositionArray(pos) {
|
||||
const { index, vertices } = indexVertices(pos);
|
||||
let mesh = new Instance.Mesh({
|
||||
vertPos: vertices.toFloat32(),
|
||||
vertProperties: vertices.toFloat32(),
|
||||
triVerts: index.toUint32()
|
||||
});
|
||||
return mesh;
|
||||
|
|
@ -108,10 +108,15 @@ function indexVertices(pos) {
|
|||
}
|
||||
|
||||
let Instance;
|
||||
Module().then(Module => {
|
||||
Module.setup();
|
||||
Instance = Module;
|
||||
|
||||
ext.manifold.then(mod => {
|
||||
mod.default({
|
||||
locateFile() { return "/wasm/manifold.wasm" }
|
||||
}).then(inst => {
|
||||
inst.setup();
|
||||
Instance = inst;
|
||||
CSG.Instance = () => { return Instance };
|
||||
});
|
||||
});
|
||||
|
||||
gapp.overlay(base, {
|
||||
|
|
|
|||
1
src/wasm/manifold.wasm
Symbolic link
1
src/wasm/manifold.wasm
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../../node_modules/manifold-3d/manifold.wasm
|
||||
Loading…
Reference in a new issue