Skip to content

Commit

Permalink
feat(app): add toggle for AR
Browse files Browse the repository at this point in the history
  • Loading branch information
9inpachi committed Jun 19, 2021
1 parent fdd492a commit a703bdd
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/phoenix-ng/projects/phoenix-app/src/assets/icons/ar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
AnimateCameraComponent,
AnimateEventComponent,
VrToggleComponent,
ArToggleComponent,
SSModeComponent,
PerformanceToggleComponent,
ShareLinkComponent,
Expand Down Expand Up @@ -87,6 +88,7 @@ const PHOENIX_COMPONENTS: Type<any>[] = [
AnimateCameraComponent,
AnimateEventComponent,
VrToggleComponent,
ArToggleComponent,
SSModeComponent,
PerformanceToggleComponent,
LoaderComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<app-menu-toggle
[disabled]="!arSupported"
[active]="arActive"
icon="ar"
(click)="arSupported && toggleAr()"
[tooltip]="
arSupported ? (arActive ? 'Exit AR' : 'Enter AR') : 'AR not supported'
"
>
</app-menu-toggle>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { ArToggleComponent } from './ar-toggle.component';

describe('ArToggleComponent', () => {
let component: ArToggleComponent;
let fixture: ComponentFixture<ArToggleComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ ArToggleComponent ]
})
.compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(ArToggleComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Component } from '@angular/core';
import { EventDisplayService } from '../../../services/event-display.service';
import { ARManager } from 'phoenix-event-display';

@Component({
selector: 'app-ar-toggle',
templateUrl: './ar-toggle.component.html',
styleUrls: ['./ar-toggle.component.scss'],
})
export class ArToggleComponent {
arSupported: boolean = false;
arActive: boolean = false;

constructor(private eventDisplay: EventDisplayService) {
// NOTE: WebXR needs secure HTTPS context
if ('xr' in navigator) {
(navigator as any)?.xr
?.isSessionSupported?.(ARManager.SESSION_TYPE)
.then((supported: boolean) => {
if (supported) {
this.arSupported = true;
}
});
} // else AR not supported
}

toggleAr() {
// If toggling AR on
if (!this.arActive) {
this.eventDisplay.initAR(() => {
this.arActive = false;
// Disable renderer XR and remove animation loop
this.eventDisplay.endAR();
});
this.arActive = true;
} else {
this.eventDisplay.endAR();
this.arActive = false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export * from './tree-menu/tree-menu.component';
export * from './tree-menu/tree-menu-item/tree-menu-item.component';
export * from './view-options/view-options.component';
export * from './vr-toggle/vr-toggle.component';
export * from './ar-toggle/ar-toggle.component';
export * from './zoom-controls/zoom-controls.component';
export * from './ss-mode/ss-mode.component';
export * from './performance-toggle/performance-toggle.component';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
<!-- Toggle for VR -->
<app-vr-toggle></app-vr-toggle>

<!-- Toggle for AR -->
<app-ar-toggle></app-ar-toggle>

<!-- Toggle for screenshot mode -->
<app-ss-mode></app-ss-mode>

Expand Down

0 comments on commit a703bdd

Please sign in to comment.