Skip to content

How to access the THREE.js instance used by 3d-force-graph to avoid multiple imports? #729

@namedgraph

Description

@namedgraph

I'm using 3d-force-graph with custom node/link labels via three-spritetext, which requires access to the THREE namespace to create sprite objects.

Currently, I'm loading THREE.js separately:

<script src="https://unpkg.com/three@0.159.0/build/three.min.js"></script>
<script src="https://unpkg.com/3d-force-graph@1.73.3/dist/3d-force-graph.min.js"></script>
<script src="https://unpkg.com/three-spritetext@1.8.2/dist/three-spritetext.min.js"></script>

This causes two issues:

  1. Deprecation warnings (as of THREE.js r150+):
Scripts "build/three.js" and "build/three.min.js" are deprecated with r150+,
and will be removed with r160. Please use ES Modules or alternatives.
  1. Multiple instances warning:
WARNING: Multiple instances of Three.js being imported.

Question: Is there a way to access the THREE.js instance that 3d-force-graph uses internally, so I can avoid importing it separately? Something like:

const THREE = graph.three(); // or similar?
const sprite = new THREE.SpriteText('Label');

This would eliminate the multiple instances issue and align with THREE.js's move toward ES modules.

Use case: Creating custom three.js objects (sprites, geometries) for nodeThreeObject() and linkThreeObject() customizations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions