I looked into your program a bit and I’ve got a little information that might be helpful.
// My character (one of the affected backwards models)
{
"camera":{
"position":{"x":-2.12929,"y":106.754,"z":20.9495},
"direction":{"x":-0.40558,"y":0.40558,"z":-0.819152}
},
"aabb":{
"min":{"x":-1.8829,"y":102.001,"z":24.481},
"max":{"x":1.8829,"y":107.494,"z":26.4291}
},
"mtl":"b6da3e06d62564d3fe10898a9f8af92d",
"obj":"2ef92602e1b9661a9b909bde08d9cbf2",
"textures":["dea5644c436252a8055a17a0eec2af29"]
}
// Your example model
{
"camera":{
"position":{"x":2.49432,"y":7.56931,"z":4.63778},
"direction":{"x":0.40558,"y":0.40558,"z":0.819152}
},
"aabb":{
"min":{"x":-2.0,"y":2.0,"z":-1.13807},
"max":{"x":2.0,"y":8.33877,"z":0.338075}
},
"mtl":"03c825e6fc0f2fa07b2936e3bb4df359",
"obj":"d58fbcd88debdfb683676a442c682651",
"textures":["edccc70298037ead5e476ff0fce8d589"]
}
You’ll notice these two are opposite:
"direction":{"x":0.40558,"y":0.40558,"z":0.819152} //yours
"direction":{"x":-0.40558,"y":0.40558,"z":-0.819152} //mine
Evaluating the direction parameter of the camera will tell you immediately whether or not you’ll need to reverse things. This should clean up the shouldFlipSkeleton function. In general, it’s a good idea to know both the position and the forward vector of objects for alignment purposes. With that being the case, it’d be better if your program were able to handle this even if we do update the web side of things.
Now, as for actually correcting this. I can see now why you can’t just rename the bones, I didn’t realize at first that you already provided screenshots of that.
The issue you were having with the mirroring code was that you were iterating over the faces, and then the verts for each face. The problem with that is that faces share verts. You were going over the same verts multiple times and that’s what was causing your model to get all scrambled as some verts were properly swapped while others were put back into their original position with multiple swaps.
I’ve taken the liberty to fork your repo on github and I’ve opened a PR for a patch that’ll correct your complier.
I’ve also updated your .gitignore to something more robust. I did not however update your shouldFlipSkeleton function, you’ll have to take care of that one yourself.
Let me know if you’ve got questions or there’s anything else i can help you with.