Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

try to use animationclip.SampleAnimation get problem

Discussion in 'Animation' started by lifeFo, Aug 18, 2019.

  1. lifeFo

    lifeFo

    Joined:
    Apr 14, 2017
    Posts:
    15
    I use for loop to sample child transform result sample part of sub gameobject,other transform not change.
    IF i use SampleAnimation in update function,all transfrom get sample properly.
    Code (CSharp):
    1. Dictionary<string, List<Matrix4x4>> m4 = new Dictionary<string, List<Matrix4x4>> (14);
    2.         for (int i = 1; i < boneMatrices.GetLength (0) - 1; i++) {
    3.             float t = (float) (i - 1) / (boneMatrices.GetLength (0) - 3);
    4.             clip.SampleAnimation (renderer.gameObject, t);
    5.             for (int j = 0; j < bones.Length; j++) {
    6.                 var tr = bones[j];
    7.                 List<Matrix4x4> samebone;
    8.                 var cmt = rootbone.worldToLocalMatrix * tr.localToWorldMatrix * bindPoses[j];
    9.                 if (m4.TryGetValue (tr.name, out samebone)) {
    10.                     if (samebone.Contains (cmt)) {
    11.                         samebone.Add (cmt);
    12.                     } else {
    13.                         samebone.Add (cmt);
    14.                     }
    15.                 } else {
    16.                     m4[tr.name] = new List<Matrix4x4> () { cmt };
    17.                 }
    18.                 boneMatrices[i, j] = cmt;
    19.             }
    20.         }
    sample in for loop

    Code (CSharp):
    1. delt1 += Time.deltaTime;
    2.         var clip = AC[0];
    3.         var mtx = sampledBoneMatrices[0];
    4.         int framid = (int) (clip.frameRate * ((delt1 > 1 ? delt1 = 0 : delt1)));
    5.         float t = (float) (framid - 1) / (mtx.GetLength (0) - 3);
    6.         clip.SampleAnimation (target, t);
    7.  
    8.         NativeArray<Matrix4x4> boneTransforms1 = new NativeArray<Matrix4x4> (mtx.GetLength (1), Allocator.Temp);
    9.         for (int i = 0; i < boneTransforms1.Length; i++) {
    10.             var finalmatrix = rootBone.worldToLocalMatrix * bonestran[i].localToWorldMatrix * BindPoses[i];
    11.             if (!bonesmtx.Contains (finalmatrix)) {
    12.                 Debug.LogError ($"not find {bonestran[i].name}  bones corresponding mtx[framid,i]\n{mtx[framid,i]} fram={framid}");
    13.                 //  boneTransforms1[i] = finalmatrix;
    14.  
    15.             }
    16.             boneTransforms1[i] = mtx[framid, i];
    17.  
    18.         }
    sampled in update function.
    Anyone konw what's happened?
     
  2. lifeFo

    lifeFo

    Joined:
    Apr 14, 2017
    Posts:
    15
    call for unity team