示例#1
0
        public static void LoadShaderForEntities1(Coocoo3DMain appBody, StorageFile storageFile, StorageFolder storageFolder, IList <MMD3DEntity> entities)
        {
            RPShaderPack shaderPack;

            lock (appBody.mainCaches.RPShaderPackCaches)
            {
                shaderPack = appBody.mainCaches.RPShaderPackCaches.GetOrCreate(storageFile.Path);
                if (shaderPack.Status != GraphicsObjectStatus.loaded)
                {
                    if (shaderPack.loadLocker.GetLocker())
                    {
                        string relativePath = storageFile.Name;
                        _ = Task.Run(async() =>
                        {
                            var task1 = shaderPack.Reload1(storageFolder, relativePath, appBody.RPAssetsManager, appBody.ProcessingList);
                            appBody.RequireRender();
                            if (await task1)
                            {
                            }
                            appBody.RequireRender();
                            shaderPack.loadLocker.FreeLocker();
                        });
                    }
                }
            }
            foreach (var entity in entities)
            {
                entity.rendererComponent.PODraw          = shaderPack.PODraw;
                entity.rendererComponent.POSkinning      = shaderPack.POSkinning;
                entity.rendererComponent.POParticleDraw  = shaderPack.POParticleDraw;
                entity.rendererComponent.ParticleCompute = shaderPack.CSParticle;
            }
            appBody.RequireRender();
        }
示例#2
0
 private void Front_Click(object sender, RoutedEventArgs e)
 {
     if (appBody.Recording)
     {
         appBody.GameDriver = appBody._GeneralGameDriver;
         appBody.Recording  = false;
     }
     appBody.GameDriverContext.PlayTime            = 0;
     appBody.GameDriverContext.RequireResetPhysics = true;
     appBody.RequireRender(true);
 }
示例#3
0
        public static void NewLighting(Coocoo3DMain appBody)
        {
            //var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();
            //Lighting lighting = new Lighting();
            //lighting.Name = resourceLoader.GetString("Object_Name_Lighting");
            //lighting.lightingComponent.Color = new Vector4(3, 3, 3, 1);
            //lighting.Rotation = Quaternion.CreateFromYawPitchRoll(0, 1.570796326794f, 0);
            //lighting.Position = new Vector3(0, 1, 0);
            //lighting.lightingComponent.Range = 10;
            //if (appBody.CurrentScene.Lightings.Count > 0)
            //    lighting.lightingComponent.LightingType = LightingType.Point;
            //appBody.CurrentScene.AddSceneObject(lighting);
            //appBody.RequireRender();
            var        resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();
            GameObject lighting       = new GameObject();

            Components.LightingComponent lightingComponent = new Components.LightingComponent();
            lighting.AddComponent(lightingComponent);
            lighting.Name           = resourceLoader.GetString("Object_Name_Lighting");
            lighting.Rotation       = Quaternion.CreateFromYawPitchRoll(0, 1.570796326794f, 0);
            lighting.Position       = new Vector3(0, 1, 0);
            lightingComponent.Color = new Vector4(3, 3, 3, 1);
            lightingComponent.Range = 10;
            appBody.CurrentScene.AddGameObject(lighting);
            appBody.RequireRender();
        }
示例#4
0
 public static void Play(Coocoo3DMain appBody)
 {
     appBody.GameDriverContext.Playing   = true;
     appBody.GameDriverContext.PlaySpeed = 1.0f;
     appBody.LatestRenderTime            = DateTime.Now - appBody.GameDriverContext.FrameInterval;
     appBody.RequireRender();
 }
示例#5
0
        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);
        }
示例#6
0
        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));
                }
            }
        }
示例#7
0
 public static void Rear(Coocoo3DMain appBody)
 {
     if (appBody.Recording)
     {
         appBody.GameDriver = appBody._GeneralGameDriver;
         appBody.Recording  = false;
     }
     appBody.GameDriverContext.PlayTime            = 9999;
     appBody.GameDriverContext.RequireResetPhysics = true;
     appBody.RequireRender(true);
 }
        private void ViewSceneObjects_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            IList <object> selectedItem = (sender as ListView).SelectedItems;

            lock (appBody.selectedObjcetLock)
            {
                appBody.SelectedEntities.Clear();
                appBody.SelectedGameObjects.Clear();
                for (int i = 0; i < selectedItem.Count; i++)
                {
                    if (selectedItem[i] is MMD3DEntity entity)
                    {
                        appBody.SelectedEntities.Add(entity);
                    }
                    else if (selectedItem[i] is GameObject gameObject)
                    {
                        appBody.SelectedGameObjects.Add(gameObject);
                    }
                }
                if (selectedItem.Count == 1)
                {
                    if (appBody.SelectedEntities.Count == 1)
                    {
                        appBody.ShowDetailPage(typeof(EntityPropertiesPage), appBody);
                    }
                    else if (appBody.SelectedGameObjects.Count == 1)
                    {
                        appBody.ShowDetailPage(typeof(GameObjectPage), appBody);
                    }
                    else
                    {
                        appBody.ShowDetailPage(typeof(EmptyPropertiesPage), null);
                    }
                }
                else
                {
                    appBody.ShowDetailPage(typeof(EmptyPropertiesPage), null);
                }
            }
            appBody.RequireRender();
        }
示例#9
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            if (file == null)
            {
                return;
            }
            Uploader uploader = new Uploader();

            uploader.Texture2D(await FileIO.ReadBufferAsync(file), true, true);
            appBody.ProcessingList.AddObject(new Texture2DUploadPack(appBody.RPContext.postProcessBackground, uploader));
            appBody.RequireRender();
        }
示例#10
0
 public static void RemoveSceneObject(Coocoo3DMain appBody, Scene scene, ISceneObject sceneObject)
 {
     if (scene.sceneObjects.Remove(sceneObject))
     {
         if (sceneObject is MMD3DEntity entity)
         {
             scene.RemoveSceneObject(entity);
         }
         else if (sceneObject is Lighting lighting)
         {
             scene.RemoveSceneObject(lighting);
         }
     }
     appBody.RequireRender();
 }
示例#11
0
        private async Task ApplySkyBoxTask(int level)
        {
            var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();

            for (int i = 0; i < 6; i++)
            {
                if (files[i] == null)
                {
                    showInfo.Text = "天空盒图片未完全填充";
                    return;
                }
            }
            showInfo.Text = resourceLoader.GetString("Message_Operating");
            var      rp       = appBody.RPContext;
            Uploader uploader = new Uploader();

            uploader.TextureCube(imgSize[0].x, imgSize[0].y,
                                 new IBuffer[] {
                await FileIO.ReadBufferAsync(files[0]),
                await FileIO.ReadBufferAsync(files[1]),
                await FileIO.ReadBufferAsync(files[2]),
                await FileIO.ReadBufferAsync(files[3]),
                await FileIO.ReadBufferAsync(files[4]),
                await FileIO.ReadBufferAsync(files[5])
            });
            int t1 = appBody.CompletedRenderCount;

            if (prevRenderFrame == t1)
            {
            }
            prevRenderFrame = t1;
            appBody.ProcessingList.AddObject(new TextureCubeUploadPack(rp.SkyBox, uploader));
            appBody.miscProcessContext.Add(new P_Env_Data()
            {
                source = rp.SkyBox, IrradianceMap = rp.IrradianceMap, EnvMap = rp.EnvironmentMap, Level = level
            });
            appBody.RequireRender();
            showInfo.Text = resourceLoader.GetString("Message_Done");
        }
示例#12
0
        public static async Task LoadEntityIntoScene(Coocoo3DMain appBody, Scene scene, StorageFile pmxFile, StorageFolder storageFolder)
        {
            string    pmxPath    = pmxFile.Path;
            string    relatePath = pmxFile.Name;
            ModelPack pack       = null;

            lock (appBody.mainCaches.ModelPackCaches)
            {
                pack = appBody.mainCaches.ModelPackCaches.GetOrCreate(pmxPath);
                if (pack.LoadTask == null && pack.Status != GraphicsObjectStatus.loaded)
                {
                    pack.LoadTask = Task.Run(async() =>
                    {
                        BinaryReader reader   = new BinaryReader((await pmxFile.OpenReadAsync()).AsStreamForRead());
                        pack.lastModifiedTime = (await pmxFile.GetBasicPropertiesAsync()).DateModified;
                        pack.Reload2(reader);
                        pack.folder       = storageFolder;
                        pack.relativePath = relatePath;
                        reader.Dispose();
                        appBody.ProcessingList.AddObject(pack.GetMesh());
                        pack.Status   = GraphicsObjectStatus.loaded;
                        pack.LoadTask = null;
                    });
                }
            }
            if (pack.Status != GraphicsObjectStatus.loaded && pack.LoadTask != null)
            {
                await pack.LoadTask;
            }
            MMD3DEntity entity = new MMD3DEntity();

            entity.Reload2(appBody.ProcessingList, pack, GetTextureList(appBody, storageFolder, pack.pmx), pmxPath);
            scene.AddSceneObject(entity);
            appBody.RequireRender();

            appBody.mainCaches.ReloadTextures(appBody.ProcessingList, appBody.RequireRender);
        }