Coder Social home page Coder Social logo

Comments (12)

klevron avatar klevron commented on May 25, 2024 5

Hi, sorry, will handle this tomorrow

from trois.

klevron avatar klevron commented on May 25, 2024 4

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>

from trois.

klevron avatar klevron commented on May 25, 2024 3

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

from trois.

klevron avatar klevron commented on May 25, 2024 3

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

from trois.

klevron avatar klevron commented on May 25, 2024 2

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" />

from trois.

oneWaveAdrian avatar oneWaveAdrian commented on May 25, 2024

Did nobody encounter this before...?

from trois.

klevron avatar klevron commented on May 25, 2024

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

from trois.

oneWaveAdrian avatar oneWaveAdrian commented on May 25, 2024

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?

from trois.

oneWaveAdrian avatar oneWaveAdrian commented on May 25, 2024

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

from trois.

oneWaveAdrian avatar oneWaveAdrian commented on May 25, 2024

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

from trois.

oneWaveAdrian avatar oneWaveAdrian commented on May 25, 2024

@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.

from trois.

oneWaveAdrian avatar oneWaveAdrian commented on May 25, 2024

@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

from trois.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.