コード例 #1
0
    // 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
        StrokeSketchObject = Instantiate(Defaults.StrokeSketchObjectPrefab).GetComponent <StrokeSketchObject>();
        Invoker            = new CommandInvoker();
        Invoker.ExecuteCommand(new AddControlPointCommand(this.StrokeSketchObject, new Vector3(1, 2, 3)));
        Invoker.ExecuteCommand(new AddControlPointCommand(this.StrokeSketchObject, new Vector3(1, 4, 2)));
        Invoker.ExecuteCommand(new AddControlPointCommand(this.StrokeSketchObject, new Vector3(1, 5, 3)));
        Invoker.ExecuteCommand(new AddControlPointCommand(this.StrokeSketchObject, 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(StrokeSketchObject, 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));
    }
コード例 #2
0
        public IEnumerator SetUpScene()
        {
            yield return(SceneManager.LoadSceneAsync("CommandTestScene", LoadSceneMode.Single));

            this.Ribbon    = GameObject.FindObjectOfType <RibbonSketchObject>();
            this.Selection = GameObject.FindObjectOfType <SketchObjectSelection>();
            yield return(null);

            Invoker = new CommandInvoker();
        }
コード例 #3
0
    IEnumerator deactivateSelection(SketchObjectSelection selection)
    {
        yield return(new WaitForSeconds(3));

        selection.Deactivate();
    }
コード例 #4
0
 public ActivateSelectionCommand(SketchObjectSelection selection)
 {
     this.Selection = selection;
 }
 public RemoveFromSelectionAndRevertHighlightCommand(SketchObjectSelection selection, SelectableObject selectableObject)
 {
     this.SelectableObject = selectableObject;
     this.Selection        = selection;
 }
コード例 #6
0
 public DeleteObjectsOfSelectionCommand(SketchObjectSelection selection)
 {
     this.Selection       = selection;
     this.selectedObjects = selection.GetObjectsOfSelection();
 }
コード例 #7
0
    // 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));
    }
コード例 #8
0
 public AddToSelectionAndHighlightCommand(SketchObjectSelection selection, SelectableObject selectableObject)
 {
     this.SelectableObject = selectableObject;
     this.Selection        = selection;
 }