public void Merge(MotionBinding other)
        {
            foreach (var boneBinding in other.BoneBindings)
            {
                var baseBoneBinding = BoneBindings.FirstOrDefault(x =>
                                                                  x.Name.Equals(boneBinding.Name, StringComparison.OrdinalIgnoreCase));

                if (baseBoneBinding == null)
                {
                    BoneBindings.Add(boneBinding);
                }
                else
                {
                    baseBoneBinding.Merge(boneBinding);
                }
            }

            Parent.FrameCount = Math.Max(Parent.FrameCount, other.Parent.FrameCount);
        }
예제 #2
0
        public MotionBinding Bind(Skeleton skeleton             = null,
                                  MotionDatabase motionDatabase = null)
        {
            if (mBinding != null)
            {
                return(mBinding);
            }

            if (skeleton == null)
            {
                throw new ArgumentNullException(nameof(skeleton));
            }

            var binding = new MotionBinding(this);

            int index = 0;

            foreach (var boneInfo in BoneInfos)
            {
                if (motionDatabase != null && boneInfo.Id >= motionDatabase.BoneNames.Count)
                {
                    break;
                }

                boneInfo.Name = boneInfo.Name ?? motionDatabase?.BoneNames[( int )boneInfo.Id] ??
                                throw new ArgumentNullException(nameof(motionDatabase));

                var bone        = skeleton.GetBone(boneInfo.Name);
                var boneBinding = new BoneBinding {
                    Name = boneInfo.Name
                };

                if (bone != null)
                {
                    if (bone.Type != BoneType.Rotation)
                    {
                        boneBinding.Position = BindNext();
                    }

                    if (bone.Type != BoneType.Position)
                    {
                        boneBinding.Rotation = BindNext();
                    }

                    binding.BoneBindings.Add(boneBinding);
                }

                else if (boneInfo.Name.Equals("gblctr", StringComparison.OrdinalIgnoreCase))
                {
                    binding.GlobalTransformation.Position = BindNext();
                }

                else if (boneInfo.Name.Equals("kg_ya_ex", StringComparison.OrdinalIgnoreCase))
                {
                    binding.GlobalTransformation.Rotation = BindNext();
                }

                KeyBinding BindNext()
                {
                    return(new KeyBinding
                    {
                        X = KeySets[index++],
                        Y = KeySets[index++],
                        Z = KeySets[index++]
                    });
                }
            }

            return(mBinding = binding);
        }