repo: janusweb
action: commit
revision: 
path_from: 
revision_from: d4c22f975fe1081c6ea909b4f6431abc41e11860:
path_to: 
revision_to: 
git.thebackupbox.net
janusweb
git clone git://git.thebackupbox.net/janusweb
commit d4c22f975fe1081c6ea909b4f6431abc41e11860
Author: James Baicoianu 
Date:   Tue Sep 3 17:43:45 2024 -0700

    Fixed player head orientation bugs (hopefully)

diff --git a/scripts/janusghost.js b/scripts/janusghost.js
index 0f06d28293af3b31b2d2d540b14b21e4a0fc5cd3..
index ..d3a0fb3174fe51ce16f54c9bbca83ac7b29a1e4d 100644
--- a/scripts/janusghost.js
+++ b/scripts/janusghost.js
@@ -286,7 +286,7 @@ elation.require(['janusweb.janusbase', 'engine.things.leapmotion'], function() {
           this.body = this.createObject('object', {
             id: bodyid,
             //orientation: new THREE.Quaternion().setFromEuler(new THREE.Euler(0,Math.PI,0)),
-            //rotation: V(0, 180, 0),
+            rotation: V(0, 180, 0),
             lighting: this.lighting,
             //cull_face: 'none'
             opacity: 0.9999,
@@ -446,7 +446,7 @@ elation.require(['janusweb.janusbase', 'engine.things.leapmotion'], function() {
           }
         });
       } else {
-        let armature = sourcecontainer.getObjectByName('Armature');
+        let armature = sourcecontainer.getObjectByName('Armature') || sourcecontainer;
         newclip.tracks.forEach(track => {
           track.name = track.name.replace('mixamorig', '');
           let p = track.name.split('.');
@@ -528,6 +528,8 @@ elation.require(['janusweb.janusbase', 'engine.things.leapmotion'], function() {
       var xdir = new THREE.Vector3(),
             ydir = new THREE.Vector3(),
             zdir = new THREE.Vector3(),
+            flip = new THREE.Quaternion().setFromEuler(new THREE.Euler(0, Math.PI, 0));
+            origin = new THREE.Vector3(),
             matrix = new THREE.Matrix4(),
             q1 = new THREE.Quaternion();
       return function(movedata) {
@@ -550,16 +552,11 @@ elation.require(['janusweb.janusbase', 'engine.things.leapmotion'], function() {
           if (this.head) {
             ydir.fromArray(parser.getVectorValue(movedata.up_dir, [0,1,0]));
             zdir.fromArray(parser.getVectorValue(movedata.view_dir, [0,0,1]));
-            xdir.crossVectors(zdir, ydir);
-
-            xdir.crossVectors(zdir, ydir).normalize();
-            zdir.crossVectors(xdir, ydir).normalize();
-
-            matrix.makeBasis(xdir, ydir, zdir);
+            matrix.lookAt(origin, zdir, ydir);
             q1.setFromRotationMatrix(matrix);
-            this.head.properties.orientation.copy(this.orientation).invert().multiply(q1);
+            this.head.properties.orientation.copy(this.orientation).invert().multiply(q1).multiply(flip);
             if (this.body && this.headaction) {
-              this.setHeadOrientation(this.head.orientation);
+              this.setHeadOrientation(this.head.orientation, true);
             }
             if (movedata.head_pos && this.face) {
               var headpos = this.head.properties.position;
@@ -863,7 +860,7 @@ return;
         let track = headaction._clip.tracks[0];
         if (track) {
           track.values[0] = orientation.x * (invert ? -1 : 1);
-          track.values[1] = orientation.y * (invert ? -1 : 1);
+          track.values[1] = orientation.y * (invert ? 1 : -1);
           track.values[2] = orientation.z * (invert ? -1 : 1);
           track.values[3] = orientation.w; // * (invert ? -1 : 1);
         }
diff --git a/scripts/janusplayer.js b/scripts/janusplayer.js
index 276d745958d9d00c338752867a55a33493bb0196..
index ..b91cdeb20564f5188b51e0076a23c8582239e1ed 100644
--- a/scripts/janusplayer.js
+++ b/scripts/janusplayer.js
@@ -303,10 +303,10 @@ document.body.dispatchEvent(click);
           }
         }
         if (this.ghost && !this.decouplehead) {
-          this.ghost.setHeadOrientation(this.head.orientation, true);
+          this.ghost.setHeadOrientation(_tmpquat.multiplyQuaternions(this.neck.orientation._target, this.head.orientation._target), true);
           if (this.ghost._target.head) {
             //this.ghost._target.face.position.copy(this.head.position);
-            this.ghost.head.orientation.copy(this.head.orientation).invert();
+            this.ghost.head.orientation.copy(this.head.orientation).multiply(this.neck.orientation);;
           }
         }
       }
@@ -510,10 +510,10 @@ document.body.dispatchEvent(click);
               avatar_src: 'data:text/plain,' + encodeURIComponent(avatar),
               showlabel: false,
               //pos: V(0, -this.fatness, 0),
-              rotation: V(0, 180, 0),
+              //rotation: V(0, 180, 0),
               renderorder: 101,
             });
-            this.ghost.orientation.set(0,1,0,0);
+            //this.ghost.orientation.set(0,1,0,0);
           }
         });
         this.visible = true;
@@ -702,7 +702,7 @@ document.body.dispatchEvent(click);
         avatar_src: 'data:text/plain,' + encodeURIComponent(avatar),
         showlabel: false,
         //pos: V(0, -this.fatness, 0),
-        rotation: V(0, 180, 0),
+        //rotation: V(0, 180, 0),
         renderorder: 101,
       });

@@ -1142,7 +1142,7 @@ document.body.dispatchEvent(click);
       if (otherpos) {
         var dir = thispos.clone().sub(otherpos).normalize();
         this.properties.orientation.setFromEuler(new THREE.Euler(0, Math.atan2(dir.x, dir.z), 0));
-        this.head.properties.orientation.setFromEuler(new THREE.Euler(-Math.asin(dir.y), 0, 0));
+        //this.head.properties.orientation.setFromEuler(new THREE.Euler(-Math.asin(dir.y), 0, 0));
         this.refresh();
         room.refresh();
         this.engine.systems.render.setdirty();
diff --git a/scripts/multiplayermanager.js b/scripts/multiplayermanager.js
index 0274fe7000e816fa910164a91b83fb6b0f42fd34..
index ..331245fc4dbafaec0a9e2fefeb7bfe475182b463 100644
--- a/scripts/multiplayermanager.js
+++ b/scripts/multiplayermanager.js
@@ -177,7 +177,7 @@ console.log('[MultiplayerManager] set active room:', room, this.activeroom);
         tmpMat.makeRotationFromQuaternion(player.properties.orientation);
         tmpMat.extractBasis(tmpVecX, tmpVecY, tmpVecZ);
         var ret = {
-          dir: (-tmpVecZ.x) + ' ' + (-tmpVecZ.y) + ' ' + (-tmpVecZ.z),
+          dir: (tmpVecZ.x) + ' ' + (tmpVecZ.y) + ' ' + (tmpVecZ.z),
           up_dir: '0 1 0',
           //view_dir: this.tmpVecZ.toArray().join(' ')
         };

-----END OF PAGE-----