Skip to content

Allow skipping interpolation when changing camera - #614

Merged
elalish merged 27 commits into
masterfrom
disable_interp
Jun 10, 2019
Merged

elalish merged 27 commits into
masterfrom
disable_interp

Conversation

@elalish

@elalish elalish commented Jun 7, 2019 •

Copy link
Copy Markdown
Contributor

Fixes #454

This is a pretty simple change to skip interpolation by calling the jumpCameraToGoal method, here exposed on the element.

@elalish
elalish requested a review from cdata June 7, 2019 18:12
@elalish elalish self-assigned this Jun 7, 2019

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

There is an important subtlety to how property values propagate after they have been set. Property change notifications are batched internally by enqueueing them in a microtask.

A brief aside on microtasks (skip if they aren't news to you):

Microtasks are a JavaScript event loop concept. Roughly speaking, there is a FIFO queue of additional tasks that get run at the end of the current event loop step (called a "task"). Microtasks are useful if you want some work to happen synchronously but not until the current call stack of the event loop unwinds, and also their qualities are essential to the underlying behavior of many web APIs.

Back to the topic at hand:

Our property updating semantics and timing are defined by the base class we depend on from LitElement.

So, if you set a property in a test, you need to wait on the microtask queue so that the change can take effect in the element. An easy way to do this in a test looks like this:

import {timePasses} from '../helpers.js';

// later...

test('property-changing test', async () => {
  element.someProperty = 'value';
  // With no arguments, this will enqueue a microtask and
  // defers until after the microtask is dequeued
  await timePasses();
  // At this point you can assume that the change has taken effect
});

An important but subtle detail of the example is that the test callback is an async function so that we can use the await keyword in the function body.

Another strategy that we use circumstantially is to dispatch an event from the element and wait for that before measuring the effects of a property change. This approach cannot always be used, however, because events dispatched on the element constitute public API.

Comment thread index.html Outdated
attribute on account of user interaction or camera interpolation.</p>
</li>
<li>
<div>jumpToGoal()</div>

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 can make the referential leap with getFieldOfView to understand that it is referring to the camera (what else could FOV be referring to?). jumpToGoal is relatively less clear.

WDYT about jumpCameraToGoal()?

@elalish

elalish commented Jun 7, 2019 •

Copy link
Copy Markdown
Contributor Author

Thanks for the explanation, this has now been fixed, and the synchronicity is checked by its test.

@elalish
elalish changed the base branch from FOV to master June 10, 2019 17:56
@elalish
elalish requested a review from cdata June 10, 2019 18:00
Comment thread index.html Outdated
<li>
<div>jumpCameraToGoal()</div>
<p>Instantaneously updates the camera to the specified goal state
instead of interpolating the motion over time.</p>

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.

It might be worth padding the language here to set the expectations about what "instantaneous" means. Maybe rephrase to read along the lines of, "the camera will immediately move to its last configured goals on the next update."

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

Minor docs change requested, but otherwise this is looking 💯

@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 as usual 🙌

@elalish
elalish merged commit e646f53 into master Jun 10, 2019
@elalish
elalish deleted the disable_interp branch June 10, 2019 19:53
@cdata cdata added this to the v0.4.0 milestone Jun 13, 2019
elalish added a commit to elalish/model-viewer that referenced this pull request Feb 4, 2020
 
Allow skipping interpolation when changing camera (google#614)

* pulled camera out of controls.ts

* interaction is smooth, 15 tests failing

* fixed some tests, 4 to go

* test assumption problem

* two tests failing

* all tests passing

* added tests

* fixed google#537

* moved framing back to controls.ts

* fixed resize bug

* added conversion tests

* rename dest -> goal

* addressing feedback

* added damper tests

* addressing feedback

* exposed jumpToGoal method

* test still fails

* update doc

* made jumpCameraToGoal synchronize with property updates

* TS cleanup

* fixed typo

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

Ability to disable camera interpolation when changing camera orbital position

2 participants