public async void CreateActionObject() { string newActionObjectName = (string)nameInput.GetValue(); if (Base.Parameter.CheckIfAllValuesValid(actionParameters)) { List <IO.Swagger.Model.Parameter> parameters = new List <IO.Swagger.Model.Parameter>(); foreach (IParameter actionParameter in actionParameters) { if (!parametersMetadata.TryGetValue(actionParameter.GetName(), out Base.ParameterMetadata actionParameterMetadata)) { Base.Notifications.Instance.ShowNotification("Failed to create new action", "Failed to get metadata for action parameter: " + actionParameter.GetName()); return; } IO.Swagger.Model.ActionParameter ap = new IO.Swagger.Model.ActionParameter(name: actionParameter.GetName(), value: JsonConvert.SerializeObject(actionParameter.GetValue()), type: actionParameterMetadata.Type); parameters.Add(DataHelper.ActionParameterToParameter(ap)); } try { IO.Swagger.Model.Pose pose = null; if (actionObjectMetadata.HasPose) { Vector3 abovePoint = SceneManager.Instance.GetCollisionFreePointAbove(SceneManager.Instance.SceneOrigin.transform, actionObjectMetadata.GetModelBB(), SceneManager.Instance.SceneOrigin.transform.localRotation); IO.Swagger.Model.Position offset = DataHelper.Vector3ToPosition(TransformConvertor.UnityToROS(abovePoint)); pose = new IO.Swagger.Model.Pose(position: offset, orientation: new IO.Swagger.Model.Orientation(1, 0, 0, 0)); } await Base.WebsocketManager.Instance.AddObjectToScene(newActionObjectName, actionObjectMetadata.Type, pose, parameters); Close(); } catch (Base.RequestFailedException e) { Base.Notifications.Instance.ShowNotification("Failed to add action", e.Message); } } }
public async void AddAP(string name) { Debug.Assert(CurrentActionPoint != null); Vector3 abovePoint = SceneManager.Instance.GetCollisionFreePointAbove(CurrentActionPoint.transform, Vector3.one * 0.025f, Quaternion.identity); IO.Swagger.Model.Position offset = DataHelper.Vector3ToPosition(TransformConvertor.UnityToROS(abovePoint)); bool result = await GameManager.Instance.AddActionPoint(name, CurrentActionPoint.Data.Id, offset); if (result) { inputDialog.Close(); } UpdateMenu(); }
public async void CreateNewAP(string name) { Debug.Assert(CurrentObject != null); /*IO.Swagger.Model.Position offset = new IO.Swagger.Model.Position(); * Vector3 aboveModel = CurrentObject.GetTopPoint(); * aboveModel.y += 0.1f; * offset = DataHelper.Vector3ToPosition(TransformConvertor.UnityToROS(CurrentObject.transform.InverseTransformPoint(aboveModel))); */ Vector3 abovePoint = SceneManager.Instance.GetCollisionFreePointAbove(CurrentObject.transform.localPosition); IO.Swagger.Model.Position offset = DataHelper.Vector3ToPosition(TransformConvertor.UnityToROS(CurrentObject.transform.InverseTransformPoint(abovePoint))); bool result = await GameManager.Instance.AddActionPoint(name, CurrentObject.Data.Id, offset); //Base.Scene.Instance.SpawnActionPoint(CurrentObject.GetComponent<Base.ActionObject>(), null); if (result) { inputDialog.Close(); } UpdateMenu(); }
public async void CreateNewAP(string name) { Debug.Assert(CurrentObject != null); IO.Swagger.Model.Position offset = new IO.Swagger.Model.Position(); if (CurrentObject.ActionObjectMetadata.ObjectModel != null) { switch (CurrentObject.ActionObjectMetadata.ObjectModel.Type) { case IO.Swagger.Model.ObjectModel.TypeEnum.Box: offset.Z = CurrentObject.ActionObjectMetadata.ObjectModel.Box.SizeY / 2m + 0.1m; break; case IO.Swagger.Model.ObjectModel.TypeEnum.Cylinder: offset.Z = CurrentObject.ActionObjectMetadata.ObjectModel.Cylinder.Height / 2m + 0.1m; break; case IO.Swagger.Model.ObjectModel.TypeEnum.Mesh: //TODO: how to handle meshes? do i know dimensions? break; case IO.Swagger.Model.ObjectModel.TypeEnum.Sphere: offset.Z = CurrentObject.ActionObjectMetadata.ObjectModel.Sphere.Radius / 2m + 0.1m; break; default: offset.Z = 0.15m; break; } } bool result = await GameManager.Instance.AddActionPoint(name, CurrentObject.Data.Id, offset); //Base.Scene.Instance.SpawnActionPoint(CurrentObject.GetComponent<Base.ActionObject>(), null); if (result) { inputDialog.Close(); } UpdateMenu(); }
public static Vector3 PositionToVector3(IO.Swagger.Model.Position position) => new Vector3((float)position.X, (float)position.Y, (float)position.Z);