Tresjs / tres

Declarative ThreeJS using Vue Components
https://tresjs.org
MIT License
1.93k stars 86 forks source link

Mesh that are delayed Join in the scene cannot trigger events #758

Open hexianWeb opened 6 days ago

hexianWeb commented 6 days ago

Describe the bug

I wrote in the code

onMounted(() => {
  setTimeout(() => {
    showRef.value = !showRef.value
  }, 2000)
})

&

  <!--mesh with click event-->
  <TresMesh :position="[2, 2, 0]" name="Father" @click="handleClick" v-if="showRef">
    <TresSphereGeometry :args="[1, 1]" />
    <TresMeshNormalMaterial />
    <Html :position="[0, 0, 0]" center>
      <span class="cool-font">Click delay event</span>
    </Html>
  </TresMesh>

I found out it couldn't trigger the event! This also happens with primitive load large glb file. But interestingly, this error may be avoided by moving the mouse in Canvasafter all model or mesh have been "loaded in the scene".

The mouse is always in the canvas (Broken)

https://github.com/Tresjs/tres/assets/59913119/e3171f55-ac9b-4f59-9848-3d5c714c42fe

The mouse enter canvas after mesh "loaded"

https://github.com/Tresjs/tres/assets/59913119/aa553c7a-355f-4d9d-a616-be3b99bf772e

Reproduction

https://stackblitz.com/github/hexianWeb/starter/tree/event-register

Steps to reproduce

If the user case is broken, please tell me in time

System Info

No response

Used Package Manager

pnpm

Code of Conduct

hexianWeb commented 6 days ago

useTresEventManager\index.ts, objects added later will not appear in the hits collection

alvarosabu commented 5 days ago

Hey buddy @garrlker mind taking a look at this one when you have a chance? Thanks 🙏🏻

andretchen0 commented 1 day ago

Possibly related