public override void Write(string pathToResourceGroup)
        {
            // Get the path to the object
            var pathToObjectInUnityProject = m_Path;
            var objectFilename             = Path.GetFileName(pathToObjectInUnityProject);

            // Create the ARReferenceObject in Xcode
            var pathToReferenceObjectInXcode = Path.Combine(pathToResourceGroup, filename);

            Directory.CreateDirectory(pathToReferenceObjectInXcode);

            // Unzip the .arobject into Xcode
            ZipFile.ExtractToDirectory(pathToObjectInUnityProject, pathToReferenceObjectInXcode);

            // Read the plist for the Contents.json
            var pathToPlist = Path.Combine(pathToReferenceObjectInXcode, "Info.plist");
            var plist       = new XmlDocument();

            plist.Load(pathToPlist);
            var info = new ARObjectInfo(plist);

            // Translate the plist into Contents.json
            var contents = new Json.ReferenceObject
            {
                info = new Json.AuthorInfo
                {
                    version = 1,
                    author  = "unity"
                },
                properties = new Json.ObjectProperties
                {
                    preview  = info.imageReference,
                    rotation = new float[4]
                    {
                        info.referenceOrigin.rotation.x,
                        info.referenceOrigin.rotation.y,
                        -info.referenceOrigin.rotation.z,
                        -info.referenceOrigin.rotation.w
                    },
                    content     = info.trackingDataReference,
                    translation = new float[3]
                    {
                        info.referenceOrigin.position.x,
                        info.referenceOrigin.position.y,
                        -info.referenceOrigin.position.z
                    },
                    version = info.version
                }
            };

            File.WriteAllText(Path.Combine(pathToReferenceObjectInXcode, "Contents.json"), JsonUtility.ToJson(contents));
            File.Delete(pathToPlist);
        }
Пример #2
0
        static Texture2D GetImageReference(ZipArchive archive, ARObjectInfo info)
        {
            var imageReferenceEntry = archive.Entries
                                      .FirstOrDefault(entry => string.Equals(entry.Name, info.imageReference, StringComparison.OrdinalIgnoreCase));

            if (imageReferenceEntry == null)
            {
                return(null);
            }

            var imageReference = new Texture2D(1, 1);

            using var memoryStream = new MemoryStream();
            imageReferenceEntry.Open().CopyTo(memoryStream);
            if (imageReference.LoadImage(memoryStream.ToArray()))
            {
                return(RotateTextureClockwise(imageReference));
            }

            Destroy(imageReference);
            return(null);
        }
Пример #3
0
 /// <summary>
 /// Constructs an <see cref="ARObject"/>.
 /// </summary>
 /// <param name="info">The <see cref="ARObjectInfo"/> associated with this <see cref="ARObject"/>.</param>
 /// <param name="preview">A preview image associated with the <c>ARObject</c>.</param>
 public ARObject(ARObjectInfo info, Texture2D preview)
 {
     this.info    = info;
     this.preview = preview;
 }