Attach mesh to a cloned mesh - how do you do this?

Hi there, I hope someone can help me please. I would like to attach a mesh to another mesh. In my playground you should see a glb cube with the number one on it. This is a mesh I want to attach to another mesh.

To see what I am looking for, right-click on the red roof area and a sphere will appear. Select it (left click… the gizmo appears) then click the grey sphere button below. The sphere’s colour will change to blue. It is at this point I need help. I would like the numbered cube to attach to the centre of the sphere. When the gizmo is used the sphere and cube should move together. Right-click on the roof space again…this time use the grey cube button to make the new sphere orange in the same way as before. But this time a cube numbered 2 is attached.

Each cube mesh has been loaded: line 135 to 141. (The cube with 1 on it would normally be hidden at the start. I just wanted you to see it right away in the playground).

Both the spheres and cube should delete, when selected, and the ‘bin’ button is clicked (they should delete one at a time).
Help with this would be appreciated.
Ps, if you are interested, the reason for attaching numbers is for accessibility. I can’t have colour alone indicating a certain sphere.

Have you tried to parent the cube to the sphere by using cube.parent = sphere;? I have done a quick test by adding scene.getMeshByName("Clone of Cube").parent = newDevObject.rootNodes[0]; at line 54 and it seems to work (you will have to offset the cube if you don’t want it to be at (0,0,0), so at the center of the sphere).

Also, I would advise to simplify your playgrounds and make the shortest PG as possible that demonstrates the problem if you want to maximize the chances that people will help because not many people may have time to go through the 300+ lines of a PG to understand what’s going on.

Hi Evgeni_Popov, thanks for your reply.

Sorry, I should have cut the code down a bit. I have a cut down version here I should say that this is the most ambitious project I have ever worked on…coding is still a strange thing to me.

I was really wanting the numbers to stay on each generated coloured sphere. It’s good that your line of code places a cube instantly on the first sphere generated (I want that), but I think the code needs to be around line 160, and also in the similar code for the orange generating sphere button (the cube) I know the buttons don’t make sense…the buttons are just placeholders for now.

So, the idea is that once several blue and orange spheres are placed around the space you will see many attached 1 and 2 cubes dotted around. You may see 4 of the 1 cube, and 6 of the 2 cube. This is so that you can identify a number of coloured spheres if you are colour blind. I hope this makes sense.

Cheers :smiley: