예제 #1
0
        public Texture2D GenerateTexture(int camIndex)
        {
            GameObject        viewingCam = viewingCamManager.ViewingCameras[camIndex];
            WebcamDeviceNames deviceName = viewingCam.GetComponent <WebCamIdentifier>().DeviceName;
            WebCamSpecs       specs      = WebCamSpecsManager.GetSpecs(deviceName);
            WebCamTexture     webFeed    = viewingCam.GetComponent <WebCamIdentifier>().WebCamFeed;

            int width  = specs.HorizontalResolution;
            int height = specs.VerticalResolution;

            // https://forum.unity.com/threads/webcamtexture-texture2d.154057/
            // Tie the texture to the webcam feed texture associated with a viewing camera
            Texture2D tex = new Texture2D(width, height, TextureFormat.RGBA32, false);

            ////var ptr = webFeed.GetNativeTexturePtr();
            ////Debug.Log(ptr);
            ////Texture2D exTex = Texture2D.CreateExternalTexture(width, height, TextureFormat.RGBA32, false, false, ptr);
            ////Debug.Log("Created external texture");
            //tex.UpdateExternalTexture(webFeed.GetNativeTexturePtr());
            //tex.Apply();
            Graphics.CopyTexture(webFeed, tex);
            tex.name = webFeed.name;

            return(tex);
        }
        public void Update()
        {
            WebCamSpecs specs = WebCamSpecsManager.GetSpecs(WebcamDeviceNames.NULL);

            switch (WebcamDeviceName)
            {
            case WebcamDeviceNames.ADESSO_CYBERTRACK_V10:
                specs = WebCamSpecsManager.GetSpecs(WebcamDeviceNames.ADESSO_CYBERTRACK_V10);
                break;

            case WebcamDeviceNames.LAPTOP_WEBCAM:
                specs = WebCamSpecsManager.GetSpecs(WebcamDeviceNames.LAPTOP_WEBCAM);
                break;

            case WebcamDeviceNames.LOGITECH_C920:
                specs = WebCamSpecsManager.GetSpecs(WebcamDeviceNames.LOGITECH_C920);
                break;

            case WebcamDeviceNames.NULL:
                specs = WebCamSpecsManager.GetSpecs(WebcamDeviceNames.NULL);
                break;
            }

            SetReviewedInfo(specs);
        }
        public GameObject GenerateViewingCamera(int camIndex)
        {
            GameObject viewingCam = new GameObject();
            Camera     cam        = viewingCam.AddComponent <Camera>();

            viewingCam.AddComponent <GUILayer>();
            viewingCam.AddComponent <FlareLayer>();
            // Avoid adding an AudioListener, this messes with Unity
            //viewingCam.AddComponent<AudioListener>();
            viewingCam.name = "ViewingCamera_";
            viewingCam.tag  = TagManager.GetViewingCameraTag();

            // Associate a webcam
            if (webCamManager.WebCams.Length > camIndex)
            {
                WebCamDevice  webCamDevice  = webCamManager.WebCams[camIndex];
                WebCamTexture webCamTexture = null;
                if (webCamManager.VideoFeeds.Length > camIndex)
                {
                    webCamTexture = webCamManager.VideoFeeds[camIndex];
                }

                WebcamDeviceNames webCamDeviceName = WebCamSpecsManager.WebCamDeviceToSpecsName(webCamDevice);
                WebCamSpecs       specs            = WebCamSpecsManager.GetSpecs(webCamDeviceName);

                // Assign attributes from webcam
                WebCamSpecsManager.AssignSpecsToCamera(cam, specs);
                WebCamIdentifier webcamID = viewingCam.AddComponent <WebCamIdentifier>();
                webcamID.SetInfo(webCamManager, camIndex);

                viewingCam.name = "ViewingCamera_" + "(" + camIndex.ToString() + ")";
            }

            cam.depth = -2;

            return(viewingCam);
        }