private void ProcessDenses(Clip clip, AnimationClipBindingConstant bindings, IReadOnlyDictionary <uint, string> tos) { DenseClip dense = clip.DenseClip; int streamCount = clip.StreamedClip.CurveCount; float[] slopeValues = new float[4]; // no slopes - 0 values for (int frameIndex = 0; frameIndex < dense.FrameCount; frameIndex++) { float time = frameIndex / dense.SampleRate; int frameOffset = frameIndex * dense.CurveCount; for (int curveIndex = 0; curveIndex < dense.CurveCount;) { int index = streamCount + curveIndex; GenericBinding binding = bindings.FindBinding(index); string path = GetCurvePath(tos, binding.Path); int framePosition = frameOffset + curveIndex; if (binding.IsTransform) { AddTransformCurve(time, binding.TransformType, dense.SampleArray, slopeValues, slopeValues, framePosition, path); curveIndex += binding.TransformType.GetDimension(); } else if (binding.CustomType == BindingCustomType.None) { AddDefaultCurve(binding, path, time, dense.SampleArray[framePosition]); curveIndex++; } else { AddCustomCurve(bindings, binding, path, time, dense.SampleArray[framePosition]); curveIndex++; } } } }
private void AddGameObjectCurve(GenericBinding binding, string path, float time, float value) { if (binding.Attribute == CRC.CalculateDigestAscii(GameObject.IsActiveName)) { FloatCurve curve = new FloatCurve(path, GameObject.IsActiveName, ClassIDType.GameObject, default); AddFloatKeyframe(curve, time, value); return; } throw new Exception($"Unsupported attribute {binding.Attribute} for {nameof(GameObject)}"); }
private void ProcessStreams(IReadOnlyList <StreamedFrame> streamFrames, AnimationClipBindingConstant bindings, IReadOnlyDictionary <uint, string> tos, float sampleRate) { float[] curveValues = new float[4]; float[] inSlopeValues = new float[4]; float[] outSlopeValues = new float[4]; float interval = 1.0f / sampleRate; // first (index [0]) stream frame is for slope calculation for the first real frame (index [1]) // last one (index [count - 1]) is +Infinity // it is made for slope processing, but we don't need them for (int frameIndex = 1; frameIndex < streamFrames.Count - 1; frameIndex++) { StreamedFrame frame = streamFrames[frameIndex]; for (int curveIndex = 0; curveIndex < frame.Curves.Count;) { StreamedCurveKey curve = frame.Curves[curveIndex]; GenericBinding binding = bindings.FindBinding(curve.Index); GetPreviousFrame(streamFrames, curve.Index, frameIndex, out int prevFrameIndex, out int prevCurveIndex); string path = GetCurvePath(tos, binding.Path); if (binding.IsTransform) { int dimension = binding.TransformType.GetDimension(); for (int key = 0; key < dimension; key++) { StreamedCurveKey keyCurve = frame.Curves[curveIndex]; StreamedFrame prevFrame = streamFrames[prevFrameIndex]; StreamedCurveKey prevKeyCurve = prevFrame.Curves[prevCurveIndex + key]; float deltaTime = frame.Time - prevFrame.Time; curveValues[key] = keyCurve.Value; inSlopeValues[key] = prevKeyCurve.CalculateNextInSlope(deltaTime, keyCurve.Value); outSlopeValues[key] = keyCurve.OutSlope; curveIndex = GetNextCurve(frame, curveIndex); } AddTransformCurve(frame.Time, binding.TransformType, curveValues, inSlopeValues, outSlopeValues, 0, path); } else if (binding.CustomType == BindingCustomType.None) { AddDefaultCurve(binding, path, frame.Time, frame.Curves[curveIndex].Value); curveIndex = GetNextCurve(frame, curveIndex); } else { AddCustomCurve(bindings, binding, path, frame.Time, frame.Curves[curveIndex].Value); curveIndex = GetNextCurve(frame, curveIndex); } } } }
private void AddGameObjectCurve(GenericBinding binding, string path, float time, float value) { if (binding.Attribute == CRC.CalculateDigestAscii(GameObject.IsActiveName)) { FloatCurve curve = new FloatCurve(path, GameObject.IsActiveName, ClassIDType.GameObject, default); AddFloatKeyframe(curve, time, value); return; } else { // that means that dev exported animation clip with missed component FloatCurve curve = new FloatCurve(path, MissedPropertyPrefix + binding.Attribute, ClassIDType.GameObject, default); AddFloatKeyframe(curve, time, value); } }
private void AddDefaultCurve(GenericBinding binding, string path, float time, float value) { switch (binding.ClassID) { case ClassIDType.GameObject: { AddGameObjectCurve(binding, path, time, value); } break; case ClassIDType.MonoBehaviour: { AddScriptCurve(binding, path, time, value); } break; default: AddEngineCurve(binding, path, time, value); break; } }
private void AddCustomCurve(AnimationClipBindingConstant bindings, GenericBinding binding, string path, float time, float value) { switch (binding.CustomType) { case BindingCustomType.AnimatorMuscle: AddAnimatorMuscleCurve(binding, path, time, value); break; default: string attribute = m_customCurveResolver.ToAttributeName(binding.CustomType, binding.Attribute, path); if (binding.IsPPtrCurve) { PPtrCurve curve = new PPtrCurve(path, attribute, binding.ClassID, binding.Script.CastTo <MonoScript>()); AddPPtrKeyframe(curve, bindings, time, (int)value); } else { FloatCurve curve = new FloatCurve(path, attribute, binding.ClassID, binding.Script.CastTo <MonoScript>()); AddFloatKeyframe(curve, time, value); } break; } }
public GenericBinding FindBinding(int index) { int curves = 0; for (int i = 0; i < GenericBindings.Count; i++) { GenericBinding gb = GenericBindings[i]; if (gb.ClassID == ClassIDType.Transform) { curves += gb.TransformType.GetDimension(); } else { curves += 1; } if (curves > index) { return(gb); } } throw new ArgumentException($"Binding with index {index} hasn't been found", nameof(index)); }
private void ProcessConstant(Clip clip, AnimationClipBindingConstant bindings, IReadOnlyDictionary <uint, string> tos, float lastFrame) { ConstantClip constant = clip.ConstantClip; int streamCount = clip.StreamedClip.CurveCount; int denseCount = clip.DenseClip.CurveCount; float[] slopeValues = new float[4]; // no slopes - 0 values // only first and last frames float time = 0.0f; for (int i = 0; i < 2; i++, time += lastFrame) { for (int curveIndex = 0; curveIndex < constant.Constants.Count;) { int index = streamCount + denseCount + curveIndex; GenericBinding binding = bindings.FindBinding(index); string path = GetCurvePath(tos, binding.Path); if (binding.IsTransform) { AddTransformCurve(time, binding.TransformType, constant.Constants, slopeValues, slopeValues, curveIndex, path); curveIndex += binding.TransformType.GetDimension(); } else if (binding.CustomType == BindingCustomType.None) { AddDefaultCurve(binding, path, time, constant.Constants[curveIndex]); curveIndex++; } else { AddCustomCurve(bindings, binding, path, time, constant.Constants[curveIndex]); curveIndex++; } } } }
private void AddAnimatorMuscleCurve(GenericBinding binding, string path, float time, float value) { FloatCurve curve = new FloatCurve(string.Empty, binding.GetHumanoidMuscle(Version).ToAttributeString(), ClassIDType.Animator, default); AddFloatKeyframe(curve, time, value); }
private void AddEngineCurve(GenericBinding binding, string path, float time, float value) { #warning TODO: FloatCurve curve = new FloatCurve(path, TypeTreePropertyPrefix + binding.Attribute, binding.ClassID, default); AddFloatKeyframe(curve, time, value); }
private void AddScriptCurve(GenericBinding binding, string path, float time, float value) { #warning TODO: FloatCurve curve = new FloatCurve(path, ScriptPropertyPrefix + binding.Attribute, ClassIDType.MonoBehaviour, binding.Script.CastTo <MonoScript>()); AddFloatKeyframe(curve, time, value); }
private static bool GetGenericBinding(AnimationClipBindingConstant bindings, int index, out GenericBinding binding) { binding = bindings.FindBinding(index); if (binding.ClassID == ClassIDType.Transform) { return(true); } #warning TODO: humanoid return(false); }
public AnimationClipBindingConstant(bool _) { m_genericBindings = new GenericBinding[0]; m_pptrCurveMapping = new PPtr <Object> [0]; }