private IEnumerator LoadImageBuffer(easyar.Buffer buffer, string name, float scale)
        {
            using (buffer)
            {
                Optional <Image> imageOptional = null;
                bool             taskFinished  = false;
                EasyARController.Instance.Worker.Run(() =>
                {
                    imageOptional = ImageHelper.decode(buffer);
                    taskFinished  = true;
                });

                while (!taskFinished)
                {
                    yield return(0);
                }
                if (imageOptional.OnNone)
                {
                    throw new Exception("invalid buffer");
                }
                using (var image = imageOptional.Value)
                {
                    CreateMultipleTargetsFromOneImage(image, 10, name, scale);
                }
            }
        }
Example #2
0
    private IEnumerator LoadImageTarget()
    {
        var path = TargetPath;
        var type = Type;
        WWW www;

        if (type == PathType.Absolute)
        {
            path = Utility.AddFileHeader(path);
#if UNITY_ANDROID && !UNITY_EDITOR
            path = "file://" + path;
#endif
        }
        else if (type == PathType.StreamingAssets)
        {
            path = Utility.AddFileHeader(Application.streamingAssetsPath + "/" + path);
        }
        Debug.Log("[EasyAR]:" + path);
        www = new WWW(path);
        while (!www.isDone)
        {
            yield return(0);
        }
        if (!string.IsNullOrEmpty(www.error))
        {
            Debug.LogError(www.error);
            www.Dispose();
            yield break;
        }
        var           data   = www.bytes;
        easyar.Buffer buffer = easyar.Buffer.create(data.Length);
        var           ptr    = buffer.data();
        Marshal.Copy(data, 0, ptr, data.Length);

        Optional <easyar.ImageTarget> op_target;
        if (targetType == TargetType.LocalImage)
        {
            var image = ImageHelper.decode(buffer);
            if (!image.OnSome)
            {
                throw new System.Exception("decode image file data failed");
            }

            var p = new ImageTargetParameters();
            p.setImage(image.Value);
            p.setName(TargetName);
            p.setScale(TargetSize);
            p.setUid("");
            p.setMeta("");
            op_target = ImageTarget.createFromParameters(p);

            if (!op_target.OnSome)
            {
                throw new System.Exception("create image target failed from image target parameters");
            }

            image.Value.Dispose();
            buffer.Dispose();
            p.Dispose();
        }
        else
        {
            op_target = ImageTarget.createFromTargetData(buffer);

            if (!op_target.OnSome)
            {
                throw new System.Exception("create image target failed from image target target data");
            }

            buffer.Dispose();
        }

        target = op_target.Value;
        Destroy(www.texture);
        www.Dispose();
        if (ImageTracker == null)
        {
            yield break;
        }
        ImageTracker.LoadImageTarget(this, (_target, status) =>
        {
            targetImage = ((_target as ImageTarget).images())[0];
            Debug.Log("[EasyAR] Targtet name: " + _target.name() + " target runtimeID: " + _target.runtimeID() + " load status: " + status);
            Debug.Log("[EasyAR] Target size" + targetImage.width() + " " + targetImage.height());
        });
    }