Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional WebXR image tracking changes for native integration #12176

Merged
merged 10 commits into from
Apr 11, 2022
2 changes: 1 addition & 1 deletion packages/dev/core/src/Engines/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ export class Engine extends ThinEngine {
* @param options An object that sets options for the image's extraction.
* @returns ImageBitmap.
*/
public createImageBitmapFromSource(imageSource: string, options?: ImageBitmapOptions): Promise<ImageBitmap> {
public _createImageBitmapFromSource(imageSource: string, options?: ImageBitmapOptions): Promise<ImageBitmap> {
const promise = new Promise<ImageBitmap>((resolve, reject) => {
const image = new Image();
image.onload = () => {
Expand Down
15 changes: 7 additions & 8 deletions packages/dev/core/src/Engines/nativeEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2405,20 +2405,19 @@ export class NativeEngine extends Engine {
* @param options An object that sets options for the image's extraction.
* @returns ImageBitmap
*/
public createImageBitmapFromSource(imageSource: string, options?: ImageBitmapOptions): Promise<ImageBitmap> {
public _createImageBitmapFromSource(imageSource: string, options?: ImageBitmapOptions): Promise<ImageBitmap> {
const promise = new Promise<ImageBitmap>((resolve, reject) => {
const image = this.createCanvasImage();
image.onload = () => {
const imageBitmap = this._engine.createImageBitmap(image);
if (imageBitmap) {
try {
const imageBitmap = this._engine.createImageBitmap(image);
resolve(imageBitmap);
return;
} else {
reject(`Error loading image ${image.src}`);
} catch (error) {
reject(`Error loading image ${image.src} with exception: ${error}`);
}
};
image.onerror = () => {
reject(`Error loading image ${image.src}`);
image.onerror = (error) => {
reject(`Error loading image ${image.src} with exception: ${error}`);
};

image.src = imageSource;
Expand Down
12 changes: 1 addition & 11 deletions packages/dev/core/src/XR/features/WebXRImageTracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { Matrix } from "../../Maths/math.vector";
import { Nullable } from "../../types";
import { Tools } from "../../Misc/tools";

declare const XRImageTrackingResult: XRImageTrackingResult;

/**
* Options interface for the background remover plugin
*/
Expand Down Expand Up @@ -132,14 +130,6 @@ export class WebXRImageTracking extends WebXRAbstractFeature {
return super.detach();
}

/**
* Check if the needed objects are defined.
* This does not mean that the feature is enabled, but that the objects needed are well defined.
*/
public isCompatible(): boolean {
Alex-MSFT marked this conversation as resolved.
Show resolved Hide resolved
return typeof XRImageTrackingResult !== "undefined";
}

/**
* Get a tracked image by its ID.
*
Expand Down Expand Up @@ -174,7 +164,7 @@ export class WebXRImageTracking extends WebXRAbstractFeature {
}
const promises = this.options.images.map((image) => {
if (typeof image.src === "string") {
return this._xrSessionManager.scene.getEngine().createImageBitmapFromSource(image.src);
return this._xrSessionManager.scene.getEngine()._createImageBitmapFromSource(image.src);
} else {
return Promise.resolve(image.src); // resolve is probably unneeded
}
Expand Down
7 changes: 5 additions & 2 deletions packages/dev/core/src/XR/native/nativeXRFrame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { RegisterNativeTypeAsync } from "../../Engines/nativeEngine";
interface INativeXRFrame extends XRFrame {
// Native-only helper functions
getPoseData: (space: XRSpace, baseSpace: XRReferenceSpace, vectorBuffer: ArrayBuffer, matrixBuffer: ArrayBuffer) => XRPose;
_imageTrackingResults?: XRImageTrackingResult[];
}

/** @hidden */
Expand Down Expand Up @@ -76,7 +77,9 @@ export class NativeXRFrame implements XRFrame {
return this._nativeImpl.featurePointCloud;
}

public readonly getImageTrackingResults = this._nativeImpl.getImageTrackingResults!.bind(this._nativeImpl);
public readonly getImageTrackingResults = (): XRImageTrackingResult[] => {
return this._nativeImpl._imageTrackingResults ?? [];
}
}

RegisterNativeTypeAsync("NativeXRFrame", NativeXRFrame);
RegisterNativeTypeAsync("NativeXRFrame", NativeXRFrame);