Exemplo n.º 1
0
        protected override async System.Threading.Tasks.Task <ResourceInfo> CreateResourceInfoFromResourceOverride(EngineNS.RName resourceName)
        {
            await EngineNS.Thread.AsyncDummyClass.DummyFunc();

            var retValue = new MaterialResourceInfo();

            retValue.ResourceName = resourceName;
            retValue.ResourceType = EngineNS.Editor.Editor_RNameTypeAttribute.Material;

            return(retValue);
        }
Exemplo n.º 2
0
        public async System.Threading.Tasks.Task <ResourceInfo> CreateEmptyResource(string Absfolder, string rootFolder, EditorCommon.Resources.IResourceCreateData createData)
        {
            await EngineNS.Thread.AsyncDummyClass.DummyFunc();

            var result = new MaterialResourceInfo();

            var data   = createData as EditorCommon.Resources.ResourceCreateDataBase;
            var reName = EngineNS.CEngine.Instance.FileManager._GetRelativePathFromAbsPath(Absfolder + "/" + data.ResourceName, rootFolder);

            reName += EngineNS.CEngineDesc.MaterialExtension;
            result.ResourceName = EngineNS.RName.GetRName(reName, data.RNameType);

            {
                // .var文件创建
                EngineNS.CEngine.Instance.FileManager.CreateFileAndFlush(result.ResourceName.Address + EngineNS.Graphics.CGfxMaterial.ShaderDefineExtension);

                // .code文件创建
                string codeContent = "void DoVSMaterial(in PS_INPUT input, inout MTL_OUTPUT mtl)\r\n{\r\n}\r\n";
                codeContent += "void DoPSMaterial(in PS_INPUT input, inout MTL_OUTPUT mtl)\r\n{\r\n}\r\n";
                codeContent += "#ifndef DO_VS_MATERIAL\r\n";
                codeContent += "#define DO_VS_MATERIAL DoVSMaterial\r\n";
                codeContent += "#endif\r\n";
                codeContent += "#ifndef DO_PS_MATERIAL\r\n";
                codeContent += "#define DO_PS_MATERIAL DoPSMaterial\r\n";
                codeContent += "#endif\r\n";


                EngineNS.CEngine.Instance.FileManager.WriteAllTextASCII(result.ResourceName.Address + EngineNS.Graphics.CGfxMaterial.ShaderIncludeExtension, codeContent);
            }

            var mat = EngineNS.CEngine.Instance.MaterialManager.NewMaterial(result.ResourceName);

            mat.SaveMaterial();

            return(result);
        }
Exemplo n.º 3
0
        protected override async Task <bool> InitializeContextMenuOverride(ContextMenu contextMenu)
        {
            await EngineNS.Thread.AsyncDummyClass.DummyFunc();

            var textSeparatorStyle = Application.Current.MainWindow.TryFindResource(new ComponentResourceKey(typeof(ResourceLibrary.CustomResources), "TextMenuSeparatorStyle")) as System.Windows.Style;
            var menuItemStyle      = Application.Current.MainWindow.TryFindResource(new ComponentResourceKey(typeof(ResourceLibrary.CustomResources), "MenuItem_Default")) as System.Windows.Style;

            contextMenu.Items.Add(new ResourceLibrary.Controls.Menu.TextSeparator()
            {
                Text  = "Common",
                Style = textSeparatorStyle,
            });

            var ciMenuItem = new MenuItem()
            {
                Name   = "MatResInfo_CreateMatIns",
                Header = "创建材质实例",
                Style  = menuItemStyle,
            };

            ciMenuItem.Click += async(object sender, RoutedEventArgs e) =>
            {
                var resInfo = new MaterialInstanceResourceInfo();

                var win = new EditorCommon.Controls.ResourceBrowser.CreateResDialog();
                win.Title        = $"创建材质实例";
                win.ResourceName = EditorCommon.Program.GetValidName(ResourceName.GetDirectory(), ResourceName.PureName() + "_ins", EngineNS.CEngineDesc.MaterialInstanceExtension);
                var data = new MaterialInstanceResourceCreateData()
                {
                    ResourceName   = win.ResourceName,
                    ParentMaterial = this.ResourceName,
                };
                win.ResCreateData = data;
                data.HostDialog   = win;
                if (win.ShowDialog((value, cultureInfo) =>
                {
                    if (value == null)
                    {
                        return(new ValidationResult(false, "内容不合法"));
                    }
                    return(resInfo.ResourceNameAvailable(ResourceName.GetDirectory(), value.ToString()));
                }) == false)
                {
                    return;
                }

                var createData = win.GetCreateData();
                createData.RNameType = ResourceName.RNameType;
                var resourceInfo = await resInfo.CreateEmptyResource(ResourceName.GetDirectory(), ResourceName.GetRootFolder(), createData);

                var pro = resourceInfo.GetType().GetProperty("ResourceType");
                pro?.SetValue(resourceInfo, EngineNS.Editor.Editor_RNameTypeAttribute.MaterialInstance);
                resourceInfo.ParentBrowser = this.ParentBrowser;
                await resourceInfo.Save(true);

                this.ParentBrowser.AddResourceInfo(resourceInfo);
                this.ParentBrowser.SelectResourceInfo(resourceInfo);
                await resourceInfo.InitializeContextMenu();
            };
            ResourceLibrary.Controls.Menu.MenuAssist.SetIcon(ciMenuItem, new BitmapImage(new System.Uri("pack://application:,,,/ResourceLibrary;component/Icons/Icons/AssetIcons/MaterialInstanceConstant_64x.png", UriKind.Absolute)));
            contextMenu.Items.Add(ciMenuItem);

            var duplicateMenuItem = new MenuItem()
            {
                Name   = "MatResInfo_Duplicate",
                Header = $"复制",
                Style  = menuItemStyle,
            };

            duplicateMenuItem.Click += async(object sender, RoutedEventArgs e) =>
            {
                var dir      = ResourceName.GetDirectory();
                var inputWin = new InputWindow.InputWindow();
                inputWin.Title       = $"复制{ResourceName.PureName()}";
                inputWin.Description = "输入材质名称";
                inputWin.Value       = EditorCommon.Program.GetValidName(dir, ResourceName.PureName(), EngineNS.CEngineDesc.MaterialExtension);
                if (inputWin.ShowDialog((value, cultureInfo) =>
                {
                    if (value == null)
                    {
                        return(new ValidationResult(false, "内容不合法"));
                    }
                    return(ResourceNameAvailable(dir, value.ToString()));
                }) == false)
                {
                    return;
                }

                var rc       = EngineNS.CEngine.Instance.RenderContext;
                var tagRName = EngineNS.RName.EditorOnly_GetRNameFromAbsFile(dir + inputWin.Value + EngineNS.CEngineDesc.MaterialExtension);
                // mat
                var mat = await EngineNS.CEngine.Instance.MaterialManager.GetMaterialAsync(rc, ResourceName);

                var matCopy = EngineNS.CEngine.Instance.MaterialManager.NewMaterial(tagRName);
                mat.CopyTo(matCopy);
                matCopy.SaveMaterial();
                // link
                var xndHolder = await EngineNS.IO.XndHolder.LoadXND(ResourceName.Address + EngineNS.Graphics.CGfxMaterial.ShaderLinkExtension);

                if (xndHolder != null)
                {
                    var container = new CodeGenerateSystem.Base.NodesContainer();
                    await container.Load(xndHolder.Node);

                    xndHolder.Node.TryReleaseHolder();

                    Controls.MaterialControl matCtrl = null;
                    foreach (var node in container.OrigionNodeControls)
                    {
                        if (node is Controls.MaterialControl)
                        {
                            node.Id = Guid.NewGuid();
                            matCtrl = node as Controls.MaterialControl;
                        }
                    }

                    System.IO.TextWriter codeFile, varFile;
                    CodeGenerator.GenerateCode(container, matCtrl, out codeFile, out varFile);

                    // var
                    System.IO.File.WriteAllText(tagRName.Address + EngineNS.Graphics.CGfxMaterial.ShaderDefineExtension, varFile.ToString());
                    // code
                    System.IO.File.WriteAllText(tagRName.Address + EngineNS.Graphics.CGfxMaterial.ShaderIncludeExtension, codeFile.ToString());
                    // link
                    var tagHolder = EngineNS.IO.XndHolder.NewXNDHolder();
                    container.Save(tagHolder.Node);
                    EngineNS.IO.XndHolder.SaveXND(tagRName.Address + EngineNS.Graphics.CGfxMaterial.ShaderLinkExtension, tagHolder);
                }
                // resInfo
                var copyedRInfo = new MaterialResourceInfo();
                copyedRInfo.ResourceName = tagRName;
                await CopyResource(copyedRInfo);

                await copyedRInfo.Save();

                // snapshot
                EngineNS.CEngine.Instance.FileManager.CopyFile(ResourceName.Address + EditorCommon.Program.SnapshotExt, tagRName.Address + EditorCommon.Program.SnapshotExt, true);
                await copyedRInfo.InitializeContextMenu();

                ParentBrowser.AddResourceInfo(copyedRInfo);
                ParentBrowser.SelectResourceInfo(copyedRInfo);
            };
            ResourceLibrary.Controls.Menu.MenuAssist.SetIcon(duplicateMenuItem, new BitmapImage(new System.Uri("pack://application:,,,/ResourceLibrary;component/Icons/Icons/icon_Edit_Duplicate_40x.png", UriKind.Absolute)));
            contextMenu.Items.Add(duplicateMenuItem);

            var menuItem = new MenuItem()
            {
                Name   = "MatResInfo_Delete",
                Header = "删除",
                Style  = menuItemStyle,
            };

            menuItem.Click += async(object sender, RoutedEventArgs e) =>
            {
                await DeleteResource();

                EngineNS.CEngine.Instance.MaterialManager.Materials.Remove(ResourceName);
            };
            ResourceLibrary.Controls.Menu.MenuAssist.SetIcon(menuItem, new BitmapImage(new System.Uri("pack://application:,,,/ResourceLibrary;component/Icons/Icons/icon_delete_16px.png", UriKind.Absolute)));
            contextMenu.Items.Add(menuItem);

            return(true);
        }