Exemple #1
0
        internal void LoadCalibrationData()
        {
            cam        = this.GetComponent <Camera>();
            projConfig = null;
            if (hasCalibration)
            {
                ProjectorCameraEnsemble ensembleConfig = calibrationData.GetEnsemble();
                foreach (ProjectorCameraEnsemble.Projector pc in ensembleConfig.projectors)
                {
                    if (pc.name == nameInConfiguration)
                    {
                        projConfig = pc;
                    }
                }
            }
            else
            {
                projConfig = null;
            }


            if (projConfig != null)
            {
                if (displayIndex < 0)
                {
                    displayIndex = projConfig.displayIndex;
                }
                //Debug.Log("Projective Rendering - Loading projector calibration information.");
                imageWidth  = projConfig.width;
                imageHeight = projConfig.height;

                //// used by shadow etc...
                //// this is the vertical field of view - fy
                cam.aspect = (float)imageWidth / imageHeight;
                float fieldOfViewRad = 2.0f * (float)Math.Atan((((double)(imageHeight)) / 2.0) / projConfig.cameraMatrix[1, 1]);
                float fieldOfViewDeg = fieldOfViewRad / 3.14159265359f * 180.0f;
                cam.fieldOfView = fieldOfViewDeg;
                Matrix4x4 opencvProjMat = GetProjectionMatrix(projConfig.cameraMatrix, cam.nearClipPlane, cam.farClipPlane);
                cam.projectionMatrix = UnityUtilities.ConvertRHtoLH(opencvProjMat);

                //var irCoef = projConfig.lensDistortion.AsFloatArray();
                //! jolaur -- looks like this is not being used and is now 2 elements instead of four in the new xml format
                //! lensDist = new Vector4(irCoef[0], irCoef[1], irCoef[2], irCoef[3]);
                lensDist = new Vector4();

                Matrix4x4 worldToLocal = RAT2Unity.Convert(projConfig.pose);
                worldToLocal = UnityUtilities.ConvertRHtoLH(worldToLocal);
                this.transform.localPosition = worldToLocal.ExtractTranslation();
                this.transform.localRotation = worldToLocal.ExtractRotation();
            }
            else
            {
                Debug.Log("Projective Rendering - Using default camera calibration information.");
                lensDist = new Vector4();
            }
        }
Exemple #2
0
        public void BuildSceneComponents()
        {
            if (calibrationData.IsValid())
            {
                ProjectorCameraEnsemble ensemble = calibrationData.GetEnsemble();

                foreach (ProjectorCameraEnsemble.Camera cam in ensemble.cameras)
                {
                    GameObject kinectGameObject = new GameObject("Kinect_" + cam.name);
                    kinectGameObject.transform.parent = transform;
                    RATKinectClient kinect = kinectGameObject.AddComponent <RATKinectClient>();

                    kinect.calibrationData     = calibrationData;
                    kinect.nameInConfiguration = cam.name;
                    kinect.UpdateFromCalibrationData();


                    GameObject deptMeshGameObject = new GameObject("DepthMesh");
                    deptMeshGameObject.transform.parent = kinectGameObject.transform;
                    deptMeshGameObject.AddComponent <RATDepthMesh>();
                    RATDepthMesh dm = deptMeshGameObject.GetComponent <RATDepthMesh>();
                    dm.kinectClient = kinect;
                    Shader s = Shader.Find("RoomAlive/DepthMeshSurfaceShader");
                    dm.surfaceMaterial = new Material(s);
                    deptMeshGameObject.transform.localPosition = Vector3.zero;
                    deptMeshGameObject.transform.localRotation = Quaternion.identity;

                    //this is purely for visualization purposes
                    if (kinectModel != null)
                    {
                        GameObject model = Instantiate(kinectModel);
                        model.name                    = "Kinect3DModel";
                        model.transform.parent        = kinectGameObject.transform;
                        model.transform.localPosition = Vector3.zero;
                        model.transform.localRotation = Quaternion.identity;
                    }
                }
                foreach (ProjectorCameraEnsemble.Projector proj in ensemble.projectors)
                {
                    GameObject projectorGameObject = new GameObject("Projector_" + proj.name);
                    //Instantiate(projectorGameObject);
                    projectorGameObject.transform.parent = transform;

                    Camera cam = projectorGameObject.AddComponent <Camera>();
                    cam.clearFlags      = CameraClearFlags.SolidColor;
                    cam.backgroundColor = Color.black;
                    cam.cullingMask     = 0; //should likely be set to render only the real world

                    RATProjector projrend = projectorGameObject.AddComponent <RATProjector>();
                    projrend.calibrationData     = calibrationData;
                    projrend.nameInConfiguration = proj.name;
                    projrend.LoadCalibrationData();


                    //uncomment this if you want to add the option of Dynamic Masking the projection output
                    //projectorGameObject.AddComponent<RATDynamicMask>();

                    //this is purely for visualization purposes
                    if (projectorModel != null)
                    {
                        GameObject model = Instantiate(projectorModel);
                        model.name                    = "Projector3DModel";
                        model.transform.parent        = projectorGameObject.transform;
                        model.transform.localPosition = Vector3.zero;
                        model.transform.localRotation = Quaternion.identity;
                    }
                }

                //add projection manager and setup appropriate viewports
                RATProjectionManager projManager = transform.gameObject.AddComponent <RATProjectionManager>();
                projManager.FindProjectionsDepthMeshesAndUsers();
                int   n  = ensemble.projectors.Count;
                float dx = 1f / n;
                projManager.screenViewports = new Rect[ensemble.projectors.Count];
                for (int i = 0; i < n; i++)
                {
                    projManager.screenViewports[i] = new Rect(i * dx, 0, dx, 1); // this is a default configuration and it needs to be edited manually if the displays are aranged differently
                }
                int cnt = 0;
                foreach (RATProjector proj in projManager.projections)
                {
                    proj.GetComponent <Camera>().rect = projManager.screenViewports[cnt++];
                }
            }
        }