Jump to content

SPS and skeleton animation


TomaszFurca
 Share

Recommended Posts

Hi, I try to run animation of skeleton on my SPS, but i don't work. 

 

Simple code:

 

                    let SPS = new BABYLON.SolidParticleSystem("SPS", scene);
                    SPS.addShape(meshP, 50);
                    let mesh = SPS.buildMesh();
                    mesh.material = meshP.material;
                    mesh.skeleton = meshP.skeleton.clone("clonedSkeleton2");
                    SPS.afterUpdateParticles = function(start, stop, update) {
                        mesh.skeleton.beginAnimation('Skill01', true);

                    }
                    SPS.initParticles();
                    SPS.setParticles();

 

Thanks for help

Tom

Link to comment
Share on other sites

I have limited knowledge of SPS(unfortunately), but could it be, that that piece of code gets called every frame? If that's the case, you won't see any difference as the animation gets restarted every ~16ms.

Try using something like a boolean.

isSPSPlaying = false;
SPS.afterUpdateParticles = function(start, stop, update) {
    if(!isSPSPlaying){
       mesh.skeleton.beginAnimation('Skill01', true);
       isSPSPlaying = true;
  }
}

I'm not sure of how you want your logic to work. But I do believe this could be the issue.

Link to comment
Share on other sites

The SPS is a big updatable mesh whose the vertex positions are all updated each call to setParticles(). That means its whole geometry is supposed to change each frame with no other global coherence. Therefore it doesn't support the skeleton by default.

Link to comment
Share on other sites

Actually, the SPS is a big mesh... nothing would prevent technically to use a skeleton. But, as all this mesh vertices are updated one by one by setParticles(), there's no guarantee that the skeleton coherence and organization is kept along (for sure, it isn't). Maybe managing by the hand each parts would work, no idea (except that this would be really complex to implement).

Link to comment
Share on other sites

I create my field of grain using instances, but perfomance would be better using SPS, but I cannot do that using SPS. 

                    let grain = self.game.factories['nature_grain'].createInstance('Grain', true);
                    grain.scaling = new BABYLON.Vector3(1.3,1.3,1.3);
                    grain.position = new BABYLON.Vector3(22.32,0,-103.46);
                    grain.skeleton.beginAnimation('ArmatureAction', true);

                    for (let i = 0; i < 1000; i++) {
                        let offsetX = (Math.random() - 0.5) * 60;
                        let offsetZ = (Math.random() - 0.5) * 10;
                        let instance = grain.createInstance("instance" + i);
                        instance.parent = grain;
                        instance.skeleton = grain.skeleton;
                        instance.position.x = offsetX;
                        instance.position.z = offsetZ;
                    }

Effect like this: https://streamable.com/wxygk

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