jroosterman Posted July 26, 2017 Share Posted July 26, 2017 I set up an OnKeyDownTrigger Action for my scene. scene.actionManager = new BABYLON.ActionManager(scene); scene.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnKeyDownTrigger, keyDownAction)); ... var keyDownAction = function (evt) { if (evt.sourceEvent.keyCode == 37) { evt.getSceneSomehow().doSomethingWithScene(); } else if (evt.sourceEvent.keyCode = 39) { evt.getSceneSomehow().doSomethingELSEWithScene(); } }; In the keyDownAction I want to get a reference to the scene that registered the action. Can I do this? Quote Link to comment Share on other sites More sharing options...
Wingnut Posted July 27, 2017 Share Posted July 27, 2017 Hi JR. I'm not sure why you would ever need to do that. var keyDownAction = function (evt) { console.log(scene); }; The actionManager is for the current scene. This actionManager registered a func within THAT scene's scope... called keyDownAction(). That func only exists in the scope of the current scene. The global scene variable is the scene you want, and it is ready for 'action'. For more scenes... scene2.actionManager = new BABYLON.ActionManager(scene2); scene2.actionManager.registerAction... scene3.actionManager = new BABYLON.ActionManager(scene3); scene3.actionManager.registerAction... This playground uses a scene.actionManager keydown func in lines 54-58. In line 57, I change the scene's background color... for every keydown. Unless I am mistaken (often I am), there is no need to derive/glean a ref to a scene object... from an evt object. Perhaps I have misunderstood, or I am blind to potential use-cases. It MIGHT be add-able to the BJS actionManager event object, but I'm not sure if it will be used. Using our 3-scene example above, are you wishing that all 3 scenes... use the same keyDownAction() handler? *nod*. I guess I can understand that. Smarter people than I may comment soon. Stay tuned. Quote Link to comment Share on other sites More sharing options...
brianzinn Posted July 27, 2017 Share Posted July 27, 2017 I wouldn't say that it's a global scene variable, but anything in scope where the function is declared will be available via Lexical Scoping: https://developer.mozilla.org/en/docs/Web/JavaScript/Closures Scene is not available from the OnKeyDownTrigger evt - here is what is available: https://doc.babylonjs.com/classes/3.0/actionevent So, looks like best bet is to have it in scope and then just use it - unless evt.meshUnderPointer.scene will always work? 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.