Skip to content

Commit

Permalink
feat: Add pose stats display to arena-camera
Browse files Browse the repository at this point in the history
Enable from same Toggle Stats as AFRAME stats
Resolves #213
  • Loading branch information
hi-liang committed Mar 7, 2022
1 parent 459d574 commit a5411d8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ <h3><img alt="CONIX Logo" class="title-logo" src="static/images/xr-logo-v7.png"/
<div id="error-block" class="error-block"></div>
</div>
<span class="echo-name" id="echo-name"></span>
<span class="pose-stats" id="pose-stats"></span>
<video autoplay="1" crossorigin="anonymous" id="cornerVideo" muted="true" playsinline="1" volume="0"></video>

<!-- login auth check with calls to mqtt connect placed in an `onauth` event listener -->
Expand Down
12 changes: 12 additions & 0 deletions src/components/arena-camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ AFRAME.registerComponent('arena-camera', {
position: {type: 'vec3', default: new THREE.Vector3()},
vioRotation: {type: 'vec4', default: new THREE.Quaternion()},
vioPosition: {type: 'vec3', default: new THREE.Vector3()},
showStats: {type: 'boolean', default: false},
},
/**
* Send initial camera create message; Setup heartbeat timer
Expand Down Expand Up @@ -73,6 +74,10 @@ AFRAME.registerComponent('arena-camera', {
}, 1000);
}
});

if (this.data.showStats) {
document.getElementById('pose-stats').style.display = 'block';
}
},
/**
* Publish user camera pose
Expand Down Expand Up @@ -162,6 +167,9 @@ AFRAME.registerComponent('arena-camera', {
*/
update(oldData) {
const data = this.data;
if (oldData.showStats !== data.showStats) {
document.getElementById('pose-stats').style.display = (data.showStats) ? 'block' : 'none';
}
},
/**
* Every tick, update rotation and position of the camera
Expand Down Expand Up @@ -211,6 +219,10 @@ AFRAME.registerComponent('arena-camera', {
this.frustMatrix.multiplyMatrices(cam.projectionMatrix, cam.matrixWorldInverse),
);
this.publishPose();
if (this.data.showStats) {
document.getElementById('pose-stats').textContent =
`Position: ${positionCoords}\r\nRotation: ${rotationCoords}`;
}
}
if (data.vioEnabled) this.publishVio(); // publish vio on every tick (if enabled)
this.lastPose = newPose;
Expand Down
3 changes: 3 additions & 0 deletions src/icons/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,9 @@ export class SideMenu {
const sceneEl = document.querySelector('a-scene');
const statsEl = sceneEl.getAttribute('stats');
sceneEl.setAttribute('stats', !statsEl);
const cam = document.getElementById('my-camera');
const showStats = cam.getAttribute('arena-camera').showStats;
cam.setAttribute('arena-camera', {showStats: !showStats});
};
formDiv.appendChild(stats);

Expand Down
16 changes: 16 additions & 0 deletions src/icons/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@
color: #fff;
}

/* Pose data of camera */
.pose-stats {
position: absolute;
display: none;
padding: 7px;
top: 285px;
left: 25px;
border-radius: 10px;
z-index: 10000; /* layered over video*/
font-size: small;
background-color: #333;
color: #fafafa;
white-space: pre;
opacity: .85;
}

/* Health-check system */
.error-icon {
position: absolute;
Expand Down

0 comments on commit a5411d8

Please sign in to comment.