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

Add xr module and support webxr #1787

Merged
merged 168 commits into from
Dec 12, 2023
Merged

Conversation

cptbtptpbcptdtptp
Copy link
Collaborator

@cptbtptpbcptdtptp cptbtptpbcptdtptp commented Sep 21, 2023

You can use XR like this:

WebGLEngine.create({
  canvas: "canvas",
  xrDevice: new WebXRDevice(),
}).then((engine) => {
  const { xrManager } = this.engine;
  const referenceImage = new XRReferenceImage(
    "test",
    "https://s3-eu-west-1.amazonaws.com/apps.playcanvas.com/ptDfZUq7/files/assets/40497609/1/tracked%20image.png?t=3dbdbc3cf8c071534b04560e611ac631"
  );
  xrManager.addFeature(XRMovementTracking);
  xrManager.addFeature(XRPlaneTracking);
  xrManager.addFeature(XRImageTracking, [referenceImage]);

  // Users need to actively click the button to enter XR
  XRButton.onClick = function () {
    xrManager.enterXR(XRSessionMode.AR).then(
      () => {
        console.log("Enter AR");
      },
      (error) => {
        console.log("Not supported AR", error);
      }
    );
  };
});

@cptbtptpbcptdtptp cptbtptpbcptdtptp added the enhancement New feature or request label Sep 21, 2023
@cptbtptpbcptdtptp cptbtptpbcptdtptp added this to the 1.2 milestone Sep 21, 2023
@cptbtptpbcptdtptp cptbtptpbcptdtptp self-assigned this Sep 21, 2023
@cptbtptpbcptdtptp cptbtptpbcptdtptp changed the title Add XR System Add xr module and support webxr Sep 21, 2023
@codecov
Copy link

codecov bot commented Sep 21, 2023

Codecov Report

Attention: 469 lines in your changes are missing coverage. Please review.

Comparison is base (7a7bc45) 67.01% compared to head (0551f9a) 66.59%.
Report is 10 commits behind head on main.

❗ Current head 0551f9a differs from pull request most recent head 6d21eeb. Consider uploading reports for the commit 6d21eeb to get more accurate results

Files Patch % Lines
packages/core/src/xr/XRManager.ts 9.60% 113 Missing ⚠️
packages/core/src/xr/input/XRInputManager.ts 12.29% 107 Missing ⚠️
packages/core/src/particle/ParticleGenerator.ts 9.85% 64 Missing ⚠️
packages/core/src/xr/session/XRSessionManager.ts 14.49% 59 Missing ⚠️
packages/core/src/xr/feature/XRFeatureManager.ts 37.93% 18 Missing ⚠️
packages/core/src/Engine.ts 33.33% 9 Missing and 7 partials ⚠️
packages/core/src/xr/input/XRController.ts 5.88% 16 Missing ⚠️
...e-deserialize/resources/parser/ReflectionParser.ts 0.00% 13 Missing ⚠️
...oader/src/ktx2/transcoder/BinomialLLCWorkerCode.ts 0.00% 10 Missing ⚠️
packages/core/src/xr/feature/XRPlatformFeature.ts 50.00% 9 Missing ⚠️
... and 11 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1787      +/-   ##
==========================================
- Coverage   67.01%   66.59%   -0.43%     
==========================================
  Files         471      487      +16     
  Lines       23742    24225     +483     
  Branches     3381     3464      +83     
==========================================
+ Hits        15911    16132     +221     
- Misses       6633     6895     +262     
  Partials     1198     1198              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

packages/core/src/Engine.ts Outdated Show resolved Hide resolved
packages/core/src/xr/XRModule.ts Outdated Show resolved Hide resolved
packages/xr-webxr/src/WebXRDevice.ts Show resolved Hide resolved
packages/xr-webxr/src/WebXRDevice.ts Outdated Show resolved Hide resolved
@cptbtptpbcptdtptp
Copy link
Collaborator Author

Let us try Mixins to split XR package:

function ApplyMixins(derivedCtor: any, baseCtors: any[]) {
    baseCtors.forEach(baseCtor => {
        Object.getOwnPropertyNames(baseCtor.prototype).forEach(name => {
            derivedCtor.prototype[name] = baseCtor.prototype[name];
        });
    });
}

// 第一个功能块
class FeatureA {
    featureA() {
        console.log('FeatureA');
    }
}

// 第二个功能块
class FeatureB {
    featureB() {
        console.log('FeatureB');
    }
}

// 主类
class MyClass {
    featureA: () => void;
    featureB: () => void;
    // 可以继续添加方法和属性
}

// 动态注入功能
ApplyMixins(MyClass, [FeatureA, FeatureB]);

// 现在 MyClass 有了 FeatureA 和 FeatureB
const myClassInstance = new MyClass();
myClassInstance.featureA(); // FeatureA
myClassInstance.featureB(); // FeatureB

Shell class focus: image

Done.

packages/xr/package.json Outdated Show resolved Hide resolved
packages/xr-webxr/package.json Outdated Show resolved Hide resolved
@cptbtptpbcptdtptp cptbtptpbcptdtptp changed the base branch from main to dev/1.2 December 11, 2023 06:57
@GuoLei1990 GuoLei1990 merged commit 6b37bba into galacean:dev/1.2 Dec 12, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request xr XR related functions
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants