How create a Group in script?

The docs mention “group” related to physics but not how to create a group of object like you can manually with objects from the library.

I dynamically created group of Cuboids in JavaScript and placed them together. I want be able to manipulate them as a group but I can’t find any way to do that??

Thanks,
Jim

I figured it out after another half hour of reading random api pages:( There really needs to be some example usage code in the docs…

objectParent.add(objectChild);
1 Like

Yes, it’s rather confusing. The parent.add(child) code mimics the CoBlocks, but doesn’t create a “Group” (which has it’s own name and peculiarities).

Group 2 Items together manually, and the Code snippet will give you something like:

Scene.getItem("sn4cB5ra") as Group;

however there’s no “Group” class in the documentation (even with deprecated turned on).

Nevertheless, if you add:

let myGroup = Scene.getItem("sn4cB5ra") as Group;
myGroup.transition.moveTo(new Vector3(0,0,0),3);

the group moves.

Can you make a new Group with an ItemCollection? Is Group an empty parent?

@Ilya.Shkuratov, you can enlighten us?

Basically Group is a special object with 0 size and mass and enabled physics. When you form a group in CoSpaces editor you basically create one such item and attach selected items to it.

There is no class Group in the documentation since there is no public API for it, so you cannot create a group from the script.

But one can get a similar functionally attaching all objects to a single parent, though in this case the parent will have a mass and size (but can be set invisible), which would make it behave a different in some scenarios compared to the Group made via the editor.

1 Like