Esempio n. 1
0
 /// <summary>
 /// Loads mesh - takes care of downloading, updating and importing mesh
 /// </summary>
 /// <param name="mesh"></param>
 /// <param name="aoId">ID of action object which is asociated with the mesh</param>
 public void LoadModel(IO.Swagger.Model.Mesh mesh, string aoId)
 {
     if (CheckIfNewerRobotModelExists(mesh.Id, mesh.DataId))
     {
         StartCoroutine(DownloadMesh(mesh.Id, mesh.DataId, aoId));
     }
     else
     {
         StartCoroutine(ImportMeshWhenReady(string.Format("{0}/meshes/{1}/{2}", Application.persistentDataPath, mesh.Id, mesh.DataId), aoId, mesh.DataId));
     }
 }
Esempio n. 2
0
    public async void CreateNewObjectType()
    {
        Debug.Assert(ModelsList.Dropdown.dropdownItems.Count > 0, "No models");
        Debug.Assert(ParentsList.Dropdown.dropdownItems.Count > 0, "No parent objects");
        string objectId = NameInput.text;

        IO.Swagger.Model.ObjectModel objectModel = new IO.Swagger.Model.ObjectModel();
        string modelTypeString = (string)ModelsList.GetValue();

        IO.Swagger.Model.ObjectTypeMeta objectTypeMeta;
        if (ModelMenus.TryGetValue(modelTypeString, out GameObject type) && type != null)
        {
            IO.Swagger.Model.ObjectModel.TypeEnum modelType = new IO.Swagger.Model.ObjectModel.TypeEnum();
            switch (modelTypeString)
            {
            case "Box":
                modelType = IO.Swagger.Model.ObjectModel.TypeEnum.Box;
                decimal sizeX = decimal.Parse(BoxX.text, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture);
                decimal sizeY = decimal.Parse(BoxY.text, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture);
                decimal sizeZ = decimal.Parse(BoxZ.text, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture);
                // no need to transform from Unity to ROS, because we are setting those scales in ROS already
                //(sizeX, sizeY, sizeZ) = TransformConvertor.UnityToROSScale(sizeX, sizeY, sizeZ);
                IO.Swagger.Model.Box box = new IO.Swagger.Model.Box(objectId, sizeX, sizeY, sizeZ);
                objectModel.Box = box;
                break;

            case "Sphere":
                modelType = IO.Swagger.Model.ObjectModel.TypeEnum.Sphere;
                decimal radius = decimal.Parse(SphereRadius.text, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture);
                IO.Swagger.Model.Sphere sphere = new IO.Swagger.Model.Sphere(objectId, radius);
                objectModel.Sphere = sphere;
                break;

            case "Cylinder":
                modelType = IO.Swagger.Model.ObjectModel.TypeEnum.Cylinder;
                decimal cylinderRadius             = decimal.Parse(CylinderRadius.text, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture);
                decimal cylinderHeight             = decimal.Parse(CylinderHeight.text, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture);
                IO.Swagger.Model.Cylinder cylinder = new IO.Swagger.Model.Cylinder(objectId, cylinderHeight, cylinderRadius);
                objectModel.Cylinder = cylinder;
                break;

            case "Mesh":
                modelType = IO.Swagger.Model.ObjectModel.TypeEnum.Mesh;
                string meshId = MeshId.text;
                IO.Swagger.Model.Mesh mesh = new IO.Swagger.Model.Mesh(id: meshId, focusPoints: new List <IO.Swagger.Model.Pose>(), uri: "");
                objectModel.Mesh = mesh;
                break;

            default:
                Debug.LogError("Model not defined!");
                return;
            }
            objectModel.Type = modelType;
            objectTypeMeta   = new IO.Swagger.Model.ObjectTypeMeta(builtIn: false, description: "", type: objectId, objectModel: objectModel,
                                                                   _base: (string)ParentsList.GetValue(), needsServices: new List <string>());
        }
        else
        {
            objectTypeMeta = new IO.Swagger.Model.ObjectTypeMeta(builtIn: false, description: "", type: objectId,
                                                                 _base: (string)ParentsList.GetValue(), needsServices: new List <string>());
        }



        bool success = await Base.GameManager.Instance.CreateNewObjectType(objectTypeMeta);

        if (success)
        {
            MenuManager.Instance.NewObjectTypeMenu.Close();
        }
    }
Esempio n. 3
0
    public IO.Swagger.Model.ObjectTypeMeta CreateObjectTypeMeta()
    {
        string objectId = NameInput.text;

        IO.Swagger.Model.ObjectModel objectModel = new IO.Swagger.Model.ObjectModel();
        string modelTypeString = (string)ModelsList.GetValue();

        IO.Swagger.Model.ObjectTypeMeta objectTypeMeta;
        if (HasSelectedParentPose() && ModelMenus.TryGetValue(modelTypeString, out GameObject type) && type != null)
        {
            IO.Swagger.Model.ObjectModel.TypeEnum modelType = new IO.Swagger.Model.ObjectModel.TypeEnum();
            switch (modelTypeString)
            {
            case "Box":
                modelType = IO.Swagger.Model.ObjectModel.TypeEnum.Box;
                decimal sizeX = decimal.Parse(BoxX.text, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture);
                decimal sizeY = decimal.Parse(BoxY.text, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture);
                decimal sizeZ = decimal.Parse(BoxZ.text, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture);
                // no need to transform from Unity to ROS, because we are setting those scales in ROS already
                //(sizeX, sizeY, sizeZ) = TransformConvertor.UnityToROSScale(sizeX, sizeY, sizeZ);
                IO.Swagger.Model.Box box = new IO.Swagger.Model.Box(objectId, sizeX, sizeY, sizeZ);
                objectModel.Box = box;
                break;

            case "Sphere":
                modelType = IO.Swagger.Model.ObjectModel.TypeEnum.Sphere;
                decimal radius = decimal.Parse(SphereRadius.text, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture);
                IO.Swagger.Model.Sphere sphere = new IO.Swagger.Model.Sphere(objectId, radius);
                objectModel.Sphere = sphere;
                break;

            case "Cylinder":
                modelType = IO.Swagger.Model.ObjectModel.TypeEnum.Cylinder;
                decimal cylinderRadius             = decimal.Parse(CylinderRadius.text, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture);
                decimal cylinderHeight             = decimal.Parse(CylinderHeight.text, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture);
                IO.Swagger.Model.Cylinder cylinder = new IO.Swagger.Model.Cylinder(objectId, cylinderHeight, cylinderRadius);
                objectModel.Cylinder = cylinder;
                break;

            case "Mesh":
                modelType = IO.Swagger.Model.ObjectModel.TypeEnum.Mesh;
                string meshId = MeshId.text;
                IO.Swagger.Model.Mesh mesh = new IO.Swagger.Model.Mesh(id: meshId, focusPoints: new List <IO.Swagger.Model.Pose>(), uri: "");
                objectModel.Mesh = mesh;
                break;

            default:
                Debug.LogError("Model not defined!");
                return(null);
            }
            objectModel.Type = modelType;
            objectTypeMeta   = new IO.Swagger.Model.ObjectTypeMeta(builtIn: false, description: "", type: objectId, objectModel: objectModel,
                                                                   _base: (string)ParentsList.GetValue(), hasPose: true);
        }
        else
        {
            objectTypeMeta = new IO.Swagger.Model.ObjectTypeMeta(builtIn: false, description: "", type: objectId,
                                                                 _base: (string)ParentsList.GetValue(), hasPose: false);
        }

        return(objectTypeMeta);
    }