private void bakeCurveSet(TargetCurveSet curveSet, float length, int bakingFramerate, ref float[] times, ref Vector3[] positions, ref Vector4[] rotations, ref Vector3[] scales) { int nbSamples = (int)(length * 30); float deltaTime = length / nbSamples; // Initialize Arrays times = new float[nbSamples]; positions = new Vector3[nbSamples]; scales = new Vector3[nbSamples]; rotations = new Vector4[nbSamples]; // Assuming all the curves exist now for (int i = 0; i < nbSamples; ++i) { float currentTime = i * deltaTime; times[i] = currentTime; positions[i] = new Vector3(curveSet.translationCurves[0].Evaluate(currentTime), curveSet.translationCurves[1].Evaluate(currentTime), curveSet.translationCurves[2].Evaluate(currentTime)); scales[i] = new Vector3(curveSet.scaleCurves[0].Evaluate(currentTime), curveSet.scaleCurves[1].Evaluate(currentTime), curveSet.scaleCurves[2].Evaluate(currentTime)); if (curveSet.rotationType == ROTATION_TYPE.EULER) { Quaternion eulerToQuat = Quaternion.Euler(curveSet.rotationCurves[0].Evaluate(currentTime), curveSet.rotationCurves[1].Evaluate(currentTime), curveSet.rotationCurves[2].Evaluate(currentTime)); rotations[i] = new Vector4(eulerToQuat.x, eulerToQuat.y, eulerToQuat.z, eulerToQuat.w); } else { rotations[i] = new Vector4(curveSet.rotationCurves[0].Evaluate(currentTime), curveSet.rotationCurves[1].Evaluate(currentTime), curveSet.rotationCurves[2].Evaluate(currentTime), curveSet.rotationCurves[3].Evaluate(currentTime)); } } }
private void generateMissingCurves(float endTime, ref Transform tr, ref Dictionary <string, TargetCurveSet> targetCurvesBinding) { foreach (string target in targetCurvesBinding.Keys) { Transform targetTr = target.Length > 0 ? tr.Find(target): tr; if (targetTr == null) { continue; } TargetCurveSet current = targetCurvesBinding[target]; if (current.translationCurves[0] == null) { current.translationCurves[0] = createConstantCurve(targetTr.localPosition.x, endTime); current.translationCurves[1] = createConstantCurve(targetTr.localPosition.y, endTime); current.translationCurves[2] = createConstantCurve(targetTr.localPosition.z, endTime); } if (current.scaleCurves[0] == null) { current.scaleCurves[0] = createConstantCurve(targetTr.localScale.x, endTime); current.scaleCurves[1] = createConstantCurve(targetTr.localScale.y, endTime); current.scaleCurves[2] = createConstantCurve(targetTr.localScale.z, endTime); } if (current.rotationCurves[0] == null) { current.rotationCurves[0] = createConstantCurve(targetTr.localRotation.x, endTime); current.rotationCurves[1] = createConstantCurve(targetTr.localRotation.y, endTime); current.rotationCurves[2] = createConstantCurve(targetTr.localRotation.z, endTime); current.rotationCurves[3] = createConstantCurve(targetTr.localRotation.w, endTime); } } }
private void bakeCurveSet(TargetCurveSet curveSet, float length, int bakingFramerate, ref float[] times, ref Vector3[] positions, ref Vector4[] rotations, ref Vector3[] scales) { int nbSamples = (int)(length * 30); float deltaTime = length / nbSamples; // Initialize Arrays times = new float[nbSamples]; positions = new Vector3[nbSamples]; scales = new Vector3[nbSamples]; rotations = new Vector4[nbSamples]; // Assuming all the curves exist now for (int i = 0; i < nbSamples; ++i) { float currentTime = i * deltaTime; times[i] = currentTime; positions[i] = new Vector3(curveSet.translationCurves[0].Evaluate(currentTime), curveSet.translationCurves[1].Evaluate(currentTime), curveSet.translationCurves[2].Evaluate(currentTime)); scales[i] = new Vector3(curveSet.scaleCurves[0].Evaluate(currentTime), curveSet.scaleCurves[1].Evaluate(currentTime), curveSet.scaleCurves[2].Evaluate(currentTime)); rotations[i] = new Vector4(curveSet.rotationCurves[0].Evaluate(currentTime), curveSet.rotationCurves[1].Evaluate(currentTime), curveSet.rotationCurves[2].Evaluate(currentTime), curveSet.rotationCurves[3].Evaluate(currentTime)); } }
private void collectClipCurves(AnimationClip clip, ref Dictionary <string, TargetCurveSet> targetCurves) { foreach (var binding in AnimationUtility.GetCurveBindings(clip)) { AnimationCurve curve = AnimationUtility.GetEditorCurve(clip, binding); if (!targetCurves.ContainsKey(binding.path)) { TargetCurveSet curveSet = new TargetCurveSet(); curveSet.Init(); targetCurves.Add(binding.path, curveSet); } TargetCurveSet current = targetCurves[binding.path]; if (binding.propertyName.Contains("m_LocalPosition")) { if (binding.propertyName.Contains(".x")) { current.translationCurves[0] = curve; } else if (binding.propertyName.Contains(".y")) { current.translationCurves[1] = curve; } else if (binding.propertyName.Contains(".z")) { current.translationCurves[2] = curve; } } else if (binding.propertyName.Contains("m_LocalScale")) { if (binding.propertyName.Contains(".x")) { current.scaleCurves[0] = curve; } else if (binding.propertyName.Contains(".y")) { current.scaleCurves[1] = curve; } else if (binding.propertyName.Contains(".z")) { current.scaleCurves[2] = curve; } } else if (binding.propertyName.ToLower().Contains("localrotation")) { current.rotationType = ROTATION_TYPE.QUATERNION; if (binding.propertyName.Contains(".x")) { current.rotationCurves[0] = curve; } else if (binding.propertyName.Contains(".y")) { current.rotationCurves[1] = curve; } else if (binding.propertyName.Contains(".z")) { current.rotationCurves[2] = curve; } else if (binding.propertyName.Contains(".w")) { current.rotationCurves[3] = curve; } } // Takes into account 'localEuler', 'localEulerAnglesBaked' and 'localEulerAnglesRaw' else if (binding.propertyName.ToLower().Contains("localeuler")) { current.rotationType = ROTATION_TYPE.EULER; if (binding.propertyName.Contains(".x")) { current.rotationCurves[0] = curve; } else if (binding.propertyName.Contains(".y")) { current.rotationCurves[1] = curve; } else if (binding.propertyName.Contains(".z")) { current.rotationCurves[2] = curve; } } targetCurves[binding.path] = current; } }
private void collectClipCurves(AnimationClip clip, ref Dictionary <string, TargetCurveSet> targetCurves) { foreach (var binding in AnimationUtility.GetCurveBindings(clip)) { AnimationCurve curve = AnimationUtility.GetEditorCurve(clip, binding); if (!targetCurves.ContainsKey(binding.path)) { TargetCurveSet curveSet = new TargetCurveSet(); curveSet.Init(); targetCurves.Add(binding.path, curveSet); } TargetCurveSet current = targetCurves[binding.path]; if (binding.propertyName.Contains("m_LocalPosition")) { if (binding.propertyName.Contains(".x")) { current.translationCurves[0] = curve; } else if (binding.propertyName.Contains(".y")) { current.translationCurves[1] = curve; } else if (binding.propertyName.Contains(".z")) { current.translationCurves[2] = curve; } } else if (binding.propertyName.Contains("m_LocalScale")) { if (binding.propertyName.Contains(".x")) { current.scaleCurves[0] = curve; } else if (binding.propertyName.Contains(".y")) { current.scaleCurves[1] = curve; } else if (binding.propertyName.Contains(".z")) { current.scaleCurves[2] = curve; } } else if (binding.propertyName.Contains("m_LocalRotation")) { if (binding.propertyName.Contains(".x")) { current.rotationCurves[0] = curve; } else if (binding.propertyName.Contains(".y")) { current.rotationCurves[1] = curve; } else if (binding.propertyName.Contains(".z")) { current.rotationCurves[2] = curve; } else if (binding.propertyName.Contains(".w")) { current.rotationCurves[3] = curve; } } } }