コード例 #1
0
    void Start()
    {
        m_frameManager = Application.Instance.KinectFrameManager;
        m_depthManager = Application.Instance.KinectDepthManager;

        m_pRenderer   = GetComponent <Renderer>();
        m_pMeshFilter = GetComponent <MeshFilter>();
        m_camera      = Application.Instance.MainCamera;

        m_pTextureMixMaterial = new Material(Resources.Load("Shaders/KinectDepthColorMixer") as Shader);
        m_pKinectDepthColorRT = new RenderTexture(m_frameManager.DepthFrameWidth, m_frameManager.DepthFrameHeight, 0, RenderTextureFormat.ARGB32);

        m_pColorToDepth = new Vector2[m_frameManager.DepthFrameWidth / m_pColorDownsampleSize * m_frameManager.DepthFrameHeight / m_pColorDownsampleSize];

        GameObject ob = GameObject.CreatePrimitive(PrimitiveType.Plane);

        ob.transform.SetParent(m_camera.transform);

        float depthAspect = m_frameManager.DepthWidthDownsampled / m_frameManager.DepthHeightDownsampled;

        m_pKinectVideoPlane = ob.AddComponent <VideoPlane>();
        m_pKinectVideoPlane.Init(Depth);
        m_pKinectVideoPlane.SetWidth(ReefHelper.DisplayHeight * depthAspect);
        m_pKinectVideoPlane.SetVideoTexture(m_pKinectDepthColorRT);

        m_pTextureMixMaterial.SetTexture("_ColorTex", m_frameManager.GetColorTexture());
        m_pTextureMixMaterial.SetTexture("_DepthTex", m_frameManager.GetDepthTexture());
        m_pTextureMixMaterial.SetFloat("_DownsampleSize", m_pColorDownsampleSize);

        ReleaseBuffers();

        DepthSpacePoint[] depthPoints = m_frameManager.GetDepthCoordinates();
        if (depthPoints != null)
        {
            m_pDepthComputeBuffer = new ComputeBuffer(m_frameManager.GetColorSpacePointBuffer().Length, sizeof(float) * 2);
            m_pTextureMixMaterial.SetBuffer("DepthCoords", m_pDepthComputeBuffer);
        }
        m_depthManager.OnActivationChanged += (x) => { SetActive(x); };
    }
コード例 #2
0
    void Update()
    {
        ColorSpacePoint[] colorSpacePoints = m_frameManager.GetColorSpacePointBuffer();

        for (int y = 0; y < m_frameManager.DepthFrameHeight; y += m_pColorDownsampleSize)
        {
            for (int x = 0; x < m_frameManager.DepthFrameWidth; x += m_pColorDownsampleSize)
            {
                int idx = x / m_pColorDownsampleSize;
                int idy = y / m_pColorDownsampleSize;

                int fullSampleIndex = y * m_frameManager.DepthFrameWidth + x;
                int downSampleIndex = (idy * (m_frameManager.DepthFrameWidth / m_pColorDownsampleSize)) + idx;

                ColorSpacePoint p        = colorSpacePoints[fullSampleIndex];
                Vector2         texcoord = new Vector2();

                texcoord.x = p.X / m_frameManager.ColorFrameWidth;
                texcoord.y = p.Y / m_frameManager.ColorFrameHeight;
                m_pColorToDepth[downSampleIndex] = texcoord;
            }
        }
        m_pDepthComputeBuffer.SetData(m_pColorToDepth);
    }