public Texture2D take_color_image() { if (ManagerManager.Manager.mZigManager.is_reader_connected() == 2) { //TODO temporarily disabled to slove wrong format bug return(null); //TODO write the shader and test ManagerManager.Log("taking color image"); Material mat = new Material(ManagerManager.Manager.mReferences.mXB1KinectImageMaskingShader); mat.SetTexture("_MainTex", mKinect.ColorTexture); mat.SetTexture("_AlphaTex", mKinect.LabelTexture); //mat.SetTexture("_MainTex",mKinect.LabelTexture); if (mColorImageRT == null) { mColorImageRT = new RenderTexture(mKinect.ColorTexture.width, mKinect.ColorTexture.height, 0); } var img = new ImageGameObjectUtility(mKinect.ColorTexture); img.PlaneObject.GetComponent <Renderer>().material = mat; Camera cam = ManagerManager.Manager.gameObject.AddComponent <Camera>(); cam.orthographic = true; cam.orthographicSize = img.BaseDimension.y; img.PlaneObject.transform.position = cam.transform.position + cam.transform.forward * 10; cam.transform.LookAt(img.PlaneObject.transform.position); //TODO resize the camera RenderTexture.active = mColorImageRT; cam.targetTexture = mColorImageRT; cam.clearFlags = CameraClearFlags.SolidColor; cam.backgroundColor = Color.blue; cam.Render(); //Texture2D copyTex = new Texture2D(mColorImageRT.width,mColorImageRT.height); //copyTex.ReadPixels(new Rect(0,0,mColorImageRT.width,mColorImageRT.height),0,0); //copyTex.Apply(); RenderTexture.active = null; cam.targetTexture = null; GameObject.Destroy(cam); img.destroy(); return(ManagerManager.Manager.mZigManager.ImageView.UpdateTexture(mKinect.ColorTexture, mKinect.LabelTexture)); } return(null); }
public override void destroy() { mImage.destroy(); }