[Solved] Changing mesh cause animation to stop

Hi again

In following of solution to my previous problem :

now I have

Mesh lodMeshes[]=new Mesh[3];
geometry.setMesh(lodMeshes[xx]);

when at the beginning i .setMesh(lodMeshes[xx]); to one of meshes in lodMeshes then start animation for the first time it plays ok. then at runtime while model in playing animation, again I call .setMesh(lodMeshes[xx]); with different mesh but animation stops playing.
So after changing mesh i tried to clear all anim channels and play animation again, but it does not play.
here is what i am doing in my CustomeLODControl:

 @Override
    protected void controlRender(RenderManager rm, ViewPort vp) {
        Camera cam=vp.getCamera();
        int distance=(int) cam.getLocation().distance(spatial.getWorldTranslation());
        if(currentLevel !=0 && distance <5)
        {
            ((Geometry) spatial).setMesh(lodMeshes.get(0));
            currentLevel=0;
            System.out.println("changed to LOD level 0");
            animControl.clearChannels();
            animControl.createChannel().setAnim("walk");
            
            
        }
        else if(currentLevel !=1 && distance >=5 && distance<15)
        {
            ((Geometry) spatial).setMesh(lodMeshes.get(1));
            currentLevel=1;
            System.out.println("changed to LOD level 1");
            animControl.clearChannels();
            animControl.createChannel().setAnim("walk");
            
            
        }
        else if(currentLevel !=2 && distance >=15)
        {
            ((Geometry) spatial).setMesh(lodMeshes.get(2));
            currentLevel=2;
            System.out.println("changed to LOD level 2");
            animControl.clearChannels();
            animControl.createChannel().setAnim("walk");
  
        }
        
        
    }

what am i doing wrong ?

Any outputs; logs etc.
Also:
At the beginning you say
Mesh lodMeshes[]=new Mesh[3];
geometry.setMesh(lodMeshes[xx]);

inn the code you do
lodMeshes.get(0)

Yes, In my control I am using ArrayList<Mesh> lodMeshes; instead.
Sorry about it.

this was the leftover from my previous post. so in my explanation i used

    Mesh lodMeshes[]=new Mesh[3];
    geometry.setMesh(lodMeshes[xx]);

but in control i updated it to ArrayList.

nothing. just my simple outputs when going close/far from model

Found LODs on Models/Models/Characters/Doha/Doha.xbuf
Aug 29, 2016 12:25:30 AM com.jme3.animation.SkeletonControl controlRender
changed to LOD level 2
INFO: Hardware skinning engaged for Armature (Node)
changed to LOD level 1
changed to LOD level 0
changed to LOD level 1
changed to LOD level 2
changed to LOD level 1
changed to LOD level 0
changed to LOD level 1
changed to LOD level 0
BUILD SUCCESSFUL (total time: 33 seconds)

Maybe printing animControl or the chanells and see if there is something strange.

HeHe

Wherever, Whenever you have problem with your code. The solution is just adding this line to first of your code : :wink:skeletonControl.setHardwareSkinningPreferred(false);

Hardware Skinning has issues with material and mesh changes.

Though keep in mind some things need hardware skinning enabled like Android.

1 Like

I guess the mesh as not been “prepared” for animation and lacks the proper buffers.
HW skinning uses 2 special buffers, but even software skinning needs the BindPosition buffer to be set properly.
I think we should investigate further the original issue with generating lod from an xbuf pipeline model.

1 Like

I could solve the problem without using SoftwareSkinning :grinning:
just needed to call mesh.prepareForAnim(false); after updating mesh on geometry.

Thanks from all you guys. :wink: