loading occ wasm from npm package

This commit is contained in:
Val Erastov 2022-06-05 22:32:25 -07:00
parent 0f0862f8ee
commit 9fc5ec7bee
8 changed files with 16413 additions and 220 deletions

16551
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -3,7 +3,7 @@
"version": "0.1.0",
"description": "JS.Sketcher is a parametric 2D and 3D CAD modeler written in pure javascript",
"scripts": {
"start": "node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js --config webpack.config.js --content-base web/ --port 3000 --host 0.0.0.0",
"start": "node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js --config webpack.config.js --port 3000 --host 0.0.0.0",
"pack": "node ./node_modules/webpack/bin/webpack.js --config webpack.config.js --progress --profile --colors",
"build": "grunt",
"lint": "eslint web/app",
@ -83,6 +83,7 @@
"react-icons": "^4.2.0",
"react-toastify": "^5.5.0",
"sprintf": "0.1.5",
"three": "^0.118.3"
"three": "^0.118.3",
"jsketcher-occ-engine": "1.0.0"
}
}

View file

@ -3,7 +3,6 @@ import {CraftEngine} from "./craftEngine";
import {createOCCService, OCCService} from "cad/craft/e0/occService";
declare module 'context' {
interface CoreContext {
occService: OCCService;
@ -23,17 +22,10 @@ export function activate(ctx) {
ctx.occService = createOCCService(ctx);
}
async function instantiateEngine(importObject, callback) {
const url = './wasm/e0/main.wasm.gz';
const buffer = pako.ungzip(await(await fetch(url)).arrayBuffer());
function instantiateEngine(importObject, callback) {
const url = './main.wasm';
// A fetched response might be decompressed twice on Firefox.
// See https://bugzilla.mozilla.org/show_bug.cgi?id=610679
if (buffer[0] === 0x1f && buffer[1] === 0x8b) {
buffer = ungzip(buffer);
}
const result = await WebAssembly.instantiate(buffer, importObject).then(results => {
WebAssembly.instantiateStreaming(fetch(url), importObject).then(results => {
callback(results.instance);
});
}
@ -56,7 +48,7 @@ function loadWasm(ctx) {
} as any;
let mainScript = document.createElement('script');
mainScript.setAttribute('src', './wasm/e0/main.js');
mainScript.setAttribute('src', './main.js');
mainScript.setAttribute('async', 'async');
document.head.appendChild(mainScript);
}

View file

@ -1,9 +1,6 @@
<html>
<head>
<title>Web CAD / Part Designer</title>
<script src="./lib/pako.min.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Condensed:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext">
<link rel="stylesheet" href="lib/font-awesome/css/font-awesome.min.css?modeler">

2
web/lib/pako.min.js vendored

File diff suppressed because one or more lines are too long

View file

@ -1,50 +0,0 @@
<style>
textarea {
width: calc(50% - 10px);
height: calc(100% - 50px);
}
</style>
<h3>TCL to JSketcher OCC API converter</h3>
<textarea id="tclIn" oninput="convertIt();"></textarea>
<textarea id="jsOut"></textarea>
<script>
async function convertIt() {
var lines = document.getElementById("tclIn").value.split('\n');
const out = document.getElementById("jsOut");
out.value = "";
for (var i = 0; i < lines.length; i++) {
out.value += await words(lines[i]) + '\n';
}
//alert("done");
}
async function words(inputLine) {
inputLine = inputLine.trim();
if (inputLine == "") return "";
var words = inputLine.trim().split(" ")
if (words[0].startsWith("#")) return "//" + inputLine;
var returnLine = "oci." + words[0];
returnLine += "(";
for (var i = 1; i < words.length; i++) {
//eliminate trailing commas.
if (words[i].trim() !== "") {
if (i == words.length - 1) {
returnLine += `"` + words[i] + `"`;
} else {
returnLine += `"` + words[i] + `",`;
}
}
}
returnLine += ");";
//console.log(returnLine);
return returnLine
}
</script>

View file

@ -34,7 +34,11 @@ module.exports = {
},
devServer: {
hot: false,
inline: false
inline: false,
contentBase: [
path.join(__dirname, 'web'),
path.join(__dirname, 'node_modules/jsketcher-occ-engine')
]
},
module: {
rules: [