Beispiel #1
0
        private void createCube(int x, int y, int z)
        {
            var json = new NodeJson(NodeDataManager.NextName(NodeType.CUBE), new Vector3(x, y, z), Vector3.one * 5, "", NodeType.CUBE);

            NodeDataManager.AddNode(json);
            NodeFactory.CreateNode(json);
        }
Beispiel #2
0
        protected override void OnClosed(EventArgs e)
        {
            NodeJson nodeJson = tree.ToNodeJson();
            string   json     = JsonConvert.SerializeObject(nodeJson);

            File.WriteAllText(Path, json);
            base.OnClosed(e);
        }
Beispiel #3
0
        public void Cuts2HoleInNonUniformRoom()
        {
            Init();
            var cube1 = new NodeJson(NodeDataManager.NextName(NodeType.CUBE), new Vector3(0, 0, 0), new Vector3(4, 3, 5), "", NodeType.CUBE);

            NodeDataManager.AddNode(cube1);
            NodeFactory.CreateNode(cube1);
            var cube2 = new NodeJson(NodeDataManager.NextName(NodeType.CUBE), new Vector3(6, 0, 0), new Vector3(6, 5, 4), "", NodeType.CUBE);

            NodeDataManager.AddNode(cube2);
            NodeFactory.CreateNode(cube2);

            runCutHoleTest(
                new Vector3(2.5f, -0.5f, 1f),
                new Vector3(2, 0.5f, 0.8f),
                (hole) => {
                if (hole.behaviour.name.Contains("right"))
                {
                    Assert.AreApproximatelyEqual(-1f, hole.position.x, "hole has wrong X pos");
                    Assert.AreApproximatelyEqual(-0.5f, hole.position.y, "hole has wrong Y pos");
                    Assert.AreApproximatelyEqual(0.8f, hole.scale.x, "hole has wrong X sca");
                    Assert.AreApproximatelyEqual(0.5f, hole.scale.y, "hole has wrong Y sca");
                }
                if (hole.behaviour.name.Contains("left"))
                {
                    Assert.AreApproximatelyEqual(1f, hole.position.x, "hole has wrong X pos");
                    Assert.AreApproximatelyEqual(-0.5f, hole.position.y, "hole has wrong Y pos");
                    Assert.AreApproximatelyEqual(0.8f, hole.scale.x, "hole has wrong X sca");
                    Assert.AreApproximatelyEqual(0.5f, hole.scale.y, "hole has wrong Y sca");
                }
            });
            this.nodesCreated.Clear();
            runCutHoleTest(
                new Vector3(2.5f, 0.75f, -0.5f),
                new Vector3(2, 0.5f, 0.8f),
                (hole) => {
                if (hole.behaviour.name.Contains("right"))
                {
                    Assert.AreApproximatelyEqual(0.1f, hole.position.x, "hole has wrong X pos");
                    Assert.AreApproximatelyEqual(0.125f / 3f, hole.position.y, "hole has wrong Y pos");
                    Assert.AreApproximatelyEqual(0.16f, hole.scale.x, "hole has wrong X sca");
                    Assert.AreApproximatelyEqual(0.5f / 3f, hole.scale.y, "hole has wrong Y sca");
                }
                if (hole.behaviour.name.Contains("left"))
                {
                    Assert.AreApproximatelyEqual(-0.125f, hole.position.x, "hole has wrong X pos");
                    Assert.AreApproximatelyEqual(-0.075f, hole.position.y, "hole has wrong Y pos");
                    Assert.AreApproximatelyEqual(0.2f, hole.scale.x, "hole has wrong X sca");
                    Assert.AreApproximatelyEqual(0.1f, hole.scale.y, "hole has wrong Y sca");
                }
            });
            CleanUp();
        }
Beispiel #4
0
        public MainWindow()
        {
            InitializeComponent();
            nodeContext        = (ContextMenu)FindResource("NodeContext");
            ScaleTrans.CenterX = ActualWidth / 2;
            ScaleTrans.CenterY = ActualHeight / 2;

            if (File.Exists(Path))
            {
                string   json     = File.ReadAllText(Path);
                NodeJson nodeJson = JsonConvert.DeserializeObject <NodeJson>(json);
                tree = nodeJson.ToNode(nodeContext);
                MainCanvas.Children.Add(tree.Canvas);
            }
        }
