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)); } } }
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); } } }