Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

GameObjectRecorder for Body Tracking

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

  1. Blarp

    Blarp

    Joined:
    May 13, 2014
    Posts:
    269
    zyonneo likes this.
  2. Blarp

    Blarp

    Joined:
    May 13, 2014
    Posts:
    269
    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:
    15
    Wow.. i had no idea something like this even existed..
    Does the above script actually work ?
     
  4. Blarp

    Blarp

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

     
    mukultictoc likes this.
  5. dpizzle

    dpizzle

    Joined:
    Feb 2, 2013
    Posts:
    31
    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.
     
    ina and Blarp like this.
  6. Blarp

    Blarp

    Joined:
    May 13, 2014
    Posts:
    269
    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:
    31
    Ah, my bad, could've sworn you can use it at runtime.
     
  8. Blarp

    Blarp

    Joined:
    May 13, 2014
    Posts:
    269
  9. User340

    User340

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

    Blarp

    Joined:
    May 13, 2014
    Posts:
    269
    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. User340

    User340

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

    Blarp

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

    Blarp

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

    Blarp

    Joined:
    May 13, 2014
    Posts:
    269
  15. Blarp

    Blarp

    Joined:
    May 13, 2014
    Posts:
    269
  16. ina

    ina

    Joined:
    Nov 15, 2010
    Posts:
    1,080
    curious on the latest here