[SOLVED] Removing Morph Targets

I’m trying to avoid this error:

E/AndroidRuntime: FATAL EXCEPTION: GLThread 56
    Process: com.mygame.Test, PID: 4271
    java.lang.ArrayIndexOutOfBoundsException: length=16; index=16
        at com.jme3.renderer.opengl.GLRenderer.setVertexAttrib(GLRenderer.java:2990)
        at com.jme3.renderer.opengl.GLRenderer.setVertexAttrib(GLRenderer.java:3046)
        at com.jme3.renderer.opengl.GLRenderer.renderMeshDefault(GLRenderer.java:3258)
        at com.jme3.renderer.opengl.GLRenderer.renderMesh(GLRenderer.java:3296)

I have a glTF that has many shape keys that hold a single value. some of the meshes within the model have up to 20 shape keys. It loads fine on my PC GPU, but not on my android device. I only need to have the model access 3 of the shape keys at a time. I was curious if I was able to remove these other unused shape keys and add them back in later ie:

float[] f = ((Geometry) s).getMorphState();
 for (int i = 0; i < f.length; i ++)
       System.out.println("removing: " + i);
       ((Geometry) s).getMesh().removeMorphTarget(0);

when I remove the shape keys and then continue with the load i get:

Oct 10, 2023 4:37:11 AM com.jme3.anim.SkinningControl controlRender
INFO: Hardware skinning engaged for RIG-Rig (Node)
Oct 10, 2023 4:37:11 AM com.jme3.app.LegacyApplication handleError
SEVERE: Uncaught exception thrown in Thread[jME3 Main,5,main]
java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
	at com.jme3.anim.MorphControl.controlRender(MorphControl.java:120)
	at com.jme3.scene.control.AbstractControl.render(AbstractControl.java:126)
	at com.jme3.scene.Spatial.runControlRender(Spatial.java:763)
	at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:796)
	at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:806)
	at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:806)
	at com.jme3.renderer.RenderManager.renderScene(RenderManager.java:780)
	at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:1205)
	at com.jme3.renderer.RenderManager.render(RenderManager.java:1287)
	at com.jme3.app.SimpleApplication.update(SimpleApplication.java:278)
	at com.jme3.system.lwjgl.LwjglWindow.runLoop(LwjglWindow.java:628)
	at com.jme3.system.lwjgl.LwjglWindow.run(LwjglWindow.java:717)
	at java.base/java.lang.Thread.run(Thread.java:829)

Oct 10, 2023 4:37:11 AM com.jme3.system.JmeSystemDelegate lambda$new$0
WARNING: JmeDialogsFactory implementation not found.
Uncaught exception thrown in Thread[jME3 Main,5,main]
ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0

If I simply:

((Geometry) s).setCullHint(CullHint.Always);

it loads just fine on android, but ideally I want to not have to hide the whole mesh entirely. Is there a way to do this?

Or is there a way to do something similiar to this?

Thanks in advance!

You removed the morph target from the mesh but you haven’t edited the rest of the animation data so it’s still trying to morph that index.

Animation data is tied closely to the mesh… if you remove stuff from the mesh data then you have to go through and tweak the animation data or you will have a bad time.

I don’t know how exactly you need to edit the animation data, but you definitely do need to. One of sgold’s libraries may apply here.

1 Like

I belive you are same person from Discord who asked similar question

So in general if you remove all morphTargets, also remove MorphControl since it need at least one of them. I guess it should help.

That’s the easy way if you want 0 morph targets.

If so then OP should clarify because I understood that he only wants to reduce the number to something that will fit.

Initially thought same, but based on Discord discuss, OP just tried first to remove every target.

I am. with the information you gave. I was able to get it to work and load on my android device now.
So the issue was I wasn’t removing the MorphControl. Once I left only 1 Morph Target it loaded. I should now be able to make this work. Thank you for the help


Yea I didn’t understand I had to update the mesh to remove the MorphControl or not delete all the morph targets. Been reading through the posts on here for days trying to figure this out and it was very simple -_- thanks for the help!

1 Like

Note that you would have similar issues if you tried to remove some vertexes from the mesh. The animation controls will be very unhappy as they target specific parts of the various mesh buffers by index.

ok. I will keep this in mind. So far all seems good, but I’m sure new issues will arise :wink: