public void EnsureQuaternionListContinuity() { float[] array = Enumerable.Repeat <float>(0f, bones.Length).ToArray <float>(); float[] array2 = Enumerable.Repeat <float>(0f, bones.Length).ToArray <float>(); float[] array3 = Enumerable.Repeat <float>(0f, bones.Length).ToArray <float>(); float[] array4 = Enumerable.Repeat <float>(0f, bones.Length).ToArray <float>(); for (int i = 0; i < this.recordedFrames.Count; i++) { ReplayRecordedFrame replayRecordedFrame = this.recordedFrames[i]; for (int j = 0; j < bones.Length; j++) { Quaternion rotation = replayRecordedFrame.transformInfos[j].rotation; float num = rotation.x; float num2 = rotation.y; float num3 = rotation.z; float num4 = rotation.w; if (array[j] * num + array2[j] * num2 + array3[j] * num3 + array4[j] * num4 < 0f) { num = -num; num2 = -num2; num3 = -num3; num4 = -num4; this.recordedFrames[i].transformInfos[j].rotation = new Quaternion(num, num2, num3, num4); } array[j] = num; array2[j] = num2; array3[j] = num3; array4[j] = num4; } } }
public void PrepareReplay() { this.recordedFrames.Clear(); int firstKey = this.replayAnimationFrames.FindIndex(f => f.key); this.replayAnimationFrames.RemoveRange(0, firstKey); MultiplayerFrameBufferObject firstRealTime, lastRealTime; firstRealTime = this.replayAnimationFrames.Find(f => f.realFrameTime != -1f); lastRealTime = this.replayAnimationFrames.Last(f => f.realFrameTime != -1f); if (firstRealTime == lastRealTime) { return; } float averageFrameTime = (lastRealTime.animFrame - firstRealTime.animFrame) / (lastRealTime.realFrameTime - firstRealTime.realFrameTime); ReplayRecordedFrame previousFrame = null; for (int f = 0; f < this.replayAnimationFrames.Count; f++) { MultiplayerFrameBufferObject frame = this.replayAnimationFrames[f]; if (f == 0) { MultiplayerFrameBufferObject firstFrameWithTime = this.replayAnimationFrames.First(obj => obj.realFrameTime != -1f); frame.realFrameTime = firstFrameWithTime.realFrameTime + (frame.animFrame - firstFrameWithTime.animFrame) * averageFrameTime; } //if(f > 0 && !frame.key && this.replayAnimationFrames[f - 1].animFrame != frame.animFrame - 1) { // continue; //} TransformInfo[] transforms = null; if (previousFrame != null && !frame.key) { Vector3[] vectors = new Vector3[frame.vectors.Length]; Quaternion[] quaternions = new Quaternion[frame.vectors.Length]; for (int i = 0; i < frame.vectors.Length; i++) { vectors[i] = previousFrame.transformInfos[i].position + frame.vectors[i]; quaternions[i].eulerAngles = previousFrame.transformInfos[i].rotation.eulerAngles + frame.quaternions[i].eulerAngles; } transforms = CreateInfoArray(vectors, quaternions); } if (frame.key) { transforms = BufferToInfo(frame); } if (frame.realFrameTime == -1f && f > 0) { frame.realFrameTime = this.replayAnimationFrames[f - 1].realFrameTime + (frame.animFrame - this.replayAnimationFrames[f - 1].animFrame) * (1f / 30f); } if (transforms != null) { this.recordedFrames.Add(new ReplayRecordedFrame(transforms, frame.realFrameTime)); previousFrame = this.recordedFrames.Last(); } } this.replayController.enabled = true; this.recordedFrames = this.recordedFrames.OrderBy(f => f.time).ToList(); this.EnsureQuaternionListContinuity(); Traverse.Create(this.replayController).Property("ClipFrames").SetValue((from f in this.recordedFrames select f.Copy()).ToList()); Traverse.Create(this.replayController).Field("m_audioEventPlayers").SetValue(new List <ReplayAudioEventPlayer>()); { // Subtract Start Time float firstFrameGameTime = ReplayRecorder.Instance.RecordedFrames[0].time; this.replayController.ClipFrames.ForEach(delegate(ReplayRecordedFrame f) { f.time -= firstFrameGameTime; }); UnityModManagerNet.UnityModManager.Logger.Log(this.replayController.ClipFrames[0].time + " " + ReplayEditorController.Instance.playbackController.ClipFrames[0].time + " " + firstFrameGameTime); this.replayController.ClipEndTime = this.replayController.ClipFrames[this.replayController.ClipFrames.Count - 1].time; } this.replayController.StartCoroutine("UpdateAnimationClip"); this.usernameObject.GetComponent <Renderer>().enabled = false; }
public void PrepareReplay() { this.recordedFrames.Clear(); this.replayAnimationFrames = this.replayAnimationFrames.OrderBy(f => f.animFrame).ToList().ToList(); if (replayAnimationFrames == null || replayAnimationFrames.Count == 0) { return; } int firstKey = this.replayAnimationFrames.FindIndex(f => f.key); if (firstKey < 0) { return; } this.replayAnimationFrames.RemoveRange(0, firstKey); MultiplayerFrameBufferObject firstRealTime, lastRealTime; firstRealTime = this.replayAnimationFrames.Find(f => f.realFrameTime != -1f); lastRealTime = this.replayAnimationFrames.Last(f => f.realFrameTime != -1f); if (firstRealTime == lastRealTime) { return; } float averageFrameTime = (lastRealTime.animFrame - firstRealTime.animFrame) / (lastRealTime.realFrameTime - firstRealTime.realFrameTime); ReplayRecordedFrame previousFrame = null; for (int f = 0; f < this.replayAnimationFrames.Count; f++) { MultiplayerFrameBufferObject frame = this.replayAnimationFrames[f]; if (f == 0) { frame.realFrameTime = firstRealTime.realFrameTime + ((frame.animFrame - firstRealTime.animFrame) * 1f / 30f); } //if(f > 0 && !frame.key && this.replayAnimationFrames[f - 1].animFrame != frame.animFrame - 1) { // continue; //} TransformInfo[] transforms = null; if (previousFrame != null && !frame.key && this.replayAnimationFrames[f - 1].animFrame != frame.animFrame) { if (this.replayAnimationFrames[f - 1].animFrame != frame.animFrame - 1) { MultiplayerFrameBufferObject nextKeyFrame = this.replayAnimationFrames.FirstOrDefault(nK => nK.animFrame > frame.animFrame); int framesToInterpolate = frame.animFrame - this.replayAnimationFrames[f - 1].animFrame; if (nextKeyFrame != null && nextKeyFrame.realFrameTime != -1f) { int frameDiff = frame.animFrame - nextKeyFrame.animFrame; for (int i = 1; i < framesToInterpolate; i++) { Vector3[] interpolatedVectors = new Vector3[frame.vectors.Length]; Quaternion[] interpolatedQuaternions = new Quaternion[frame.vectors.Length]; for (int c = 0; c < frame.vectors.Length; c++) { interpolatedVectors[c] = Vector3.Lerp(this.replayAnimationFrames[f - 1].vectors[c], nextKeyFrame.vectors[c], c / frameDiff); interpolatedQuaternions[c] = Quaternion.Slerp(this.replayAnimationFrames[f - 1].quaternions[c], nextKeyFrame.quaternions[c], c / frameDiff); } float frameTime = this.replayAnimationFrames[f - 1].realFrameTime + (i / frameDiff) * (nextKeyFrame.frameTime - this.replayAnimationFrames[f - 1].realFrameTime); this.recordedFrames.Add(new ReplayRecordedFrame(CreateInfoArray(interpolatedVectors, interpolatedQuaternions), frameTime)); previousFrame = this.recordedFrames.Last(); } } } Vector3[] vectors = new Vector3[frame.vectors.Length]; Quaternion[] quaternions = new Quaternion[frame.vectors.Length]; for (int i = 0; i < frame.vectors.Length; i++) { vectors[i] = previousFrame.transformInfos[i].position + frame.vectors[i]; quaternions[i].eulerAngles = previousFrame.transformInfos[i].rotation.eulerAngles + frame.quaternions[i].eulerAngles; } transforms = CreateInfoArray(vectors, quaternions); } else if (frame.key && (f != 0 && frame.animFrame != this.replayAnimationFrames[f - 1].animFrame)) { transforms = BufferToInfo(frame); } if (frame.realFrameTime == -1f && f > 0) { frame.realFrameTime = this.replayAnimationFrames[f - 1].realFrameTime + (frame.animFrame - this.replayAnimationFrames[f - 1].animFrame) * (1f / 30f); } if (transforms != null && frame.realFrameTime != -1f) { this.recordedFrames.Add(new ReplayRecordedFrame(transforms, frame.realFrameTime)); previousFrame = this.recordedFrames.Last(); } } Traverse.Create(replayController).Property("gameplayEvents").SetValue(new List <GPEvent>()); FinalizeReplay(true); }
public void PrepareReplay() { this.recordedFrames.Clear(); this.replayAnimationFrames = this.replayAnimationFrames.OrderBy(f => f.animFrame).ToList(); if (replayAnimationFrames == null || replayAnimationFrames.Count == 0) { return; } int firstKey = this.replayAnimationFrames.FindIndex(f => f.key); if (firstKey < 0) { return; } this.replayAnimationFrames.RemoveRange(0, firstKey); MultiplayerFrameBufferObject firstRealTime, lastRealTime; firstRealTime = this.replayAnimationFrames.Find(f => f.realFrameTime != -1f); lastRealTime = this.replayAnimationFrames.Last(f => f.realFrameTime != -1f); if (firstRealTime == lastRealTime) { return; } float averageFrameTime = (lastRealTime.animFrame - firstRealTime.animFrame) / (lastRealTime.realFrameTime - firstRealTime.realFrameTime); ReplayRecordedFrame previousFrame = null; for (int f = 0; f < this.replayAnimationFrames.Count; f++) { MultiplayerFrameBufferObject frame = this.replayAnimationFrames[f]; if (f == 0) { frame.realFrameTime = firstRealTime.realFrameTime + ((frame.animFrame - firstRealTime.animFrame) * 1f / 30f); } //if(f > 0 && !frame.key && this.replayAnimationFrames[f - 1].animFrame != frame.animFrame - 1) { // continue; //} TransformInfo[] transforms = null; if (previousFrame != null && !frame.key) { Vector3[] vectors = new Vector3[frame.vectors.Length]; Quaternion[] quaternions = new Quaternion[frame.vectors.Length]; for (int i = 0; i < frame.vectors.Length; i++) { vectors[i] = previousFrame.transformInfos[i].position + frame.vectors[i]; quaternions[i].eulerAngles = previousFrame.transformInfos[i].rotation.eulerAngles + frame.quaternions[i].eulerAngles; } transforms = CreateInfoArray(vectors, quaternions); } else if (frame.key) { transforms = BufferToInfo(frame); } if (frame.realFrameTime == -1f && f > 0) { frame.realFrameTime = this.replayAnimationFrames[f - 1].realFrameTime + (frame.animFrame - this.replayAnimationFrames[f - 1].animFrame) * (1f / 30f); } if (transforms != null) { this.recordedFrames.Add(new ReplayRecordedFrame(transforms, frame.realFrameTime)); previousFrame = this.recordedFrames.Last(); } } FinalizeReplay(); }