aframe icon indicating copy to clipboard operation
aframe copied to clipboard

Issue Raycasting Against Sprites

Open epiqueras opened this issue 3 years ago • 10 comments

https://github.com/vasturiano/react-force-graph/issues/356

epiqueras avatar Apr 18 '22 22:04 epiqueras

Can you describe the issue?

dmarcos avatar Apr 20 '22 16:04 dmarcos

I linked to the description and original discussion. I'm sorry that I wasn't clearer.

Raycasting against sprites fails with:

THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.
Uncaught TypeError: Cannot read properties of null (reading 'matrixWorld')

You can reproduce by running this:

<head>
  <style>
    body {
      margin: 0;
    }
  </style>

  <script src="//unpkg.com/react/umd/react.production.min.js"></script>
  <script src="//unpkg.com/react-dom/umd/react-dom.production.min.js"></script>
  <script src="//unpkg.com/babel-standalone"></script>

  <script src="//unpkg.com/three"></script>
  <script src="//unpkg.com/three-spritetext"></script>
  <script src="//unpkg.com/react-force-graph-vr"></script>
</head>

<body>
  <div id="graph"></div>

  <script type="text/jsx">
    function genRandomTree(N = 300, reverse = false) {
      return {
        nodes: [...Array(N).keys()].map(i => ({ id: i })),
          links: [...Array(N).keys()]
        .filter(id => id)
        .map(id => ({
          [reverse ? 'target' : 'source']: id,
          [reverse ? 'source' : 'target']: Math.round(Math.random() * (id-1))
        }))
      };
    }
    ReactDOM.render(
      <ForceGraphVR
        graphData={genRandomTree()}
        nodeAutoColorBy="id"
        onNodeClick={console.log}
        nodeThreeObject={node => {
          const sprite = new SpriteText(node.id);
          sprite.color = node.color;
          sprite.textHeight = 8;
          return sprite;
        }}
      />,
      document.getElementById('graph')
    );
  </script>
</body>

epiqueras avatar Apr 21 '22 02:04 epiqueras

Are you using A-Frame? It seems you're using THREE only + React?

If you are using A-Frame. Can you create a simple standalone example that reproduces the issue? Glitch is great

I'm not familiar with the libraries you're using and it's going to be hard for me to debug.

dmarcos avatar Apr 21 '22 19:04 dmarcos

I'm not familiar with how A-Frame is used here.

@vasturiano can you provide some context, please?

epiqueras avatar Apr 25 '22 20:04 epiqueras

@dmarcos thanks for looking at this!

I've made a simple example on Glitch that highlights the issue: https://glitch.com/edit/#!/aframe-raycaster-sprites

Essentially the scene includes just an a-frame component containing a simple ThreeJS Sprite, and a raycaster entity.

You'll notice that in the console this leads to the error:

"THREE.Sprite: 'Raycaster.camera' needs to be set in order to raycast against sprites."

Is this something that needs to be set inside the raycaster component perhaps? https://github.com/aframevr/aframe/blob/master/src/components/raycaster.js

vasturiano avatar Apr 25 '22 22:04 vasturiano

Running into this in a few projects. Any updates? Thanks!

sf17 avatar Dec 29 '22 14:12 sf17

I am also having an issue with this. Are there any updates? Thanks!

donkikos avatar May 14 '23 01:05 donkikos