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

No access to controls when using useTresContext #840

Open
5 tasks done
whitespacecode opened this issue Sep 24, 2024 · 1 comment
Open
5 tasks done

No access to controls when using useTresContext #840

whitespacecode opened this issue Sep 24, 2024 · 1 comment

Comments

@whitespacecode
Copy link

whitespacecode commented Sep 24, 2024

Describe the bug

Adding OrbitControls in a child component and trying to have access to it in other components i would expect it works the same way as 'camera' by using TresContext.

controls just returns null.

Reproduction

https://play.tresjs.org/#eNqdVW1v2zYQ/iuEgsEtZkuykxSb5g6Z3Xbo0DZB429VPzDS1WJCkQRJvy3If99RLzblJanaRLCte3nuuePx7j5YaDB/KRWuVxAkwdRkmilLDNiVIpyK5es0sCYN/kwFK5XUltwT5zKnYk0NeSDftCzJ4MKi7NZEmdQw+GNvuyiYzq9AGykawzDyZC6oZz0vGM/nslR7272ktUzFNKopIiF8sVAqTi3gGyFTj9iGiVxuRob9CyTjQPUok1xqzObkt8mb2fy8Song39QnGTXCRrWPfyR3gd4wDZllUlD+gS0LSxIlDXMCDPIlHpLJkJx9TQOSMGFBoGqHinE4QVFGjR2ZgiLFJuQ0OpBHwTTyMsNXY3fc/SxsyYepuJH5jtw7v5LqJRMJibE4hCia50ws29cCHLGEjOP4l0qwYbkt9u8PqTihStVA37El5IZmd0stVyKvS5mQkzh2cRAGD6UiGAyD+ixHJVXhLVYUe6qCTxsFtlJSB3Qyv22cIg0Ka5VJoijLBfrnwNlahwJsJFQZ+eYXZ+EknEQ5MzZyYrROAyzNETADYWUVtC927YHwcRiPBGxtOD5EabTdYHYD9E5R0SeFvW0VoEVuhWHJnI+PXWjohevsLhDxFdKOfgVT+tXA27My0LvMnvnFOA7PERGvE2zDslvkxg4bWUP+A8C1w3PQaDjKoWQ9QFtTl/xZ+Cri7MaHdIjYoQ/YmtZkUnxjy6PGzPB+Mw76UrnL221Qyrnc/FPJrF7Bnl9WQHb3iPzWbGvKV9gsoNdY7sNR4lUFW6vfXn/CzvKUpcxXvDmcJ5SfwUi+chxrsxleRaTt2VVs31f3DKfAwrzdVoOnSapD1O4UVNIvtcTrtVrwtSpcZV8dh5uCT1XpkNlpeOoV/GjU990vl/qG2bkUVkv+yIqpr+Dg2VXQzGgXW7kpvYY5LUHT7pD+fUjc44Z0O+Cn3eBO3JnFmFVnKfXNCdu+GvAIjGf7+N50aWCHGmeP3236r4+cX7ysFqGzlBxCLpcvBvPLT4vPlx+uB8O9Z7imfAUv+5TpI5iiW5kRLi984mp/aWmpt9c+UluEV+9rbQPTLl8p4G+QJVi9Iwl2hXE+4yEZh+dDcuoX2gu9kFIgKGhGOdI/WtOHo6lWpHN4njtSdI8L5u3ZbtiZ3D7C05FsP36I69k79/8TXLHGrtT/r+S1KkAfatmbybvZLD6dPcWk28oP/wEJMkhh

Steps to fix

When adding you need to add the make-default and combined with nextTick we have access to it.

//parent
<template>
  <TresCanvas>
    <ThirdPerson />
    <ChildComp/>
  </TresCanvas>
</template>

//ThirdPerson
<template>
     <OrbitControls make-default />
 </template>
 
 //ChildComp
 <script setup lang="ts">
 import { useTresContext } from "@tresjs/core";
 import { nextTick } from "vue";
 
const { controls } = useTresContext();

console.log("Controls Is NULL", controls.value)

nextTick(() => {
    console.log("We now have access to controls",controls.value)
})
</script>

Code of Conduct

@duc-ekahau
Copy link

Confirm this is a real bug and it happens for our case. In our case, we want to have some transition animation, so we are implementing moving the camera from top down to some certain x,y,z. However, we also have Orbit control in our screen, hence, we need to detect when the orbit control "starts" to stop the transition, otherwise, the camera will try to bounce back to x.y.z whenever the user move around with orbit control

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants