// Loads a file using a path private void LoadFileUsingPath(string path) { if (path.Length != 0) { importedPath = path; //this is how a Collada is loaded FileStream file = File.OpenRead(importedPath); XmlDocument doc = new XmlDocument(); string aux; using (StreamReader reader = new StreamReader(file)) { aux = reader.ReadToEnd(); } doc.LoadXml(aux); //The xml has been loaded. A collada is a xml file GameObject importedGO = new GameObject(); ColladaImporter importer = new ColladaImporter(ref importedGO); //This calls the class that loads the collada model. We made it a coroutine in order to have a loading screen StartCoroutine(importer.getMesh(doc, shader)); //This gets the filesize to show it on the screen System.IO.FileInfo fileInfo = new System.IO.FileInfo(importedPath); ulong mapFileSize = (ulong)fileInfo.Length; mapFileSize = mapFileSize / 1024; MissionManager.fileSize = mapFileSize; //This sends the loading screen into a class that is not going to be destroyed modelLoadingPanel.SetActive(true); StartCoroutine(WaitForModel()); //CalibrateOrLoad(); //if (clientUnity.client.isConnected) //{ // SceneManager.LoadScene("ModelAlignment"); //} //else { //planSelectionPanel.SetActive(true); Destroy(); //} //titletext.SetActive(false); //textosave.SetActive(false); //savefile.SetActive(false); //loadedtext.SetActive(false); //loadfile.SetActive(false); //slider.SetActive(true); //slider2.SetActive(true); //slider3.SetActive(true); //slider4.SetActive(true); //inputfield.SetActive(true); //inputfield2.SetActive(true); //inputfield3.SetActive(true); } else { UnityEngine.Debug.Log("Invalid path given"); } }
public void LoadDOC(XmlDocument doc, Shader shader) { GameObject importedGO = new GameObject(); ColladaImporter importer = new ColladaImporter(ref importedGO); StartCoroutine(importer.getMesh(doc, shader)); importedGO.name = "DaeModelChild"; //DontDestroyOnLoad(importedGO); //if (!Directory.Exists(Application.dataPath + "/Resources/" + "bb8.fbx") && Directory.Exists(Application.dataPath)) //GameObject aux = Instantiate(File.OpenRead(path)) as GameObject; //Canvas.GetComponent<PlaceModel>().Change(mesh); //GameObject aux = Instantiate(AssetBundle.LoadFromFile(path) as GameObject; // Convert the file from a byte array into a string //string fileData = bFormatter.Deserialize(file) as string; //Mesh mesh = FastObjImporter.Instance.ImportFile(path); }
// Loads a file using a path private void LoadFileUsingPath(string path) { if (path.Length != 0) { BinaryFormatter bFormatter = new BinaryFormatter(); // Open the file using the path FileStream file = File.OpenRead(path); //var xmlWriter = new XmlTextWriter(file, Encoding.UTF8); //xmlWriter. XmlDocument doc = new XmlDocument(); string aux; using (StreamReader reader = new StreamReader(file)) { aux = reader.ReadToEnd(); } doc.LoadXml(aux); //The xml has been loaded. A collada is a xml file GameObject mesh = new GameObject(); ColladaImporter importer = new ColladaImporter(ref mesh); //This calls the class that loads the collada model. We made it a coroutine in order to have a loading screen StartCoroutine(importer.getMesh(doc, shader)); //if (!Directory.Exists(Application.dataPath + "/Resources/" + "bb8.fbx") && Directory.Exists(Application.dataPath)) //GameObject aux = Instantiate(File.OpenRead(path)) as GameObject; Canvas.GetComponent <PlaceModel>().Change(mesh); //GameObject aux = Instantiate(AssetBundle.LoadFromFile(path) as GameObject; // Convert the file from a byte array into a string //string fileData = bFormatter.Deserialize(file) as string; //Mesh mesh = FastObjImporter.Instance.ImportFile(path); titletext.SetActive(false); textosave.SetActive(false); savefile.SetActive(false); loadedtext.SetActive(false); loadfile.SetActive(false); slider.SetActive(true); slider2.SetActive(true); slider3.SetActive(true); slider4.SetActive(true); inputfield.SetActive(true); inputfield2.SetActive(true); inputfield3.SetActive(true); //CombineInstance[] combine = new CombineInstance[aux.Length]; /*while (i < aux.Length) * { * combine[i].mesh = aux[i]; * //combine[i].transform = aux[i].transform.localToWorldMatrix; * //meshFilters[i].gameObject.active = false; * i++; * } * //Mesh[] mesh = Resources.LoadAll<Mesh>("mapa"); * // We're done working with the file so we can close it * //file.Close(); * // Set the LoadedText with the value of the file * //_loadedText.GetComponent<Text>().text = "Loaded data: \n" + fileData; * GameObject sderfd = new GameObject(); * sderfd.transform.position = new Vector3(0, 0, 0); * sderfd.AddComponent<MeshFilter>(); * * sderfd.GetComponent<MeshFilter>().mesh.CombineMeshes(combine); * sderfd.AddComponent<MeshRenderer>();*/ } else { UnityEngine.Debug.Log("Invalid path given"); } }
/// <summary> /// This is the main fucntion that loads the map and the plan waypoints /// </summary> /// <param name="path"></param> void LoadMap(string path) { //We load the main path if (ownPath == null) { ownPath = Path.Instance; } //laod the metadata string json = System.IO.File.ReadAllText(path); MapMetadata metadata = JsonUtility.FromJson <MapMetadata>(json); UnityEngine.Debug.Log("Loading map"); BinaryFormatter bFormatter = new BinaryFormatter(); //if (!AskForMap()) // return; FileStream file; //If it is a pointcloud we load a pointcloud map, and if it isn't a collada if (metadata.Map_type == (byte)MapMetadata.MapType.PointCloud) { file = File.OpenRead(Application.persistentDataPath + "/PersistentData/Maps/" + MissionManager.guid + ".dpl.map"); } else { file = File.OpenRead(Application.persistentDataPath + "/PersistentData/Maps/" + MissionManager.guid + ".dae.map"); } //var xmlWriter = new XmlTextWriter(file, Encoding.UTF8); //xmlWriter. XmlDocument doc = new XmlDocument(); string aux; GameObject auxGameObject = new GameObject(); UnityEngine.Debug.Log(MissionManager.invMatrix); //An empty box and a 3d model are the same if (metadata.Map_type == (byte)MapMetadata.MapType.EmptyBox) { using (StreamReader reader = new StreamReader(file)) { aux = reader.ReadToEnd(); } doc.LoadXml(aux); ColladaImporter importer = new ColladaImporter(ref auxGameObject); StartCoroutine(importer.getMesh(doc, cullBackShader)); } else if (metadata.Map_type == (byte)MapMetadata.MapType.Model3D) { using (StreamReader reader = new StreamReader(file)) { aux = reader.ReadToEnd(); } doc.LoadXml(aux); ColladaImporter importer = new ColladaImporter(ref auxGameObject); StartCoroutine(importer.getMesh(doc, shader)); }//But pointclouds are loaded different else { //MapLoader used in mapalignment uses this exact function and they are already explained there createBaseTriangle(); byte[] pclBytes = File.ReadAllBytes(Application.persistentDataPath + "/PersistentData/Maps/" + MissionManager.guid + ".dpl.map"); GameObject daeModel = new GameObject(); daeModel.name = "DaeModel"; daeModel.transform.parent = auxGameObject.transform; LoadPointCloud(pclBytes, ref daeModel); //SavedPointCloud pointCloud = JsonUtility.FromJson<SavedPointCloud>(aux); // //for (int i = 0; i < pointCloud.PointCloud.Count; i++) //{ // // GameObject gameObject = Instantiate(pcPrefab, auxGameObject.transform); // gameObject.GetComponent<MeshFilter>().sharedMesh = new Mesh(); // gameObject.GetComponent<MeshFilter>().sharedMesh.name = "cmesh" + i.ToString(); // gameObject.GetComponent<MeshFilter>().mesh.vertices = pointCloud.PointCloud[i].vertex; // int[] indices = new int[pointCloud.PointCloud[i].vertex.Length]; // Color[] colors = new Color[indices.Length]; // for (int j = 0; j < pointCloud.PointCloud[i].vertex.Length; j++) // { // indices[j] = j; // colors[j] = new Color(pointCloud.PointCloud[i].colors[j].x, pointCloud.PointCloud[i].colors[j].y, pointCloud.PointCloud[i].colors[j].z, 1); // } // gameObject.GetComponent<MeshFilter>().mesh.colors = colors; // gameObject.GetComponent<MeshFilter>().mesh.RecalculateNormals(); // gameObject.GetComponent<MeshFilter>().mesh.SetIndices(indices, MeshTopology.Triangles, 0, true); // gameObject.GetComponent<MeshFilter>().mesh.RecalculateBounds(); // Matrix4x4 auxMat = pointCloud.PointCloud[i].matrix; // gameObject.transform.rotation = auxMat.rotation; // gameObject.transform.position = new Vector3(auxMat.m03, auxMat.m13, auxMat.m23); // // //} } //Once the maps are loaded, we start with the waypoints. First a mission is loaded auxGameObject.name = "DaemodelChild"; string mapJson = File.ReadAllText(Application.persistentDataPath + "/PersistentData/Missions/" + MissionManager.guid + ".json.mission"); Map map = JsonUtility.FromJson <Map>(mapJson); Path waypointPath = Path.Instance; //sphereParentGO.transform.position = auxGameObject.transform.position; //If this isn't a new plan, we load the plan selected previously if (MissionManager.planIndex != -1) { //Here we get a plan from all the paths saved in missionmanager waypointPath = map.Paths[MissionManager.planIndex]; ownPath.setPath(waypointPath); //And give them the default parameters previously selected MissionManager.planDefaultHeight = waypointPath.FlightParams.height; MissionManager.planDefaultSpeed = waypointPath.FlightParams.speed; MissionManager.planDefaultDuration = waypointPath.FlightParams.duration; //Here we instantiate the waypoints for (int i = 0; i < waypointPath.Count(); i++) { //waypointPath.GetPoint(i).PointPosition = new Vector3(waypointPath.GetPoint(i).PointPosition.x, waypointPath.GetPoint(i).PointPosition.z, waypointPath.GetPoint(i).PointPosition.y); GameObject auxPoint = Instantiate(pointGO, waypointPath.GetPoint(i).PointPosition, Quaternion.Euler(0, 0, 0), sphereParentGO.transform); //assign them the transform to the script waypointPath.GetPoint(i).PointTransf = auxPoint.transform; auxPoint.SetActive(true); //Scale it TransformSphere(topCam, auxPoint); //And if it is the first one, we assign it the yellow colour, and to the last one, the green colour. The rest use the normal waypoint colour if (i == 0) { auxPoint.transform.GetChild(0).GetComponent <Renderer>().sharedMaterial = homeNotSelectedMaterial; //auxPoint.transform.GetChild(1).GetComponent<Renderer>().sharedMaterial.color = Color.white; } else if (i != waypointPath.Count() - 1) { auxPoint.transform.GetChild(0).GetComponent <Renderer>().sharedMaterial = waypointNotSelectedMaterial; // auxPoint.transform.GetChild(1).GetComponent<Renderer>().sharedMaterial.color = Color.white; //auxPoint.transform.GetChild(0).GetComponent<Renderer>().sharedMaterial = whiteOutlineMaterial; //auxPoint.transform.GetChild(1).GetComponent<Renderer>().sharedMaterial = whiteOutlineMaterial; } else { //auxPoint.transform.GetChild(0).GetComponent<Renderer>().sharedMaterial = landingMaterial; //auxPoint.transform.GetChild(1).GetComponent<Renderer>().sharedMaterial = landingMaterial; auxPoint.transform.GetChild(0).GetComponent <Renderer>().sharedMaterial = landingNotSelectedMaterial; //auxPoint.transform.GetChild(1).GetComponent<Renderer>().sharedMaterial.color = Color.white; } //We assign the monobehaviour that contains the point parameters auxPoint.AddComponent <PathPoint>().createPathPointWithPoint(waypointPath.GetPoint(i), 0, 0); } //here we create the middlepoints that the curve contains for (int i = 0; i < waypointPath.Count() - 1; i++) { lineMat.SetPass(0); if (topCam != null) { CatmullRomSpline.DisplayCatmullRomSpline2(waypointPath, i, ref waypointPath.middlePointsTop, topCam.orthographicSize / 2.0f, true, topCam); } if (frontCam != null) { CatmullRomSpline.DisplayCatmullRomSpline(waypointPath, i, ref waypointPath.middlePointsRight, frontCam.orthographicSize / 2.0f, true, frontCam); } } //This script is also used on recording, where we don't want points of interests. We adjust the path to the adjustmnets doen in model alignment and exit if (GeneralSceneManager.sceneState == GeneralSceneManager.SceneState.Recording) { sphereParentGO.transform.position = new Vector3(map.unityToAnchors.m03 * 0.001f, map.unityToAnchors.m23 * 0.001f, map.unityToAnchors.m13 * 0.001f); sphereParentGO.transform.localScale = new Vector3(map.unityToAnchors.m00 * 0.001f, map.unityToAnchors.m11 * 0.001f, map.unityToAnchors.m22 * 0.001f); return; } //If not we create the points of interest poisCreated = new List <GameObject>(); for (int i = 0; i < waypointPath.wpParametersCount(); i++) { //for each waypoint of interest that the path contains, we assign it to the respective waypoint GimballParameters auxGimballUpdateParameters = waypointPath.getGbUpdateParameter(i); Point auxPoint = waypointPath.GetPoint(auxGimballUpdateParameters.id_pointer); auxPoint.PointTransf.gameObject.GetComponent <PathPoint>().Wp.gimbal_parameters = auxGimballUpdateParameters; //And now depending on the type of point of interest, one behaviour is assigned. It can be a look at point, look at the curve, //locked in yaw only while looking in a direction or looking in a direction without locks switch (auxGimballUpdateParameters.mode) { case 0: GameObject newpoi; //First we search for a POI System.Predicate <GameObject> predicate = (GameObject p) => { return(p.transform.position == auxGimballUpdateParameters.poi_or_angles); }; //If one POI has been placed at least if (poisCreated.Count > 0) { //we find if the POI was already there, just in case multiple waypoints share the same POI newpoi = poisCreated.Find(predicate); if (newpoi == null) { newpoi = Instantiate(poi, auxGimballUpdateParameters.poi_or_angles, Quaternion.Euler(new Vector3(0, 0, 0))); poisCreated.Add(newpoi); newpoi.AddComponent <POI>(); } } else { newpoi = Instantiate(poi, auxGimballUpdateParameters.poi_or_angles, Quaternion.Euler(new Vector3(0, 0, 0))); poisCreated.Add(newpoi); newpoi.AddComponent <POI>(); } //We create a new line that points from the POI to the waypoint. The poi object already has one, but if there is more than one waypoint //related to the POI, we need to create more lines GameObject newLine = newpoi.transform.GetChild(2).gameObject; if (i > 0) { newLine = Instantiate(poi.transform.GetChild(2).gameObject, newpoi.transform.position, Quaternion.Euler(new Vector3(0, 0, 0)), newpoi.transform); } //All of this calculate the rotation, position and size of the line Vector3 centerPos = new Vector3(auxPoint.PointTransf.position.x + newpoi.transform.position.x, auxPoint.PointTransf.position.y + newpoi.transform.position.y, auxPoint.PointTransf.position.z + newpoi.transform.position.z) / 2f; float scaleX = Mathf.Abs((auxPoint.PointTransf.position - newpoi.transform.position).magnitude); newLine.transform.localScale = new Vector3(scaleX, 3f, 3f); //Esto es para rotar las imagenes de las camaras que tienen cada Waypoint Transform cube = auxPoint.PointTransf.Find("CubeTop"); cube.gameObject.SetActive(true); //float distance = Vector3.Distance(item.transform.position, newpoi.transform.position); //float distance2 = Vector3.Distance(cube.position, item.transform.position) * 2; Vector2 from = new Vector2(-1, 0); Vector3 aux2 = newpoi.transform.position - auxPoint.PointTransf.position; Vector2 to = new Vector2(aux2.x, aux2.z).normalized; float angle = Vector2.SignedAngle(from, to); Transform cube2 = auxPoint.PointTransf.Find("CubeFront"); //float distance = Vector3.Distance(item.transform.position, newpoi.transform.position); //float distance2 = Vector3.Distance(cube.position, item.transform.position) * 2; Vector2 from2 = new Vector2(-1, 0); Vector3 aux3 = newpoi.transform.position - auxPoint.PointTransf.position; Vector2 to2 = new Vector2(aux3.x, aux3.y).normalized; float angle2 = Vector2.SignedAngle(from2, to2); //float angle = Mathf.Acos(distance2 / distance); //item.transform.Rotate(new Vector3(0, 1, 0), Vector2.Angle(from, to)); cube.transform.rotation = Quaternion.Euler(new Vector3(0, -angle, 0)); cube2.transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle2)); cube.GetChild(0).GetComponent <MeshRenderer>().material.color = Color.white; cube2.GetChild(0).GetComponent <MeshRenderer>().material.color = Color.white; auxPoint.PointTransf.GetComponent <PathPoint>().Poi = newpoi.transform; newpoi.GetComponent <POI>().addPoint(auxPoint.PointTransf.GetComponent <PathPoint>(), newLine); //UnityEngine.Debug.Log(newpoi.GetComponent<POI>().Referenced.Count); float sineC = (auxPoint.PointTransf.position.y - newpoi.transform.position.y) / scaleX; newLine.transform.rotation = Quaternion.Euler(0, -angle, Mathf.Asin(sineC) * Mathf.Rad2Deg); newLine.transform.position = newpoi.transform.position; var rotation = Quaternion.Euler(0, -angle, Mathf.Asin(sineC) * Mathf.Rad2Deg).eulerAngles; auxPoint.PointTransf.GetComponent <PathPoint>().GimbalRotation = new Vector3(rotation.z, rotation.y, rotation.x + 90); auxPoint.PointTransf.GetComponent <PathPoint>().getGimballMode = 0; TransformSphere(topCam, newpoi); break; case 1: //This is the case where the direction will always point to the curve float angle3 = 0; float angle4 = 0; int middlePointsIndexTop = 0; int middlePointsIndexRight = 0; //We iterate through the array to see the closest point from the curve to the waypoint. The signal that indicates this mode is activated is a green camera looking at that point on the waypoint. for (i = 0; i < waypointPath.Count(); i++) { if (waypointPath.GetPoint(i) == auxPoint) { break; } middlePointsIndexTop += waypointPath.GetPoint(i).SegmentsTop; middlePointsIndexRight += waypointPath.GetPoint(i).SegmentsRight; } //If this is the last point, there is no curve to look at anymore if (middlePointsIndexRight >= waypointPath.middlePointsRight.Count) { break; } //Now from here we calculate the rotation of the camera mentioned above Vector3 pointRight = waypointPath.middlePointsRight[middlePointsIndexRight]; Vector3 pointTop = waypointPath.middlePointsTop[middlePointsIndexTop]; //Esto es para rotar las imagenes de las camaras que tienen cada Waypoint Transform cube3 = auxPoint.PointTransf.Find("CubeTop"); cube3.gameObject.SetActive(true); //float distance = Vector3.Distance(item.transform.position, newpoi.transform.position); //float distance2 = Vector3.Distance(cube.position, item.transform.position) * 2; Vector2 from3 = new Vector2(-1, 0); Vector3 aux4 = pointTop - auxPoint.PointTransf.position; Vector2 to3 = new Vector2(aux4.x, aux4.z).normalized; angle3 = Vector2.SignedAngle(from3, to3); Transform cube4 = auxPoint.PointTransf.Find("CubeFront"); cube4.gameObject.SetActive(true); cube3.GetChild(0).GetComponent <MeshRenderer>().material.color = Color.green; cube4.GetChild(0).GetComponent <MeshRenderer>().material.color = Color.green; //float distance = Vector3.Distance(item.transform.position, newpoi.transform.position); //float distance2 = Vector3.Distance(cube.position, item.transform.position) * 2; Vector2 from4 = new Vector2(-1, 0); Vector3 aux5 = pointRight - auxPoint.PointTransf.position; Vector2 to4 = new Vector2(aux5.x, aux5.y).normalized; angle4 = Vector2.SignedAngle(from4, to4); //float angle = Mathf.Acos(distance2 / distance); //item.transform.Rotate(new Vector3(0, 1, 0), Vector2.Angle(from, to)); cube3.transform.rotation = Quaternion.Euler(new Vector3(0, -angle3, 0)); cube4.transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle4)); //UnityEngine.Debug.Log(newpoi.GetComponent<POI>().Referenced.Count); break; case 2: //This mode is for a direction with the yaw? locked //We only show a line in this mode, so even if we instantiate a poi, is not shown GameObject newpoi2 = Instantiate(poi, auxGimballUpdateParameters.poi_or_angles + auxPoint.PointTransf.position, Quaternion.Euler(new Vector3(0, 0, 0))); //UnityEngine.Debug.Log(" POI POS: " + auxGimballUpdateParameters.poi_or_angles + " ITEM POS: " + auxPoint.PointTransf.position); /* * if (Input.mousePosition.x < Camera.main.pixelWidth / 2) * { * newpoi.transform.position = new Vector3(newpoi.transform.position.x, 0, newpoi.transform.position.z); * * } * else * { * newpoi.transform.position = new Vector3(newpoi.transform.position.x, newpoi.transform.position.y, 1); * * }*/ newpoi2.SetActive(true); newpoi2.transform.GetChild(0).gameObject.SetActive(false); newpoi2.transform.GetChild(1).gameObject.SetActive(false); newpoi2.AddComponent <POI>(); newpoi2.GetComponent <POI>().Direction = true; float angle5 = 0; float angle6 = 0; float sineC5 = 0; //from now on, we isntantiate a line and calculate position and direction GameObject newLine2 = newpoi2.transform.GetChild(2).gameObject; if (i > 0) { newLine2 = Instantiate(poi.transform.GetChild(2).gameObject, newpoi2.transform.position, Quaternion.Euler(new Vector3(0, 0, 90)), newpoi2.transform); } newLine2.transform.GetChild(0).GetComponent <Renderer>().material.color = Color.grey; newLine2.transform.GetChild(0).gameObject.layer = 10; //Que tamaño tendra float scaleX5 = Mathf.Abs((auxPoint.PointTransf.position - newpoi2.transform.position).magnitude); newLine2.transform.localScale = new Vector3(scaleX5, 3f, 3f); //Esto es para rotar las imagenes de las camaras que tienen cada Waypoint Transform cube5 = auxPoint.PointTransf.Find("CubeTop"); cube5.gameObject.SetActive(false); //float distance = Vector3.Distance(item.transform.position, newpoi.transform.position); //float distance2 = Vector3.Distance(cube.position, item.transform.position) * 2; Vector2 from5 = new Vector2(-1, 0); Vector3 aux6 = newpoi2.transform.position - auxPoint.PointTransf.position; Vector2 to5 = new Vector2(aux6.x, aux6.z).normalized; if (i == 0) { angle5 = Vector2.SignedAngle(from5, to5); } Transform cube6 = auxPoint.PointTransf.Find("CubeFront"); //float distance = Vector3.Distance(item.transform.position, newpoi.transform.position); //float distance2 = Vector3.Distance(cube.position, item.transform.position) * 2; Vector2 from6 = new Vector2(-1, 0); Vector3 aux7 = newpoi2.transform.position - auxPoint.PointTransf.position; Vector2 to6 = new Vector2(aux7.x, aux7.y).normalized; if (i == 0) { angle6 = Vector2.SignedAngle(from6, to6); } //float angle = Mathf.Acos(distance2 / distance); //item.transform.Rotate(new Vector3(0, 1, 0), Vector2.Angle(from, to)); cube5.transform.rotation = Quaternion.Euler(new Vector3(0, -angle5, 0)); cube6.transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle6)); cube5.GetChild(0).GetComponent <MeshRenderer>().material.color = Color.white; cube6.GetChild(0).GetComponent <MeshRenderer>().material.color = Color.white; auxPoint.PointTransf.GetComponent <PathPoint>().Poi = newpoi2.transform; newpoi2.GetComponent <POI>().addPoint(auxPoint.PointTransf.GetComponent <PathPoint>(), newLine2); //UnityEngine.Debug.Log(newpoi.GetComponent<POI>().Referenced.Count); sineC5 = (auxPoint.PointTransf.transform.position.y - newpoi2.transform.position.y) / scaleX5; newLine2.transform.rotation = Quaternion.Euler(0, -angle5, Mathf.Asin(sineC5) * Mathf.Rad2Deg); newLine2.transform.position = auxPoint.PointTransf.transform.position; var rotation2 = Quaternion.Euler(0, -angle5, Mathf.Asin(sineC5) * Mathf.Rad2Deg).eulerAngles; break; case 3: //Same as above without locking yaw GameObject newpoi3 = Instantiate(poi, auxGimballUpdateParameters.poi_or_angles + auxPoint.PointTransf.position, Quaternion.Euler(new Vector3(0, 0, 0))); newpoi3.transform.GetChild(0).gameObject.SetActive(false); newpoi3.transform.GetChild(1).gameObject.SetActive(false); newpoi3.AddComponent <POI>(); newpoi3.GetComponent <POI>().Direction = true; float angle7 = 0; float angle8 = 0; float sineC7 = 0; //Creamos una nueva linea que apunta del waypoint al POI GameObject newLine3 = newpoi3.transform.GetChild(2).gameObject; //newLine3 = Instantiate(poi.transform.GetChild(2).gameObject, newpoi3.transform.position, Quaternion.Euler(new Vector3(0, 0, 0)), newpoi3.transform); newLine3.transform.GetChild(0).GetComponent <Renderer>().material.color = Color.gray; //Que tamaño tendra float scaleX7 = Mathf.Abs((auxPoint.PointTransf.position - newpoi3.transform.position).magnitude); newLine3.transform.localScale = new Vector3(scaleX7, 3f, 3f); //Esto es para rotar las imagenes de las camaras que tienen cada Waypoint Transform cube7 = auxPoint.PointTransf.Find("CubeTop"); cube7.gameObject.SetActive(true); //float distance = Vector3.Distance(item.transform.position, newpoi.transform.position); //float distance2 = Vector3.Distance(cube.position, item.transform.position) * 2; Vector2 from7 = new Vector2(-1, 0); Vector3 aux8 = newpoi3.transform.position - auxPoint.PointTransf.position; Vector2 to7 = new Vector2(aux8.x, aux8.z).normalized; if (i == 0) { angle7 = Vector2.SignedAngle(from7, to7); } Transform cube8 = auxPoint.PointTransf.Find("CubeFront"); //float distance = Vector3.Distance(item.transform.position, newpoi.transform.position); //float distance2 = Vector3.Distance(cube.position, item.transform.position) * 2; Vector2 from8 = new Vector2(-1, 0); Vector3 aux9 = newpoi3.transform.position - auxPoint.PointTransf.position; Vector2 to8 = new Vector2(aux8.x, aux8.y).normalized; if (i == 0) { angle2 = Vector2.SignedAngle(from8, to8); } //float angle = Mathf.Acos(distance2 / distance); //item.transform.Rotate(new Vector3(0, 1, 0), Vector2.Angle(from, to)); cube7.transform.rotation = Quaternion.Euler(new Vector3(0, -angle7, 0)); cube8.transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle8)); cube7.GetChild(0).GetComponent <MeshRenderer>().material.color = Color.white; cube8.GetChild(0).GetComponent <MeshRenderer>().material.color = Color.white; auxPoint.PointTransf.GetComponent <PathPoint>().Poi = newpoi3.transform; newpoi3.GetComponent <POI>().addPoint(auxPoint.PointTransf.GetComponent <PathPoint>(), newLine3); //UnityEngine.Debug.Log(newpoi.GetComponent<POI>().Referenced.Count); sineC7 = (auxPoint.PointTransf.position.y - newpoi3.transform.position.y) / scaleX7; newLine3.transform.rotation = Quaternion.Euler(0, -angle7, Mathf.Asin(sineC7) * Mathf.Rad2Deg); newLine3.transform.position = auxPoint.PointTransf.transform.position; break; default: break; } } //This assigns reccam parameters to the waypoints that had them for (int i = 0; i < waypointPath.rcParametersCount(); i++) { RecCamParameters auxRcUpdateParameters = waypointPath.getRcUpdateParameter(i); reSetRecCamGuis(auxRcUpdateParameters, waypointPath.GetPoint(auxRcUpdateParameters.id_pointer).PointTransf.gameObject.GetComponent <PathPoint>()); } if (poiEditorPanel != null) { poiEditorPanel.GetComponent <POIEditor>().Deactivate(); } //activate every panel. If we saved a path, there has to be enough points to make sure this can be done if (editPointButton != null) { editPointButton.interactable = true; editPOIButton.interactable = true; previewButton.interactable = true; CurveButton.interactable = true; } } else //We assign an index to the new path { if (waypointPath != null) { MissionManager.planIndex = map.Paths.Count; } } //importedGO.name = "DaeModel"; }