Пример #1
0
    /// <summary>
    /// Scans the roboy_worlds repository and stores the worlds in a dictionary.
    /// </summary>
    public void Scan()
    {
        string[] scanArguments = { "python", UpdaterUtility.PathToScanScript, Github_Repository + @"tree/" + Branch };
        CommandlineUtility.RunCommandLine(scanArguments);
        // to do whether scan file exists and is right
        // check whether file exists
        string pathToScanFile = UpdaterUtility.ProjectFolder + @"/tempModelURLs.txt";

        if (!File.Exists(pathToScanFile))
        {
            Debug.LogWarning("Scan file not found! Check whether it exists or if python script is working!");
            return;
        }
        // get file content of format title;url
        string[] scanContent = File.ReadAllLines(pathToScanFile);

        File.Delete(pathToScanFile);

        Dictionary <string, string> tempURLDic = new Dictionary <string, string>();

        foreach (var line in scanContent)
        {
            // split at ":"
            string[] titleURL = line.Split(';');
            // check if there is exactly one ";" meaning only two elements
            if (titleURL.Length != 2)
            {
                Debug.Log("In line:\n" + line + "\nthe format does not match title;URL");
                continue;
            }
            // ignore link if it is not in the github repo
            if (!titleURL[1].Contains(Github_Repository))
            {
                Debug.Log("Link does not have the github repository!");
                continue;
            }
            if (titleURL[0] != "models")
            {
                tempURLDic.Add(titleURL[0], titleURL[1]);
            }
            else
            {
                m_PathToModelsFolder = titleURL[1];
            }
        }
        // clear all old links and add the new links
        m_URLDictionary.Clear();
        m_URLDictionary = tempURLDic;
        WorldChoiceDictionary.Clear();

        Debug.Log(m_PathToModelsFolder);

        //this will be used to select the models to download
        foreach (var urlDicEntry in m_URLDictionary)
        {
            WorldChoiceDictionary.Add(urlDicEntry.Key, false);
        }
        WorldsCurrentState = UpdaterUtility.State.Scanned;
    }
Пример #2
0
    /// <summary>
    /// Downloads the models from the scan dictionary which were selected by the user.
    /// </summary>
    public void UpdateModels()
    {
        string pathToOriginModels = UpdaterUtility.ProjectFolder + @"/SimulationModels/";
        //var processInfo = new ProcessStartInfo("cmd.exe", "/C" + "start \"\" \"" + m_PathToBlender + "\" -P \"" + m_PathToDownloadScript + "\" \"" + pathToMeshes + "\" \"" + m_pathToProjectModels + "\" \"\"");
        //UnityEngine.Debug.Log("Run not implemented yet!");
        // get a list of all entries which the user wants to update
        List <KeyValuePair <string, bool> > tempURLList = ModelChoiceDictionary.Where(entry => entry.Value == true).ToList();

        foreach (var urlEntry in tempURLList)
        {
            string[] scanArguments = { "python", UpdaterUtility.PathToScanScript, m_URLDictionary[urlEntry.Key] };
            CommandlineUtility.RunCommandLine(scanArguments);
            //Debug.Log(m_URLDictionary[urlEntry.Key]);

            string pathToScanFile = UpdaterUtility.ProjectFolder + @"/tempModelURLs.txt";
            if (!File.Exists(pathToScanFile))
            {
                Debug.LogWarning("Scan file not found! Check whether it exists or if python script is working!");
                return;
            }
            // get file content of format title:url
            string[] scanContent = File.ReadAllLines(pathToScanFile);

            File.Delete(pathToScanFile);

            foreach (var line in scanContent)
            {
                string[] titleURL = line.Split(';');
                // check if there is exactly one ";" meaning only two elements
                if (titleURL.Length != 2)
                {
                    Debug.Log("In line:\n" + line + "\nthe format does not match title;URL");
                    continue;
                }
                // ignore link if it is not in the github repo
                if (!titleURL[1].Contains(Github_Repository))
                {
                    Debug.Log("Link does not have the github repository!");
                    continue;
                }

                //replace "tree" with "raw" in URL
                var regex = new Regex(Regex.Escape("tree"));
                titleURL[1] = regex.Replace(titleURL[1], "raw", 1);

                //replace "tree" with "raw" in URL
                var    regex1       = new Regex(Regex.Escape("tree"));
                string tempModelURL = regex.Replace(m_URLDictionary[urlEntry.Key], "raw", 1);

                //start modeldownloader.py for visual
                string[] updateArgumentsXML = { "start \"\" \"" + UpdaterUtility.PathToBlender + "\" -P", UpdaterUtility.PathToDownloadScript, tempModelURL + @"/", UpdaterUtility.ProjectFolder + @"/SimulationModels/" + urlEntry.Key + @"/OriginModels", "" };
                CommandlineUtility.RunCommandLine(updateArgumentsXML);

                //start modeldownloader.py for visual
                string[] updateArgumentsVis = { "start \"\" \"" + UpdaterUtility.PathToBlender + "\" -P", UpdaterUtility.PathToDownloadScript, titleURL[1] + @"/visual/", UpdaterUtility.ProjectFolder + @"/SimulationModels/" + urlEntry.Key + @"/OriginModels/visual", "" };
                CommandlineUtility.RunCommandLine(updateArgumentsVis);

                //start modeldownloader.py for collision
                string[] updateArgumentsCol = { "start \"\" \"" + UpdaterUtility.PathToBlender + "\" -P", UpdaterUtility.PathToDownloadScript, titleURL[1] + @"/collision/", UpdaterUtility.ProjectFolder + @"/SimulationModels/" + urlEntry.Key + @"/OriginModels/collision", "" };
                CommandlineUtility.RunCommandLine(updateArgumentsCol);

                if (!m_ModelNames.Contains(urlEntry.Key))
                {
                    m_ModelNames.Add(urlEntry.Key);
                }
            }
            if (File.Exists(pathToOriginModels + urlEntry.Key + @"/OriginModels/model.sdf"))
            {
                Debug.Log("model.sdf found!");
                // read .sdf file
                string[] argumentsSDFreader = { "python \"" + UpdaterUtility.PathToSDFreader + "\"", pathToOriginModels + urlEntry.Key + @"/OriginModels/model.sdf" };
                CommandlineUtility.RunCommandLine(argumentsSDFreader);
            }
            else
            {
                Debug.LogWarning("model.sdf not found!");
            }

            ModelsCurrentState = UpdaterUtility.State.Downloaded;
        }
    }
