Skip to content

Instantly share code, notes, and snippets.

@cdriesler
Created January 5, 2020 02:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdriesler/93ef642a12f63b6c39876b1d782caed2 to your computer and use it in GitHub Desktop.
Save cdriesler/93ef642a12f63b6c39876b1d782caed2 to your computer and use it in GitHub Desktop.
Run rhino3dm.js 'synchronously'
import Rhino3dm, { RhinoModule } from 'rhino3dm';
let rhinoModule:RhinoModule = undefined;
const wasmHandler: ProxyHandler<any> = {
apply: (target: any, thisArg: any, argArray?: any) => {
console.log('from proxy');
if (rhinoModule == undefined) {
Rhino3dm().then(rhino => {
console.log('rhino wasm not initialized');
rhinoModule = rhino;
return target(argArray[0], argArray[1]);
});
}
else {
return target(argArray[0], argArray[1]);
}
}
}
export default class RhinoService {
public static doSomething = new Proxy(RhinoService.doSomethingProxy, wasmHandler);
private static doSomethingProxy(): void {
console.log('from fct');
const r = rhinoModule;
const pointList = new r.Point3dList(0);
pointList.add(1, 2, 3);
pointList.add(2, 3, 4);
console.log(pointList.count);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment