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

Add individual model projection in 2D / CV for `ModelExperimental #10419

Merged
merged 15 commits into from
Jun 3, 2022

Conversation

j9liu
Copy link
Contributor

@j9liu j9liu commented Jun 1, 2022

This PR closes #9934. It allows models loaded in with ModelExperimental to render in 2D / CV, without needing projectTo2D enabled. This is ideal for individual models that aren't part of a 3D Tiles tileset.

This required refactoring the draw command system of ModelExperimental; now there is a ModelExperimentalDrawCommand class that handles a primitive's draw command, and any other commands derived from it.

I also found that the check for adding commands in 2D for Model was incorrect; it would always evaluate to true, so it was always adding the 2D commands even if the model was nowhere near the IDL.

Sandcastles for testing:

@ptrgags can you review?

@j9liu j9liu requested a review from ptrgags June 1, 2022 20:57
@cesium-concierge
Copy link

Thanks for the pull request @j9liu!

  • ✔️ 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.

@ptrgags
Copy link
Contributor

ptrgags commented Jun 2, 2022

@j9liu looking at the sandcastles you posted, I had some questions:

2D / CV Sandcastle:

  1. I notice that the lighting looks different on the two halves of the model in 2D mode (I presume because the light direction is different for each copy of the model?). Is this the intended behavior? I would think that you need both halves of the model should pretend the sun is in the same place, though not sure how easy it would be to override czm_lightDirection in the shader. Might be easiest to leave it alone, but wasn't sure.
    image
  2. I noticed some weird behavior in the map when I do the following in that sandcastle. Might just be a corner case in the camera code for 2D. Can you reproduce this behavior? What about with the old Model?
  • Zoom out on the map so you can see the map repeat.
  • Pan the view so you can see the IDL 180 degrees to the right of where you started
  • Load a different model from the dropdown
  • The map suddenly renders as 2 wedges for some reason:
    image
  1. I notice that the model always shows up on one edge of the map in CV mode (either the left or the right, not always consistently. e.g. the balloon shows up on the right but everything else shows up on the left. Is that what we want, or should it appear on both sides of the map?
  2. In the culling/translucent Sandcastle, if enable both, the model shows up as translucent but back faces are not culled. Is that supposed to happen?

@ptrgags
Copy link
Contributor

ptrgags commented Jun 2, 2022

@j9liu looking at the sandcastles you posted, I had some questions:

2D / CV Sandcastle:

  1. I notice that the lighting looks different on the two halves of the model in 2D mode (I presume because the light direction is different for each copy of the model?). Is this the intended behavior? I would think that you need both halves of the model should pretend the sun is in the same place, though not sure how easy it would be to override czm_lightDirection in the shader. Might be easiest to leave it alone.
    image
  2. I noticed some weird behavior in the map when I do the following in that sandcastle. Might just be a corner case in the camera code for 2D. Can you reproduce this behavior? What about with the old Model?
  • Zoom out on the map so you can see the map repeat.
  • Pan the view so you can see the IDL 180 degrees to the right of where you started
  • Load a different model from the dropdown
  • The map suddenly renders as 2 wedges for some reason:
    image
  1. I notice that the model always shows up on one edge of the map in CV mode (either the left or the right, not always consistently. e.g. the balloon shows up on the right but everything else shows up on the left. Is that what we want, or should it appear on both sides of the map?
  2. In the culling/translucent Sandcastle, if enable both, the model shows up as translucent but back faces are not culled. Is that supposed to happen?

@j9liu
Copy link
Contributor Author

j9liu commented Jun 2, 2022

@ptrgags

  1. This behavior is consistent with Model. If we want, we can fix it later, but I don't think it should delay this PR.
  2. Yeah I see this happen. I think it's because of the camera transformation when choosing a new model. The orientation of the camera is meant to be in 3D space but I see it causes problems for 2D mode. Probably should open an issue for this, but again outside the scope of the PR.
  3. I believe this is consistent with Model.
  4. This is supposed to happen. Back-face culling shouldn't apply to translucent models.

Copy link
Contributor

@ptrgags ptrgags left a comment

Choose a reason for hiding this comment

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

@j9liu I'm liking the new ModelExperimentalDrawCommand architecture, it feels a lot more straightforward than what Model was doing, and it simplifies quite a bit of the rest of the code.

I had some comments, mostly small suggestions or clarification questions

Source/Scene/Model.js Outdated Show resolved Hide resolved
Comment on lines 5690 to 5693
if (
frameState.mode === SceneMode.SCENE2D &&
(boundingVolume.center.y + boundingVolume.radius > idl2D ||
boundingVolume.center.y - boundingVolume.radius < idl2D)
left < idl2D &&
right > idl2D
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, is there a reason why this code isn't checking a similar conditions at y=0?

e.g. if left < 0 && right > 0 wouldn't that also be straddling the IDL?

Copy link
Contributor Author

@j9liu j9liu Jun 2, 2022

Choose a reason for hiding this comment

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

I'm not sure what you mean, does the IDL wrap around to y = 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, after some debugging, I found that it was supposed to check if left < -idl2D && right > -idl2D as well. so the general idea was right

Source/Scene/Model.js Outdated Show resolved Hide resolved
Specs/Scene/Cesium3DTilesetSpec.js Show resolved Hide resolved
Specs/Scene/Cesium3DTilesetSpec.js Show resolved Hide resolved
@ptrgags
Copy link
Contributor

ptrgags commented Jun 3, 2022

@j9liu this is looking pretty close, though there's a small merge conflict in the changelog.

I also noticed that in 2D mode, the propellers on the drone disappear on one side:

image

I wondered if the individual primitives in the model are being translated to different copies of the IDL since each primitive bounding sphere is different. I tried modifying the Sandcastle to put the model close to the edge but not quite. I notice that at longitude = 179.999994 degrees this behavior appears, but when I change it to 179.999993 it works fine.

@j9liu
Copy link
Contributor Author

j9liu commented Jun 3, 2022

@ptrgags updated!

@ptrgags
Copy link
Contributor

ptrgags commented Jun 3, 2022

@j9liu looks good and I confirmed that you fixed the missing primitives. Thanks!

@ptrgags ptrgags merged commit e0f92af into main Jun 3, 2022
@ptrgags ptrgags deleted the individual-model-projection branch June 3, 2022 15:12
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.

ModelExperimental - Support rendering in 2D and Columbus View modes
3 participants