legallon Posted April 9, 2018 Share Posted April 9, 2018 Hi everyone, I'm just discovering BabylonJS and this is my first post ever on a forum so please be patient with me So, I'm working on a small project which consists at the moment in creating meshes via a funtion addMesh(), and I wanted to add a "selection animation" to all my meshes, basically by changing their color to an emissive white one. However, this seems not to be working, and I saw on other topics that I needed to create an actionManager for every mesh of my scene. Is there any way to make my code bellow work and have an actionManager associated to all meshes created by my function addMesh()? Here are the 2 main functions : var makeOverOut = function (mesh) { mesh.actionManager.registerAction(new BABYLON.SetValueAction (BABYLON.ActionManager.OnPointerOutTrigger, mesh.material, "emissiveColor", mesh.material.emissiveColor)); mesh.actionManager.registerAction(new BABYLON.SetValueAction (BABYLON.ActionManager.OnPointerOverTrigger, mesh.material, "emissiveColor", BABYLON.Color3.White())); mesh.actionManager.registerAction(new BABYLON.InterpolateValueAction (BABYLON.ActionManager.OnPointerOutTrigger, mesh, "scaling", new BABYLON.Vector3(1, 1, 1), 150)); mesh.actionManager.registerAction(new BABYLON.InterpolateValueAction (BABYLON.ActionManager.OnPointerOverTrigger, mesh, "scaling", new BABYLON.Vector3(1.1, 1.1, 1.1), 150)); } function addMesh() { var box = BABYLON.Mesh.CreateBox('box', 100, scene); box.position = new BABYLON.Vector3( Math.random() * 480, 50, Math.random() * 480, ); makeOverOut(box); } Thank you for you time, any suggestion would be appreciated ! ps : Sorry for my English . Quote Link to comment Share on other sites More sharing options...
Guest Posted April 9, 2018 Share Posted April 9, 2018 Hello and welcome! No problem with your english! Mine is far worse I created a playground for you: https://www.babylonjs-playground.com/#XR0Q0H the big difference is at line #31 (you need to instanciate the actionManager :)) legallon 1 Quote Link to comment Share on other sites More sharing options...
legallon Posted April 10, 2018 Author Share Posted April 10, 2018 16 hours ago, legallon said: Oh ok I see what you mean. I corrected that and it's working perfectly, maybe I should've seen that alone ! Thanks a lot for your time ps : your framework rocks ! GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
legallon Posted April 11, 2018 Author Share Posted April 11, 2018 @Deltakosh Hi again, I've done few other things on my project, but now I come back to a similar problem : I import a .babylon object, let's say the "skull.babylon" in a createfunction which allows me to create skulls, and I want to apply the actions that we talked about just above. Yet only the scaling modification works, the white emissive color doesn't,while it works for standard Babylon Meshes as a cube or a sphere. Do we need to use a different action or thing like this when it comes to imported meshes or am I just doing a common stupid mistake ? Here's my code : var mesh; BABYLON.SceneLoader.ImportMesh("", "/usine3d/FromScratch/objets/", "skull.babylon", scene, function (newMeshes) { mesh = newMeshes[0]; scene.registerBeforeRender(objProperty); }); function objProperty(){ var material = new BABYLON.StandardMaterial("material01", scene); mesh.material = material; mesh.actionManager = new BABYLON.ActionManager(scene); mesh.actionManager.registerAction(new BABYLON.InterpolateValueAction (BABYLON.ActionManager.OnPointerOutTrigger, mesh, "emissiveColor", new BABYLON.Color3(0, 0, 0), 150)); mesh.actionManager.registerAction(new BABYLON.InterpolateValueAction (BABYLON.ActionManager.OnPointerOverTrigger, mesh, "emissiveColor", new BABYLON.Color3.White(), 150)); mesh.actionManager.registerAction(new BABYLON.InterpolateValueAction (BABYLON.ActionManager.OnPointerOutTrigger, mesh, "scaling", new BABYLON.Vector3(1, 1, 1), 150)); mesh.actionManager.registerAction(new BABYLON.InterpolateValueAction (BABYLON.ActionManager.OnPointerOverTrigger, mesh, "scaling", new BABYLON.Vector3(1.1, 1.1, 1.1), 150)); } Thanks for your time, any suggestion would be massively appreciated ! edit : my code doesn't work since I modified and tried different things for the emissiveColor, sorry for that Quote Link to comment Share on other sites More sharing options...
Guest Posted April 11, 2018 Share Posted April 11, 2018 So you're good? Quote Link to comment Share on other sites More sharing options...
legallon Posted April 12, 2018 Author Share Posted April 12, 2018 No I'm not, sorry for my edit it was misunderstandable ! I definitely need an advice for this Quote Link to comment Share on other sites More sharing options...
Guest Posted April 12, 2018 Share Posted April 12, 2018 Ok you should not call objProperty pre frame: scene.registerBeforeRender(objProperty); }); will call objPropery 60 times per sec Quote Link to comment Share on other sites More sharing options...
legallon Posted April 12, 2018 Author Share Posted April 12, 2018 I quite of managed to solve my problem, if you look at my objProperty call in the registerBeforeRender, I call objProperty without "()" . But when I noticed that mistake ( is it a mistake ? because this didn't raise any error) and changed my call to objProperty() all worked fine. The fact that no error was raised didn't help me to solve this but apparently it was juste a syntax error. 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.