Skip to content

Commit 9e644de

Browse files
committed
Add hide-on-enter-vr component analog to hide-on-enter-ar
1 parent baca22b commit 9e644de

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

Diff for: docs/components/hide-on-enter-vr.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
title: hide-on-enter-vr
3+
type: components
4+
layout: docs
5+
parent_section: components
6+
source_code: src/components/hide-on-enter-vr.js
7+
examples: []
8+
---
9+
10+
When the user enters VR this component will hide the entity by toggling it's `visible` state.
11+
12+
Depending on the immersive mode: VR or AR one might want to show / hide different entities.
13+
14+
## Example
15+
16+
```html
17+
<a-entity hide-on-enter-vr></a-entity>
18+
```
19+
20+
## Properties
21+
22+
None
23+
24+
## Events
25+
26+
None

Diff for: src/components/hide-on-enter-vr.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var register = require('../core/component').registerComponent;
2+
3+
module.exports.Component = register('hide-on-enter-vr', {
4+
init: function () {
5+
var self = this;
6+
this.el.sceneEl.addEventListener('enter-vr', function () {
7+
if (self.el.sceneEl.is('vr-mode')) {
8+
self.el.object3D.visible = false;
9+
}
10+
});
11+
this.el.sceneEl.addEventListener('exit-vr', function () {
12+
self.el.object3D.visible = true;
13+
});
14+
}
15+
});

Diff for: src/components/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require('./hand-tracking-controls');
1010
require('./hand-tracking-grab-controls');
1111
require('./hand-controls');
1212
require('./hide-on-enter-ar');
13+
require('./hide-on-enter-vr');
1314
require('./hp-mixed-reality-controls');
1415
require('./layer');
1516
require('./laser-controls');

0 commit comments

Comments
 (0)