public float getValue(int frame) { AnimKey f1 = null, f2 = null; for (int i = 0; i < keys.Count - 1; i++) { if ((keys [i].input - 1 <= frame && keys [i + 1].input - 1 >= frame)) { f1 = keys [i]; f2 = keys [i + 1]; break; } } if (f1 == null) { if (keys.Count <= 1) { return(keys [0].output); } else { f1 = keys [keys.Count - 2]; f2 = keys [keys.Count - 1]; } } return(CHR0.interHermite(frame + 1, f1.input, f2.input, weighted ? f1.t1 : 0, weighted ? f2.t1 : 0, f1.output, f2.output)); }
public void PlayAnimation(AnimKey key) { // If Exist xlua when run Xlua xlua = gameObject.GetComponent <XLuaBehaviour>(); if (xlua != null) { xlua.InvokeXLua("PlayAnimation", key.ToString()); return; } if (anim != null) { isLayerAnimOpenDone = false; anim.enabled = true; graphicRaycaster.enabled = false; if (key == AnimKey.OpenPopup || key == AnimKey.ClosePopup) { if (key == AnimKey.OpenPopup) { StartCoroutine(DelayToResetAfterAnim()); } anim.SetTrigger(key.ToString()); } else { StartCoroutine(DelaytoRunAnim(key)); } } else { isLayerAnimOpenDone = true; } }
static void AddAnimData(ExportSettings settings, AnimBone animBone, IOAnimationTrack track, ControlType ctype, TrackType ttype) { AnimData d = new AnimData(); d.controlType = ctype; d.type = ttype; d.preInfinity = CurveWrapModes[track.PreWrap]; d.postInfinity = CurveWrapModes[track.PostWrap]; //Check if any tangents include weights. d.weighted = track.KeyFrames.Any(x => x is IOKeyFrameHermite && ((IOKeyFrameHermite)x).IsWeighted); bool isAngle = ctype == ControlType.rotate; if (isAngle) { d.output = OutputType.angular; } float value = track.KeyFrames.Count > 0 ? (float)track.KeyFrames[0].Value : 0; bool IsConstant = true; foreach (var key in track.KeyFrames) { if ((float)key.Value != value) { IsConstant = false; break; } } foreach (var key in track.KeyFrames) { AnimKey animKey = new AnimKey() { input = key.Frame + 1, output = isAngle ? GetAngle(settings, (float)key.Value) : (float)key.Value, }; if (key is IOKeyFrameHermite) { animKey.intan = "fixed"; animKey.outtan = "fixed"; animKey.t1 = ((IOKeyFrameHermite)key).TangentSlopeInput; animKey.t2 = ((IOKeyFrameHermite)key).TangentSlopeOutput; animKey.w1 = ((IOKeyFrameHermite)key).TangentWeightInput; animKey.w2 = ((IOKeyFrameHermite)key).TangentWeightOutput; } d.keys.Add(animKey); if (IsConstant) { break; } } if (d.keys.Count > 0) { animBone.atts.Add(d); } }
void UpdateCurrentObjectAnimation(GameObject gObject) { if (null == currentObject || currentObject != gObject) { return; } Clear(); AnimationSet animationSet = GlobalState.Animation.GetObjectAnimation(gObject); if (null == animationSet) { UpdateTrackName(); return; } // Take only one curve (the first one) to add keys foreach (AnimationKey key in animationSet.curves[0].keys) { if (!keys.TryGetValue(key.frame, out List <AnimKey> keyList)) { keyList = new List <AnimKey>(); keys[key.frame] = keyList; } keyList.Add(new AnimKey(key.value, key.interpolation)); } UpdateTrackName(); Transform keyframes = transform.Find("MainPanel/Tracks/Summary/Keyframes"); foreach (var key in keys) { GameObject keyframe = GameObject.Instantiate(keyframePrefab, keyframes); List <AnimKey> animKeys = key.Value; AnimKey firstKey = animKeys[0]; switch (firstKey.interpolation) { case Interpolation.Constant: keyframe.GetComponent <MeshRenderer>().material.SetColor("_UnlitColor", constantInterpolationColor); break; case Interpolation.Linear: keyframe.GetComponent <MeshRenderer>().material.SetColor("_UnlitColor", linearInterpolationColor); break; case Interpolation.Bezier: keyframe.GetComponent <MeshRenderer>().material.SetColor("_UnlitColor", bezierInterpolationColor); break; } } UpdateKeyframes(); }
private static void AddAnimData(AnimBone animBone, SBKeyGroup <float> keys, ControlType ctype, TrackType ttype) { AnimData d = new AnimData(); d.controlType = ctype; d.type = ttype; if (IsAngular(ctype)) { d.output = OutputType.angular; } float value = 0; if (keys.Keys.Count > 0) { value = keys.Keys[0].Value; } bool IsConstant = true; foreach (var key in keys.Keys) { if (key.Value != value) { IsConstant = false; break; } } foreach (var key in keys.Keys) { AnimKey animKey = new AnimKey() { input = key.Frame + 1, output = IsAngular(ctype) ? (MayaSettings.UseRadians ? key.Value : (float)(key.Value * (180 / Math.PI))) : key.Value, }; if (key.InterpolationType == InterpolationType.Hermite) { animKey.intan = "fixed"; animKey.outtan = "fixed"; animKey.t1 = key.InTan; animKey.t2 = key.OutTan; } d.keys.Add(animKey); if (IsConstant) { break; } } if (d.keys.Count > 0) { animBone.atts.Add(d); } }
private static void AddAnimData(AnimBone animBone, SBKeyGroup <Matrix4> node, ControlType ctype, TrackType ttype) { AnimData d = new AnimData(); d.controlType = ctype; d.type = ttype; foreach (var key in node.Keys) { AnimKey animKey = new AnimKey() { input = key.Frame + 1, output = GetValue(key.Value, ctype, ttype) }; d.keys.Add(animKey); } if (d.keys.Count > 0) { animBone.atts.Add(d); } }
private static void AddAnimData(AnimBone animBone, IOAnimNode node, IOTrackType type, ControlType ctype, TrackType ttype) { AnimData d = new AnimData(); d.controlType = ctype; d.type = ttype; foreach (IOAnimKey key in node.GetKeysForTrack(type)) { AnimKey animKey = new AnimKey() { input = key.Frame + 1, output = key.Value, }; d.keys.Add(animKey); } if (d.keys.Count > 0) { animBone.atts.Add(d); } }
public static SkelAnimation read(string filename, VBN vbn) { StreamReader reader = File.OpenText(filename); string line; bool isHeader = true; string angularUnit, linearUnit, timeUnit; int startTime = 0; int endTime = 0; List <AnimBone> bones = new List <AnimBone>(); AnimBone current; AnimData att = new AnimData(); bool inKeys = false; while ((line = reader.ReadLine()) != null) { string[] args = line.Replace(";", "").TrimStart().Split(' '); if (isHeader) { if (args [0].Equals("anim")) { isHeader = false; } else if (args [0].Equals("angularUnit")) { angularUnit = args [1]; } else if (args [0].Equals("endTime")) { endTime = (int)Math.Ceiling(float.Parse(args [1])); } else if (args [0].Equals("startTime")) { startTime = (int)Math.Ceiling(float.Parse(args [1])); } } if (!isHeader) { if (inKeys) { if (args[0].Equals("}")) { inKeys = false; continue; } AnimKey k = new AnimKey(); att.keys.Add(k); k.input = float.Parse(args [0]); k.output = float.Parse(args [1]); k.intan = (args [2]); k.outtan = (args [3]); if (args.Length > 7 && att.weighted) { k.t1 = float.Parse(args[7]) * (float)(Math.PI / 180f); k.w1 = float.Parse(args[8]); } } if (args [0].Equals("anim")) { inKeys = false; if (args.Length == 5) { //TODO: finish this type // can be name of attribute } if (args.Length == 7) { // see of the bone of this attribute exists current = null; foreach (AnimBone b in bones) { if (b.name.Equals(args [3])) { current = b; break; } } if (current == null) { current = new AnimBone(); bones.Add(current); } current.name = args [3]; att = new AnimData(); att.type = args [2]; current.atts.Add(att); // row child attribute aren't needed here } } if (args [0].Equals("input")) { att.input = args [1]; } if (args [0].Equals("output")) { att.output = args [1]; } if (args [0].Equals("weighted")) { att.weighted = args [1].Equals("1"); } if (args [0].Equals("preInfinity")) { att.preInfinity = args [1]; } if (args [0].Equals("postInfinity")) { att.postInfinity = args [1]; } // begining keys section if (args [0].Contains("keys")) { inKeys = true; } } } SkelAnimation a = new SkelAnimation(); for (int i = 0; i < endTime - startTime + 1; i++) { KeyFrame key = new KeyFrame(); a.addKeyframe(key); foreach (AnimBone b in bones) { KeyNode n = new KeyNode(); n.id = vbn.boneIndex(b.name); if (n.id == -1) { continue; } else { n.hash = vbn.bones[n.id].boneId; } foreach (AnimData d in b.atts) { if (d.type.Contains("translate")) { n.t_type = KeyNode.INTERPOLATED; if (d.type.Contains("X")) { n.t.X = d.getValue(i); } if (d.type.Contains("Y")) { n.t.Y = d.getValue(i); } if (d.type.Contains("Z")) { n.t.Z = d.getValue(i); } } if (d.type.Contains("rotate")) { n.r_type = KeyNode.INTERPOLATED; if (d.type.Contains("X")) { n.r.X = d.getValue(i) * (float)(Math.PI / 180f); } if (d.type.Contains("Y")) { n.r.Y = d.getValue(i) * (float)(Math.PI / 180f); } if (d.type.Contains("Z")) { n.r.Z = d.getValue(i) * (float)(Math.PI / 180f); } } if (d.type.Contains("scale")) { n.s_type = KeyNode.INTERPOLATED; if (d.type.Contains("X")) { n.s.X = d.getValue(i); } if (d.type.Contains("Y")) { n.s.Y = d.getValue(i); } if (d.type.Contains("Z")) { n.s.Z = d.getValue(i); } } } key.addNode(n); } } // keynode rotations need caluclation foreach (KeyFrame f in a.frames) { foreach (KeyNode n in f.nodes) { n.r = VBN.FromEulerAngles(n.r.Z, n.r.Y, n.r.X); } } reader.Close(); return(a); }
public static unsafe AnimationClip ParseAnimation(Dictionary <string, string> BoneKey, RayFile file) { AnimationClip Out = new AnimationClip(); Out.name = file.GetStringBuffer(0).Buffer; int count = file.Header.HeaderCount - 1; for (int i = 0; i < count / 2; i++) { int index = (i * 2) + 1; string[] name = file.GetStringBuffer(index).Buffer.Split('-'); if (name[1] == "transform") { AnimationCurve XCurve = new AnimationCurve(); AnimationCurve YCurve = new AnimationCurve(); AnimationCurve ZCurve = new AnimationCurve(); AnimationCurve RotationCurveX = new AnimationCurve(); AnimationCurve RotationCurveY = new AnimationCurve(); AnimationCurve RotationCurveZ = new AnimationCurve(); AnimationCurve RotationCurveW = new AnimationCurve(); AnimationCurve XScCurve = new AnimationCurve(); AnimationCurve YScCurve = new AnimationCurve(); AnimationCurve ZScCurve = new AnimationCurve(); fixed(byte *b = &file.Buffers[index + 1][0]) { AnimKey *Data = AnimKey.GetBuffer(b); int size = file.Buffers[index + 1].Length / sizeof(AnimKey); for (int time = 0; time < size; time++) { AnimKey Key = Data[time]; XCurve.AddKey(new Keyframe(time / 60.0f, Key.Position.x)); YCurve.AddKey(new Keyframe(time / 60.0f, Key.Position.y)); ZCurve.AddKey(new Keyframe(time / 60.0f, Key.Position.z)); RotationCurveX.AddKey(new Keyframe(time / 60.0f, Key.Rotation.x)); RotationCurveY.AddKey(new Keyframe(time / 60.0f, Key.Rotation.y)); RotationCurveZ.AddKey(new Keyframe(time / 60.0f, Key.Rotation.z)); RotationCurveW.AddKey(new Keyframe(time / 60.0f, Key.Rotation.w)); XScCurve.AddKey(new Keyframe(time / 60.0f, Key.Scale.x)); YScCurve.AddKey(new Keyframe(time / 60.0f, Key.Scale.y)); ZScCurve.AddKey(new Keyframe(time / 60.0f, Key.Scale.z)); } } if (BoneKey.ContainsKey(name[0])) { Out.SetCurve(BoneKey[name[0]], typeof(Transform), "localPosition.x", XCurve); Out.SetCurve(BoneKey[name[0]], typeof(Transform), "localPosition.y", YCurve); Out.SetCurve(BoneKey[name[0]], typeof(Transform), "localPosition.z", ZCurve); Out.SetCurve(BoneKey[name[0]], typeof(Transform), "localRotation.x", RotationCurveX); Out.SetCurve(BoneKey[name[0]], typeof(Transform), "localRotation.y", RotationCurveY); Out.SetCurve(BoneKey[name[0]], typeof(Transform), "localRotation.z", RotationCurveZ); Out.SetCurve(BoneKey[name[0]], typeof(Transform), "localRotation.w", RotationCurveW); Out.SetCurve(BoneKey[name[0]], typeof(Transform), "localScale.x", XScCurve); Out.SetCurve(BoneKey[name[0]], typeof(Transform), "localScale.x", YScCurve); Out.SetCurve(BoneKey[name[0]], typeof(Transform), "localScale.x", ZScCurve); } } } return(Out); }
public void Open(string fileName) { using (StreamReader r = new StreamReader(new FileStream(fileName, FileMode.Open))) { AnimData currentData = null; while (!r.EndOfStream) { var line = r.ReadLine(); var args = line.Trim().Replace(";", "").Split(' '); switch (args[0]) { case "animVersion": header.animVersion = float.Parse(args[1]); break; case "mayaVersion": header.mayaVersion = args[1]; break; case "timeUnit": header.timeUnit = args[1]; break; case "linearUnit": header.linearUnit = args[1]; break; case "angularUnit": header.angularUnit = args[1]; break; case "startTime": header.startTime = float.Parse(args[1]); break; case "endTime": header.endTime = float.Parse(args[1]); break; case "anim": if (args.Length != 7) { continue; } var currentNode = Bones.Find(e => e.name.Equals(args[3])); if (currentNode == null) { currentNode = new AnimBone(); currentNode.name = args[3]; Bones.Add(currentNode); } currentData = new AnimData(); currentData.controlType = (ControlType)Enum.Parse(typeof(ControlType), args[1].Split('.')[0]); if (currentData.controlType == ControlType.MaxHandle) { currentData = null; break; } currentData.type = (TrackType)Enum.Parse(typeof(TrackType), args[2]); currentNode.atts.Add(currentData); break; case "animData": if (currentData == null) { continue; } string dataLine = r.ReadLine(); while (!dataLine.Contains("}")) { var dataArgs = dataLine.Trim().Replace(";", "").Split(' '); switch (dataArgs[0]) { case "input": currentData.input = (InputType)Enum.Parse(typeof(InputType), dataArgs[1]); break; case "output": currentData.output = (OutputType)Enum.Parse(typeof(OutputType), dataArgs[1]); break; case "weighted": currentData.weighted = dataArgs[1] == "1"; break; case "preInfinity": currentData.preInfinity = (InfinityType)Enum.Parse(typeof(InfinityType), dataArgs[1]); break; case "postInfinity": currentData.postInfinity = (InfinityType)Enum.Parse(typeof(InfinityType), dataArgs[1]); break; case "keys": string keyLine = r.ReadLine(); while (!keyLine.Contains("}")) { var keyArgs = keyLine.Trim().Replace(";", "").Split(' '); var key = new AnimKey() { input = float.Parse(keyArgs[0]), output = float.Parse(keyArgs[1]) }; if (keyArgs.Length >= 7) { key.intan = keyArgs[2]; key.outtan = keyArgs[3]; } if (key.intan == "fixed") { key.t1 = float.Parse(keyArgs[7]); key.w1 = float.Parse(keyArgs[8]); } if (key.outtan == "fixed" && keyArgs.Length > 9) { key.t2 = float.Parse(keyArgs[9]); key.w2 = float.Parse(keyArgs[10]); } currentData.keys.Add(key); keyLine = r.ReadLine(); } break; } dataLine = r.ReadLine(); } break; } } } }
float PlayNewEnemyAnimation() { ClipAnimSet newAnimSet = null; AnimKey key = new AnimKey(GetAnimState(), _animDirection); if (_animations.TryGetValue(key, out newAnimSet)) { if (newAnimSet != currentAnimSet) { bool isLooping = key.State == AnimState.Idle || key.State == AnimState.Run || key.State == AnimState.Attack; ClipAnim newAnim = newAnimSet.GetNextAnim(); if (newAnim == null) { throw new InvalidOperationException("Could not find Enemy animation for " + key.State.ToString() + "-" + key.Direction.ToString()); } else { ClipInstance.Play(newAnim, isLooping); } currentAnimSet = newAnimSet; } return ClipInstance.CurrentAnim.DurationInSecondsRemaining; } return 0.0f; }
public BFRES_FSHU(MTA mta, ShaderParamAnim fshu, ResFile b) { mta.Text = fshu.Name; mta.FrameCount = (uint)fshu.FrameCount; foreach (ShaderParamMatAnim matanim in fshu.ShaderParamMatAnims) { MatAnimEntry mat = new MatAnimEntry(); mat.Text = matanim.Name; Console.WriteLine($"MatAnim = {mat.Text}"); Console.WriteLine($"Curve Count = {matanim.Curves.Count}"); if (matanim.Curves.Count == 0) { } //First set the data then iterpolate foreach (AnimCurve cr in matanim.Curves) { mat.InterpolateWU(cr); } mta.matEntries.Add(mat); for (int Frame = 0; Frame < fshu.FrameCount; Frame++) { foreach (MatAnimData track in mat.matCurves) { AnimKey left = track.GetLeft(Frame); AnimKey right = track.GetRight(Frame); track.Value = Animation.Hermite(Frame, left.frame, right.frame, 0, 0, left.unk1, right.unk1); } } int CurCurve = 0; for (int Frame = 0; Frame < fshu.FrameCount; Frame++) { foreach (MatAnimData track in mat.matCurves) { //This works like this //Each param has their own info. While this loop through each curve determine which data is which //Set the param name. Then detemine the data in between begin curve and total count //Example. Begin curve starts at 0. Count may be 3 for RGB values //Then for next curve would start at 3 and so on //For color I simply use the values starting from RGBA //Then for the next param i subtract the start value to reset the index back to 0 foreach (ParamAnimInfo inf in matanim.ParamAnimInfos) { track.shaderParamName = inf.Name; if (inf.BeginCurve >= CurCurve) { if (inf.FloatCurveCount >= CurCurve) { int ColorIndex = CurCurve - inf.BeginCurve; track.AnimColorType = (MatAnimData.ColorType)ColorIndex; } } } } CurCurve++; } mta.matEntries.Add(mat); } }
IEnumerator DelaytoRunAnim(AnimKey key) { yield return(new WaitForSeconds(0.2f)); anim.SetTrigger(key.ToString()); }