Unity: Get joint rotations of each frame from FBX file - unity3d

I have some animations stored in FBX files that I need to analyse. I need to know the localRotations and localPositions of each joint for each frame.
My current approach is to use Unity and assign the FBX file to a state in an animation controller and play it. Then I assign a script to the root joint and in each Update() call I recursively read the localRotation of each joint and save them to a list.
My questions are now:
How can I guarantee that I get each frame from the FBX exactly once? Should i use FixedUpdate instead of Update? I want this script to be not influenced by any load caused by other programs that run in parallel.
How can I get the current frame number that is played? How can I detect if the animation has ended or is just being looped?
I need this only to get the joint rotations from the animation. It is not relevant that the animation is actually played on the screen. If there is an easier way, I would also be interested. I want to extract this information from around 200 FBX files that have a length of 2-10 seconds.
I only want to use Unity to process the files, everything else will be done in Python as I have almost no Unity experience.

Related

How to record animation in runtime

I have some animations for upper body and lower body. I use avatar mask and set weight for them so them can override each other. I have 1 button for each animation. You can see it in this video.
https://youtu.be/fYdoFFJCuxk
All I want is how can I record the animation that I play in runtime and export it to a file(anim, fbx, ...).
Thanks in advance!
Your question is not trivial, meaning that maybe you need to try something out to narrow down the specific problem you might encounter in your attempt.
I am not 100% about how would I do it but I think there are 2 options.
1.- Runtime animation info serialize + save and load:
You would need to have a script that keeps track of the animation's state machine to save that info along the timeline. This script should save the info to a file (.xml, . json or text) so that it can be loaded and played. This info should hold basically the time and the state of the animation changes along the timeline since the animation play.
2.- Transform record:
You can have component for all the gameobjects you want to track that serialize and store the transform of your gameObject along a timeline. This is basically a replay system. If you play the animation, all the transforms info is saved to file (positions and rotations) and then when loaded, this positions and rotations are applied to the respective gameObjects.
You can give a look to the Easy replay system asset in the asset store. I bought it, it really simple and works really good. I tried it also with animations and it works.
Does not have the serialization and save and load part, but you can work that out very probably.
From scratch I think the best option is 1. With some asset, that might be more expensive if includes the serialization and save/load part, maybe you can get it done faster with option 2.

I can't figure out Unity / Blender / makehuman root motion

I have tried every single variation and permutation that I can think of.
I start at make human while I'm prototyping because it's fast. I then take it to Blender where I apply a bvh file.
I adjust the graph editor because the bvh files never get it quite right. Then I import into Unity.
I think the root node would be [character/master/root]. I set the root position x/y baked. I have set the rig's root to the above.
My character either jumps back at loop, which I know means wrong root node, but when he doesn't do that there is no forward movement whatsoever.
Unless I click is kinematic which removes the interaction with physics.
When iskinematic is clicked it moves like I want it to, but you know that isn't good for physics. What can I try next?
i found a solution i had not seen yet and i went back to make human and imported a new unity rig from https://forum.unity.com/threads/makehuman-and-unity.617311/
and exported to blender using the unity export...
then i exported to unity and made a humanoid animation it seems to be working better

Unity - How to change player spritesheet while runtime?

I'm currently working on a 2D pixel Jump'n'Run. I want the player to be able to "buy" new skins for the player-character. I have multiple sprite-sheets. They all have the same structure. I'm using sprite animations.
How can I change the sprite-sheet at runtime? I found the following solution, but it's very resource intense: https://youtu.be/HM17mAmLd7k?t=1818
Sincerly,
Julian
The reason it's so resource intensive in the video is because the all the sprites are loaded in each LateUpdate(), which is once per frame. The script looks like it's grabbing all the sprites in the sprite-sheet and loading them every frame so that if the spriteSheetName ever changes, it will update the renderer on the next frame.
I don't believe that's necessary and in the video he mentions that it's just being used as an example. What I'd do is move it out of the LateUpdate() method and into its own method that can be called only whenever the user wants to change the sprite-sheet. So instead of mindlessly loading the sprites from the sprite-sheet each frame, you'll only load them whenever the user selects it.
That should accomplish drastically cutting down the intensity of this script because you're not loading all the sprites in a sprite-sheet and looping through each of their renderers on every single frame.

How do I get the camera to follow a Gameobject in unity?

I want to get a camera to follow a gameObject. So I am using a spring formula at the moment along a 2D plan within a 3D scene.
I have used this formula within the Update function, with the inbuilt lookat function.
It works as it should, however it really choppy (it is like a really low frame rate but the rest of it doesn't seem to be effected). Does anyone know what could be wrong?
I'm using Unity 5 and can upload the project somewhere if needed.

Positioning 3d objects for AR in Unity3d

I'm experimenting with an AR experience in Unity3D. I'd like to place models in my Unity scene and have them show up on top of real world objects using tango. I'm using tango's augmentedReality scene as a starting point.
Say there is a table in a room and I want a 3d cube to sit on top of it when it is in tangos view. Do I need to be using an .adf file to solve this problem or is there something else I should be looking into.
Is there some way to test an .adf file locally in my unity scene? This would be ideal to establish and debug the correct positions to place models in my scene.
Just trying to sort everything out.
If you want keep your virtual object's position persistent between different runs of the application, you will need a ADF file to relocalize. Unfortunately, there's no in-editor debug functions for ADF at the moment, so you will need to create a program to place the objects.
You could take a look of the Experiments/PersistentState example for reference. This example is not using AR, however, it's saving objects position with respect to your ADF's origin and keeping them persistently.