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

Raycaster does not detect click on GltfModel #67

Closed
oneWaveAdrian opened this issue May 28, 2021 · 12 comments
Closed

Raycaster does not detect click on GltfModel #67

oneWaveAdrian opened this issue May 28, 2021 · 12 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request

Comments

@oneWaveAdrian
Copy link

Great library!

When I use Raycaster it does not detect clicks on loaded Gltf-Models.
When I activate the option intersectRecursive and then console log the click event, the intersectObjects list only contains meshes with a direct parent of scene and no loaded models.
Is there a hidden attribute that has to be set in the Gltf-Model loading process?

@oneWaveAdrian
Copy link
Author

Did nobody encounter this before...?

@klevron klevron added the enhancement New feature or request label Jun 1, 2021
@klevron
Copy link
Member

klevron commented Jun 1, 2021

Hi, thanks, did you try with raycaster component ?
https://troisjs.github.io/guide/meshes/events.html#raycaster-component

@oneWaveAdrian
Copy link
Author

Jup, here is a minimal reproducible example: https://glitch.com/edit/#!/apricot-neighborly-century

After glancing over the raycaster code I assume that gltf models are not added to the list of intersect objects upon load. Is there a way to do it manually?

@oneWaveAdrian
Copy link
Author

I attempted to fix this. @klevron can you verify that this is correct? I don't have a local trois instance yet and purely did this by comparing the process on mesh.ts

@klevron
Copy link
Member

klevron commented Jun 3, 2021

Thanks for your PR, I will handle this asap because there's another problem : raycaster component don't work with gltf because it's a group (not a mesh) and intersectObjects is not updated when model is loaded

@klevron klevron self-assigned this Jun 3, 2021
@klevron klevron added the bug Something isn't working label Jun 3, 2021
@oneWaveAdrian
Copy link
Author

Hey @klevron, this issue is currently blocking a project of mine - is there any way I can support you to get this working faster?

@klevron
Copy link
Member

klevron commented Jun 7, 2021

Hi, sorry, will handle this tomorrow

klevron added a commit that referenced this issue Jun 8, 2021
@klevron
Copy link
Member

klevron commented Jun 8, 2021

This should work with 0.3.2, you can use :

<Renderer :pointer="{ intersectRecursive: true }">
  <Camera :position="{ z: 1 }" />
  <Scene>
    <GltfModel @click="onClick" src="..." />
  </Scene>
</Renderer>

Or :

<Renderer>
  <Camera :position="{ z: 1 }" />
  <Scene>
    <Raycaster intersect-recursive @click="onClick" />
    <GltfModel src="..." />
  </Scene>
</Renderer>

@oneWaveAdrian
Copy link
Author

@klevron I updated the glitch from above. Running into another issue now.

image

In the glitch the click function for box fires twice, when I click once, while the gltf model behaves normal (see screenshot).

In my other project it behaves exactly the other way around. GLTF fires twice.

@klevron
Copy link
Member

klevron commented Jun 8, 2021

You should use :

<renderer ref="renderer" antialias orbit-ctrl resize="window" :pointer="{ intersectRecursive: true }">
  <camera :position="{ z: 10 }"></camera>
  <scene>
    <point-light :position="{ y: 50, z: 50 }"></point-light>
    <box
      ref="box"
      :rotation="{ y: Math.PI / 4, z: Math.PI / 4 }"
      @click="gotClicked('Box')"
      :position="{x: 1}"
    >
      <lambert-material></lambert-material>
    </box>
    <gltf-model
      ref="mars"
      src="https://cdn.glitch.com/7196f70c-5654-466a-aa15-c2d49cf73ffc%2Fmars.glb?v=1622584963291"
      :position="{x: -1}"
      @click="gotClicked('Snickers')"
    />
  </scene>
</renderer>

You don't need to use Raycaster component

@oneWaveAdrian
Copy link
Author

@klevron thanks!
For documentation purposes, when should raycaster be used and when is it sufficient to use pointer ?
I will happily write the article for this later, just want to be sure I'll get it right

@klevron
Copy link
Member

klevron commented Jun 8, 2021

You can use Raycaster if you need to raycast all objects (scene.children), the events props has to be set on Raycaster component : <Raycaster @click="onClick" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants