Jump to content

[Solved] Removing highlights when clicking in scene and Highlighting objects in an array


joeBImagine
 Share

Recommended Posts

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);
      }

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.  :o 

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.  :)

 

Link to comment
Share on other sites

:D  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.  :)

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.  :D  Indisputably solved.  :)

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...