private VMDFormat.CameraData ReadCameraData() { VMDFormat.CameraData result = new VMDFormat.CameraData(); result.frame_no = binary_reader_.ReadUInt32(); result.length = binary_reader_.ReadSingle(); result.location = ReadSinglesToVector3(binary_reader_); result.rotation = ReadSinglesToVector3(binary_reader_); result.interpolation = binary_reader_.ReadBytes(24); result.viewing_angle = binary_reader_.ReadUInt32(); result.perspective = binary_reader_.ReadByte(); return(result); }
public AnimationClip CreateCameraAnimationClip(VMDFormat format, GameObject camera_root, int interpolationQuality) { AnimationClip animationClip = new AnimationClip(); if (VMDHSConverter.p_legacy != null) { VMDHSConverter.p_legacy.SetValue(animationClip, true, null); } BoneAdjustment boneAdjustment = this.boneAdjustment["camera"]; if (camera_root.transform.Find("camera") == null) { new GameObject("camera").transform.parent = camera_root.transform; } if (camera_root.transform.Find("length") == null) { new GameObject("length").transform.parent = camera_root.transform; } if (camera_root.transform.Find("view_angle") == null) { new GameObject("view_angle").transform.parent = camera_root.transform; } if (camera_root.transform.Find("perspective") == null) { new GameObject("perspective").transform.parent = camera_root.transform; } List <VMDHSConverter.FloatKeyframe> list = new List <VMDHSConverter.FloatKeyframe>(); List <VMDHSConverter.FloatKeyframe> list2 = new List <VMDHSConverter.FloatKeyframe>(); List <VMDHSConverter.FloatKeyframe> list3 = new List <VMDHSConverter.FloatKeyframe>(); List <VMDHSConverter.FloatLinearKeyframe> list4 = new List <VMDHSConverter.FloatLinearKeyframe>(); List <VMDHSConverter.FloatLinearKeyframe> list5 = new List <VMDHSConverter.FloatLinearKeyframe>(); List <Keyframe> list6 = new List <Keyframe>(); VMDHSConverter.FloatKeyframe prev_keyframe = null; VMDHSConverter.FloatKeyframe prev_keyframe2 = null; VMDHSConverter.FloatKeyframe prev_keyframe3 = null; int num = 0; int num2 = 0; int num3 = 0; int num4 = 0; while ((long)num4 < (long)((ulong)format.camera_list.camera_count)) { VMDFormat.CameraData cameraData = format.camera_list.camera[num4]; float num5 = 0.0333333351f * cameraData.flame_no; Vector3 location = cameraData.location; location.z = -location.z; location.x = -location.x; VMDHSConverter.FloatKeyframe floatKeyframe = new VMDHSConverter.FloatKeyframe(num5, location.x * this.scale.x); VMDHSConverter.FloatKeyframe floatKeyframe2 = new VMDHSConverter.FloatKeyframe(num5, location.y * this.scale.y); VMDHSConverter.FloatKeyframe floatKeyframe3 = new VMDHSConverter.FloatKeyframe(num5, location.z * this.scale.z); VMDHSConverter.FloatLinearKeyframe item = new VMDHSConverter.FloatLinearKeyframe(num5, cameraData.length * this.scale.z); VMDHSConverter.FloatLinearKeyframe item2 = new VMDHSConverter.FloatLinearKeyframe(num5, cameraData.viewing_angle); VMDHSConverter.FloatKeyframe.AddBezierKeyframes(cameraData.interpolation, 0, prev_keyframe, floatKeyframe, interpolationQuality, ref list, ref num); VMDHSConverter.FloatKeyframe.AddBezierKeyframes(cameraData.interpolation, 1, prev_keyframe2, floatKeyframe2, interpolationQuality, ref list2, ref num2); VMDHSConverter.FloatKeyframe.AddBezierKeyframes(cameraData.interpolation, 2, prev_keyframe3, floatKeyframe3, interpolationQuality, ref list3, ref num3); list4.Add(item); list5.Add(item2); prev_keyframe = floatKeyframe; prev_keyframe2 = floatKeyframe2; prev_keyframe3 = floatKeyframe3; Keyframe item3; item3 = new Keyframe(num5, (float)cameraData.perspective); list6.Add(item3); num4++; } if (format.camera_list.camera_count != 0u) { VMDHSConverter.FloatKeyframe[] custom_keys = list.ToArray(); VMDHSConverter.FloatKeyframe[] custom_keys2 = list2.ToArray(); VMDHSConverter.FloatKeyframe[] custom_keys3 = list3.ToArray(); VMDHSConverter.FloatLinearKeyframe[] custom_keys4 = list4.ToArray(); VMDHSConverter.FloatLinearKeyframe[] custom_keys5 = list5.ToArray(); AnimationCurve animationCurve = new AnimationCurve(this.ToKeyframesForLocation(custom_keys)); AnimationCurve animationCurve2 = new AnimationCurve(this.ToKeyframesForLocation(custom_keys2)); AnimationCurve animationCurve3 = new AnimationCurve(this.ToKeyframesForLocation(custom_keys3)); AnimationCurve animationCurve4 = new AnimationCurve(this.ToKeyframesForLocation(custom_keys4)); AnimationCurve animationCurve5 = new AnimationCurve(this.ToKeyframesForLocation(custom_keys5)); Keyframe[] array = list6.ToArray(); this.AddDummyKeyframe(ref array); AnimationCurve animationCurve6 = new AnimationCurve(array); animationClip.SetCurve("camera", typeof(Transform), "localPosition.x", animationCurve); animationClip.SetCurve("camera", typeof(Transform), "localPosition.y", animationCurve2); animationClip.SetCurve("camera", typeof(Transform), "localPosition.z", animationCurve3); animationClip.SetCurve("length", typeof(Transform), "localPosition.z", animationCurve4); animationClip.SetCurve("view_angle", typeof(Transform), "localPosition.z", animationCurve5); animationClip.SetCurve("perspective", typeof(Transform), "localPosition.z", animationCurve6); } List <VMDHSConverter.QuaternionKeyframe> list7 = new List <VMDHSConverter.QuaternionKeyframe>(); Quaternion identity = Quaternion.identity; int num6 = 0; while ((long)num6 < (long)((ulong)format.camera_list.camera_count)) { VMDFormat.CameraData cameraData2 = format.camera_list.camera[num6]; float time = 0.0333333351f * cameraData2.flame_no; Vector3 vector = cameraData2.rotation * 57.29578f; vector.y *= -1f; Quaternion quaternion = Quaternion.Euler(vector); quaternion = boneAdjustment.GetAdjustedRotation(quaternion); VMDHSConverter.QuaternionKeyframe item4 = new VMDHSConverter.QuaternionKeyframe(time, quaternion); list7.Add(item4); num6++; } Keyframe[] array2 = null; Keyframe[] array3 = null; Keyframe[] array4 = null; Dictionary <string, Keyframe[]> dictionary = this.ToKeyframesForRotation(list7.ToArray(), ref array2, ref array3, ref array4, false); AnimationCurve animationCurve7 = new AnimationCurve(dictionary["localRotation.x"]); AnimationCurve animationCurve8 = new AnimationCurve(dictionary["localRotation.y"]); AnimationCurve animationCurve9 = new AnimationCurve(dictionary["localRotation.z"]); AnimationCurve animationCurve10 = new AnimationCurve(dictionary["localRotation.w"]); animationClip.SetCurve("camera", typeof(Transform), "localRotation.x", animationCurve7); animationClip.SetCurve("camera", typeof(Transform), "localRotation.y", animationCurve8); animationClip.SetCurve("camera", typeof(Transform), "localRotation.z", animationCurve9); animationClip.SetCurve("camera", typeof(Transform), "localRotation.w", animationCurve10); return(animationClip); }
private VMDFormat.CameraData ReadCameraData() { VMDFormat.CameraData result = new VMDFormat.CameraData(); result.flame_no = binary_reader_.ReadUInt32(); result.length = binary_reader_.ReadSingle(); result.location = ReadSinglesToVector3(binary_reader_); result.rotation = ReadSinglesToVector3(binary_reader_); result.interpolation = binary_reader_.ReadBytes(24); result.viewing_angle = binary_reader_.ReadUInt32(); result.perspective = binary_reader_.ReadByte(); return result; }