/// <summary> /// Returns false if error. /// </summary> /// <returns></returns> public static void UpdateRgbFrame() { MetaCoreInterop.meta_get_rgb_frame(RawPixelBuffer, _translation, _new_rotation); // The buffer is pre-allocated by constructor. // Check for a difference bool isEqual = true; // Check for a difference in pose (should change with each new RGB frame). for (int i = 0; i < _new_rotation.Length; ++i) { isEqual = _rotation[i] == _new_rotation[i]; if (!isEqual) { break; } } // If the two rotations are not equal, we have a new rgb frame. if (!isEqual) { // Copy new rotation if it's different. for (int i = 0; i < _new_rotation.Length; ++i) { _rotation[i] = _new_rotation[i]; } _rgbTexture.LoadRawTextureData(RawPixelBuffer, _totalBufferSize); _rgbTexture.Apply(); } }
// Update is called once per frame void Update() { MetaCoreInterop.meta_get_point_cloud(ref _metaPointCloud, _translation, _rotation); //Added by Yuqi Ding MetaCoreInterop.meta_get_rgb_frame(RawPixelBuffer, _translation, _new_rotation); // The buffer is pre-allocated by constructor. // Check for a difference bool isEqual = true; // Check for a difference in pose (should change with each new RGB frame). for (int i = 0; i < _new_rotation.Length; ++i) { isEqual = _rotation[i] == _new_rotation[i]; if (!isEqual) { break; } } // If the two rotations are not equal, we have a new rgb frame. if (!isEqual) { // Copy new rotation if it's different. for (int i = 0; i < _new_rotation.Length; ++i) { _rotation[i] = _new_rotation[i]; } _rgbTexture.LoadRawTextureData(RawPixelBuffer, _totalBufferSize); _rgbTexture.Apply(); if (Time.frameCount % 48 == 0) { byte[] bytes = _rgbTexture.EncodeToPNG(); string rgbname = string.Format("{0}/{1:D04} shot.png", folder, Time.frameCount); File.WriteAllBytes(rgbname, bytes); } } // Added end SetDepthToWorldTransform(); if (SavePointCloud && (Time.frameCount % 48 == 0)) { MarshalMetaPointCloud(); //UpdateMesh(); int num = _metaPointCloud.num_points; Debug.Log(_translation[0].ToString()); Debug.Log(_translation[1].ToString()); Debug.Log(_translation[2].ToString()); if (num != 0) { string Name1 = string.Format("{0}/{1:D04} shot.ply", folder, Time.frameCount); SavePointCloudToPly(Name1, _pointCloud); } } }
// Update is called once per frame void Update() { MetaCoreInterop.meta_get_point_cloud(ref _metaPointCloud, _translation, _rotation); SetDepthToWorldTransform(); if (RenderPointCloud) { MarshalMetaPointCloud(); UpdateMesh(); } }
// Update is called once per frame void Update() { //Added by Yuqi Ding MetaCoreInterop.meta_get_point_cloud(ref _metaPointCloud, _translation, _rotation); // obtain the rgb data MetaCoreInterop.meta_get_rgb_frame(RawPixelBuffer, _translation_rgb, _new_rotation_rgb); // The buffer is pre-allocated by constructor. // obtain the rgb data parameter MetaCoreInterop.meta_get_rgb_intrinsics(ref _camera_params); // Check for a difference bool isEqual = true; // Check for a difference in pose (should change with each new RGB frame). for (int i = 0; i < _new_rotation_rgb.Length; ++i) { isEqual = _rotation_rgb[i] == _new_rotation_rgb[i]; if (!isEqual) { break; } } // If the two rotations are not equal, we have a new rgb frame. if (!isEqual) { // Copy new rotation if it's different. for (int i = 0; i < _new_rotation_rgb.Length; ++i) { _rotation_rgb[i] = _new_rotation_rgb[i]; } _rgbTexture.LoadRawTextureData(RawPixelBuffer, _totalBufferSize); _rgbTexture.Apply(); } SetDepthToWorldTransform(); if (SavePointCloud && (Time.frameCount % 48 == 0)) { MarshalMetaPointCloud(); int num = _metaPointCloud.num_points; if (num != 0) { //save the point cloud string PointCloudName = string.Format("{0}/{1:D04} shot.ply", folder, Time.frameCount); SavePointCloudToPly(PointCloudName, _pointCloud); string PointCloudIntrName = string.Format("{0}/{1:D04} pointcloud_Intr.txt", folder, Time.frameCount); SavePointCloudPara(PointCloudIntrName, _translation, _rotation); //save the rgb frame Color[] color2dtemp = _rgbTexture.GetPixels(); for (int i = 0; i < color2dtemp.Length; i++) { float temp = 0.0f; temp = color2dtemp[i].r; color2dtemp[i].r = color2dtemp[i].b; color2dtemp[i].b = temp; } _rgbTexture.SetPixels(color2dtemp); //Debug.Log("Swap r and b"); byte[] bytes = _rgbTexture.EncodeToJPG(); string rgbName = string.Format("{0}/{1:D04} shot.jpg", folder, Time.frameCount); File.WriteAllBytes(rgbName, bytes); string rgbIntrName = string.Format("{0}/{1:D04} shot_Intr.txt", folder, Time.frameCount); SaveRGBIntrinsics(rgbIntrName, _camera_params); string rgbParaName = string.Format("{0}/{1:D04} shot_Para.txt", folder, Time.frameCount); SaveRGBPara(rgbParaName, _translation_rgb, _rotation_rgb); } // Added end } }