Subin George Posted June 11, 2014 Share Posted June 11, 2014 How do we identify the object whiel trigering a custom action?, See the example belowwindow.onload = function () { // Check support if (!BABYLON.Engine.isSupported()) { window.alert('Browser not supported'); } else { //var canvas = document.getElementById("renderCanvas"); var canvas = document.getElementById("canvas"); var engine = new BABYLON.Engine(canvas, true); var scene = new BABYLON.Scene(engine); var light = new BABYLON.DirectionalLight("dir01", new BABYLON.Vector3(0, -0.5, 1.0), scene); var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0, 10, BABYLON.Vector3.Zero(), scene); camera.setPosition(new BABYLON.Vector3(20, 70, 100)); light.position = new BABYLON.Vector3(0, 25, -50); var y = 0; i=0; var ddd2= BABYLON.Mesh.CreateBox('ddd', 20.0, scene, false); ddd2.position.y = y; y+= 45; ddd2.actionManager = new BABYLON.ActionManager(scene); ddd2.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPickTrigger,test)); var ddd3= BABYLON.Mesh.CreateBox('ddd4', 20.0, scene, false); ddd3.position.y = y; y+= 45; ddd3.actionManager = new BABYLON.ActionManager(scene); ddd3.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPickTrigger,test)); // Render camera.attachControl(canvas); engine.runRenderLoop(function () { scene.render(); }); } function test(){ console.log(this); }}; Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 11, 2014 Share Posted June 11, 2014 Next version will add a parameter to executecodeaction that will be the source object Quote Link to comment Share on other sites More sharing options...
Wingnut Posted June 12, 2014 Share Posted June 12, 2014 DK, will that affect http://www.html5gamedevs.com/topic/6706-drop-down-menu-mouseover/?p=40901 ? Are you SURE you don't want to send an 'event object' as a parameter to function targetted by executeCodeAction()? The 'event object' could contain lots of information... like pointerX and pointerY and (NAME or ID of) picked object/objectUnderPointer, etc, and it could expand in the future, as needed. I don't know. Just thinking. In subinapptest's example, he called a function called 'test'. But what if he called this.parent.setRotation(new BABYLON.Vector3(0, Math.PI/2, 0))? Ok, maybe not. I'm just being goofy. Ok, what if he called event.target.parent.setRotation(new BABYLON.Vector3(0, Math.PI/2, 0))? Nah. Still too goofy. I'm just trying some comedy here, but comedy with a reason. You see, people are used-to using functions named like onTouch/onLeftPick, and onRightPick, and onMiddlePick, and onMouseOver, and onMouseOut, and onTouchLift, and onRightLift, etc... because those are DOM-like names (sort of ). When those dom-type of functions are called, 'event' objects are sent as the parameter... and event objects have lots of information on them... that can be 'getted'. So if you sent a DOM-event-like object to the function being called... that would seem natural to folks, right? But if this doesn't fit your hope for a 'state machine'-like thing, just ignore me. You might have a plan... and DOM event-like things... might not fit that plan. It just seems like scene.meshUnderPointer, and scene.pointerX and scene.pointerY... contradict sending the source object to an executeCodeAction-targetted function. It seems more wise to send a single (info-)object that has a set .source, .pointerX, .pointerY, and .meshUnderPointer (meshUnderPointer would be the same as the source object, maybe? Sometimes?). *shrug* Sorry for doing a tangent on your thread, subinapptest, but this subject has been visited once before (see the url above), and therefore some information from that previous visit... should be included here, too. Quote Link to comment Share on other sites More sharing options...
Kilombo Posted June 12, 2014 Share Posted June 12, 2014 I have to agree with Wingnut on this. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 12, 2014 Share Posted June 12, 2014 hehe, Interesting discussion! Some personal thoughts:- I want to reduce to to minimum all objects creation during rendering. If I want to add an event object I have to instantiate it each time the trigger is raised. I can do this obviously but it is not a good thing for performance- ExecuteCodeAction is not the only place where you may need meshUnderPointer, PointerX and PointerY- There will be new trigger like OnIntersection which are not related at all with the pointer- If I add meshUnderPointer, PointerX and PointerY, why not adding all *potential* properties you may require? When should I stop? I cannot shape the API for too much specific needs- ActionManager is intended to be use as a state machine (A specific UI will be developed for) Given these points do you still think we can create an event object? To be honest I think it could be great but all the points mentioned above prevent me to do so Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 12, 2014 Share Posted June 12, 2014 OK because simplicity is the foundation of babylonjs, I added an ActionEvent to ExecutecodeAction I did some performances tests and this is OK, events are not generated too quickly Quote Link to comment Share on other sites More sharing options...
Wingnut Posted June 12, 2014 Share Posted June 12, 2014 Thanks for the explanation, DK... I appreciate it. I understand better, now... thanks for helping me learn the issues. Do what you think is right, of course. When should I stop? I cannot shape the API for too much specific needs.Good point. The event object(s) could get out of control easily. Thanks again for telling me/us the issues involved. As another method, maybe don't provide a parameter to the function, and instead... scene.lastTriggerSource? *shrug* Or maybe actionManager.lastTriggerSource? I'm just shooting in the dark, here. Quote Link to comment Share on other sites More sharing options...
HappyEnd Posted June 12, 2014 Share Posted June 12, 2014 If I understand correctly, you could manage to do it manually without changing the core just by using javascript native functions : ddd2.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPickTrigger,test.bind(ddd2)));function test(){ console.log(this); // this = ddd2 here // code}Also possible using a closure (but can lead to memory issue) :ddd2.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPickTrigger,test(ddd2)));function test(ref) { return function() { console.log(ref); // ddd2 // code };} Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 12, 2014 Share Posted June 12, 2014 Finally (because I want a simple API) the event is raised with the function Quote Link to comment Share on other sites More sharing options...
Subin George Posted June 13, 2014 Author Share Posted June 13, 2014 @deltakosh: Thanks a lot for the quick action: I have upgraded to latest beta and is tirggering with object information. its awsome.barsList[barCounter].actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPickTrigger, function (object) { console.log(object); }));I personally feel click event is less sensitive than Hover, becuase click required zoom to the object and need to specific click. Do we have any way improve the click sensitivity?Also one click trigger an event twice. what could be the issue? Quote Link to comment Share on other sites More sharing options...
Wingnut Posted June 13, 2014 Share Posted June 13, 2014 Hi everyone! Are we all being friendly and accomodating? Allow me to try to ruin that. hehe. Deltakosh - Finally (because I want a simple API) the event is raised with the function Deltakosh - what do you mean when you say "finally"? Does that mean that you would like this discussion... to finish? I hope we are not being annoying. We users did not invent the mouse or touch actions. We just need the right tools to properly process those actions. When you built the actionManager, Dk... you knew that executeCodeAction would be the most popular and most powerful, because the other actions (the interpolators) have limited power and use. So, you can 'want' a simple API, and I think I speak for most users when I say we want that, too. BUT... executeCodeAction is a place of full power and versatility, and we/you should probably try to prepare for its heavy usage. It is mouse and touch events that is trying to complicate the API, not this discussion or the user's concerns (as best I can tell). There might be no way to avoid a certain level of complication... when it comes to executeCodeAction. Maybe I have misunderstood, though. I hope I speak for all of us when I say that it is not our intention to be annoying or harmful to simplicity. PS: Welcome HappyEnd and Subin George... good to have you with us on-forum and in this discussion! Quote Link to comment Share on other sites More sharing options...
Kilombo Posted June 13, 2014 Share Posted June 13, 2014 Hi everyone! Are we all being friendly and accomodating? Allow me to try to ruin that. hehe. Deltakosh - what do you mean when you say "finally"? Does that mean that you would like this discussion... to finish? I hope we are not being annoying. We users did not invent the mouse or touch actions. We just need the right tools to properly process those actions. When you built the actionManager, Dk... you knew that executeCodeAction would be the most popular and most powerful, because the other actions (the interpolators) have limited power and use. So, you can 'want' a simple API, and I think I speak for most users when I say we want that, too. BUT... executeCodeAction is a place of full power and versatility, and we/you should probably try to prepare for its heavy usage. It is mouse and touch events that is trying to complicate the API, not this discussion or the user's concerns (as best I can tell). There might be no way to avoid a certain level of complication... when it comes to executeCodeAction. Maybe I have misunderstood, though. I hope I speak for all of us when I say that it is not our intention to be annoying or harmful to simplicity. PS: Welcome HappyEnd and Subin George... good to have you with us on-forum and in this discussion! Djee... mate. I totally agree with you. But..... I think you are beeing a but hard in your speech. After all.... It's open source. The community it's speechless (by this i mean, everyone helps everyone, and the developers listen the users everyday). I feel that the developers do make one hell of one effort do answer and help anyone. We can ask if it is possible to implement stuff. But i don't think that the users are in a position to claim anything. By this i don't want to be hard on you also. Since you are a really good contributor (in my point of view) and one of the most active members of the community (and the funniest also), and you probably should stay has you are.... What the hell, I don't know what i'm talking about anymore. Lol. Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted June 13, 2014 Share Posted June 13, 2014 hehe. You're as goofy as I am, Kilombo! Subin George, don't worry. We haven't forgotten about your questions. I moved my actionManager ramblings over to that other thread, so you can get your answers here, soon. But feel free to join us over in the "Drop down menu mouseover" thread, too. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 13, 2014 Share Posted June 13, 2014 My "finally" means: At the end of the day, I change my mind Sounds like I did not use the right word Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 13, 2014 Share Posted June 13, 2014 @Subin George: Could you create a small repro case using www.babylonjs.com/playground ? Quote Link to comment Share on other sites More sharing options...
Wingnut Posted June 13, 2014 Share Posted June 13, 2014 @DK - understood. That is actually a good use of "finally", just a bit uncommon. In USA English, it tends to mean something is satisfied after a lot of work or time or both. "After much work, I finally found a solution" or "Finally, I arrived at my destination." So, your use is not so wrong... just unusual. That's why I asked... and you clarified... and its time to PARTY ON or something. Quote Link to comment Share on other sites More sharing options...
Subin George Posted June 16, 2014 Author Share Posted June 16, 2014 @Deltakosh: Sorry for the delayed the delayed resposnse, I was out of town. I will create same in playgraound and update you. Mean while I have found the issue of duplicate event triggering. It can be aoided by adding .then(new BABYLON.DoNothingAction()); But for me it seems odd, do we really need this to avoid multple tigger? Thanks Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted June 16, 2014 Share Posted June 16, 2014 Forgive me if I am off base, since have not used this facility yet. I am in the process of evaluating doing something in the graphics area. Have been looking at Babylon in a rather hands on, but different manner that is starting to relate to this topic. I have been programming longer than some of you have been alive. While I understand you wish to make this as easy for non-programmers as possible, I think this may limit some. My hands on tutorial has been to rewrite / re-organize the Blender export script. I did not know python, but it is easy to learn. I turned it into a multi-output script (.babylon, inline .js, & .log). My version of the .babylon I think is complete, and a lot smaller. The .log lists what was done & includes warnings about things that are not supported. The inline .js also allows you to specify a subclass of mesh using a custom property, where you can place higher level code, like maybe a bi_ped subclass of mesh. The script sublasses either mesh or your subclass of mesh for those meshes which have no parent, and instances meshes or your subclass of children, making them a member of the parent class. How it is starting to relate is the base-subclass of mesh if you will, can now remember or hold the state of the "thing", including net result of performing these actions. I feel that while a mesh instance from a .babylon file could be surrounded by an application level class it might be kind of fragile the more AI like stuff that is added to the render loop. I also do not like "my code" to be locked into some data structure I have no control over, but that might just my bias. The inline .js output is way under tested, and not really ready for production, but if please remember as this action manager and other enhancements occur, like instancing, mesh IS subclassable & everybody may not be using a .babylon file. Thanks Jeff 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.