static IEnumerable <ARResourceGroup> ResourceGroups()
        {
            // Create a resource group for each reference image library
            foreach (var library in ARKitBuildProcessor.AssetsOfType <XRReferenceImageLibrary>())
            {
                var resourceGroup = new ARResourceGroup(library.name + "_" + library.guid.ToUUIDString());

                // Create a resource group for each library
                foreach (var referenceImage in library)
                {
                    try
                    {
                        resourceGroup.AddResource(new ARReferenceImage(referenceImage));
                    }
                    catch (ARReferenceImage.InvalidWidthException)
                    {
                        throw new BuildFailedException(string.Format("ARKit requires dimensions for all images. Reference image at index {0} named '{1}' in library '{2}' requires a non-zero width.",
                                                                     library.indexOf(referenceImage), referenceImage.name, AssetDatabase.GetAssetPath(library)));
                    }
                    catch (ARReferenceImage.MissingTextureException)
                    {
                        throw new BuildFailedException(string.Format("Reference image at index {0} named '{1}' in library '{2}' is missing a texture.",
                                                                     library.indexOf(referenceImage), referenceImage.name, AssetDatabase.GetAssetPath(library)));
                    }
                    catch (ARReferenceImage.BadTexturePathException)
                    {
                        throw new BuildFailedException(string.Format("Could not resolve texture path for reference image at index {0} named '{1}' in library '{2}'.",
                                                                     library.indexOf(referenceImage), referenceImage.name, AssetDatabase.GetAssetPath(library)));
                    }
                    catch (ARReferenceImage.LoadTextureException e)
                    {
                        throw new BuildFailedException(string.Format("Could not load texture at path {0} for reference image at index {1} named '{2}' in library '{3}'.",
                                                                     e.path, library.indexOf(referenceImage), referenceImage.name, AssetDatabase.GetAssetPath(library)));
                    }
                    catch (ARReferenceImage.TextureNotExportableException)
                    {
                        throw new BuildFailedException(string.Format(
                                                           "Reference image at index {0} named '{1}' in library '{2}' could not be exported. " +
                                                           "ARKit can directly use a texture's source asset if it is a JPG or PNG. " +
                                                           "For all other formats, the texture must be exported to PNG, which requires the texture to be readable and uncompressed. " +
                                                           "Change the Texture Import Settings or use a JPG or PNG.",
                                                           library.indexOf(referenceImage), referenceImage.name, AssetDatabase.GetAssetPath(library)));
                    }
                    catch
                    {
                        Debug.LogErrorFormat("Failed to generate reference image at index {0} named '{1}' in library '{2}'.",
                                             library.indexOf(referenceImage), referenceImage.name, AssetDatabase.GetAssetPath(library));

                        throw;
                    }
                }

                yield return(resourceGroup);
            }
        }
Beispiel #2
0
        public void AddResourceGroup(ARResourceGroup group)
        {
            if (group == null)
            {
                throw new ArgumentNullException("group");
            }

            if (m_ResourceGroups.Contains(group))
            {
                throw new InvalidOperationException(string.Format("Duplicate resource group '{0}'", group.name));
            }

            m_ResourceGroups.Add(group);
        }
        static IEnumerable <ARResourceGroup> ResourceGroups(Warnings warnings)
        {
            foreach (var library in ARKitBuildProcessor.AssetsOfType <XRReferenceObjectLibrary>())
            {
                // Create a resource group for each reference object library
                var resourceGroup = new ARResourceGroup(library.name + "_" + library.guid.ToString().ToUpper());
                int resourceCount = 0;

                foreach (var referenceObject in library)
                {
                    if (string.IsNullOrEmpty(referenceObject.name) && (warnings & Warnings.MissingName) != 0)
                    {
                        Debug.LogWarningFormat("Reference object {0} named '{1}' in library {2} does not have a name. The reference object will still work, but you will not be able to refer to it by name.",
                                               library.indexOf(referenceObject), referenceObject.name, AssetDatabase.GetAssetPath(library));
                    }

                    var arkitEntry = referenceObject.FindEntry <ARKitReferenceObjectEntry>();
                    if (arkitEntry == null)
                    {
                        if ((warnings & Warnings.MissingEntry) != 0)
                        {
                            Debug.LogWarningFormat("The ARKit variant for reference object {0} named '{1}' in library {2} is missing. This reference object will omitted from the library.",
                                                   library.indexOf(referenceObject), referenceObject.name, AssetDatabase.GetAssetPath(library));
                        }
                    }
                    else
                    {
                        try
                        {
                            resourceGroup.AddResource(new ARReferenceObject(referenceObject, arkitEntry));
                            resourceCount++;
                        }
                        catch (ARReferenceObject.InvalidAssetPathException)
                        {
                            throw new BuildFailedException(string.Format(
                                                               "The ARKit variant for reference object {0} named '{1}' in reference object library {2} does not refer to a valid asset file.",
                                                               library.indexOf(referenceObject), referenceObject.name, AssetDatabase.GetAssetPath(library)));
                        }
                        catch (ARReferenceObject.MissingMetadataException)
                        {
                            throw new BuildFailedException(string.Format(
                                                               "The ARKit variant for reference object {0} named '{1}' in reference object library {2} could not be read. The arobject file may be corrupt.",
                                                               library.indexOf(referenceObject), referenceObject.name, AssetDatabase.GetAssetPath(library)));
                        }
                        catch (ARReferenceObject.MissingTrackingDataException)
                        {
                            throw new BuildFailedException(string.Format(
                                                               "The ARKit variant for reference object {0} named '{1}' in reference object library {2} is missing tracking data (the 3D object scan data). The arobject file may be corrupt.",
                                                               library.indexOf(referenceObject), referenceObject.name, AssetDatabase.GetAssetPath(library)));
                        }
                    }
                }

                if ((resourceCount == 0) && (warnings & Warnings.EmptyLibrary) != 0)
                {
                    Debug.LogWarningFormat("Reference object library at {0} does not contain any ARKit reference objects. The library will be empty.",
                                           AssetDatabase.GetAssetPath(library));
                }

                yield return(resourceGroup);
            }
        }