gryff Posted July 31, 2014 Share Posted July 31, 2014 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 namevar aMeshName = myScene.meshUnderPointer.name; Question I have is how can I get the name of the mesh I have just intersected with? cheers, gryff Quote Link to comment Share on other sites More sharing options...
gryff Posted August 1, 2014 Author Share Posted August 1, 2014 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 Quote Link to comment Share on other sites More sharing options...
Temechon Posted August 1, 2014 Share Posted August 1, 2014 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 ! gryff 1 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted August 1, 2014 Share Posted August 1, 2014 isEnabled() return boolean but does not modify and setEnabled(bool) are 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); } }})); gryff and GameMonetize 2 Quote Link to comment Share on other sites More sharing options...
gryff Posted August 1, 2014 Author Share Posted August 1, 2014 isEnabled() return boolean but does not modify and setEnabled(bool) are 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? ) 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 Quote Link to comment Share on other sites More sharing options...
Temechon Posted August 1, 2014 Share Posted August 1, 2014 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, Quote Link to comment Share on other sites More sharing options...
Dad72 Posted August 1, 2014 Share Posted August 1, 2014 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. GameMonetize 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.