public WebCamProfile.ProfileCollection LoadAndParseWebcamProfiles(string path) { WebCamProfile.ProfileData data; Dictionary <string, WebCamProfile.ProfileData> profiles = new Dictionary <string, WebCamProfile.ProfileData>(); try { XmlDocument document = new XmlDocument(); document.Load(path); foreach (XmlNode node in document.GetElementsByTagName("webcam")) { profiles[node.Attributes["deviceName"].Value.ToLower()] = this.ParseConfigurationEntry(node); } data = this.ParseConfigurationEntry(document.GetElementsByTagName("default")[0]); } catch (Exception exception) { string message = "Exception occurred when trying to parse web cam profile file: " + exception.Message; EditorUtility.DisplayDialog("Error occurred!", message, "Ok"); Debug.LogError(message); data = new WebCamProfile.ProfileData { RequestedFPS = 30, RequestedTextureSize = new QCARRenderer.Vec2I(640, 480), ResampledTextureSize = new QCARRenderer.Vec2I(640, 480) }; } return(new WebCamProfile.ProfileCollection(data, profiles)); }
private WebCamProfile.ProfileData ParseConfigurationEntry(XmlNode cameraNode) { foreach (XmlNode xmlNode in cameraNode.ChildNodes) { string value = "undefined"; if (Application.platform == RuntimePlatform.WindowsEditor) { value = "windows"; } if (Application.platform == RuntimePlatform.OSXEditor) { value = "osx"; } if (xmlNode.Name.Equals(value)) { int v = 0; string valueOfChildNodeByName = UnityPlayModeEditorUtility.GetValueOfChildNodeByName(xmlNode, "resampledTextureHeight"); if (!valueOfChildNodeByName.Equals(string.Empty)) { v = int.Parse(valueOfChildNodeByName); } WebCamProfile.ProfileData profileData = default(WebCamProfile.ProfileData); profileData.RequestedTextureSize = new VuforiaRenderer.Vec2I(int.Parse(UnityPlayModeEditorUtility.GetValueOfChildNodeByName(xmlNode, "requestedTextureWidth")), int.Parse(UnityPlayModeEditorUtility.GetValueOfChildNodeByName(xmlNode, "requestedTextureHeight"))); profileData.ResampledTextureSize = new VuforiaRenderer.Vec2I(int.Parse(UnityPlayModeEditorUtility.GetValueOfChildNodeByName(xmlNode, "resampledTextureWidth")), v); profileData.RequestedFPS = 30; //profileData = profileData; return(profileData); } } throw new Exception("Could not parse webcam profile: " + cameraNode.InnerXml); }
public WebCamProfile.ProfileCollection LoadAndParseWebcamProfiles(string path) { Dictionary <string, WebCamProfile.ProfileData> dictionary = new Dictionary <string, WebCamProfile.ProfileData>(); WebCamProfile.ProfileData defaultProfile; try { XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(path); foreach (XmlNode xmlNode in xmlDocument.GetElementsByTagName("webcam")) { dictionary[xmlNode.Attributes["deviceName"].Value.ToLower()] = this.ParseConfigurationEntry(xmlNode); } defaultProfile = this.ParseConfigurationEntry(xmlDocument.GetElementsByTagName("default")[0]); } catch (Exception ex) { string text = "Exception occurred when trying to parse web cam profile file: " + ex.Message; EditorUtility.DisplayDialog("Error occurred!", text, "Ok"); Debug.LogError(text); defaultProfile = new WebCamProfile.ProfileData { RequestedFPS = 30, RequestedTextureSize = new VuforiaRenderer.Vec2I(640, 480), ResampledTextureSize = new VuforiaRenderer.Vec2I(640, 0) }; } return(new WebCamProfile.ProfileCollection(defaultProfile, dictionary)); }
public WebCamImpl(Camera arCamera, Camera backgroundCamera, int renderTextureLayer, string webcamDeviceName, bool flipHorizontally) { if (QCARRuntimeUtilities.IsPlayMode()) { this.mRenderTextureLayer = renderTextureLayer; this.mARCamera = arCamera; this.mOriginalCameraClearFlags = this.mARCamera.clearFlags; this.mARCamera.clearFlags = CameraClearFlags.Depth; this.mBackgroundCameraInstance = backgroundCamera; this.mBgRenderingTexBehaviour = this.mBackgroundCameraInstance.GetComponentInChildren <BGRenderingAbstractBehaviour>(); if (this.mBgRenderingTexBehaviour == null) { Debug.LogError("Instanciated Prefab does not contain VideoTextureBehaviour!"); } else { this.mOriginalCameraCullMask = this.mARCamera.cullingMask; this.mARCamera.cullingMask &= ~(((int)1) << this.mBgRenderingTexBehaviour.gameObject.layer); this.mARCamera.cullingMask &= ~(((int)1) << this.mRenderTextureLayer); WebCamProfile profile = new WebCamProfile(); if (QCARRuntimeUtilities.IsQCAREnabled() && (WebCamTexture.devices.Length > 0)) { bool flag = false; foreach (WebCamDevice device in WebCamTexture.devices) { if (device.name.Equals(webcamDeviceName)) { flag = true; } } if (!flag) { webcamDeviceName = WebCamTexture.devices[0].name; } this.mWebCamProfile = profile.GetProfile(webcamDeviceName); this.mWebCamTexture = new WebCamTexAdaptorImpl(webcamDeviceName, this.mWebCamProfile.RequestedFPS, this.mWebCamProfile.RequestedTextureSize); } else { this.mWebCamProfile = profile.Default; this.mWebCamTexture = new NullWebCamTexAdaptor(this.mWebCamProfile.RequestedFPS, this.mWebCamProfile.RequestedTextureSize); } this.mBgRenderingTexBehaviour.SetFlipHorizontally(flipHorizontally); this.mFlipHorizontally = flipHorizontally; } } }
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 }
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 }
public ProfileCollection(WebCamProfile.ProfileData defaultProfile, Dictionary <string, WebCamProfile.ProfileData> profiles) { this.DefaultProfile = defaultProfile; this.Profiles = profiles; }