What are the uses of Group in three.js?

I need to know the uses of Grouping in Threejs. Please any one say?

I never use it - it’s so similar to Object3D, but it is specifically designed for containing groups of meshes, so that’s what it’s for. Object3D is the parent class for meshes and other objects, so Group is intended to be used for grouping, preserving Object3D for the purposes of inheritance.
Best practice is to use group, I guess for the sake of future developments that might put Object3D out of reach.

1 Like

@Cotterzz You are right, Group is basically syntax sugar so it becomes more clear when objects are grouped together. However, there is one additional effect when using groups:

If you set the renderOrder property for an instance of Group, all descendants objects will be sorted and rendered together. This is very useful if you are going to render e.g. sprite characters. Inspired by Unity’s Sorting Group :innocent:

9 Likes

Can You please share an example application with Grouping.

What are the uses if the objects are grouped together?

let boxes = new THREE.Group
let geo = new THREE.BoxGeometry(1,1,1)
let material = new THREE.MeshBasicMaterial({color: ‘ffffff’})
let mesh = new THREE.Mesh(geo,material)
boxes.add(mesh)

This is a basic example of group
you can refer doc https://threejs.org/docs/#api/en/objects/Group

@Yash_Joshi. I know the syntax for that. I need to know the use of adding the object into a group

it collect all the meshes together you are able to manipulate them as group like move them together and rotate them

2 Likes

@Mugen87 Thanks, that’s useful to know. I guessed there might be more to it.
I’m regularly extending Object3D to make new es6 classes, so I use it all over the place.
It does the job but I’m guessing this isn’t best practice?

@jaya_kannan adding objects to a group means you can treat them as a single object and rotate/scale/move them as one. Also, as Mugen87 said - it gives you some better depth sorting options and allows you to apply a depth to them as one layer, if I read that right.

Doing so is just fine. Apart from the renderOrder thing, Object3D and Group are identical. At least up to R108^^.

Scaling several objects at a time like if they were just 1 is definitely quite handy.

2 Likes

I’m using it to group stars in celestial sphere, then I can rotate this group instead of rotate each star

astroweb.kimuningenieria.cl

1 Like

Oh. Thank you