-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add xr-session.mjs script #7942
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds a WebXR session management script that provides a unified interface for starting/ending AR and VR sessions with automatic camera state preservation and environment adjustments.
- Implements event-driven XR session control with configurable event names for AR, VR start/end operations
- Adds camera transform state preservation and restoration when entering/exiting XR sessions
- Includes AR-specific environment handling by disabling skybox and making camera background transparent
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| if (!this.cameraEntity.camera) { | ||
| console.error('XrSession: No cameraEntity.camera found on the entity.'); | ||
| return; | ||
| } |
Copilot
AI
Sep 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential null reference error. The code checks this.cameraEntity.camera but this.cameraEntity itself could be null if no camera component is found during initialization (line 44). This should check this.cameraEntity first before accessing its camera property.
| } | ||
|
|
||
| endSession() { | ||
| if (!this.cameraEntity.camera) return; |
Copilot
AI
Sep 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same potential null reference issue as in startSession. Should check this.cameraEntity is not null before accessing its camera property.
| if (!this.cameraEntity.camera) return; | |
| if (!this.cameraEntity || !this.cameraEntity.camera) return; |
| if (this.app.xr.type === 'immersive-ar') { | ||
| // Make camera background transparent and hide the sky | ||
| this.clearColor.copy(this.cameraEntity.camera.clearColor); | ||
| this.cameraEntity.camera.clearColor = new Color(0, 0, 0, 0); |
Copilot
AI
Sep 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating a new Color object on every XR session start is inefficient. Consider creating a static transparent color constant or reusing an instance variable to avoid repeated allocations.
Adds an ESM script for managing XR sessions.
Checklist