/// @endcond /// @cond EXCLUDE_FROM_DOXYGEN /// <summary> /// Gets the image entries that require updating of the image quality score. /// </summary> /// <returns>A list of image entries that require updating of the image quality /// score.</returns> public List <AugmentedImageDatabaseEntry> GetDirtyQualityEntries() { var dirtyEntries = new List <AugmentedImageDatabaseEntry>(); string cliBinaryPath; if (!FindCliBinaryPath(out cliBinaryPath)) { return(dirtyEntries); } string currentCliVersion; { string error; #if !UNITY_EDITOR_WIN string output; ShellHelper.RunCommand("chmod", "+x " + cliBinaryPath, out output, out error); if (!string.IsNullOrEmpty(error)) { Debug.LogWarning(error); return(dirtyEntries); } #endif ShellHelper.RunCommand(cliBinaryPath, "version", out currentCliVersion, out error); if (!string.IsNullOrEmpty(error)) { Debug.LogWarning(error); return(dirtyEntries); } } bool cliUpdated = m_CliVersion != currentCliVersion; // When CLI is updated, mark all entries dirty. if (cliUpdated) { for (int i = 0; i < m_Images.Count; ++i) { AugmentedImageDatabaseEntry updatedImage = m_Images[i]; updatedImage.Quality = string.Empty; m_Images[i] = updatedImage; } m_CliVersion = currentCliVersion; EditorUtility.SetDirty(this); } for (int i = 0; i < m_Images.Count; ++i) { if (!string.IsNullOrEmpty(m_Images[i].Quality)) { continue; } dirtyEntries.Add(m_Images[i]); } return(dirtyEntries); }
/// <summary> /// Adds an image entry to the end of the database. /// </summary> /// <param name="entry">The image entry to add.</param> public void Add(AugmentedImageDatabaseEntry entry) { m_Images.Add(entry); m_IsRawDataDirty = true; EditorUtility.SetDirty(this); }
// creates augmented image database private UnityEngine.Object CreateArImageDatabase(List <SerializedProperty> anchorImageProps) { if (!Directory.Exists(SaveResourcePath)) { Directory.CreateDirectory(SaveResourcePath); AssetDatabase.Refresh(); } #if UNITY_ANDROID var imageDatabase = ScriptableObject.CreateInstance <GoogleARCore.AugmentedImageDatabase>(); for (int i = 0; i < anchorImageProps.Count; i++) { SerializedProperty property = anchorImageProps[i]; SerializedProperty imageProp = property.FindPropertyRelative("image"); SerializedProperty widthProp = property.FindPropertyRelative("width"); if (imageProp == null || imageProp.objectReferenceValue == null) { continue; } Object imageObj = imageProp.objectReferenceValue; string assetPath = AssetDatabase.GetAssetPath(imageObj); var fileName = Path.GetFileName(assetPath); var imageName = fileName.Replace(Path.GetExtension(fileName), string.Empty); GoogleARCore.AugmentedImageDatabaseEntry newEntry = new GoogleARCore.AugmentedImageDatabaseEntry(imageName, AssetDatabase.LoadAssetAtPath <Texture2D>(assetPath), widthProp.floatValue); imageDatabase.Add(newEntry); } string saveImageDbPath = Path.Combine(SaveResourcePath, ArCoreImageDatabase); if (File.Exists(saveImageDbPath)) { AssetDatabase.DeleteAsset(saveImageDbPath); } //saveDbPath = AssetDatabase.GenerateUniqueAssetPath(saveDbPath); AssetDatabase.CreateAsset(imageDatabase, saveImageDbPath); // // build the database // string sError = string.Empty; // newDatabase.BuildIfNeeded(out sError); // // if (!string.IsNullOrEmpty(sError)) // { // Debug.LogError(sError); // } return(imageDatabase); #elif UNITY_IOS var imageDatabase = ScriptableObject.CreateInstance <ARReferenceImagesSet>(); imageDatabase.resourceGroupName = "ArKitImageDatabase"; imageDatabase.referenceImages = new ARReferenceImage[anchorImageProps.Count]; for (int i = 0; i < anchorImageProps.Count; i++) { SerializedProperty property = anchorImageProps[i]; SerializedProperty imageProp = property.FindPropertyRelative("image"); SerializedProperty widthProp = property.FindPropertyRelative("width"); if (imageProp == null || imageProp.objectReferenceValue == null) { continue; } Object imageObj = imageProp.objectReferenceValue; Texture2D imageTex = imageObj as Texture2D; if (imageTex != null) { var imageRef = ScriptableObject.CreateInstance <ARReferenceImage>(); imageRef.imageTexture = imageTex; imageRef.imageName = imageTex.name; imageRef.physicalSize = widthProp.floatValue; string saveImageRefPath = Path.Combine(SaveResourcePath, "ArKitImageRef" + i + ".asset"); if (File.Exists(saveImageRefPath)) { AssetDatabase.DeleteAsset(saveImageRefPath); } AssetDatabase.CreateAsset(imageRef, saveImageRefPath); imageDatabase.referenceImages[i] = AssetDatabase.LoadAssetAtPath <ARReferenceImage>(saveImageRefPath); } } string saveImageDbPath = Path.Combine(SaveResourcePath, ArKitImageDatabase); if (File.Exists(saveImageDbPath)) { AssetDatabase.DeleteAsset(saveImageDbPath); } AssetDatabase.CreateAsset(imageDatabase, saveImageDbPath); return(imageDatabase); #else return(null); #endif }