public void OnClick()
    {
        Debug.Log("OnClick");

        if (Application.platform == RuntimePlatform.IPhonePlayer)
        {
            int     width = 0, height = 0;
            float[] pixels = null;
            capture_.AcquireNextFrame((pVideoData, videoWidth, videoHeight, pDepthData, depthWidth, depthHeight) =>
            {
                width  = depthWidth;
                height = depthHeight;
                pixels = new float[width * height];
                Marshal.Copy(pDepthData, pixels, 0, width * height);
            });

            var texture = new Texture2D(width, height);
            for (var y = 0; y < (int)height; y++)
            {
                for (var x = 0; x < (int)width; x++)
                {
                    var   v = pixels[y * width + x];
                    Color color;
                    if (float.IsNaN(v))
                    {
                        color = new Color(0f, 1f, 0f);
                    }
                    else
                    {
                        color = new Color(v, v, v);
                    }
                    texture.SetPixel(x, y, color);
                }
            }

            quad.GetComponent <Renderer>().material.mainTexture = texture;
            texture.Apply();
        }
    }
Esempio n. 2
0
 private DepthReadResult getDepthDataFloatArray()
 {
     if (Application.platform == RuntimePlatform.IPhonePlayer)
     {
         int     width = 0, height = 0;
         float[] pixels = null;
         int     imgWidth = 0, imgHeight = 0;
         byte[]  imgPixels = null;
         capture_.AcquireNextFrame((pVideoData, videoWidth, videoHeight, pDepthData, depthWidth, depthHeight) =>
         {
             width     = depthWidth;
             height    = depthHeight;
             imgWidth  = videoWidth;
             imgHeight = videoHeight;
             pixels    = new float[width * height];
             imgPixels = new byte[imgWidth * imgHeight * 4];
             Marshal.Copy(pDepthData, pixels, 0, width * height);
             Marshal.Copy(pVideoData, imgPixels, 0, imgWidth * imgHeight * 4);
         });
         return(new DepthReadResult(pixels, width, height, imgPixels, imgWidth, imgHeight));
     }
     else
     {
         var checkerboard    = new float[4096];
         var checkerboardImg = new byte[4096 * 4];
         for (var y = 0; y < 64; y++)
         {
             for (var x = 0; x < 64; x++)
             {
                 checkerboard[y * 64 + x]              = y / 64f;
                 checkerboardImg[(y * 64 + x) * 4]     = 128;
                 checkerboardImg[(y * 64 + x) * 4 + 1] = 128;
                 checkerboardImg[(y * 64 + x) * 4 + 2] = (byte)(y * 3);
                 checkerboardImg[(y * 64 + x) * 4 + 3] = 255;
             }
         }
         return(new DepthReadResult(checkerboard, 64, 64, checkerboardImg, 64, 64));
     }
 }