Пример #3
0
    /// <summary>
    /// Downloads models given in the .world files and saves their pose in a struct.
    /// </summary>
    public void Magic()
    {
        List <KeyValuePair <string, bool> > tempURLList = WorldChoiceDictionary.Where(entry => entry.Value == true).ToList();

        foreach (var urlEntry in tempURLList)
        {
            if (File.Exists(UpdaterUtility.ProjectFolder + @"/SimulationWorlds/" + urlEntry.Key + @"/" + urlEntry.Key + ".world"))
            {
                Debug.Log(".world file found!");
                // read .world file
                string[] argumentsSDFreader = { "python \"" + UpdaterUtility.PathToWorldReader + "\" \"" + UpdaterUtility.ProjectFolder + @"/SimulationWorlds/" + urlEntry.Key + @"/" + urlEntry.Key + ".world\"" };
                CommandlineUtility.RunCommandLine(argumentsSDFreader);
            }
            else
            {
                Debug.LogWarning(".world file not found!");
            }

            string pathToWorldFile = UpdaterUtility.ProjectFolder + @"/temp" + urlEntry.Key + @"World.txt";
            if (!File.Exists(pathToWorldFile))
            {
                Debug.LogWarning("Scan file not found! Check whether it exists or if python script is working!");
                return;
            }

            //save content of temp file
            string[] WorldContent = File.ReadAllLines(pathToWorldFile);

            //delete temp file
            File.Delete(pathToWorldFile);

            List <string[]> modelList = new List <string[]>();

            foreach (string line in WorldContent)
            {
                //each line contains of a model link with pose, scale, model_link
                string[] SDFline = line.Split(';');
                modelList.Add(SDFline);
            }
            string worldName = null;
            for (int i = 0; i < modelList.Count; i++)
            {
                if (modelList[i][0] == "world_name")
                {
                    //get world name
                    worldName = modelList[i][1];
                    modelList.Remove(modelList[i]);
                }
            }

            foreach (string[] line in modelList)
            {
                //each model will be saved in a struct, so we can apply pose and scale later on
                ModelTransformation testModel = new ModelTransformation();
                testModel.worldname = worldName;

                //check which attributes are set by the .world file and set them in the struct
                for (int j = 0; j < line.Length; j++)
                {
                    testModel.link = new LinkTransformation();

                    string[] pose = null;


                    if (line[j] == "model_pose")
                    {   //saving model_pose
                        pose = line[j + 1].Split(' ');
                        testModel.position = GazeboUtility.GazeboPositionToUnity(new Vector3(float.Parse(pose[0], CultureInfo.InvariantCulture.NumberFormat),
                                                                                             float.Parse(pose[1], CultureInfo.InvariantCulture.NumberFormat),
                                                                                             float.Parse(pose[2], CultureInfo.InvariantCulture.NumberFormat)));
                        testModel.rotation = GazeboUtility.GazeboPositionToUnity(new Vector3(Mathf.Rad2Deg * float.Parse(pose[3], CultureInfo.InvariantCulture.NumberFormat),
                                                                                             Mathf.Rad2Deg * float.Parse(pose[4], CultureInfo.InvariantCulture.NumberFormat),
                                                                                             Mathf.Rad2Deg * float.Parse(pose[5], CultureInfo.InvariantCulture.NumberFormat)));
                    }

                    if (line[j] == "model_link")
                    {   //saving model_link name
                        testModel.link.name = line[j + 1];
                    }
                    if (line[j] == "VIS_mesh_uri")
                    {   // saving VIS_mesh_link and model.name
                        testModel.link.VIS_meshName = line[j + 1];
                        string name1 = Regex.Replace(line[j + 1], ".*?//", "");
                        string name2 = Regex.Replace(name1, "/.*", "");
                        testModel.name = name2;
                        Debug.Log(testModel.link.VIS_meshName);
                    }

                    //saving COL_mesh_link
                    if (line[j] == "COL_mesh_uri")
                    {
                        testModel.link.COL_meshName = line[j + 1];
                    }

                    string[] VIS_Scale = null;
                    if (line[j] == "VIS_mesh_scale")
                    {
                        //saving model scale
                        VIS_Scale = line[j + 1].Split(' ');
                    }
                    if (VIS_Scale != null)
                    {   //converting model scale
                        testModel.link.VIS_scale = GazeboUtility.GazeboPositionToUnity(new Vector3(100 * float.Parse(VIS_Scale[0], CultureInfo.InvariantCulture.NumberFormat),
                                                                                                   100 * float.Parse(VIS_Scale[1], CultureInfo.InvariantCulture.NumberFormat),
                                                                                                   100 * float.Parse(VIS_Scale[2], CultureInfo.InvariantCulture.NumberFormat)));
                    }
                    string[] linkpose = null;
                    if (line[j] == "link_pose")
                    {
                        pose = line[j + 1].Split(' ');
                    }
                    if (linkpose != null)
                    {
                        testModel.position = GazeboUtility.GazeboPositionToUnity(new Vector3(float.Parse(linkpose[0], CultureInfo.InvariantCulture.NumberFormat),
                                                                                             float.Parse(linkpose[1], CultureInfo.InvariantCulture.NumberFormat),
                                                                                             float.Parse(linkpose[2], CultureInfo.InvariantCulture.NumberFormat)));
                        testModel.rotation = GazeboUtility.GazeboPositionToUnity(new Vector3(Mathf.Rad2Deg * float.Parse(linkpose[3], CultureInfo.InvariantCulture.NumberFormat),
                                                                                             Mathf.Rad2Deg * float.Parse(linkpose[4], CultureInfo.InvariantCulture.NumberFormat),
                                                                                             Mathf.Rad2Deg * float.Parse(linkpose[5], CultureInfo.InvariantCulture.NumberFormat)));
                    }
                }
                modellist.Add(testModel);


                //}
            }


            WorldsCurrentState = UpdaterUtility.State.Downloaded;
        }
        List <string> names = new List <string>();

        foreach (ModelTransformation model in modellist)
        {
            if (!names.Contains(model.name))
            {
                names.Add(model.name);
                //Debug.Log(model.name);
            }
        }
        foreach (string name in names)
        {
            //replace "tree" with "raw" in URL
            var regex = new Regex(Regex.Escape("tree"));
            m_PathToModelsFolder = regex.Replace(m_PathToModelsFolder, "raw", 1);
            //start modeldownloader.py for visual
            string[] updateArgumentsWorld = { "start \"\" \"" + UpdaterUtility.PathToBlender + "\" -P", UpdaterUtility.PathToDownloadScript, m_PathToModelsFolder + @"/" + name + @"/meshes/", UpdaterUtility.ProjectFolder + @"/SimulationWorlds/Models/" + name + "/meshes", "" };
            CommandlineUtility.RunCommandLine(updateArgumentsWorld);
        }
    }