In the ongoing discussion in the question's comments, it has been pointed out that there is minimal disparity between a Group
and a Scene
. Both classes inherit the add
method from Object3D
(Object3D.add
)
Here is an illustration of how the process of adding/parenting works:
const scene = new THREE.Scene()
const group = new THREE.Group()
const mesh = new THREE.Mesh(/*...*/)
// scene.children == []
// scene.parent = null
// group.children == []
// group.parent = null
// mesh.parent == null
scene.add(mesh)
// scene.children == [ mesh ]
// scene.parent = null
// group.children == []
// group.parent = null
// mesh.parent == scene
group.add(mesh)
// scene.children == []
// scene.parent = null
// group.children == [ mesh ]
// group.parent = null
// mesh.parent == group
scene.add(group)
// scene.children == [ group ]
// scene.parent = null
// group.children == [ mesh ]
// group.parent = scene
// mesh.parent == group
The relevant section of the Object3d.add
function is as follows:
if ( object.parent !== null ) {
object.parent.remove( object );
}
This ensures that each object is only parented to one other object.
If your goal is to have meshes directly within your scene, but still want to organize them using Group
objects for organizational purposes, you can manually add them to the group's children
array. Just remember that if you remove a mesh from the scene later on, it will not be garbage-collected until it is removed from the group as well. Personally, I prefer using an array or a map for better management.