Skip to content

Commit

Permalink
fix: expose inputState.object correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
bbohlender committed Oct 17, 2024
1 parent 96d35bf commit 406cd2c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/react/xr/src/hand.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const XRHandModel = forwardRef<Object3D, XRHandModelOptions>((options, re
const gltf = useLoader(GLTFLoader, state.assetPath)
const model = useMemo(() => cloneXRHandGltf(gltf), [gltf])
configureXRHandModel(model, options)
state.object = model
useImperativeHandle(ref, () => model, [model])
const referenceSpace = useXRSpace()
const update = useMemo(
Expand Down
9 changes: 5 additions & 4 deletions packages/xr/src/vanilla/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ import { Object3D } from 'three'
import { XRControllerLayout } from '../controller/layout.js'
import { XRControllerModelOptions, configureXRControllerModel, loadXRControllerModel } from '../controller/model.js'
import { createUpdateXRControllerVisuals } from '../controller/visual.js'
import { XRControllerGamepadState } from '../controller/gamepad.js'
import { onXRFrame } from './utils.js'
import { XRControllerState } from '../input.js'

export class XRControllerModel extends Object3D {
constructor(layout: XRControllerLayout, gamepadState: XRControllerGamepadState, options?: XRControllerModelOptions) {
constructor(state: XRControllerState, options?: XRControllerModelOptions) {
super()
let update = () => {}
onXRFrame(() => update())
loadXRControllerModel(layout).then((model) => {
loadXRControllerModel(state.layout).then((model) => {
this.add(model)
state.object = model
configureXRControllerModel(model, options)
update = createUpdateXRControllerVisuals(model, layout, gamepadState)
update = createUpdateXRControllerVisuals(model, state.layout, state.gamepad)
})
}
}
4 changes: 2 additions & 2 deletions packages/xr/src/vanilla/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ export function createDefaultXRHand(
)
let removeModel: (() => void) | undefined
if (modelOptions !== false) {
const model = new XRHandModel(state.inputSource.hand, state.assetPath, spreadable(modelOptions))
const model = new XRHandModel(state, spreadable(modelOptions))
space.add(model)
removeModel = () => space.remove(model)
}
Expand Down Expand Up @@ -365,7 +365,7 @@ export function createDefaultXRController(

let removeModel: (() => void) | undefined
if (modelOptions !== false) {
const model = new XRControllerModel(state.layout, state.gamepad, spreadable(modelOptions))
const model = new XRControllerModel(state, spreadable(modelOptions))
space.add(model)
removeModel = () => space.remove(model)
}
Expand Down
8 changes: 5 additions & 3 deletions packages/xr/src/vanilla/hand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ import { Object3D } from 'three'
import { XRHandModelOptions, configureXRHandModel, createUpdateXRHandVisuals, loadXRHandModel } from '../hand/index.js'
import { onXRFrame } from './utils.js'
import { getSpaceFromAncestors } from '../space.js'
import { XRHandState } from '../input.js'

export class XRHandModel extends Object3D {
constructor(hand: XRHand, assetPath: string, options?: XRHandModelOptions) {
constructor(state: XRHandState, options?: XRHandModelOptions) {
super()
let update: (frame: XRFrame) => void = () => {}
onXRFrame((frame) => update(frame))
loadXRHandModel(assetPath).then((model) => {
loadXRHandModel(state.assetPath).then((model) => {
this.add(model)
state.object = model
configureXRHandModel(model, options)
update = createUpdateXRHandVisuals(hand, model, () => getSpaceFromAncestors(this))
update = createUpdateXRHandVisuals(state.inputSource.hand, model, () => getSpaceFromAncestors(this))
})
}
}

0 comments on commit 406cd2c

Please sign in to comment.