コード例 #1
0
    public WebCamImpl(Camera arCamera, Camera backgroundCamera, int renderTextureLayer, string webcamDeviceName, bool flipHorizontally)
    {
#if UNITY_EDITOR
        mRenderTextureLayer = renderTextureLayer;

        // get main camera, set correct clear flags:
        mARCamera = arCamera;
        mOriginalCameraClearFlags = mARCamera.clearFlags;
        mARCamera.clearFlags      = CameraClearFlags.Depth;

        // instanciate BackgroundCamera
        mBackgroundCameraInstance = backgroundCamera;

        // make sure the correct prefab has been attached:
        mBgRenderingTexBehaviour =
            mBackgroundCameraInstance.GetComponentInChildren <BGRenderingBehaviour>();
        if (mBgRenderingTexBehaviour == null)
        {
            Debug.LogError("Instanciated Prefab does not contain VideoTextureBehaviour!");
        }
        else
        {
            mOriginalCameraCullMask = mARCamera.cullingMask;
            // set mask to cull away bg rendering behaviour and texture buffer layer
            mARCamera.cullingMask &= ~(1 << mBgRenderingTexBehaviour.gameObject.layer);
            mARCamera.cullingMask &= ~(1 << mRenderTextureLayer);

            // load the webcam profiles
            WebCamProfile profiles = new WebCamProfile();

            if (QCARRuntimeUtilities.IsQCAREnabled() && (WebCamTexture.devices.Length > 0))
            {
                // check if selected web cam shows up in list of available devices:
                bool selectedWebCamAvailable = false;
                foreach (WebCamDevice webCamDevice in WebCamTexture.devices)
                {
                    if (webCamDevice.name.Equals(webcamDeviceName))
                    {
                        selectedWebCamAvailable = true;
                    }
                }

                // if it was not found, default to first available camera
                if (!selectedWebCamAvailable)
                {
                    webcamDeviceName = WebCamTexture.devices[0].name;
                }

                mWebCamProfile = profiles.GetProfile(webcamDeviceName);

                // create webcam texture adaptor
                mWebCamTexture = new WebCamTexAdaptorImpl(webcamDeviceName, mWebCamProfile.RequestedFPS,
                                                          mWebCamProfile.RequestedTextureSize);
            }
            else
            {
                // no webcam connected, use default profile and null implementation for webcam
                mWebCamProfile = profiles.Default;

                // create null webcam implementation
                mWebCamTexture = new NullWebCamTexAdaptor(mWebCamProfile.RequestedFPS, mWebCamProfile.RequestedTextureSize);
            }

            // override the texture created by the the VideoTextureBehaviour
            mBgRenderingTexBehaviour.SetFlipHorizontally(flipHorizontally);

            mFlipHorizontally = flipHorizontally;
        }
#endif
    }
コード例 #2
0
    public WebCamImpl(Camera arCamera, Camera backgroundCamera, int renderTextureLayer, string webcamDeviceName, bool flipHorizontally)
    {
        #if UNITY_EDITOR
        mRenderTextureLayer = renderTextureLayer;

        // get main camera, set correct clear flags:
        mARCamera = arCamera;
        mOriginalCameraClearFlags = mARCamera.clearFlags;
        mARCamera.clearFlags = CameraClearFlags.Depth;

        // instanciate BackgroundCamera
        mBackgroundCameraInstance = backgroundCamera;

        // make sure the correct prefab has been attached:
        mBgRenderingTexBehaviour =
            mBackgroundCameraInstance.GetComponentInChildren<BGRenderingBehaviour>();
        if (mBgRenderingTexBehaviour == null)
        {
            Debug.LogError("Instanciated Prefab does not contain VideoTextureBehaviour!");
        }
        else
        {
            mOriginalCameraCullMask = mARCamera.cullingMask;
            // set mask to cull away bg rendering behaviour and texture buffer layer
            mARCamera.cullingMask &= ~(1 << mBgRenderingTexBehaviour.gameObject.layer);
            mARCamera.cullingMask &= ~(1 << mRenderTextureLayer);

            // load the webcam profiles
            WebCamProfile profiles = new WebCamProfile();

            if (QCARRuntimeUtilities.IsQCAREnabled() && (WebCamTexture.devices.Length > 0))
            {
                // check if selected web cam shows up in list of available devices:
                bool selectedWebCamAvailable = false;
                foreach (WebCamDevice webCamDevice in WebCamTexture.devices)
                    if (webCamDevice.name.Equals(webcamDeviceName))
                        selectedWebCamAvailable = true;

                // if it was not found, default to first available camera
                if (!selectedWebCamAvailable) webcamDeviceName = WebCamTexture.devices[0].name;

                mWebCamProfile = profiles.GetProfile(webcamDeviceName);

                // create webcam texture adaptor
                mWebCamTexture = new WebCamTexAdaptorImpl(webcamDeviceName, mWebCamProfile.RequestedFPS,
                                                            mWebCamProfile.RequestedTextureSize);
            }
            else
            {
                // no webcam connected, use default profile and null implementation for webcam
                mWebCamProfile = profiles.Default;

                // create null webcam implementation
                mWebCamTexture = new NullWebCamTexAdaptor(mWebCamProfile.RequestedFPS, mWebCamProfile.RequestedTextureSize);
            }

            // override the texture created by the the VideoTextureBehaviour
            mBgRenderingTexBehaviour.SetFlipHorizontally(flipHorizontally);

            mFlipHorizontally = flipHorizontally;
        }
        #endif
    }