Repository navigation
Conversation
cdata
left a comment
There was a problem hiding this comment.
This is really exciting \o/ nothing major needs changing, mostly just cleanup and bike shedding on my part. I do think that we might be allowing framing to bleed into SmoothControls a bit, and that we should probably strive to keep a clean separation between those concepts. I'm interested to hear your thoughts on this.
| return null; | ||
| }; | ||
|
|
||
| export const deserializeAngleToDeg = (angleString: string): number|null => { |
| try { | ||
| const angleValueNode = parseValues(angleString); | ||
|
|
||
| if (angleValueNode.length === 1) { |
There was a problem hiding this comment.
Does the length imply a unit?
The unit should probably be inferred from angleValueNode.unit
There was a problem hiding this comment.
No, that's the desired (output) units I'm specifying there; the input units are inferred.
| if (typeof destRadius === 'string') { | ||
| switch (destRadius) { | ||
| default: | ||
| case 'auto': |
There was a problem hiding this comment.
The notion of "auto" is domain-specific to <model-viewer>. SmoothControls is domain-agnostic. Do we gain something from moving this domain-specific concept into SmoothControls?
There was a problem hiding this comment.
The "auto" keyword means apply the ideal camera distance, which I've moved into SmoothControls because I think it is more generically useful than to just <model-viewer>. However, we could tweak the API shape to clean it up a bit; maybe skip the string and use null to represent auto?
| * | ||
| */ | ||
| updateFramedHeight(framedHeight: number) { | ||
| updateFraming(framedHeight: number, modelDepth: number, aspect: number) { |
There was a problem hiding this comment.
Why should camera controls care about framing? Should there be a higher-order construct that understands framing so that the camera controls don't have to?
There was a problem hiding this comment.
Framing seems pretty central to camera controls to me. What was strange was that both controls.ts and SmoothControls.ts were manipulating the camera, and when I was working on them I was running into a lot of bugs because it was unclear when one was stomping on the other. Also they were passing a lot of values back and forth, which is an indicator to me that the concepts are not well isolated. If you want to go down the bike shed route, I might rename SmoothControls to CameraControls and controls to CameraAttributes to make the current separation more clear.
There was a problem hiding this comment.
These are the questions that are running through my mind as I consider this:
- If I used
SmoothControlsin a Three.js application that had nothing to do with<model-viewer>, would "framing" have meaning to me? - If I replaced Three.js with another renderer (thus requiring a new version of
SmoothControlsthat worked in terms of that renderer's API), would I have to re-implement the notion of framing entirely? - Can the concept of framing be implemented without direct access to the private implementation details of
SmoothControls?
Framing as a concept is currently part of the ModelScene. This makes sense after a fashion. After all, what purpose does the scene have if not to set the stage for the viewer?
OTOH it may make sense to extract it from ModelScene and implement it in a new construct that integrates a ModelScene and SmoothControls. But, adding it directly into SmoothControls is conflating two concepts without clear justification. Yes, it's obvious that there is overlap in terms of values that are used in both cases. But it's not obvious that there is conceptual overlap (or even API access requirements) to justify moving the implementation here.
There was a problem hiding this comment.
Put this back too, but keeping camera ownership in one place.
There was a problem hiding this comment.
Thanks!
We spoke f2f about this topic. SmoothControls is responsible for manipulating the position (and now FOV) of the camera, while another entity (currently ModelScene) is responsible for determining the "framing" of the model by adjusting the frustum and repositioning the camera as needed.
Position / FOV manipulation is the domain of SmoothControls, so ModelScene should never perform those changes directly on the camera instance.
FOV sits at an intersection between these responsibilities. It seems like there is a lot of meat left on the bone for improvement in how the camera reference is manipulated by these different constructs.
| cameraOrbit: string = DEFAULT_CAMERA_ORBIT; | ||
|
|
||
| @property( | ||
| {type: String, attribute: 'camera-FOV', hasChanged: () => true}) |
There was a problem hiding this comment.
FYI HTML5 DOM attribute names are case insensitive
| return x; | ||
| // Critically damped | ||
| const acceleration = NATURAL_FREQ * NATURAL_FREQ * (xDest - x) - | ||
| 2 * NATURAL_FREQ * this[$velocity]; |
There was a problem hiding this comment.
Avoid abbreviations (NATURAL_FREQ and xDest in this case)
| if (Math.abs(this[$velocity]) < NIL_SPEED * xNormalization && | ||
| acceleration * (xDest - x) <= 0) { | ||
| // This ensures the controls settle and stop calling this function instead | ||
| // of asymptotically approaching their destination. |
| private[$destSpherical]: Spherical = new Spherical(); | ||
| private[$thetaDamper]: Damper = new Damper(); | ||
| private[$phiDamper]: Damper = new Damper(); | ||
| private[$radiusDamper]: Damper = new Damper(); |
There was a problem hiding this comment.
We are completely inconsistent with this, but I recently learned that TypeScript will infer a class field or variable's type based on initial assignment. Feel free to take advantage of this for brevity whenever you feel like it 💁♂
| this[$options] = Object.assign({}, DEFAULT_OPTIONS); | ||
|
|
||
| this.setOrbit(); | ||
| this.setOrbit(0, Math.PI / 2, 1); |
There was a problem hiding this comment.
Previously, initial orbital position was inferred from the configured camera's position. One reason why this seems preferable is that it gives the user the ability to change camera control schemes without forcing the camera to reset its position to some fixed default.
OTOH this is of marginal benefit to <model-viewer>. But, the fixed defaults used here seem separable from SmoothControls implementation...
There was a problem hiding this comment.
I removed that because I thought it was confusing. Sure, it uses the camera's existing position, but then ignores its orientation and instead points at the target, which you were not allowed to configure yet. Plus the most common case is that the camera is at the origin, which leads to a divide by zero, which was only solved by some surprising side effects of the default minimum radius. I think this will be more clear for developers.
| private[$upQuaternion]: Quaternion = new Quaternion(); | ||
| private[$upQuaternionInverse]: Quaternion = new Quaternion(); | ||
| private[$spherical]: Spherical = new Spherical(); | ||
| private[$targetSpherical]: Spherical = new Spherical(); |
There was a problem hiding this comment.
Thanks for fixing our terminology usage here 🍻
cdata
left a comment
There was a problem hiding this comment.
A bit more cleanup requested 🙇
|
|
||
| @property( | ||
| {type: String, attribute: 'camera-fov', hasChanged: () => true}) | ||
| fieldOfView: string = DEFAULT_CAMERA_FOV; |
| cameraOrbit: string = DEFAULT_CAMERA_ORBIT; | ||
|
|
||
| @property( | ||
| {type: String, attribute: 'camera-fov', hasChanged: () => true}) |
There was a problem hiding this comment.
Make sure to update the attribute name here to field-of-view
|
|
||
| protected[$controls]: SmoothControls; | ||
|
|
||
| protected[$idealCameraDistance] = -1.0; |
There was a problem hiding this comment.
Is -1.0 a stand-in for "no value" here? If so, I would recommend using null instead, as it is more conventionally consistent with the rest of the library.
| return {theta, phi, radius}; | ||
| } | ||
|
|
||
| getCameraFov(): number { |
There was a problem hiding this comment.
Let's change this to getFieldOfView() to be inline with the property/attribute
| } | ||
| } | ||
|
|
||
| [$updateCameraFov]() { |
| }); | ||
| }); | ||
|
|
||
| suite('deserializeAngleToDeg', () => { |
| export const settleControls = (controls: SmoothControls) => | ||
| controls.update(performance.now(), FIFTY_FRAME_DELTA); | ||
|
|
||
| suite('Damper', () => { |
|
|
||
| update( | ||
| x: number, xGoal: number, timeStepMilliseconds: number, | ||
| xNormalization: number): number { |
There was a problem hiding this comment.
thx clang-format 🙄 very readable
| this[$velocity] = 0; | ||
| return xGoal; | ||
| } else | ||
| return x + this[$velocity] * timeStepMilliseconds; |
There was a problem hiding this comment.
This should be enforced by linting in some way, but conventionally we always express if/else clauses as blocks. Please wrap this clause and the others above in braces { }
Filed #608 to make improvements here
There was a problem hiding this comment.
Not sure why this doesn't show as outdated, but I did fix this, along with any other unbracketed if statements I could find. I'm used to the Google C++ style guide where the brackets are omitted.
| this[$zoomMeters] = framedHeight / 10; | ||
| updateIntrinsics( | ||
| nearPlane: number, farPlane: number, aspect: number, | ||
| zoomSensitivity: number) { |
cdata
left a comment
There was a problem hiding this comment.
Sweet! So excited for this...
* 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
Adjustable FOV (google#563) * 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
Reference Issue
Fixes #232, #537
This adds the camera-FOV attribute to the element, allowing control of the camera's field of view. In the process of making SmoothControls properly interpolate FOV, I also rewrote the interpolation scheme to be simpler, with fewer parameters and extensible to any number of interpolated states, which should help when we want to add configurable targets. I also removed the camera from controls.ts, such that SmoothControls is now the only place where the camera is updated.
One thing I have not done, but I mentioned in #232 was to change the definition of FOV from vertical FOV to widest FOV. I think this would be a good change to make, but the rest of this PR should not affect framing at all, so that might be best in a separate one, assuming others agree to the change. Also, it looks like the fidelity goldens are out of date again.