Ejemplo n.º 1
0
    private byte[] ProcessSingleClip(AnimationClip clip, Transform[] bones)
    {
        int allFrame = (int)(clip.length * clip.frameRate);

        byte[]         results = new byte[allFrame * sizeof(float3x4) * bones.Length + sizeof(AnimationHead)];
        AnimationHead *headPtr = (AnimationHead *)results.Ptr();

        headPtr->frameRate  = clip.frameRate;
        headPtr->length     = clip.length;
        headPtr->bonesCount = bones.Length;
        Debug.Log("FrameRate: " + clip.frameRate);
        Debug.Log("Length: " + clip.length);
        float3x4 *bonesPtr = (float3x4 *)(headPtr + 1);

        for (int i = 0; i < allFrame; ++i)
        {
            clip.SampleAnimation(targetAnimator.gameObject, i / clip.frameRate);
            for (int j = 0; j < bones.Length; ++j)
            {
                float4x4 mat = bones[j].localToWorldMatrix;
                (*bonesPtr) = float3x4(mat.c0.xyz, mat.c1.xyz, mat.c2.xyz, mat.c3.xyz);
                bonesPtr++;
            }
        }
        return(results);
    }
Ejemplo n.º 2
0
    public static void ExecuteAfterFrame()
    {
        if (!allMatrices.IsCreated)
        {
            return;
        }
        float3x4 *ptr = allMatrices.Ptr();

        for (int i = 0; i < allDrawers.Count; ++i)
        {
            float4x4 mat = allDrawers[i].transform.localToWorldMatrix;
            ptr->c0 = mat.c0.xyz;
            ptr->c1 = mat.c1.xyz;
            ptr->c2 = mat.c2.xyz;
            ptr->c3 = mat.c3.xyz;
            ptr++;
        }
    }