Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using filament.wasm / NPM module as a Node.js dependency #2647

Closed
sleroux opened this issue Jun 5, 2020 · 9 comments
Closed

Using filament.wasm / NPM module as a Node.js dependency #2647

sleroux opened this issue Jun 5, 2020 · 9 comments

Comments

@sleroux
Copy link

sleroux commented Jun 5, 2020

I've been browsing through the web target for Filament which looks to be for browsers only and was wondering if it was possible to get it running alongside a Node.js application. I figured there's a couple of node/browser polyfills that would be to be involved for fetch and canvas but not sure if there might be something in the prebuilt WASM files that would cause problems. Out of the box the NPM module doesn't work as the Filament global that is defined doesn't get exposed on window like it does on the browser so there's that to contend with.

@prideout
Copy link
Contributor

prideout commented Jun 5, 2020

Correct, our JavaScript and TypeScript API's are designed for Browsers, not nodejs.

I don't know much about nodejs but maybe you could just build a nodejs addon yourself, link against the core Filament library, and use our first-class C++ API.

@prideout prideout closed this as completed Jun 5, 2020
@romainguy
Copy link
Collaborator

Actually I'm curious, what would be the render target in such an environment? I.e. what's the h
replacement for canvas?

@prideout
Copy link
Contributor

prideout commented Jun 5, 2020

I'm curious too. If you're writing an Electron app, maybe your usage of filament could live in the Renderer process rather than the Main process, in which case you could simply use our JS API, right?

@sleroux
Copy link
Author

sleroux commented Jun 5, 2020

Actually I'm curious, what would be the render target in such an environment? I.e. what's the h
replacement for canvas?

I was thinking of using node-canvas which uses Cairo. I'm imagining running this on a virtualized Linux box so it'll probably use X window as it's target through Cairo.

As an example of something similar, I wrote a small screenshotting tool that spins up an instance of headless chrome, tosses in a element, and produces a render from a browser context but using something like Filament seems more direct without having to load up Chrome. The end goal is to be able to produce 3D renders on a GPU-less docker image hosted somewhere.

I could always end up just using the C++ API directly instead of going through this rigmarole of getting it working throw a 'web' context but was curious if it was possible.

@romainguy
Copy link
Collaborator

What I'm worried about is whether the whole GL initialization can succeed. Cairo is a 2D renderer and I have no idea if going through it would allow Filament to take over the surface with a 3D context.

@sleroux
Copy link
Author

sleroux commented Jun 5, 2020

Good point. I took a peek at node-canvas and it looks like it only supports the 2d context. You could possibly add support for a webgl context by shimming in one of the node-webgl libraries like https://github.com/stackgl/headless-gl but then it kinda feels like you're going down this rabbit hole of web shims on top of native APIs.

I still wonder what the possibilities are for using the WASM bundle that can be built for Filament in different contexts. With new WASM runtimes like Lucet one could imagine an intersection of rendering and edge computing.

In any case, thanks for the quick responses and insightful conversation on this!

@donmccurdy
Copy link

I think headless-gl is typically what people use when going this direction... I've tested "swapping in" a headless-gl instance with other renderers (http://regl.party/) and it just worked. From the docs, "It is built on top of ANGLE and passes the full Khronos ARB conformance suite, which means it works exactly the same on all supported systems."

@prideout
Copy link
Contributor

stackgl/headless-gl is a WebGL 1.0 impl, Filament requires 2.0.

@donmccurdy
Copy link

Hm, good point. Following the comment threads a bit further, it doesn't look like they've made much progress on WebGL 2 (stackgl/headless-gl#109). Perhaps https://github.com/google/node-gles then, if/when it becomes stable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants