Skip to content

Commit

Permalink
fix: camera controls ignored props
Browse files Browse the repository at this point in the history
  • Loading branch information
whereiswolf committed Apr 18, 2024
1 parent e71bc7f commit 37fa163
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions src/core/controls/CameraControls.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts" setup>
import CameraControls from 'camera-controls'
import { ref, watchEffect, onUnmounted, toRefs } from 'vue'
import { ref, watchEffect, onUnmounted, toRefs, computed } from 'vue'
import type {
PerspectiveCamera,
OrthographicCamera,
Expand Down Expand Up @@ -321,9 +321,8 @@ const props = withDefaults(defineProps<CameraControlsProps>(), {
boundaryFriction: 0.0,
restThreshold: 0.01,
colliderMeshes: () => [],
// FIXME: set default values for mouseButtons and touches
// mouseButtons: {},
// touches: {}
mouseButtons: () => defaultMouseButtons,
touches: () => defaultTouches,
})
const emit = defineEmits(['change', 'start', 'end'])
Expand Down Expand Up @@ -354,8 +353,20 @@ const {
boundaryFriction,
restThreshold,
colliderMeshes,
mouseButtons: mouseButtonsRef,
touches: touchesRef,
} = toRefs(props)
const mouseButtons = computed(() => ({
...defaultMouseButtons,
...mouseButtonsRef.value,
}))
const touches = computed(() => ({
...defaultTouches,
...touchesRef.value,
}))
// allow for tree shaking, only importing required classes
const subsetOfTHREE = {
Box3,
Expand Down Expand Up @@ -411,6 +422,21 @@ defineExpose({
})
</script>

<script lang="ts">
const defaultMouseButtons: CameraControls['mouseButtons'] = {
left: CameraControls.ACTION.ROTATE,
middle: CameraControls.ACTION.DOLLY,
right: CameraControls.ACTION.TRUCK,
wheel: CameraControls.ACTION.DOLLY,
}
const defaultTouches: CameraControls['touches'] = {
one: CameraControls.ACTION.TOUCH_ROTATE,
two: CameraControls.ACTION.TOUCH_DOLLY_TRUCK,
three: CameraControls.ACTION.TOUCH_TRUCK,
}
</script>

<template>
<TresCameraControls
v-if="(camera || activeCamera) && (domElement || renderer)"
Expand Down Expand Up @@ -440,5 +466,7 @@ defineExpose({
:rest-threshold="restThreshold"
:collider-meshes="colliderMeshes"
:args="[camera || activeCamera, domElement || renderer.domElement]"
:mouse-buttons="mouseButtons"
:touches="touches"
/>
</template>

0 comments on commit 37fa163

Please sign in to comment.