Exemple #1
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);
        }
 public MotionBinding(Motion parent)
 {
     Parent               = parent;
     BoneBindings         = new List <BoneBinding>();
     GlobalTransformation = new BoneBinding();
 }