Пример #1
0
    public void SaveCameraData(string name)
    {
        GameObject cameraRoot = GameObject.Find(name);

        Table.CameraLabel[] newLabel = new Table.CameraLabel[cameraRoot.transform.childCount];

        Debug.Log(cameraRoot.transform.childCount);

        for (int i = 0; i < cameraRoot.transform.childCount; i++)
        {
            newLabel [i] = new Table.CameraLabel();

            Transform temp = cameraRoot.transform.GetChild(i);

            newLabel [i].CameraID = i;
            newLabel [i].FileName = temp.gameObject.name;
            newLabel [i].X        = temp.position.x;
            newLabel [i].Y        = -temp.position.y;
            newLabel [i].Z        = temp.position.z;
            newLabel [i].W        = temp.rotation.w;
            newLabel [i].P        = temp.rotation.x;
            newLabel [i].Q        = -temp.rotation.y;
            newLabel [i].R        = temp.rotation.z;
        }

        Table.CameraTableReader.Instance.SaveCameraDataToCSV(newLabel, name);
    }
    void SetTansformData(GameObject gameobj, string PATH)
    {
        if (File.Exists(Application.dataPath + "/Resources/Table/SavedData/" + PATH + ".txt"))
        {
            Table.CameraTableReader.Instance.ReadFromFile("SavedData/" + PATH);
            Table.CameraLabel cameraLabel = Table.CameraTableReader.Instance.GetItem(0);

            gameobj.transform.position   = new Vector3(cameraLabel.X, -cameraLabel.Y, cameraLabel.Z);
            gameobj.transform.rotation   = new Quaternion(cameraLabel.P, -cameraLabel.Q, cameraLabel.R, cameraLabel.W);
            gameobj.transform.localScale = new Vector3(cameraLabel.S, cameraLabel.S, cameraLabel.S);
        }
    }
Пример #3
0
    // Start Coroutine of reading the points from the OFF file and creating the meshes
    IEnumerator loadOFF(string dPath, string transPath)
    {
        // Read file
        StreamReader sr = new StreamReader(Application.dataPath + dPath + ".off");

        sr.ReadLine();                           // OFF
        string[] buffer = sr.ReadLine().Split(); // nPoints, nFaces

        int numPoints = int.Parse(buffer[0]);

        Vector3[] points = new Vector3[numPoints];
        int[,] colors = new int[numPoints, 3];
        Vector3 minValue = new Vector3();

        for (int i = 0; i < numPoints; i++)
        {
            buffer = sr.ReadLine().Split();

            points[i] = new Vector3(float.Parse(buffer[0]), float.Parse(buffer[1]) * -1f, float.Parse(buffer[2]));

            colors [i, 0] = int.Parse(buffer [3]);
            colors [i, 1] = int.Parse(buffer [4]);
            colors [i, 2] = int.Parse(buffer [5]);
        }

        string fullPath = "D:/UnityWorkSpace/PointCloudLibrary/Assets/Resources/Table/SavedData/" + dPath + ".off";

        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 = "COFF";

        sw.WriteLine(data);

        data = String.Format("{0} 0 0", numPoints);
        sw.WriteLine(data);

        GameObject ROOT = new GameObject();

        if (File.Exists(Application.dataPath + "/Resources/Table/SavedData/" + transPath + ".txt"))
        {
            Table.CameraTableReader.Instance.ReadFromFile("SavedData/" + transPath);
            Table.CameraLabel cameraLabel = Table.CameraTableReader.Instance.GetItem(0);

            ROOT.transform.position   = new Vector3(cameraLabel.X, -cameraLabel.Y, cameraLabel.Z);
            ROOT.transform.rotation   = new Quaternion(cameraLabel.P, -cameraLabel.Q, cameraLabel.R, cameraLabel.W);
            ROOT.transform.localScale = new Vector3(cameraLabel.S, cameraLabel.S, cameraLabel.S);
        }

        for (int i = 0; i < numPoints; i++)
        {
            points [i] = ROOT.transform.localToWorldMatrix.MultiplyPoint(points [i]);

            data = String.Format("{0:F6} {1:F6} {2:F6} {3} {4} {5} 255", points[i].x, points[i].y * -1f, points[i].z, colors[i, 0], colors[i, 1], colors[i, 2]);
            sw.WriteLine(data);
        }

        sw.Close();
        fs.Close();
        Debug.Log("Done.");

        yield return(new WaitForEndOfFrame());
    }