THREE.Interactive icon indicating copy to clipboard operation
THREE.Interactive copied to clipboard

It is recommended to mention the `name` field in the documentation

Open wang1212 opened this issue 2 years ago • 1 comments

A common programming idiom is to call add() when the object (interactive) is created, and then call remove() when the object is destroyed.

However, due to the lack of understanding of the source code details, if the name field of the object is not assigned, it will cause all objects called remove() to be removed.

https://github.com/markuslerner/THREE.Interactive/blob/v1.6.1/src/index.ts#L223

remove() {
   if (!object) return;
   const filterSet = new Set<string>(
     childNames.length > 0 ? childNames : [object.name]  // If `name` is `undefined` ?
   );

  this.interactiveObjects = this.interactiveObjects.filter(
    (o) => !filterSet.has(o.name)  // If `name` is `undefined` ?
  );
}

So, if I understand correctly, the name field value of a 3D object should be unique? If yes, is this critical and should it be specifically mentioned in the docs?

wang1212 avatar Mar 31 '23 06:03 wang1212

Hi @wang1212, thank you for pointing this out. There was indeed a bug in the remove function. The intention was not to make object.name mandatory. I just published release 1.7.0, which fixes this. Now all objects, whose name is undefined won't be removed when calling InteractionManager.remove(...) with an object whose name is undefined.

markuslerner avatar Mar 31 '23 08:03 markuslerner