/// <summary> /// Must be called after initializing the viewing cameras. /// </summary> /// <param name="camIndex"></param> private ClipPlaneManager associateClipPlane(GameObject viewingCam) { //ClipPlaneManager clipPlane = ViewingCameras[camIndex].AddComponent<ClipPlaneManager>(); //ClipPlanes[camIndex] = clipPlane; ClipPlaneManager clipPlane = viewingCam.AddComponent <ClipPlaneManager>(); //UpdateViewingCameraClipPlane(camIndex); UpdateViewingCameraClipPlane(clipPlane, viewingCam); // Add miscellaneous scripts UVCalc uvCalc = viewingCam.AddComponent <UVCalc>(); uvCalc.SetRepresentativePlane(viewingCam.GetComponent <Camera>()); return(clipPlane); }
public Vector2[] GenerateUV(int camIndex) { // Assumes LL, UL, UR, LR Vector2[] UVs = new Vector2[4]; GameObject viewingCam = viewingCamManager.ViewingCameras[camIndex]; UVCalc uvCalc = viewingCam.GetComponent <UVCalc>(); //ClipPlaneManager viewingCamClipPlane = viewingCamManager.ClipPlanes[camIndex]; //Vector3 origin = MainCamera.transform.position; Vector3 origin = viewingCam.transform.position; //PlaneRect aggregatePlane = aggregateClipPlane.GetComponent<AggregateClipPlane>().GenerateAggregatePlaneRect(viewingCamManager.ClipPlanes); Vector3[] aggregatePlaneVertices; bool interpolatedPlaneInitialized = aggregateClipPlane.transform.childCount == 1 && aggregateClipPlane.transform.GetChild(0).name.Equals(aggregateClipPlane.GetComponent <AggregateClipPlane>().PlaneName); if (interpolatedPlaneInitialized) { GameObject interpolatedPlane = aggregateClipPlane.transform.GetChild(0).gameObject; DebugPlaneRect dpr = interpolatedPlane.GetComponent <DebugPlaneRect>(); aggregatePlaneVertices = new Vector3[4] { dpr.LowerLeft, dpr.UpperLeft, dpr.UpperRight, dpr.LowerRight }; //Debug.Log("Taking UV values from Interpolated plane debug plane rectangle."); } else { PlaneRect aggregatePlane = aggregateClipPlane.GetComponent <AggregateClipPlane>().GenerateAggregatePlaneRect(); aggregatePlaneVertices = new Vector3[4] { aggregatePlane.Corner00, aggregatePlane.Corner01, aggregatePlane.Corner11, aggregatePlane.Corner10 }; Debug.Log("Taking UV values from uninitialized plane calculations."); } //Debug.Log("aggregatePlaneVertices[0] = " + aggregatePlaneVertices[0]); //Debug.Log("aggregatePlaneVertices[1] = " + aggregatePlaneVertices[1]); //Debug.Log("aggregatePlaneVertices[2] = " + aggregatePlaneVertices[2]); //Debug.Log("aggregatePlaneVertices[3] = " + aggregatePlaneVertices[3]); // Calculate the UV values of the aggregate plane in terms of the // UV for the clip plane of the given viewing camera clip plane. // This makes it so that the four corners of the aggregate plane // can be passed in as UV values and compared to each of the // textures in the texture array to determine easily if a given uv // value for the aggregate plane corresponds to a point on any of // the independent texture planes //Vector2 LL = uvCalc.UVOffCanvas(origin, viewingCamClipPlane.clipPlane.Corner00); //Vector2 UL = uvCalc.UVOffCanvas(origin, viewingCamClipPlane.clipPlane.Corner01); //Vector2 UR = uvCalc.UVOffCanvas(origin, viewingCamClipPlane.clipPlane.Corner11); //Vector2 LR = uvCalc.UVOffCanvas(origin, viewingCamClipPlane.clipPlane.Corner10); Vector2 LL = uvCalc.UVOffCanvas(origin, aggregatePlaneVertices[0]); // lower left Vector2 UL = uvCalc.UVOffCanvas(origin, aggregatePlaneVertices[1]); // upper left Vector2 UR = uvCalc.UVOffCanvas(origin, aggregatePlaneVertices[2]); // upper right Vector2 LR = uvCalc.UVOffCanvas(origin, aggregatePlaneVertices[3]); // lower right UVs[0] = LL; UVs[1] = UL; UVs[2] = UR; UVs[3] = LR; // update values shown on uvCalc script of viewing camera uvCalc.LowerLeft = LL; uvCalc.UpperLeft = UL; uvCalc.UpperRight = UR; uvCalc.LowerRight = LR; return(UVs); }