コード例 #1
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));
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Skeleton"/> class.
        /// </summary>
        public Skeleton(IKeyValueCollection modelData)
        {
            // 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 start = 0;
            var end   = remapTable.Length;

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

            // we only use lod 1
            if (remapTableStarts.Length > 1)
            {
                start = (int)remapTableStarts[0];
                end   = (int)remapTableStarts[1];
            }

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

            if (invMapTable.Any())
            {
                AnimationTextureSize = invMapTable.Select(g => g.Max()).Max() + 1;
            }

            // Construct the armature from the skeleton KV
            ConstructFromNTRO(modelData.GetSubCollection("m_modelSkeleton"), invMapTable);
        }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Skeleton"/> class.
        /// </summary>
        public Skeleton(IKeyValueCollection modelData)
        {
            Bones = new Bone[0];
            Roots = new List <Bone>();

            // 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 invMapTable = new Dictionary <long, int>();

            for (var i = 0; i < remapTable.Length; i++)
            {
                if (!invMapTable.ContainsKey(remapTable[i]))
                {
                    invMapTable.Add(remapTable[i], i);
                }
            }

            // Construct the armature from the skeleton KV
            ConstructFromNTRO(modelData.GetSubCollection("m_modelSkeleton"), invMapTable);
        }
コード例 #4
0
        public RandomColor(IKeyValueCollection keyValues)
        {
            random = new Random();

            if (keyValues.ContainsKey("m_ColorMin"))
            {
                var vectorValues = keyValues.GetIntegerArray("m_ColorMin");
                colorMin = new Vector3(vectorValues[0], vectorValues[1], vectorValues[2]) / 255f;
            }

            if (keyValues.ContainsKey("m_ColorMax"))
            {
                var vectorValues = keyValues.GetIntegerArray("m_ColorMax");
                colorMax = new Vector3(vectorValues[0], vectorValues[1], vectorValues[2]) / 255f;
            }
        }
コード例 #5
0
        /// <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;
            }

            // Initialise bone array
            Bones = new Bone[boneNames.Length];

            //Add all bones to the list
            for (var i = 0; i < boneNames.Length; i++)
            {
                if ((boneFlags[i] & BoneUsedByVertexLod0) != BoneUsedByVertexLod0)
                {
                    continue;
                }

                var name = boneNames[i];

                var position = bonePositions[i];
                var rotation = boneRotations[i];

                // Create bone
                var bone = new Bone(name, remapTable[i].ToList(), position, rotation);

                if (boneParents[i] != -1)
                {
                    bone.SetParent(Bones[boneParents[i]]);
                    Bones[boneParents[i]].AddChild(bone);
                }

                Bones[i] = bone;
            }

            FindRoots();
        }
コード例 #6
0
        public ColorInterpolate(IKeyValueCollection keyValues)
        {
            if (keyValues.ContainsKey("m_ColorFade"))
            {
                var vectorValues = keyValues.GetIntegerArray("m_ColorFade");
                colorFade = new Vector3(vectorValues[0], vectorValues[1], vectorValues[2]) / 255f;
            }

            if (keyValues.ContainsKey("m_flFadeStartTime"))
            {
                fadeStartTime = keyValues.GetFloatProperty("m_flFadeStartTime");
            }

            if (keyValues.ContainsKey("m_flFadeEndTime"))
            {
                fadeEndTime = keyValues.GetFloatProperty("m_flFadeEndTime");
            }
        }
コード例 #7
0
        public Particle(IKeyValueCollection baseProperties)
        {
            if (baseProperties.ContainsKey("m_ConstantColor"))
            {
                var vectorValues = baseProperties.GetIntegerArray("m_ConstantColor");
                ConstantColor = new Vector3(vectorValues[0], vectorValues[1], vectorValues[2]) / 255f;
            }

            if (baseProperties.ContainsKey("m_flConstantRadius"))
            {
                ConstantRadius = baseProperties.GetFloatProperty("m_flConstantRadius");
            }

            if (baseProperties.ContainsKey("m_flConstantLifespan"))
            {
                ConstantLifetime = baseProperties.GetFloatProperty("m_flConstantLifespan");
            }

            Init();
        }
コード例 #8
0
        public Particle(IKeyValueCollection baseProperties)
        {
            ParticleCount    = 0;
            Alpha            = 1.0f;
            AlphaAlternate   = 1.0f;
            Position         = Vector3.Zero;
            PositionPrevious = Vector3.Zero;
            Rotation         = Vector3.Zero;
            RotationSpeed    = Vector3.Zero;
            Velocity         = Vector3.Zero;
            ConstantRadius   = 5.0f;
            ConstantAlpha    = 1.0f;
            ConstantColor    = Vector3.One;
            ConstantLifetime = 1;
            TrailLength      = 1;
            Sequence         = 0;

            if (baseProperties.ContainsKey("m_ConstantColor"))
            {
                var vectorValues = baseProperties.GetIntegerArray("m_ConstantColor");
                ConstantColor = new Vector3(vectorValues[0], vectorValues[1], vectorValues[2]) / 255f;
            }

            if (baseProperties.ContainsKey("m_flConstantRadius"))
            {
                ConstantRadius = baseProperties.GetFloatProperty("m_flConstantRadius");
            }

            if (baseProperties.ContainsKey("m_flConstantLifespan"))
            {
                ConstantLifetime = baseProperties.GetFloatProperty("m_flConstantLifespan");
            }

            Color    = ConstantColor;
            Lifetime = ConstantLifetime;
            Radius   = ConstantRadius;
        }
コード例 #9
0
        /// <summary>
        /// Construct the Armature object from mesh skeleton KV data.
        /// </summary>
        public void ConstructFromNTRO(IKeyValueCollection skeletonData, Dictionary <long, int> remapTable)
        {
            var boneNames     = skeletonData.GetArray <string>("m_boneName");
            var boneParents   = skeletonData.GetIntegerArray("m_nParent");
            var bonePositions = skeletonData.GetArray("m_bonePosParent", v => v.ToVector3());
            var boneRotations = skeletonData.GetArray("m_boneRotParent", v => v.ToQuaternion());

            // Initialise bone array
            Bones = new Bone[boneNames.Length];

            //Add all bones to the list
            for (var i = 0; i < boneNames.Length; i++)
            {
                var name = boneNames[i];

                var position = bonePositions[i];
                var rotation = boneRotations[i];

                // Create bone
                var index = remapTable.ContainsKey(i) ? remapTable[i] : -1;
                var bone  = new Bone(name, index, position, rotation);

                if (boneParents[i] != -1)
                {
                    bone.SetParent(Bones[boneParents[i]]);
                    Bones[boneParents[i]].AddChild(bone);
                }

                Bones[i] = bone;
            }

            FindRoots();

            // Figure out the index of the last bone so we dont have to do that every draw call
            LastBone = Bones.Length > 0 ? Bones.Max(b => b.Index) : -1;
        }