model-viewer icon indicating copy to clipboard operation
model-viewer copied to clipboard

Support Blob and File as value types for backgroundImage and environmentImage

Open cdata opened this issue 6 years ago • 4 comments

Currently, we detect HDR images by their file extension. This is great if you only ever use URLs to specify the image, but it falls apart for drag/drop (such as with Ricardo's demo here) and other workflows where the file extension is obscured by URL.createObjectURL.

There are a few ways to address this that might be worth discussing. However, I would recommend that for the user's benefit we should transparently support Blob and File as valid values for backgroundImage and environmentImage. Both of these values should give us enough information to detect an HDR image (mime-type and filename, respectively). This will allow users to directly assign these properties and not worry about the finer details required to accomplish what they are trying to do.

cdata avatar Mar 03 '19 19:03 cdata

Note: a rough analog for this type of support is the srcObject property of the <video> element.

cdata avatar Mar 04 '19 16:03 cdata

Any updates on supporting blobs as envrontment/sky image?

trollcus avatar Dec 02 '20 14:12 trollcus

@trollcus It's still a good idea. Not a top priority at the moment. Any interest in contributing?

elalish avatar Dec 03 '20 16:12 elalish

Understand it's not a priority, and an old issue, but just ran into this as well while implementing drag-and-drop-some-environment-onto-a-viewer.

I also found the fun hack in the editor that makes it work there 😀 (appending #.hdr to URL.createObjectURL to trick the loader into accepting it as HDR file)

  • https://github.com/google/model-viewer/blob/1807c5eedf2b55e69f24dd0921fba8f53ecc2800/packages/space-opera/src/components/model_viewer_snippet/components/open_button.ts#L263C43-L265

but only for .hdr, not for .exr.

hybridherbst avatar Jan 02 '23 23:01 hybridherbst