Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
saitonakamura committed Dec 21, 2022
1 parent 8e453b8 commit a9e8479
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/libs/MotionControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,28 +66,28 @@ const MotionControllerConstants = {
NONE: 'none',
LEFT: 'left',
RIGHT: 'right',
}),
} as const),

ComponentState: Object.freeze({
DEFAULT: 'default',
TOUCHED: 'touched',
PRESSED: 'pressed',
}),
} as const),

ComponentProperty: Object.freeze({
BUTTON: 'button',
X_AXIS: 'xAxis',
Y_AXIS: 'yAxis',
STATE: 'state',
}),
} as const),

ComponentType: Object.freeze({
TRIGGER: 'trigger',
SQUEEZE: 'squeeze',
TOUCHPAD: 'touchpad',
THUMBSTICK: 'thumbstick',
BUTTON: 'button',
}),
} as const),

ButtonTouchThreshold: 0.05,

Expand All @@ -96,7 +96,7 @@ const MotionControllerConstants = {
VisualResponseProperty: Object.freeze({
TRANSFORM: 'transform',
VISIBILITY: 'visibility',
}),
} as const),
}

/**
Expand Down
14 changes: 10 additions & 4 deletions src/webxr/XRControllerModelFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class XRControllerModelFactory {
const controllerModel = new XRControllerModel()
let scene: Object3D | null = null

controller.addEventListener('connected', (event) => {
const onConnected = (event: any): void => {
const xrInputSource = event.data

if (xrInputSource.targetRayMode !== 'tracked-pointer' || !xrInputSource.gamepad) return
Expand Down Expand Up @@ -222,9 +222,13 @@ class XRControllerModelFactory {
.catch((err) => {
console.warn(err)
})
})
}

controller.addEventListener('connected', onConnected)

controller.addEventListener('disconnected', () => {
const onDisconnected = (): void => {
controller.removeEventListener('connected', onConnected)
controller.removeEventListener('disconnected', onDisconnected)
controllerModel.motionController = null
controller.dispatchEvent({
type: 'motionControllerDestroyed',
Expand All @@ -233,7 +237,9 @@ class XRControllerModelFactory {
controllerModel.remove(scene)
}
scene = null
})
}

controller.addEventListener('disconnected', onDisconnected)

return controllerModel
}
Expand Down

0 comments on commit a9e8479

Please sign in to comment.