private int InitCameraDevice(int camera)
 {
     if (VuforiaRuntimeUtilities.IsPlayMode())
     {
         int result = 0;
         try
         {
             WebCamARController expr_0E = WebCamARController.Instance;
             expr_0E.InitCamera();
             CameraDeviceImpl.mWebCam = expr_0E.ImplementationClass;
             VuforiaRenderer.Vec2I resampledTextureSize = CameraDeviceImpl.mWebCam.ResampledTextureSize;
             if (resampledTextureSize.y != 0)
             {
                 VuforiaWrapper.Instance.CameraDeviceSetCameraConfiguration(resampledTextureSize.x, resampledTextureSize.y);
             }
             result = 1;
         }
         catch (NullReferenceException arg_4B_0)
         {
             Debug.LogError(arg_4B_0.Message);
         }
         VuforiaWrapper.Instance.CameraDeviceInitCamera(camera);
         this.mCameraImages.Clear();
         return(result);
     }
     return(VuforiaWrapper.Instance.CameraDeviceInitCamera(camera));
 }
Example #2
0
        public static VuforiaRenderer.Vec2I ScreenSpaceToCameraFrameCoordinates(Vector2 screenSpaceCoordinate, Rect bgTextureViewPortRect, bool isTextureMirrored, CameraDevice.VideoModeData videoModeData)
        {
            float xMin   = bgTextureViewPortRect.xMin;
            float yMin   = bgTextureViewPortRect.yMin;
            float width  = bgTextureViewPortRect.width;
            float height = bgTextureViewPortRect.height;
            bool  flag   = false;
            float num    = (float)videoModeData.width;
            float num2   = (float)videoModeData.height;
            float num3   = 0f;
            float num4   = 0f;
            float num5   = 0f;
            float num6   = 0f;

            VuforiaRuntimeUtilities.PrepareCoordinateConversion(isTextureMirrored, ref num3, ref num4, ref num5, ref num6, ref flag);
            float num7 = (screenSpaceCoordinate.x - xMin) / width;
            float num8 = (screenSpaceCoordinate.y - yMin) / height;

            VuforiaRenderer.Vec2I result;
            if (flag)
            {
                result = new VuforiaRenderer.Vec2I(Mathf.RoundToInt((num3 + num5 * num8) * num), Mathf.RoundToInt((num4 + num6 * num7) * num2));
            }
            else
            {
                result = new VuforiaRenderer.Vec2I(Mathf.RoundToInt((num3 + num5 * num7) * num), Mathf.RoundToInt((num4 + num6 * num8) * num2));
            }
            return(result);
        }
Example #3
0
 public WebCamTexAdaptorImpl(string deviceName, int requestedFPS, VuforiaRenderer.Vec2I requestedTextureSize)
 {
     this.mWebCamTexture                 = new WebCamTexture();
     this.mWebCamTexture.deviceName      = deviceName;
     this.mWebCamTexture.requestedFPS    = (float)requestedFPS;
     this.mWebCamTexture.requestedWidth  = requestedTextureSize.x;
     this.mWebCamTexture.requestedHeight = requestedTextureSize.y;
 }
Example #4
0
 public NullWebCamTexAdaptor(int requestedFPS, VuforiaRenderer.Vec2I requestedTextureSize)
 {
     this.mTexture         = new Texture2D(requestedTextureSize.x, requestedTextureSize.y);
     this.mMsBetweenFrames = 1000.0 / (double)requestedFPS;
     this.mLastFrame       = DateTime.Now - TimeSpan.FromDays(1.0);
     if (VuforiaRuntimeUtilities.IsVuforiaEnabled())
     {
         PlayModeEditorUtility.Instance.DisplayDialog("Error occurred!", "No camera connected!\nTo run your application using Play Mode, please connect a webcam to your computer.", "Ok");
         Debug.LogError("No camera connected!\nTo run your application using Play Mode, please connect a webcam to your computer.");
     }
 }
