Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#68549 [WebXR] Add detectedPlanes, improve …
Browse files Browse the repository at this point in the history
…detectedMeshes, add tests by @sorskoot
  • Loading branch information
sorskoot authored Feb 8, 2024
1 parent 52aee1d commit d934214
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 23 deletions.
64 changes: 41 additions & 23 deletions types/webxr/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,15 +329,6 @@ interface XRFrame {
* @param referenceSpace
*/
getViewerPose(referenceSpace: XRReferenceSpace): XRViewerPose | undefined;

/**
* XRFrame is extended to contain detectedMeshes attribute
* which contains all meshes that are still tracked in the frame.
*
* The set is initially empty and will be populated by the update meshes algorithm.
* If this attribute is accessed when the frame is not active, the user agent MUST throw InvalidStateError.
*/
readonly detectedMeshes: XRMeshSet;
}

declare abstract class XRFrame implements XRFrame {}
Expand Down Expand Up @@ -662,7 +653,22 @@ interface XRPlane {
orientation: XRPlaneOrientation;
planeSpace: XRSpace;
polygon: DOMPointReadOnly[];
lastChangedTime: number;
lastChangedTime: DOMHighResTimeStamp;

}

interface XRFrame {
/**
* XRFrame is extended to contain detectedPlanes attribute which contains
* all planes that are still tracked in the frame.
*
* The set is initially empty and will be populated by the update planes
* algorithm. If this attribute is accessed when the frame is not active,
* the user agent MUST throw InvalidStateError.
*
* @see https://immersive-web.github.io/real-world-geometry/plane-detection.html#plane-set
*/
readonly detectedPlanes?: XRPlaneSet;
}

declare abstract class XRPlane implements XRPlane {}
Expand All @@ -678,22 +684,34 @@ interface XRMesh {
semanticLabel?: string;
}

interface XRFrame {
/**
* XRFrame is extended to contain detectedMeshes attribute
* which contains all meshes that are still tracked in the frame.
*
* The set is initially empty and will be populated by the update meshes algorithm.
* If this attribute is accessed when the frame is not active, the user agent
* MUST throw InvalidStateError.
*
* @see https://immersive-web.github.io/real-world-meshing/#mesh-set
*/
readonly detectedMeshes?: XRMeshSet;
}

declare abstract class XRMesh implements XRMesh {}

interface XRSession {
// Legacy
updateWorldTrackingState?: (options: {
planeDetectionState?: { enabled: boolean } | undefined;
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
}) => void | undefined;
}

interface XRFrame {
worldInformation?:
| {
detectedPlanes?: XRPlaneSet | undefined;
}
| undefined;
/**
* XRSession is extended to contain the initiateRoomCapture method which,
* if supported, will ask the XR Compositor to capture the current room layout.
* It is up to the XRCompositor if this will replace or augment the set of tracked planes.
* The user agent MAY also ignore this call, for instance if it doesn’t support a manual room
* capture more or if it determines that the room is already set up.
* The initiateRoomCapture method MUST only be able to be called once per XRSession.
*
* @see https://immersive-web.github.io/real-world-geometry/plane-detection.html#plane-set
*/
initiateRoomCapture?():Promise<undefined>;
}

/**
Expand Down
28 changes: 28 additions & 0 deletions types/webxr/webxr-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ function assertNever(value: never) {
const handle = session.requestAnimationFrame(loop);
session.cancelAnimationFrame(handle);

if(session.initiateRoomCapture){
session.initiateRoomCapture().then(()=>{
console.log("Room capture initiated");
});
}

const renderFrame = (frame: XRFrame) => {
const tf = new XRRigidTransform(startSpot, startRot);
space = space.getOffsetReferenceSpace(tf);
Expand All @@ -102,6 +108,28 @@ function assertNever(value: never) {
const angularVelocity: DOMPointReadOnly | undefined = pose.angularVelocity;
const linearVelocity: DOMPointReadOnly | undefined = pose.linearVelocity;
}

const detectedMeshes = frame.detectedMeshes;
detectedMeshes?.forEach((mesh:XRMesh) => {
const meshPose = frame.getPose(mesh.meshSpace, space);
if(meshPose){
const transform = meshPose.transform;
}
console.log(mesh.lastChangedTime);
console.log(mesh.indices);
console.log(mesh.vertices);
console.log(mesh.lastChangedTime);
console.log(mesh.semanticLabel);
});

const detectedPlanes = frame.detectedPlanes;
detectedPlanes?.forEach((plane:XRPlane) => {
const planePose = frame.getPose(plane.planeSpace, space);
console.log(plane.lastChangedTime);
console.log(plane.orientation);
console.log(plane.polygon);
});

};

navigator.xr.addEventListener("devicechange", (e: Event) => {
Expand Down

0 comments on commit d934214

Please sign in to comment.