Search Unity

Question How to extract body data??

Discussion in 'Unity MARS' started by moderebel, Feb 22, 2022.

  1. moderebel

    moderebel

    Joined:
    Feb 20, 2018
    Posts:
    4
    I need help. I've been wrestling with this for several days. I really want to love MARS - the thinking that's gone into it is amazing and it seems like a powerful tool. However, getting it to do anything beyond the basics using scripting is proving difficult using the current documentation.

    Note: I paid the $600 for the product, and still can't get off of the ground.

    Here's my question: I want to extract the HumanPose data on every MARS session update. My goal is to apply that data to a secondary human avatar. The workflow is: pull HumanPose from the MARS detected human, then apply that data to an NPC human avatar.

    I've implemented the Action interface, then attached the script to the body Proxy, as described in the documentation. However, I can't seem to read the data from the queryResult. I've tried the TryGetTrait route, but its data always reports null (when running from the simulator). I've also tried queryResult.ResolveValue, but that throws an exception:

    NullReferenceException: Object reference not set to an instance of an object
    Unity.MARS.Data.IUsesMARSTrackableDataGenericMethods.GetIdValue[T] (Unity.MARS.Data.IUsesMARSTrackableData`1[T] obj, System.Int32 dataId) (at Library/PackageCache/com.unity.mars@1.4.1/Interfaces/Subscribers/IUsesMARSTrackableData.cs:50)
    Unity.MARS.Query.QueryResult.ResolveValue[T] (Unity.MARS.Data.IUsesMARSTrackableData`1[T] dataUser) (at Library/PackageCache/com.unity.mars@1.4.1/Runtime/Scripts/Backend/Queries/QueryResult.cs:57)

    I've attached an example script.

    PLEASE HELP!!!!
     

    Attached Files:

  2. jmunozarUTech

    jmunozarUTech

    Unity Technologies

    Joined:
    Jun 1, 2020
    Posts:
    297
    Hey there!,

    There are several things that you need to check before resolving a query result. you are trying to get a MarsBody directly and that its not how it works.

    ARKit has a complete different bone structure of their skeleton which MARS has to translate so doing a 1:1 translation to Unity bodies will not work.

    If you check the code, the
    BoneLengths
    property is optional so its not necessarily assigned/initialized.

    When you want to update a body pose you should:
    1. resolve the pose from the query result.
    2. Assign the resolved
    bodyPose
    from the
    IMarsBody
    to a
    HumanPose

    3. Reset the asigned
    HumanPose
    transform (position Vector3.zero and rotation Quat.identity)
    4. Set the
    HumanPose
    ` through a
    HumanPoseHandler
    that you assign your avatar to.
    5. Try to get the trait for a body from the mars db with
    queryResult.TryGetTrait(TraitNames.Pose /*<-- This is the string "body" you have in your code but instead is a pose*/, out Pose newPose))


    And if succeded assign the
    newPose
    to this transform (
    transform.localPosition = pose.position; transform.localRotation = pose.rotation;
    (which would be the proxy this action is attached to))

    and that should animate your avatar.

    In case you haven't already, take a look into
    MatchBodyPoseAction
    where the
    UpdateBodyPose
    method is described; it basically follows what I just mentioned above. That should get you going.

    Hope it helps! :)
     
  3. moderebel

    moderebel

    Joined:
    Feb 20, 2018
    Posts:
    4
    Fantastic! Thanks so much for the reply. This helps a lot!
     
    jmunozarUTech likes this.