Highlighting a grouped mesh by parenting

Hello,

I’ve got a a set of box meshes which I’ve grouped together by setting them all to the same parent. Is there anyway I can do actions to the multiple set of meshes in one go? I tried adding highlight to parent and it doesnt seem to work. I’ve checked the bounding box of the parent, and it seems correct (the bounding box added up all the meshes). Is the only way is to loop through all the children and highlight for each of the children? It seems pretty intensive.

Thank you!

Hiya @kzaky, welcome to the forum. Sorry for the slow replies.

I think you are correct… it seems “intense” to use glow or highlight to “select” (and de-select) a parent and its children. I have no solutions at this time. Let’s hope others have some miracle ideas.

I did do some tests… using glowLayer.

https://playground.babylonjs.com/#129LNB#11

Just a pile of junk, both mesh-wise and code-wise :slight_smile:

I was HOPING that the glow layer feature had a simple .includedMeshes property into-which I could “copy” pickedMesh.getChildren(null, false) // an array of all descendants, even non-direct).

But no. Glow uses ._includedOnlyMeshes and ._excludedMeshes …arrays that seem to contain mesh.uniqueId’s… a completely different “data format” than that returned-by pickedMesh.getChildren(null, false). So, no easy “plug’n’play” of arrays of mesh… into a glowMachine.

AND SO… we seem to need these goofy little for-loop iterations… using some “add()” and “remove()” methods on the glow layer… like that seen in playground lines 93-96…

for (mesh of pi.pickInfo.pickedMesh.getChildren(null, false)) {
    glow.addIncludedOnlyMesh(mesh);
    glow.removeExcludedMesh(mesh);
}

“Intense” is exactly correct.

Anyway, in that playground… top gray box has 4 direct descendants (one of each color), and about 80 indirect descendants. The level below it (4 boxes)… each have 20 descendants. The level below that… each have 4 descendants. (sorry for the bad positioning of the kids of kids of kids pyramid - not very intuitive). See console for more goods.

Clicking ground turns-off all glowings.

Just a testing playground. I wanted to “feel” the “intense”. :slight_smile: I didn’t test the highlightLayer feature… only glowLayer. But glowLayer is certainly not designed for easy select-o-mesh, is it? It is rather inconveneint to loop-thru meshes… using it’s addxxxxx() and removexxxxx() upon two separate arrays of mesh.uniqueIds (._includedOnlyMeshes and ._excludedMeshes properties). Painful!

I guess we’ll listen for more ideas. This is definitely an issue that could use some improvements/new features. Parent/child groups would gain lots of power… if we had an easy way to select/de-select them, eh? Yep. Darn. Sorry that I have no good news.

We don’t have a mesh.showBoundingBox({includeSummedAreaOfAllDescendants: true}); METHOD, either, do we? We DO have a mesh.showSubMeshesBoundingBox = true; thing… but I don’t think that is for us. subMeshes !== children. hmm.

1 Like

Thank you so much! I’m glad someone even replied, let alone helping out and doing things in details. In my original post, I stated that I will have a large set of box meshes. Would this be more efficient by having 1 single custom mesh that make up the vertices and indices of these set of boxes?
again, thank you very much !

My pleasure, thanks for the returned kindness… nice of ya.

I think that depends-upon many factors, like how often you need to add/remove boxes from the group, and how “clustered” the group will be, etc. We have a mergeMeshes feature… but after the merge, the meshes cannot be re-separated. BUT, you CAN maintain a group in 2 forms… the separated version, and the merged version.

Without knowing your project, it is difficult to determine more-efficient ways.

After a group of mesh are merged… then yes, it is treated as a single mesh… easy to highlight or glow. But merged groups have limits… such as… difficult to drag/drop children to different positions/rotations within the group. I don’t know if you will ever need to do that, or not.

https://doc.babylonjs.com/how_to/how_to_merge_meshes

Playground search for mergeMeshes: Playground search page | Babylon.js Documentation

It might be worth examining and testing. shrug

There might be a solution with Babylon’s SPS system, too. It is a “solid particle system” that “digests” mesh primitives such as boxes, and then the SPS.mesh is treated like a single mesh, even though its .particles array contains many boxes (or other mesh shapes).

Example: https://playground.babylonjs.com/#LXXL6Y#13

Many boxes, as particles. BUT… as you can see in lines 64-68, I am failing to get the solid particle system ‘mesh’ to use glow. Glow uses mesh.material.emissiveColor… and I don’t know how to activate a standardMaterial.emissiveColor on each SPS box-particle. I would need to experiment.

An SPS “central mesh” might never be able to be glowed or highlighted… due to what it is. Not sure. It might not have “geometry” in the same way as standard mesh. (I’m no pro at SPS or much of anything, really). Maybe some SPS experts will visit the thread. Maybe @jerome ? (thx J)

I HOPE others comment, because… efficiency questions/concerns are not my expertise. I’m just a youngster, programming/tech-wise - a 4-year-old driving a top-fuel dragster. :slight_smile:

Perhaps, in the end, you will find that creating a custom function like toggleHighlightOfParentAndKids()… is the most efficient way for your project. Does “efficient” sometimes mean… “easy for YOU to use, even if not lightning fast”?

Kzaky’s Family-Highlighting Toolkit… v1.0 :slight_smile: Sure, the function(s) is/are tedious/intense, but you only need to code it once, and then you use it like a maniac… easily. AND, the rest of us get to steal your code/toolkit… cuz it’s super handy/powerful. :smiley:

1 Like

Thank you very much Wingnut! the merge mesh is just what I needed! since I wont be manipulating the position of children in anyway. If I do, I’d be manipulating the whole children(parent) which is perfect with merge mesh. Don’t worry, it is really helpful to get any help I can from anyone since I’ve just started 3D and Babylon around 3-4 weeks ago :).

Thank you!

1 Like

Cool! You’re doing great… you speak like a pro. Good luck, welcome to Lake Babylon!

It’s a nice town… and we serve REALLY cold beer. :slight_smile:

Hi Wingnut,
you’ve just forgotten to give the sps mesh a material :wink:
https://playground.babylonjs.com/#LXXL6Y#14
https://playground.babylonjs.com/#LXXL6Y#15
For the per particle material, well, just wait that I implement the SPS multimaterial support …

1 Like

Oh, well that was easy enough. Thx J! Very nice!

1 Like