Can I run A-Frame in node.js (server-side)?

Viewed 46

I'd like to take a lot of screenshots and export .glb from thousands of generated a-frame models. Since I can't save files from the browser without prompt, generating the models on the server-side with node.js would be awesome.

(As a workaround I could probably generate the models in the browser and POST them to a local server that saves the files to disk but I'd prefer the server-side rendering if possible)

So, how can I render A-Frame models in node.js?

1 Answers

Tried approaches like this with mock-browser for mocking the DOM (which is necessary in three, let alone DOM-based a-frame) and headless-gl for creating a WebGL context in node.

No luck there, so I settled with an electron application.

tldr: check this out. Download, npm install; npm run start; and render screenshots / export the scene as glb. If you like it, let me know how to improve it to make it more useful.


non tldr:

You can load up an a-frame website using electron, but use the main process to save the screenshot on your drive - so there are no prompts, and it can be automated.

To make a render, You can simply use the native screenshot component to create a canvas containing the screenshot image

document.querySelector('a-scene').components.screenshot.getCanvas('equirectangular');

but instead of downloading the blob, pass it into the main process via an renderer to main IPC channel - where you can save it on your drive.

Related