Show / Hide Mesh on the click of a button?

Greeting,

I would like to completely remove the mesh from the scene by clicking on the button, and by clicking the button again, return the mesh to the scene. (Show / Hide)
This I did with the help of visibility, but it does not completely remove mesh from the scene.
How to completely remove mesh from scenes and restore it again by clicking on the button ???

This is a babylon playground example:
https://playground.babylonjs.com/#743FF8
I tried with meshone.dispose (true); but it does not work ā€¦
Does anyone have any idea or there is a regular way ???

https://doc.babylonjs.com/api/classes/babylon.mesh#setenabled

:slight_smile:

1 Like

Checkout the button code on mesh3 here : https://playground.babylonjs.com/#743FF8#1 It is worth noting that the loaded object wasnā€™t just a mesh, it was an array with two meshes.

2 Likes

:slight_smile: hmm. What IS the plural form of ā€˜meshā€™? Maybe meshi? mesha? heh.

ā€˜Meshesā€™ doesnā€™t feel right. Saying itā€¦ causes too much saliva movement and promotes spittle. :blush:

Should we treat him nice some more, TTC? https://playground.babylonjs.com/#743FF8#2

Gosh, I love that ā€˜ofā€™ directive. for (mesh of myMeshThree)

Iā€™m going to wear-out that ā€˜ofā€™ in no-time, so I guess I better order a case of them.

Iā€™m going to pay the extra $$$ ā€¦ and get the ā€œindustrial strengthā€ ofā€™s. :slight_smile:

2 Likes

Meshes :slight_smile:
Thank you for your answers
Wingnut very simple and concise answer ā€¦
timetocode. you answered in part to the next question ā€¦
To clarify;
My project has a model group that will be named (myMeshesOne, myMeshesTwo ā€¦), and each model group will be named by its name. Clicking this button should appear and disappear from the entire model group (myMeshesOne), which we successfully solved.

The next thing I need by clicking on the button is to remove an individual model within the model group (myMeshesOne, myMeshesTwo ā€¦). If I do this on a timetocode. example;
myMeshThree [0] .setEnabled (false)
myMeshThree [1] .setEnabled (false)
but if later add more models, a button names and sequence of model names is mixed.

Is there an option to show / hide an individual model within myMeshesOne group clicking the button, but to be based on the model name?
If I click on the button named
Show/Hide myMeshesOne Box One to remove
myMeshOne [BoxOne] .setEnabled (false),
Show/Hide myMeshesOne Box Two to remove
myMeshOne [BoxTwo] .setEnabled (false)

Example of babylon.js playground:
https://playground.babylonjs.com/#LGKV0P
myMeshesOne has two models named BoxOne and BoxTwo
myMeshesTwo has two models named SphereOne and SphereTwo
myMeshesThree has two models named CylinderOne and CylinderTwo

Ooooh, ā€œgrowingā€ buttons only AFTER all the mesh arrive in the scene! Cooooool.

Yep, eachMesh.enableDisableButton = a GUI button programmed to enable-disable IT. :smiley: Fun!

Each mesh could have an ā€œinfo panelā€ textBlock tooā€¦ which displays string text-infoā€¦ that arrived during the load-inā€¦ stored in the meshā€™s .metadata property. COOOOOOL!

Super-fun when it comes time to display those buttons in a sane/logical way. :slight_smile: yeah!

GUI smart-menuā€¦ able to traverse any subsection of the scene hierarchyā€¦ but never needing to display TOO MANY buttons at the same time. Menu only displays buttons for the subgroup of the subgroup of the subgroupā€¦ that the user is working-within. heh. Wild! Menu re-configs every time a subgroup is ā€œdrillied-intoā€, or ā€œbacked-out-ofā€. Nice.

I think AA is going to use HTML buttons on a sidebar, though (not BJS GUI).

