public void Awake() { cam = this.GetComponent <Camera>(); LoadCalibrationData(); if (projectionManager == null) { projectionManager = GetComponent <RATProjectionManager>(); if (projectionManager == null) { projectionManager = GetComponentInParent <RATProjectionManager>(); } if (projectionManager == null) { projectionManager = GameObject.FindObjectOfType <RATProjectionManager>(); } } if (projectionManager != null) { projectionManager.RegisterProjector(this); } cam.enabled = false; dynamicMask = GetComponent <RATDynamicMask>(); initialized = true; }
void Start() { if (projectionManager == null) { projectionManager = GameObject.FindObjectOfType <RATProjectionManager>(); } if (projectionManager != null) { projectionManager.RegisterUser(this); } //Code assumes that this script is added to the camera GO cameraGO = this.gameObject; cameraGO.transform.localPosition = new Vector3(); targetRGBTexture = new RenderTexture(texWidth, texHeight, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Default); targetRGBTexture.filterMode = FilterMode.Trilinear; targetRGBTexture.autoGenerateMips = true; targetRGBTexture.depth = 24; targetRGBTexture.Create(); rectReadRT = new Rect(0, 0, texWidth, texHeight); depthMeshes = GameObject.FindObjectsOfType <RATDepthMesh>(); initialized = true; }
void Start() { meshFilter = gameObject.AddComponent <MeshFilter>(); meshRenderer = gameObject.AddComponent <MeshRenderer>(); Shader unlitShader = Shader.Find("Unlit/Texture"); meshMat = new Material(unlitShader); debugPlaneM = new Mesh(); meshFilter.hideFlags = HideFlags.HideInInspector; meshRenderer.hideFlags = HideFlags.HideInInspector; meshMat.hideFlags = HideFlags.HideInInspector; if (projectionManager == null) { projectionManager = GameObject.FindObjectOfType <RATProjectionManager>(); } if (projectionManager != null) { projectionManager.RegisterUser(this); } //Code assumes that this script is added to the camera GO cameraGO = this.gameObject; cam = this.GetComponent <Camera>(); if (cam == null) { cam = gameObject.AddComponent <Camera>(); } cam.hideFlags = HideFlags.HideInInspector; // | HideFlags.HideInHierarchy cam.rect = new Rect(0, 0, 1, 1); cam.enabled = false; //important to disable this camera as we will be calling Render() directly. cam.aspect = texWidth / texHeight; cameraGO.transform.localPosition = new Vector3(); targetRGBTexture = new RenderTexture(texWidth, texHeight, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Default); targetRGBTexture.filterMode = FilterMode.Trilinear; targetRGBTexture.autoGenerateMips = true; targetRGBTexture.depth = 24; targetRGBTexture.Create(); rectReadRT = new Rect(0, 0, texWidth, texHeight); depthMeshes = GameObject.FindObjectsOfType <RATDepthMesh>(); initialized = true; }
/// <summary> /// Very destructive operation. Use with caution! /// </summary> public void ClearSceneComponents() { var klist = transform.GetComponentsInChildren <RATKinectClient>(true); foreach (RATKinectClient k in klist) { DestroyImmediate(k.transform.gameObject); } var plist = transform.GetComponentsInChildren <RATProjector>(true); foreach (RATProjector p in plist) { DestroyImmediate(p.transform.gameObject); } RATProjectionManager projManager = GetComponent <RATProjectionManager>(); if (projManager != null) { DestroyImmediate(projManager); } }
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++]; } } }