playcanvas / supersplat

3D Gaussian Splat Editor
https://playcanvas.com/supersplat/editor
MIT License
1.28k stars 120 forks source link

[Feature Request] Implement File System API #98

Closed CiberNin closed 3 months ago

CiberNin commented 4 months ago

image

https://developer.mozilla.org/en-US/docs/Web/API/File_System_API

Will need to keep track of file handle to save to. Starts out null, then gets remembered on first open. Need to grey out save options before first open since we won't have a handle yet. On save-as need to overwrite file handle with new one in case it changed and also remember file type.

Also need to handle when used a PWA default file handler.

Loading file example:

const pickerOpts = {
  types: [
    {
      description: "Images",
      accept: {
        "image/*": [".png", ".gif", ".jpeg", ".jpg"],
      },
    },
  ],
  excludeAcceptAllOption: true,
  multiple: false,
};

async function getTheFile() {
  // Open file picker and destructure the result the first handle
  const [fileHandle] = await window.showOpenFilePicker(pickerOpts);

  // get file contents
  const fileData = await fileHandle.getFile();
}

Saving file example:

async function saveFile() {
  // create a new handle
  const newHandle = await window.showSaveFilePicker();

  // create a FileSystemWritableFileStream to write to
  const writableStream = await newHandle.createWritable();

  // write our file
  await writableStream.write(imgBlob);

  // close the file and write the contents to disk.
  await writableStream.close();
}
slimbuck commented 4 months ago

Hi @CiberNin ,

This is great timing. We're busy planning our next round of updates to supersplat and among other things would like to support for offline mode and file system handling. (And also the ability to combine multiple splats).

So thanks very much for this!

slimbuck commented 3 months ago

This was done in #105 and is now deployed.