<commit_before>using System;
using System.Collections.Generic;
using System.Linq;
using ValveResourceFormat.Serialization;

namespace ValveResourceFormat.ResourceTypes.ModelAnimation
{
    public class Skeleton
    {
        private const int BoneUsedByVertexLod0 = 0x00000400;

        public List<Bone> Roots { get; private set; } = new List<Bone>();
        public Bone[] Bones { get; private set; } = Array.Empty<Bone>();
        public int AnimationTextureSize { get; } = 0;

        /// <summary>
        /// Initializes a new instance of the <see cref="Skeleton"/> class.
        /// </summary>
        public static Skeleton FromModelData(IKeyValueCollection modelData, int meshIndex)
        {
            // Check if there is any skeleton data present at all
            if (!modelData.ContainsKey("m_modelSkeleton"))
            {
                Console.WriteLine("No skeleton data found.");
            }

            // Get the remap table and invert it for our construction method
            var remapTable = modelData.GetIntegerArray("m_remappingTable");

            var remapTableStarts = modelData.GetIntegerArray("m_remappingTableStarts");

            var start = (int)remapTableStarts[meshIndex];
            var end = meshIndex < remapTableStarts.Length - 1
                ? (int)remapTableStarts[meshIndex + 1]
                : remapTable.Length;

            var invMapTable = remapTable.Skip(start).Take(end - start)
                .Select((mapping, index) => (mapping, index))
                .ToLookup(mi => mi.mapping, mi => mi.index);

            // Construct the armature from the skeleton KV
            return new Skeleton(modelData.GetSubCollection("m_modelSkeleton"), invMapTable);
        }

        /// <summary>
        /// Construct the Armature object from mesh skeleton KV data.
        /// </summary>
        private Skeleton(IKeyValueCollection skeletonData, ILookup<long, int> remapTable)
        {
            var boneNames = skeletonData.GetArray<string>("m_boneName");
            var boneParents = skeletonData.GetIntegerArray("m_nParent");
            var boneFlags = skeletonData.GetIntegerArray("m_nFlag");
            var bonePositions = skeletonData.GetArray("m_bonePosParent", v => v.ToVector3());
            var boneRotations = skeletonData.GetArray("m_boneRotParent", v => v.ToQuaternion());

            if (remapTable.Any())
            {
                AnimationTextureSize = remapTable.Select(g => g.Max()).Max() + 1;
            }
<commit_msg>Set animation texture size only if there are any bones<commit_after>using System;
using System.Collections.Generic;
using System.Linq;
using ValveResourceFormat.Serialization;

namespace ValveResourceFormat.ResourceTypes.ModelAnimation
{
    public class Skeleton
    {
        private const int BoneUsedByVertexLod0 = 0x00000400;

        public List<Bone> Roots { get; private set; } = new List<Bone>();
        public Bone[] Bones { get; private set; } = Array.Empty<Bone>();
        public int AnimationTextureSize { get; } = 0;

        /// <summary>
        /// Initializes a new instance of the <see cref="Skeleton"/> class.
        /// </summary>
        public static Skeleton FromModelData(IKeyValueCollection modelData, int meshIndex)
        {
            // Check if there is any skeleton data present at all
            if (!modelData.ContainsKey("m_modelSkeleton"))
            {
                Console.WriteLine("No skeleton data found.");
            }

            // Get the remap table and invert it for our construction method
            var remapTable = modelData.GetIntegerArray("m_remappingTable");

            var remapTableStarts = modelData.GetIntegerArray("m_remappingTableStarts");

            var start = (int)remapTableStarts[meshIndex];
            var end = meshIndex < remapTableStarts.Length - 1
                ? (int)remapTableStarts[meshIndex + 1]
                : remapTable.Length;

            var invMapTable = remapTable.Skip(start).Take(end - start)
                .Select((mapping, index) => (mapping, index))
                .ToLookup(mi => mi.mapping, mi => mi.index);

            // Construct the armature from the skeleton KV
            return new Skeleton(modelData.GetSubCollection("m_modelSkeleton"), invMapTable);
        }

        /// <summary>
        /// Construct the Armature object from mesh skeleton KV data.
        /// </summary>
        private Skeleton(IKeyValueCollection skeletonData, ILookup<long, int> remapTable)
        {
            var boneNames = skeletonData.GetArray<string>("m_boneName");
            var boneParents = skeletonData.GetIntegerArray("m_nParent");
            var boneFlags = skeletonData.GetIntegerArray("m_nFlag");
            var bonePositions = skeletonData.GetArray("m_bonePosParent", v => v.ToVector3());
            var boneRotations = skeletonData.GetArray("m_boneRotParent", v => v.ToQuaternion());

            if (boneNames.Length > 0 && remapTable.Any())
            {
                AnimationTextureSize = remapTable.Select(g => g.Max()).Max() + 1;
            }

{'fraction_non_alphanumeric': 0.10300766660114016, 'fraction_numerical': 0.006093965008846078, 'mean_word_length': 2.340774786605384, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3873310', 'n_tokens_mistral': 1422, 'n_tokens_neox': 1332, 'n_words': 341}