private void CreateKeysForSkin(VMDFormat format, AnimationClip clip) { this.usedFaceNames = new HashSet <string>(); foreach (KeyValuePair <string, List <VMDFormat.SkinData> > keyValuePair in format.skin_list.skin) { string key = keyValuePair.Key; if (!this.faceNames.Contains(key)) { Console.WriteLine("Face Setting for {0} not found. Ignore this face morph.", key); } else { List <VMDFormat.SkinData> value = keyValuePair.Value; Keyframe[] array = new Keyframe[keyValuePair.Value.Count]; for (int i = 0; i < keyValuePair.Value.Count; i++) { array[i] = new Keyframe(value[i].flame_no * 0.0333333351f, value[i].weight); array[i].tangentMode = 21; if (i > 0) { float linearTangentForPosition = this.GetLinearTangentForPosition(array[i - 1], array[i]); array[i - 1].outTangent = linearTangentForPosition; array[i].inTangent = linearTangentForPosition; } } this.AddDummyKeyframe(ref array); AnimationCurve animationCurve = new AnimationCurve(array); clip.SetCurve(this.faceGoPath + "/" + key, typeof(Transform), "localPosition.z", animationCurve); this.usedFaceNames.Add(key); } } }
private VMDFormat Read() { format_ = new VMDFormat(); EntryPathes(); // 読み込み失敗した場合はだいたいデータがない // 失敗しても読み込み続けることがあるので例外でキャッチして残りはnullにしておく int read_count = 0; try { format_.header = ReadHeader(); read_count++; format_.motion_list = ReadMotionList(); read_count++; format_.skin_list = ReadSkinList(); read_count++; format_.camera_list = ReadCameraList(); read_count++; format_.light_list = ReadLightList(); read_count++; format_.self_shadow_list = ReadSelfShadowList(); read_count++; } catch (EndOfStreamException e) { Debug.Log(e.Message); if (read_count <= 0) format_.header = null; if (read_count <= 1 || format_.motion_list.motion_count <= 0) format_.motion_list = null; if (read_count <= 2 || format_.skin_list.skin_count <= 0) format_.skin_list = null; if (read_count <= 3 || format_.camera_list.camera_count <= 0) format_.camera_list = null; if (read_count <= 4 || format_.light_list.light_count <= 0) format_.light_list = null; if (read_count <= 5 || format_.self_shadow_list.self_shadow_count <= 0) format_.self_shadow_list = null; } return format_; }
public bool SetCameraAnimation(string path) { Dictionary <string, BoneAdjustment> dictionary = new Dictionary <string, BoneAdjustment>(); dictionary.Add("camera", BoneAdjustment.Init("VMDCameraAnim", this.boneAdjustSpec, Vector3.zero, false)); KKVMDPlugin.Logger.Log(BepInEx.Logging.LogLevel.Debug, string.Format("bone adjustment init", path)); if (!File.Exists(path)) { KKVMDPlugin.Logger.Log(BepInEx.Logging.LogLevel.Debug, string.Format("File not found. {0} ", path)); return(false); } this.Stop(); bool result; using (BinaryReader binaryReader = new BinaryReader(File.OpenRead(path))) { VMDFormat format = VMDLoader.Load(binaryReader, path, "VMDCameraAnim"); KKVMDPlugin.Logger.Log(BepInEx.Logging.LogLevel.Debug, string.Format("VMD file loaded {0}:", path)); this._cameraVMDFilePath = path; AnimationClip animationClip = new VMDHSConverter(dictionary, this._scaleBase * this.modelScale).CreateCameraAnimationClip(format, base.gameObject, 4); KKVMDPlugin.Logger.Log(BepInEx.Logging.LogLevel.Debug, string.Format("Converted as an animation clip", animationClip)); KKVMDPlugin.Logger.Log(BepInEx.Logging.LogLevel.Debug, string.Format("Set to animation ", this.cameraAnimation)); animationClip.name = "VMDCameraAnim"; this.cameraAnimation.AddClip(animationClip, "VMDCameraAnim"); this.cameraAnimation.clip = animationClip; AnimationState animationState = this.cameraAnimation["VMDCameraAnim"]; KKVMDPlugin.Logger.Log(BepInEx.Logging.LogLevel.Debug, string.Format("Found animation info {0}", animationState)); animationState.speed = this._speed; animationState.wrapMode = (this._loop ? (WrapMode)2 : (WrapMode)1); result = true; } return(result); }
public static async Task LoadVMD(Coocoo3DMain appBody, StorageFile storageFile, MMD3DEntity entity) { BinaryReader reader = new BinaryReader((await storageFile.OpenReadAsync()).AsStreamForRead()); VMDFormat motionSet = VMDFormat.Load(reader); entity.motionComponent.Reload(motionSet); appBody.RequireRender(true); }
private async void Grid_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e) { Grid grid = sender as Grid; if (grid.DataContext is StorageFolder folder) { viewFolderStack.Add(folder); await SetFolder(); } else if (grid.DataContext is StorageFile file && !HaveLoadTask) { var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView(); if (file.FileType.Equals(".pmx", StringComparison.CurrentCultureIgnoreCase)) { try { await UI.UISharedCode.LoadEntityIntoScene(appBody, appBody.CurrentScene, file, viewFolderStack.Last()); } catch (Exception exception) { MessageDialog dialog = new MessageDialog(string.Format(resourceLoader.GetString("Error_Message_PMXError"), exception)); await dialog.ShowAsync(); } } else if (file.FileType.Equals(".vmd", StringComparison.CurrentCultureIgnoreCase)) { HaveLoadTask = true; try { BinaryReader reader = new BinaryReader((await file.OpenReadAsync()).AsStreamForRead()); VMDFormat motionSet = VMDFormat.Load(reader); lock (appBody.deviceResources) { foreach (var entity in appBody.SelectedEntities) { entity.motionComponent.Reload(motionSet); } } } catch (Exception exception) { MessageDialog dialog = new MessageDialog(string.Format(resourceLoader.GetString("Error_Message_VMDError"), exception)); await dialog.ShowAsync(); HaveLoadTask = false; return; } appBody.GameDriverContext.RequireResetPhysics = true; appBody.RequireRender(true); HaveLoadTask = false; } else if (file.FileType.Equals(".hlsl", StringComparison.CurrentCultureIgnoreCase)) { UI.UISharedCode.LoadShaderForEntities1(appBody, file, viewFolderStack.Last(), new List <Present.MMD3DEntity>(appBody.SelectedEntities)); } } }
private VMDFormat Read() { format_ = new VMDFormat(); EntryPathes(); // 読み込み失敗した場合はだいたいデータがない // 失敗しても読み込み続けることがあるので例外でキャッチして残りはnullにしておく int read_count = 0; try { format_.header = ReadHeader(); read_count++; format_.motion_list = ReadMotionList(); read_count++; format_.skin_list = ReadSkinList(); read_count++; format_.camera_list = ReadCameraList(); read_count++; format_.light_list = ReadLightList(); read_count++; format_.self_shadow_list = ReadSelfShadowList(); read_count++; } catch (EndOfStreamException e) { Debug.Log(e.Message); if (read_count <= 0) { format_.header = null; } if (read_count <= 1 || format_.motion_list.motion_count <= 0) { format_.motion_list = null; } if (read_count <= 2 || format_.skin_list.skin_count <= 0) { format_.skin_list = null; } if (read_count <= 3 || format_.camera_list.camera_count <= 0) { format_.camera_list = null; } if (read_count <= 4 || format_.light_list.light_count <= 0) { format_.light_list = null; } if (read_count <= 5 || format_.self_shadow_list.self_shadow_count <= 0) { format_.self_shadow_list = null; } } return(format_); }
private void FullEntryBoneAnimation(VMDFormat format, AnimationClip clip, Dictionary <string, string> dic, Dictionary <string, GameObject> obj, int interpolationQuality) { foreach (KeyValuePair <string, string> keyValuePair in dic) { GameObject gameObject = null; if (obj.ContainsKey(keyValuePair.Key)) { gameObject = obj[keyValuePair.Key]; Rigidbody component = gameObject.GetComponent <Rigidbody>(); if (component != null && !component.isKinematic) { continue; } } this.CreateKeysForLocation(format, clip, keyValuePair.Key, keyValuePair.Value, interpolationQuality, gameObject); this.CreateKeysForRotation(format, clip, keyValuePair.Key, keyValuePair.Value, interpolationQuality); } }
public AnimationClip CreateAnimationClip(VMDFormat format, GameObject assign_pmd, int interpolationQuality) { AnimationClip animationClip = new AnimationClip(); animationClip.name = format.clip_name; if (VMDHSConverter.p_legacy != null) { VMDHSConverter.p_legacy.SetValue(animationClip, true, null); } Dictionary <string, string> dic = new Dictionary <string, string>(); this.FullSearchBonePath(assign_pmd.transform, assign_pmd.transform, dic); Dictionary <string, GameObject> obj = new Dictionary <string, GameObject>(); this.FullEntryBoneAnimation(format, animationClip, dic, obj, interpolationQuality); this.CreateKeysForSkin(format, animationClip); this.ReadIKModeSettings(format); return(animationClip); }
public void OnFrame() { if (UIImGui.requireOpenFolder.SetFalse()) { string path = OpenResourceFolder(); if (!string.IsNullOrEmpty(path)) { DirectoryInfo folder = new DirectoryInfo(path); UIImGui.viewRequest = folder; caches.AddFolder(folder); } gameDriverContext.RequireRender(false); } if (UIImGui.requestSelectRenderPipelines.SetFalse()) { string path = OpenResourceFolder(); if (!string.IsNullOrEmpty(path)) { DirectoryInfo folder = new DirectoryInfo(path); UIImGui.renderPipelinesRequest = folder; caches.AddFolder(folder); } gameDriverContext.RequireRender(false); } if (UIImGui.viewRequest != null) { var view = UIImGui.viewRequest; UIImGui.viewRequest = null; UIImGui.currentFolder = view; SetViewFolder(view.GetFileSystemInfos()); gameDriverContext.RequireRender(false); } if (UIImGui.openRequest != null) { var file = UIImGui.openRequest; UIImGui.openRequest = null; string ext = file.Extension.ToLower(); switch (ext) { case ".pmx": case ".gltf": LoadEntityIntoScene(file); break; case ".vmd": BinaryReader reader = new BinaryReader(file.OpenRead()); VMDFormat motionSet = VMDFormat.Load(reader); if (motionSet.CameraKeyFrames.Count != 0) { var camera = windowSystem.currentChannel.camera; camera.cameraMotion.cameraKeyFrames = motionSet.CameraKeyFrames; for (int i = 0; i < camera.cameraMotion.cameraKeyFrames.Count; i++) { CameraKeyFrame frame = camera.cameraMotion.cameraKeyFrames[i]; frame.distance *= 0.1f; frame.position *= 0.1f; camera.cameraMotion.cameraKeyFrames[i] = frame; } camera.CameraMotionOn = true; } else { foreach (var gameObject in this.scene.SelectedGameObjects) { var animationState = gameObject.GetComponent <Components.AnimationStateComponent>(); if (animationState != null) { animationState.motionPath = file.FullName; } } gameDriverContext.RequireResetPhysics = true; } break; case ".coocoo3dscene": var scene = ReadJsonStream <Coocoo3DScene>(file.OpenRead()); scene.ToScene(this.scene, caches); gameDriverContext.RequireResetPhysics = true; break; } gameDriverContext.RequireRender(true); } if (UIImGui.requestRecord.SetFalse()) { gameDriverContext.NeedRender = 0; string path = OpenResourceFolder(); if (!string.IsNullOrEmpty(path)) { DirectoryInfo folder = new DirectoryInfo(path); if (!folder.Exists) { return; } gameDriver.ToRecordMode(folder.FullName); } } if (UIImGui.requestSave.SetFalse()) { FileOpenDialog fileDialog = new FileOpenDialog() { file = new string(new char[512]), fileTitle = new string(new char[512]), initialDir = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer), filter = ".coocoo3DScene\0*.coocoo3DScene\0\0", defExt = "coocoo3DScene", flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008, structSize = Marshal.SizeOf(typeof(FileOpenDialog)) }; fileDialog.maxFile = fileDialog.file.Length; fileDialog.maxFileTitle = fileDialog.fileTitle.Length; if (GetSaveFileName(fileDialog)) { var scene = Coocoo3DScene.FromScene(this.scene); SaveJsonStream(new FileInfo(fileDialog.file).Create(), scene); } } }
private void ReadIKModeSettings(VMDFormat format) { }
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 Dictionary <string, AnimationCurve> CollectCurve(VMDFormat format, string boneName, int interpolationQuality) { if (!format.motion_list.motion.ContainsKey(boneName)) { return(null); } Dictionary <string, AnimationCurve> dictionary = new Dictionary <string, AnimationCurve>(); List <VMDFormat.Motion> list = format.motion_list.motion[boneName]; Vector3 zero = Vector3.zero; this.GetKeyframeCount(list, 0, interpolationQuality); this.GetKeyframeCount(list, 1, interpolationQuality); this.GetKeyframeCount(list, 2, interpolationQuality); List <VMDHSConverter.FloatKeyframe> list2 = new List <VMDHSConverter.FloatKeyframe>(); List <VMDHSConverter.FloatKeyframe> list3 = new List <VMDHSConverter.FloatKeyframe>(); List <VMDHSConverter.FloatKeyframe> list4 = new List <VMDHSConverter.FloatKeyframe>(); VMDHSConverter.FloatKeyframe prev_keyframe = null; VMDHSConverter.FloatKeyframe prev_keyframe2 = null; VMDHSConverter.FloatKeyframe prev_keyframe3 = null; int num = 0; int num2 = 0; int num3 = 0; for (int i = 0; i < list.Count; i++) { float time = list[i].flame_no * 0.0333333351f; VMDHSConverter.FloatKeyframe floatKeyframe = new VMDHSConverter.FloatKeyframe(time, list[i].location.x * this.scale.x + zero.x); VMDHSConverter.FloatKeyframe floatKeyframe2 = new VMDHSConverter.FloatKeyframe(time, list[i].location.y * this.scale.y + zero.y); VMDHSConverter.FloatKeyframe floatKeyframe3 = new VMDHSConverter.FloatKeyframe(time, list[i].location.z * this.scale.z + zero.z); VMDHSConverter.FloatKeyframe.AddBezierKeyframes(list[i].interpolation, 0, prev_keyframe, floatKeyframe, interpolationQuality, ref list2, ref num); VMDHSConverter.FloatKeyframe.AddBezierKeyframes(list[i].interpolation, 1, prev_keyframe2, floatKeyframe2, interpolationQuality, ref list3, ref num2); VMDHSConverter.FloatKeyframe.AddBezierKeyframes(list[i].interpolation, 2, prev_keyframe3, floatKeyframe3, interpolationQuality, ref list4, ref num3); prev_keyframe = floatKeyframe; prev_keyframe2 = floatKeyframe2; prev_keyframe3 = floatKeyframe3; } if (list.Count != 0) { VMDHSConverter.FloatKeyframe[] custom_keys = list2.ToArray(); VMDHSConverter.FloatKeyframe[] custom_keys2 = list3.ToArray(); VMDHSConverter.FloatKeyframe[] custom_keys3 = list4.ToArray(); AnimationCurve value = new AnimationCurve(this.ToKeyframesForLocation(custom_keys)); AnimationCurve value2 = new AnimationCurve(this.ToKeyframesForLocation(custom_keys2)); AnimationCurve value3 = new AnimationCurve(this.ToKeyframesForLocation(custom_keys3)); dictionary.Add("localPosition.x", value); dictionary.Add("localPosition.y", value2); dictionary.Add("localPosition.z", value3); } VMDHSConverter.QuaternionKeyframe[] custom_keys4 = new VMDHSConverter.QuaternionKeyframe[this.GetKeyframeCount(list, 3, interpolationQuality)]; VMDHSConverter.QuaternionKeyframe prev_keyframe4 = null; int num4 = 0; for (int j = 0; j < list.Count; j++) { float time2 = list[j].flame_no * 0.0333333351f; Quaternion rotation = list[j].rotation; VMDHSConverter.QuaternionKeyframe quaternionKeyframe = new VMDHSConverter.QuaternionKeyframe(time2, rotation); VMDHSConverter.QuaternionKeyframe.AddBezierKeyframes(list[j].interpolation, 3, prev_keyframe4, quaternionKeyframe, interpolationQuality, ref custom_keys4, ref num4); prev_keyframe4 = quaternionKeyframe; } Keyframe[] array = null; Keyframe[] array2 = null; Keyframe[] array3 = null; this.ToKeyframesForRotation(custom_keys4, ref array, ref array2, ref array3, false); AnimationCurve value4 = new AnimationCurve(array); AnimationCurve value5 = new AnimationCurve(array2); AnimationCurve value6 = new AnimationCurve(array3); dictionary.Add("localEulerAngles.x", value4); dictionary.Add("localEulerAngles.y", value5); dictionary.Add("localEulerAngles.z", value6); return(dictionary); }
private void CreateKeysForLocation(VMDFormat format, AnimationClip clip, string current_bone, string bone_path, int interpolationQuality, GameObject current_obj = null) { try { if (this.boneNameMap.ContainsKey(current_bone)) { string text = this.boneNameMap[current_bone]; if (!format.motion_list.motion.ContainsKey(text)) { Console.WriteLine("bone {0} not found in motionlist", text); } else { HashSet <string> hashSet = new HashSet <string> { "全ての親", "センター", "グルーブ", "右足IK親", "右足IK", "右つま先IK", "左足IK親", "左足IK", "左つま先IK" }; Vector3 vector = Vector3.zero; List <VMDFormat.Motion> list = format.motion_list.motion[text]; this.GetKeyframeCount(list, 0, interpolationQuality); this.GetKeyframeCount(list, 1, interpolationQuality); this.GetKeyframeCount(list, 2, interpolationQuality); List <VMDHSConverter.FloatKeyframe> list2 = new List <VMDHSConverter.FloatKeyframe>(); List <VMDHSConverter.FloatKeyframe> list3 = new List <VMDHSConverter.FloatKeyframe>(); List <VMDHSConverter.FloatKeyframe> list4 = new List <VMDHSConverter.FloatKeyframe>(); VMDHSConverter.FloatKeyframe prev_keyframe = null; VMDHSConverter.FloatKeyframe prev_keyframe2 = null; VMDHSConverter.FloatKeyframe prev_keyframe3 = null; int num = 0; int num2 = 0; int num3 = 0; uint num4 = uint.MaxValue; for (int i = 0; i < list.Count; i++) { float num5 = list[i].flame_no * 0.0333333351f; if (num4 > list[i].flame_no) { num4 = list[i].flame_no; } Vector3 vector2 = list[i].location; if (!(vector2 == Vector3.zero) || hashSet.Contains(text)) { vector2.z = -vector2.z; vector2.x = -vector2.x; if (float.IsNaN(vector2.x) || float.IsNaN(vector2.y) || float.IsNaN(vector2.z)) { KKVMDPlugin.Logger.Log(BepInEx.Logging.LogLevel.Debug, string.Format("position value is NaN. Treat as / 100 of max. {0}", num5)); vector2 = new Vector3(3.40282359E+36f, 3.40282359E+36f, 3.40282359E+36f); } else if (vector2.magnitude > 1E+07f) { KKVMDPlugin.Logger.Log(BepInEx.Logging.LogLevel.Debug, string.Format("position value is too large. Treat as / 100 to avoid clipping. {0}, ({1} {2} {3})", new object[] { num5, vector2.x, vector2.y, vector2.z })); vector2 /= 100f; } if (text == "センター") { vector = this.HSModelBaseline.centerBasePos; } if (text == "グルーブ") { vector = this.HSModelBaseline.grooveBasePos; } if (text == "左足IK親") { vector = this.HSModelBaseline.leftIKCenterPos; } else if (text == "右足IK親") { vector = this.HSModelBaseline.rightIKCenterPos; } if (text == "右足IK") { vector = this.HSModelBaseline.rightFootPos; } else if (text == "左足IK") { vector = this.HSModelBaseline.leftFootPos; } if (text == "右つま先IK") { vector = this.HSModelBaseline.rightToePosRel; } else if (text == "左つま先IK") { vector = this.HSModelBaseline.leftToePosRel; } VMDHSConverter.FloatKeyframe floatKeyframe = new VMDHSConverter.FloatKeyframe(num5, vector2.x * this.scale.x + vector.x); VMDHSConverter.FloatKeyframe floatKeyframe2 = new VMDHSConverter.FloatKeyframe(num5, vector2.y * this.scale.y + vector.y); VMDHSConverter.FloatKeyframe floatKeyframe3 = new VMDHSConverter.FloatKeyframe(num5, vector2.z * this.scale.z + vector.z); VMDHSConverter.FloatKeyframe.AddBezierKeyframes(list[i].interpolation, 0, prev_keyframe, floatKeyframe, interpolationQuality, ref list2, ref num); VMDHSConverter.FloatKeyframe.AddBezierKeyframes(list[i].interpolation, 1, prev_keyframe2, floatKeyframe2, interpolationQuality, ref list3, ref num2); VMDHSConverter.FloatKeyframe.AddBezierKeyframes(list[i].interpolation, 2, prev_keyframe3, floatKeyframe3, interpolationQuality, ref list4, ref num3); prev_keyframe = floatKeyframe; prev_keyframe2 = floatKeyframe2; prev_keyframe3 = floatKeyframe3; } } VMDHSConverter.FloatKeyframe[] custom_keys = list2.ToArray(); VMDHSConverter.FloatKeyframe[] custom_keys2 = list3.ToArray(); VMDHSConverter.FloatKeyframe[] custom_keys3 = list4.ToArray(); if (list.Count != 0) { if (hashSet.Contains(text)) { AnimationCurve animationCurve = new AnimationCurve(this.ToKeyframesForLocation(custom_keys)); AnimationCurve animationCurve2 = new AnimationCurve(this.ToKeyframesForLocation(custom_keys2)); AnimationCurve animationCurve3 = new AnimationCurve(this.ToKeyframesForLocation(custom_keys3)); clip.SetCurve(bone_path, typeof(Transform), "localPosition.x", animationCurve); clip.SetCurve(bone_path, typeof(Transform), "localPosition.y", animationCurve2); clip.SetCurve(bone_path, typeof(Transform), "localPosition.z", animationCurve3); } else { KKVMDPlugin.Logger.Log(BepInEx.Logging.LogLevel.Error, string.Format("Location data for non movable bone {0} found. Ignore.", text)); } } } } } catch (KeyNotFoundException) { } }
private void CreateKeysForRotation(VMDFormat format, AnimationClip clip, string current_bone, string bone_path, int interpolationQuality) { try { if (this.boneNameMap.ContainsKey(current_bone)) { string text = this.boneNameMap[current_bone]; List <VMDFormat.Motion> list; if (!format.motion_list.motion.ContainsKey(text)) { Console.WriteLine("bone {0} not found in motionlist", text); Console.WriteLine("Add dummy rotation frame (rot 0,0,0) for the bone {0}", text); list = new List <VMDFormat.Motion>(); VMDFormat.Motion item = new VMDFormat.Motion(text, 0u, Vector3.zero, Quaternion.identity, new byte[64]); list.Add(item); } else { list = format.motion_list.motion[text]; } Dictionary <string, AnimationCurve> dictionary = null; BoneAdjustment boneAdjustment = null; if (this.boneAdjustment.ContainsKey(current_bone)) { boneAdjustment = this.boneAdjustment[current_bone]; } VMDHSConverter.QuaternionKeyframe[] custom_keys = new VMDHSConverter.QuaternionKeyframe[this.GetKeyframeCount(list, 3, interpolationQuality)]; VMDHSConverter.QuaternionKeyframe prev_keyframe = null; int num = 0; Quaternion quaternion = Quaternion.identity; for (int i = 0; i < list.Count; i++) { float num2 = list[i].flame_no * 0.0333333351f; Quaternion quaternion2 = list[i].rotation; if (dictionary != null) { AnimationCurve animationCurve = null; dictionary.TryGetValue("localEulerAngles.x", out animationCurve); AnimationCurve animationCurve2 = null; dictionary.TryGetValue("localEulerAngles.y", out animationCurve2); AnimationCurve animationCurve3 = null; dictionary.TryGetValue("localEulerAngles.z", out animationCurve3); Quaternion quaternion3 = Quaternion.identity; if (animationCurve != null && animationCurve2 != null && animationCurve3 != null) { quaternion3 = Quaternion.Euler(animationCurve.Evaluate(num2), animationCurve2.Evaluate(num2), animationCurve3.Evaluate(num2)); quaternion2 *= quaternion3; } } if (boneAdjustment != null) { quaternion2 = boneAdjustment.GetAdjustedRotation(quaternion2); } if (i != 0) { quaternion2 = Quaternion.Slerp(quaternion, quaternion2, 0.99999f); } VMDHSConverter.QuaternionKeyframe quaternionKeyframe = new VMDHSConverter.QuaternionKeyframe(num2, quaternion2); VMDHSConverter.QuaternionKeyframe.AddBezierKeyframes(list[i].interpolation, 3, prev_keyframe, quaternionKeyframe, interpolationQuality, ref custom_keys, ref num); prev_keyframe = quaternionKeyframe; quaternion = quaternion2; } Keyframe[] array = null; Keyframe[] array2 = null; Keyframe[] array3 = null; Dictionary <string, Keyframe[]> dictionary2 = this.ToKeyframesForRotation(custom_keys, ref array, ref array2, ref array3, false); new AnimationCurve(array); new AnimationCurve(array2); new AnimationCurve(array3); AnimationCurve animationCurve4 = new AnimationCurve(dictionary2["localRotation.x"]); AnimationCurve animationCurve5 = new AnimationCurve(dictionary2["localRotation.y"]); AnimationCurve animationCurve6 = new AnimationCurve(dictionary2["localRotation.z"]); AnimationCurve animationCurve7 = new AnimationCurve(dictionary2["localRotation.w"]); clip.SetCurve(bone_path, typeof(Transform), "localRotation.x", animationCurve4); clip.SetCurve(bone_path, typeof(Transform), "localRotation.y", animationCurve5); clip.SetCurve(bone_path, typeof(Transform), "localRotation.z", animationCurve6); clip.SetCurve(bone_path, typeof(Transform), "localRotation.w", animationCurve7); if (text == "センター") { this.centerXCurve = animationCurve4; this.centerYCurve = animationCurve5; this.centerZCurve = animationCurve6; this.centerWCurve = animationCurve7; } } } catch (KeyNotFoundException) { } }
/// <summary> /// AnimationClipを作成する /// </summary> /// <param name='name'>内部形式データ</param> /// <param name='assign_pmd'>使用するPMDのGameObject</param> /// <param name='interpolationQuality'>補完曲線品質</param> public static AnimationClip CreateAnimationClip(VMDFormat format, GameObject assign_pmd, int interpolationQuality) { VMDConverter converter = new VMDConverter(); return(converter.CreateAnimationClip_(format, assign_pmd, interpolationQuality)); }