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 · 14 comments
Open

Export FBX animation #59

alexcroft93 opened this issue Apr 14, 2024 · 14 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).

@alexcroft93
Copy link
Author

alexcroft93 commented Oct 5, 2024

Hi @ammaraskar , I picked up the project again after quite some time. I was trying to load the "a2o-tent-getIn_anim" animation from bonvoyage in the simanimationtestscript. I used the version of OpenTS2 (https://github.com/LazyDuchess/OpenTS2/tree/d0ca1fe69f17387cc7900ab49fe5cda10b3ce816) and modified the file "OpenTS2/Assets/Scripts/OpenTS2/Engine/Tests/SimAnimationTest.cs" by adding this code:

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

However, the script is unable to correctly retrieve the animation, it simply doesn't find it.
I can't figure out where I'm going wrong. Could you help me? Thanks

@ammaraskar
Copy link
Collaborator

Heyo, try doing:

contentProvider.AddPackages(Filesystem.GetPackagesInDirectory("C:/Path/To/Bon/Voyage/Res/Sims3D"));

I think the product flags have to be configured correctly in config.json which is why it might not be working.

@alexcroft93
Copy link
Author

Thanks it works now

@alexcroft93
Copy link
Author

Hi Anmar, can I ask you what is the process to load objects with animations instead of sims? thanks

@ammaraskar
Copy link
Collaborator

ammaraskar commented Oct 20, 2024

You can try using the ScenegraphGMDCTest scene for that.

You'll need to change this line:

var resourceName = "chairReclinerPuffy_cres";

to be the object you want to load

and then this line:

var recline = ContentProvider.Get().GetAsset<ScenegraphAnimationAsset>(
new ResourceKey("o2a-chairRecliner-recline_anim", GroupIDs.Scenegraph, TypeIDs.SCENEGRAPH_ANIM));

to be the animation you want.

I think (most) objects don't use inverse kinematics, except things like the cow plant so that should work. I think I exported the recling chair asset to view on the web here a while ago.

@alexcroft93
Copy link
Author

alexcroft93 commented Oct 20, 2024

For the o2a-vehicleOWN-superSportsCar-getIn_anim of the vehiclesupersportscarnew_cres it doesn't load the l_door_rot bone animations. Maybe something missing in the script?

EDIT: I also tried loading the "o-vehicleOWN-SuperSportsCar-driveway-DriveThruFromPark_anim" animation for the "vehiclesupersportscarnew_cres" object, but the rotation animation of the car doesn't load. I don’t understand in which part of the scripts the bone animations are being referenced.

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