Skip to content

Commit 9b739a2

Browse files
committedJul 24, 2023
feat: chg to event, rmv vmodel,
1 parent 4af9a80 commit 9b739a2

File tree

3 files changed

+11
-20
lines changed

3 files changed

+11
-20
lines changed
 

‎docs/guide/controls/pointer-lock-controls.md

+2-8
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,13 @@ Additional we can detect if the controls has been active or not in a reactive wa
5050

5151
```vue{3}
5252
<script setup lang="ts">
53-
import { ref, watchEffect} from 'vue'
54-
55-
const isLock = ref()
56-
57-
watchEffect(() => {
58-
console.log('jaime ~ isLock:', isLock.value)
59-
})
53+
const isActive = (state: boolean) => console.log(state)
6054
6155
</script>
6256
<template>
6357
<button id="lock">Lock</button>
6458
<TresCanvas shadows alpha>
65-
<TresPerspectiveCamera :position="[0, 0, 3]" v-model="isLock" />
59+
<TresPerspectiveCamera :position="[0, 0, 3]" @is-lock="state => isActive(state)" />
6660
<PointerLockControls selector="lock" />
6761
<TresGridHelper :args="[10, 10]" />
6862

‎playground/src/pages/FirstPersonControlsDemo.vue

+2-5
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,14 @@ const gl = {
1717
shadowMapType: BasicShadowMap,
1818
toneMapping: NoToneMapping,
1919
}
20-
const isLock = ref(false)
2120
22-
watchEffect(() => {
23-
console.log('jaime ~ isLock:', isLock.value)
24-
})
21+
const isActive = (state: boolean) => console.log(state)
2522
</script>
2623

2724
<template>
2825
<TresCanvas v-bind="gl">
2926
<TresPerspectiveCamera :position="[0, 3, 10]" />
30-
<PointerLockControls ref="PLControlsRef" v-model="isLock" make-default />
27+
<PointerLockControls ref="PLControlsRef" make-default @is-lock="state => isActive(state)" />
3128
<KeyboardControls head-bobbing />
3229

3330
<TresGridHelper :args="[100, 100]" />

‎src/core/controls/PointerLockControls.vue

+7-7
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ let triggerSelector: HTMLElement | undefined
5353
5454
extend({ PointerLockControls })
5555
56-
const emit = defineEmits(['update:modelValue'])
56+
const emit = defineEmits(['isLock'])
5757
58-
const isLockEvent = (event: boolean) => {
59-
emit('update:modelValue', event)
58+
const isLockEmitter = (event: boolean) => {
59+
emit('isLock', event)
6060
}
6161
6262
watch(controls, value => {
@@ -69,14 +69,14 @@ watch(controls, value => {
6969
triggerSelector = selector ? selector : state.renderer?.domElement
7070
useEventListener(triggerSelector, 'click', () => {
7171
controls.value?.lock()
72-
controls.value?.addEventListener('lock', () => isLockEvent(true))
73-
controls.value?.addEventListener('unlock', () => isLockEvent(false))
72+
controls.value?.addEventListener('lock', () => isLockEmitter(true))
73+
controls.value?.addEventListener('unlock', () => isLockEmitter(false))
7474
})
7575
})
7676
7777
onUnmounted(() => {
78-
controls.value?.removeEventListener('lock', () => isLockEvent(true))
79-
controls.value?.removeEventListener('unlock', () => isLockEvent(false))
78+
controls.value?.removeEventListener('lock', () => isLockEmitter(true))
79+
controls.value?.removeEventListener('unlock', () => isLockEmitter(false))
8080
})
8181
8282
defineExpose({ value: controls })

0 commit comments

Comments
 (0)
Please sign in to comment.