Skip to content

Commit 9ded79b

Browse files
committed
Be able to display a custom cursor appearance using a mesh, work in stereo
#2
1 parent ef0d949 commit 9ded79b

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

‎index.js‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import { flattenDeep } from 'lodash/core'
2+
// import checkHeadsetConnected from 'aframe/src/utils/checkHeadsetConnected'
23

34
if (typeof AFRAME === 'undefined') {
45
throw 'Component attempted to register before AFRAME was available.'
56
}
67

8+
// const IS_VR_AVAILABLE = window.hasNativeWebVRImplementation && checkHeadsetConnected()
9+
const IS_VR_AVAILABLE = AFRAME.utils.isMobile() || window.hasNonPolyfillWebVRSupport
10+
711
/**
812
* Mouse Cursor Component for A-Frame.
913
*/
@@ -202,9 +206,8 @@ AFRAME.registerComponent('mouse-cursor', {
202206
* @private
203207
*/
204208
__onEnterVR () {
205-
this.__isStereo = true
206-
if (this.__isMobile) {
207-
this.pause()
209+
if (IS_VR_AVAILABLE) {
210+
this.__isStereo = true
208211
}
209212
},
210213

@@ -213,7 +216,6 @@ AFRAME.registerComponent('mouse-cursor', {
213216
*/
214217
__onExitVR () {
215218
this.__isStereo = false
216-
this.play()
217219
},
218220

219221

@@ -227,6 +229,7 @@ AFRAME.registerComponent('mouse-cursor', {
227229
*/
228230
__getPosition (evt) {
229231
const { innerWidth: w, innerHeight: h } = window
232+
230233
let cx, cy
231234
if (this.__isMobile) {
232235
const { touches } = evt
@@ -239,10 +242,16 @@ AFRAME.registerComponent('mouse-cursor', {
239242
cx = evt.clientX
240243
cy = evt.clientY
241244
}
242-
return {
243-
x: (cx / w) * 2 - 1,
244-
y: - (cy / h) * 2 + 1
245+
246+
if (this.__isStereo) {
247+
cx = (cx % (w/2)) * 2
245248
}
249+
250+
const x = (cx / w) * 2 - 1
251+
const y = - (cy / h) * 2 + 1
252+
253+
return { x: x, y: y }
254+
246255
},
247256

248257
/**

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
},
3333
"homepage": "https://github.com/mayognaise/aframe-mouse-cursor-component#readme",
3434
"devDependencies": {
35-
"aframe": "aframevr/aframe",
35+
"aframe": "^0.2.0",
3636
"aframe-event-set-component": "^3.0.1",
3737
"babel-core": "^6.7.6",
3838
"babel-loader": "^6.2.4",

0 commit comments

Comments
 (0)