// Go through each animation node public override void Process() { // Some objects may have Keyframe data without text keys. Maybe these should be added into the animation curve of whatever object they are loaded onto? Ignore unless we're having animation issues and can't find any other causes if (niFile.animationCache == null) { return; } // Go through each clip var path = GetRelativePath(); foreach (var clip in niFile.animationCache.Values) { if (quaternionKeys != null) { var animationCurves = quaternionKeys.GetAnimationCurves(clip.Start, clip.Stop); // These checks need to sample the curve at the start and stop if the length is 0, and add a start and stop keyfame if needed if (animationCurves[0].length > 1) { clip.clip.SetCurve(path, typeof(Transform), "localRotation.x", animationCurves[0]); clip.clip.SetCurve(path, typeof(Transform), "localRotation.y", animationCurves[1]); clip.clip.SetCurve(path, typeof(Transform), "localRotation.z", animationCurves[2]); clip.clip.SetCurve(path, typeof(Transform), "localRotation.w", animationCurves[3]); } } if (translationKeyframes != null) { var animationCurves = translationKeyframes.GetAnimationCurves(clip.Start, clip.Stop); if (animationCurves[0].length > 1) { clip.clip.SetCurve(path, typeof(Transform), "localPosition.x", animationCurves[0]); clip.clip.SetCurve(path, typeof(Transform), "localPosition.y", animationCurves[1]); clip.clip.SetCurve(path, typeof(Transform), "localPosition.z", animationCurves[2]); } } if (scaleKeyframes != null) { var animationCurves = scaleKeyframes.GetAnimationCurves(clip.Start, clip.Stop); if (animationCurves[0].length > 1) { clip.clip.SetCurve(path, typeof(Transform), "localScale.x", animationCurves[0]); clip.clip.SetCurve(path, typeof(Transform), "localScale.y", animationCurves[0]); clip.clip.SetCurve(path, typeof(Transform), "localScale.z", animationCurves[0]); } } } }
public NiUVData(NiFile niFile) : base(niFile) { clip = new AnimationClip() { frameRate = 15, legacy = true, name = "animation", wrapMode = WrapMode.Loop }; // U Translation var length = niFile.Reader.ReadInt32(); if (length > 0) { var interpolation = (KeyType)niFile.Reader.ReadInt32(); var uTranslation = new NiFloatKeyframeGroup(length, interpolation, niFile.Reader); var animationCurves = uTranslation.GetAnimationCurves(); clip.SetCurve(string.Empty, typeof(Renderer), "material._MainTex_ST.z", animationCurves[0]); } // V Translation length = niFile.Reader.ReadInt32(); if (length > 0) { var interpolation = (KeyType)niFile.Reader.ReadInt32(); var vTranslation = new NiFloatKeyframeGroup(length, interpolation, niFile.Reader); var animationCurves = vTranslation.GetAnimationCurves(); clip.SetCurve(string.Empty, typeof(Renderer), "material._MainTex_ST.w", animationCurves[0]); } // U Tiling length = niFile.Reader.ReadInt32(); if (length > 0) { var interpolation = (KeyType)niFile.Reader.ReadInt32(); var uTiling = new NiFloatKeyframeGroup(length, interpolation, niFile.Reader); var animationCurves = uTiling.GetAnimationCurves(); clip.SetCurve(string.Empty, typeof(Renderer), "material._MainTex_ST.x", animationCurves[0]); } else { var curve = new AnimationCurve(); curve.AddKey(0, 1); curve.AddKey(clip.length, 1); clip.SetCurve(string.Empty, typeof(Renderer), "material._MainTex_ST.x", curve); } // V Tiling length = niFile.Reader.ReadInt32(); if (length > 0) { var interpolation = (KeyType)niFile.Reader.ReadInt32(); var vTiling = new NiFloatKeyframeGroup(length, interpolation, niFile.Reader); var animationCurves = vTiling.GetAnimationCurves(); clip.SetCurve(string.Empty, typeof(Renderer), "material._MainTex_ST.y", animationCurves[0]); } else { var curve = new AnimationCurve(); curve.AddKey(0, 1); curve.AddKey(clip.length, 1); clip.SetCurve(string.Empty, typeof(Renderer), "material._MainTex_ST.y", curve); } }