Exemplo n.º 1
0
        static void ImportEnvironmentProbeAnchors()
        {
            string[] filters  = { "Dat Files", "dat" };
            string   fileName = EditorUtility.OpenFilePanelWithFilters(
                "Import Environment Probes",
                ".",
                filters);

            if (fileName.Length == 0)
            {
                return;
            }

            try
            {
                using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                {
                    using (BinaryReader sr = new BinaryReader(fs))
                    {
                        int anchorCount = sr.ReadInt32();
                        for (int i = 0; i < anchorCount; ++i)
                        {
                            Vector3   extent = SpatialUtils.readVector3(sr);
                            Matrix4x4 matrix = SpatialUtils.readMatrix(sr);

                            ReflectionProbe probe = new GameObject(string.Format("Probe_{0}", i)).AddComponent <ReflectionProbe>();
                            probe.mode = UnityEngine.Rendering.ReflectionProbeMode.Custom;
                            probe.size = extent;

                            Debug.LogFormat("Extent: {0}/{1}/{2}", extent.x, extent.y, extent.z);

                            Vector3 anchorPos = Vector3.zero;
                            anchorPos.x = matrix[0, 3];
                            anchorPos.y = matrix[1, 3];
                            anchorPos.z = -matrix[2, 3];

                            probe.transform.position = anchorPos;
                            probe.transform.rotation = Quaternion.identity;//matrix.rotation;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Debug.LogErrorFormat("Error parsing {0} with exception: {1}", fileName, e);
            }
        }
Exemplo n.º 2
0
        static void ImportUserAnchors(BinaryReader sr, SpatialCameraAsset cameraAsset)
        {
            // User anchors introduced in 202005
            if (cameraAsset.version < 202005)
            {
                return;
            }

            int anchorCount = sr.ReadInt32();

            cameraAsset.userAnchors = new Vector3[anchorCount];
            for (int i = 0; i < anchorCount; ++i)
            {
                Vector3 position = SpatialUtils.readVector3(sr);
                cameraAsset.userAnchors[i] = position;
                Debug.LogFormat("Extent: {0}/{1}/{2}", position.x, position.y, position.z);
            }
        }
Exemplo n.º 3
0
        static void VisualizeCamera()
        {
            string[] filters  = { "Replay Files", "dat" };
            string   fileName = EditorUtility.OpenFilePanelWithFilters(
                "Load Replay",
                ".",
                filters);

            if (fileName.Length == 0)
            {
                return;
            }

            try
            {
                using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                {
                    using (BinaryReader sr = new BinaryReader(fs))
                    {
                        int version = sr.ReadInt32();
                        Debug.LogFormat("Version {0}", version);

                        int frameCount = sr.ReadInt32();
                        Debug.LogFormat("Read {0} frames", frameCount);

                        int deviceOrientation = sr.ReadInt32();
                        Debug.LogFormat("Device Orientation {0}", deviceOrientation);

                        float fovX = sr.ReadSingle();
                        float fovY = sr.ReadSingle();

                        float flX = sr.ReadSingle();
                        float flY = sr.ReadSingle();

                        int captureType = sr.ReadInt32();

                        int anchorCount = sr.ReadInt32();
                        for (int i = 0; i < anchorCount; ++i)
                        {
                            SpatialUtils.readVector3(sr);
                        }

                        Transform root = new GameObject("root").transform;
                        root.position = Vector3.zero;
                        root.rotation = Quaternion.identity;

                        for (int i = 0; i < Mathf.Max(30, frameCount); ++i)
                        {
                            double timeStamp = sr.ReadDouble();

                            Vector3 pos = Vector3.zero;
                            Vector3 rot = Vector3.zero;
                            //Quaternion rot = Quaternion.identity;

                            SpatialUtils.readCameraTransform(sr, ref pos, ref rot);
                            sr.ReadSingle();
                            sr.ReadDouble();
                            //                            Debug.LogFormat("Frame {0}, pos: {1}, {2}, {3}, rot: {4}, {5}, {6}, {7}", i, pos.x, pos.y, pos.z, rot.x, rot.y, rot.z, rot.w);

                            Transform t = GameObject.CreatePrimitive(PrimitiveType.Cube).transform;
                            t.name       = i.ToString();
                            t.localScale = Vector3.one * 0.01f;
                            t.parent     = root;
                            t.position   = pos;
                            t.rotation   = Quaternion.identity;

                            t.Rotate(Vector3.forward, rot.z);
                            t.Rotate(Vector3.up, rot.y);
                            t.Rotate(Vector3.right, rot.x);


                            //                            t.eulerAngles = rot;
                            //                            t.rotation = rot;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Debug.LogWarningFormat("Error parsing {0} with exception: {1}", fileName, e);
            }
        }