Rotate vertices and bones transforms while reading mesh data

Hi all, I’m working on a rework of a game which uses SMD file format. We so far are able to import everything without any problem, meshes, bones, bone weights and animation clips and everything else work fine.

However when I load the mesh its forward is poiting down. I’ve been using this script to change the vertices in a way the mesh points forward after loaded, the problem now is the animations get completely borked.

private static Vector3 FixRotation(Vector3 v) {
        var center = Vector3.zero;
        var newRotation = new UnityEngine.Quaternion {
            eulerAngles = new Vector3(-90, 90, 90)
        };

        return newRotation * (v - center) + center;
}

I have tried applying that same change to all the mesh bones and also rotation the animation clip quaternions but the animation after that gets even more creepier.

I know I could just rotate the parent GameObject by -90 on the X and it would be fixed but I’m trying to fix this at the lowest level possible. What would be the correct approach to make the mesh look forward and have its animations working properly?

The fix at the lowest level possible would be to export the mesh/animations in such a way that it’s oriented correctly. Basically every 3D modeling software has settings for that, since different engines often use different coordinate systems.

Forgot to mention other than that. The lowest possible level within the editor boundaries xD

I know you said within the editor boundaries but what about importing the mesh into Blender and exporting it in the correct orientation?

Otherwise you would have to apply the correct rotation to every single keyframe of your animations. The AnimationUtility class contains functions to edit keyframe data in animation clips, but I’ve never used that API before so sadly I can’t really help you with that.

Do you mean put it into a parent object and rotate said object(child) by 90?

If so, that’s what I would do, as I normally have the main parent as an empty object with player script and handle parent/childs appropriately. If the animations still work, then I wouldn’t mess with them, just sounds like the object in question needs rotated.

This would be the only other way, as far as I know, which sounds like “headache city” to me. :face_with_spiral_eyes:

But for sure, trying to manipulate forwards or root positions is a ton of work. Not to mention unnecessary large amounts of work. It’s much easier to let background tasks, and local positions handle all that leg-work. :slight_smile:

Oh yea, I actually went the blender way with a simple-ish script to import the model, change the world up and export… Took a couple of hours but it did the job brilliantly