Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: transformControls throws error when switching active camera #367

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/core/controls/TransformControls.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<script setup lang="ts">
import type { ShallowRef } from 'vue'
import { onUnmounted, shallowRef, watchEffect, toRefs } from 'vue'
import type { Object3D, Event } from 'three'
import type { Object3D, Camera, Event } from 'three'

import { TransformControls } from 'three-stdlib'
import { useEventListener } from '@vueuse/core'
import { useTresContext } from '@tresjs/core'

export interface TransformControlsProps {
object: Object3D
camera?: Camera
mode?: string
enabled?: boolean
axis?: 'X' | 'Y' | 'Z' | 'XY' | 'YZ' | 'XZ' | 'XYZ'
Expand Down Expand Up @@ -40,7 +41,7 @@ const { object, mode, enabled, axis, translationSnap, rotationSnap, scaleSnap, s

const controlsRef: ShallowRef<TransformControls | undefined> = shallowRef()

const { controls, camera, renderer, extend } = useTresContext()
const { controls, camera: activeCamera, renderer, extend } = useTresContext()

extend({ TransformControls })

Expand Down Expand Up @@ -72,10 +73,11 @@ onUnmounted(() => {

<template>
<TresTransformControls
v-if="camera && renderer"
v-if="(camera || activeCamera) && renderer"
ref="controlsRef"
:key="(camera || activeCamera)?.uuid"
:object="object"
:args="[camera, renderer.domElement]"
:args="[camera || activeCamera, renderer.domElement]"
:mode="mode"
:enabled="enabled"
:axis="axis"
Expand Down