// Draw a corner if the 3 spawnedWalls intersect at a single point private void DrawOneCorner(GameObject s0, GameObject s1, GameObject s2) { Vector3 point; bool success = Math3DUtils.planesIntersectAtSinglePoint(s0, s1, s2, out point); if (success) { GameObject go = Math3DUtils.CreateSphere(point, Color.yellow, 0.1f); ui3dGOs.Add(go); go.name = "Corner"; GameObject line0 = DrawCornerLine(point, s0, s1, s2); GameObject line1 = DrawCornerLine(point, s1, s2, s0); GameObject line2 = DrawCornerLine(point, s2, s0, s1); if (line0) { line0.transform.parent = go.transform; } if (line1) { line1.transform.parent = go.transform; } if (line2) { line2.transform.parent = go.transform; } AddPointToWall(s0, point); AddPointToWall(s1, point); AddPointToWall(s2, point); } }
float getAngle(int t, Camera camera) { Mesh m = getMesh(); Vector3 a = worldVertices[m.triangles[t * 3 + 0]]; Vector3 b = worldVertices[m.triangles[t * 3 + 1]]; Vector3 c = worldVertices[m.triangles[t * 3 + 2]]; Plane plane = new Plane(a, b, c); Vector3 norm = plane.normal; Vector3 dirProjector = camera.transform.forward; float angle = Vector3.Angle(norm, -dirProjector); if (debug) { Debug.Log("normal:" + norm); Math3DUtils.CreateSphere(a, Color.gray); Debug.DrawRay(a, norm, Color.white, 100); Debug.DrawRay(a, -dirProjector, Color.black, 100); Debug.Log("dir:" + this.transform.forward); Debug.Log("Angle:" + angle); // mod 90 } return(angle); }
public string GetImage1() //not blocking, screenshot will be done later { float hfov = calculateFov(); string fn = System.DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + "_fov_" + hfov + "_screenshot.jpg"; ScreenCapture.CaptureScreenshot(fn); //doesnt not block image, screenshot will be done/written in few ms later Math3DUtils.Log("Focal: " + hfov + " Resolution: " + Screen.width + "x" + Screen.height + "Fn: " + fn); return(fn); }
void Start() { Math3DUtils.MeshDivide(go); Math3DUtils.MeshDivide(go); Math3DUtils.MeshDivide(go); Math3DUtils.MeshDivide(go); Math3DUtils.MeshDivide(go); Math3DUtils.MeshDivide(go); Math3DUtils.MeshDivide(go); Math3DUtils.MeshDivide(go); }
private void DrawOneLine(GameObject spawnedA, GameObject spawnedB) { Vector3 point = Vector3.zero; Vector3 direction = Vector3.zero; bool success = Math3DUtils.planePlaneIntersection(out point, out direction, spawnedA, spawnedB); if (success) { DebugDrawLineVect(point, direction, 0.5f, Color.red, 10f); InstLine(point, direction, Color.yellow); } }
// Draw a lines private GameObject DrawCornerLine(Vector3 point, GameObject s0, GameObject s1, GameObject s2) { Vector3 point0; Vector3 dir0; bool success0 = Math3DUtils.planePlaneIntersection(out point0, out dir0, s0, s1); if (success0) { Vector3 dir0fixed = FixPositiveNegative(dir0, s2); return(InstLine(point + dir0fixed / 2, dir0, Color.yellow)); } return(null); }
public string GetImage() //blocking until screenshot is done { float hfov = calculateFov(); Texture2D snap = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false); snap.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0); snap.Apply(); string fn = System.DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + "_fov_" + hfov + "_tscreenshot.jpg"; string pathSnap = Application.persistentDataPath + "/" + fn; System.IO.File.WriteAllBytes(Application.persistentDataPath + "/" + fn, snap.EncodeToJPG()); Math3DUtils.Log("Focal: " + hfov + " Resolution: " + Screen.width + "x" + Screen.height + "Fn: " + fn); return(fn); }
void GenerateObj() { Debug.Log("Divide walls into smaller triangles"); Math3DUtils.MeshDivide(wallsQuads, 7); List <Camera> cameras = new List <Camera>(); foreach (GameObject go in projectors) { if (go.active) //to be able to disable some projection to debug { cameras.Add(go.GetComponent <Camera>()); } } String path = ObjExportUtils.Export(cameras, this.wallsQuads); Debug.Log("File created: " + path); }
private void ReDrawUI3D() { DestroyUI3D(); //Draw points with "axis" if (spawnedWalls.Count >= 3) { for (int i = 0; i < spawnedWalls.Count - 2; i++) { for (int j = i + 1; j < spawnedWalls.Count - 1; j++) { for (int k = j + 1; k < spawnedWalls.Count; k++) { DrawOneCorner(spawnedWalls[i], spawnedWalls[j], spawnedWalls[k]); } } } } foreach (List <Vector3> vs in wallPointsList.Values) { GameObject go = new GameObject("Wall"); //Draw lines between points int count = vs.Count; for (int i = 0; i < count - 1; i++) { for (int j = i; j < count; j++) { Math3DUtils.CreateLine(vs[i], vs[j]).transform.parent = go.transform; } } //Draw quad if (vs.Count == 4) { GameObject goQuad = Math3DUtils.CreateQuad(vs.ToArray(), matWall, true); wallsQuads.Add(goQuad); goQuad.transform.parent = go.transform; } ui3dGOs.Add(go); } //Draw photo frame from photo taken // also load fov ? foreach (GameObject go in spawnedPhotos) { projectors.Add(DrawProjector(dirname + "/" + go.name, go.transform.position, go.transform.rotation)); } // Add Projector to dropdown if (dropdownCamera) { //Draw photo frame and add them to dropdown dropdownCameraValues.Add("All", null); foreach (GameObject projector in projectors) { dropdownCameraValues.Add(projector.name.Substring(14), projector); } dropdownCamera.AddOptions(dropdownCameraValues.Keys.ToList <string>()); } }
public string fn = null; //dir + image name eg "2020-12-24_143059/2020-12-24_143059....jpg" // Draw frame and put it 1m far from camera void Start() { this.name = "Projector " + fn; //load texture if (!String.IsNullOrEmpty(fn)) //otherwise display already loaded texture projectcube.jpg { string path = UnityEngine.Application.persistentDataPath + "/" + fn; if (!System.IO.File.Exists(path)) { Debug.LogError("file not found: " + path); } byte[] fileData = System.IO.File.ReadAllBytes(path); Texture2D tex = new Texture2D(1, 1); tex.LoadImage(fileData); //load also width/height plane.GetComponent <Renderer>().material.mainTexture = tex; //project texture this.GetComponent <Projector>().material = new Material(Shader.Find("Projector/Multiply")); Material thisProjectorMat = this.GetComponent <Projector>().material; thisProjectorMat.SetTexture("_ShadowTex", tex); thisProjectorMat.SetTexture("_FalloffTex", tex); this.GetComponent <Projector>().material = thisProjectorMat; w = tex.width; h = tex.height; } else { w = 4618; h = 3464; } this.GetComponent <Camera>().aspect = this.GetComponent <Projector>().aspectRatio = (float)w / h; this.GetComponent <Camera>().fieldOfView = this.GetComponent <Projector>().fieldOfView = this.vfov; float hfov = getHorizontalFov(); Debug.Log("vfov:" + this.vfov + " hfov:" + hfov + " w:" + w + " h:" + h + " fn:" + fn); var halfw = getHalfWidth(); var halfh = getHalfHeight(); Vector3 centerplane = this.transform.position + this.transform.forward * far; //an alternative is to use go.transform.Translate plane.transform.position = centerplane; plane.transform.localScale = new Vector3(halfw * 2f, halfh * 2f, 1f); Vector3 ne = ProjectOnPlaneViewport(new Vector2(1, 1)); Vector3 se = ProjectOnPlaneViewport(new Vector2(1, 0)); Vector3 sw = ProjectOnPlaneViewport(new Vector2(0, 0)); Vector3 nw = ProjectOnPlaneViewport(new Vector2(0, 1)); Debug.DrawLine(this.transform.position, centerplane, Color.blue, 99f); Debug.DrawLine(this.transform.position, ne, Color.white, 99f); Debug.DrawLine(this.transform.position, se, Color.white, 99f); Debug.DrawLine(this.transform.position, sw, Color.white, 99f); Debug.DrawLine(this.transform.position, nw, Color.white, 99f); Math3DUtils.CreateSphere(ne, Color.red, 0.01f).transform.parent = this.transform; Math3DUtils.CreateSphere(se, Color.red, 0.01f).transform.parent = this.transform; Math3DUtils.CreateSphere(sw, Color.red, 0.01f).transform.parent = this.transform; Math3DUtils.CreateSphere(nw, Color.red, 0.01f).transform.parent = this.transform; //https://forum.unity.com/threads/solved-image-projection-shader.254196/ }