Пример #1
0
    public uint Update()
    {
        if (wasInitialized)
        {
            if (isMobile)
            {
                if (Screen.orientation != currentOrientation && Time.frameCount > 1)
                {
                    ApplyViewSettings();

                    MobileWrapper.String_SetProjectionAndViewport(_camera.projectionMatrix, _camera.rect, (int)(currentOrientation = Screen.orientation), _reorientIPhoneSplash);
                }

                markerCount = MobileWrapper.String_GetData(markerInfo, maxMarkerCount);
            }
            else
            {
                if (DesktopWrapper.IsNewFrameReady())
                {
                    DesktopWrapper.ProcessFrame((uint)videoTextures[0].GetNativeTextureID(), 0);
                    markerCount             = DesktopWrapper.GetDataQuaternionBased(markerInfo, maxMarkerCount);
                    videoPlaneObject.active = true;
                }
            }
        }
        else
        {
            // Write dummy output data
            markerCount = 1;
            markerInfo[0].DummyData();
        }

        return(markerCount);
    }
Пример #2
0
    public int LoadImageMarker(string fileName, string extension)
    {
        if (wasInitialized)
        {
            if (isMobile)
            {
                return(MobileWrapper.String_LoadImageMarker("Data/Raw/" + fileName, extension));
            }
            else
            {
                string path = Application.dataPath + "/StreamingAssets/" + fileName;

                int id = DesktopWrapper.LoadImageMarker(path, extension);

                if (id < 0)
                {
                    Debug.LogWarning("Failed to load marker image \"" + path + "." + extension + "\"");
                }
                else
                {
                    Debug.Log("Loaded marker image \"" + path + "." + extension + "\"");
                }

                return(id);
            }
        }
        else
        {
            return(-1);
        }
    }
Пример #3
0
 /// <summary>
 ///   Refreshes toolbar graphics
 /// </summary>
 internal void Refresh() => DesktopWrapper?.Invalidate();
Пример #4
0
    void InitializePreviewPlugin(string preferredDeviceName, Camera camera)
    {
        // Test library compatibility
        if (DesktopWrapper.GetInterfaceVersion() != 3)
        {
            Debug.LogError("You appear to be using incompatible versions of StringWrapper.cs and String.bundle; Please make sure you're using the latest versions of both.");

            return;
        }

        // Enumerate devices
        uint maxDeviceCount = 10;

        DeviceInfo[] deviceInfo = new DeviceInfo[maxDeviceCount];

        uint deviceCount = DesktopWrapper.EnumerateDevices(deviceInfo, maxDeviceCount);

        for (int i = 0; i < deviceCount; i++)
        {
            Debug.Log("Found camera \"" + deviceInfo[i].name + "\" (" + (deviceInfo[i].isAvailable ? "available for use.)" : "not available for use.)"));
        }

        if (deviceCount > 0)
        {
            uint i;

            for (i = 0; i < deviceCount; i++)
            {
                if (deviceInfo[i].name == preferredDeviceName)
                {
                    break;
                }
            }

            if (i < deviceCount)
            {
                Debug.Log("Capturing video from preferred device \"" + deviceInfo[i].name + "\".");
            }
            else
            {
                i = 0;

                if (preferredDeviceName != null)
                {
                    Debug.Log("Preferred device was not found. Using \"" + deviceInfo[i].name + "\".");
                }
                else
                {
                    Debug.Log("Capturing video from device \"" + deviceInfo[i].name + "\".");
                }
            }

            if (DesktopWrapper.InitTracker(deviceInfo[i].id, ref previewWidth, ref previewHeight, _previewCamApproxVerticalFOV))
            {
                CreateVideoMaterial();
                CreateVideoMesh();

                float scale = camera.farClipPlane * 0.99f;

                float verticalScale = scale * Mathf.Tan(_previewCamApproxVerticalFOV * Mathf.PI / 360f);

                videoPlaneObject           = new GameObject("Video Plane", new Type[] { typeof(MeshRenderer), typeof(MeshFilter) });
                videoPlaneObject.hideFlags = HideFlags.HideAndDontSave;
                videoPlaneObject.active    = false;

                videoPlaneObject.renderer.material = videoMaterial;

                MeshFilter meshFilter = (MeshFilter)videoPlaneObject.GetComponent(typeof(MeshFilter));
                meshFilter.sharedMesh = videoPlaneMesh;

                videoPlaneObject.transform.parent        = camera.transform;
                videoPlaneObject.transform.localPosition = new Vector3(0, 0, scale);
                videoPlaneObject.transform.localRotation = Quaternion.identity;
                videoPlaneObject.transform.localScale    = new Vector3(verticalScale * (float)previewWidth / previewHeight, verticalScale, 1);

                wasInitialized = true;
            }
            else
            {
                Debug.Log("Failed to initialize String.");
            }
        }
        else
        {
            Debug.LogError("No devices suitable for video capture were detected.");
        }
    }