Exemplo n.º 1
0
        static void ReadSkeletonDefinition(BinaryReader sr, SpatialSkeletonAsset skeletonAsset)
        {
            // Read skeleton definition
            int jointCount = sr.ReadInt32();

            skeletonAsset.jointNames = new string[jointCount];
            for (int i = 0; i < jointCount; ++i)
            {
                string name = SpatialUtils.readString(sr);
                skeletonAsset.jointNames[i] = name;
            }

            int parentCount = sr.ReadInt32();

            skeletonAsset.parents = new int[parentCount];
            for (int i = 0; i < parentCount; ++i)
            {
                int parent = sr.ReadInt32();
                skeletonAsset.parents[i] = parent;
            }

            skeletonAsset.refSkeleton = new BoneData[jointCount];
            for (int b = 0; b < jointCount; ++b)
            {
                skeletonAsset.refSkeleton[b] = new BoneData();
                SpatialUtils.readBoneData(sr, skeletonAsset.refSkeleton[b], skeletonAsset.jointNames[b]);
            }
        }
Exemplo n.º 2
0
        void Start()
        {
            if (replayData == null)
            {
                enabled = false;
                return;
            }

            Application.targetFrameRate = 60;

            sr        = new BinaryReader(new MemoryStream(replayData.frameData));
            currFrame = 0;

            if (replayCamera != null)
            {
                replayCamera.fieldOfView = replayData.verticalFOV;
            }

            skeleton = new BoneData[replayData.refSkeleton.Length];
            for (int i = 0; i < skeleton.Length; ++i)
            {
                skeleton[i] = new BoneData();
            }

            if (showDebugSkeleton)
            {
                debugSkeleton = SpatialUtils.createSkeleton(replayData.jointNames, replayData.parents);
            }
        }
Exemplo n.º 3
0
        void readCamera()
        {
            Vector3 pos = Vector3.zero;
            Vector3 rot = Vector3.zero;

            SpatialUtils.readCameraTransform(sr, ref pos, ref rot);
            SpatialUtils.applyCameraTransform(replayCamera.transform, pos, rot);
        }
Exemplo n.º 4
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.º 5
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.º 6
0
        void Update()
        {
            frameTimestamp = sr.ReadDouble();

            Vector3 pos = Vector3.zero;
            Vector3 rot = Vector3.zero;

            SpatialUtils.readCameraTransform(sr, ref pos, ref rot);
            SpatialUtils.applyCameraTransform(transform, pos, rot);

            frameExposureOffset   = sr.ReadSingle();
            frameExposureDuration = sr.ReadDouble();

            if (++currFrame >= replayData.frameCount)
            {
                currFrame = 0;
                sr.BaseStream.Seek(0, System.IO.SeekOrigin.Begin);
                enabled = loop;
            }
        }
Exemplo n.º 7
0
        void readSkeleton()
        {
            int  jointCount    = replayData.refSkeleton.Length;
            uint skeletonCount = sr.ReadUInt32();

            for (int i = 0; i < skeletonCount; ++i)
            {
                for (int b = 0; b < jointCount; ++b)
                {
                    SpatialUtils.readBoneData(sr, skeleton[b], replayData.jointNames[b]);
                }

                if (showDebugSkeleton)
                {
                    Transform root = transform;
                    for (int b = 0; b < skeleton.Length; ++b)
                    {
                        debugSkeleton[b].position = root.TransformPoint(skeleton[0].pos + skeleton[b].pos);
                        debugSkeleton[b].rotation = root.rotation * skeleton[b].rot;
                    }
                }
            }
        }
Exemplo n.º 8
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);
            }
        }
Exemplo n.º 9
0
        static void VisualizeFrame()
        {
            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();

                        // Read skeleton definition
                        int      jointCount = sr.ReadInt32();
                        string[] jointNames = new string[jointCount];
                        for (int i = 0; i < jointCount; ++i)
                        {
                            string name = SpatialUtils.readString(sr);
                            jointNames[i] = name;
                        }

                        int   parentCount = sr.ReadInt32();
                        int[] parents     = new int[parentCount];
                        for (int i = 0; i < parentCount; ++i)
                        {
                            int parent = sr.ReadInt32();
                            parents[i] = parent;
                        }

                        Transform[] neutralSkeleton = SpatialUtils.createSkeleton(jointNames, parents);
                        neutralSkeleton[0].name = "netural_" + neutralSkeleton[0].name;
                        FramePose neutralPose = new FramePose();
                        neutralPose.init(jointCount);
                        // Read neutral skeleton transforms
                        for (int b = 0; b < jointCount; ++b)
                        {
                            SpatialUtils.readBoneData(sr, neutralPose.m_bones[b], jointNames[b]);
                        }
                        visualizeFramePose(neutralPose, neutralSkeleton);


                        // Create skeleton structure
                        Transform[] skeleton = SpatialUtils.createSkeleton(jointNames, parents);
                        FramePose   pose     = new FramePose();
                        pose.init(jointCount);

                        // Create Camera Transform
                        Transform cameraTransform = GameObject.CreatePrimitive(PrimitiveType.Cube).transform;
                        cameraTransform.name       = "Camera Transform";
                        cameraTransform.localScale = Vector3.one * 0.01f;
                        cameraTransform.parent     = null;

                        // PER FRAME DATA STARTS HERE

                        for (int f = 0; f < frameCount; ++f)
                        {
                            // Update skeleton and camera!
                            uint skeletonCount = sr.ReadUInt32();
                            for (int i = 0; i < skeletonCount; ++i)
                            {
                                for (int b = 0; b < jointCount; ++b)
                                {
                                    SpatialUtils.readBoneData(sr, pose.m_bones[b], jointNames[b]);
                                }

                                visualizeFramePose(pose, skeleton);
                            }

                            Vector3 pos = Vector3.zero;
                            Vector3 rot = Vector3.zero;
                            SpatialUtils.readCameraTransform(sr, ref pos, ref rot);

                            Transform t = GameObject.CreatePrimitive(PrimitiveType.Cube).transform;
                            t.name       = f.ToString();
                            t.localScale = Vector3.one * 0.01f;
                            t.parent     = cameraTransform;
                            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);

                            /*
                             *                          cameraTransform.position = pos;
                             *                          cameraTransform.rotation = Quaternion.identity;
                             *                          cameraTransform.Rotate(Vector3.forward, rot.z);
                             *                          cameraTransform.Rotate(Vector3.up, rot.y);
                             *                          cameraTransform.Rotate(Vector3.right, rot.x);
                             */
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Debug.LogWarningFormat("Error parsing {0} with exception: {1}", fileName, e);
            }
        }