joeBImagine Posted November 17, 2017 Share Posted November 17, 2017 Hello BabylonJs peeps!! I am currently able to select and deselect a mesh using actions and triggers as seen in this included playground: http://www.babylonjs-playground.com/#WG9OY#9. I am curious however if there is a way to deselect the mesh if you click anywhere in the scene or even on another mesh Also when I create the same code using an array of meshes, I get errors. I thought wrapping the solution into a for loop would work, but alas I think I am missing something. for (i = 0; i < newMeshes.length; i++) { //select the meshes in the scene newMeshes[i].actionManager = new BABYLON.ActionManager(scene); var hl1 = new BABYLON.HighlightLayer("hl1", scene); const action1 = new BABYLON.ExecuteCodeAction( BABYLON.ActionManager.OnPickTrigger, () => { hl1.addMesh(newMeshes[i], BABYLON.Color3.White()); } ); const action2 = new BABYLON.ExecuteCodeAction( BABYLON.ActionManager.OnPickTrigger, () => { hl1.removeMesh(newMeshes[i]); } ); newMeshes[i].actionManager.registerAction(action1).then(action2); } Quote Link to comment Share on other sites More sharing options...
brianzinn Posted November 18, 2017 Share Posted November 18, 2017 The thing about removing meshes is that the unique ID of the mesh is used internally for removing a mesh from a highlight layer (https://github.com/BabylonJS/Babylon.js/blob/master/src/Layer/babylon.highlightlayer.ts#L812). So, you will need to remember what is highlighted. I made a PG where the mesh is deselected when you click on a new one. In the PG if it's not a sphere you could just deselect. http://www.babylonjs-playground.com/indexstable#WG9OY#15 ** Right now the playground is not working for me for even basic scenes on 'latest', so just click on the "version" dropdown and click stable. joeBImagine and Wingnut 2 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted November 19, 2017 Share Posted November 19, 2017 Hi guys. Yeah, something is strange in that PG. Load-in, click a few times, and try RUN again. Stuff goes to heck, stable version or not. Strange. Firefox. I've seen this on some playground physics demos, too. Can't RUN it more than once. e.physicsBody is undefined. Hmm. I was going to try to add the "click in unoccupied space = de-select all" -feature, but the PG was so annoying to edit... that I bailed. I think BJS 3.1 is getting ready to "ship", though I never understand where it is going to be shipped. But for some reason, these "ship" versions are given more love than un-shipped versions. So, there could be some unusual work happening, at this time. Thx for the click'n'glow PG demo, guys. tiz good... but it's giving something an upset stomach. brianzinn 1 Quote Link to comment Share on other sites More sharing options...
brianzinn Posted November 19, 2017 Share Posted November 19, 2017 @Wingnut I think stable is OK, but anything on latest was not working and also the playground kept switching to latest! I thought momentarily I was at a Pink Floyd concert or something - maybe just an acid flashback. sorry for the upset stomach! Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted November 20, 2017 Share Posted November 20, 2017 Pink Floyd! Cool! (Wingnut hugs you) Ok, let's talk for a moment about this "kept switching to latest". I don't think it's doing that. I think, when switching to stable version, a playground re-load needs to happen. The playground defaults to "Latest" for the selected choice in that selectbox. So when the PG reloads, it appears that we went back to "Latest" but that's a lie. Look at the URL - I think that is the only accurate indicator. Just thought I'd pass-on what little I know about it. Currently, I think the selector will indicate "Latest" no matter which version of BJS is selected. Sorry for the deek/foolery. I'm not sure it can be changed/fixed... but... we all can look it over and think about it, I suppose. Quote Link to comment Share on other sites More sharing options...
joeBImagine Posted November 20, 2017 Author Share Posted November 20, 2017 @brianzinn That is awesome thank you! Quick question, is there also a way to deselect the sphere if you click on the scene itself, in the same vein that applications like 3ds max, blender, etc work? Or would that be difficult as clicking in the scene is currently only mouse click and drag. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted November 20, 2017 Share Posted November 20, 2017 https://www.babylonjs-playground.com/indexstable#WG9OY#19 Added the else block in lines 63-65. Should work. joeBImagine 1 Quote Link to comment Share on other sites More sharing options...
joeBImagine Posted November 20, 2017 Author Share Posted November 20, 2017 @Wingnut you are awesome thank you!! You all make it look so easy!! Quote Link to comment Share on other sites More sharing options...
Wingnut Posted November 20, 2017 Share Posted November 20, 2017 Thx. It just takes some time to learn to think like { braces } Look at line 52: if (evt.pickInfo.hit && evt.pickInfo.pickedMesh !== undefined) { To re-word... if we hit something, and the thing we hit wasn't an "air-biscuit" (substance-less) ... do stuff. I said... oookay... but... what if it IS a miss, and an air-biscuit? Else... what? Shut off the highlight... that's what. But... yeah... that line 51-62 "glob" of code... is like looking-at shredded wheat in a blender. Nest-o-rama. :/ Once ya get braces-brain, it will all be better, but you will no longer be able to deal-with the un-structured-ness of daily life... after that. You'll have programmer's disease... and start expecting real life to act like a program. I won't get into all that. Wha cha workin' on? Got a project in-mind? Wanna share? You can do it here, but... The Wingnut Chronicles is a thread that is wide-open for yapping about anything. Drop a line there anytime, about anything. Party on! Quote Link to comment Share on other sites More sharing options...
joeBImagine Posted November 20, 2017 Author Share Posted November 20, 2017 @Wingnut that is good to know! And I finally figured out how to mark the thread solved hahaha!! I will let you know what I am working on over at the Wingnut Chronicles!! Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted November 21, 2017 Share Posted November 21, 2017 It's all good. There's multiple ways to mark as solved. Actually, it was probably MY fault... on this. I wrote the comment about making sure you mark "solved"... and then I looked, and you had already done that. Dummy me. So I deleted that part of the comment... but I think you already saw it. But now ya got it double-marked as solved, so... it is seriously solved. Indisputably solved. joeBImagine 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.