public static AnimationClipCurveData[] GetAllCurves(AnimationClip clip, [DefaultValue("true")] bool includeCurveData) { EditorCurveBinding[] curveBindings = AnimationUtility.GetCurveBindings(clip); AnimationClipCurveData[] array = new AnimationClipCurveData[curveBindings.Length]; for (int i = 0; i < array.Length; i++) { array[i] = new AnimationClipCurveData(curveBindings[i]); if (includeCurveData) { array[i].curve = AnimationUtility.GetEditorCurve(clip, curveBindings[i]); } } return(array); }
public static AnimationClipCurveData[] GetAllCurves(AnimationClip clip, [DefaultValue("true")] bool includeCurveData) { EditorCurveBinding[] curveBindings = GetCurveBindings(clip); AnimationClipCurveData[] dataArray = new AnimationClipCurveData[curveBindings.Length]; for (int i = 0; i < dataArray.Length; i++) { dataArray[i] = new AnimationClipCurveData(curveBindings[i]); if (includeCurveData) { dataArray[i].curve = GetEditorCurve(clip, curveBindings[i]); } } return dataArray; }
public static AnimationClipCurveData[] GetAllCurves(AnimationClip clip, [DefaultValue("true")] bool includeCurveData) { EditorCurveBinding[] bindings = GetCurveBindings(clip); AnimationClipCurveData[] curves = new AnimationClipCurveData[bindings.Length]; for (int i = 0; i < curves.Length; i++) { curves[i] = new AnimationClipCurveData(bindings[i]); if (includeCurveData) { curves[i].curve = GetEditorCurve(clip, bindings[i]); } } return(curves); }
public void AddCurveData(AnimationClipCurveData pData) { _needsPostprocess = true; var targetPropertyBits = pData.propertyName.Split('.'); var target = targetPropertyBits[0]; int componentIdx = "xyzw".IndexOf(targetPropertyBits[1][0]); //var skeleton = _clip.Animation.Skeleton; //skeleton. // Figure out what this curve targets in terms of Goo data if (target == "m_LocalPosition") { for (int i = 0; i < _clip.KeyframeCount; ++i) { _translationKeyframes[i][componentIdx] = pData.curve.Evaluate(_clip.GetTimeAtKeyframe(i)); } } else if (target == "m_LocalRotation") { for (int i = 0; i < _clip.KeyframeCount; ++i) { _rotationKeyframes[i][componentIdx] = pData.curve.Evaluate(_clip.GetTimeAtKeyframe(i)); } } else if (target == "m_LocalScale") { for (int i = 0; i < _clip.KeyframeCount; ++i) { _scaleKeyframes[i][componentIdx] = pData.curve.Evaluate(_clip.GetTimeAtKeyframe(i)); } } else { Debug.LogError("Curve describes a property we don't understand: " + target); } }
void CheckCurvePathNameCountEqualToBipGameObjectCountAndKeyInfo(string aniname, List<GameObject> bipGameObject, List<string> pathName, AnimationClipCurveData[] animationClipCurveDatas, float cliplength) { List<string> bipNameList = new List<string>(); Dictionary<string, problemBonesInfo> problemBones = new Dictionary<string, problemBonesInfo>(); List<string> ProblemBipNameList_FirstKey = new List<string>(); List<string> ProblemBipNameList_LastKey = new List<string>(); List<string> ProblemBipNameList_WithoutKey = new List<string>(); string bonenames = ""; problemBones.Add(aniname, new problemBonesInfo()); foreach (var a in bipGameObject) { bipNameList.Add(a.name); } foreach (var p in pathName) { if (p != "Bip01") { int index = p.LastIndexOf('/'); index += 1; string s = p.Substring(index, p.Length - index); if (bipNameList.Contains(s)) { bipNameList.Remove(s); } } else { if (bipNameList.Contains(p)) { bipNameList.Remove(p); } } } foreach (var a in animationClipCurveDatas) { if (a.curve.keys[0].time != 0) { if (a.path == "Bip01") { string splitStr = " " + a.path + "; "; if (!ProblemBipNameList_FirstKey.Contains(splitStr)) { ProblemBipNameList_FirstKey.Add(splitStr); } } else { int index = a.path.LastIndexOf('/'); index += 1; string s = a.path.Substring(index, a.path.Length - index); string splitStr = " " + s + "; "; if (!ProblemBipNameList_FirstKey.Contains(splitStr)) { ProblemBipNameList_FirstKey.Add(splitStr); } } } if ((cliplength - a.curve.keys[a.curve.length - 1].time) > 0.01f) { if (a.path == "Bip01") { string splitStr = " " + a.path + "; "; if (!ProblemBipNameList_LastKey.Contains(splitStr)) { ProblemBipNameList_LastKey.Add(splitStr); } } else { int index = a.path.LastIndexOf('/'); index += 1; string s = a.path.Substring(index, a.path.Length - index); string splitStr = " " + s + "; "; if (!ProblemBipNameList_LastKey.Contains(splitStr)) { ProblemBipNameList_LastKey.Add(splitStr); } } } } foreach (var p in bipNameList) { bonenames = " " + p + " ; "; if (!ProblemBipNameList_WithoutKey.Contains(bonenames)) { ProblemBipNameList_WithoutKey.Add(bonenames); } } if (localAniName == "") { localAniName = aniname; } else { if (localAniName != aniname) { int index_first=0; int index_last=0; int index_without=0; foreach (var a in ProblemBipNameList_FirstKey) { index_first+=1; if (index_first == 3) { problemBones[aniname].problemBonesAtKeyOne += a + "\r\n"; problemBones[aniname].ProblemName_FirstKey = " Doesn't have first key"; index_first=0; } else { problemBones[aniname].problemBonesAtKeyOne += a ; problemBones[aniname].ProblemName_FirstKey = " Doesn't have first key"; } } foreach (var a in ProblemBipNameList_LastKey) { index_last += 1; if (index_last == 3) { problemBones[aniname].problemBonesAtLastKey += a+"\r\n"; problemBones[aniname].ProblemName_LastKey = " Doesn't have last key"; index_last = 0; } else { problemBones[aniname].problemBonesAtLastKey += a; problemBones[aniname].ProblemName_LastKey = " Doesn't have last key"; } } foreach (var a in ProblemBipNameList_WithoutKey) { index_without += 1; if (index_without == 3) { problemBones[aniname].problemBonesWithNoKey += a+"\r\n"; problemBones[aniname].ProblemName_withOutKey = " Doesn't have keys"; index_without = 0; } else { problemBones[aniname].problemBonesWithNoKey += a; problemBones[aniname].ProblemName_withOutKey = " Doesn't have keys"; } } PrintProblemDictionary(problemBones); scoll_y += 5; localAniName = aniname; } } }
protected void marshalRotation( int node_id, AnimationClipCurveData[] curve_datas ) { AnimationCurve qx = null, qy = null, qz = null, qw = null; foreach ( AnimationClipCurveData curve_data in curve_datas ) { if( curve_data.propertyName == "m_LocalRotation.x" ) qx = curve_data.curve; else if( curve_data.propertyName == "m_LocalRotation.y" ) qy = curve_data.curve; else if( curve_data.propertyName == "m_LocalRotation.z" ) qz = curve_data.curve; else if( curve_data.propertyName == "m_LocalRotation.w" ) qw = curve_data.curve; if ( qx != null && qy != null && qz != null && qw != null ) break; } if ( qx != null && qy != null && qz != null && qw != null ) { AnimationCurve rx = new AnimationCurve(); AnimationCurve ry = new AnimationCurve(); AnimationCurve rz = new AnimationCurve(); for ( int ii = 0; ii < qx.length; ii++ ) { Keyframe key_qx = qx.keys[ ii ]; Keyframe key_qy = qy.keys[ ii ]; Keyframe key_qz = qz.keys[ ii ]; Keyframe key_qw = qw.keys[ ii ]; Quaternion quat = new Quaternion( key_qx.value, key_qy.value, key_qz.value, key_qw.value ); Vector3 eulerAngle = quat.eulerAngles; HoudiniAssetUtility.addKeyToCurve( key_qx.time, eulerAngle.x, rx ); HoudiniAssetUtility.addKeyToCurve( key_qx.time, -eulerAngle.y, ry ); HoudiniAssetUtility.addKeyToCurve( key_qx.time, -eulerAngle.z, rz ); } marshalAnimCurve( node_id, rx, HAPI_TransformComponent.HAPI_TRANSFORM_RX ); marshalAnimCurve( node_id, ry, HAPI_TransformComponent.HAPI_TRANSFORM_RY ); marshalAnimCurve( node_id, rz, HAPI_TransformComponent.HAPI_TRANSFORM_RZ ); } }
void OutputAnimationClip(AnimationClipCurveData curveData) { Debug.Log(curveData.path); Debug.Log(curveData.propertyName); AnimationCurve curve = curveData.curve; Keyframe[] keys = curve.keys; Debug.Log(keys.Length); Keyframe k = keys[0]; Debug.Log(k.tangentMode); }
public void Populate (AnimationClipCurveData curveData) { string propName = curveData.propertyName; if (times == null) // allocate one array of times, assumes all channels have same number of keys { timeAccessor = new GlTF_Accessor(name+"TimeAccessor", "SCALAR", "FLOAT"); timeAccessor.bufferView = GlTF_Writer.floatBufferView; GlTF_Writer.accessors.Add (timeAccessor); times = new float[curveData.curve.keys.Length]; for (int i = 0; i < curveData.curve.keys.Length; i++) times[i] = curveData.curve.keys[i].time; timeAccessor.Populate (times); } if (propName.Contains("m_LocalPosition")) { if (positions == null) { translationAccessor = new GlTF_Accessor(name+"TranslationAccessor", "VEC3", "FLOAT"); translationAccessor.bufferView = GlTF_Writer.vec3BufferView; GlTF_Writer.accessors.Add (translationAccessor); positions = new Vector3[curveData.curve.keys.Length]; } if (propName.Contains (".x")) { px = true; for (int i = 0; i < curveData.curve.keys.Length; i++) positions[i].x = curveData.curve.keys[i].value; } else if (propName.Contains (".y")) { py = true; for (int i = 0; i < curveData.curve.keys.Length; i++) positions[i].y = curveData.curve.keys[i].value; } else if (propName.Contains (".z")) { pz = true; for (int i = 0; i < curveData.curve.keys.Length; i++) positions[i].z = curveData.curve.keys[i].value; } if (px && py && pz) translationAccessor.Populate (positions); } if (propName.Contains("m_LocalScale")) { if (scales == null) { scaleAccessor = new GlTF_Accessor(name+"ScaleAccessor", "VEC3", "FLOAT"); scaleAccessor.bufferView = GlTF_Writer.vec3BufferView; GlTF_Writer.accessors.Add (scaleAccessor); scales = new Vector3[curveData.curve.keys.Length]; } if (propName.Contains (".x")) { sx = true; for (int i = 0; i < curveData.curve.keys.Length; i++) scales[i].x = curveData.curve.keys[i].value; } else if (propName.Contains (".y")) { sy = true; for (int i = 0; i < curveData.curve.keys.Length; i++) scales[i].y = curveData.curve.keys[i].value; } else if (propName.Contains (".z")) { sz = true; for (int i = 0; i < curveData.curve.keys.Length; i++) scales[i].z = curveData.curve.keys[i].value; } if (sx && sy && sz) scaleAccessor.Populate (scales); } if (propName.Contains("m_LocalRotation")) { if (rotations == null) { rotationAccessor = new GlTF_Accessor(name+"RotationAccessor", "VEC4", "FLOAT"); rotationAccessor.bufferView = GlTF_Writer.vec4BufferView; GlTF_Writer.accessors.Add (rotationAccessor); rotations = new Vector4[curveData.curve.keys.Length]; } if (propName.Contains (".x")) { rx = true; for (int i = 0; i < curveData.curve.keys.Length; i++) rotations[i].x = curveData.curve.keys[i].value; } else if (propName.Contains (".y")) { ry = true; for (int i = 0; i < curveData.curve.keys.Length; i++) rotations[i].y = curveData.curve.keys[i].value; } else if (propName.Contains (".z")) { rz = true; for (int i = 0; i < curveData.curve.keys.Length; i++) rotations[i].z = curveData.curve.keys[i].value; } else if (propName.Contains (".w")) { rw = true; for (int i = 0; i < curveData.curve.keys.Length; i++) rotations[i].w = curveData.curve.keys[i].value; } if (rx && ry && rz && rw) rotationAccessor.Populate (scales); } }
AnimCurveData ExprotCurve(AnimationClipCurveData data) { AnimCurveData curve = new AnimCurveData(); curve.path = data.path; curve.propertyName = data.propertyName; Keyframe[] keys = data.curve.keys; curve.Alloc(keys.Length); for (int i = 0; i < keys.Length; i++) { curve.inTangent[i] = keys[i].inTangent; curve.outTangent[i] = keys[i].outTangent; curve.tangentMode[i] = keys[i].tangentMode; curve.time[i] = keys[i].time; curve.value[i] = keys[i].value; } return curve; }
void CopyCurvesToDuplicate() { // Edit here FusionInfo[] fusionInfo = { new FusionInfo("MyAnime0.anim", srcFps, 0, 0, dstFps, 0 * speed), new FusionInfo("MyAnime3.anim", srcFps, 0, 0, dstFps, 6 * speed), new FusionInfo("MyAnime5.anim", srcFps, 0, 0, dstFps, 10 * speed), new FusionInfo("MyAnime7.anim", srcFps, 0, 0, dstFps, 14 * speed), new FusionInfo("MyAnime10.anim", srcFps, 0, 0, dstFps, 20 * speed), new FusionInfo("MyAnime12.anim", srcFps, 0, 0, dstFps, 24 * speed), new FusionInfo("MyAnime13.anim", srcFps, 0, 0, dstFps, 26 * speed), new FusionInfo("MyAnime14.anim", srcFps, 0, 0, dstFps, 28 * speed), new FusionInfo("MyAnime15.anim", srcFps, 0, 0, dstFps, 30 * speed), new FusionInfo("MyAnime23.anim", srcFps, 0, 0, dstFps, 46 * speed), new FusionInfo("MyAnime33.anim", srcFps, 0, 0, dstFps, 66 * speed), new FusionInfo("MyAnime40.anim", srcFps, 0, 0, dstFps, 80 * speed), new FusionInfo("MyAnime45.anim", srcFps, 0, 0, dstFps, 90 * speed), new FusionInfo("MyAnime50.anim", srcFps, 0, 0, dstFps, 100 * speed), new FusionInfo("MyAnime55.anim", srcFps, 0, 0, dstFps, 110 * speed), new FusionInfo("MyAnime70.anim", srcFps, 0, 0, dstFps, 140 * speed), new FusionInfo("MyAnime90.anim", srcFps, 0, 0, dstFps, 180 * speed), }; AnimationClipCurveData[][] curveDatasSrc = new AnimationClipCurveData[fusionInfo.Length][]; Debug.Log(assetPathPrefix + fusionInfo[0].anim_src_name); AnimationClip imported0 = (AnimationClip)AssetDatabase.LoadAssetAtPath(assetPathPrefix + fusionInfo[0].anim_src_name, typeof(AnimationClip)); if (imported0 == null) { Debug.Log("Selected object is not an AnimationClip"); return; } AnimationClipCurveData[] curveDatas0 = AnimationUtility.GetAllCurves(imported0, true); AnimationCurve[] curveTmp = new AnimationCurve[curveDatas0.Length]; for (int L = 0; L < fusionInfo.Length; L++) { AnimationClip imported = (AnimationClip)AssetDatabase.LoadAssetAtPath(assetPathPrefix + fusionInfo[L].anim_src_name, typeof(AnimationClip)); if (imported == null) { Debug.Log("Selected object is not an AnimationClip"); return; } curveDatasSrc[L] = AnimationUtility.GetAllCurves(imported, true); for (int i = 0; i < curveDatasSrc[L].Length; i++) { if (L == 0) { curveTmp[i] = new AnimationCurve(); curveTmp[i].preWrapMode = curveDatasSrc[L][i].curve.preWrapMode; curveTmp[i].postWrapMode = curveDatasSrc[L][i].curve.postWrapMode; } Keyframe keyFrameTmp = new Keyframe(); float val_min = float.MaxValue; for (int k = 0; k < curveDatasSrc[L][i].curve.length; k++) { float val_tmp = Mathf.Abs(fusionInfo[L].src_time - curveDatasSrc[L][i].curve.keys[k].time); if (val_tmp < val_min) { keyFrameTmp = new Keyframe(curveDatasSrc[L][i].curve.keys[k].time, curveDatasSrc[L][i].curve.keys[k].value, curveDatasSrc[L][i].curve.keys[k].inTangent, curveDatasSrc[L][i].curve.keys[k].outTangent); val_min = val_tmp; } } keyFrameTmp.time = fusionInfo[L].dst_time; curveTmp[i].AddKey(keyFrameTmp); } } AnimationClip fusionClip = null; string importedPath = AssetDatabase.GetAssetPath(imported0); string fusionPath = assetPathPrefix + outputName; CopyClip(importedPath, fusionPath); fusionClip = AssetDatabase.LoadAssetAtPath(fusionPath, typeof(AnimationClip)) as AnimationClip; if (fusionClip == null) { Debug.Log("No copy found at " + fusionPath); return; } // Output fusion anime { AnimationClip imported2 = (AnimationClip)AssetDatabase.LoadAssetAtPath(assetPathPrefix + fusionInfo[0].anim_src_name, typeof(AnimationClip)); if (imported2 == null) { Debug.Log("Selected object is not an AnimationClip"); return; } AnimationClipCurveData[] curveDatas = AnimationUtility.GetAllCurves(imported2, true); for (int i = 0; i < curveDatas.Length; i++) { AnimationUtility.SetEditorCurve( fusionClip, curveDatas[i].path, curveDatas[i].type, curveDatas[i].propertyName, curveTmp[i] ); } } Debug.Log("Generating fusion animation into " + fusionClip.name + " is done"); }
public static AnimationClipCurveData[] GetAllCurves(AnimationClip clip, [DefaultValue("true")] bool includeCurveData) { EditorCurveBinding[] curveBindings = AnimationUtility.GetCurveBindings(clip); AnimationClipCurveData[] animationClipCurveDataArray = new AnimationClipCurveData[curveBindings.Length]; for (int index = 0; index < animationClipCurveDataArray.Length; ++index) { animationClipCurveDataArray[index] = new AnimationClipCurveData(curveBindings[index]); if (includeCurveData) animationClipCurveDataArray[index].curve = AnimationUtility.GetEditorCurve(clip, curveBindings[index]); } return animationClipCurveDataArray; }
public CurveInformation AddIfNonExistant(List<string> path, AnimationClipCurveData animationCLipCurveData) { if (Name.Equals(path[0])) { if (path.Count == 1) { AnimationClipCurveData = animationCLipCurveData; return this; } var pathReduced = path; pathReduced.RemoveAt(0); foreach (CurveInformation curveInformation in Children) { if (curveInformation.Name.Equals(pathReduced[0])) { CurveInformation childResult = curveInformation.AddIfNonExistant(pathReduced, animationCLipCurveData); if (childResult != null) { return childResult; } } } } CurveInformation newChild = new CurveInformation(path[0]); Children.Add(newChild); if (path.Count == 1) { newChild.AnimationClipCurveData = animationCLipCurveData; return newChild; } else { var pathReduced = path; pathReduced.RemoveAt(0); return newChild.AddIfNonExistant(pathReduced, animationCLipCurveData); } }
private void UpdateCurveInformation(string nameOfClip, CurveInformation curveInformationToUpdate, AnimationClipCurveData animationCruveData) { List<string> curveInformationNames = animationCruveData.path.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries).ToList(); curveInformationNames.Insert(0, nameOfClip); curveInformationNames.Add(animationCruveData.type.ToString()); curveInformationNames.Add(animationCruveData.propertyName); curveInformationToUpdate.AddIfNonExistant(curveInformationNames, animationCruveData); }
private void InsertCurve(AnimationClipCurveData animationClipCurveData) { EditorCurveBinding editorCurveBinding = new EditorCurveBinding(); editorCurveBinding.path = animationClipCurveData.path; editorCurveBinding.propertyName = animationClipCurveData.propertyName; editorCurveBinding.type = animationClipCurveData.type; AnimationUtility.SetEditorCurve(selectedAnimationClip, editorCurveBinding, animationClipCurveData.curve); }
public AnimationProperty (string n, AnimationClipCurveData d) { Property = n; Curve = d.curve; }