Repository navigation
Camera now uses meters - #526
Conversation
|
Thanks for taking on this work @elalish . While I'm doing the review, I have one piece of immediate feedback on the PR overall: for the benefit of your reviewers, and also for posterity, it would be nice to have an abstract summary of how the issues were addressed in the PR description. Particularly in this case, it would be nice to have a brief sentence or two describing how we will define 1 meter moving forward based on this change. |
|
Sure thing. The model is no longer scaled at all, meaning all dimensions,
including those of the camera, are in model units. If all models are loaded
in meters, then the camera is also in meters. It would behoove us to check
all of our supported file formats to make sure they specify units and scale
appropriately. Traditionally 3D model files ignored units and everyone was
expected to know that implicit units in equaled implicit units out, but
that doesn’t work anymore with AR.
…On Fri, May 3, 2019 at 7:50 AM Christopher Joel ***@***.***> wrote:
Thanks for taking on this work @elalish <https://github.com/elalish> .
While I'm doing the review, I have one piece of immediate feedback on the
PR overall: for the benefit of your reviewers, and also for posterity, it
would be nice to have an abstract summary of how the issues were addressed
in the PR description. Particularly in this case, it would be nice to have
a brief sentence or two describing how we will define 1 meter moving
forward based on this change.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#526 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAMS2LEKYPB4SJBHVTBU72TPTRGMLANCNFSM4HKLZ2HQ>
.
|
|
Any idea what's up with the failed builds? The first one throws |
cdata
left a comment
There was a problem hiding this comment.
Overall this looks like a huge improvement 🙌 I played around with it locally, and things seemed to work more or less as I expected them to. Kudos for going out of your way to preserve some of the legacy framing details while overhauling how we think about units 💯
There is a bunch of minor stuff that should be corrected from a conventions / readability perspective, enough that I realized that we badly need some of our guidelines to be documented. Without further ado: there is now a "code conventions" page on the wiki!
This wiki page probably isn't comprehensive. My hope is that we can all work together to improve it over time so that nit-y feedback in PRs can just point to subheaders of this page in the future. And, as I took care to note on the page: hopefully we can codify as much of those guidelines in tools as possible so that we don't have to wait until code review to point them out 🙏
| const POLAR_TRIENT_LABELS = ['upper-', '', 'lower-']; | ||
|
|
||
| const ORBIT_CAMERA_NEAR_PLANE = FRAMED_HEIGHT / 10.0; | ||
| const ORBIT_CAMERA_FAR_PLANE = FRAMED_HEIGHT * 10.0; |
There was a problem hiding this comment.
Don't celebrate quite yet; this logic is still included, just further down. I kept the functionality identical for now, but we might want to revisit how we want to compute our near and far planes.
| this[$orbitCamera].near = ORBIT_CAMERA_NEAR_PLANE; | ||
| this[$orbitCamera].far = ORBIT_CAMERA_FAR_PLANE; | ||
| this[$orbitCamera].updateProjectionMatrix(); | ||
| this[$orbitCamera] = scene.getCamera(); |
| getCameraOrbit(): SphericalPosition { | ||
| const {theta, phi, radius} = this[$lastSpherical]; | ||
| return {theta, phi, radius: radius / FRAMED_HEIGHT}; | ||
| return {theta, phi, radius}; |
| if (sphericalValues == null) { | ||
| sphericalValues = deserializeSpherical(DEFAULT_CAMERA_ORBIT)!; | ||
| } | ||
| setCameraOrbit() { |
There was a problem hiding this comment.
A few thoughts on this:
- For public API, we should always add documentation to describe what the method does
- The name suggests it is an
setaccessor counterpart togetCameraOrbitbut it accepts no arguments. What is being set? - The method is de facto public API, but probably should not be. Use a
Symbolfor protected/private API
| * dimensions for the encapsulating element. | ||
| */ | ||
| applyRoomSize() { | ||
| applyCanvasSize() { |
There was a problem hiding this comment.
If all this is doing is changing the dimensions of a <canvas>, then I would agree this name is close to fine (I might have gone with updateCanvasSize).
But, this is also computing values for the framedHeight and modelDepth. These seem only passingly related to changing the size of a <canvas>. All of these things are part of some higher-order change taking place, so we should probably choose a name that reflects that.
There was a problem hiding this comment.
Agreed. I kind of hate naming, so suggestions welcome.
There was a problem hiding this comment.
We use the word "frame" a lot these days. I would be happy with updateFraming.
| scene.scaleModelToFitRoom(); | ||
| }); | ||
|
|
||
| test('increases the scale of a small object to fill the limit', () => { |
There was a problem hiding this comment.
Holy test suite bloodbath, Batman 😱
It's not necessarily bad to remove tests. Sometimes they will be obsolete and dead-weight. But, without additional context, I would say that these tests look at least conceptually relevant (even if their implementation might now be obsolete).
My recommendations here are:
- It's usually better to evolve a test towards relevance rather than remove it
- Our test suite is already sparse; a change with the scope of this one might even call for additional tests (esp. since issues are being closed out)
- If you remove obsolete, dead-weight tests, explain why in the PR description for the benefit of your reviewers
Also added some guidelines here: https://github.com/GoogleWebComponents/model-viewer/wiki/Code-conventions#tests
There was a problem hiding this comment.
Fair enough. I removed these because really I combined them with another set of tests above. Once the logic was simplified, they ended up testing pretty much the same thing. More tests could always be added of course. If you see something that looks like it could use more, I’m happy to add it.
There was a problem hiding this comment.
A good place to start would be to add at least one test for each issue being closed out that will guard us against likely regressions.
For example, I might have expected to see a test added that asserts that the scale of the model does not change as the element resizes. In fact, looking back this seems to be the spirit of the tests you removed (checking how the scale of the model changes).
|
|
||
| private[$userAdjustOrbit](deltaTheta: number, deltaPhi: number, deltaRadius: number): boolean { | ||
| private[$userAdjustOrbit]( | ||
| deltaTheta: number, deltaPhi: number, deltaRadius: number): boolean { |
There was a problem hiding this comment.
Thanks for running clang-format. We need to set this up to run on a pre-commit hook...
Filed #530
There was a problem hiding this comment.
I must have not had it set up at first, because a bunch of new formatting changes came in this time.
| this[$twoTouchDistance](touches[0], touches[1]); | ||
| const radiusDelta = -1 * (touchDistance - lastTouchDistance) / 10.0; | ||
| const radiusDelta = -1 * this[$zoomMeters] * | ||
| (touchDistance - lastTouchDistance) / 10.0; |
There was a problem hiding this comment.
I don't know if this is actionable or not, but I think magic number 10.0 here might have been previously related to FRAMED_HEIGHT. Did you poke at that at all?
There was a problem hiding this comment.
Maybe, but it’s also an arbitrary scale. There’s an issue around dpr where we should probably fix this.
Our test suite has undergone some growing pains / scaling issues over time, and also we have some outstanding flakes (#522, #146). Sauce Labs in particular has been known to be unpredictably available, and occasionally will waste hours of our lives while we reboot the test suite and watch browsers timeout or fail to start at random. That Edge failure is new to me, though. Recording here for posterity: ...and rebooting the build :) |
There was a problem hiding this comment.
Great work so far 🙌 this is getting pretty close to done.
I played around with camera-orbit with this change in place. It seems as though our reckoning of meters (as far as radius is concerned) has been very wrong this whole time, and it's a lot more obvious now that 1 unit = 1 meter. Huge kudos for getting us onto this good path!
One side-effect of this is that our camera-orbit demos look a bit too "zoomed in" because the fixed values were picked due to their subjectively good framing. Would you mind going in and picking some longer radii in the two demos that specify camera-orbit on this page?
| if (sphericalValues == null) { | ||
| sphericalValues = deserializeSpherical(DEFAULT_CAMERA_ORBIT)!; | ||
| } | ||
| [$applyCameraOrbit]() { |
There was a problem hiding this comment.
Let's stick with $updateCameraOrbit for this
|
|
||
| // When we update the idealCameraDistance due to reframing, we want to | ||
| // maintain the user's zoom level (how they have changed the camera | ||
| // radius), which we represent here as a ratio. |
| * dimensions (modelDepth) are the same (for Y-rotation) and the X/Y ratio is | ||
| * the aspect ratio of the canvas (framedHeight is the Y dimension). At the | ||
| * ideal distance, the camera's fov exactly covers the front face of this box | ||
| * when looking down the Z-axis. |
There was a problem hiding this comment.
Great comment. It's interesting to see that the notion of a room survives, just in a somewhat deconstructed form...
There was a problem hiding this comment.
Yeah, I wanted to call it out because I wasn't sure if everyone was clear on how our framing really worked. It means that for a model that touches its bounding box corners, it will still get clipped at certain rotations. I'm not sure I'd recommend changing the framing, but we might want to allow a little extra zoom out to ensure that any model can be entirely visible in frame from any angle.
There was a problem hiding this comment.
You can see what I'm talking about here: https://maps3d.io/blog/what-is-the-gltf-glb-format-3d-file/
There was a problem hiding this comment.
Yeah, I agree with you regarding the extra zoom-out by default. We also want to just let users configure the allowed min/max #458
| * Time and delta are measured in milliseconds. | ||
| */ | ||
| update(_time: number, delta: number) { | ||
| if (this[$targetSpherical] === this[$spherical]) { |
There was a problem hiding this comment.
This condition should never be true because it is comparing two class instances (not their properties) and we (should) never re-assign them after they have been created.
Usually Three.js includes an equality helper for classes like Spherical, but that is not the case here. The best you can do under the circumstances is compare each of the three relevant properties directly (sadly it is very verbose to do so).
There was a problem hiding this comment.
Thank you! I didn't realize that logic would apply like a pointer comparison. I'll fix that.
| // acceleration constraint. We only "apply" velocity when accelerating. | ||
| // When decelerating, we apply dampening exclusively. | ||
| const applyVelocity = distance > this[$options].decelerationMargin!; | ||
| const applyVelocity = distance > this[$options].decelerationMargin !; |
There was a problem hiding this comment.
The space between the property name and the ! is unorthodox. Is clang-format picking up our local project configuration?
There was a problem hiding this comment.
Yeah, I was wondering about that. I'll see if I can fix my clang-format, because something is weird.
|
|
||
| handled = this[$userAdjustOrbit](deltaTheta, deltaPhi, 0) | ||
|
|
||
| break; |
There was a problem hiding this comment.
Weird indentation on this line
| } | ||
|
|
||
| private[$handlePointerDown](event: MouseEvent|TouchEvent) { | ||
| private[$handlePointerDown](event: MouseEvent | TouchEvent) { |
There was a problem hiding this comment.
Also weird spaces in the union type here
| * Move the camera instantly instead of accelerating toward the setOrbit() | ||
| * parameters. | ||
| */ | ||
| jumpCamera() { |
There was a problem hiding this comment.
This is going to be very bike-shed-y of me, but I liked your previous name a lot better (jumpToTarget).
There was a problem hiding this comment.
The reason I changed it is because it referred to $targetSpherical, which is an implementation detail. We intend to add a configurable camera target, at which point this function would start to sound like it only applied that property. This name implies the camera is shifted based on all of its changed properties.
There was a problem hiding this comment.
Good point, we have overused the word target here:
private $targetSpherical- the target destination of the camerapublic target- the orbital focal point
Elsewhere, I have taken to referring to the first one as the "destination" of the camera, so what would you say to jumpToDestination?
| scene.alignModel(); | ||
|
|
||
| expect(scene.model.position).to.be.eql(expectedPosition); | ||
| expect(scene.model.position).to.be.eql(new Vector3(-5, -10, -20)); |
| } | ||
|
|
||
| /** | ||
| * Resets the input sensitivity based on model scale, here represented by |
There was a problem hiding this comment.
Does it only affect input? It seems like $zoomMeters is also used when update is invoked (which is usually caused by configuration changes)
There was a problem hiding this comment.
Yes, it's used as a normalization for radius to affect acceleration of the smooth controls (which I would still consider a type of input sensitivity). I can't really think of a better way to explain it.
There was a problem hiding this comment.
For me, the word "input" suggests "user input," or something the person clicking / tapping / interacting with the page is doing. In practice, $zoomMeters is universally applied regardless of the origin of the change. "Zoom" might be a fine substitute that avoids the ambiguity.
|
Really great foundational work here @elalish 👍 |
* removed default camera * refactor complete, not tested * tests pass * fixed flex syntax * fixed framing and added tests * fixed zoom sensitivity * fixed shadow and framing * fixed SmoothControls * addressing feedback * fixed divide by zero * addressing feedback * unformatted the html * forgot a couple pieces of feedback

Reference Issue
Fixes #450, #197
This refactor removes the "room" and cleans up a bunch of camera stuff. I believe this has made no difference to our fidelity tests, but we should double check when we have the proper master renders to compare to.