Skip to content
This repository was archived by the owner on May 18, 2025. It is now read-only.

Commit 5ec4c8c

Browse files
better #rot (blink-controls some sidefx)
1 parent 512fae8 commit 5ec4c8c

File tree

12 files changed

+11818
-46
lines changed

12 files changed

+11818
-46
lines changed

dist/xrfragment.aframe.all.js

Lines changed: 58 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/xrfragment.aframe.js

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* v0.5.1 generated at Tue Dec 12 05:22:39 PM CET 2023
2+
* v0.5.1 generated at Tue Dec 12 06:06:16 PM CET 2023
33
* https://xrfragment.org
44
* SPDX-License-Identifier: MPL-2.0
55
*/
@@ -1174,6 +1174,7 @@ xrf.frag.pos = function(v, opts){
11741174
camera.position.y = v.y
11751175
camera.position.z = v.z
11761176
}
1177+
camera.updateMatrixWorld()
11771178
}
11781179
xrf.frag.rot = function(v, opts){
11791180
let { frag, mesh, model, camera, scene, renderer, THREE} = opts
@@ -1184,6 +1185,8 @@ xrf.frag.rot = function(v, opts){
11841185
v.y * Math.PI / 180,
11851186
v.z * Math.PI / 180
11861187
)
1188+
camera.rotation.offset = camera.rotation.clone() // remember
1189+
//camera.updateProjectionMatrix()
11871190
}else{
11881191
obj = model.scene.isReparented ? model.scene.children[0] : model.scene
11891192
obj.rotation.set(
@@ -2759,6 +2762,59 @@ window.AFRAME.registerComponent('xrf', {
27592762
},
27602763

27612764
})
2765+
// look-controls turns off autoUpdateMatrix (of player) which
2766+
// will break teleporting and other stuff
2767+
// overriding this is easier then adding updateMatrixWorld() everywhere else
2768+
2769+
//AFRAME.components['look-controls'].Component.prototype.onEnterVR = function () {}
2770+
//AFRAME.components['look-controls'].Component.prototype.onExitVR = function () {}
2771+
AFRAME.components['look-controls'].Component.prototype.onEnterVR = function () {
2772+
var sceneEl = this.el.sceneEl;
2773+
if (!sceneEl.checkHeadsetConnected()) { return; }
2774+
this.saveCameraPose();
2775+
this.el.object3D.position.set(0, 0, 0);
2776+
this.el.object3D.rotation.set(0, 0, 0);
2777+
if (sceneEl.hasWebXR) {
2778+
// this.el.object3D.matrixAutoUpdate = false;
2779+
this.el.object3D.updateMatrix();
2780+
}
2781+
}
2782+
2783+
/**
2784+
* Restore the pose.
2785+
*/
2786+
AFRAME.components['look-controls'].Component.prototype.onExitVR = function () {
2787+
if (!this.el.sceneEl.checkHeadsetConnected()) { return; }
2788+
this.restoreCameraPose();
2789+
this.previousHMDPosition.set(0, 0, 0);
2790+
this.el.object3D.matrixAutoUpdate = true;
2791+
}
2792+
2793+
// it also needs to apply the offset (in case the #rot was used in URLS)
2794+
2795+
AFRAME.components['look-controls'].Component.prototype.updateOrientation = function () {
2796+
var object3D = this.el.object3D;
2797+
var pitchObject = this.pitchObject;
2798+
var yawObject = this.yawObject;
2799+
var sceneEl = this.el.sceneEl;
2800+
2801+
// In VR or AR mode, THREE is in charge of updating the camera pose.
2802+
if ((sceneEl.is('vr-mode') || sceneEl.is('ar-mode')) && sceneEl.checkHeadsetConnected()) {
2803+
// With WebXR THREE applies headset pose to the object3D internally.
2804+
return;
2805+
}
2806+
2807+
this.updateMagicWindowOrientation();
2808+
2809+
let offsetX = object3D.rotation.offset ? object3D.rotation.offset.x : 0
2810+
let offsetY = object3D.rotation.offset ? object3D.rotation.offset.y : 0
2811+
2812+
// On mobile, do camera rotation with touch events and sensors.
2813+
object3D.rotation.x = this.magicWindowDeltaEuler.x + offsetX + pitchObject.rotation.x;
2814+
object3D.rotation.y = this.magicWindowDeltaEuler.y + offsetY + yawObject.rotation.y;
2815+
object3D.rotation.z = this.magicWindowDeltaEuler.z;
2816+
object3D.matrixAutoUpdate = true
2817+
}
27622818
window.AFRAME.registerComponent('xrf-button', {
27632819
schema: {
27642820
label: {
@@ -2797,6 +2853,7 @@ window.AFRAME.registerComponent('xrf-button', {
27972853
depth: 0.005
27982854
});
27992855
el.setAttribute('material', {
2856+
shader: "flat",
28002857
color: this.color,
28012858
transparent:true,
28022859
opacity:0.7
@@ -2998,19 +3055,6 @@ window.AFRAME.registerComponent('xrf-get', {
29983055

29993056
});
30003057

3001-
// gaze click on mobile VR
3002-
3003-
AFRAME.registerComponent('xrf-moveplayer',{
3004-
schema:{
3005-
},
3006-
init:function(data){
3007-
this.player = document.querySelector('#player')
3008-
},
3009-
tick:function(){
3010-
this.player.object3D.rotation.copy( this.el.object3D.rotation )
3011-
this.player.object3D.position.copy( this.el.object3D.position )
3012-
}
3013-
});
30143058
window.AFRAME.registerComponent('xrf-wear', {
30153059
schema:{
30163060
el: {type:"selector"},

0 commit comments

Comments
 (0)