Skip to content

Commit

Permalink
refactor: made controllers and is properties a ref on the ctx
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarosabu committed Jun 27, 2024
1 parent e13280e commit b12a2fb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/components/XR.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import XRManager from './XRManager.vue'
const props = defineProps<XRProps>()
const ctx: XrContext = {
controllers: [],
isPresenting: false,
isHandTracking: false,
controllers: ref([]),
isPresenting: ref(false),
isHandTracking: ref(false),
player: new Group(),
session: ref(null),
foveation: 0,
Expand Down
28 changes: 14 additions & 14 deletions src/components/XRManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
<script setup lang="ts">
import { computed, inject, watchEffect } from 'vue'
import { useTresContext } from '@tresjs/core'
import type { XRManagerEvent, XRProps } from '../types/xr'
import type { XRProps } from '../types/xr'
import { useGlobalSessionStore } from '../stores/globalSession'
import type { XrContext } from '../core/injectionKeys'
import { xrInjectionKey } from '../core/injectionKeys'
import InteractionManager from './InteractionManager.vue'

Expand All @@ -24,13 +25,12 @@ const XRCamera = computed(() => {
})

const {
session,
player,
controllers,
foveation,
session,
isHandTracking,
isPresenting,
} = inject(xrInjectionKey)
/* isHandTracking,
isPresenting, */
} = inject(xrInjectionKey) as XrContext

watchEffect(() => {
console.log('handler watch effect')
Expand Down Expand Up @@ -88,23 +88,23 @@ watchEffect(() => {
globalSessionStore.referenceSpaceType = referenceSpace
})

const handleSessionStart = (_nativeEvent: XRManagerEvent) => {
/* const handleSessionStart = (_nativeEvent: XRManagerEvent) => {
isPresenting.value = true
// onSessionStartRef.current?.({ nativeEvent: { ...nativeEvent, target: session }, target: session })
}
const handleSessionEnd = (_nativeEvent: XRManagerEvent) => {
} */
/* const handleSessionEnd = (_nativeEvent: XRManagerEvent) => {
isPresenting.value = false
session.value = null
globalSessionStore.session = null
// onSessionEndRef.current?.({ nativeEvent: { ...nativeEvent, target: session }, target: session })
}
const handleVisibilityChange = (_nativeEvent: XRSessionEvent) => {
} */
/* const handleVisibilityChange = (_nativeEvent: XRSessionEvent) => {
// onVisibilityChangeRef.current?.({ nativeEvent, target: session })
}
const handleInputSourcesChange = (_nativeEvent: XRInputSourceChangeEvent) => {
} */
/* const handleInputSourcesChange = (_nativeEvent: XRInputSourceChangeEvent) => {
isHandTracking.value = Object.values(session.inputSources).some(source => source.hand)
// onInputSourcesChangeRef.current?.({ nativeEvent, target: session })
}
} */

/* watchEffect(() => {
console.log('watch effect session handling', session)
Expand Down
6 changes: 4 additions & 2 deletions src/core/injectionKeys.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import type { Group, Intersection, Object3D } from 'three'
import type { InjectionKey, Ref } from 'vue'
import type { XRInteractionHandler, XRInteractionType } from '../types/interaction'
import type { XRController } from '../classes/XRController'

export interface XrContext {
isPresenting: boolean
isHandTracking: boolean
isPresenting: Ref<boolean>
isHandTracking: Ref<boolean>
player: Group
session: Ref<XRSession | null>
controllers: Ref<XRController[]>
foveation: number
frameRate?: number
hoverState: Record<XRHandedness, Map<Object3D, Intersection>>
Expand Down

0 comments on commit b12a2fb

Please sign in to comment.