Search Unity

GameObjectRecorder for Body Tracking

Discussion in 'ARKit' started by Blarp, Sep 4, 2019.

  1. Blarp

    Blarp

    Joined:
    May 13, 2014
    Posts:
    193
  2. Blarp

    Blarp

    Joined:
    May 13, 2014
    Posts:
    193
    WIP, not sure if this is the right direction.

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using UnityEditor.Animations;
    4. public class RecordTransformHierarchy : MonoBehaviour
    5. {
    6.     //recorded clip
    7.     public AnimationClip clip;
    8.     //recorder
    9.     private GameObjectRecorder m_Recorder;
    10.     //gameobject that animations will be copied to
    11.     public GameObject dummy;
    12.     //animation controllers for dummy
    13.     public Animator animator;
    14.     public AnimatorOverrideController animatorOverrideController;
    15.  
    16.     void LateUpdate()
    17.     {
    18.         if (clip == null)
    19.             return;
    20.         // Take a snapshot and record all the bindings values for this frame.
    21.         m_Recorder.TakeSnapshot(Time.deltaTime);
    22.     }
    23.  
    24.     public void StartAnimRecord()
    25.     {
    26.         GameObject humanObj = this.gameObject.GetComponent<HumanBodyTracking>().humanObj;
    27.      
    28.         if(humanObj == null)
    29.         {
    30.             return;
    31.         }
    32.      
    33.         // Create recorder and record the script GameObject.
    34.         m_Recorder = new GameObjectRecorder(humanObj);
    35.         // Bind all the Transforms on the GameObject and all its children.
    36.         m_Recorder.BindComponentsOfType<Transform>(humanObj, true);
    37.     }
    38.     public void StopAnimRecord()
    39.     {
    40.         if (clip == null)
    41.             return;
    42.         if (m_Recorder.isRecording)
    43.         {
    44.             // Save the recorded session to the clip.
    45.             m_Recorder.SaveToClip(clip);
    46.         }
    47.         clip = null;
    48.     }
    49.  
    50.     //WIP - Assign completed anim to dummy model
    51.     public void PlayAnimRecord()
    52.     {
    53.         animatorOverrideController = new AnimatorOverrideController(animator.runtimeAnimatorController);
    54.         animator.runtimeAnimatorController = animatorOverrideController;  
    55.     }
    56. }
    57.  
     
    mukultictoc and jeromeWork like this.
  3. mukultictoc

    mukultictoc

    Joined:
    Sep 24, 2016
    Posts:
    9
    Wow.. i had no idea something like this even existed..
    Does the above script actually work ?
     
  4. Blarp

    Blarp

    Joined:
    May 13, 2014
    Posts:
    193
    This is a stress test of the github proj

     
    mukultictoc likes this.
  5. dpizzle

    dpizzle

    Joined:
    Feb 2, 2013
    Posts:
    28
    Instead of rolling your own, maybe use the official Unity Recorder package (available as a preview package in the package manager) to record the animation clips.
     
    Blarp likes this.
  6. Blarp

    Blarp

    Joined:
    May 13, 2014
    Posts:
    193
    You can only use the Recorder in the Unity Editor. It does not work in standalone Unity Players or builds.
     
  7. dpizzle

    dpizzle

    Joined:
    Feb 2, 2013
    Posts:
    28
    Ah, my bad, could've sworn you can use it at runtime.
     
  8. Blarp

    Blarp

    Joined:
    May 13, 2014
    Posts:
    193
  9. HonorableDaniel

    HonorableDaniel

    Joined:
    Feb 28, 2007
    Posts:
    2,830
    Have you had any luck with creating AnimationClips at runtime?
     
  10. Blarp

    Blarp

    Joined:
    May 13, 2014
    Posts:
    193
    I haven't quite played with that part yet.

    Id make an empty clip, and set it as a var in the editor. than overwrite it at runtime
     
  11. HonorableDaniel

    HonorableDaniel

    Joined:
    Feb 28, 2007
    Posts:
    2,830
    Does that work for Humanoid animations?
     
  12. Blarp

    Blarp

    Joined:
    May 13, 2014
    Posts:
    193
  13. Blarp

    Blarp

    Joined:
    May 13, 2014
    Posts:
    193
  14. Blarp

    Blarp

    Joined:
    May 13, 2014
    Posts:
    193