Skip to content
This repository has been archived by the owner on Feb 10, 2023. It is now read-only.

Moving instancedMesh individual instances #103

Answered by IRobot1
Polyterative asked this question in Q&A
Discussion options

You must be logged in to vote

You were close. I'll let you fix the movement logic.

  onAnimationReady($event: { state: NgtRender; object: Object3D }): void {
    let object = <InstancedMesh>$event.object;

    this.data.forEach((child, index) => {
      let distanceFromCenter = child.position.distanceTo(new Vector3(0, 0, 0));

      // move the individual instance closer to the center 0,0,0
      child.position.add(new Vector3(-distanceFromCenter / 100, -distanceFromCenter / 100, -distanceFromCenter / 100));

      const matrix = new Matrix4();
      matrix.setPosition(child.position);
      matrix.scale(child.scale);
      object.setMatrixAt(index, matrix);
    });

    object.instanceMatrix.needsUpdate = true;
  }

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Polyterative
Comment options

Answer selected by Polyterative
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants