Repository navigation
Implement SmoothControls - #288
Conversation
jsantell
left a comment
There was a problem hiding this comment.
Looks great, excellent work! I just reviewed the code, not the UX of the changes. A handful of comments/questions, but the gifs look soooo good, and hope & dream to see a future of these controls beyond just model-viewer 🥂
| "@polymer/paper-button": "^3.0.1", | ||
| "@polymer/paper-radio-group": "^3.0.1", | ||
| "@polymer/paper-slider": "^3.0.1", | ||
| "@types/three": "^0.93.12", |
There was a problem hiding this comment.
Is there any correllation here with three version? Doesn't seem to be, but wondering how to handle when latest three is out of sync here
There was a problem hiding this comment.
That's a good point. Three.js's API is unusually stable thanks to @mrdoob 's strong discipline for maintaining backwards-compatibility. But, I suspect there is a real risk here of the types falling out of date, and I also suspect that these are only updated as people notice that the API has changed.
There was a problem hiding this comment.
@mrdoob I would second that person's recommendation for another reason: @types/three do not currently work if we import individual modules. This would be easy to fix with "sidecar" type declarations.
But, it's also a large burden on you and your contributors to maintain those type files, so I understand if that doesn't seem like a good idea to you.
| }); | ||
| }); | ||
|
|
||
| suite('step', () => { |
There was a problem hiding this comment.
For functions like step, clamp, I wonder if we could just leverage lodash or something for these small utilities (although a quick look, there is no step function in lodash, maybe under another name)? No strong feelings
There was a problem hiding this comment.
Yeah, we should definitely consider that as the utils file grows. The cost of adding a third party dependency is greater than zero, though, so we should weigh it against the cost of 10s of lines of first-party JS.
| const MAXIMUM_DAMPENING_FACTOR = 0.05; | ||
| const MINIMUM_DAMPENING_FACTOR = 0.3; | ||
| const FRAME_MILLISECONDS = 1000.0 / 60.0; | ||
| const TWO_PI = 2 * Math.PI; |
| * interpolating its position and rotation until it lines up with the | ||
| * designated target orbital position. | ||
| */ | ||
| update(_time: number, delta: number) { |
There was a problem hiding this comment.
I've seen delta be both milliseconds and seconds in three controls -- milliseconds seems more common, but would be worthwhile documenting
| zoomPolicy: 'allow-when-focused' | ||
| }); | ||
|
|
||
| const $constraints = Symbol('constraints'); |
There was a problem hiding this comment.
Lots of symbols! I think it'd be helpful having a one line comment above each group to indicate how they're used, e.g. // Mouse events
There was a problem hiding this comment.
Yeah, it's a bit of a mess. I'll try to clean it up.
There was a problem hiding this comment.
I added comments to the various groupings of symbols
| element.style.cursor = 'grab'; | ||
|
|
||
| this[$previousPosition].copy(this.camera.position); | ||
| this[$positionToSpherical](this.camera.position, this[$spherical]); |
There was a problem hiding this comment.
This assumes the camera has no parent, and that its initial pose was set via TRS rather than a matrix, and positionToSpherical assumes the position in world space as well (since subtracting from the sceneOrigin) (which is probably ok, but should be clear on that caveat)
There was a problem hiding this comment.
I believe these are the same assumptions made by OrbitControls. I'll double check and document where we diverge.
There was a problem hiding this comment.
Looks like these assumptions are the same. I'll document explicitly that we assume TRS is synced with the object's matrix.
| } | ||
|
|
||
| private[$handleWheel](event: Event) { | ||
| const rootNode = this.element.getRootNode() as Document | ShadowRoot; |
There was a problem hiding this comment.
Do the web component polyfills add this method? https://developer.mozilla.org/en-US/docs/Web/API/Node/getRootNode
There was a problem hiding this comment.
| maximumPolarAngle?: number; | ||
| minimumAzimuthalAngle?: number; | ||
| maximumAzimuthalAngle?: number; | ||
| decelerationMargin?: number; |
There was a problem hiding this comment.
Would be helpful for some comments on decelerationMargin, acceleration, dampeningScale, eventHandlingBehavior, zoomPolicy -- when using controls like this, they're often arbitrary scales and requires some plugging in numbers to find an acceptable range, rather than something bound to time, e.g. m/s^2
| export type ZoomPolicy = 'always-allow'|'allow-when-focused'; | ||
| export type TouchMode = 'rotate'|'zoom'; | ||
|
|
||
| export interface SmoothControlsConstraints { |
There was a problem hiding this comment.
I'm not sure of the word "constraints" (and below, e.g. applyConstraints), as it's accurate for most of the options, but less obvious for acceleration, etc.
There was a problem hiding this comment.
👍 I don't love it either, open to alternatives
There was a problem hiding this comment.
Maybe configuration or options or something, but don't feel strongly (and more important if used outside of model-viewer)
|
|
||
| export interface SmoothControlsConstraints { | ||
| nearOrbitRadius?: number; | ||
| farOrbitRadius?: number; |
There was a problem hiding this comment.
near and far imply (IMO) that it has something to do with the camera's near and far planes and was unclear what these values did until digging more -- maybe, similar to the polar/azimuthal config, and using terminology used elsewhere in the controls (zoom and radius), maybe something like minimumZoom/maximumZoom, minimumRadius, maxiumRadius
There was a problem hiding this comment.
I haven't fully thought this out, but it seems like zoom and radius are distinct things and that it is better to be explicit about what is being adjusted.
I agree that near and far are weird words to use, can change that to minimum and maximum.
There was a problem hiding this comment.
Looking again, agreed that zoom doesn't match -- minimumRadius and maximumRadius sound great to me and inline with the other options
| * limitations under the License. | ||
| */ | ||
|
|
||
| import {Camera, EventDispatcher, Quaternion, Spherical, Vector2, Vector3} from 'three'; |
There was a problem hiding this comment.
Don't you want to import directly from source?
There was a problem hiding this comment.
I do, but see comment above about type declarations #288 (comment)
a303722 to
d17dfde
Compare
jsantell
left a comment
There was a problem hiding this comment.
Thanks for the changes! LGTM, but think the skysphere logic may have changed
| [$tick](time, delta) { | ||
| super[$tick](time, delta); | ||
| const camera = this[$scene].getCamera(); | ||
| this[$scene].skysphere.position.copy(camera.position); |
There was a problem hiding this comment.
Why is this no longer needed? Wouldn't this change the skysphere behavior to 'zoom' when zooming in on the model, as opposed to it's current implementation? I think there are also some scenarios where the skysphere may not be big enough, but I think that was due to panning in orbit controls
There was a problem hiding this comment.
Speaking subjectively, the behavior without this line looks more natural to me when moving towards / away from the model.
There was a problem hiding this comment.
I agree, and that's what we had originally -- I believe @mrdoob mentioned that a skybox moving with the camera was the common/expected skybox behavior though
There was a problem hiding this comment.
I asked @smalls for an additional take and he prefers skybox not zooming, so I will revert this line
There was a problem hiding this comment.
Backreferencing #100 so that we can track this discussion as part of that issue
| maximumPolarAngle?: number; | ||
| minimumAzimuthalAngle?: number; | ||
| maximumAzimuthalAngle?: number; | ||
| decelerationMargin?: number; |
d17dfde to
08fd33a
Compare
This change proposes
SmoothControlsas a more suitable alternative toOrbitControls.PatchedOrbitControlsis no longer necessary)OrbitControls(pole, azimuth, radius)Basic Example
Background Image
Keyboard Input
Scrolling Behavior
Fixes #75
Fixes #178