Best way to send data from node addon to ThreeJs


#1

I’m creating a 3D application which uses a node addon written in C++ to generate 3D objects (vertices, normals, indices etc) which I need to pass down to my electron renderer which contains a webGL window (I’m using Three.js)

What is the most efficient way to transmit my large data arrays (My 3D objects contain many polygons) from C++ (Node addon) to the renderer front end in electron? Ideally I would love it if I could allocate some heap memory in C++ and have it accessible from the renderer thread to create the Three.Js objects. Is that possible?

Right now I’m allocating buffers in C++, passing them down to Node’s (main thread) via v8, and then using MainWindow.webContents to send this data to the electron’s render thread which can then create my Three.js objects for rendering in webGL. This seems inefficient so I hope there is a better way.


#2

I understand your challenge :slight_smile: (in fact, one feature of my project also faced the same issue but I do not involve directly to this part currently).

However, I don’t think we can allocate the HEAP in main process, and read it in renderer process which you use three.js since they are totally different processes. which basically, HEAP memory is belong to the allocated process.

What could be useful for you probably to research if there are the better IPC modules which give you better performance than built-in Electron’s ipc.