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

Correct bounding sphere transform for glTF 2.0. #6803

Merged
merged 3 commits into from
Jul 18, 2018
Merged

Conversation

emackey
Copy link
Contributor

@emackey emackey commented Jul 13, 2018

Fixes #6784.

@cesium-concierge
Copy link

cesium-concierge commented Jul 13, 2018

Thanks for the pull request @emackey!

  • ✔️ Signed CLA found.
  • CHANGES.md was not updated.
    • If this change updates the public API in any way, please add a bullet point to CHANGES.md.

Reviewers, don't forget to make sure that:

  • Cesium Viewer works.
  • Works in 2D/CV.
  • Works (or fails gracefully) in IE11.

I am a bot who helps you make Cesium awesome! Contributions to my configuration are welcome.

🌍 🌎 🌏

@lilleyse
Copy link
Contributor

The pivot point is a bit off center in CV and 2D, but only for OffsetCube. It seems worse in 1.46 though, so maybe not relevant to this PR.

Also it would be good to get to the bottom of why the transform is applied first for computing the bounding sphere but last for the model matrix.

@lilleyse
Copy link
Contributor

Besides that, this does fix the problem.

@emackey
Copy link
Contributor Author

emackey commented Jul 17, 2018

Also it would be good to get to the bottom of why the transform is applied first for computing the bounding sphere but last for the model matrix.

The (non-bounding-sphere) model matrix is being transformed by another matrix. The original model matrix is oriented for Cesium (+X forward, +Z up), then transformed to Y-up (still +X forward), and finally to +Z forward, +Y up. The resulting transformation matrix takes vertices expressed in that system and gets them into Cesium's preferred orientation.

The BoundingSphere calculations are taking a single point, the sphere's center point, and getting it into Cesium's coordinate system. So we're transforming a point by two different matrices, not stacking up the matrix multiplications into a single transform matrix.

For example, in the case of OffsetCube, the glTF mesh data is centered around [2, 4, 6], with 4 being "up" (glTF +Y) and 6 being "forward" (glTF +Z). We first transform +Z to +X, and get [6, 4, -2] as an intermediate center point. Then we transform +Y to +Z, and get [6, 2, 4]. Previously, 4 had been "up", and this is now +Z where Cesium expects. Previously 6 had been "forward", and this is now +X where Cesium expects.

@lilleyse
Copy link
Contributor

Ah yeah that makes sense. In both cases the Z_UP_TO_X_UP transform is still applied first, but it just appears different because the model matrix stacks it last. Thanks!

@lilleyse lilleyse merged commit 40ba971 into master Jul 18, 2018
@lilleyse lilleyse deleted the bounding-gltf-2.0 branch July 18, 2018 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants