public void SaveTransDataToCSV(Transform obj, string fullPath) { Debug.Log("Saving : " + fullPath); Table.CameraLabel tansData = TransToCameraLable(obj); fullPath = "D:/UnityWorkSpace/PointCloudLibrary/Assets/Resources/Table/SavedData/" + fullPath + ".txt"; System.IO.FileInfo fi = new System.IO.FileInfo(fullPath); if (!fi.Directory.Exists) { fi.Directory.Create(); } System.IO.FileStream fs = new System.IO.FileStream(fullPath, System.IO.FileMode.Create, System.IO.FileAccess.Write); System.IO.StreamWriter sw = new System.IO.StreamWriter(fs, System.Text.Encoding.UTF8); string data = "FileName\tX\tY\tZ\tW\tP\tQ\tR\tS"; sw.WriteLine(data); sw.WriteLine(data); data = ""; data = String.Format("{0}\t{1:F6}\t{2:F6}\t{3:F6}\t{4:F6}\t{5:F6}\t{6:F6}\t{7:F6}\t{8:F6}", tansData.FileName, tansData.X, tansData.Y, tansData.Z, tansData.W, tansData.P, tansData.Q, tansData.R, tansData.S); sw.WriteLine(data); sw.Close(); fs.Close(); Debug.Log("Done."); }
Table.CameraLabel TransToCameraLable(Transform obj) { Table.CameraLabel tansData = new Table.CameraLabel(); tansData.FileName = obj.name; tansData.X = obj.position.x; tansData.Y = -obj.position.y; tansData.Z = obj.position.z; tansData.W = obj.rotation.w; tansData.P = obj.rotation.x; tansData.Q = -obj.rotation.y; tansData.R = obj.rotation.z; tansData.S = obj.localScale.x; return(tansData); }