Created
January 5, 2020 02:02
-
-
Save cdriesler/93ef642a12f63b6c39876b1d782caed2 to your computer and use it in GitHub Desktop.
Run rhino3dm.js 'synchronously'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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