Ejemplo n.º 1
0
        /// <summary>
        /// If HierInfo represents a UsdSkelRoot, reads the associated skelton joints into the
        /// skelJoints member.
        /// </summary>
        static void ReadSkeletonJoints(ref HierInfo skelRootInfo)
        {
            if (skelRootInfo.prim == null)
            {
                return;
            }

            var skelRoot = new UsdSkelRoot(skelRootInfo.prim);

            if (!skelRoot)
            {
                return;
            }

            var processed = new HashSet <SdfPath>();

            foreach (UsdSkelBinding binding in skelRootInfo.skelBindings)
            {
                var skel = binding.GetSkeleton();

                if (!skel)
                {
                    continue;
                }

                // If the same skeleton is referenced multiple times, only process it once.
                if (processed.Contains(skel.GetPath()))
                {
                    continue;
                }
                processed.Add(skel.GetPath());

                var jointsAttr = skel.GetJointsAttr();
                if (!jointsAttr)
                {
                    continue;
                }

                var vtJoints = jointsAttr.Get();
                if (vtJoints.IsEmpty())
                {
                    continue;
                }
                var vtStrings = UsdCs.VtValueToVtTokenArray(vtJoints);
                var joints    = UnityTypeConverter.FromVtArray(vtStrings);

                var skelPath = skel.GetPath();
                skelRootInfo.skelJoints = new SdfPath[joints.Length];

                for (int i = 0; i < joints.Length; i++)
                {
                    var jointPath = new SdfPath(joints[i]);
                    if (joints[i] == "/")
                    {
                        skelRootInfo.skelJoints[i] = skelPath;
                        continue;
                    }
                    else if (jointPath.IsAbsolutePath())
                    {
                        Debug.LogException(new Exception("Unexpected absolute joint path: " + jointPath));
                        jointPath = new SdfPath(joints[i].TrimStart('/'));
                    }
                    skelRootInfo.skelJoints[i] = skelPath.AppendPath(jointPath);
                }
            }
        }
Ejemplo n.º 2
0
        static void ReadSkeleton(ref HierInfo info)
        {
            if (info.prim == null)
            {
                return;
            }

            var skelRoot = new UsdSkelRoot(info.prim);

            if (!skelRoot)
            {
                return;
            }

            var skelRel = info.prim.GetRelationship(UsdSkelTokens.skelSkeleton);

            if (!skelRel)
            {
                return;
            }

            SdfPathVector targets = skelRel.GetForwardedTargets();

            if (targets == null || targets.Count == 0)
            {
                return;
            }

            var skelPrim = info.prim.GetStage().GetPrimAtPath(targets[0]);

            if (!skelPrim)
            {
                return;
            }

            var skel = new UsdSkelSkeleton(skelPrim);

            if (!skel)
            {
                return;
            }

            var jointsAttr = skel.GetJointsAttr();

            if (!jointsAttr)
            {
                return;
            }

            var vtJoints = jointsAttr.Get();

            if (vtJoints.IsEmpty())
            {
                return;
            }
            var vtStrings = UsdCs.VtValueToVtTokenArray(vtJoints);
            var joints    = UnityTypeConverter.FromVtArray(vtStrings);

            var skelPath = skelPrim.GetPath();

            info.skelJoints = new SdfPath[joints.Length];

            for (int i = 0; i < joints.Length; i++)
            {
                var jointPath = new SdfPath(joints[i]);
                if (joints[i] == "/")
                {
                    info.skelJoints[i] = skelPath;
                    continue;
                }
                else if (jointPath.IsAbsolutePath())
                {
                    Debug.LogException(new Exception("Unexpected absolute joint path: " + jointPath));
                    jointPath = new SdfPath(joints[i].TrimStart('/'));
                }
                info.skelJoints[i] = skelPath.AppendPath(jointPath);
            }
        }