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

Only update local matrix if needed #135

Open
gkjohnson opened this issue May 4, 2019 · 2 comments
Open

Only update local matrix if needed #135

gkjohnson opened this issue May 4, 2019 · 2 comments
Labels

Comments

@gkjohnson
Copy link
Owner

gkjohnson commented May 4, 2019

At the moment the world matrix is marked as out of date when joints are updated but realistically the local matrices need to be updated. However, three.js does not support marking the local matrix as dirty.

Options

  • Mark matrixAutoUpdate as false.
  • Override the updateMatrix function to only update the local transform if a custom variable is marked as true.
  • Mark all child meshes as matrixAutoUpdate = false because we expect that they will not change. Possibly gate this behind an option?
  • The childrens world matrices will have to be recursively marked as out of date, too.
  • Caveat is that if the world or local matrix are manually updated then children will have to be notified that their world matrices are incorrect.
@EzraBrooks
Copy link
Contributor

I'm working on an application that we want to be available at the edge (e.g. a ruggedized Android tablet out in the middle of nowhere on an LTE radio), and we're looking at eking as much performance out of Three and urdf-loader as possible. I have noticed in flame graphs that this issue seems to be a major contributor to rendering overhead in our app.

I'd be interested in discussing what the preferred solution would be here, and may be able to contribute code, as my employer generally favors open source contributions over rolling our own solutions.

@gkjohnson
Copy link
Owner Author

Looks like I'd made #174 for the same type of problem 😅

You can see the logic for updating the world matrices in three.js here. By default when the matrix world is updated the local matrix is always updated which means matrixWorld is always updated leading to some of the issues you're seeing. It's convenient but not optimal.

Here are the constraints we have if we're trying to optimize the matrix updates:

  • If the robot root transform (rotation, scale, position) change then all child object world matrices (but not local matrices) need to be updated.
  • If a joint moves then only its local matrix needs to be updated and all child world matrices need to be updated.

So here's what I propose:

  • On load set "autoUpdateMatrix" to false on all child objects (not the robot root)
  • Add a "jointMatrixNeedsUpdate" field to the URDFJoints that defaults to false
  • Override URDFJoint.updateMatrixWorld to account for jointMatrixNeedsUpdate in addition to the auto update flag.
  • Override URDFRobot.updateMatrixWorld to update only if its matrix world has changed (see similar implementation here)
  • Add "optimizeMatrixUpdate" flags to the joints and robot objects that toggles the above optimizations
  • Add "optimizeMatrixUpdate" flag to the loader that sets the above mentioned flag on the robot and joints. Defaults to false.

I've written that down quickly but I think that should work. Let me know what you think. I'd like to add this in a backwards compatible way - thanks for looking into it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants