// sets up all gameobjects needed to render frames, including a mesh with the correct material public TextureRenderer(Texture textureToRender, int renderTextureLayer, QCARRenderer.Vec2I requestedTextureSize) { if (renderTextureLayer > 31) { Debug.LogError("WebCamBehaviour.SetupTextureBufferCamera: configured layer > 31 is not supported by Unity!"); return; } mTextureWidth = requestedTextureSize.x; mTextureHeight = requestedTextureSize.y; float halfMeshHeight = (mTextureHeight / (float)mTextureWidth) * 0.5f; // camera object: GameObject texBufferGameObj = new GameObject("TextureBufferCamera"); mTextureBufferCamera = texBufferGameObj.AddComponent<Camera>(); mTextureBufferCamera.isOrthoGraphic = true; mTextureBufferCamera.orthographicSize = halfMeshHeight; mTextureBufferCamera.aspect = mTextureWidth / (float)mTextureHeight; mTextureBufferCamera.nearClipPlane = 0.5f; mTextureBufferCamera.farClipPlane = 1.5f; mTextureBufferCamera.cullingMask = (1 << renderTextureLayer); mTextureBufferCamera.enabled = false; // camera will only render on demand!! // mesh to display the given texture GameObject textureBufferMesh = new GameObject("TextureBufferMesh", new[] { typeof(MeshFilter), typeof(MeshRenderer) }); textureBufferMesh.transform.parent = texBufferGameObj.transform; textureBufferMesh.layer = renderTextureLayer; Mesh mesh = new Mesh { vertices = new[] { new Vector3(-0.5f, halfMeshHeight, 1f), new Vector3(0.5f, halfMeshHeight, 1f), new Vector3(-0.5f, -halfMeshHeight, 1f), new Vector3(0.5f, -halfMeshHeight, 1f), }, uv = new[] { new Vector2(0f, 0f), new Vector2(1f, 0f), new Vector2(0f, 1f), new Vector2(1f, 1f), }, triangles = new[] { 0,1,2, 2,1,3 } }; // renderer and material MeshRenderer meshRenderer = textureBufferMesh.GetComponent<MeshRenderer>(); meshRenderer.material = new Material(Shader.Find("Unlit/Texture")); meshRenderer.material.mainTexture = textureToRender; MeshFilter meshFilter = textureBufferMesh.GetComponent<MeshFilter>(); meshFilter.mesh = mesh; }
public WebCamTexAdaptorImpl(string deviceName, int requestedFPS, QCARRenderer.Vec2I requestedTextureSize) { mWebCamTexture = new WebCamTexture(); mWebCamTexture.deviceName = deviceName; mWebCamTexture.requestedFPS = requestedFPS; mWebCamTexture.requestedWidth = requestedTextureSize.x; mWebCamTexture.requestedHeight = requestedTextureSize.y; }
public NullWebCamTexAdaptor(int requestedFPS, QCARRenderer.Vec2I requestedTextureSize) { mTexture = new Texture2D(requestedTextureSize.x, requestedTextureSize.y); mMsBetweenFrames = 1000d/requestedFPS; // initialize last frame way back mLastFrame = DateTime.Now - TimeSpan.FromDays(1); if (QCARRuntimeUtilities.IsQCAREnabled()) { #if UNITY_EDITOR EditorUtility.DisplayDialog("Error occurred!", ERROR_MSG, "Ok"); #endif Debug.LogError(ERROR_MSG); } }