nativeXRFrame.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { RegisterNativeTypeAsync } from "../../Engines/nativeEngine.js";
  2. /** @internal */
  3. export class NativeXRFrame {
  4. get session() {
  5. return this._nativeImpl.session;
  6. }
  7. constructor(_nativeImpl) {
  8. this._nativeImpl = _nativeImpl;
  9. this._xrTransform = new XRRigidTransform();
  10. this._xrPose = {
  11. transform: this._xrTransform,
  12. emulatedPosition: false,
  13. };
  14. // Enough space for position, orientation
  15. this._xrPoseVectorData = new Float32Array(4 + 4);
  16. this.fillPoses = this._nativeImpl.fillPoses.bind(this._nativeImpl);
  17. this.getViewerPose = this._nativeImpl.getViewerPose.bind(this._nativeImpl);
  18. this.getHitTestResults = this._nativeImpl.getHitTestResults.bind(this._nativeImpl);
  19. this.getHitTestResultsForTransientInput = () => {
  20. throw new Error("XRFrame.getHitTestResultsForTransientInput not supported on native.");
  21. };
  22. this.createAnchor = this._nativeImpl.createAnchor.bind(this._nativeImpl);
  23. this.getJointPose = this._nativeImpl.getJointPose.bind(this._nativeImpl);
  24. this.fillJointRadii = this._nativeImpl.fillJointRadii.bind(this._nativeImpl);
  25. this.getLightEstimate = () => {
  26. throw new Error("XRFrame.getLightEstimate not supported on native.");
  27. };
  28. this.getImageTrackingResults = () => {
  29. return this._nativeImpl._imageTrackingResults ?? [];
  30. };
  31. }
  32. getPose(space, baseSpace) {
  33. if (!this._nativeImpl.getPoseData(space, baseSpace, this._xrPoseVectorData.buffer, this._xrTransform.matrix.buffer)) {
  34. return undefined;
  35. }
  36. const position = this._xrTransform.position;
  37. position.x = this._xrPoseVectorData[0];
  38. position.y = this._xrPoseVectorData[1];
  39. position.z = this._xrPoseVectorData[2];
  40. position.w = this._xrPoseVectorData[3];
  41. const orientation = this._xrTransform.orientation;
  42. orientation.x = this._xrPoseVectorData[4];
  43. orientation.y = this._xrPoseVectorData[5];
  44. orientation.z = this._xrPoseVectorData[6];
  45. orientation.w = this._xrPoseVectorData[7];
  46. return this._xrPose;
  47. }
  48. get trackedAnchors() {
  49. return this._nativeImpl.trackedAnchors;
  50. }
  51. get worldInformation() {
  52. return this._nativeImpl.worldInformation;
  53. }
  54. get detectedPlanes() {
  55. return this._nativeImpl.detectedPlanes;
  56. }
  57. get featurePointCloud() {
  58. return this._nativeImpl.featurePointCloud;
  59. }
  60. getDepthInformation(view) {
  61. throw new Error("This function is not available in Babylon Native");
  62. // return this._nativeImpl.getDepthInformation(view);
  63. }
  64. }
  65. RegisterNativeTypeAsync("NativeXRFrame", NativeXRFrame);
  66. //# sourceMappingURL=nativeXRFrame.js.map