Skip to content

Camera now uses meters - #526

Merged
cdata merged 18 commits into
masterfrom
room_refactor
May 10, 2019
Merged

cdata merged 18 commits into
masterfrom
room_refactor

Conversation

@elalish

@elalish elalish commented May 2, 2019

Copy link
Copy Markdown
Contributor

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.

@elalish
elalish requested a review from cdata May 2, 2019 23:09
@elalish elalish self-assigned this May 2, 2019
@cdata

cdata commented May 3, 2019

Copy link
Copy Markdown
Contributor

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.

@elalish

elalish commented May 3, 2019 via email

Copy link
Copy Markdown
Contributor Author

@elalish

elalish commented May 3, 2019

Copy link
Copy Markdown
Contributor Author

Any idea what's up with the failed builds? The first one throws THREE.WebGLRenderer: EXT_shader_texture_lod extension not supported. during npm run check-fidelity and the second one fails three tests on Edge 18 due to failing loads a valid HDR texture from URL

@cdata cdata left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 🙏

Comment thread src/features/controls.ts
const POLAR_TRIENT_LABELS = ['upper-', '', 'lower-'];

const ORBIT_CAMERA_NEAR_PLANE = FRAMED_HEIGHT / 10.0;
const ORBIT_CAMERA_FAR_PLANE = FRAMED_HEIGHT * 10.0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🍻

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Comment thread src/features/controls.ts Outdated
this[$orbitCamera].near = ORBIT_CAMERA_NEAR_PLANE;
this[$orbitCamera].far = ORBIT_CAMERA_FAR_PLANE;
this[$orbitCamera].updateProjectionMatrix();
this[$orbitCamera] = scene.getCamera();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

Comment thread src/features/controls.ts
getCameraOrbit(): SphericalPosition {
const {theta, phi, radius} = this[$lastSpherical];
return {theta, phi, radius: radius / FRAMED_HEIGHT};
return {theta, phi, radius};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

Comment thread src/features/controls.ts Outdated
if (sphericalValues == null) {
sphericalValues = deserializeSpherical(DEFAULT_CAMERA_ORBIT)!;
}
setCameraOrbit() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 set accessor counterpart to getCameraOrbit but it accepts no arguments. What is being set?
  • The method is de facto public API, but probably should not be. Use a Symbol for protected/private API

Comment thread src/features/controls.ts Resolved
Comment thread src/three-components/ModelScene.js Resolved
Comment thread src/three-components/ModelScene.js Outdated
* dimensions for the encapsulating element.
*/
applyRoomSize() {
applyCanvasSize() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed. I kind of hate naming, so suggestions welcome.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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', () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@elalish elalish May 6, 2019 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure thing, added.


private[$userAdjustOrbit](deltaTheta: number, deltaPhi: number, deltaRadius: number): boolean {
private[$userAdjustOrbit](
deltaTheta: number, deltaPhi: number, deltaRadius: number): boolean {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for running clang-format. We need to set this up to run on a pre-commit hook...

Filed #530

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Maybe, but it’s also an arbitrary scale. There’s an issue around dpr where we should probably fix this.

@cdata

cdata commented May 5, 2019 •

Copy link
Copy Markdown
Contributor

Any idea what's up with the failed builds?

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:

image

...and rebooting the build :)

@elalish
elalish requested a review from cdata May 6, 2019 21:52
@cdata cdata mentioned this pull request May 9, 2019
2 of 11 tasks

@cdata cdata left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

Comment thread src/features/controls.ts Outdated
if (sphericalValues == null) {
sphericalValues = deserializeSpherical(DEFAULT_CAMERA_ORBIT)!;
}
[$applyCameraOrbit]() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's stick with $updateCameraOrbit for this

Comment thread src/features/controls.ts

// 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💯

* 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great comment. It's interesting to see that the notion of a room survives, just in a somewhat deconstructed form...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Comment thread src/three-components/SmoothControls.ts Outdated
* Time and delta are measured in milliseconds.
*/
update(_time: number, delta: number) {
if (this[$targetSpherical] === this[$spherical]) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you! I didn't realize that logic would apply like a pointer comparison. I'll fix that.

Comment thread src/three-components/SmoothControls.ts Outdated
// 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 !;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The space between the property name and the ! is unorthodox. Is clang-format picking up our local project configuration?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Weird indentation on this line

Comment thread src/three-components/SmoothControls.ts Outdated
}

private[$handlePointerDown](event: MouseEvent|TouchEvent) {
private[$handlePointerDown](event: MouseEvent | TouchEvent) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also weird spaces in the union type here

Comment thread src/three-components/SmoothControls.ts Outdated
* Move the camera instantly instead of accelerating toward the setOrbit()
* parameters.
*/
jumpCamera() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is going to be very bike-shed-y of me, but I liked your previous name a lot better (jumpToTarget).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good point, we have overused the word target here:

  • private $targetSpherical - the target destination of the camera
  • public 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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sounds good

scene.alignModel();

expect(scene.model.position).to.be.eql(expectedPosition);
expect(scene.model.position).to.be.eql(new Vector3(-5, -10, -20));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🍻

Comment thread src/three-components/SmoothControls.ts Outdated
}

/**
* Resets the input sensitivity based on model scale, here represented by

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does it only affect input? It seems like $zoomMeters is also used when update is invoked (which is usually caused by configuration changes)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@elalish
elalish requested a review from cdata May 10, 2019 19:50
@cdata

cdata commented May 10, 2019

Copy link
Copy Markdown
Contributor

Really great foundational work here @elalish 👍

@cdata
cdata merged commit 09745dc into master May 10, 2019
@cdata
cdata deleted the room_refactor branch May 10, 2019 20:32
@cdata cdata added this to the v0.4.0 milestone May 11, 2019
elalish added a commit to elalish/model-viewer that referenced this pull request Feb 4, 2020
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Establish concrete definition of 1 meter as it relates to user-configurable API

2 participants