As outlined in the information provided by the three.js documentation
.userData : Object
This particular object serves as a repository where custom data related to Object3D can be stored. It is advised not to incorporate references to functions as they will not undergo cloning.
Moreover, what exactly does Object3D entail?
Object3D essentially acts as the fundamental class for numerous objects within three.js and boasts a collection of properties alongside methods tailored for the manipulation of 3D objects.
Hence, it becomes evident that Object3D assumes the role of the foundational class for a broad array of objects in three.js such as Cameras, Lights, Meshes, Materials, among others.
Whenever there arises a necessity to retain particular custom details about an object which may subsequently be utilized for presentation or any form of calculation, such information should be housed within the .userData
attribute.
To elucidate further, envision a scenario where you have produced a geometry (for instance, a BoxGeometry) and wish to monitor the count of user clicks on said geometry. This tally can conveniently reside within the .userData
property. At a later point, this recorded count can be put to use however deemed appropriate—be it for display purposes or for carrying out additional computations.