Need a Rhino3dm package that can be used directly in Unity WASM

Sorry I only saw it now.

The whole process looks complicated, but in fact each step is very simple, so simple that I feel that if you tell me how to compile your WASM package, I can compile a package that can be used by Unity.

I have implemented calling your WASM package in Unity.

The following figure is the directory structure after Unity is compiled into a WebGL package

The Hashcode method is implemented, and the purpose is to pass its return value as an ID to Unity. Unity does not save anything in essence, but only saves an ID, which is used as the basis for the communication between JS code and Unity code

The following figure is the JS interoperability mechanism provided by Unity, all I did is to convert the Rhino cross-platform method call into a call to the WASM package you provided.

The one that looks more complicated is HEAP32[from >> 2] , related resources are: WebGL:与浏览器脚本交互 - Unity 手册

The following figure is the code of the package that calls Rhino3dm in Unity

The following picture is more critical. I modified the source code of Rhino3dm appropriately so that it no longer calls the UnsafeNativeMethods.ON_LineCurve_New method, but instead calls the ON_LineCurve_New3 method, which will be translated by Unity into the JS interop method I just mentioned.

Without very complicated theoretical knowledge, the ultimate goal is to use Unity’s cross-platform mechanism to convert Rhino method calls into calls to the Rhino3dm WASM package, which is far less difficult than compiling the WASM package.

I understand that what you need to do is, according to the content of GitHub - Unity-Technologies/NativeRenderingPlugin: C++ Rendering Plugin example for Unity, compile your project source code compiled into a WASM package in the form of this link, you will get dll or lib file, this lib file can be used directly for Unity

1 Like