-
Notifications
You must be signed in to change notification settings - Fork 838
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
Announce camera orientation #325
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,12 +13,20 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
import {PerspectiveCamera, Vector3} from 'three'; | ||
import {PerspectiveCamera, Spherical, Vector3} from 'three'; | ||
|
||
import {$ariaLabel, $needsRender, $onModelLoad, $onResize, $scene, $tick} from '../model-viewer-base.js'; | ||
import {FRAMED_HEIGHT} from '../three-components/ModelScene.js'; | ||
import {SmoothControls} from '../three-components/SmoothControls.js'; | ||
|
||
const HALF_PI = Math.PI / 2.0; | ||
const THIRD_PI = Math.PI / 3.0; | ||
const QUARTER_PI = HALF_PI / 2.0; | ||
const PHI = 2.0 * Math.PI; | ||
|
||
const AZIMUTHAL_QUADRANT_LABELS = ['front', 'right', 'back', 'left']; | ||
const POLAR_TRIENT_LABELS = ['upper-', '', 'lower-']; | ||
|
||
const ORBIT_NEAR_PLANE = 0.01; | ||
const ORBIT_FAR_PLANE = 1000; | ||
|
||
|
@@ -43,6 +51,8 @@ const $waitingToPromptUser = Symbol('waitingToPromptUser'); | |
const $userPromptedOnce = Symbol('userPromptedOnce'); | ||
const $idleTime = Symbol('idleTime'); | ||
|
||
const $lastSpherical = Symbol('lastSpherical'); | ||
|
||
export const $promptElement = Symbol('promptElement'); | ||
|
||
export const ControlsMixin = (ModelViewerElement) => { | ||
|
@@ -69,6 +79,8 @@ export const ControlsMixin = (ModelViewerElement) => { | |
this[$orbitCamera].updateProjectionMatrix(); | ||
this[$controls] = null; | ||
|
||
this[$lastSpherical] = new Spherical(); | ||
|
||
this[$changeHandler] = () => this[$onChange](); | ||
this[$focusHandler] = () => this[$onFocus](); | ||
this[$blurHandler] = () => this[$onBlur](); | ||
|
@@ -170,8 +182,10 @@ export const ControlsMixin = (ModelViewerElement) => { | |
// original, non-prompt label if appropriate. If the user has already | ||
// interacted, they no longer need to hear the prompt. Otherwise, they | ||
// will hear it again after the idle prompt threshold has been crossed. | ||
if (canvas.getAttribute('aria-label') === IDLE_PROMPT) { | ||
canvas.setAttribute('aria-label', this[$ariaLabel]); | ||
const ariaLabel = this[$ariaLabel]; | ||
|
||
if (canvas.getAttribute('aria-label') !== ariaLabel) { | ||
canvas.setAttribute('aria-label', ariaLabel); | ||
} | ||
|
||
// NOTE(cdata): When focused, if the user has yet to interact with the | ||
|
@@ -202,6 +216,31 @@ export const ControlsMixin = (ModelViewerElement) => { | |
if (this[$userPromptedOnce]) { | ||
this[$shouldPromptUserToInteract] = false; | ||
} | ||
|
||
const {theta: lastTheta, phi: lastPhi} = this[$lastSpherical]; | ||
const {theta, phi} = | ||
this[$controls].getCameraSpherical(this[$lastSpherical]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
const lastAzimuthalQuadrant = | ||
(4 + Math.floor(((lastTheta % PHI) + QUARTER_PI) / HALF_PI)) % 4; | ||
const azimuthalQuadrant = | ||
(4 + Math.floor(((theta % PHI) + QUARTER_PI) / HALF_PI)) % 4; | ||
|
||
const lastPolarTrient = Math.floor(lastPhi / THIRD_PI); | ||
const polarTrient = Math.floor(phi / THIRD_PI); | ||
|
||
if (azimuthalQuadrant !== lastAzimuthalQuadrant || | ||
polarTrient !== lastPolarTrient) { | ||
const {canvas} = this[$scene]; | ||
const azimuthalQuadrantLabel = | ||
AZIMUTHAL_QUADRANT_LABELS[azimuthalQuadrant]; | ||
const polarTrientLabel = POLAR_TRIENT_LABELS[polarTrient]; | ||
|
||
const ariaLabel = | ||
`View from stage ${polarTrientLabel}${azimuthalQuadrantLabel}`; | ||
|
||
canvas.setAttribute('aria-label', ariaLabel); | ||
} | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I'm hungry 🍰