Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Magnum to latest version that supports loading custom batch-optimized glTFs #1776

Merged
merged 1 commit into from
Jun 8, 2022

Conversation

mosra
Copy link
Collaborator

@mosra mosra commented Jun 8, 2022

Motivation and Context

Updates Magnum to current master, and while at it also update all copies of CMake Find modules from it (which I need for a local build that uses system installation of Magnum).

The most important new feature is that the code is now able to read batch-friendly glTFs produced by tools from the experimental batch renderer. In particular, those use the (provisional) KHR_texture_ktx extension to combine several textures into one large 2D array texture, and combine all meshes into one while referencing just sub-ranges of it from actual nodes, thus enabling a multi-draw workflow. Just for completeness, the produced batch-friendly glTF looks like this:

{
  "asset": {
    "version": "2.0",
    "generator": "Magnum GltfSceneConverter"
  },
  "extensionsRequired": [
    "MAGNUMX_mesh_views",
    "KHR_texture_ktx"
  ],
  ...
  "images": [
    {
      "uri": "yay.0.ktx2"
    }
  ],
  "textures": [
    ...
    {
      "extensions": {
        "KHR_texture_ktx": {
          "source": 0,
          "layer": 70
        }
      }
    },
    ...
  ], 
  "nodes": [
    ..
    {
      "matrix": [
        ...
      ],
      "mesh": 0,
      "extras": {
        "meshViewIndexOffset": 328332,
        "meshViewIndexCount": 600,
        "meshViewMaterial": 46
      },
      "name": "frl_apartment_door_part_01"
    },
    ...
  ]
}

And when opened, the custom extra information is exposed as such (magnum-sceneconverter --info on a composite file containing all 105 ReplicaCAD scenes and then some):

image

In other words, this PR makes it possible to start integrating the batch renderer implementation directly into Habitat main, with only the Galakhtic project having to rely on a custom branch to be able to produce the files (glTF export is still being developed in a Magnum branch).

Other things worth mentioning:

  • The CgltfImporter plugin is now called just GltfImporter, as the 3rd party parser code got removed from underneat, to make addition of new features and support of custom extensions a matter of hours instead of weeks
  • Utility::Json and Utility::JsonWriter, powering glTF import and export, is now mostly feature-complete, with convenience APIs for type-safe parsing and straightforward reading and writing of large data arrays
  • Scene node extras import isn't limited to just the glTF files produced by the batch renderer tools, but to any other files. Floorplanner assets, for example, supply various annotations and tags in those.
  • All material textures now have also a *TextureLayer attribute to support texture arrays
  • Improved DdsImporter plugin and a new AstcImporter plugin, to make it easier to try alternatives to the Basis Universal format, which takes an impractical amount of time and memory to compress (>12 GB RAM and 30 minutes with the composite file). Not enabled in Habitat at the moment.
  • (Contributed) new WebPImporter plugin for reading *.webp files. WebP is capable of producing a 25%-34% smaller file than JPEG in a comparable lossy quality, and ~25% smaller lossless file than a PNG. Including support in glTF via the EXT_texture_webp extension. Not enabled in Habitat at the moment.

How Has This Been Tested

My CIs pass, hopefully this one too.

Types of changes

  • Docs change / refactoring / dependency upgrade

CgltfImporter has been renamed to GltfImporter, no other breaking
change, just a ton of new features.
@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Jun 8, 2022
@Skylion007
Copy link
Contributor

Exciting; A shame MeshViews isn't an officially supported extension though, kinda surprises me.

Copy link
Contributor

@aclegg3 aclegg3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for the upgrade. 👍

@mosra
Copy link
Collaborator Author

mosra commented Jun 8, 2022

A shame MeshViews isn't an officially supported extension though

A glTF file can be produced in a form where it's possible to infer the views implicitly from the accessor and buffer view layout. But that involves a lot of complex corner case checking and error handling, so I took a shortcut for now and used a bunch of explicit extras fields :)

The ultimate goal here is to have the glTF produces without these extras, and figure out the view offset/sizes implicitly, so Blender and other tools can read those without needing additional conversion.

@aclegg3 aclegg3 merged commit 571a057 into main Jun 8, 2022
@aclegg3 aclegg3 deleted the update-magnum12 branch June 8, 2022 19:28
@mosra
Copy link
Collaborator Author

mosra commented Jun 8, 2022

Uh oh, seems like I didn't actually update the submodules to the latest latest, sorry. #1777 has the rest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants