alembic / alembic

Alembic is an open framework for storing and sharing scene data that includes a C++ library, a file format, and client plugins and applications.
http://alembic.io/
Other
1.06k stars 254 forks source link

Consider support for the Web Platform. #323

Open Mugen87 opened 3 years ago

Mugen87 commented 3 years ago

I'm investigating a possible implementation for an Alembic loader for three.js since it would be great to have the opportunity to quickly view .abc files in the three.js editor via drag'n'drop.

The idea is to use Alembic as a WebAssembly module with a JavaScript wrapper in the same way DRACO is used on the web platform.

Since I can compile Alembic on my mac without issues, I've tried the compilation to WebAssembly with Emscripten. Unfortunately, even after many attempts my build still fails with this error:

error: undefined symbol: _ZN9Imath_2_57srand48El (referenced by top-level compiled C/C++ code) warning: __ZN9Imath_2_57srand48El may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library Error: Aborting compilation due to previous errors

My C/C++ skills are only basic and I'm out of ideas where to start looking for a fix.

I was wondering now if the maintainers of Alembic could consider this issue as a feature request and provide WebAssembly/JavaScript build configurations within this project. The possibility of using Alembic on the Web Platform would enable many interesting use cases and scenarios. Not only for three.js^^.

lamiller0 commented 3 years ago

What version of Imath are you trying to use?

Mugen87 commented 3 years ago

It's 2.5.2.

lamiller0 commented 3 years ago

Hmmm, that should be recent enough. srand48 would normally come from stdlib.h, I wonder if its a configuration issue, that its not finding it there.

I'd be surprised if Imath was actually trying to define it. (but its always possible)

meshula commented 3 years ago

There's a Imath namespaced srand48, but it is adorned for external symbol visibility.

IMATH_EXPORT void       srand48 (long int seed);

It's defined in ImathRandom.cpp. There's no obvious reason for an Emscripten build to fail, but a likely cause is having more than one copy of Imath on your machine, i.e. compiled with one set of headers, but linked versus a different version of the library.

Mugen87 commented 3 years ago

but a likely cause is having more than one copy of Imath on your machine

Would having more than one copy of Imath also break the "normal" build of Alembic (without Emscripten)?

In my CMakeCache.txt file for the Emscripten build, I'm using the same paths for targeting Imath like the normal build.

//Path to a library.
ALEMBIC_ILMBASE_IMATH_LIB:FILEPATH=/usr/local/lib/libImath-2_5.dylib

//Path to a file.
ILMBASE_INCLUDE_DIR:PATH=/usr/local/include/OpenEXR

//Version of OpenEXR lib
ILMBASE_VERSION:STRING=2.5.2
meshula commented 3 years ago

I see, mismatched versions are probably not the issue then.

Mugen87 commented 3 years ago

Quick update on this: It is possible to generate more detailed warnings by adding -s LLD_REPORT_UNDEFINED to the CMake settings. However, even with more logging I was not able to solve the linking issues.

For testing purposes, I have added the following to my setting to force a completion of the build.

set(CMAKE_EXE_LINKER_FLAGS "-s ERROR_ON_UNDEFINED_SYMBOLS=0")

This just disables errors for undefined symbols. But I was not able to use the resulting combination of WASM and JS files in the browser. E.g. it's possible to load abcecho into a website but you immediately get warnings in the browser console.

abcecho.js:2066 USAGE: ./this.program program exited (with status: -1), but EXIT_RUNTIME is not set, so halting execution but not exiting the runtime or preventing further async execution (build with EXIT_RUNTIME=1, if you want a true shutdown)

At this point, I'm not sure how to execute abcecho correctly in the browser since I was not able to call main from the JS interface. I'll attach the WASM and JS file for abcecho here: abcecho.zip

I've also noticed that a build target like alembic.wasm/alembic.js would be required that bundles the entire core into a single file. I don't know if it's possible to produce such an artifact with special Emscripten settings or if the build in general needs an update. However, such bundles are produced in other projects e.g. ammo.js which is a JS port of the Bullet Physics Engine.

Unfortunately, I have no time anymore to tackle this issue since I have to focus on work that I can actually finish. But I hope somebody else with more skills in this area can jump in^^. It would be great to have Alembic on the web.

chrisnovello commented 3 years ago

+1 / following in case anyone takes helm. Beyond scope of my ability at the moment, but it would be amazing to get vertex cache animations on the web and in other wasm applications !

lamiller0 commented 3 years ago

Has anyone tried out master recently?

It includes this: https://github.com/alembic/alembic/pull/332

and support for Imath 3 (to be released hopefully April 1st)

Which should hopefully help with emscripten support.

walton007 commented 2 years ago

any update?

mrdoob commented 2 years ago

Seem like USD is the way to go these days? https://autodesk-forks.github.io/USD/

lamiller0 commented 2 years ago

We added Imath 3 support, I'm not sure if anyone tried rebuilding it for a web platform again.