Example #5
0
        public override bool SetRegionOfInterest(Rect detectionRegion, Rect trackingRegion)
        {
            VuforiaARController expr_05        = VuforiaARController.Instance;
            Rect videoBackgroundRectInViewPort = expr_05.GetVideoBackgroundRectInViewPort();
            bool flag = expr_05.VideoBackGroundMirrored == VuforiaRenderer.VideoBackgroundReflection.ON;

            CameraDevice.VideoModeData videoMode = CameraDevice.Instance.GetVideoMode();
            Vector2 screenSpaceCoordinate;
            Vector2 screenSpaceCoordinate2;

            VuforiaRuntimeUtilities.SelectRectTopLeftAndBottomRightForLandscapeLeft(detectionRegion, flag, out screenSpaceCoordinate, out screenSpaceCoordinate2);
            Vector2 screenSpaceCoordinate3;
            Vector2 screenSpaceCoordinate4;

            VuforiaRuntimeUtilities.SelectRectTopLeftAndBottomRightForLandscapeLeft(trackingRegion, flag, out screenSpaceCoordinate3, out screenSpaceCoordinate4);
            VuforiaRenderer.Vec2I vec2I  = VuforiaRuntimeUtilities.ScreenSpaceToCameraFrameCoordinates(screenSpaceCoordinate, videoBackgroundRectInViewPort, flag, videoMode);
            VuforiaRenderer.Vec2I vec2I2 = VuforiaRuntimeUtilities.ScreenSpaceToCameraFrameCoordinates(screenSpaceCoordinate2, videoBackgroundRectInViewPort, flag, videoMode);
            VuforiaRenderer.Vec2I vec2I3 = VuforiaRuntimeUtilities.ScreenSpaceToCameraFrameCoordinates(screenSpaceCoordinate3, videoBackgroundRectInViewPort, flag, videoMode);
            VuforiaRenderer.Vec2I vec2I4 = VuforiaRuntimeUtilities.ScreenSpaceToCameraFrameCoordinates(screenSpaceCoordinate4, videoBackgroundRectInViewPort, flag, videoMode);
            if (VuforiaWrapper.Instance.TextTrackerSetRegionOfInterest(vec2I.x, vec2I.y, vec2I2.x, vec2I2.y, vec2I3.x, vec2I3.y, vec2I4.x, vec2I4.y, (int)this.CurrentUpDirection) == 0)
            {
                Debug.LogError(string.Format("Could not set region of interest: ({0}, {1}, {2}, {3}) - ({4}, {5}, {6}, {7})", new object[]
                {
                    detectionRegion.x,
                    detectionRegion.y,
                    detectionRegion.width,
                    detectionRegion.height,
                    trackingRegion.x,
                    trackingRegion.y,
                    trackingRegion.width,
                    trackingRegion.height
                }));
                return(false);
            }
            return(true);
        }
 public void Update()
 {
     if (VuforiaRuntimeUtilities.IsPlayMode())
     {
         this.mWebCamTexture.CheckPermissions();
         if (!this.IsTextureSizeAvailable && this.mWebCamTexture.DidUpdateThisFrame)
         {
             this.IsTextureSizeAvailable = true;
             if (this.mWebCamProfile.ResampledTextureSize.y == 0)
             {
                 this.ComputeResampledTextureSize();
                 VuforiaWrapper.Instance.CameraDeviceStopCamera();
                 VuforiaWrapper.Instance.CameraDeviceDeinitCamera();
                 VuforiaWrapper.Instance.CameraDeviceSetCameraConfiguration(this.mWebCamProfile.ResampledTextureSize.x, this.mWebCamProfile.ResampledTextureSize.y);
                 VuforiaWrapper.Instance.CameraDeviceInitCamera(1);
                 VuforiaWrapper.Instance.CameraDeviceSelectVideoMode(-1);
                 VuforiaWrapper.Instance.CameraDeviceStartCamera();
             }
             VuforiaRenderer.Vec2I resampledTextureSize = this.mWebCamProfile.ResampledTextureSize;
             this.mVideoModeData = new CameraDevice.VideoModeData
             {
                 width     = resampledTextureSize.x,
                 height    = resampledTextureSize.y,
                 frameRate = (float)this.mWebCamProfile.RequestedFPS
             };
             this.mVideoTextureInfo = new VuforiaRenderer.VideoTextureInfo
             {
                 imageSize   = resampledTextureSize,
                 textureSize = resampledTextureSize
             };
             this.mTextureRenderer   = new TextureRenderer(this.mWebCamTexture.Texture, this.mRenderTextureLayer, resampledTextureSize);
             this.mBufferReadTexture = new Texture2D(resampledTextureSize.x, resampledTextureSize.y);
             this.mReadPixelsRect    = new Rect(0f, 0f, (float)resampledTextureSize.x, (float)resampledTextureSize.y);
         }
     }
 }
        public TextureRenderer(Texture textureToRender, int renderTextureLayer, VuforiaRenderer.Vec2I requestedTextureSize)
        {
            if (renderTextureLayer > 31)
            {
                Debug.LogError("WebCamBehaviour.SetupTextureBufferCamera: configured layer > 31 is not supported by Unity!");
                return;
            }
            this.mTextureWidth  = requestedTextureSize.x;
            this.mTextureHeight = requestedTextureSize.y;
            float      num        = (float)this.mTextureHeight / (float)this.mTextureWidth * 0.5f;
            GameObject gameObject = new GameObject("TextureBufferCamera");

            this.mTextureBufferCamera = gameObject.AddComponent <Camera>();
            this.mTextureBufferCamera.orthographic       = true;
            this.mTextureBufferCamera.orthographicSize   = num;
            this.mTextureBufferCamera.aspect             = (float)this.mTextureWidth / (float)this.mTextureHeight;
            this.mTextureBufferCamera.nearClipPlane      = 0.5f;
            this.mTextureBufferCamera.farClipPlane       = 1.5f;
            this.mTextureBufferCamera.cullingMask        = 1 << renderTextureLayer;
            this.mTextureBufferCamera.enabled            = false;
            this.mTextureBufferCamera.transform.position = new Vector3(-1000f, -1000f, -1000f);
            UnityEngine.Object.DontDestroyOnLoad(gameObject);
            GameObject gameObject2 = new GameObject("TextureBufferMesh", new Type[]
            {
                typeof(MeshFilter),
                typeof(MeshRenderer)
            });

            gameObject2.transform.parent        = gameObject.transform;
            gameObject2.transform.localPosition = Vector3.zero;
            gameObject2.layer = renderTextureLayer;
            Mesh mesh = new Mesh();

            mesh.vertices = new Vector3[]
            {
                new Vector3(-0.5f, num, 1f),
                new Vector3(0.5f, num, 1f),
                new Vector3(-0.5f, -num, 1f),
                new Vector3(0.5f, -num, 1f)
            };
            mesh.uv = new Vector2[]
            {
                new Vector2(0f, 0f),
                new Vector2(1f, 0f),
                new Vector2(0f, 1f),
                new Vector2(1f, 1f)
            };
            mesh.triangles = new int[]
            {
                0,
                1,
                2,
                2,
                1,
                3
            };
            Mesh         mesh2    = mesh;
            MeshRenderer expr_23F = gameObject2.GetComponent <MeshRenderer>();

            expr_23F.material             = new Material(Shader.Find("Unlit/Texture"));
            expr_23F.material.mainTexture = textureToRender;
            gameObject2.GetComponent <MeshFilter>().mesh = mesh2;
        }