Beispiel #5
0
        public void CutHoleWhenParentHaveScale()
        {
            Init();
            // create cube inside of empty with scale, but cube is still 5*5*5 to world
            var empty1Json = new NodeJson("empty1Json", new Vector3(0, 0, 0), new Vector3(5, 2, 1), "", NodeType.EMPTY);

            NodeDataManager.AddNode(empty1Json);
            var empty2Json = new NodeJson("empty2Json", new Vector3(0, 0, 0), new Vector3(1, 2, 2), "", NodeType.EMPTY)
            {
                parentName = "empty1Json"
            };

            NodeDataManager.AddNode(empty2Json);
            var cubeJson = new NodeJson("cubeJson", new Vector3(0, 0, 0), new Vector3(1, 1.2f, 2.4f), "", NodeType.CUBE)
            {
                parentName = "empty2Json"
            };

            NodeDataManager.AddNode(cubeJson);
            NodeFactory.CreateNodes(NodeDataManager.NodeJsons);

            var cutterPos = new Vector3(3, 0.5f, -1);
            var cutterSca = new Vector3(2, 2, 2);

            this.cutter.transform.position   = cutterPos;
            this.cutter.transform.localScale = cutterSca;
            Debug.Log(string.Format("testing cutter with pos:{0} sca:{1}", cutterPos, cutterSca));

            NodeDataManager.onAddNode += this.onAddNode;
            NodeHoleCutter.CutHoles(this.cutter);

            var holeCount = 1;

            Assert.AreEqual(holeCount, this.nodesCreated.Count, string.Format("There are not {0} holes", holeCount));
            foreach (var hole in this.nodesCreated)
            {
                Assert.AreEqual(NodeType.HOLE, hole.nodeType);

                Assert.AreApproximatelyEqual(0.2f, hole.position.x, "hole has wrong X pos");
                Assert.AreApproximatelyEqual(0.125f, hole.position.y, "hole has wrong Y pos");
                Assert.AreApproximatelyEqual(0.4f, hole.scale.x, "hole has wrong X sca");
                Assert.AreApproximatelyEqual(0.5f, hole.scale.y, "hole has wrong Y sca");
            }

            NodeDataManager.onAddNode -= this.onAddNode;
            CleanUp();
        }
Beispiel #6
0
        private void ButtonOnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (_nodeControl != null)
            {
                var item = sender as SuperContextMenuItem;
                if (item != null)
                {
                    var node    = new NodeJson(_nodeControl.ViewModelNode);
                    var map     = new NodeJson(_nodeControl.ParentSurface.Context);
                    var rootMap = new NodeJson(RootMapProperties.Instance.Metadata, RootMapProperties.Instance.Id, RootMapProperties.Instance.DomainId);

                    var nodeJson    = node.ToJson();
                    var mapJson     = map.ToJson();
                    var rootMapJson = rootMap.ToJson();

                    JavascriptCallbackRegister.Instance.CallBack(Type, item.Name, rootMapJson, mapJson, nodeJson);
                }
            }
            OnMenuClosed(this, null);
        }
Beispiel #7
0
 private void onAddNode(NodeJson node)
 {
     this.nodesCreated.Add(node);
 }
        private void ButtonOnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (_nodeControl != null )
            {
                var item = sender as SuperContextMenuItem;
                if (item != null)
                {
                    var node = new NodeJson(_nodeControl.ViewModelNode);
                    var map = new NodeJson(_nodeControl.ParentSurface.Context);
                    var rootMap = new NodeJson(RootMapProperties.Instance.Metadata, RootMapProperties.Instance.Id, RootMapProperties.Instance.DomainId);

                    var nodeJson = node.ToJson();
                    var mapJson = map.ToJson();
                    var rootMapJson = rootMap.ToJson();

                    JavascriptCallbackRegister.Instance.CallBack(Type, item.Name, rootMapJson, mapJson, nodeJson);
                }

                
            }
            OnMenuClosed(this, null);
        }