Skip to content

Commit 5a7c2ca

Browse files
authoredMar 7, 2025··
feat(OrbitControls): add mouseButtons prop to customize mouse interactions (#603)
* feat(OrbitControls): add mouseButtons prop to customize mouse interactions - Updated OrbitControls component to support custom mouse button configurations - Added `mouseButtons` prop to documentation and component - Imported MOUSE enum from three.js - Updated demo and documentation to showcase new prop * chore(CI): update corepack installation in GitHub workflow - Force install corepack globally using npm to ensure compatibility - Modify workflow to use global corepack installation before enabling
1 parent d2f3d42 commit 5a7c2ca

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed
 

‎.github/workflows/pkg.pr.new.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- name: Checkout code
2727
uses: actions/checkout@v4
2828

29-
- run: corepack enable
29+
- run: npm i -g --force corepack && corepack enable
3030
- uses: actions/setup-node@v4
3131
with:
3232
node-version: ${{ matrix.node-version }}

‎docs/guide/controls/orbit-controls.md

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Is really important that the Perspective camera is set first in the canvas. Othe
4646
| **minZoom** | The minimum field of view angle, in radians. Default is 0. | `0` |
4747
| **maxZoom** | The maximum field of view angle, in radians. ( OrthographicCamera only ). Default is Infinity. | `Infinity` |
4848
| **touches** | This object contains references to the touch actions used by the controls. | `{ ONE: TOUCH.ROTATE, TWO: TOUCH.DOLLY_PAN }` |
49+
| **mouseButtons** | This object contains references to the mouse actions used by the controls. LEFT: Rotate around the target, MIDDLE: Zoom the camera, RIGHT: Pan the camera. | `{ LEFT: MOUSE.ROTATE, MIDDLE: MOUSE.DOLLY, RIGHT: MOUSE.PAN }` |
4950
| - | - |
5051
| **enableZoom** | Whether to enable zooming. | `true` |
5152
| **zoomSpeed** | How fast to zoom in and out. Default is 1. | `1` |

‎playground/vue/src/pages/controls/OrbitControlsDemo.vue

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { OrbitControls } from '@tresjs/cientos'
44
import { TresCanvas } from '@tresjs/core'
55
import { TresLeches, useControls } from '@tresjs/leches'
6-
import { BasicShadowMap, NoToneMapping, SRGBColorSpace } from 'three'
6+
import { BasicShadowMap, MOUSE, NoToneMapping, SRGBColorSpace } from 'three'
77
import { reactive } from 'vue'
88
import { useState } from '../../composables/state'
99
import '@tresjs/leches/styles'
@@ -36,6 +36,11 @@ const controlsState = reactive({
3636
zoomSpeed: 1,
3737
enableRotate: true,
3838
rotateSpeed: 1,
39+
mouseButtons: {
40+
LEFT: MOUSE.ROTATE,
41+
MIDDLE: MOUSE.DOLLY,
42+
RIGHT: MOUSE.PAN,
43+
},
3944
})
4045

4146
const {

‎src/core/controls/OrbitControls.vue

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts" setup>
22
import { useLoop, useTresContext } from '@tresjs/core'
33
import { useEventListener } from '@vueuse/core'
4-
import { TOUCH } from 'three'
4+
import { MOUSE, TOUCH } from 'three'
55
import { OrbitControls } from 'three-stdlib'
66
import { onUnmounted, shallowRef, toRefs, watch } from 'vue'
77
import type { TresVector3 } from '@tresjs/core'
@@ -228,6 +228,22 @@ export interface OrbitControlsProps {
228228
* @see https://threejs.org/docs/#examples/en/controls/OrbitControls.rotateSpeed
229229
*/
230230
rotateSpeed?: number
231+
/**
232+
* This object contains references to the mouse actions used by the controls.
233+
* LEFT: Rotate around the target
234+
* MIDDLE: Zoom the camera
235+
* RIGHT: Pan the camera
236+
*
237+
* @default { LEFT: MOUSE.ROTATE, MIDDLE: MOUSE.DOLLY, RIGHT: MOUSE.PAN }
238+
* @type {{ LEFT?: number, MIDDLE?: number, RIGHT?: number }}
239+
* @memberof OrbitControlsProps
240+
* @see https://threejs.org/docs/#examples/en/controls/OrbitControls.mouseButtons
241+
*/
242+
mouseButtons?: {
243+
LEFT?: number
244+
MIDDLE?: number
245+
RIGHT?: number
246+
}
231247
}
232248
233249
const props = withDefaults(defineProps<OrbitControlsProps>(), {
@@ -252,6 +268,7 @@ const props = withDefaults(defineProps<OrbitControlsProps>(), {
252268
touches: () => ({ ONE: TOUCH.ROTATE, TWO: TOUCH.DOLLY_PAN }),
253269
rotateSpeed: 1,
254270
target: () => [0, 0, 0],
271+
mouseButtons: () => ({ LEFT: MOUSE.ROTATE, MIDDLE: MOUSE.DOLLY, RIGHT: MOUSE.PAN }),
255272
})
256273
257274
const emit = defineEmits(['change', 'start', 'end'])
@@ -278,6 +295,7 @@ const {
278295
touches,
279296
rotateSpeed,
280297
target,
298+
mouseButtons,
281299
} = toRefs(props)
282300
283301
const { camera: activeCamera, renderer, extend, controls, invalidate } = useTresContext()
@@ -351,6 +369,7 @@ defineExpose({ instance: controlsRef })
351369
:zoom-speed="zoomSpeed"
352370
:enable-rotate="enableRotate"
353371
:rotate-speed="rotateSpeed"
372+
:mouse-buttons="mouseButtons"
354373
:args="[camera || activeCamera, domElement || renderer.domElement]"
355374
/>
356375
</template>

0 commit comments

Comments
 (0)
Please sign in to comment.