简体   繁体   English

我可以在 node.js(服务器端)中运行 A-Frame 吗?

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

I'd like to take a lot of screenshots and export.glb from thousands of generated a-frame models.我想从数千个生成的 a-frame 模型中截取大量屏幕截图和 export.glb。 Since I can't save files from the browser without prompt, generating the models on the server-side with node.js would be awesome.由于我无法在没有提示的情况下从浏览器保存文件,因此使用 node.js 在服务器端生成模型会很棒。

(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?那么,如何在 node.js 中渲染 A-Frame 模型?

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.尝试使用模拟浏览器mocking DOM( three中是必需的,更不用说基于 DOM 的a-frame )和headless-gl用于在 node.js 中创建 WebGL 上下文。

What I did, that resembles what you're looking for, is an electron application.我所做的,类似于您正在寻找的,是一个electron应用程序。

tldr: check this out . tldr:看看这个 Download, npm install; npm run start;下载, npm install; npm run start; npm install; npm run start; and render screenshots / export the scene as glb.并渲染屏幕截图/将场景导出为 glb。 If you like it, let me know how to improve it to make it more useful.如果您喜欢它,请告诉我如何改进它以使其更有用。


non tldr: 非 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.您可以使用 electron 加载a-frame网站,但使用主进程将屏幕截图保存在驱动器上 - 因此没有提示,并且可以自动化。

To make a render, You can simply use the nativescreenshot component to create a canvas containing the screenshot image要进行渲染,您可以简单地使用原生截图组件创建一个包含截图图像的 canvas

 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.但不是下载 blob,而是通过渲染器将其传递到主进程到主 IPC 通道- 您可以将其保存在驱动器上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM