Пример #1
0
        public void IsValidTest()
        {
            var m = Matrix44F.CreateTranslation(1, 2, 3) * Matrix44F.CreateRotationY(0.1f) * Matrix44F.CreateScale(-2, 3, 4);

            Assert.IsTrue(SrtTransform.IsValid(m));

            // Concatenating to SRTs creates a skew.
            m = Matrix44F.CreateRotationZ(0.1f) * Matrix44F.CreateScale(-2, 3, 4) * m;
            Assert.IsFalse(SrtTransform.IsValid(m));
        }
        private void BuildSkeleton()
        {
            // Get an array of all bones in depth-first order.
            // (Same as MeshHelper.FlattenSkeleton(root).)
            var bones = TreeHelper.GetSubtree(_rootBone, n => n.Children.OfType <BoneContent>(), true)
                        .ToList();

            // Create list of parent indices, bind pose transformations and bone names.
            var boneParents      = new List <int>();
            var bindTransforms   = new List <SrtTransform>();
            var boneNames        = new List <string>();
            int numberOfWarnings = 0;

            foreach (var bone in bones)
            {
                int parentIndex = bones.IndexOf(bone.Parent as BoneContent);
                boneParents.Add(parentIndex);

                // Log warning for invalid transform matrices - but not too many warnings.
                if (numberOfWarnings < 2)
                {
                    if (!SrtTransform.IsValid((Matrix)bone.Transform))
                    {
                        if (numberOfWarnings < 1)
                        {
                            _context.Logger.LogWarning(null, _input.Identity, "Bone transform is not supported. Bone transform matrices may only contain scaling, rotation and translation.");
                        }
                        else
                        {
                            _context.Logger.LogWarning(null, _input.Identity, "More unsupported bone transform found.");
                        }

                        numberOfWarnings++;
                    }
                }

                bindTransforms.Add(SrtTransform.FromMatrix(bone.Transform));

                if (boneNames.Contains(bone.Name))
                {
                    string message = String.Format(CultureInfo.InvariantCulture, "Duplicate bone name (\"{0}\") found.", bone.Name);
                    throw new InvalidContentException(message, _input.Identity);
                }

                boneNames.Add(bone.Name);
            }

            // Create and return a new skeleton instance.
            _skeleton = new Skeleton(boneParents, boneNames, bindTransforms);
        }