Example #1
0
 static void ReadHeader(BinaryReader sr, SpatialCameraAsset cameraAsset)
 {
     cameraAsset.version           = sr.ReadInt32();
     cameraAsset.frameCount        = sr.ReadInt32();
     cameraAsset.deviceOrientation = sr.ReadInt32();
     cameraAsset.horizontalFOV     = sr.ReadSingle();
     cameraAsset.verticalFOV       = sr.ReadSingle();
     cameraAsset.focalLengthX      = sr.ReadSingle();
     cameraAsset.focalLengthY      = sr.ReadSingle();
     cameraAsset.captureType       = (SpatialCameraAsset.CaptureType)sr.ReadInt32();
 }
Example #2
0
        static void ImportSpatialSkeleton()
        {
            string[] filters  = { "Replay Files", "dat" };
            string   fileName = EditorUtility.OpenFilePanelWithFilters(
                "Load Replay",
                ".",
                filters);

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

            SpatialSkeletonAsset skeletonAsset = SpatialCameraAsset.CreateInstance <SpatialSkeletonAsset>();

            skeletonAsset.captureType = SpatialCameraAsset.CaptureType.Skeleton;

            try
            {
                using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                {
                    using (BinaryReader sr = new BinaryReader(fs))
                    {
                        ReadHeader(sr, skeletonAsset);
                        ImportUserAnchors(sr, skeletonAsset);
                        ReadSkeletonDefinition(sr, skeletonAsset);
                        skeletonAsset.frameData = sr.ReadBytes((int)(fs.Length - fs.Position));
                    }
                }
            }
            catch (Exception e)
            {
                Debug.LogErrorFormat("Error parsing {0} with exception: {1}", fileName, e);
            }


            // Save Asset

            string savePath = EditorUtility.SaveFilePanelInProject("Save Asset", "Camera.asset", "asset", "Please enter a file name to save the asset to");

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

            AssetDatabase.CreateAsset(skeletonAsset, savePath);
            AssetDatabase.SaveAssets();

            EditorUtility.FocusProjectWindow();
            Selection.activeObject = skeletonAsset;
        }
Example #3
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);
            }
        }
Example #4
0
        public override void OnInspectorGUI()
        {
            base.DrawDefaultInspector();

            GUILayout.Space(20f);

            if (GUILayout.Button("Create Anchors"))
            {
                SpatialCameraAsset asset = (SpatialCameraAsset)target;
                if (asset.userAnchors.Length == 0)
                {
                    return;
                }
                Transform root = new GameObject(target.name).transform;
                root.position = Vector3.zero;

                for (int i = 0; i < asset.userAnchors.Length; ++i)
                {
                    Transform anchor = new GameObject(string.Format("UserAnchor_{0}", i)).transform;
                    anchor.SetParent(root);
                    anchor.position = asset.userAnchors[i];
                }
            }
        }