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

Best way to add dynamic external object #671

Open
MathieuSlt opened this issue Mar 5, 2024 · 0 comments
Open

Best way to add dynamic external object #671

MathieuSlt opened this issue Mar 5, 2024 · 0 comments

Comments

@MathieuSlt
Copy link

I want to surround some of my nodes with externals objects to create kind of groups of nodes.

I am doing it using the onEngineTick callback. I am getting all of my nodes coordinates and create a THREE.ConvexGeometry.

here is a simplify version

this.Graph.onEngineTick(() => {
  const coordinates = []
  forEach(node => 
      coordinates.push(getCoordinates(node))
  )
  const existingMesh = this.Graph.scene().getObjectByName(MESH_ID);
  const convexGeometry = new ConvexGeometry(coordinates);

  if (existingMesh) {
        existingMesh.geometry.dispose();
        existingMesh.geometry = convexGeometry;
  } else {
        const meshMaterial = new THREE.MeshLambertMaterial();
        const mesh = new THREE.Mesh(convexGeometry, meshMaterial);
        mesh.name = MESH_ID;
        this.Graph.scene().add(mesh);
  }
}

The problem is that on every tick there's a lot of calculation to determine the coordinates and the geometry.

I wanted to know if there are good practices to add a dynamic external element, if to use onEngineTick is judiscious for this example or if there is another way ?

Thanks for the potential ideas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant