Jump to content

Add a actionManager.registerAction to instances of an object


legallon
 Share

Recommended Posts

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 .

Link to comment
Share on other sites

@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

Link to comment
Share on other sites

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.

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