three-spritetext icon indicating copy to clipboard operation
three-spritetext copied to clipboard

Crash when dragging nodes together with SpriteText

Open alierdogan7 opened this issue 7 months ago • 2 comments

Hi @vasturiano, I render SpriteTexts with your nice library threesprite-text along with SphereGeometry in the same Mesh object, as you adviced in one of issues in order to display 2D text over nodes.

(node) => {
      const material = new THREE.MeshLambertMaterial({
        color: node !== hoverNode ? "gray" : "red",
        transparent: true,
        opacity: 0.75,
      });

      let geometry = new THREE.SphereGeometry(24, 32, 16);
      const meshObject = new THREE.Mesh(geometry, material);
      if (node.id) {
        const labelText = new SpriteText(node.id!.toString());
        labelText.color = "red";
        labelText.fontWeight = "bold";
        labelText.textHeight = 30;
        labelText.position.set(25, 25, 25);
        meshObject.add(labelText);
      }
      return meshObject;
    }

image

It works great, but if I try to drag nodes by clicking the sprite text instead of the sphere object it causes multiple crashes in the internals of ThreeJS library's DragControls as below:

image

I prepared this codesandbox for minimal reproducable example: https://codesandbox.io/p/sandbox/react-force-graph-threesprite-text-6mpzsk

As a workaround I thought disabling the mouse over events on SpriteTexts so that clicking on texts won't cause a drag event but couldn't find a way to do so.

Also, if I disable either showing spritetexts or highlighting nodes on hover, the crash goes away.

Do you have any suggestions to prevent the crash?

Thanks for the great library and support!

alierdogan7 avatar Jul 11 '24 13:07 alierdogan7