najadojo / gltf-import-export

Convert between GLB and GLTF files.
MIT License
204 stars 31 forks source link

Preserve MIME type for unknown extensions during import #18

Closed emackey closed 2 years ago

emackey commented 2 years ago

Hi @najadojo, hope you're doing well! Here's a suggestion from @rawnsley and Mozilla Hubs.

During GLB to GLTF conversion, it might be good to preserve the mimeType field, at least for types that are unknown to the guessFileExtension function. This would enable RGBE environment maps that Hubs has an extension for. Even if these files got a .bin extension, they would have a MIME type applied.

via https://github.com/AnalyticalGraphicsInc/gltf-vscode/issues/243

najadojo commented 2 years ago

@rawnsley do you have a sample file I could use to test this out? If not I can hack something up quickly enough.

rawnsley commented 2 years ago

Thanks for looking into this @najadojo. This GLB file is a complete Hubs scene file with a mix of extensions as described in the original issue. You can see the scene itself live here: https://hubs.mozilla.com/scenes/HQLCKaM/gltf-test-scene

najadojo commented 2 years ago

@rawnsley and @emackey I've merged a change and published the npm package that addresses this. Here is a section of the sample gltf after conversion:

{
  "images": [
    {
      "name": "skybox",
      "uri": "hubs-scene-sample-dw0.1.0_img0.png"
    },
    {
      "name": "envmap-category",
      "mimeType": "image/vnd.radiance",
      "uri": "hubs-scene-sample-dw0.1.0_img1.bin"
    },
    {
      "name": "lightmap",
      "mimeType": "image/vnd.radiance",
      "uri": "hubs-scene-sample-dw0.1.0_img2.bin"
    },
    {
      "name": "WoodFloor040_4K_Color",
      "uri": "hubs-scene-sample-dw0.1.0_img3.ktx2"
    }
  ],
  "buffers": [
    {
      "uri": "hubs-scene-sample-dw0.1.0_data.bin",
      "byteLength": 33384
    }
  ]
}
emackey commented 2 years ago

Wow that was fast, thanks!

rawnsley commented 2 years ago

🤯