google / draco

Draco is a library for compressing and decompressing 3D geometric meshes and point clouds. It is intended to improve the storage and transmission of 3D graphics.
https://google.github.io/draco/
Apache License 2.0
6.43k stars 960 forks source link

WebGL build support in Unity #436

Open TobiasMorell opened 6 years ago

TobiasMorell commented 6 years ago

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 commented 6 years ago

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,

FrankGalligan commented 6 years ago

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.

TobiasMorell commented 6 years ago

@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.

FrankGalligan commented 6 years ago

Thanks @TobiasMorell

TobiasMorell commented 6 years ago

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?
FrankGalligan commented 6 years ago

@tomfinegan Can you help @TobiasMorell out with cmake?

tomfinegan commented 6 years ago

@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 commented 6 years ago

@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.

TobiasMorell commented 6 years ago

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 commented 5 years ago

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

tomfinegan commented 5 years ago

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.

Rakiah commented 5 years ago

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

atteneder commented 4 years ago

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.

XanNava commented 4 years ago

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

hybridherbst commented 4 years ago

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