|
@@ -22,6 +22,7 @@
|
22
|
22
|
|
23
|
23
|
import Speedy from 'speedy-vision';
|
24
|
24
|
import { SpeedyMedia } from 'speedy-vision/types/core/speedy-media';
|
|
25
|
+import { SpeedyMediaSourceNativeElement } from 'speedy-vision/types/core/speedy-media-source';
|
25
|
26
|
import { SpeedyPromise } from 'speedy-vision/types/core/speedy-promise';
|
26
|
27
|
import { Nullable, Utils } from '../utils/utils';
|
27
|
28
|
import { AREvent, AREventTarget } from '../utils/ar-events';
|
|
@@ -525,33 +526,51 @@ export class Session extends AREventTarget<SessionEventType>
|
525
|
526
|
}
|
526
|
527
|
|
527
|
528
|
/**
|
528
|
|
- * Render the user media to the background canvas
|
|
529
|
+ * Render content to the background canvas
|
529
|
530
|
*/
|
530
|
|
- private _renderUserMedia(): void
|
|
531
|
+ private _renderBackground(): void
|
531
|
532
|
{
|
532
|
|
- const media = this._primarySource?._internalMedia;
|
533
|
533
|
const canvas = this._viewport._backgroundCanvas;
|
534
|
534
|
const ctx = canvas.getContext('2d', { alpha: false });
|
535
|
535
|
|
536
|
|
- if(ctx && media && media.type != 'data') {
|
537
|
|
- ctx.imageSmoothingEnabled = false;
|
|
536
|
+ // error?
|
|
537
|
+ if(!ctx)
|
|
538
|
+ return;
|
|
539
|
+ ctx.imageSmoothingEnabled = false;
|
538
|
540
|
|
539
|
|
- // draw user media
|
540
|
|
- const image = media.source as CanvasImageSource;
|
541
|
|
- ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
|
|
541
|
+ // render user media
|
|
542
|
+ if(this._primarySource !== null) {
|
|
543
|
+ const media = this._primarySource._internalMedia;
|
|
544
|
+ this._renderMedia(ctx, media);
|
|
545
|
+ }
|
542
|
546
|
|
543
|
|
- // render output image(s)
|
544
|
|
- for(let i = 0; i < this._trackers.length; i++) {
|
545
|
|
- const media = this._trackers[i]._output.image;
|
546
|
|
- if(media !== undefined) {
|
547
|
|
- const image = media.source as CanvasImageSource;
|
548
|
|
- ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
|
549
|
|
- //ctx.drawImage(image, canvas.width - media.width, canvas.height - media.height, media.width, media.height);
|
550
|
|
- }
|
551
|
|
- }
|
|
547
|
+ // render output image(s)
|
|
548
|
+ for(let i = 0; i < this._trackers.length; i++) {
|
|
549
|
+ const media = this._trackers[i]._output.image;
|
|
550
|
+ if(media !== undefined)
|
|
551
|
+ this._renderMedia(ctx, media);
|
|
552
|
+ }
|
|
553
|
+
|
|
554
|
+ // render gizmos
|
|
555
|
+ this._gizmos._render(this._viewport, this._trackers);
|
|
556
|
+ }
|
552
|
557
|
|
553
|
|
- // render gizmos
|
554
|
|
- this._gizmos._render(this._viewport, this._trackers);
|
|
558
|
+ /**
|
|
559
|
+ * Render a SpeedyMedia
|
|
560
|
+ * @param ctx rendering context
|
|
561
|
+ * @param media
|
|
562
|
+ */
|
|
563
|
+ private _renderMedia(ctx: CanvasRenderingContext2D, media: SpeedyMedia): void
|
|
564
|
+ {
|
|
565
|
+ const canvas = ctx.canvas;
|
|
566
|
+
|
|
567
|
+ if(media.type != 'data') {
|
|
568
|
+ const image = media.source as Exclude<SpeedyMediaSourceNativeElement, ImageData>;
|
|
569
|
+ ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
|
|
570
|
+ }
|
|
571
|
+ else {
|
|
572
|
+ const image = media.source as ImageData;
|
|
573
|
+ ctx.putImageData(image, 0, 0, 0, 0, canvas.width, canvas.height);
|
555
|
574
|
}
|
556
|
575
|
}
|
557
|
576
|
|
|
@@ -676,9 +695,9 @@ export class Session extends AREventTarget<SessionEventType>
|
676
|
695
|
const rafQueue = this._rafQueue.slice(0);
|
677
|
696
|
this._rafQueue.length = 0;
|
678
|
697
|
|
679
|
|
- // render user media
|
|
698
|
+ // render content to the background canvas
|
680
|
699
|
if(!skipUserMedia)
|
681
|
|
- this._renderUserMedia();
|
|
700
|
+ this._renderBackground();
|
682
|
701
|
|
683
|
702
|
// render frame
|
684
|
703
|
for(let i = 0; i < rafQueue.length; i++)
|