public void SampleByTime(float t, out Vector3 pos, out Quaternion q, out Vector3 s) { int left = 0, right = 0; pos = Vector3.zero; q = Quaternion.identity; s = Vector3.one; GOECurveFindIndexResults b = FindIndexByTime(t, out left, out right); if (b > GOECurveFindIndexResults.FailedNoKeyFrame) { GOECurvKeyFrame l = keyFrames[left]; GOECurvKeyFrame r = keyFrames[right]; GOECurvInterpolationType interpMode = l.PositionInterpolationType; pos = SampleKeyByTime(t, l, r, interpMode, l.Position, r.Position); interpMode = l.RotationInterpolationType; if (interpMode == GOECurvInterpolationType.Const || left == right) { q = l.Rotation; } else if (interpMode == GOECurvInterpolationType.Linear) { Quaternion ql, qr; ql = l.Rotation; qr = r.Rotation; q = Quaternion.Slerp(ql, qr, (t - l.Time) / (r.Time - l.Time)); } interpMode = l.ScaleInterpolationType; s = SampleKeyByTime(t, l, r, interpMode, l.Scale, r.Scale); } }
public void SampleByIndex3(int idx, ref Vector3 pos, ref Quaternion q, ref Vector3 s, ref GOECurvInterpolationType posInterpMode, ref GOECurvInterpolationType rotInterpMode, ref GOECurvInterpolationType scaleInterpMode, ref Vector3 posInTangent, ref Vector3 posOutTangent, ref Vector3 scaleInTangent, ref Vector3 scaleOutTangent) { SampleByIndex2(idx, ref pos, ref q, ref s, ref posInterpMode, ref rotInterpMode, ref scaleInterpMode); /*posInterpMode.x = posx.keys[idx].tangentMode; * posInterpMode.y = posy.keys[idx].tangentMode; * posInterpMode.z = posz.keys[idx].tangentMode; * rotInterpMode = rotx.keys[idx].tangentMode; * scaleInterpMode.x = scalex.keys[idx].tangentMode; * scaleInterpMode.y = scaley.keys[idx].tangentMode; * scaleInterpMode.z = scalez.keys[idx].tangentMode; * rotType = rottype.keys[idx].value; * posInTangent.x = posx.keys[idx].inTangent; * posInTangent.y = posy.keys[idx].inTangent; * posInTangent.z = posz.keys[idx].inTangent; * posOutTangent.x = posx.keys[idx].outTangent; * posOutTangent.y = posy.keys[idx].outTangent; * posOutTangent.z = posz.keys[idx].outTangent; * scaleInTangent.x = scalex.keys[idx].inTangent; * scaleInTangent.y = scaley.keys[idx].inTangent; * scaleInTangent.z = scalez.keys[idx].inTangent; * scaleOutTangent.x = scalex.keys[idx].outTangent; * scaleOutTangent.y = scaley.keys[idx].outTangent; * scaleOutTangent.z = scalez.keys[idx].outTangent;*/ }
public void SampleByIndex2(int idx, ref Vector3 pos, ref Quaternion q, ref Vector3 s, ref GOECurvInterpolationType posInterpMode, ref GOECurvInterpolationType rotInterpMode, ref GOECurvInterpolationType scaleInterpMode) { SampleByIndex(idx, ref pos, ref q, ref s); GOECurvKeyFrame frame = keyFrames[idx]; posInterpMode = frame.PositionInterpolationType; rotInterpMode = frame.RotationInterpolationType; scaleInterpMode = frame.ScaleInterpolationType; }
Vector3 SampleKeyByTime(float t, GOECurvKeyFrame left, GOECurvKeyFrame right, GOECurvInterpolationType interpMode, Vector3 val, Vector3 val2) { if (interpMode == GOECurvInterpolationType.Const || left.Time == right.Time) { return(val); } else if (interpMode == GOECurvInterpolationType.Linear) { float durance = right.Time - left.Time; if (0 == durance) { return(val); } else { float factor = (t - left.Time) / durance; return(val * (1 - factor) + val2 * factor); } } else if (interpMode == GOECurvInterpolationType.Bezier) { float x = SampleBezierByTime(t, left, right, val.x, val2.x); float y = SampleBezierByTime(t, left, right, val.y, val2.y); float z = SampleBezierByTime(t, left, right, val.z, val2.z); } return(val); }
public void AddKey(float time, ref Vector3 vp, ref Quaternion vr, ref Vector3 vs, GOECurvInterpolationType pt = GOECurvInterpolationType.Linear, GOECurvInterpolationType rt = GOECurvInterpolationType.Linear, GOECurvInterpolationType st = GOECurvInterpolationType.Linear) { GOECurvKeyFrame kf = new GOECurvKeyFrame(); kf.Time = time; kf.Position = vp; kf.Rotation = vr; kf.Scale = vs; kf.PositionInterpolationType = pt; kf.RotationInterpolationType = rt; kf.ScaleInterpolationType = st; int left, right; GOECurveFindIndexResults b = FindIndexByTime(time, out left, out right); if (b == GOECurveFindIndexResults.AfterAllKeyFrame || b == GOECurveFindIndexResults.FailedNoKeyFrame) { keyFrames.Add(kf); } else if (b == GOECurveFindIndexResults.BeforeAllKeyFrame) { KeyFrames.Insert(0, kf); } else { keyFrames.Insert(left + 1, kf); } if (EditorGameObject) { kf.EnsureEditorGO(EditorGameObject); UnityEditor.Selection.activeGameObject = kf.EditorGameObject; } }