Jump to content

Action Manager and OnIntersectionEnterTrigger


gryff
 Share

Recommended Posts

After a lot of procrastination, I have started playing around with the Action Manager and quite enjoying it (after Temechon pointed out the necessary BJS to use).

 

I have been testing it with mesh picking and intersecting. With mesh picking I can use ExecuteCodeAction to call a function , and in that function use this line of code to get the mesh name

var aMeshName = myScene.meshUnderPointer.name;

 Question I have is how can I get the name of the mesh I have just intersected with?

 

cheers, gryff :)

Link to comment
Share on other sites

And another little question. I want to disable (not change its on/off state) a light through the Action Manager. I've tried these lines of code:

mesh.actionManager.registerAction(new BABYLON.SetValueAction({ trigger: BABYLON.ActionManager.OnIntersectionEnterTrigger, parameter: camSensor }, light, "setEnabled", false));andmesh.actionManager.registerAction(new BABYLON.SwitchBooleanAction({ trigger: BABYLON.ActionManager.OnIntersectionEnterTrigger, parameter: camSensor }, light, "setEnabled", false));and mesh.actionManager.registerAction(new BABYLON.SwitchBooleanAction({ trigger: BABYLON.ActionManager.OnIntersectionEnterTrigger, parameter: camSensor }, light, "isEnabled", false));

none of them  work.

 

Any thoughts gratefully appreciated

 

cheers, gryff :)

Link to comment
Share on other sites

Hey gryff, 

 

 

 

Question I have is how can I get the name of the mesh I have just intersected with?

 

Yes you can. In your callback function of ExecuteCodeAction : 

function(evt) {   // myarray is an array containing all meshes colliding with your mesh   var myarray = evt.source._intersectionsInProgress;}

Next question : 

 

 

 

 I want to disable (not change its on/off state) a light through the Action Manager

 

I don't know how you can disable a light in a scene but I will guess you can use the function setEnabled. If so, you can use : 

mesh.actionManager.registerAction(new BABYLON.SetValueAction({ trigger: BABYLON.ActionManager.OnIntersectionEnterTrigger, parameter: camSensor }, light, "_isEnabled", false));

or : 

mesh.actionManager.registerAction(new BABYLON.SwitchBooleanAction({ trigger: BABYLON.ActionManager.OnIntersectionEnterTrigger, parameter: camSensor }, light, "_isEnabled"));

(Code not tested).

 

Cheers !

Link to comment
Share on other sites

isEnabled() return boolean but does not modify and setEnabled(boolare functions and it is asking "property" in switchBooleanAction or SetValueAction for example.
 
It would be interesting to have a property for the lights with a boolean for the show or hide.
 
light.show = true || false; //for example would be good
 
Otherwise: (ExecuteCodeAction)

mesh.actionManager.registerAction(new BABYLON.ExecuteCodeAction({ trigger: BABYLON.ActionManager.OnIntersectionEnterTrigger, parameter: camSensor },     function() {          if(light.isEnabled() == false) {               light.setEnabled(true);          } else {               light.setEnabled(false);          }    }}));
Link to comment
Share on other sites

isEnabled() return boolean but does not modify and setEnabled(boolare functions and it is asking "property" in switchBooleanAction or SetValueAction for example.

 

It would be interesting to have a property for the lights with a boolean for the show or hide.

 

@dad72: I was thinking that way too. And I was figuring that I would have to use some "ExecuteCodeAction" in some way.

 

But then I tried Temechon's suggested code - and it worked.  :)  You can try it here:

 

Actions and Lights in Zones

 

The pink cube is a "pick" action that toggles its material. Move the little blue cube (attached to the free camera) towards a corner watch lights go on and off. 

 

(Edit: Updated the scene so now there are 9 lights - a Hemi and two Pointlights per colour zone .)

---------------------------------------------------------------------------------------------------------

 

@Temechon: I have absolutely no idea why your code works. The difference between code I tried and your code seems to be the little underscore.

 

My code: "isEnabled" -  throws errors.

Your code "_isEnabled" - works like a charm.

 

A little question - why? (Or is that part of the "Black Arts" that is involved in writing javascript? :o )

 

dad72 and Temechon - TY both for thoughts and ideas. And thanks to you Temechon for that second tutorial of yours that got me investigating the Action Manager :)

 

cheers, gryff :)

 

Link to comment
Share on other sites

It's totally black magic ! :)

 

Actually, the underscore means private members in javascript. But in Javascript, private does not exist, everything is public, and the underscore is more than a naming convention.

 

You can see in the method setEnabled in class Node that the attribute set to false is...this._isEnabled, With the underscore :) 

 

Cheers, 

Link to comment
Share on other sites

Normally isEnabled() or _isEnabled is done to check whether true or false. It is of course possible the put a false or true, but not the interest of this function.

 

setEnabled() is to write and the variable isEnabled() a true or false.

 

Even if this works, this is not the good ways of the used.

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