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

[geometry] Unbundle glTFs before sending to Meshcat #20877

Merged

Conversation

jwnimmer-tri
Copy link
Collaborator

@jwnimmer-tri jwnimmer-tri commented Feb 4, 2024

This substantially improves loading times for large files.

Towards #19598.


This change is Reviewable

Copy link
Collaborator Author

@jwnimmer-tri jwnimmer-tri left a comment

Choose a reason for hiding this comment

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

Reviewed 12 of 12 files at r1, 3 of 3 files at r2, 1 of 1 files at r3, all commit messages.
Reviewable status: 1 unresolved discussion, needs platform reviewer assigned, needs at least two assigned reviewers, labeled "do not merge", commits need curation (https://drake.mit.edu/reviewable.html#curated-commits), missing label for release notes (waiting on @jwnimmer-tri)


geometry/meshcat_internal.cc line 162 at r1 (raw file):

  }
  if (edited) {
    *gltf_contents = gltf.dump();

Working

Is nlohmann output deterministic?

Copy link
Collaborator Author

@jwnimmer-tri jwnimmer-tri left a comment

Choose a reason for hiding this comment

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

Reviewable status: needs platform reviewer assigned, needs at least two assigned reviewers, labeled "do not merge", commits need curation (https://drake.mit.edu/reviewable.html#curated-commits), missing label for release notes (waiting on @jwnimmer-tri)


geometry/meshcat_internal.cc line 162 at r1 (raw file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

Working

Is nlohmann output deterministic?

Done.

Yes, per https://json.nlohmann.me/features/object_order/ by default it's a std::map so the output should be reasonably consistent. The formatting for floating-point types might change when we upgrade nlohmann (nlohmann/json#2526) but for any given version pin it should be deterministic.

@jwnimmer-tri jwnimmer-tri added priority: high release notes: fix This pull request contains fixes (no new features) and removed status: do not merge status: do not review labels Feb 5, 2024
@jwnimmer-tri jwnimmer-tri marked this pull request as ready for review February 5, 2024 21:51
@jwnimmer-tri
Copy link
Collaborator Author

jwnimmer-tri commented Feb 5, 2024

+@rpoyner-tri for feature review, please.

+@SeanCurtis-TRI please give this a quick "sniff test" to make sure the design seems unobjectionble. (It should be sufficient to just look at meshcat_internal.h and meshcat.cc to get the idea.)

Then we can tag Grant for platform tomorrow.

Copy link
Collaborator Author

@jwnimmer-tri jwnimmer-tri left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 2 files at r4, all commit messages.
Reviewable status: LGTM missing from assignees rpoyner-tri(platform),SeanCurtis-TRI(platform)

Copy link
Contributor

@SeanCurtis-TRI SeanCurtis-TRI left a comment

Choose a reason for hiding this comment

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

Seems reasonable to me.

Reviewed 1 of 3 files at r2, 1 of 1 files at r3.
Reviewable status: 4 unresolved discussions, LGTM missing from assignees rpoyner-tri(platform),SeanCurtis-TRI(platform)


geometry/meshcat.cc line 266 at r4 (raw file):

  DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN(MeshcatShapeReifier);

  explicit MeshcatShapeReifier(

nit No longer necessary.

Code quote:

explicit 

geometry/meshcat_internal.h line 57 at r4 (raw file):

them. Meshcat is MUCH slower at loading bundled assets compared to unbundled.

When glTF file has relative path URIs (i.e., unbundled files on disk), this

nit: typo

Suggestion:

When a glTF

geometry/meshcat_internal.h line 58 at r4 (raw file):

When glTF file has relative path URIs (i.e., unbundled files on disk), this
loads the files FileStorage so that we can serve them later, even if the

nit: typo

Suggestion:

files into FileStorage

geometry/meshcat_internal.h line 62 at r4 (raw file):

@param[in] gltf_filename The glTF filename, used to calculate relative paths.
@param[in,out] gltf_contents The glTF data already loaded from `gltf_filename`.

nit; I think you mean "glTF file contents" as something to contrast with "glTF data" which would be the form that is stored in memory (e.g., decoded mesh data), right?

Code quote:

glTF data

Copy link
Collaborator Author

@jwnimmer-tri jwnimmer-tri left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 2 files at r5, all commit messages.
Reviewable status: 1 unresolved discussion, LGTM missing from assignees rpoyner-tri(platform),SeanCurtis-TRI(platform)


geometry/meshcat_internal.h line 62 at r4 (raw file):

Previously, SeanCurtis-TRI (Sean Curtis) wrote…

nit; I think you mean "glTF file contents" as something to contrast with "glTF data" which would be the form that is stored in memory (e.g., decoded mesh data), right?

I tried to rephrase it a bit for clarity.

Copy link
Contributor

@SeanCurtis-TRI SeanCurtis-TRI left a comment

Choose a reason for hiding this comment

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

Reviewable status: 1 unresolved discussion, LGTM missing from assignees rpoyner-tri(platform),SeanCurtis-TRI(platform)


geometry/meshcat.cc line 382 at r4 (raw file):

      }
    } else if (format == "gltf") {
      assets_ =

BTW It seems that we'd want to explain why we're locally overriding this parameter from the constructor. That seems a bit odd.


geometry/meshcat_internal.h line 62 at r4 (raw file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

I tried to rephrase it a bit for clarity.

Very clear.

Copy link
Collaborator Author

@jwnimmer-tri jwnimmer-tri left a comment

Choose a reason for hiding this comment

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

Reviewable status: 1 unresolved discussion, LGTM missing from assignees rpoyner-tri(platform),SeanCurtis-TRI(platform)


geometry/meshcat.cc line 382 at r4 (raw file):

Previously, SeanCurtis-TRI (Sean Curtis) wrote…

BTW It seems that we'd want to explain why we're locally overriding this parameter from the constructor. That seems a bit odd.

I'm not sure what you mean. Are you saying we could envision the assets_ as [in,out] instead of just [out], so we should append to it here instead of overwriting it? (Maybe I could add Doxygen to the constructor to clarify what's going on?)

Copy link
Contributor

@SeanCurtis-TRI SeanCurtis-TRI left a comment

Choose a reason for hiding this comment

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

Reviewable status: 1 unresolved discussion, LGTM missing from assignees rpoyner-tri(platform),SeanCurtis-TRI(platform)


geometry/meshcat.cc line 382 at r4 (raw file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

I'm not sure what you mean. Are you saying we could envision the assets_ as [in,out] instead of just [out], so we should append to it here instead of overwriting it? (Maybe I could add Doxygen to the constructor to clarify what's going on?)

Clarification is key. You contrast [in,out] and [out], but there is, of course, no documentation to either extent. It stands in particular contrasts to its adjacent parameter, file_storage which is definitely [in,out].

Documenting the semantics is minimally sufficient.

Copy link
Collaborator Author

@jwnimmer-tri jwnimmer-tri left a comment

Choose a reason for hiding this comment

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

Reviewable status: 1 unresolved discussion, LGTM missing from assignees rpoyner-tri(platform),SeanCurtis-TRI(platform)


geometry/meshcat.cc line 382 at r4 (raw file):

Previously, SeanCurtis-TRI (Sean Curtis) wrote…

Clarification is key. You contrast [in,out] and [out], but there is, of course, no documentation to either extent. It stands in particular contrasts to its adjacent parameter, file_storage which is definitely [in,out].

Documenting the semantics is minimally sufficient.

Working

Right, the problem is it's really a new addition to the return value, and instead of refactoring the reifier stuff to admit as much, I hacked it into the constructor. I'll work on refactoring the reifier to "return" more than one value.

Copy link
Collaborator Author

@jwnimmer-tri jwnimmer-tri left a comment

Choose a reason for hiding this comment

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

Reviewable status: LGTM missing from assignees rpoyner-tri(platform),SeanCurtis-TRI(platform)


geometry/meshcat.cc line 382 at r4 (raw file):

Previously, jwnimmer-tri (Jeremy Nimmer) wrote…

Working

Right, the problem is it's really a new addition to the return value, and instead of refactoring the reifier stuff to admit as much, I hacked it into the constructor. I'll work on refactoring the reifier to "return" more than one value.

Yup, much clearer now. Now we have consistency:

  • the long-lived helper tools are constructor arguments,
  • the shape details are the ImplementGeometry argument,
  • the reification result is the reify output argument.

Copy link
Contributor

@rpoyner-tri rpoyner-tri left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 6 of 12 files at r1, 1 of 3 files at r2, 1 of 1 files at r3, 2 of 2 files at r4, 1 of 2 files at r5, 1 of 1 files at r6, all commit messages.
Reviewable status: LGTM missing from assignee SeanCurtis-TRI(platform)

Copy link
Collaborator Author

@jwnimmer-tri jwnimmer-tri left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r6, all commit messages.
Reviewable status: LGTM missing from assignee SeanCurtis-TRI(platform)

@jwnimmer-tri
Copy link
Collaborator Author

+@xuchenhan-tri for platform review per schedule, please.

Copy link
Contributor

@xuchenhan-tri xuchenhan-tri left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 6 of 12 files at r1, 1 of 3 files at r2, 1 of 1 files at r3, 2 of 2 files at r4, 1 of 2 files at r5, 1 of 1 files at r6, all commit messages.
Reviewable status: 3 unresolved discussions, LGTM missing from assignee SeanCurtis-TRI(platform)


geometry/meshcat_file_storage_internal.cc line 138 at r6 (raw file):

  // not contain a subdirectory (i.e., no "/" characters) because that confuses
  // any assets that refer to sub-assets.
  return fmt::format("cas-v1-{}", asset.sha256.to_string());

BTW, what does "v1? mean here?

Code quote:

cas-v1

geometry/meshcat_internal.cc line 98 at r6 (raw file):

      return nullptr;
    }
    // TODO(jwnimer-tri) Save the media type to http-serve later on.

typo

Suggestion:

// TODO(jwnimmer-tri) Save the media type to http-serve later on.

geometry/meshcat_internal.cc line 100 at r6 (raw file):

    // TODO(jwnimer-tri) Save the media type to http-serve later on.
    // For now, we'll just skip ahead to the actual content.
    std::string_view base64_content = uri.substr(pos + 8);

BTW, what is the magic number 8?

Code quote:

std::string_view base64_content = uri.substr(pos + 8);

This substantially improves loading times for large files.
Copy link
Collaborator Author

@jwnimmer-tri jwnimmer-tri left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 2 files at r7, all commit messages.
Reviewable status: LGTM missing from assignee SeanCurtis-TRI(platform)


geometry/meshcat_internal.cc line 100 at r6 (raw file):

Previously, xuchenhan-tri wrote…

BTW, what is the magic number 8?

Replaced with a more meaningful constant expression.

@jwnimmer-tri jwnimmer-tri merged commit 35c1de4 into RobotLocomotion:master Feb 7, 2024
10 checks passed
@jwnimmer-tri jwnimmer-tri deleted the meshcat-gltf-unbundle branch February 7, 2024 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: high release notes: fix This pull request contains fixes (no new features)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants