public static ESet <string> GetProjectFileCSFiles(bool reload, bool getFullPaths) { if (projectFileCSFiles == null || reload) { projectFileCSFiles = new ESet <string>(); projectFileCSFilesFullPaths = new ESet <string>(); if (ProjectFileExists()) { try { using (var projectCollection = CreateProjectCollection()) { Project project = projectCollection.LoadProject(GetProjectFileName()); foreach (var item in GetProjectCSFiles(project)) { var name = item.UnevaluatedInclude; projectFileCSFiles.AddWithCheckAlreadyContained(name); projectFileCSFilesFullPaths.AddWithCheckAlreadyContained(Path.Combine(ProjectDir, name)); } } } catch (Exception e) { //!!!! Log.Warning($"Unable to read file \'{GetProjectFileName()}\'. Error: {e.Message}"); } } } return(getFullPaths ? projectFileCSFilesFullPaths : projectFileCSFiles); }
// public ReverseEnumerator(ESet <T> dictionary) { this.set = dictionary; this.version = dictionary.version; this.orderedIndex = dictionary.orderedLastIndex; this.current = default(T); }
static void CheckMissingSummaries() { //ESet<string> toSkip = new ESet<string>(); //toSkip.Add( "NeoAxis.Component.T property: Enabled" ); //toSkip.Add( "NeoAxis.Component.T property: Name" ); bool titleWasAdded = false; ESet <Metadata.Member> processed = new ESet <Metadata.Member>(8000); foreach (var type in MetadataManager.NetTypes.ToArray()) { if (typeof(Component).IsAssignableFrom(type.GetNetType()) && type.GetNetType().IsPublic) { Metadata.GetMembersContext context = new Metadata.GetMembersContext(); context.filter = false; foreach (var member in type.MetadataGetMembers(context)) { string missingText = null; var property = member as Metadata.Property; if (property != null && property.Browsable && !processed.Contains(property)) { processed.AddWithCheckAlreadyContained(property); var id = GetMemberId(member); if (!string.IsNullOrEmpty(id)) { if (string.IsNullOrEmpty(GetMemberSummary(id))) { var text = type.Name + " " + "property: " + member.Name; //if( !toSkip.Contains( text ) ) missingText = text; } } } //!!!!events if (missingText != null) { if (!titleWasAdded) { Log.InvisibleInfo("-----------------------------"); Log.InvisibleInfo("Missing type descriptions:"); titleWasAdded = true; } Log.InvisibleInfo(missingText); } } } } if (titleWasAdded) { Log.InvisibleInfo("-----------------------------"); } }
// public Enumerator(ESet <T> set) { this.set = set; this.version = set.version; this.orderedIndex = set.orderedStartIndex; this.current = default(T); }
static void CheckResetProjectData() { if (needResetProjectData) { projectFileCSFiles = null; projectFileCSFilesFullPaths = null; projectFileReferences = null; needResetProjectData = false; } }
//!!!! //private const string MSBuildSDKsPath = nameof( MSBuildSDKsPath ); public static ESet <string> GetProjectFileCSFiles(bool reload, bool getFullPaths) { CheckResetProjectData(); if (useManualParser) { GetProjectFileData_ManualParser(reload); } else { if (projectFileCSFiles == null || reload) { projectFileCSFiles = new ESet <string>(); projectFileCSFilesFullPaths = new ESet <string>(); if (ProjectFileExists()) { //!!!! //var sdksPath = @"F:\Dev5\Project\Binaries\NeoAxis.Internal\Platforms\Windows\dotnet\sdk\3.1.302"; //var oldMSBuildSDKsPath = Environment.GetEnvironmentVariable( MSBuildSDKsPath ); //Environment.SetEnvironmentVariable( MSBuildSDKsPath, sdksPath ); try { using (var projectCollection = CreateProjectCollection()) { Project project = projectCollection.LoadProject(GetProjectFileName()); foreach (var item in GetProjectCSFiles(project)) { var name = item.UnevaluatedInclude; projectFileCSFiles.AddWithCheckAlreadyContained(name); projectFileCSFilesFullPaths.AddWithCheckAlreadyContained(Path.Combine(ProjectDir, name)); } } } catch (Exception e) { //!!!! Log.Warning($"Unable to read file \'{GetProjectFileName()}\'. Error: {e.Message}"); } finally { //!!!! //Environment.SetEnvironmentVariable( MSBuildSDKsPath, oldMSBuildSDKsPath ); } } } } return(getFullPaths ? projectFileCSFilesFullPaths : projectFileCSFiles); }
/////////////////////////////////////////////// static void GetProjectFileData_ManualParser(bool reload) { if (projectFileCSFiles == null || reload) { projectFileCSFiles = new ESet <string>(); projectFileCSFilesFullPaths = new ESet <string>(); projectFileReferences = new List <string>(); if (ProjectFileExists()) { try { var xmldoc = new XmlDocument(); xmldoc.Load(GetProjectFileName()); { var list = xmldoc.SelectNodes("//Reference"); foreach (XmlNode node in list) { var include = node.Attributes["Include"].Value; projectFileReferences.Add(include); } } { var list = xmldoc.SelectNodes("//PackageReference"); foreach (XmlNode node in list) { var include = node.Attributes["Include"].Value; projectFileReferences.Add(include); } } { var list = xmldoc.SelectNodes("//Compile"); foreach (XmlNode node in list) { var include = node.Attributes["Include"].Value; projectFileCSFiles.AddWithCheckAlreadyContained(include); projectFileCSFilesFullPaths.AddWithCheckAlreadyContained(Path.Combine(ProjectDir, include)); } } } catch (Exception e) { Log.Warning($"Unable to read file \'{GetProjectFileName()}\'. Error: {e.Message}"); } } } }
///////////////////////////////////////// public static void CheckToRemoveNotExistsFilesFromProject() { var notExists = new ESet <string>(); foreach (var path in GetProjectFileCSFiles(false, true)) { if (!File.Exists(path)) { notExists.AddWithCheckAlreadyContained(path); } } if (notExists.Count != 0) { var text = EditorLocalization.Translate("General", "Unable to compile Project.csproj. The project contains files which are not exists. Remove these files from the project?") + "\r\n"; int counter = 0; foreach (var fullPath in notExists) { if (counter > 20) { text += "\r\n..."; break; } var path = fullPath.Replace(ProjectDir + Path.DirectorySeparatorChar, ""); text += "\r\n" + path; counter++; } if (EditorMessageBox.ShowQuestion(text, EMessageBoxButtons.YesNo) == EDialogResult.Yes) { if (UpdateProjectFile(null, notExists, out var error)) { if (notExists.Count > 1) { Log.Info(EditorLocalization.Translate("General", "Items have been removed from the Project.csproj.")); } else { Log.Info(EditorLocalization.Translate("General", "The item has been removed from the Project.csproj.")); } } else { Log.Warning(error); } } } }
public void UpdateCells() { var actualControls = new ESet <Component>(Rows * Columns); //add new cells for (int nRow = 0; nRow < Rows; nRow++) { for (int nColumn = 0; nColumn < Columns; nColumn++) { var name = string.Format("Cell {0} {1}", nRow, nColumn); var control = Components.GetByName(name); if (control == null) { control = CreateComponent <UIControl>(); control.Name = name; } actualControls.Add(control); } } var toDelete = new ESet <Component>(); foreach (var c in GetCells()) { if (!actualControls.Contains(c)) { toDelete.Add(c); } } //delete old foreach (var c in toDelete) { c.RemoveFromParent(false); } if (AutoPosition) { UpdateCellsPositionAndSize(); } }
public static List <Component> GetComponentsWithoutChildren(ICollection <Component> list) { var set = new ESet <Component>(list.Count); set.AddRangeWithCheckAlreadyContained(list); var newList = new List <Component>(list.Count); foreach (var obj in list) { var allParents = obj.GetAllParents(false); if (!allParents.Any(p => set.Contains(p))) { newList.Add(obj); } } return(newList); }
public static bool IsEqual(ESet <T> set1, ESet <T> set2) { if (set1.Count != set2.Count) { return(false); } var enum1 = set1.GetEnumerator(); var enum2 = set2.GetEnumerator(); while (enum1.MoveNext()) { enum2.MoveNext(); if (!Equals(enum1.Current, enum2.Current)) { return(false); } } return(true); }
public static bool GetRequestedFullLicenseInfo(out string license, out ESet <string> purchasedProducts, out string tokenTransactions, out string error) { if (!string.IsNullOrEmpty(requestedFullLicenseInfo_License) || !string.IsNullOrEmpty(requestedFullLicenseInfo_Error)) { license = requestedFullLicenseInfo_License; purchasedProducts = requestedFullLicenseInfo_PurchasedProducts; tokenTransactions = requestedFullLicenseInfo_TokenTransactions; error = requestedFullLicenseInfo_Error; //pro = requestedFullLicenseInfo_License.Contains( "Pro" ); return(true); } else { license = ""; purchasedProducts = new ESet <string>(); tokenTransactions = ""; error = ""; //pro = false; return(false); } }
static bool LoadContext_ProcessComponentItems(Metadata.LoadContext context, out string error) { //базовое поведение: //сначала вглубь создаем компоненты //далее загружаем свойства //если нельзя создать компоненту, то помечаем "есть дыра" //если есть дыра, то после первого обхода смысла запускать еще раз первый нет //нужно второй запускать (сериализацию) //она для всех не пройдет, т.к. есть дыры //если были изменения, то всё сначала //!!!!сортировать компоненты int noChangesCounter = 0; again :; var unableToGetTypeName = new ESet <string>(); LoadContext_ProcessComponentsCreation(context, out var changed1, out var finished, unableToGetTypeName); if (!LoadContext_ProcessComponentsSerialization(context, out var changed2, out finished, out error)) { return(false); } //check can't load if (!changed1 && !changed2) { noChangesCounter++; if (noChangesCounter == 10) { //error if (unableToGetTypeName.Count != 0) { error = "Types with next names are not exists:"; //error = "Not all types are available. Types with next names are not available:"; foreach (var name in unableToGetTypeName) { error += "\r\n" + name; } } else { error = "Unknown error, no error info."; } context.rootComponentItem?.component?.Dispose(); return(false); } } else { noChangesCounter = 0; } if (!finished) { goto again; } if (!context.rootComponentItem.loaded) { Log.Fatal("never happen"); } error = ""; return(true); }
static void LoadContext_ProcessComponentCreation(Metadata.LoadContext context, Metadata.LoadContext.ComponentItem item, out bool changed, out bool finished, ESet <string> unableToGetTypeName) { changed = false; if (item.component == null && (item.parent != null && item.parent.component != null || item.parent == null)) { Metadata.TypeInfo type = MetadataManager.GetType(item.textBlock.Data); if (type != null) { //!!!!new //use component by base type if (item.parent != null && item.parent.component != null && item.textBlock.AttributeExists("CreatedByBaseType")) { bool createdByBaseType = bool.Parse(item.textBlock.GetAttribute("CreatedByBaseType")); if (createdByBaseType) { int hierarchyIndex = int.Parse(item.textBlock.GetAttribute("CreatedByBaseTypeHierarchyIndex", "0")); int nameIndex = int.Parse(item.textBlock.GetAttribute("CreatedByBaseTypeNameIndex", "0")); Component useComponent = null; foreach (var c in item.parent.component.Components) { if (c.Name == item.name) { //!!!!return true проверять может таки c.GetBaseTypeIndex(out int baseHierarchyIndex, out string baseName, out int baseNameIndex); if (baseHierarchyIndex == hierarchyIndex && baseNameIndex == nameIndex) { useComponent = c; break; } } } if (useComponent != null) { item.component = useComponent; } } } if (item.component == null) { //create item.component = (Component)type.InvokeInstance(null); //remove was deleted components created by base type { //!!!!slowly maybe //reverse order foreach (TextBlock childBlock in item.textBlock.Children.GetReverse()) { if (childBlock.Name == ".componentCreatedByBaseTypeWasDeleted") { int hierarchyIndex = int.Parse(childBlock.GetAttribute("CreatedByBaseTypeHierarchyIndex", "0")); string name = childBlock.GetAttribute("CreatedByBaseTypeName"); int nameIndex = int.Parse(childBlock.GetAttribute("CreatedByBaseTypeNameIndex", "0")); Component foundComponent = null; foreach (var c in item.component.Components) { if (c.Name == name) { //!!!!return true проверять может таки c.GetBaseTypeIndex(out int baseHierarchyIndex, out string baseName, out int baseNameIndex); if (baseHierarchyIndex == hierarchyIndex && baseNameIndex == nameIndex) { foundComponent = c; break; } } } if (foundComponent != null) { foundComponent.RemoveFromParent(false); foundComponent.Dispose(); } } } } item.component.providedTypeAllow = false; //!!!!new item.component.Name = item.name; //!!!!сортировать item.parent.component.AddComponent(item.component); } changed = true; } else { unableToGetTypeName.AddWithCheckAlreadyContained(item.textBlock.Data); } } finished = item.component != null; }
static void LoadContext_ProcessComponentsCreation(Metadata.LoadContext context, out bool changed, out bool finished, ESet <string> unableToGetTypeName) { changed = false; finished = true; foreach (var item in context.allComponentItemsCreationOrder) { LoadContext_ProcessComponentCreation(context, item, out bool changed2, out bool finished2, unableToGetTypeName); if (changed2) { changed = true; } if (!finished2) { finished = false; } } }
public bool BuildArchive() //string writeToDirectory ) { var destFileName = Path.Combine(writeToDirectory, GetIdentifier() + "-" + GetVersion() + ".neoaxispackage"); //check file already exists if (File.Exists(destFileName)) { var text = $"The file with name \'{destFileName}\' is already exists. Overwrite?"; if (EditorMessageBox.ShowQuestion(text, EMessageBoxButtons.OKCancel) == EDialogResult.Cancel) { return(false); } } try { var sourceDirectory = Path.GetDirectoryName(VirtualPathUtility.GetRealPathByVirtual(ComponentUtility.GetOwnedFileNameOfComponent(this))); //make zip if (File.Exists(destFileName)) { File.Delete(destFileName); } //prepare Package.info var packageInfoTempFileName = Path.GetTempFileName(); { var block = new TextBlock(); block.SetAttribute("Identifier", GetIdentifier()); block.SetAttribute("Title", Title.Value); block.SetAttribute("Version", GetVersion()); //!!!! block.SetAttribute("Author", "Share CC Attribution"); block.SetAttribute("Description", ShortDescription); //"ShortDescription" block.SetAttribute("FullDescription", FullDescription.Value); string license = ""; switch (License.Value) { case LicenseEnum.MIT: license = "MIT"; break; case LicenseEnum.CCAttribution: license = "CC Attribution"; break; case LicenseEnum.FreeToUse: license = "Free To Use"; break; case LicenseEnum.PaidPerSeat: license = "Paid Per Seat"; break; } block.SetAttribute("License", license); if (License.Value == LicenseEnum.PaidPerSeat) { block.SetAttribute("Cost", Cost.Value.ToString()); } { var s = ""; foreach (CategoryEnum flag in GetFlags(Categories.Value)) { if (flag != 0) { if (s.Length != 0) { s += ", "; } s += TypeUtility.DisplayNameAddSpaces(flag.ToString()); } } block.SetAttribute("Categories", s); } block.SetAttribute("Tags", Tags.Value); //!!!! var openAfterInstall = sourceDirectory.Substring(VirtualFileSystem.Directories.Assets.Length + 1); block.SetAttribute("OpenAfterInstall", openAfterInstall); //MustRestart = True //AddCSharpFilesToProject = "Store\\Simple Level Generator" File.WriteAllText(packageInfoTempFileName, block.DumpToString()); } string[] files; using (var archive = ZipFile.Open(destFileName, ZipArchiveMode.Create)) { files = Directory.GetFiles(sourceDirectory, "*", SearchOption.AllDirectories); foreach (var file in files) { if (Path.GetExtension(file) == ".store") { continue; } var entryName = file.Substring(VirtualFileSystem.Directories.Project.Length + 1); //var entryName = file.Substring( sourceDirectory.Length + 1 ); archive.CreateEntryFromFile(file, entryName); } archive.CreateEntryFromFile(packageInfoTempFileName, "Package.info"); } if (File.Exists(packageInfoTempFileName)) { File.Delete(packageInfoTempFileName); } //write info json { var jsonFileName = destFileName + ".json"; var sw = new StringWriter(); using (JsonWriter writer = new JsonTextWriter(sw)) { writer.Formatting = Formatting.Indented; writer.WriteStartObject(); writer.WritePropertyName("Author"); //!!!! //writer.WriteValue( "3" ); writer.WriteValue("Share CC Attribution"); writer.WritePropertyName("Identifier"); writer.WriteValue(GetIdentifier()); writer.WritePropertyName("Title"); writer.WriteValue(Title.Value); writer.WritePropertyName("License"); switch (License.Value) { case LicenseEnum.MIT: writer.WriteValue("MIT"); break; case LicenseEnum.CCAttribution: writer.WriteValue("CC Attribution"); break; case LicenseEnum.FreeToUse: writer.WriteValue("Free To Use"); break; case LicenseEnum.PaidPerSeat: writer.WriteValue("Paid Per Seat"); break; } //writer.WriteValue( License.Value.ToString() ); writer.WritePropertyName("Cost"); writer.WriteValue(Cost.Value.ToString()); writer.WritePropertyName("ShortDescription"); writer.WriteValue(ShortDescription.Value); writer.WritePropertyName("FullDescription"); writer.WriteValue(FullDescription.Value); { writer.WritePropertyName("Categories"); var s = ""; foreach (CategoryEnum flag in GetFlags(Categories.Value)) { if (flag != 0) { if (s.Length != 0) { s += ", "; } s += TypeUtility.DisplayNameAddSpaces(flag.ToString()); } } writer.WriteValue(s); //writer.WriteValue( Categories.Value.ToString() ); } writer.WritePropertyName("Tags"); writer.WriteValue(Tags.Value); writer.WritePropertyName("Version"); writer.WriteValue(GetVersion()); //writer.WriteEnd(); writer.WriteEndObject(); } File.WriteAllText(jsonFileName, sw.ToString()); } //try to create screenshots if (CreateScreenshots) { //find in the folder one import file (FBX, etc). make screenshot of 'Mesh' object inside the import file. var resourceType = ResourceManager.GetTypeByName("Import 3D"); var importExtensions = new ESet <string>(); foreach (var e in resourceType.FileExtensions) { importExtensions.AddWithCheckAlreadyContained("." + e); } var importVirtualFileNames = new List <string>(); foreach (var file in files) { var ext = Path.GetExtension(file); if (!string.IsNullOrEmpty(ext) && importExtensions.Contains(ext)) { var virtualFileName = VirtualPathUtility.GetVirtualPathByReal(file); if (!string.IsNullOrEmpty(virtualFileName)) { importVirtualFileNames.Add(virtualFileName); } } } if (importVirtualFileNames.Count == 1) { var import3D = ResourceManager.LoadResource <Component_Import3D>(importVirtualFileNames[0]); if (import3D != null) { var mesh = import3D.GetComponent <Component_Mesh>("Mesh"); if (mesh != null) { var generator = new MeshImageGenerator(); generator.Generate(mesh, destFileName + ".logo.png"); } } } } } catch (Exception e) { EditorMessageBox.ShowWarning(e.Message); return(false); } return(true); }
internal static void ParseDisableAssemblyNamespaceRegistration() { disableAssemblyRegistration = new ESet <string>(); disableNamespaceRegistration = new ESet <string>(); string realFileName = Path.Combine(VirtualFileSystem.Directories.Binaries, "NeoAxis.DefaultSettings.config"); if (File.Exists(realFileName)) { var block = TextBlockUtility.LoadFromRealFile(realFileName); if (block != null) { { var groupBlock = block.FindChild("DisableAssemblyRegistration"); if (groupBlock != null) { foreach (var itemBlock in groupBlock.Children) { if (itemBlock.Name == "Assembly") { bool disable = true; var platform = itemBlock.GetAttribute("Platform"); if (!string.IsNullOrEmpty(platform)) { if (string.Compare(SystemSettings.CurrentPlatform.ToString(), platform, true) != 0) { disable = false; } } if (disable) { var name = itemBlock.GetAttribute("Name"); disableAssemblyRegistration.AddWithCheckAlreadyContained(name); } } } } } { var groupBlock = block.FindChild("DisableNamespaceRegistration"); if (groupBlock != null) { foreach (var itemBlock in groupBlock.Children) { if (itemBlock.Name == "Namespace") { bool disable = true; var platform = itemBlock.GetAttribute("Platform"); if (!string.IsNullOrEmpty(platform)) { if (string.Compare(SystemSettings.CurrentPlatform.ToString(), platform, true) != 0) { disable = false; } } if (disable) { var name = itemBlock.GetAttribute("Name"); disableNamespaceRegistration.AddWithCheckAlreadyContained(name); } } } } } } } else { Log.Warning("AssemblyUtility: ParseDisableAssemblyNamespaceRegistration: \"NeoAxis.DefaultSettings.config\" is not exists."); } }
public override void Register() { //Upload to the Store { var a = new EditorAction(); //!!!! a.Name = "Prepare for the Store"; //a.Name = "Upload to the Store"; a.Description = "Uploads the selected product or all products in the selected folder to the NeoAxis Store."; a.CommonType = EditorAction.CommonTypeEnum.General; a.ImageSmall = Properties.Resources.Package_16; a.ImageBig = Properties.Resources.Package_32; a.QatSupport = true; a.ContextMenuSupport = EditorContextMenuWinForms.MenuTypeEnum.Resources; a.RibbonText = ("Upload", ""); a.GetState += delegate(EditorAction.GetStateContext context) { if (context.ObjectsInFocus.DocumentWindow == null && context.ObjectsInFocus.Objects.Length != 0) { var fileItems = context.ObjectsInFocus.Objects.OfType <ContentBrowserItem_File>(); foreach (var fileItem in fileItems) { if (fileItem.IsDirectory) { bool skip = false; if (context.Holder == EditorAction.HolderEnum.ContextMenu) { var files = Directory.GetFiles(fileItem.FullPath, "*.store", SearchOption.AllDirectories); if (files.Length == 0) { skip = true; } } if (!skip) { context.Enabled = true; break; } } if (!fileItem.IsDirectory && Path.GetExtension(fileItem.FullPath).ToLower() == ".store") { context.Enabled = true; break; } } } }; a.Click += delegate(EditorAction.ClickContext context) { if (context.ObjectsInFocus.DocumentWindow == null && context.ObjectsInFocus.Objects.Length != 0) { var realFileNames = new ESet <string>(); { var fileItems = context.ObjectsInFocus.Objects.OfType <ContentBrowserItem_File>(); foreach (var fileItem in fileItems) { if (fileItem.IsDirectory) { realFileNames.AddRangeWithCheckAlreadyContained(Directory.GetFiles(fileItem.FullPath, "*.store", SearchOption.AllDirectories)); } if (!fileItem.IsDirectory && Path.GetExtension(fileItem.FullPath).ToLower() == ".store") { realFileNames.AddWithCheckAlreadyContained(fileItem.FullPath); break; } } } var virtualFileNames = new List <string>(); foreach (var realFileName in realFileNames) { var virtualFileName = VirtualPathUtility.GetVirtualPathByReal(realFileName); if (VirtualFile.Exists(virtualFileName)) { virtualFileNames.Add(virtualFileName); } } if (virtualFileNames.Count == 0) { return; } var text = "Upload selected products to the store?\n\n"; foreach (var fileName in virtualFileNames) { text += fileName + "\n"; } if (EditorMessageBox.ShowQuestion(text, EMessageBoxButtons.OKCancel) == EDialogResult.Cancel) { return; } //process var item = ScreenNotifications.ShowSticky("Processing..."); try { foreach (var fileName in virtualFileNames) { var res = ResourceManager.LoadResource(fileName, true); if (res != null) { var product = res.ResultComponent as Component_StoreProduct; if (product != null) { if (!product.BuildArchive()) { return; } } } } } catch (Exception e) { Log.Warning(e.Message); return; } finally { item.Close(); } if (virtualFileNames.Count > 1) { ScreenNotifications.Show("The products were prepared successfully."); } else { ScreenNotifications.Show("The product was prepared successfully."); } //open folder in the Explorer Win32Utility.ShellExecuteEx(null, Component_StoreProduct.writeToDirectory); } }; EditorActions.Register(a); } }
public bool DoUpdate(ReimportSettings reimportSettings, out string error) { try { insideDoUpdate = true; if (reimportSettings == null) { reimportSettings = new ReimportSettings(); } error = ""; //bool createDocumentConfig = Components.Count == 0; //disable _Import3D bool wasEnabled = Enabled; Enabled = false; try { var settings = new ImportGeneral.Settings(); settings.updateMaterials = reimportSettings.UpdateMaterials; settings.updateMeshes = reimportSettings.UpdateMeshes; settings.updateObjectsInSpace = reimportSettings.UpdateObjectsInSpace; //remove old objects if (settings.updateObjectsInSpace) { var c = GetComponent("Object In Space"); if (c != null) { RemoveComponent(c, false); } c = GetComponent("Objects In Space"); if (c != null) { RemoveComponent(c, false); } } if (settings.updateMeshes) { var c = GetComponent("Mesh"); if (c != null) { RemoveComponent(c, false); } c = GetComponent("Meshes"); if (c != null) { RemoveComponent(c, false); } } if (settings.updateMaterials) { var c = GetComponent("Material"); if (c != null) { RemoveComponent(c, false); } c = GetComponent("Materials"); if (c != null) { RemoveComponent(c, false); } } if (Parent != null || ParentRoot.HierarchyController == null || ParentRoot.HierarchyController.CreatedByResource == null || !ParentRoot.HierarchyController.CreatedByResource.Owner.LoadFromFile) { error = "This component must be root of the resource."; return(false); } var virtualFileName = ParentRoot.HierarchyController.CreatedByResource.Owner.Name; settings.component = this; settings.virtualFileName = virtualFileName; if (Path.GetExtension(virtualFileName).ToLower() == ".json") { //Quixel Megascans ImportMegascans.DoImport(settings, out error); if (!string.IsNullOrEmpty(error)) { return(false); } } else if (Path.GetExtension(virtualFileName).ToLower() == ".fbx") { //FBX //settings.loadAnimations = true; //!!!!to options? settings.frameStep = .25; Import.FBX.ImportFBX.DoImport(settings, out error); if (!string.IsNullOrEmpty(error)) { return(false); } } else { //Assimp //settings.loadAnimations = false; ImportAssimp.DoImport(settings, out error); if (!string.IsNullOrEmpty(error)) { return(false); } } UpdatePostProcess?.Invoke(this, settings); //DeleteUnusedMaterials if (settings.updateMaterials && DeleteUnusedMaterials && !settings.disableDeletionUnusedMaterials) { var usedMaterials = new ESet <Component_Material>(); foreach (var meshGeometry in GetComponents <Component_MeshGeometry>(false, true)) { var material = meshGeometry.Material.Value; if (material != null) { usedMaterials.AddWithCheckAlreadyContained(material); } } again: foreach (var material in GetComponents <Component_Material>(false, true)) { if (!usedMaterials.Contains(material)) { material.RemoveFromParent(false); material.Dispose(); goto again; } } } } finally { //enable _Import3D if (wasEnabled) { Enabled = true; } } //set EditorDocumentConfiguration //if( createDocumentConfig ) { //!!!!что еще при Mode = Scene var toSelect = new List <Component>(); //root object toSelect.Add(this); //mesh var mesh = GetComponent("Mesh") as Component_Mesh; if (mesh != null) { toSelect.Add(mesh); } //materials var materials = GetComponents <Component_Material>(false, true); if (materials.Length <= 4) { foreach (var material in materials) { var graph = material.GetComponent <Component_FlowGraph>(); if (graph != null && graph.TypeSettingsIsPublic()) { toSelect.Add(graph); } } } //select window with mesh or select window with root object var selectObject = mesh != null ? (Component)mesh : this; EditorDocumentConfiguration = KryptonConfigGenerator.CreateEditorDocumentXmlConfiguration(toSelect, selectObject); //update windows //!!!!какие-то еще проверки? if (EngineApp.ApplicationType == EngineApp.ApplicationTypeEnum.Editor) { var document = EditorAPI.GetDocumentByObject(this); if (document != null) { ////close old windows //EditorAPI.CloseAllDocumentWindowsOnSecondLevel( document ); //open windows foreach (var obj in toSelect) { if (obj != this) { EditorAPI.OpenDocumentWindowForObject(document, obj); } } //delete old windows EditorAPI.CloseAllDocumentWindowsOnSecondLevelWithDeletedObjects(document); //select window var windows = EditorAPI.FindDocumentWindowsWithObject(selectObject); if (windows.Count != 0) { EditorAPI.SelectDockWindow(windows[0]); } } //!!!!or restore window configuration from EditorDocumentConfiguration } } } finally { insideDoUpdate = false; } return(true); }
static bool UpdateProjectFile_ManualParser(ICollection <string> addFiles, ICollection <string> removeFiles, out bool wasUpdated, out string error) { wasUpdated = false; error = ""; try { var xmldoc = new XmlDocument(); xmldoc.Load(GetProjectFileName()); if (removeFiles != null) { var removeFilesSet = new ESet <string>(); foreach (var fileName in removeFiles) { var fixedPath = fileName; if (Path.IsPathRooted(fixedPath)) { fixedPath = fixedPath.Replace(ProjectDir + Path.DirectorySeparatorChar, ""); } removeFilesSet.AddWithCheckAlreadyContained(fixedPath); } var nodesToRemove = new List <XmlNode>(); var list = xmldoc.SelectNodes("//Compile"); foreach (XmlNode node in list) { var name = node.Attributes["Include"].Value; if (removeFilesSet.Contains(name)) { nodesToRemove.Add(node); wasUpdated = true; } } foreach (var node in nodesToRemove.GetReverse()) { node.ParentNode.RemoveChild(node); } } if (addFiles != null) { XmlNode itemGroupNode = null; { var list = xmldoc.SelectNodes("//Compile"); foreach (XmlNode node in list) { itemGroupNode = node.ParentNode; break; } } if (itemGroupNode == null) { XmlNode projectNode = null; { var list = xmldoc.SelectNodes("//Project"); foreach (XmlNode node in list) { projectNode = node; break; } } if (projectNode == null) { throw new Exception("Project node not found."); } itemGroupNode = xmldoc.CreateNode(XmlNodeType.Element, "ItemGroup", null); projectNode.AppendChild(itemGroupNode); } foreach (var fileName in addFiles) { var fixedPath = fileName; if (Path.IsPathRooted(fixedPath)) { fixedPath = fixedPath.Replace(ProjectDir + Path.DirectorySeparatorChar, ""); } var node = xmldoc.CreateNode(XmlNodeType.Element, "Compile", null); var includeAttribute = xmldoc.CreateAttribute("Include"); includeAttribute.Value = fixedPath; node.Attributes.Append(includeAttribute); itemGroupNode.AppendChild(node); wasUpdated = true; } } if (wasUpdated) { xmldoc.Save(GetProjectFileName()); } } catch (Exception e) { error = e.Message; return(false); } return(true); }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //!!!! public static bool CanBeShaderParameter(Type type) { if (shaderParameterTypesSupported == null) { shaderParameterTypesSupported = new ESet <Type>(); shaderParameterTypesSupported.Add(typeof(bool)); shaderParameterTypesSupported.Add(typeof(sbyte)); shaderParameterTypesSupported.Add(typeof(byte)); shaderParameterTypesSupported.Add(typeof(char)); shaderParameterTypesSupported.Add(typeof(short)); shaderParameterTypesSupported.Add(typeof(ushort)); shaderParameterTypesSupported.Add(typeof(int)); shaderParameterTypesSupported.Add(typeof(uint)); //shaderParameterTypesSupported.Add( typeof( long ) ); //shaderParameterTypesSupported.Add( typeof( ulong ) ); shaderParameterTypesSupported.Add(typeof(float)); shaderParameterTypesSupported.Add(typeof(double)); shaderParameterTypesSupported.Add(typeof(Vector2F)); shaderParameterTypesSupported.Add(typeof(RangeF)); shaderParameterTypesSupported.Add(typeof(Vector3F)); shaderParameterTypesSupported.Add(typeof(Vector4F)); //shaderParameterTypesSupported.Add( typeof( BoundsF ) ); shaderParameterTypesSupported.Add(typeof(QuaternionF)); shaderParameterTypesSupported.Add(typeof(ColorValue)); shaderParameterTypesSupported.Add(typeof(ColorValuePowered)); shaderParameterTypesSupported.Add(typeof(SphericalDirectionF)); shaderParameterTypesSupported.Add(typeof(Vector2I)); shaderParameterTypesSupported.Add(typeof(Vector3I)); shaderParameterTypesSupported.Add(typeof(Vector4I)); shaderParameterTypesSupported.Add(typeof(RectangleF)); shaderParameterTypesSupported.Add(typeof(RectangleI)); shaderParameterTypesSupported.Add(typeof(DegreeF)); shaderParameterTypesSupported.Add(typeof(RadianF)); shaderParameterTypesSupported.Add(typeof(Vector2)); shaderParameterTypesSupported.Add(typeof(Range)); shaderParameterTypesSupported.Add(typeof(RangeI)); shaderParameterTypesSupported.Add(typeof(Vector3)); shaderParameterTypesSupported.Add(typeof(Vector4)); //shaderParameterTypesSupported.Add( typeof( Bounds ) ); shaderParameterTypesSupported.Add(typeof(Quaternion)); shaderParameterTypesSupported.Add(typeof(SphericalDirection)); shaderParameterTypesSupported.Add(typeof(Rectangle)); shaderParameterTypesSupported.Add(typeof(Degree)); shaderParameterTypesSupported.Add(typeof(Radian)); shaderParameterTypesSupported.Add(typeof(AnglesF)); shaderParameterTypesSupported.Add(typeof(Angles)); shaderParameterTypesSupported.Add(typeof(Matrix2F)); shaderParameterTypesSupported.Add(typeof(Matrix2)); shaderParameterTypesSupported.Add(typeof(Matrix3F)); shaderParameterTypesSupported.Add(typeof(Matrix3)); shaderParameterTypesSupported.Add(typeof(Matrix4F)); shaderParameterTypesSupported.Add(typeof(Matrix4)); shaderParameterTypesSupported.Add(typeof(PlaneF)); shaderParameterTypesSupported.Add(typeof(Plane)); } return(shaderParameterTypesSupported.Contains(type) || typeof(Component_Image).IsAssignableFrom(type)); }
public static Component_Mesh.StructureClass CreateMeshStructure(Face[] faces) { var result = new Component_Mesh.StructureClass(); int vertexMaxIndex = 0; //faces result.Faces = new Component_Mesh.StructureClass.Face[faces.Length]; for (int nFace = 0; nFace < faces.Length; nFace++) { var face = faces[nFace]; var triangles2 = new Component_Mesh.StructureClass.FaceVertex[face.Triangles.Length]; for (int n = 0; n < triangles2.Length; n++) { var faceVertex = face.Triangles[n]; triangles2[n] = new Component_Mesh.StructureClass.FaceVertex(faceVertex.Vertex, 0, faceVertex.RawVertex); vertexMaxIndex = Math.Max(vertexMaxIndex, faceVertex.Vertex); } result.Faces[nFace] = new Component_Mesh.StructureClass.Face(triangles2, null, 0); } //edges var edges = new ESet <Vector2I>(vertexMaxIndex * 3); for (int nFace = 0; nFace < faces.Length; nFace++) { var face = faces[nFace]; var edgeCounts = new Dictionary <Vector2I, int>(face.Triangles.Length); for (int nTriangle = 0; nTriangle < face.Triangles.Length / 3; nTriangle++) { var faceVertex0 = face.Triangles[nTriangle * 3 + 0]; var faceVertex1 = face.Triangles[nTriangle * 3 + 1]; var faceVertex2 = face.Triangles[nTriangle * 3 + 2]; void AddEdge(int vertex1, int vertex2) { int v1, v2; if (vertex1 > vertex2) { v1 = vertex2; v2 = vertex1; } else { v1 = vertex1; v2 = vertex2; } var key = new Vector2I(v1, v2); edgeCounts.TryGetValue(key, out var count); edgeCounts[key] = count + 1; } AddEdge(faceVertex0.Vertex, faceVertex1.Vertex); AddEdge(faceVertex1.Vertex, faceVertex2.Vertex); AddEdge(faceVertex2.Vertex, faceVertex0.Vertex); } foreach (var pair in edgeCounts) { if (pair.Value == 1) { var edge = pair.Key; edges.AddWithCheckAlreadyContained(new Vector2I(edge.X, edge.Y)); } } //for( int nTriangle = 0; nTriangle < face.Triangles.Length / 3; nTriangle++ ) //{ // var faceVertex0 = face.Triangles[ nTriangle * 3 + 0 ]; // var faceVertex1 = face.Triangles[ nTriangle * 3 + 1 ]; // var faceVertex2 = face.Triangles[ nTriangle * 3 + 2 ]; // void AddEdge( int vertex1, int vertex2 ) // { // int v1, v2; // if( vertex1 > vertex2 ) // { // v1 = vertex2; // v2 = vertex1; // } // else // { // v1 = vertex1; // v2 = vertex2; // } // edges.AddWithCheckAlreadyContained( new Vector2I( v1, v2 ) ); // } // AddEdge( faceVertex0.Vertex, faceVertex1.Vertex ); // AddEdge( faceVertex1.Vertex, faceVertex2.Vertex ); // AddEdge( faceVertex2.Vertex, faceVertex0.Vertex ); //} } result.Edges = edges.Select(e => new Component_Mesh.StructureClass.Edge(e.X, e.Y)).ToArray(); //vertices result.Vertices = new Component_Mesh.StructureClass.Vertex[vertexMaxIndex + 1]; return(result); }