draco icon indicating copy to clipboard operation
draco copied to clipboard

WebGL build support in Unity

Open TobiasMorell opened this issue 5 years ago • 15 comments

I'm very interested in the Draco Unity plugin and would like to use it in a project. Before starting I have a couple of questions:

  1. The project is meant to run in a browser, will I be able to use the Draco plugin for Unity for that or should I use the one for JavaScript?
  2. I'm running Ubuntu 16.04 and after importing the plugin and bunny.drc file, I'm getting a DllNotFoundException. The README.md file only mentions support for Windows, iOS and Android. Is it in any way possible to use the plugin on Ubuntu 16.04?

Thank you in advance for your help.

TobiasMorell avatar Jul 18 '18 06:07 TobiasMorell

I've done some more research and have been able to generate answers for my questions. I will post them here if anyone has similar needs:

  1. Unity is able to build for WebGL, however, when I'm opening the project I get an error stating:

uncaught exception: abort("To use dlopen, you need to use Emscripten's linking support, see https://github.com/kripken/emscripten/wiki/Linking")

I currently suspect this is an issue in Unity's build system and I have replied to a forum post about a similar issue and hope for aid there.

  1. You can compile the Draco plugin for the Unity3D beta for Ubuntu 16.04. I downloaded the source code and followed the compile instructions for Windows. After the compilation I copied the file libdracodec_unity.so into my Unity project in the folder Assets/Plugins.

I will leave the issue open until I have a definite answer for my first question,

TobiasMorell avatar Jul 19 '18 12:07 TobiasMorell

Hi @TobiasMorell Unfortunately we have not been able to get Unity to load a Draco plug-in in the browser as well. I will keep this open as an enhancement. Hopefully in the future we will figure out how to get this to work.

FrankGalligan avatar Aug 06 '18 17:08 FrankGalligan

@FrankGalligan thank you for your reply. I haven't had time to check it myself, but I was thinking that it might be possible to use the readymade JavaScript compilation instead. I will examine myself when I have some spare time and post my discoveries here.

If you want to check it out you can find more information about interfacing with browser scripting.

TobiasMorell avatar Aug 07 '18 08:08 TobiasMorell

Thanks @TobiasMorell

FrankGalligan avatar Aug 08 '18 21:08 FrankGalligan

Hi @FrankGalligan I spent some time this morning trying to add a JavaScript library. I tried to things, none of which were successful:

  1. Use the pre-built emscripten library. My problem here was that it does not work like the Unity plugin, i.e. it does not contain the function DecodeMeshForUnity.
  2. Build a JavaScript version of the plugin with Emscripten. I tried to mess around with the make-files, hoping that it would allow me to output a JavaScript-file instead of the .so file that it does now. I feel like this might be a decent solution, but my knowledge about CMake and Make is very limited. Would it be possible to add a make-target in the final step that compiles everything with Emscripten instead of gcc?

TobiasMorell avatar Aug 09 '18 07:08 TobiasMorell

@tomfinegan Can you help @TobiasMorell out with cmake?

FrankGalligan avatar Aug 10 '18 18:08 FrankGalligan

@TobiasMorell:

I'm assuming you already have the emsdk installed, and that an Emscripten build of Draco works for you in its standard form. In other words, this should already work:

$ cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=/path/to/Emscripten.cmake path/to/draco && make

Assuming the above is working, what happens if you run cmake and build Draco like this?

$ cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=/path/to/Emscripten.cmake -DBUILD_UNITY_PLUGIN=1 -DENABLE_JS_GLUE=0 && make

tomfinegan avatar Aug 10 '18 18:08 tomfinegan

@TobiasMorell

Note, the second step is likely not enough, but would be a starting point. Glue code and IDL are likely needed for DracoToUnityMesh, ReleaseUnityMesh(), and DecodeMeshForUnity(). I can look into hooking this up next week.

tomfinegan avatar Aug 10 '18 18:08 tomfinegan

Hi @tomfinegan. Thank you for your help.

Both commands ran to completion without any errors. However, it seems that the second command outputs both the libdracodec_unity.so file and the draco_encoder.js and draco_decoder.js. I was not able to find a js-version of the Unity-plugin after the build. Please let me know if there's anything I can do to help.

TobiasMorell avatar Aug 13 '18 06:08 TobiasMorell

Hi @tomfinegan. Have you had time to look into this issue?

TobiasMorell avatar Aug 30 '18 10:08 TobiasMorell

Only enough time to confirm that Draco needs IDL and wrapper code for the Draco Unity Plugin for this to progress further. I'm going to flip the assignment of this back to @FrankGalligan, at least for now, as I don't have time to investigate this more deeply at present.

tomfinegan avatar Aug 30 '18 21:08 tomfinegan

Hey guys, any updates about this? would like to contribute to this if any "direction" was given in how to complete this @FrankGalligan @tomfinegan

Rakiah avatar Mar 03 '19 19:03 Rakiah

My forked Unity package is a much improved version and works in WebGL as well: https://gitlab.com/atteneder/DracoUnity It's a shame my PR #540 goes unoticed for months now.

atteneder avatar Nov 18 '19 23:11 atteneder

I think I am running into this also, anyone have ideas?

XanNava avatar Dec 06 '19 07:12 XanNava

@tomfinegan have you had time to look at @atteneder's PR referenced above?

hybridherbst avatar Jan 02 '20 09:01 hybridherbst