I'd like to implement this code using nim. The expected result is here -it takes some time because it loads OpenCascade.js which is very heavy-.
I tried to do it here. I managed to compile the file index.nim using:
nim js -d:nimExperimentalAsyncjsThen index
I also had to comment these lines: this and this, to avoid some complain about export. I also commented many lines here (stuff not needed for this example and the import lines).
I don't see any error message in the browser's Console, but it is not working the replacement for index.js that I am trying to create.
I managed to wrap a basic example using threejs that I left here: threejs.nim, but I am struggling to do something similar in this case.
Perhaps I am misunderstanding how you are running this, but you do not load your compiled index.js file inside your index.html.
Once you add that you'll see a bunch of errors about things being undefined, because you removed the imports in library.js. You can fix some of these by changing e.g. new Scene() to new THREE.Scene() (The threejs script adds a global THREE that you can access).
After that there are other errors with imports, for example OrbitControls. You do not include this code so it is undefined (and threejs does not bundle it automatically, so you will need to include it yourself). The example you copied from probably uses webpack or similar to bundle all this code
After many tries I think I am closer now, but not done. I am getting the following error message in the console:
Uncaught (in promise) TypeError: opencascade_469762091.makePolygon is not a function
at HEX3Aanonymous_469762090 (index.js:107:72)
It is referring to L107.
The original line would be here.
I think I am messing things up here with the async, await, then, ... which I am not familiar with.
Any advise?
makePolygon is defined as a js function:
const makePolygon = (openCascade) => { ... }
But the generated javascript calls opencascade_469762091.makePolygon(), when it needs to be makePolygon(opencascade_469762091) (JS does not have UFCS like Nim)
So you need to wrap the function in one of these ways:
proc makePolygon*(openCascade: JsObject): TopoDS_Compound {.importc.}
proc makePolygon*(openCascade: JsObject): TopoDS_Compound {.importcpp: "makePolygon(#)".}
proc makePolygon*(openCascade: JsObject): TopoDS_Compound {.importjs: "makePolygon(#)".}