void Start() { _videoStreamFilter = new RsVideoStreamRequest(); _currVideoStreamFilter = _videoStreamFilter.Clone(); RsDevice.Instance.OnNewSampleSet += OnFrames; RsDevice.Instance.OnStop += Dispose; }
virtual protected void Awake() { threadId = Thread.CurrentThread.ManagedThreadId; _videoStreamFilter = new RsVideoStreamRequest() { Stream = _stream, Format = _format, StreamIndex = _streamIndex }; _currVideoStreamFilter = _videoStreamFilter.Clone(); }
private void ResetTexture(RsVideoStreamRequest vsr) { if (texture != null) { Destroy(texture); } texture = new Texture2D(vsr.Width, vsr.Height, Convert(vsr.Format), false, true) { wrapMode = TextureWrapMode.Clamp, filterMode = filterMode }; _currVideoStreamFilter = vsr.Clone(); texture.Apply(); textureBinding.Invoke(texture); }
private void ResetMesh(RsVideoStreamRequest vsr) { int width = vsr.Width; int height = vsr.Height; if (width == 0 || height == 0) { return; } Dispose(); Assert.IsTrue(SystemInfo.SupportsTextureFormat(TextureFormat.RGFloat)); uvmap = new Texture2D(width, height, TextureFormat.RGFloat, false, true) { wrapMode = TextureWrapMode.Clamp, filterMode = FilterMode.Point, }; GetComponent <MeshRenderer>().sharedMaterial.SetTexture("_UVMap", uvmap); if (mesh != null) { mesh.Clear(); } else { mesh = new Mesh() { indexFormat = IndexFormat.UInt32, } }; vertices = new Vector3[width * height]; handle = GCHandle.Alloc(vertices, GCHandleType.Pinned); verticesPtr = handle.AddrOfPinnedObject(); var indices = new int[vertices.Length]; for (int i = 0; i < vertices.Length; i++) { indices[i] = i; } mesh.MarkDynamic(); mesh.vertices = vertices; var uvs = new Vector2[width * height]; Array.Clear(uvs, 0, uvs.Length); for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { uvs[i + j * width].x = i / (float)width; uvs[i + j * width].y = j / (float)height; } } mesh.uv = uvs; mesh.SetIndices(indices, MeshTopology.Points, 0, false); mesh.bounds = new Bounds(Vector3.zero, Vector3.one * 10f); GetComponent <MeshFilter>().sharedMesh = mesh; _currVideoStreamFilter = vsr.Clone(); } void OnDestroy() { Dispose(); if (mesh != null) { Destroy(null); } }