public IEnumerator SetUpScene() { yield return(SceneManager.LoadSceneAsync("CommandTestScene", LoadSceneMode.Single)); this.RibbonSketchObject = GameObject.FindObjectOfType <RibbonSketchObject>(); yield return(null); }
// Start is called before the first frame update void Start() { //Create a SketchWorld, many commands require a SketchWorld to be present SketchWorld = Instantiate(Defaults.SketchWorldPrefab).GetComponent <SketchWorld>(); //Create a LineSketchObject LineSketchObject = Instantiate(Defaults.LineSketchObjectPrefab).GetComponent <LineSketchObject>(); Invoker = new CommandInvoker(); Invoker.ExecuteCommand(new AddControlPointCommand(this.LineSketchObject, new Vector3(1, 2, 3))); Invoker.ExecuteCommand(new AddControlPointCommand(this.LineSketchObject, new Vector3(1, 4, 2))); Invoker.ExecuteCommand(new AddControlPointCommand(this.LineSketchObject, new Vector3(1, 5, 3))); Invoker.ExecuteCommand(new AddControlPointCommand(this.LineSketchObject, new Vector3(1, 5, 2))); Invoker.Undo(); Invoker.Redo(); //Create a RibbonSketchObject RibbonSketchObject = Instantiate(Defaults.RibbonSketchObjectPrefab).GetComponent <RibbonSketchObject>(); Invoker.ExecuteCommand(new AddPointAndRotationCommand(RibbonSketchObject, new Vector3(1, 1, 1), Quaternion.identity)); Invoker.ExecuteCommand(new AddPointAndRotationCommand(RibbonSketchObject, new Vector3(1, 2, 2), Quaternion.Euler(25, 45, 0))); Invoker.ExecuteCommand(new AddPointAndRotationCommand(RibbonSketchObject, new Vector3(1, 2, 3), Quaternion.Euler(-25, 45, 0))); //Create a PatchSketchObject PatchSketchObject = Instantiate(Defaults.PatchSketchObjectPrefab).GetComponent <PatchSketchObject>(); PatchSketchObject.Width = 3; Invoker.ExecuteCommand(new AddSegmentCommand(PatchSketchObject, new List <Vector3> { new Vector3(0, 0, 1), new Vector3(0, 1, 2), new Vector3(0, 0, 3) })); Invoker.ExecuteCommand(new AddSegmentCommand(PatchSketchObject, new List <Vector3> { new Vector3(1, 1, 1), new Vector3(1, 0, 2), new Vector3(1, 1, 3) })); Invoker.ExecuteCommand(new AddSegmentCommand(PatchSketchObject, new List <Vector3> { new Vector3(2, 0, 1), new Vector3(2, 1, 2), new Vector3(2, 0, 3) })); //Add the LineSketchObject to the SketchWorld Invoker.ExecuteCommand(new AddObjectToSketchWorldRootCommand(LineSketchObject, SketchWorld)); //Create a SketchObjectGroup and add objects to it SketchObjectGroup = Instantiate(Defaults.SketchObjectGroupPrefab).GetComponent <SketchObjectGroup>(); Invoker.ExecuteCommand(new AddToGroupCommand(SketchObjectGroup, RibbonSketchObject)); Invoker.ExecuteCommand(new AddToGroupCommand(SketchObjectGroup, PatchSketchObject)); //Add the SketchObjectGroup to the SketchWorld Invoker.ExecuteCommand(new AddObjectToSketchWorldRootCommand(SketchObjectGroup, SketchWorld)); //Serialize the SketchWorld to a XML file SavePath = System.IO.Path.Combine(Application.dataPath, "YourSketch.xml"); SketchWorld.SaveSketchWorld(SavePath); //Create another SketchWorld and load the serialized SketchWorld DeserializedSketchWorld = Instantiate(Defaults.SketchWorldPrefab).GetComponent <SketchWorld>(); DeserializedSketchWorld.LoadSketchWorld(SavePath); DeserializedSketchWorld.transform.position += new Vector3(5, 0, 0); //Export the SketchWorld as an OBJ file SketchWorld.ExportSketchWorldToDefaultPath(); //Select the SketchObjectGroup SketchObjectSelection = Instantiate(Defaults.SketchObjectSelectionPrefab).GetComponent <SketchObjectSelection>(); Invoker.ExecuteCommand(new AddToSelectionAndHighlightCommand(SketchObjectSelection, SketchObjectGroup)); Invoker.ExecuteCommand(new ActivateSelectionCommand(SketchObjectSelection)); }
/// <summary> /// Create a command that represents deleting the last control point at the end of a ribbon sketch object. /// </summary> /// <param name="ribbonSketchObject">The ribbon to add the control point to.</param> public DeletePointAndRotationCommand(RibbonSketchObject ribbonSketchObject) { this.RibbonSketchObject = ribbonSketchObject; List <Vector3> Points = ribbonSketchObject.GetPoints(); List <Quaternion> Rotations = ribbonSketchObject.GetRotations(); Point = Points[Points.Count - 1]; Rotation = Rotations[Rotations.Count - 1]; }
// Start is called before the first frame update void Start() { RibbonSketchObject = Instantiate(RibbonPrefab).GetComponent <RibbonSketchObject>(); //RibbonSketchObjectTest(); //ribbonMesh = new RibbonMesh(Vector3.one * .5f); //StartCoroutine(addPointCoroutine()); //setPointsToRibbon(); //addPointsToRibbon(); }
// Start is called before the first frame update void Start() { strokeSketchObject = Instantiate(StrokeSketchObjectPrefab).GetComponent <StrokeSketchObject>(); strokeSketchObject.SetStrokeDiameter(.5f); //lineSketchObject2 = Instantiate(LineSketchObjectPrefab).GetComponent<LineSketchObject>(); strokeSketchObject2 = Instantiate(defaults.LinearInterpolationStrokeSketchObjectPrefab).GetComponent <StrokeSketchObject>(); patchSketchObject = Instantiate(defaults.PatchSketchObjectPrefab).GetComponent <PatchSketchObject>(); ribbonSketchObject = Instantiate(defaults.RibbonSketchObjectPrefab).GetComponent <RibbonSketchObject>(); }
public IEnumerator SetUpScene() { yield return(SceneManager.LoadSceneAsync("CommandTestScene", LoadSceneMode.Single)); this.Ribbon = GameObject.FindObjectOfType <RibbonSketchObject>(); this.Stroke = GameObject.FindObjectOfType <StrokeSketchObject>(); this.Patch = GameObject.FindObjectOfType <PatchSketchObject>(); yield return(null); Invoker = new CommandInvoker(); }
/// <summary> /// Create a command that represents adding a new control point to the end of a ribbon sketch object. /// </summary> /// <param name="ribbonSketchObject">The ribbon to add the control point to.</param> /// <param name="point">The point to add.</param> /// <param name="rotation">The rotation of the cross section at this point.</param> public AddPointAndRotationContinuousCommand(RibbonSketchObject ribbonSketchObject, Vector3 point, Quaternion rotation) { this.RibbonSketchObject = ribbonSketchObject; Point = point; Rotation = rotation; }
// Start is called before the first frame update void Start() { //Create a SketchWorld, many commands require a SketchWorld to be present SketchWorld = Instantiate(Defaults.SketchWorldPrefab).GetComponent <SketchWorld>(); //Create a LineSketchObject LineSketchObject = Instantiate(Defaults.LineSketchObjectPrefab).GetComponent <LineSketchObject>(); Invoker = new CommandInvoker(); Invoker.ExecuteCommand(new AddControlPointCommand(this.LineSketchObject, new Vector3(1, 2, 3))); Invoker.ExecuteCommand(new AddControlPointCommand(this.LineSketchObject, new Vector3(1, 4, 2))); Invoker.ExecuteCommand(new AddControlPointCommand(this.LineSketchObject, new Vector3(1, 5, 3))); Invoker.ExecuteCommand(new AddControlPointCommand(this.LineSketchObject, new Vector3(1, 5, 2))); Invoker.Undo(); Invoker.Redo(); LineBrush brush = this.LineSketchObject.GetBrush() as LineBrush; brush.CrossSectionVertices = CircularCrossSection.GenerateVertices(3); brush.CrossSectionNormals = CircularCrossSection.GenerateVertices(3, 1); Invoker.ExecuteCommand(new SetBrushCommand(this.LineSketchObject, brush)); //oder ohne Command //this.LineSketchObject.SetBrush(brush); //oder nur //this.LineSketchObject.SetLineCrossSection(... //Create a RibbonSketchObject RibbonSketchObject = Instantiate(Defaults.RibbonSketchObjectPrefab).GetComponent <RibbonSketchObject>(); Invoker.ExecuteCommand(new AddPointAndRotationCommand(RibbonSketchObject, new Vector3(1, 1, 1), Quaternion.identity)); Invoker.ExecuteCommand(new AddPointAndRotationCommand(RibbonSketchObject, new Vector3(1.5f, 1.1f, 1), Quaternion.Euler(0, 0, 0))); Invoker.ExecuteCommand(new AddPointAndRotationCommand(RibbonSketchObject, new Vector3(2f, 1.2f, 1), Quaternion.Euler(22, 0, 0))); Invoker.ExecuteCommand(new AddPointAndRotationCommand(RibbonSketchObject, new Vector3(2.5f, 1.3f, 1), Quaternion.Euler(45, 0, 0))); Invoker.ExecuteCommand(new AddPointAndRotationCommand(RibbonSketchObject, new Vector3(3f, 1.4f, 1), Quaternion.Euler(60, 0, 0))); //Create a PatchSketchObject PatchSketchObject = Instantiate(Defaults.PatchSketchObjectPrefab).GetComponent <PatchSketchObject>(); PatchSketchObject.Width = 3; Invoker.ExecuteCommand(new AddSegmentCommand(PatchSketchObject, new List <Vector3> { new Vector3(0, 0, 1), new Vector3(0, 1, 2), new Vector3(0, 0, 3) })); Invoker.ExecuteCommand(new AddSegmentCommand(PatchSketchObject, new List <Vector3> { new Vector3(1, 1, 1), new Vector3(1, 0, 2), new Vector3(1, 1, 3) })); Invoker.ExecuteCommand(new AddSegmentCommand(PatchSketchObject, new List <Vector3> { new Vector3(2, 0, 1), new Vector3(2, 1, 2), new Vector3(2, 0, 3) })); //Add the LineSketchObject to the SketchWorld Invoker.ExecuteCommand(new AddObjectToSketchWorldRootCommand(LineSketchObject, SketchWorld)); //Create a SketchObjectGroup and add objects to it SketchObjectGroup = Instantiate(Defaults.SketchObjectGroupPrefab).GetComponent <SketchObjectGroup>(); Invoker.ExecuteCommand(new AddToGroupCommand(SketchObjectGroup, RibbonSketchObject)); Invoker.ExecuteCommand(new AddToGroupCommand(SketchObjectGroup, PatchSketchObject)); //Add the SketchObjectGroup to the SketchWorld Invoker.ExecuteCommand(new AddObjectToSketchWorldRootCommand(SketchObjectGroup, SketchWorld)); //Serialize the SketchWorld to a XML file SavePath = System.IO.Path.Combine(Application.dataPath, "YourSketch.xml"); SketchWorld.SaveSketchWorld(SavePath); //Create another SketchWorld and load the serialized SketchWorld DeserializedSketchWorld = Instantiate(Defaults.SketchWorldPrefab).GetComponent <SketchWorld>(); DeserializedSketchWorld.LoadSketchWorld(SavePath); DeserializedSketchWorld.transform.position += new Vector3(5, 0, 0); //Export the SketchWorld as an OBJ file //SketchWorld.ExportSketchWorldToDefaultPath(); //Select the SketchObjectGroup SketchObjectSelection = Instantiate(Defaults.SketchObjectSelectionPrefab).GetComponent <SketchObjectSelection>(); Invoker.ExecuteCommand(new AddToSelectionAndHighlightCommand(SketchObjectSelection, SketchObjectGroup)); Invoker.ExecuteCommand(new ActivateSelectionCommand(SketchObjectSelection)); }
/// <summary> /// This will only return a command object if the distance between the previous and new control point is larger than minimumDistance. /// </summary> /// <param name="ribbonSketchObject"></param> /// <param name="point"></param> /// <param name="rotation"></param> /// <param name="minimumDistanceToLastControlPoint"></param> /// <returns>A command or null if the distance is smaller than minimumDistance.</returns> public static AddPointAndRotationCommand GetAddPointAndRotationCommandContinuous(RibbonSketchObject ribbonSketchObject, Vector3 point, Quaternion rotation, float minimumDistanceToLastControlPoint) { if ((ribbonSketchObject.GetPoints()[ribbonSketchObject.GetPoints().Count - 1] - point).magnitude >= minimumDistanceToLastControlPoint) { return(new AddPointAndRotationCommand(ribbonSketchObject, point, rotation)); } else { return(null); } }