Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export FBX animation #59

Open
alexcroft93 opened this issue Apr 14, 2024 · 8 comments
Open

Export FBX animation #59

alexcroft93 opened this issue Apr 14, 2024 · 8 comments

Comments

@alexcroft93
Copy link

alexcroft93 commented Apr 14, 2024

Hello, your re-implementation of the sims 2 in unity is really impressive.
I'm currently looking for a way to transfer animations from The Sims 2 to Blender.
I've downloaded the OpenTS2 Unity project and loaded everything correctly with @ammaraskar unity simanimationtestscript. I'm able to play the animations and view their keyframes. Now, I tried exporting the mesh, rig, and animation to Blender using a Unity FBX export, but it seems not to work correctly. Maybe for the IK CHAIN. Is there a way to bake the ik chain directly in unity of the simanimationtestscript to the rig bones, so when i import the fbx in blender it reads only the bones keyframes and not also the ikchain (ik bones).

thanks

@ammaraskar
Copy link
Collaborator

Aah it's unfortunate that Unity's FBX export doesn't bake in the inverse kinematics. If there isn't a way to do that with the built-in exporter then you may have to write your own exporter that goes frame-by-frame and dumps the IK-updated position of bones.

@LazyDuchess has an example of an .obj exporter from a past version of OpenTS2 here https://github.com/LazyDuchess/SimUnity2/blob/73a0fd8d08d21cc79397253ab0909f31ac972a07/Assets/Editor/ObjExporter.cs
You may have to write something similar.

@alexcroft93
Copy link
Author

Unfortunately, I don’t know the programming language in C#. Could you help me write the script?

@ammaraskar
Copy link
Collaborator

ammaraskar commented May 9, 2024

Hey @alexcroft93, sorry for the late response but I pushed some code to the branch bake_ik_animations https://github.com/LazyDuchess/OpenTS2/compare/bake_ik_animations

This adds a "baked" version of each animation as it plays which should hopefully survive the export process. Could you give this a try and see if it works?

image

@alexcroft93
Copy link
Author

It works perfectly. Thanks!!!
Now the only problem is that Blender doesn't correctly import the rig structure. Root_trans and root_rot are interpreted as empties and not as parented bones. The armature should be 'auskel' and not 'root_rot'. But I believe this is an issue with importing FBX into Blender. I'll understand how to solve it, maybe by searching for information on Blender forums. As for the simanimationtestscript, I noticed that it only reads animations from the base game. In fact, to try to read animations from funkybusiness, I had to copy the object.package from the path 'The Sims 2 Ultimate Collection\Best of Business\EP3\TSData\Res\3D' containing the animations into the base game folder. I would like to find a way to make the script also read the paths of the various expansions.
Screenshot 2

@ammaraskar
Copy link
Collaborator

ammaraskar commented May 11, 2024

That's awesome! Would you mind saving one of those animations out as a .blend file for me? I'm having some trouble getting it to import properly in blender myself. I'm not super experienced with blender but I'll see if I can try to figure out why the armature shows up on the wrong object.

As for loading animations from the DLCs, after this line:

// Load base game assets.
contentProvider.AddPackages(
Filesystem.GetPackagesInDirectory(Filesystem.GetDataPathForProduct(ProductFlags.BaseGame) +
"/Res/Sims3D"));

go ahead and add the line

            contentProvider.AddPackages(
                Filesystem.GetPackagesInDirectory(Filesystem.GetDataPathForProduct(ProductFlags.Business) +
                                                  "/Res/Sims3D"));

You can find the other ProductFlags. identifiers here: https://github.com/LazyDuchess/OpenTS2/blob/bake_ik_animations/Assets/Scripts/OpenTS2/Content/ProductFlags.cs

@alexcroft93
Copy link
Author

Sure. To export the animation I select only the one baked animation deleting all others animation array elements in the animation section of the inspector under the amFace_cres object.
Then i select all keyframes of the amFace_cres object and export the fbx using the unity fbx exporter (export format binary)
To import the fbx in blender i use the Better FBX importer (https://blendermarket.com/products/better-fbx-importer--exporter) which is not free unfortunately.
This is a blend file of the exercisemachine animation. Thanks!
exercisemachineanim.zip

@ammaraskar
Copy link
Collaborator

I pushed some code that optimizes the keyframes used in the animations to make it take up less space. I also made a separate baked object to just contain the animations at the auskel level without all the extra stuff we use to make the IK work.

Using the https://github.com/KhronosGroup/UnityGLTF extension, I was able to manage to export the sim and animations into a .glb file. This file imports pretty cleanly into blender with the animations separated. As far as the armature not being rooted at auskel, this is how the skeleton in the sims2 geometry is set up, the root bone is actually root_rot.

You can switch between the animations by filtering to root_rot in the blender Action Editor window:

image

@alexcroft93
Copy link
Author

It works!! Thanks to your work, there is finally a way to export animations from The Sims 2 (using unity).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants