Пример #1
0
        public AnimationClip buildAnimationClip(ZMD skeleton)
        {
            var clip = new AnimationClip();

            for (var i = 0; i < channelCount; ++i)
            {
                if (Channels[i].ID < 0 || Channels[i].ID >= skeleton.nBones)
                {
                    Debug.LogWarning("Found invalid channel index.");
                    continue;
                }

                string cbn = skeleton.bones[Channels[i].ID].Path;
                if (Channels[i].Type == ChannelType.Rotation)
                {
                    var curvex = new AnimationCurve();
                    var curvey = new AnimationCurve();
                    var curvez = new AnimationCurve();
                    var curvew = new AnimationCurve();
                    for (var j = 0; j < frameCount; ++j)
                    {
                        Frame.Channel chan = Frames[j].Channels[i];
                        curvex.AddKey((float)j / (float)FPS, chan.Rotation.x);
                        curvey.AddKey((float)j / (float)FPS, chan.Rotation.y);
                        curvez.AddKey((float)j / (float)FPS, chan.Rotation.z);
                        curvew.AddKey((float)j / (float)FPS, chan.Rotation.w);
                    }
                    clip.SetCurve(cbn, typeof(Transform), "localRotation.x", curvex);
                    clip.SetCurve(cbn, typeof(Transform), "localRotation.y", curvey);
                    clip.SetCurve(cbn, typeof(Transform), "localRotation.z", curvez);
                    clip.SetCurve(cbn, typeof(Transform), "localRotation.w", curvew);
                }
                else if (Channels[i].Type == ChannelType.Position)
                {
                    var curvex = new AnimationCurve();
                    var curvey = new AnimationCurve();
                    var curvez = new AnimationCurve();
                    for (var j = 0; j < frameCount; ++j)
                    {
                        Frame.Channel chan = Frames[j].Channels[i];
                        curvex.AddKey((float)j / (float)FPS, chan.Position.x);
                        curvey.AddKey((float)j / (float)FPS, chan.Position.y);
                        curvez.AddKey((float)j / (float)FPS, chan.Position.z);
                    }
                    clip.SetCurve(cbn, typeof(Transform), "localPosition.x", curvex);
                    clip.SetCurve(cbn, typeof(Transform), "localPosition.y", curvey);
                    clip.SetCurve(cbn, typeof(Transform), "localPosition.z", curvez);
                }
            }

            clip.EnsureQuaternionContinuity();
            return(clip);
        }
Пример #2
0
        // The following Get[Asset] functions will perform the following sequence:
        // 1. Determine if the unity asset is available, load it from Asset DB, then return a pointer to the asset
        // 2. If not present, create one from the corresponding rose files then place it in the same directory tree but GameData instead of 3DDATA
        // 3. Reload the asset from the Asset DB and return a pointer to it
        public static AnimationClip GetClip(string zmoPath, ZMD skeleton, string name)
        {
            DirectoryInfo zmoDir = new DirectoryInfo(zmoPath);
            string unityPath = zmoDir.FullName.Replace(zmoDir.Name, name) + ".anim";

            AnimationClip clip = (AnimationClip)Utils.LoadAsset(unityPath, ".anim");

            if (clip == null)
            {
                clip = new ZMO(zmoPath).buildAnimationClip(skeleton);
                clip.name = name;
                clip.legacy = true;
                clip = (AnimationClip)Utils.SaveReloadAsset(clip, unityPath, ".anim");
            }

            return clip;
        }
Пример #3
0
        // The following Get[Asset] functions will perform the following sequence:
        // 1. Determine if the unity asset is available, load it from Asset DB, then return a pointer to the asset
        // 2. If not present, create one from the corresponding rose files then place it in the same directory tree but GameData instead of 3DDATA
        // 3. Reload the asset from the Asset DB and return a pointer to it

        public static AnimationClip GetClip(string zmoPath, ZMD skeleton, string name)
        {
            DirectoryInfo zmoDir    = new DirectoryInfo(zmoPath);
            string        unityPath = zmoDir.FullName.Replace(zmoDir.Name, name) + ".anim";

            AnimationClip clip = (AnimationClip)Utils.LoadAsset(unityPath, ".anim");

            if (clip == null)
            {
                clip        = new ZMO(zmoPath).buildAnimationClip(skeleton);
                clip.name   = name;
                clip.legacy = true;
                clip        = (AnimationClip)Utils.SaveReloadAsset(clip, unityPath, ".anim");
            }

            return(clip);
        }
Пример #4
0
        public void LoadClips(GameObject skeleton, ZMD zmd, GenderType gender, RigType rig, Dictionary<String, String> zmoPaths)
        {
            List<AnimationClip> clips = new List<AnimationClip>();

            foreach (KeyValuePair<String, String> motion in zmoPaths)
            {
                string unityPath = "Assets/Resources/Animation/" + gender.ToString() + "/" + rig.ToString() + "/clips/" + motion.Key + ".anim";

                AnimationClip clip = new ZMO("Assets/" + motion.Value).buildAnimationClip(zmd);
                clip.name = motion.Key;
                clip.legacy = true;
                clip = (AnimationClip)Utils.SaveReloadAsset(clip, unityPath, ".anim");
                clips.Add(clip);
            }

            Animation animation = skeleton.AddComponent<Animation>();
            AnimationUtility.SetAnimationClips(animation, clips.ToArray());
        }
Пример #5
0
        /// <summary>
        /// Loads all animations for given weapon type and gender. The clips are saved to Animation/{gender}/{weapon}/clips/{action}.anim 
        /// Used only in editor to generate prefabs
        /// </summary>
        /// <param name="skeleton"></param>
        /// <param name="weapon"></param>
        /// <param name="gender"></param>
        /// <returns></returns>
        public void LoadClips(GameObject skeleton, ZMD zmd, WeaponType weapon, GenderType gender)
        {
            List<AnimationClip> clips = new List<AnimationClip>();

            foreach (ActionType action in Enum.GetValues(typeof(ActionType)))
            {
                string zmoPath = Utils.FixPath(ResourceManager.Instance.GetZMOPath(weapon, action, gender));  // Assets/3ddata path
                string unityPath = "Assets/Resources/Animation/" + gender.ToString() + "/" + weapon.ToString() + "/clips/" + action.ToString() + ".anim";

                AnimationClip clip =  new ZMO("Assets/" + zmoPath).buildAnimationClip(zmd);
                clip.name = action.ToString();
                clip.legacy = true;
                clip = (AnimationClip)Utils.SaveReloadAsset(clip, unityPath, ".anim");
                clips.Add(clip);
            }

            Animation animation = skeleton.AddComponent<Animation> ();
            AnimationUtility.SetAnimationClips(animation, clips.ToArray());
        }
Пример #6
0
        /// <summary>
        /// Loads all animations for equiped weapon type. Used only in editor to generate prefabs
        /// </summary>
        /// <param name="WeaponType"></param>
        public void LoadAnimations(GameObject player, ZMD skeleton, WeaponType weapon, GenderType gender)
        {
            List<AnimationClip> clips = new List<AnimationClip>();

            foreach (ActionType action in Enum.GetValues(typeof(ActionType)))
            {
                // Attempt to find animation asset, and if not found, load from ZMO
                string zmoPath = Utils.FixPath(ResourceManager.Instance.GetZMOPath(weapon, action, gender));
                AnimationClip clip = R2U.GetClip(zmoPath, skeleton, action.ToString());
                clip.legacy = true;
                clips.Add(clip);
            }

            Animation animation = player.GetComponent<Animation>();
            AnimationUtility.SetAnimationClips(animation, clips.ToArray());
        }
Пример #7
0
        public void GenerateAnimationAsset(GenderType gender, RigType rig, Dictionary<String,String> zmoPaths)
        {
            GameObject skeleton = new GameObject("skeleton");
            bool male = (gender == GenderType.MALE);
            ZMD zmd = new ZMD(male ? "Assets/3DData/Avatar/MALE.ZMD" : "Assets/3DData/Avatar/FEMALE.ZMD");
            zmd.buildSkeleton(skeleton);

            BindPoses poses = ScriptableObject.CreateInstance<BindPoses>();
            poses.bindPoses = zmd.bindposes;
            poses.boneNames = getBoneNames(zmd.boneTransforms);
            poses.boneTransforms = zmd.boneTransforms;
            LoadClips(skeleton, zmd, gender, rig, zmoPaths);
            string path = "Assets/Resources/Animation/" + gender.ToString() + "/" + rig.ToString() + "/skeleton.prefab";
            AssetDatabase.CreateAsset(poses, path.Replace("skeleton.prefab", "bindPoses.asset"));
            AssetDatabase.SaveAssets();
            PrefabUtility.CreatePrefab(path, skeleton);
        }
Пример #8
0
        public AnimationClip buildAnimationClip(ZMD skeleton)
        {
            var clip = new AnimationClip();

            for (var i = 0; i < channelCount ; ++i) {
                if (Channels[i].ID < 0 || Channels[i].ID >= skeleton.nBones) {
                    Debug.LogWarning("Found invalid channel index.");
                    continue;
                }

                string cbn = skeleton.bones[Channels[i].ID].Path;
                if (Channels[i].Type == ChannelType.Rotation) {
                    var curvex = new AnimationCurve();
                    var curvey = new AnimationCurve();
                    var curvez = new AnimationCurve();
                    var curvew = new AnimationCurve();
                    for (var j = 0; j < frameCount; ++j) {
                        Frame.Channel chan = Frames[j].Channels[i];
                        curvex.AddKey((float)j / (float)FPS, chan.Rotation.x);
                        curvey.AddKey((float)j / (float)FPS, chan.Rotation.y);
                        curvez.AddKey((float)j / (float)FPS, chan.Rotation.z);
                        curvew.AddKey((float)j / (float)FPS, chan.Rotation.w);
                    }
                    clip.SetCurve(cbn, typeof(Transform), "localRotation.x", curvex);
                    clip.SetCurve(cbn, typeof(Transform), "localRotation.y", curvey);
                    clip.SetCurve(cbn, typeof(Transform), "localRotation.z", curvez);
                    clip.SetCurve(cbn, typeof(Transform), "localRotation.w", curvew);
                }
                else if (Channels[i].Type == ChannelType.Position) {
                    var curvex = new AnimationCurve();
                    var curvey = new AnimationCurve();
                    var curvez = new AnimationCurve();
                    for (var j = 0; j < frameCount; ++j) {
                        Frame.Channel chan = Frames[j].Channels[i];
                        curvex.AddKey((float)j / (float)FPS, chan.Position.x);
                        curvey.AddKey((float)j / (float)FPS, chan.Position.y);
                        curvez.AddKey((float)j / (float)FPS, chan.Position.z);
                    }
                    clip.SetCurve(cbn, typeof(Transform), "localPosition.x", curvex);
                    clip.SetCurve(cbn, typeof(Transform), "localPosition.y", curvey);
                    clip.SetCurve(cbn, typeof(Transform), "localPosition.z", curvez);
                }
            }

            clip.EnsureQuaternionContinuity ();
            return clip;
        }