Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
saitonakamura committed Jan 12, 2023
1 parent c31dd43 commit 48a31de
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/webxr/XRControllerModelFactory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Mesh, Object3D, SphereGeometry, MeshBasicMaterial } from 'three'
import type { Texture, Group } from 'three'
import type { Texture } from 'three'
// @ts-ignore
import { GLTFLoader } from '../loaders/GLTFLoader'
import { fetchProfile, MotionController, MotionControllerConstants } from '../libs/MotionControllers'
Expand Down Expand Up @@ -99,7 +99,7 @@ export class XRControllerModel extends Object3D {
})
}

dispose(): void {
disconnect(): void {
this.motionController = null
this.dispatchEvent({
type: 'motionControllerDestroyed',
Expand All @@ -109,6 +109,10 @@ export class XRControllerModel extends Object3D {
}
this.scene = null
}

dispose(): void {
this.disconnect()
}
}

/**
Expand Down Expand Up @@ -196,13 +200,10 @@ class XRControllerModelFactory {
}
}

createControllerModel(event: any): XRControllerModel {
const controllerModel = new XRControllerModel()
let scene: Object3D | null = null

initializeControllerModel(controllerModel: XRControllerModel, event: any): void {
const xrInputSource = event.data

if (xrInputSource.targetRayMode !== 'tracked-pointer' || !xrInputSource.gamepad) return controllerModel
if (xrInputSource.targetRayMode !== 'tracked-pointer' || !xrInputSource.gamepad) return

fetchProfile(xrInputSource, this.path, DEFAULT_PROFILE)
.then(({ profile, assetPath }) => {
Expand All @@ -217,7 +218,7 @@ class XRControllerModelFactory {

const cachedAsset = this._assetCache[assetUrl]
if (cachedAsset) {
scene = cachedAsset.scene.clone()
const scene = cachedAsset.scene.clone()

controllerModel.addScene(scene)
} else {
Expand All @@ -227,15 +228,15 @@ class XRControllerModelFactory {

this.gltfLoader.setPath('')
this.gltfLoader.load(
motionController.assetUrl,
assetUrl,
(asset: { scene: Object3D }) => {
if (!controllerModel.motionController) {
console.warn('motionController gone while gltf load, bailing...')
return
}

this._assetCache[assetUrl] = asset
scene = asset.scene.clone()
const scene = asset.scene.clone()
controllerModel.addScene(scene)
},
null,
Expand All @@ -248,8 +249,6 @@ class XRControllerModelFactory {
.catch((err) => {
console.warn(err)
})

return controllerModel
}
}

Expand Down

0 comments on commit 48a31de

Please sign in to comment.