Still, grow THAT HTML drill-able sidebar treeviewā€¦ after the scene is loaded and after the mesh-names gathered. Yum. I bet others have done that, already. PG inspector, BJS editor, and Dad72ā€™s many editorsā€¦ all probably generate HTML treeviewsā€¦ from scene graphs.

Might be a job for BJS Tags, which make great group identifiers and managers. Tags can be used similar to a mesh TYPE, and thereā€™s plenty of Tags System search power to gather/collect all mesh with similar tag-names, from within scene.meshes. Easy to set layerMasks and/or renderGroupIdsā€¦ based on tag-groups, too. Raspberry YUM!

I wonder if .tags is an unused mesh property on Blender mesh. Could add it via Blender Custom Propertiesā€¦ but Iā€™m not sure that it would make the trip to BJSville.

1 Like

Thank you for your replyā€¦
I found a solution;
Line: 107
https://playground.babylonjs.com/#LGKV0P#1
Uh ā€¦, Iā€™m learning ā€¦:wink:
Letā€™s go to the next level ā€¦

1 Like

Hey, nice work! Yeah, you should definitely go to the next level.

You have a brand new machete - quite sharp. You should be able to blaze some amazing and innovative trailsā€¦ with it.

You could possibly cut some bindings/vines, and maybe chop-up any teddy bears that you might still be hugging. :slight_smile: Take a little drinkā€¦ from your self-confidence canteenā€¦ youā€™ve earned it.

(What the hell is Wingnut talking about now?) heh.

Good olā€™ JS. Thereā€™s not really a proper way to do something. Instead, thereā€™s 10 ways to do something. If you want to find the BEST way of 10, it requires performance testing, and analysis of which ways the author/usersā€¦ like the most.


Hey fellow forum-folkā€¦

Does anyone know-of, or want to try/buildā€¦ a real-time-generated playground-based sceneGraph-To-HtmlTreeView JS routine?

I know the playground Inspector does thatā€¦ butā€¦ Iā€™m looking for something that we can edit in a playground, and is easy for Aldin to ā€œstealā€, if wanted. You knowā€¦ a generateDrillableHtmlSidebarSceneGraphTreeView() func. :slight_smile:

Extra credit for setEnabled toggle/checkboxes (at branch/group/layer levels, and at individual mesh level)ā€¦ just like the PG Inspector feature. But, hmmā€¦ disabled mesh must not leave the treeView upon being disabled.

(ā€¦or else user canā€™t re-enable. treeView item disappeared because of live treeview updatingā€¦ no good for enable/disable toggles. Only mesh.dispose can remove a treeView meshItem - duh, Wingy).

DOUBLE extra-creditā€¦ for restructureMeshBranchesByTagNames() feature. :wink: (as opposed to default parent/child branch structures). Then Aldin can load in PILES of meshā€¦ in a single fileā€¦ and use his precision-planned mesh tagNamesā€¦ to sort his mesh into groups/branches/layers.

Ooohā€¦ sort by layerMasks or renderingGroupIds! Coooooool. :slight_smile: (Wingnut grabs a Blender Collection from a 2.80 .blend fileā€¦ shows it to @JCPalmer and @gryff for no reason whatsoever, and then crams it into a nearby treeView control.)

1 Like

Oooo ā€¦, Iā€™ll drink a lot :wink:
Of the 10 ways, the best one is the simplest.
I found one of the solutions but also a small mistake ā€¦
If I click on the Show / Hide myMeshesOne Box One button and remove BoxOne, then I click on the Show / Hide MyMeshesOne button to remove everything, an error occurs: BoxOne appears and remove Box Two ā€¦
Maybe I should click Show / Hide myMeshesOne Box One to show or hide everything first and then hide or show it all. Any idea?

2 Likes

All your ideas sound good. Test test testā€¦ thatā€™s the part that is the most fun.

If you are haunted by cost-of-living deadlines/pressure/terrorism, that can kill experimenting fun. Iā€™m working-on fixing that issueā€¦ daily. :open_mouth: :smiley:

2 Likes