Skip to content

Implement camera-orbit attribute - #452

Merged
cdata merged 7 commits into
masterfrom
configurable-camera-orbit
Apr 3, 2019
Merged

cdata merged 7 commits into
masterfrom
configurable-camera-orbit

Conversation

@cdata

@cdata cdata commented Mar 29, 2019 •

Copy link
Copy Markdown
Contributor

Configurable camera-orbit attribute

This change proposes the addition of a camera-orbit attribute to enable users to control the starting and subsequent positions of the camera long a spherical orbit centered on the model.


Highlights

  • camera-orbit attribute allows CSS-like configuration of starting and subsequent camera positions
    • Accepts values in the form of $theta $phi $radius
    • Example accepted values include: 0deg 75deg 1m, 1 2 3, 1rad 2deg 100cm
    • Default units are radians for angles, meters for radius
    • Special radius value auto: refers to the "ideal" camera distance as determined by scene framing
    • Camera interpolates from its current position to subsequent values of camera-orbit (see also Ability to disable camera interpolation when changing camera orbital position #454)
  • getCameraOrbit method for real-time querying of current orbital position
    • Realtime position may not align to attribute on account of interpolation or user interaction
  • interaction-prompt-threshold attribute controls the time that must have passed before an interaction prompt is presented to the user
  • 🚨 BREAKING CHANGE: The controls attribute has been renamed to camera-controls
    • Rationale: disambiguates from controls attribute in the <video> element
  • New modules for parsing and converting complex attribute values have been introduced
  • Lots of new tests for all of above have been added
  • Controls feature has been converted to TypeScript
  • A new documentation section for "Staging & Camera Control" has been added
  • A new model has been contributed to help document the align-model attribute introduced in Implement align-model attribute #441

Name rationale

I waffled a bit when deciding what name to propose for the attribute. Initially, I thought that camera-position was a good name. But, position is already used by Three.js (and other libraries) to refer to the cartesian coordinates of things in 3D space. This attribute, by contrast, represents the spherical coordinates of the camera relative to a separately defined target origin.

As far as API shape is concerned, the spherical position can be queried by the user, and is represented by a plain-object version of Three.js's Spherical data structure e.g., { theta, phi, radius }. However, it might make sense to name this object's properties more explicitly, e.g., { azimuth, inclination, radius }. Feedback here is requested.

Future work

Fixes #98

Additional fixes have been rolled in from #457 :

Fixes #435
Fixes #437
Fixes #446
Fixes #456

Comment thread src/conversions.ts Outdated
/**
* Convert a number expressing degrees to a number expressing radians.
*/
const degreesToRadians = (() => {

Copy link
Copy Markdown
Collaborator

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.

👍 good catch, will fix!

@cdata
cdata force-pushed the configurable-camera-orbit branch from f5cc8f3 to 52d9f5e Compare March 30, 2019 19:44
@cdata
cdata marked this pull request as ready for review March 30, 2019 19:45
@cdata cdata added this to the v0.2.0 milestone Mar 30, 2019
@cdata
cdata requested review from jsantell, mrdoob and smalls April 1, 2019 15:15
const expect = chai.expect;

suite('conversions', () => {
suite('deserializeSpherical', () => {

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.

Nice! So glad to see the unit tests :)

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.

🍻

smalls
smalls previously approved these changes Apr 1, 2019
Comment thread src/conversions.ts
const value = parseFloat(lengthValueNode.value as any);

if ((self as any).isNaN(value)) {
return 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.

Why not throw an exception or log an error?

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 rationale here is that 0 is a reasonable default for any given meters length that cannot be parsed correctly. This is an homage to the CSS roots of this configuration value style. CSS doesn't throw or even warn you for invalid values. Instead, it substitutes a reasonable default.

Comment thread src/parsers.ts
@@ -0,0 +1,55 @@
export interface ValueNode {

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.

Missing license.

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.

Will fix

Comment thread src/parsers.ts Outdated
};

const extractValue = (() => {
const VALUE_RE = /^(([^-^.^0-9].*)|([-]?[0-9.]+))/;

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.

In [^-^.^0-9], I think you only need the first ^ (that negates the entire class; the additional ^ match the actual ^ character). New thing I learned: you don't seem to need to escape the . inside of the class. I think that ([^-\.0-9]) is equivalent (or ([^-.0-9]) but I guess I'm not comfortable with my new fact).

Logically, extracting the value and the units feels paired, but here they're in separate methods. I'd see about combining them (I thought about suggesting putting them in the same regex, but I think that might make things more confusing); or, documenting the flow a bit more.

@smalls smalls Apr 1, 2019 •

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 makes a bit more logical sense to me (ha, I know, regexes), although it still only extracts the values. I think it's a bit stricter (although still not strict) - specifically, "#a3#fd" now only matches "#a3".

^((?:(?:#|[a-zA-Z])[a-zA-Z\d]*)|(?:-?[\d.]+))

Oh! This will get the units too (in a second capture group). If my comment above regarding capturing both the values & units in the same method makes sense, and then the whole string can be matched (taking advantage of the strictness).

^((?:(?:#|[a-zA-Z])[a-zA-Z\d]*)|(?:-?[\d.]+))([a-zA-Z]*)$

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.

Doing everything in one JavaScript RegExp match is way faster than approaches that require an extra String.prototype.replace (in Chrome, anyway):

image

Good call on this. Will fix.

Fixes fidelity test camera orientation and interaction prompt timing
@cdata

cdata commented Apr 3, 2019

Copy link
Copy Markdown
Contributor Author

FYI @svinkle this change will pull in the fix for screen reader SVG discoverability.

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 Author

Choose a reason for hiding this comment

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

FYI @mrdoob I renamed these :)

@cdata
cdata merged commit ee577ad into master Apr 3, 2019
@cdata
cdata deleted the configurable-camera-orbit branch April 3, 2019 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants