Tresjs / tres

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

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

Closed hexianWeb closed 2 months ago

hexianWeb commented 4 months 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 4 months ago

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

alvarosabu commented 4 months ago

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

andretchen0 commented 4 months ago

Possibly related

garrlker commented 4 months ago

@hexianWeb is this issue fixed for you in version 4.2.0?

hexianWeb commented 3 months ago

Yes, it has been fixed after version tresjs 4.2.0