Skip to content

Commit

Permalink
added inputSensitivity (google#3719)
Browse files Browse the repository at this point in the history
* added inputSensitivity

* added docs

* deflake more tests

* condense AR tests

* fix ar test

* check ar test

* more logs

* fix boolean

* more logging

* try a fix

* more async changes

* cleanup
  • Loading branch information
elalish authored Aug 23, 2022
1 parent 47d5ae2 commit 8541890
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 166 deletions.
2 changes: 1 addition & 1 deletion packages/model-viewer/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const HAS_WEBXR_DEVICE_API = navigator.xr != null &&
(self as any).XRSession != null && navigator.xr.isSessionSupported != null;

export const HAS_WEBXR_HIT_TEST_API = HAS_WEBXR_DEVICE_API &&
(self as any).XRSession.prototype.requestHitTestSource;
(self as any).XRSession.prototype.requestHitTestSource != null;

export const HAS_RESIZE_OBSERVER = self.ResizeObserver != null;

Expand Down
27 changes: 13 additions & 14 deletions packages/model-viewer/src/features/ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export const ARMixin = <T extends Constructor<ModelViewerElementBase>>(
this[$arAnchor].removeEventListener('message', this[$onARTap]);
}

async update(changedProperties: Map<string, any>) {
update(changedProperties: Map<string, any>) {
super.update(changedProperties);

if (changedProperties.has('arScale')) {
Expand All @@ -178,16 +178,14 @@ export const ARMixin = <T extends Constructor<ModelViewerElementBase>>(
this[$needsRender]();
}

if (!changedProperties.has('ar') && !changedProperties.has('arModes') &&
!changedProperties.has('src') && !changedProperties.has('iosSrc')) {
return;
}

if (changedProperties.has('arModes')) {
this[$arModes] = deserializeARModes(this.arModes);
}

this[$selectARMode]();
if (changedProperties.has('ar') || changedProperties.has('arModes') ||
changedProperties.has('src') || changedProperties.has('iosSrc')) {
this[$selectARMode]();
}
}

/**
Expand Down Expand Up @@ -216,36 +214,36 @@ configuration or device capabilities');
}

async[$selectARMode]() {
this[$arMode] = ARMode.NONE;
let arMode = ARMode.NONE;
if (this.ar) {
if (this.src != null) {
for (const value of this[$arModes]) {
if (value === 'webxr' && IS_WEBXR_AR_CANDIDATE && !isWebXRBlocked &&
await this[$renderer].arRenderer.supportsPresentation()) {
this[$arMode] = ARMode.WEBXR;
arMode = ARMode.WEBXR;
break;
}
if (value === 'scene-viewer' && IS_SCENEVIEWER_CANDIDATE &&
!isSceneViewerBlocked) {
this[$arMode] = ARMode.SCENE_VIEWER;
arMode = ARMode.SCENE_VIEWER;
break;
}
if (value === 'quick-look' && IS_AR_QUICKLOOK_CANDIDATE) {
this[$arMode] = ARMode.QUICK_LOOK;
arMode = ARMode.QUICK_LOOK;
break;
}
}
}

// The presence of ios-src overrides the absence of quick-look
// ar-mode.
if (!this.canActivateAR && this.iosSrc != null &&
if (arMode === ARMode.NONE && this.iosSrc != null &&
IS_AR_QUICKLOOK_CANDIDATE) {
this[$arMode] = ARMode.QUICK_LOOK;
arMode = ARMode.QUICK_LOOK;
}
}

if (this.canActivateAR) {
if (arMode !== ARMode.NONE) {
this[$arButtonContainer].classList.add('enabled');
this[$arButtonContainer].addEventListener(
'click', this[$onARButtonContainerClick]);
Expand All @@ -260,6 +258,7 @@ configuration or device capabilities');
this.dispatchEvent(
new CustomEvent<ARStatusDetails>('ar-status', {detail: {status}}));
}
this[$arMode] = arMode;
}

protected async[$enterARWithWebXR]() {
Expand Down
11 changes: 10 additions & 1 deletion packages/model-viewer/src/features/controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ export declare interface ControlsInterface {
resetInteractionPrompt(): void;
zoom(keyPresses: number): void;
interact(duration: number, finger0: Finger, finger1?: Finger): void;
inputSensitivity: number;
}

export const ControlsMixin = <T extends Constructor<ModelViewerElementBase>>(
Expand Down Expand Up @@ -361,6 +362,14 @@ export const ControlsMixin = <T extends Constructor<ModelViewerElementBase>>(
protected[$initialized] = false;
protected[$maintainThetaPhi] = false;

get inputSensitivity(): number {
return this[$controls].inputSensitivity;
}

set inputSensitivity(value: number) {
this[$controls].inputSensitivity = value;
}

getCameraOrbit(): SphericalPosition {
const {theta, phi, radius} = this[$lastSpherical];
return {
Expand Down Expand Up @@ -490,7 +499,7 @@ export const ControlsMixin = <T extends Constructor<ModelViewerElementBase>>(
}

if (changedProperties.has('orbitSensitivity')) {
controls.sensitivity = this.orbitSensitivity;
controls.orbitSensitivity = this.orbitSensitivity;
}

if (changedProperties.has('interpolationDecay')) {
Expand Down
4 changes: 2 additions & 2 deletions packages/model-viewer/src/features/loading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ export const LoadingMixin = <T extends Constructor<ModelViewerElementBase>>(
* An enumerable attribute describing under what conditions the
* <model-viewer> should reveal a model to the viewer.
*
* The default value is "auto". The only supported alternative values are
* "interaction" and "manual".
* The default value is "auto". The only supported alternative values is
* "manual".
*/
@property({type: String})
reveal: RevealAttributeValue = RevealStrategy.AUTO;
Expand Down
Loading

0 comments on commit 8541890

Please sign in to comment.