It looks like the first time CPU skinning is used the vertex positions and normals are cached, then each time you set computeBonesUsingShaders to true it resets them from the cache, overwriting the changes that you made to them manually.
I think one way to fix it is to manually set the vertex positions and normals again after you set computeBonesUsingShaders to true, like on lines 55-56 below.
The thing that is odd is that if you toggle computeBonesUsingShaders = true/false again after your PG line, the mesh collapses again
Whereas if you do the same toggle during the very start of the code, the mesh doesn’t seem to be affected
Why is this though? Maybe it’s due to mesh.skeleton = null
Yes at the start of the code you haven’t removed the skeleton and set the vertices with the skeleton applied yet, so toggling CPU mode is fine at that point. But then any time later when you set computeBonesUsingShaders to true to stop using CPU skinning, then the vertex positions and normals get reset from the values that were cached before you set the vertices, undoing your changes to them. So then they need to be set again.
Maybe you could set the vertex positions and normals first thing, before you start using CPU skinning the 1st time, so that the cached values will be those that you want and that’s what will be reset to each time you stop using CPU skinning. But maybe in the morning others will have better ways (maybe that cache can be reset manually for instance).
So that means I just set it the first time, and I don’t have to worry about side effects of computeBoneUsingShaders etc? That’ll be awesome if that’s the case!
Do you know what are the other possible side effects of doing it this way? Bearing in mind using this for gltf exports etc
Well it seems you only want those particular vertex values when the skeleton is null so I don’t think my last approach/idea is really a full solution, depending on the needs. I think resetting the cache after you change the values manually would maybe be a good way to go, but IDK how to do that with the public API… Let’s see what solutions others will have thou.
Just for example thou, here’s a test where I invalidate the cache by just adding line 46 to your original PG, right after you set the new vertex data. So maybe there’s a public, cleaner way to do below.
Hmm, I think the new issue there is that since you brought the skeleton back you need the original vertex positions and normals back too. Here I set them back to their original values and wiped the cash again after setting the skeleton back and seems to be working again… LOL it is getting harry thou.
I think in the Mesh class’s computeBonesUsingShaders setter function, when it’s set to true the cache should be reset too. That way after turning CPU skinning on and then off again, you could afterwards change the vertex positions and normals, and then turn it on and off again and it would reset to your new values. Otherwise they’ll be overwritten without resetting the cache so that the new values can be cached and reset to…
EDIT: oops I meant when setting to true to reset the cache…