コード例 #1
0
        public static void CreateStoredPose()
        {
            string          name = "New";
            StoredPoseAsset sp   = ScriptableObject.CreateInstance <StoredPoseAsset>();
            Transform       root = Selection.activeGameObject.transform;

            //SkeletonConfiguration cpp = Selection.activeGameObject.transform.GetComponent<SkeletonConfiguration>();
            //if (cpp == null) cpp = Selection.activeGameObject.transform.GetComponentInChildren<SkeletonConfiguration>();
            //if (cpp == null) cpp = Selection.activeGameObject.transform.GetComponentInParent<SkeletonConfiguration>();

            //if (cpp != null) {
            name = root.name;
            //if (cpp.rootBone != null)
            //     sp.pose = StoredPoseAsset.StorePose(cpp.rootBone);
            //else sp.pose = StoredPoseAsset.StorePose(cpp.transform);
            sp.pose = StoredPoseAsset.StorePose(root);
            //} else {
            //    Debug.LogError("Failed to create a StoredPose. Select a SkeletonConfiguration in the hierarchy panel.");
            //}

            AssetDatabase.CreateAsset(sp, "Assets/" + name + "StoredPose.asset");
            AssetDatabase.SaveAssets();
            EditorUtility.FocusProjectWindow();
            Selection.activeObject = sp;
        }
コード例 #2
0
        public VJoint[] GenerateVJoints()
        {
            if (vJoints != null && vJoints.Length > 0)
            {
                return(vJoints);
            }
            Animator a = GetComponent <Animator>();

            if (a != null)
            {
                a.enabled = false;
            }
            StoredPoseAsset.ApplyPose(aPose.pose, transform);
            List <BoneMapAsset.HAnimBoneMapping> mergedMap = new List <BoneMapAsset.HAnimBoneMapping>();

            foreach (BoneMapAsset.HAnimBoneMapping m in boneMap.mappings)
            {
                mergedMap.Add(m);
            }
            foreach (BoneMapAsset.ExtraBone eb in boneMap.extraBones)
            {
                string bone_name = eb.hanim_bone.ToString();
                if (eb.hanim_bone == CanonicalRepresentation.HAnimBones.NONE)
                {
                    bone_name = eb.bone_name;
                }
                Transform ebTransform       = transform.FindChildRecursive(bone_name);
                Transform ebParentTransform = transform.FindChildRecursive(eb.parent_src_bone);
                if (ebTransform == null && ebParentTransform != null)
                {
                    ebTransform = (new GameObject(bone_name)).transform;
                    ebTransform.SetParent(ebParentTransform);
                    ebTransform.position      = ebParentTransform.position + eb.localPosition;
                    ebTransform.localRotation = Quaternion.Euler(eb.localEulerRotation.x, eb.localEulerRotation.y, eb.localEulerRotation.z);
                }
                BoneMapAsset.HAnimBoneMapping newMap;
                newMap.hanim_bone = eb.hanim_bone;
                newMap.src_bone   = bone_name;
                mergedMap.Add(newMap);
            }
            rig = new CanonicalRig(transform, mergedMap.ToArray());

            if (rig.boneMap == null)
            {
                _ready = false;
                rig    = null;
                Debug.LogError("Failed to create CanonicalRig");
                return(null);
            }

            VJoint[] res = new VJoint[rig.boneMap.Length];
            Dictionary <string, VJoint> lut = new Dictionary <string, VJoint>();

            for (int b = 0; b < rig.boneMap.Length; b++)
            {
                Transform bone = rig.boneMap[b].bone;
                if (rig.boneMap[b].canonicalBoneName == CanonicalRepresentation.HAnimBones.skullbase)
                {
                    head = bone;
                }
                VJoint     parent = null;
                Vector3    pos    = Vector3.zero;
                Quaternion rot    = rig.boneMap[b].CurrentRotationInCanonical();
                if (b == 0)
                {
                    pos = rootPosition;
                    rot = rot * rootRotation;
                }
                else
                {
                    pos    = (bone.position - bone.parent.position);
                    parent = lut[bone.parent.name];
                    if (parent == null)
                    {
                        Debug.LogError("Parent of " + bone.parent.name + " not added yet");
                        return(null);
                    }
                }
                string hAnimName = "";
                if (rig.boneMap[b].canonicalBoneName != CanonicalRepresentation.HAnimBones.NONE)
                {
                    hAnimName = rig.boneMap[b].canonicalBoneName.ToString();
                }
                res[b] = new VJoint(bone.name, hAnimName, pos, rot, parent);
                lut.Add(bone.name, res[b]);
            }
            vJoints = res;
            _ready  = true;
            return(vJoints);
        }