Beispiel #1
0
    public CraHandle PlayerNew()
    {
        if (PlayerCounter + 1 >= (PlayerData.GetCapacity() * 4))
        {
            Debug.LogError($"Limit of {CraSettings.MAX_PLAYERS} Animation Players ({PlayerData.GetCapacity()} Player Data) reached!");
            return(new CraHandle(-1));
        }

        int dataIdx = PlayerCounter / 4;
        int subIdex = PlayerCounter % 4;

        if (dataIdx >= PlayerData.GetNumAllocated())
        {
            int newIdx = PlayerData.Alloc();
            Debug.Assert(newIdx == dataIdx);
        }

        CraPlayerData data = PlayerData.Get(dataIdx);

        data.ClipIndex[subIdex]     = -1;
        data.PlaybackSpeed[subIdex] = 1f;
        data.Transition[subIdex]    = 1f;
        PlayerData.Set(dataIdx, in data);

        Debug.Assert(PlayerAssignedBones.Count == PlayerCounter);

        PlayerAssignedBones.Add(new List <int>());
        return(new CraHandle(PlayerCounter++));
    }
Beispiel #2
0
        public void Execute(int index, TransformAccess transform)
        {
            int playerIdx = BoneData[index].PlayerIndex;
            int boneIndex = BoneData[index].ClipBoneIndex;

            int playerMemIdx = playerIdx / 4;
            int playerSubIdx = playerIdx % 4;

            CraPlayerData player = PlayerData[playerMemIdx];

            if (!player.IsPlaying[playerSubIdx])
            {
                return;
            }

            int clipIdx         = player.ClipIndex[playerSubIdx];
            int clipFrameCount  = ClipData[clipIdx].FrameCount;
            int clipFrameOffset = ClipData[clipIdx].FrameOffset;
            int localFrameIndex = player.FrameIndex[playerSubIdx];

            float transition = player.Transition[playerSubIdx];
            int   frameIndex = clipFrameOffset + (boneIndex * clipFrameCount) + localFrameIndex;

            CraTransform frameTransform = BakedClipTransforms[frameIndex];

            transform.localPosition = math.lerp(
                transform.localPosition,
                frameTransform.Position,
                transition
                );

            transform.localRotation = math.slerp(
                transform.localRotation,
                frameTransform.Rotation,
                transition
                );
        }
Beispiel #3
0
        public void Execute(int index)
        {
            CraPlayerData player = PlayerData[index];

            //player.Playback += DeltaTime * player.PlaybackSpeed;
            //bool4 end = player.Playback >= player.Duration;

            player.Transition = math.clamp(player.Transition + DeltaTime / TransitionSpeed, float4.zero, new float4(1f, 1f, 1f, 1f));

            // TODO: This is BAAAAAAAAAAD
            for (int i = 0; i < 4; ++i)
            {
                if (!player.IsPlaying[i])
                {
                    continue;
                }

                CraClipData clip = ClipData[player.ClipIndex[i]];
                player.Playback[i] += DeltaTime * player.PlaybackSpeed[i];



                if (player.PlaybackSpeed[i] > 0f)
                {
                    if (player.Playback[i] >= player.Duration[i])
                    {
                        if (!player.Looping[i])
                        {
                            player.Playback[i]  = player.Duration[i] - 0.001f;
                            player.IsPlaying[i] = false;
                            player.Finished[i]  = true;
                        }
                        else
                        {
                            player.Playback[i]   = 0;
                            player.FrameIndex[i] = 0;
                            player.Finished[i]   = false;
                        }
                    }
                    else
                    {
                        player.FrameIndex[i] = (int)math.floor(clip.FPS * player.Playback[i]);
                    }
                }
                else
                {
                    if (player.Playback[i] <= 0f)
                    {
                        if (!player.Looping[i])
                        {
                            player.Playback[i]  = 0.001f;
                            player.IsPlaying[i] = false;
                            player.Finished[i]  = true;
                        }
                        else
                        {
                            player.Playback[i]   = player.Duration[i];
                            player.FrameIndex[i] = (int)math.floor(clip.FPS * player.Duration[i]);
                            player.Finished[i]   = false;
                        }
                    }
                    else
                    {
                        player.FrameIndex[i] = (int)math.floor(clip.FPS * player.Playback[i]);
                    }
                }
            }

            PlayerData[index] = player;
        }