Skip to content

Commit

Permalink
feat(anchor): add createAnchor method on XRHitTestResult
Browse files Browse the repository at this point in the history
Summary: The createAnchor method is not present in the HitTest module https://immersive-web.github.io/hit-test/#xr-hit-test-result-interface, but is tucked away in Anchors Module https://immersive-web.github.io/anchors/#dom-xrhittestresult-createanchor. This diff implements the createAnchor method on XRHitTestResult

Reviewed By: snagy

Differential Revision:
D44428490

Privacy Context Container: L1164747

fbshipit-source-id: f1894a89bdf6790e469819272c99ff01686ee4d9
  • Loading branch information
felixtrz authored and facebook-github-bot committed Mar 27, 2023
1 parent b780071 commit 0dff0fc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
2 changes: 1 addition & 1 deletion polyfill/XRScene.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export default class XRScene {
this.raycaster = new Raycaster();
this.hitTestTarget = new Object3D();
this.hitTestMarker = new Object3D();
this.hitTestMarker.rotateX(Math.PI / 2);
this.hitTestMarker.rotateX(-Math.PI / 2);
this.hitTestTarget.add(this.hitTestMarker);
}

Expand Down
44 changes: 30 additions & 14 deletions polyfill/api/XRHitTestResult.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
export const PRIVATE = Symbol('@@webxr-polyfill/XRHitTestResult');

import { XRAnchor } from './XRAnchor';
import { PRIVATE as XRFRAME_PRIVATE } from 'webxr-polyfill/src/api/XRFrame';
import XRSpace from 'webxr-polyfill/src/api/XRSpace';
import {
mat4
} from 'gl-matrix';
import { mat4 } from 'gl-matrix';

export default class XRHitTestResult {
constructor(frame, transform) {
this[PRIVATE] = {
frame,
transform
};
}
constructor(frame, transform) {
this[PRIVATE] = {
frame,
transform,
};
}

getPose(baseSpace) {
const space = new XRSpace();
space._baseMatrix = mat4.copy(
mat4.create(),
this[PRIVATE].transform.matrix,
);
return this[PRIVATE].frame.getPose(space, baseSpace);
}

getPose(baseSpace) {
const space = new XRSpace();
space._baseMatrix = mat4.copy(mat4.create(), this[PRIVATE].transform.matrix);
return this[PRIVATE].frame.getPose(space, baseSpace);
}
async createAnchor() {
const anchorSpace = new XRSpace();
anchorSpace._baseMatrix = mat4.copy(
mat4.create(),
this[PRIVATE].transform.matrix,
);
const session = this[PRIVATE].frame[XRFRAME_PRIVATE].session;
const anchor = new XRAnchor(session, anchorSpace);
session.addTrackedAnchor(anchor);
return anchor;
}
}

0 comments on commit 0dff0fc

Please sign in to comment.