Esempio n. 1
0
 internal void RegisterProjector(RATProjector projection)
 {
     if (!projections.Contains(projection))
     {
         projections.Add(projection);
     }
 }
Esempio n. 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++];
                }
            }
        }