Skip to content

Commit

Permalink
fix: prevent error in WristMountedUI when gripPose is null
Browse files Browse the repository at this point in the history
  • Loading branch information
lojjic committed Dec 3, 2020
1 parent 040816c commit 755d560
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions packages/troika-xr/src/facade/wrist-mounted-ui/WristMountedUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export class WristMountedUI extends Group3DFacade {
let gripPose = null
let inputSources = xrFrame.session.inputSources
if (inputSources) {
let active = false
let gripSpace = null
for (let i = 0, len = inputSources.length; i < len; i++) {
if (inputSources[i].handedness === this.preferredHand) {
Expand All @@ -91,18 +92,19 @@ export class WristMountedUI extends Group3DFacade {
// treat them always as relative to default position/orientation.
let cam = this.getCameraFacade()
gripPose = xrFrame.getPose(gripSpace, cam.xrReferenceSpace)

// If turned to upward angle, set to active
// TODO: needs debouncing!
tempVec3.set(1, 0, 0).applyQuaternion(
tempQuat.setFromRotationMatrix(tempMat4.fromArray(gripPose.transform.matrix))
)
let active = tempVec3.angleTo(upVec3) < this.activeUpAngle
if (active !== this.active) {
this.active = active
this.afterUpdate()
if (gripPose) {
// If turned to upward angle, set to active
// TODO: needs debouncing!
tempVec3.set(1, 0, 0).applyQuaternion(
tempQuat.setFromRotationMatrix(tempMat4.fromArray(gripPose.transform.matrix))
)
active = tempVec3.angleTo(upVec3) < this.activeUpAngle
}
}
if (active !== this.active) {
this.active = active
this.afterUpdate()
}
}

if (gripPose || !this.gripPose) {
Expand Down

0 comments on commit 755d560

Please sign in to comment.