Opening local model files from electron

I’m writing an electron app for viewing local obj and stl files. Currently I’m having the trouble where file:/// files aren’t allowed. I’ve looked over the local files documentation but it doesn’t really answer what I’m hoping to do.

My goal -

  • allow the user to click a button (easy enough)
  • pick a file on their computer anywhere (easy enough)
  • add that model to a scene so that the user can view it. (here’s the real question)

I’m looking at using IPC to send that file contents as a blob to the renderer, but is there no better way? And if this is the best way :slight_smile: does anyone have a quick code example where they’ve done the same?

It’s not really viable for me to http serve the files because they could be anywhere on the drive.

Have you already tried the approach explained in this video?

Hey, thanks for the response. This is similar to what I’m thinking about doing, using IPC to pass the file contents as a Blob. But how do you then open it in three.js?

Well, since you essentially writing a node application, you have to ensure that the Blob is interpreter as ASCII text in order to use OBJLoader. You can then use the loader like so:

const loader = new OBJLoader();
const result = loader.parse( text );

Keep in mind that loaders have sometimes dependencies to Web APIs and thus not work in a node environment. That means you probably have to adjust the loader or implement polyfills.

That’s why I was asking if anyone had done it in electron. Looking for someone who has passed a file over ipc and opened it on the three.js in the frontend. If not I can keep fighting through it and testing (in the end i want to open multiple types so that should be fun)