コード例 #1
0
    public void ReOrder(NodePoint N, int Dir)
    {
        if (N.LockedNode)
        {
            return;
        }

        for (int i = 0; i < Nodes.Count; i++)
        {
            if (Nodes[i] == N)
            {
                if ((i + Dir) >= 0 && (i + Dir) < Nodes.Count)
                {
                    Debug.Log(Dir + " " + i);
                    NodePoint temp = Nodes[i];
                    Nodes.RemoveAt(i);
                    Nodes.Insert((i + Dir), temp);

                    TG.DeleteAllSegments();
                    TG.GenerateAllSegments();

                    return;
                }
            }
        }
    }
コード例 #2
0
        private static double getDistance(NodePoint A, NodePoint B)
        {
            double dx = B.X - A.X;
            double dy = B.Y - A.Y;
            double dz = B.Z - A.Z;

            return(Math.Abs((Math.Sqrt((dx * dx) + (dy * dy) + (dz * dz)))));
        }
コード例 #3
0
    public void AddObjects()
    {
        NodeManager NM = FindObjectOfType <NodeManager>();

        NodePoint p = NM.Nodes[0];

        Instantiate(EndCover, p.Posistion, Quaternion.Euler(p.Rotation), transform);

        p = NM.Nodes[1];
        Instantiate(StartingLights, p.Posistion, Quaternion.Euler(p.Rotation), transform);

        //cones random
        //for(int i = 0; i < NM.Nodes.Count * 3; i++)
        //{
        //    int x = Random.Range(0, map.GetLength(0));
        //    int y = Random.Range(0, map.GetLength(1));

        //    if (map[x, y])
        //    {
        //        if(Random.value < .8f)
        //            Instantiate(Cones, new Vector3(x * 2 + Random.value * 2f, 1.2f, y * 2 + Random.value * 2f) - (new Vector3(map.GetLength(0) * 2, 0, map.GetLength(1) * 2) * .5f), Quaternion.identity, transform);
        //    }
        //    else
        //    {
        //        i--;
        //    }
        //}

        for (int i = 0; i < 3000; i++)
        {
            int x = Random.Range(0, map.GetLength(0));
            int y = Random.Range(0, map.GetLength(1));

            if (!map[x, y])
            {
                if (Mathf.PerlinNoise(x * 0.0054f, y * 0.00554478f) < .8f)
                {
                    Vector3    pos = new Vector3(x * 2 + Random.value, 15, y * 2 + Random.value) - (new Vector3(map.GetLength(0) * 2, 0, map.GetLength(1) * 2) * .5f);
                    Ray        ray = new Ray(pos, Vector3.down);
                    RaycastHit hit;

                    Physics.Raycast(ray, out hit, 14, enviomentLayer);

                    if (hit.collider != null)
                    {
                        Instantiate(Tree, hit.point, Quaternion.Euler(hit.normal), transform);
                    }
                }
            }
            else
            {
                i--;
            }
        }
    }
コード例 #4
0
ファイル: Program.cs プロジェクト: MacSergey/RoundRoadTools
        static void TestMethod(float sx, float sz, float sdx, float sdz, int sm, float ex, float ez, float edx, float edz, int em, int r, bool cw, float?rx = null, float?rz = null)
        {
            var startNode = new NodePoint(sx, sz, sdx, sdz, height: 260);
            var endNode   = new NodePoint(ex, ez, edx, edz, height: 272);

            var calculation = new RoundRoadCalculation();

            calculation.Radius.Value        = r;
            calculation.SegmentLenght.Value = 5;

            var calcRoadResult = calculation.CalculateRoad(startNode, endNode, (s) => Console.WriteLine(s));
        }
コード例 #5
0
        private void DrawPoints(IWorkbook Doc)
        {
            AllPoints.Clear();
            int    errcount = 0;
            ISheet Sheet    = Doc.GetSheetAt(0);

            for (int i = 1; i < Sheet.PhysicalNumberOfRows; i++)
            {
                if (Sheet.GetRow(i) != null)
                {
                    try
                    {
                        IRow      Row       = Sheet.GetRow(i);
                        string    name      = Row.GetCell(0).ToString();
                        string    badsymbol = @"'";
                        double    X         = Convert.ToDouble(Row.GetCell(1).ToString().Replace('.', ',').Replace(badsymbol, "").Replace(" ", ""));
                        double    Y         = Convert.ToDouble(Row.GetCell(2).ToString().Replace('.', ',').Replace(badsymbol, "").Replace(" ", ""));
                        double    Z         = Convert.ToDouble(Row.GetCell(3).ToString().Replace('.', ',').Replace(badsymbol, "").Replace(" ", ""));
                        NodePoint iNode     = new NodePoint(name, X, Y, Z, null);
                        AllPoints.Add(iNode);
                    }
                    catch
                    {
                        errcount++;
                    }
                }
            }
            ////
            CATIA = (INFITF.Application)Marshal.GetActiveObject("Catia.Application");
            var partDoc = CATIA.ActiveDocument as PartDocument;

            if (partDoc != null)
            {
                var Part    = partDoc.Part;
                var HBodies = Part.HybridBodies;
                var HBody   = HBodies.Add();
                HBody.set_Name("Import Points_" + AllPoints.Count.ToString());
                Part.Update();
                var ShapeFactory = Part.HybridShapeFactory as HybridShapeFactory;
                foreach (NodePoint iNode in AllPoints)
                {
                    var Point = ShapeFactory.AddNewPointCoord(iNode.X, iNode.Y, iNode.Z);
                    Point.set_Name(iNode.Name);
                    iNode.link = Point as HybridShapeTypeLib.Point;
                    HBody.AppendHybridShape(Point);
                }
                Part.Update();
            }
            else
            {
                throw new InvalidOperationException("Документ не найден.Проставление точек невозможно при работе с CATProduct.Откройте нужную деталь(CATPart) отдельно.");
            }
        }
コード例 #6
0
    private void DrawPoints(IWorkbook Doc)
    {
        AllPoints.Clear();
        int    errcount = 0;
        ISheet Sheet    = Doc.GetSheetAt(0);

        for (int i = 1; i < Sheet.PhysicalNumberOfRows; i++)
        {
            if (Sheet.GetRow(i) != null)
            {
                try
                {
                    IRow      Row       = Sheet.GetRow(i);
                    string    name      = Row.GetCell(0).ToString();
                    string    badsymbol = @"'";
                    double    X         = Convert.ToDouble(Row.GetCell(1).ToString().Replace('.', ',').ToString().Replace('.', ',').Replace(badsymbol, "").Replace(" ", ""));
                    double    Y         = Convert.ToDouble(Row.GetCell(2).ToString().Replace('.', ',').ToString().Replace('.', ',').Replace(badsymbol, "").Replace(" ", ""));
                    double    Z         = Convert.ToDouble(Row.GetCell(3).ToString().Replace('.', ',').ToString().Replace('.', ',').Replace(badsymbol, "").Replace(" ", ""));
                    NodePoint iNode     = new NodePoint(name, X, Y, Z);
                    AllPoints.Add(iNode);
                }
                catch
                {
                    errcount++;
                }
            }
        }

        int             counter = 0;
        var             part    = theSession.Parts.Work;
        var             Tags    = new List <Tag>();
        var             tag     = new Tag();
        List <NXObject> Tlist   = new List <NXObject>();

        foreach (NodePoint node in AllPoints)
        {
            var newpoint = new Point3d(node.X, node.Y, node.Z);
            var p        = part.Points.CreatePoint(newpoint);
            Tlist.Add(p as NXObject);
            p.SetName(node.Name);
            PointFeatureBuilder p_feature;
            p_feature       = part.BaseFeatures.CreatePointFeatureBuilder(null);
            p_feature.Point = p;
            p_feature.Commit();
            p_feature.GetFeature().SetName(node.Name);
            Tags.Add(p_feature.GetFeature().Tag);
            p.SetVisibility(SmartObject.VisibilityOption.Visible);
        }
        theUFSession.Modl.CreateSetOfFeature("Points", Tags.ToArray(), Tags.Count, 1, out tag);
        theUI.NXMessageBox.Show("Завершено", NXMessageBox.DialogType.Information, "Ошибки: " + errcount.ToString());
    }
コード例 #7
0
            public NodePoint getClosestNode()
            {
                NodePoint result = null;
                double    min    = DistanceTo.Values.Min();

                foreach (NodePoint n in DistanceTo.Keys)
                {
                    if (DistanceTo[n] <= min)
                    {
                        result = n;
                    }
                }
                return(result);
            }
コード例 #8
0
    //returns the point location and orientation of the point
    OrientedBezier GetOrientedBezierData(NodePoint a, NodePoint b, float t)
    {
        OrientedBezier OB = new OrientedBezier();

        Vector3 p1 = Vector3.Lerp(a.Posistion, a.Forward, t);
        Vector3 p2 = Vector3.Lerp(a.Forward, b.Back, t);
        Vector3 p3 = Vector3.Lerp(b.Back, b.Posistion, t);

        Vector3 p4 = Vector3.Lerp(p1, p2, t);
        Vector3 p5 = Vector3.Lerp(p2, p3, t);

        OB.position = Vector3.Lerp(p4, p5, t);
        OB.rotation = Quaternion.LookRotation((p5 - p4).normalized, Vector3.up);

        return(OB);
    }
コード例 #9
0
    // Start is called before the first frame update
    void Start()
    {
        nointelPointNb = allPointObj.GetComponentsInChildren <NodePoint>();

        foreach (var n in nointelPointNb)
        {
            n.position = n.transform.localPosition;
            allPosition.Add(n.position);
            //print(n.position);
        }

        ip                    = intelPoint.transform.localPosition;
        tp                    = _target.GetComponent <Rigidbody>().position;
        dir                   = tp - ip;
        intelPointNb          = intelPoint.GetComponent <NodePoint>();
        originaldeltaPosition = deltaPosition;
    }
コード例 #10
0
    public override void InitializeAgent()
    {
        nointelPointNb = allPointObj.GetComponentsInChildren <NodePoint>();

        foreach (var n in nointelPointNb)
        {
            n.position = n.transform.localPosition;
            allPosition.Add(n.position);
            //print(n.position);
        }

        ip                    = intelPoint.position;
        tp                    = _target.GetComponent <Rigidbody>().position;
        dir                   = tp - ip;
        intelPointNb          = intelPoint.GetComponent <NodePoint>();
        originaldeltaPosition = deltaPosition;
        SetReward(0.005f);
    }
コード例 #11
0
        protected override void DoWorkTick(bool isFirstTick, bool isTestMode)
        {
            if (isFirstTick || _stopwatch.Elapsed.TotalSeconds > 1)
            {
                _stopwatch.Restart();

                if (isFirstTick)
                {
                    NodeItems testNodeItems = new NodeItems();
                    testNodeItems.SetItem("item1", "value1");
                    testNodeItems.SetItem("아이템2", "값2");
                    DataRepository.SetNode("/camera/basic", new Node("c0001", "카메라1", NodeStatus.Normal, "Camera", items: testNodeItems));
                    DataRepository.SetNode("/camera/basic", new Node("c0002", "카메라2", NodeStatus.Normal, "Camera"));
                    DataRepository.SetNode("/camera/basic", new Node("c0003", "카메라3", NodeStatus.Normal, "Camera", items: testNodeItems));
                    DataRepository.SetNode("/camera/composite", new Node("c0002-1", "카메라2-1", NodeStatus.Normal, "Camera", items: testNodeItems));
                    DataRepository.SetNode("/camera/composite/leaf", new Node("c0002-1-1", "카메라12-1-1", NodeStatus.Normal, "Camera", items: testNodeItems));

                    DataRepository.SetNode("/sensor/composite", new Node("s0002-1", "sensor2-1", NodeStatus.Alarm, "Sensor"));
                    DataRepository.SetNode("/sensor/composite/leaf", new Node("s0002-1-1", "sensor12-1-1", NodeStatus.Normal, "Sensor", items: testNodeItems));
                }

                var sen001_1 = new Node("sen001_1", "1층 출입문 센서");
                sen001_1.SetItem("위치", "1층 현관 출입문");
                sen001_1.SetItem("상태", "닫침");
                DataRepository.SetNode("sensor/basic", sen001_1);
                NodePoint point       = new NodePoint(37.1235, 127.2222);
                var       sen001_2    = new Node("sen001_2", "1층 화제 센서", NodeStatus.Normal, point: point);
                double    temperature = Math.Round(_random.NextDouble() * 30.0, 1);
                sen001_2.Attributes["Temperature"] = $"{temperature}";
                sen001_2.SetItem("온도", $"{temperature}도");
                DataRepository.SetNode("sensor/basic", sen001_2);

                temperature = Math.Round(_random.NextDouble() * 30.0, 1);
                var sen001_3 = new Node("sen001_3", "1층 열화상 카메라", NodeStatus.Alarm);
                sen001_3.Attributes["Temperature"] = $"{temperature}";
                sen001_3.SetItem("최고온도", $"{temperature}도", "Alarm");
                sen001_3.SetItem("평균온도", "30.1도", "Normal");
                sen001_3.SetItem("최저온도", "26.5도", "Normal");
                DataRepository.SetNode("sensor/basic", sen001_3);

                _stopwatch.Restart();
            }
        }
コード例 #12
0
    public void Rotate(NodePoint node, bool rotateRight)
    {
        if (node.LockedNode)
        {
            return;
        }
        //add some kinda restaint in here for the angle it can rotate to

        if (rotateRight)
        {
            node.RotateRight();
        }
        else
        {
            node.RotateLeft();
        }

        UpdateNode(node, node.Posistion);
    }
コード例 #13
0
        private void Pulse(RadiationPulse Pulse)
        {
            StopWatchlog.Restart();

            //Radiation distance
            int radius = (int)Math.Round(Pulse.Strength / (Math.PI * 75));

            if (radius > 50)
            {
                radius = 50;
            }

            //Logger.Log("Radius > " + Radius);
            //Generates the conference
            circleBres(Pulse.Location.x, Pulse.Location.y, radius);

            //Logger.Log("CircleCircumference.Count > " + CircleCircumference.Count);
            //Logger.Log("Pulse.Strengt> " + Pulse.Strength);
            //Radiation for each line ( Dont worry it stacks)
            float InitialRadiation = Pulse.Strength / CircleCircumference.Count;

            foreach (var ToPoint in CircleCircumference)
            {
                DrawRadiationLine(Pulse.Location.x, Pulse.Location.y, ToPoint.x, ToPoint.y, InitialRadiation, Pulse);
            }

            //Logger.Log("CircleArea.Count > " + CircleArea.Count);
            //Set values on tiles
            foreach (var NodePoint in CircleArea)
            {
                NodePoint.AddRadiationPulse(NodePoint.MidCalculationNumbers, DateTime.Now,
                                            Pulse.SourceID); //Drops off too quickly
                NodePoint.MidCalculationNumbers = 0;
                //Logger.Log("rad onv " + NodePoint.RadiationLevel);
            }

            CircleCircumference.Clear();
            CircleArea.Clear();

            StopWatchlog.Stop();
            Logger.Log("StopWatchlog ElapsedMilliseconds time " + StopWatchlog.ElapsedMilliseconds, Category.Radiation);
        }
コード例 #14
0
    public void RemoveNode(NodePoint node)
    {
        if (node.LockedNode)
        {
            return;
        }

        Debug.Log("Destroying Node");

        for (int i = 0; i < Nodes.Count; i++)
        {
            if (Nodes[i] == node)
            {
                Nodes.RemoveAt(i);
                Destroy(node.gameObject);
                ///**THIS SHOULD BE UPDATING ONLY THE NEW MESHES NOT ALL OF THEM
                TG.DeleteAllSegments();
                TG.GenerateAllSegments();
                return;
            }
        }

        Debug.Log("Couldn't find node");
    }
コード例 #15
0
        private void ExportWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            AllPoints.Clear();
            CATIA = (INFITF.Application)Marshal.GetActiveObject("Catia.Application");
            Selection sel = CATIA.ActiveDocument.Selection;

            sel.Search("((((((CATStFreeStyleSearch.Point + CAT2DLSearch.2DPoint) + CATSketchSearch.2DPoint) + CATDrwSearch.2DPoint) + CATPrtSearch.Point) + CATGmoSearch.Point) + CATSpdSearch.Point),sel");
            //sel.Search("CATPrtsearch.point, sel");
            object[] coords  = new object[3];
            int      counter = 0;

            if (sel.Count != 0)
            {
                for (int i = 1; i <= sel.Count2; i++)
                {
                    var item = sel.Item2(i).Value as HybridShapeTypeLib.Point;
                    item.GetCoordinates(coords);
                    double X    = Convert.ToDouble(coords[0]);
                    double Y    = Convert.ToDouble(coords[1]);
                    double Z    = Convert.ToDouble(coords[2]);
                    string name = "";
                    if (item.get_Name().Contains("Точка.") || item.get_Name().Contains("Point."))
                    {
                        name = "Point_" + counter++;
                    }
                    else
                    {
                        name = item.get_Name();
                    }
                    NodePoint iNode = new NodePoint(name, X, Y, Z, item);
                    if (!AllPoints.Any(p => Math.Round(p.X, 3) == Math.Round(X, 3) && Math.Round(p.Y, 3) == Math.Round(Y, 3) && Math.Round(p.Z, 3) == Math.Round(Z, 3)))
                    {
                        AllPoints.Add(iNode); // Собираем список всех точек в NodeList
                    }
                }
                /////

                if (AllPoints.All(x => x.Name.Contains("Point_"))) //Если у все хточек нет нормальных названий
                {
                    var type = GraphTypeCombo.SelectedValue.ToString();
                    //var type = "Random Points";
                    counter = 0;
                    switch (type)
                    {
                    case "Gap or Size":
                        #region Gap Calculation
                        foreach (NodePoint Vstart in AllPoints)
                        {
                            foreach (NodePoint Vend in AllPoints)
                            {
                                if (Vstart.Name != Vend.Name)
                                {
                                    Vstart.DistanceTo.Add(Vend, getDistance(Vstart, Vend));
                                }
                            }
                        }
                        Graph.Clear();
                        NodePoint thisNode = AllPoints[0];
                        NodePoint nextNode = null;
                        counter       = 0;
                        thisNode.Name = "A" + counter++;
                        Graph.AddLast(thisNode);
                        while (Graph.Count < AllPoints.Count)
                        {
                            nextNode = thisNode.getClosestNode();
                            while (Graph.Contains(nextNode))
                            {
                                thisNode.DistanceTo.Remove(nextNode);
                                nextNode = thisNode.getClosestNode();
                            }
                            thisNode      = nextNode;
                            thisNode.Name = "A" + counter++;
                            Graph.AddLast(thisNode);
                        }

                        for (LinkedListNode <NodePoint> node = Graph.First; node != null; node = node.Next)
                        {
                            node.Value.link.set_Name(node.Value.Name);
                        }
                        break;

                        #endregion
                    case "Curvature":
                        #region Curvature Calculation
                        var Zsort = new SortByZ();
                        AllPoints.Sort(Zsort);
                        foreach (NodePoint node in AllPoints)
                        {
                            node.Name = "A" + counter++;
                            node.link.set_Name(node.Name);
                        }
                        break;

                        #endregion
                    case "Random Points":
                        #region Random Calculation
                        foreach (NodePoint node in AllPoints)
                        {
                            node.Name = "A" + counter++;
                            node.link.set_Name(node.Name);
                        }
                        break;
                        #endregion
                    }
                }
                else
                {
                    var Dsort = new SortByNameDigit();
                    AllPoints.Sort(Dsort);
                }
                //
                ComposeXLSX();
                var result =
                    e.Result = "ok";
            }
            else
            {
                e.Result = "no points";
            }
        }
コード例 #16
0
        void MakeBranch(Vector2i Origin, int Size, int Movement, double Roughness, int Depth, double heightstart)
        {
            Increment increment        = GetIncrement(Center.X - Origin.X, Center.Y - Origin.Y);
            Increment inc1             = increment;
            double    OriginDistance   = Math.Max(Math.Sqrt(increment.X * increment.X + increment.Y * increment.Y), 1);
            double    DistanceModifier = Size / Movement * (Depth + 1);

            increment = GetIncrement((increment.X / OriginDistance + (random.NextDouble() - 0.5) * AngleRandomer) * DistanceModifier,
                                     (increment.Y / OriginDistance + (random.NextDouble() - 0.5) * AngleRandomer) * DistanceModifier);
            if (Depth == 0)
            {
                double ang = Math.Atan2(increment.Y, increment.X);
                for (int i = 0; i < UsedAngles.Count; i++)
                {
                    if (Math.Abs(UsedAngles[i] - ang) < (Math.PI * 1.5 / Movement))
                    {
                        if (bounces++ < 15)
                        {
                            MakeBranch(Origin, Size, Movement, Roughness, Depth, heightstart);
                            return;
                        }
                    }
                }
                UsedAngles.Add(ang);
            }

            Vector2i Destination = FixBounds(new Vector2i((int)Math.Round(Center.X + increment.X),
                                                          (int)Math.Round(Center.Y + increment.Y)), Size);

            List <Vector2i> Points    = MakeLine(Origin, Destination, Size, Roughness);
            int             PointSize = Points.Count;

            if (PointSize == 0)
            {
                return;
            }

            Destination = Points[PointSize - 1];
            double distX = Center.X - Destination.X;
            double distY = Center.Y - Destination.Y;
            double DestinationDistance = Math.Max(Math.Sqrt(distX * distX + distY * distY), 1);

            double HeightStart = heightstart;
            double HeightDecay = (HeightStart - Height * ((MaxDistance - DestinationDistance) / MaxDistance)) / PointSize;

            int Branching = 0;

            Vector2i Previous = new Vector2i((int)(Origin.X / DetailScaler / SHRINKER + ADDER), (int)(Origin.Y / DetailScaler / SHRINKER / SHRINKER + ADDER));
            Vector2i prev2    = Previous;
            Vector2i Next;

            for (int i = 0; i < PointSize; i++)
            {
                double HeightValue = HeightStart - HeightDecay * (i + 1);

                Vector2i point = Points[i];

                Vector2i ScaledPoint = new Vector2i((int)(point.X / DetailScaler / SHRINKER + ADDER), (int)(point.Y / DetailScaler / SHRINKER + ADDER));

                if (prev2.X == ScaledPoint.X && prev2.Y == ScaledPoint.Y)
                {
                    prev2 = new Vector2i(ScaledPoint.X - Math.Sign(inc1.X), ScaledPoint.Y - Math.Sign(inc1.Y));
                    if (prev2.X == ScaledPoint.X && prev2.Y == ScaledPoint.Y)
                    {
                        prev2 = new Vector2i(ScaledPoint.X - 1, ScaledPoint.Y - 1);
                    }
                }


                Next = ScaledPoint;
                int n = 1;
                while (i + n < PointSize)
                {
                    Next = new Vector2i((int)(Points[i + n].X / DetailScaler / SHRINKER + ADDER), (int)(Points[i + n].Y / DetailScaler / SHRINKER + ADDER));
                    if (Next.X != ScaledPoint.X || Next.Y != ScaledPoint.Y)
                    {
                        break;
                    }
                    n++;
                }
                if (i + n >= PointSize)
                {
                    Next = new Vector2i((int)(Destination.X / DetailScaler / SHRINKER + ADDER), (int)(Destination.Y / DetailScaler / SHRINKER + ADDER));
                    if (Next.X == ScaledPoint.X && Next.Y == ScaledPoint.Y)
                    {
                        Next = new Vector2i(ScaledPoint.X + Math.Sign(increment.X), ScaledPoint.Y + Math.Sign(increment.Y));
                    }
                }
                NodePoint ScaledNodePoint = GetNodePoint(prev2, ScaledPoint, Next, HeightValue);

                if (!Nodes.ContainsKey(ScaledPoint))
                {
                    Nodes.Add(ScaledPoint, ScaledNodePoint);
                    prev2    = Previous;
                    Previous = ScaledPoint;
                }
                ToHandle.Add(new KeyValuePair <Vector2i, double>(new Vector2i((int)(point.X / SHRINKER + ADDER * DetailScaler), (int)(point.Y / SHRINKER + ADDER * DetailScaler)), HeightValue));

                if (random.NextDouble() < 0.2 && Depth < Movement && Branching < 5)
                {
                    Branching++;
                    MakeBranch(Destination, Size, Movement, Roughness, Depth + 1, HeightStart - HeightDecay * (PointSize + 1));
                }
            }
        }
コード例 #17
0
    //updates a mesh based upon a node
    public void UpdateNode(NodePoint NP, Vector3 pos)
    {
        if (NP.LockedNode)
        {
            return;
        }
        //makes sure nodes are far enough away from each other
        foreach (NodePoint n in Nodes)
        {
            if (NP == n)
            {
                continue;
            }

            if ((pos - n.Posistion).magnitude < minDist)
            {
                Debug.Log("Too Close");
                return;
            }
        }

        //makes sure a node is in front of the current node
        int index = Nodes.IndexOf(NP);

        ///THIS NEEDS TO CHANGE TO INCLUDE WRAPPING FOR LOOPED TRACKS
        if (index != 0)
        {
            Vector3 direction = (pos - Nodes[index - 1].Posistion).normalized;
            //find the forward vector of the last node
            Vector3 forward = Nodes[index - 1].transform.forward;
            //if the direction > forward vector?
            float angle = Vector3.Dot(direction, forward);
            Debug.Log(angle);
            if (angle < -.01f)
            {
                return;
            }
        }

        //need to add code to limit the angle it can be turned.

        NP.SetPosition(pos);

        for (int i = 0; i < Nodes.Count; i++)
        {
            if (Nodes[i] == NP)
            {
                if ((i != Nodes.Count - 1) || (TG.LoopTrack && i == Nodes.Count - 1))
                {
                    TG.DeleteSegment(i);
                    TG.GenerateSegement(i);
                }

                if (i != 0)
                {
                    TG.DeleteSegment(i - 1);
                    TG.GenerateSegement(i - 1);
                }

                if (TG.LoopTrack && i == 0)
                {
                    TG.DeleteSegment(TG.trackSegements.Count - 1);
                    TG.GenerateSegement(Nodes.Count - 1);
                }
            }
        }
    }
コード例 #18
0
ファイル: Program.cs プロジェクト: 19900623/PointManagers
    public static int NotMain(string[] args)
    {
        theSession = Session.GetSession();
        uf         = UFSession.GetUFSession();
        theUI      = UI.GetUI();
        var Zsort     = new SortByZ();
        var part      = theSession.Parts.Work;
        var AllPoints = new List <NodePoint>();
        int counter   = 0;

        for (int i = 0; i < theUI.SelectionManager.GetNumSelectedObjects(); i++)
        {
            TaggedObject obj = theUI.SelectionManager.GetSelectedTaggedObject(i);
            if (obj is Point)
            {
                Point3d   coords = ((Point)obj).Coordinates;
                NodePoint iNode  = new NodePoint("Point_" + counter++, coords);
                AllPoints.Add(iNode); // Собираем список всех точек
            }
        }

        var Tags = new List <Tag>();
        var tag  = new Tag();

        /* // Curvature = OK
         * AllPoints.Sort(Zsort);
         * foreach (NodePoint node in AllPoints)
         * {
         *  var newpoint = new Point3d(node.X, node.Y, node.Z);
         *  var p = part.Points.CreatePoint(newpoint);
         *  node.Name = "A" + counter++;
         *  p.SetName(node.Name);
         *  PointFeatureBuilder p_feature;
         *  p_feature = part.BaseFeatures.CreatePointFeatureBuilder(null);
         *  p_feature.Point = p;
         *  p_feature.Commit();
         *  p_feature.GetFeature().SetName(node.Name);
         *  Tags.Add(p_feature.GetFeature().Tag);
         *  p.SetVisibility(SmartObject.VisibilityOption.Visible);
         * }
         * uf.Modl.CreateSetOfFeature("Curvature", Tags.ToArray(), Tags.Count, 1, out tag);
         */


        /*
         * foreach (NodePoint Vstart in AllPoints)
         * {
         *  foreach (NodePoint Vend in AllPoints)
         *  {
         *      if (Vstart.Name != Vend.Name)
         *      {
         *          Vstart.DistanceTo.Add(Vend, getDistance(Vstart, Vend));
         *      }
         *  }
         * }
         *
         *
         * NodePoint thisNode = AllPoints[0];
         * NodePoint nextNode = null;
         * counter = 0;
         * thisNode.Name = "A" + counter++;
         * Graph.AddLast(thisNode);
         *
         * while (Graph.Count < AllPoints.Count)
         * {
         *  nextNode = thisNode.getClosestNode();
         *  while (Graph.Contains(nextNode))
         *  {
         *      thisNode.DistanceTo.Remove(nextNode);
         *      nextNode = thisNode.getClosestNode();
         *  }
         *  thisNode = nextNode;
         *  thisNode.Name = "A" + counter++;
         *  Graph.AddLast(thisNode);
         * }
         *
         * for (LinkedListNode<NodePoint> node = Graph.First; node != null; node = node.Next)
         * {
         *  var newpoint = new Point3d(node.Value.X, node.Value.Y, node.Value.Z);
         *  var p = part.Points.CreatePoint(newpoint);
         *  p.SetName(node.Value.Name);
         *  PointFeatureBuilder p_feature;
         *  p_feature = part.BaseFeatures.CreatePointFeatureBuilder(null);
         *  p_feature.Point = p;
         *  p_feature.Commit();
         *  p_feature.GetFeature().SetName(node.Value.Name);
         *  Tags.Add(p_feature.GetFeature().Tag);
         *  p.SetVisibility(SmartObject.VisibilityOption.Visible);
         * }
         *
         *
         * uf.Modl.CreateSetOfFeature("Curvature", Tags.ToArray(), Tags.Count, 1, out tag);
         */
        return(0);
    }
コード例 #19
0
    //------------------------------------------------------------------------------
    //Callback Name: update_cb
    //------------------------------------------------------------------------------
    public int update_cb(NXOpen.BlockStyler.UIBlock block)
    {
        try
        {
            if (block == GraphTypeSelect)
            {
            }
            else if (block == PointSelector)
            {
                AllPoints.Clear();
                int        counter   = 0;
                var        Selection = PointSelector.GetSelectedObjects();
                var        Sect      = Selection[0] as Section;
                NXObject[] Data;
                Sect.EvaluateAndAskOutputEntities(out Data);
                foreach (NXObject obj in Data)
                {
                    Point3d   coords = ((Point)obj).Coordinates;
                    NodePoint iNode  = new NodePoint("Point_" + counter++, coords);
                    if (!AllPoints.Any(p => Math.Round(p.X, 3) == Math.Round(coords.X, 3) && Math.Round(p.Y, 3) == Math.Round(coords.Y, 3) && Math.Round(p.Z, 3) == Math.Round(coords.Z, 3)))
                    {
                        AllPoints.Add(iNode); // Собираем список всех точек в NodeList
                    }
                }
                if (AllPoints.Count != 0)
                {
                    ExportButton.Enable = true;
                }
                else
                {
                    ExportButton.Enable = false;
                }
            }

            else if (block == ExportButton)
            {
                var type    = GraphTypeSelect.ValueAsString;
                var part    = theSession.Parts.Work;
                var Tags    = new List <Tag>();
                var tag     = new Tag();
                int counter = 0;
                switch (type)
                {
                case "Gap or Size":
                    #region Gap Calculation

                    foreach (NodePoint Vstart in AllPoints)
                    {
                        foreach (NodePoint Vend in AllPoints)
                        {
                            if (Vstart.Name != Vend.Name)
                            {
                                Vstart.DistanceTo.Add(Vend, getDistance(Vstart, Vend));
                            }
                        }
                    }
                    Graph.Clear();
                    NodePoint thisNode = AllPoints[0];
                    NodePoint nextNode = null;
                    counter       = 0;
                    thisNode.Name = "A" + counter++;
                    Graph.AddLast(thisNode);
                    while (Graph.Count < AllPoints.Count)
                    {
                        nextNode = thisNode.getClosestNode();
                        while (Graph.Contains(nextNode))
                        {
                            thisNode.DistanceTo.Remove(nextNode);
                            nextNode = thisNode.getClosestNode();
                        }
                        thisNode      = nextNode;
                        thisNode.Name = "A" + counter++;
                        Graph.AddLast(thisNode);
                    }

                    for (LinkedListNode <NodePoint> node = Graph.First; node != null; node = node.Next)
                    {
                        var newpoint = new Point3d(node.Value.X, node.Value.Y, node.Value.Z);
                        var p        = part.Points.CreatePoint(newpoint);
                        p.SetName(node.Value.Name);
                        PointFeatureBuilder p_feature;
                        p_feature       = part.BaseFeatures.CreatePointFeatureBuilder(null);
                        p_feature.Point = p;
                        p_feature.Commit();
                        p_feature.GetFeature().SetName(node.Value.Name);
                        Tags.Add(p_feature.GetFeature().Tag);
                        p.SetVisibility(SmartObject.VisibilityOption.Visible);
                    }
                    theUFSession.Modl.CreateSetOfFeature("Contour Points", Tags.ToArray(), Tags.Count, 1, out tag);

                    break;

                    #endregion
                case "Curvature":
                    #region Curvature Calculation
                    var Zsort = new SortByZ();
                    AllPoints.Sort(Zsort);
                    foreach (NodePoint node in AllPoints)
                    {
                        var newpoint = new Point3d(node.X, node.Y, node.Z);
                        var p        = part.Points.CreatePoint(newpoint);
                        node.Name = "A" + counter++;
                        p.SetName(node.Name);
                        PointFeatureBuilder p_feature;
                        p_feature       = part.BaseFeatures.CreatePointFeatureBuilder(null);
                        p_feature.Point = p;
                        p_feature.Commit();
                        p_feature.GetFeature().SetName(node.Name);
                        Tags.Add(p_feature.GetFeature().Tag);
                        p.SetVisibility(SmartObject.VisibilityOption.Visible);
                    }
                    theUFSession.Modl.CreateSetOfFeature("Curvature", Tags.ToArray(), Tags.Count, 1, out tag);
                    break;

                    #endregion
                case "Random Points":
                    #region Random Calculation
                    foreach (NodePoint node in AllPoints)
                    {
                        var newpoint = new Point3d(node.X, node.Y, node.Z);
                        var p        = part.Points.CreatePoint(newpoint);
                        node.Name = "A" + counter++;
                        p.SetName(node.Name);
                        PointFeatureBuilder p_feature;
                        p_feature       = part.BaseFeatures.CreatePointFeatureBuilder(null);
                        p_feature.Point = p;
                        p_feature.Commit();
                        p_feature.GetFeature().SetName(node.Name);
                        Tags.Add(p_feature.GetFeature().Tag);
                        p.SetVisibility(SmartObject.VisibilityOption.Visible);
                    }
                    theUFSession.Modl.CreateSetOfFeature("Points", Tags.ToArray(), Tags.Count, 1, out tag);
                    break;
                    #endregion
                }

                ComposeXLSX();
            }
            else if (block == ImportButton)
            {
                OpenFileDialog myDialog = new OpenFileDialog();
                string         FileName = "";
                myDialog.Filter = "Документы Excel (*.xlsx)|**.XLSX";
                if (myDialog.ShowDialog() == DialogResult.OK)
                {
                    FileName = myDialog.FileName;
                    var inputFile = new FileStream(FileName, FileMode.Open, FileAccess.Read);
                    if (FileName.ToLower().EndsWith(".xlsx"))
                    {
                        XSSFWorkbook inbook = OpenFileXLSX(FileName);
                        DrawPoints(inbook);
                    }
                    if (FileName.ToLower().EndsWith(".xls"))
                    {
                        HSSFWorkbook inbook = OpenFileXLS(FileName);
                        DrawPoints(inbook);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            //---- Enter your exception handling code here -----
            theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
        }
        return(0);
    }
コード例 #20
0
ファイル: Mountains.cs プロジェクト: BlackCoyote/FurAnjel
        public static void MakeBranch(Point Origin, int Size, int Movement, double Roughness, int Depth)
        {
            Increment increment        = GetIncrement(Center.X - Origin.X, Center.Y - Origin.Y);
            Increment inc1             = increment;
            double    OriginDistance   = Math.Max(Math.Sqrt(increment.X * increment.X + increment.Y * increment.Y), 1);
            double    DistanceModifier = Size / Movement * (Depth + 1);

            increment = GetIncrement((increment.X / OriginDistance + random.NextDouble() - 0.5) * DistanceModifier, (increment.Y / OriginDistance + random.NextDouble() - 0.5) * DistanceModifier);

            Point Destination = FixBounds(new Point((int)Math.Round(Center.X + increment.X),
                                                    (int)Math.Round(Center.Y + increment.Y)), Size);

            List <Point> Points    = MakeLine(Origin, Destination, Size, Roughness);
            int          PointSize = Points.Count;

            if (PointSize == 0)
            {
                return;
            }

            Destination = Points[PointSize - 1];
            double distX = Center.X - Destination.X;
            double distY = Center.Y - Destination.Y;
            double DestinationDistance = Math.Max(Math.Sqrt(distX * distX + distY * distY), 1);

            double HeightStart = Height * ((MaxDistance - OriginDistance) / MaxDistance);
            double HeightDecay = (HeightStart - Height * ((MaxDistance - DestinationDistance) / MaxDistance)) / PointSize;

            int Branching = 0;

            Point Previous = new Point(Origin.X / DetailScaler, Origin.Y / DetailScaler);
            Point prev2    = Previous;
            Point Next;

            for (int i = 0; i < PointSize; i++)
            {
                double HeightValue = HeightStart - HeightDecay * (i + 1);

                Point point = Points[i];

                Point ScaledPoint = new Point(point.X / DetailScaler, point.Y / DetailScaler);

                if (prev2.X == ScaledPoint.X && prev2.Y == ScaledPoint.Y)
                {
                    prev2 = new Point(ScaledPoint.X - Math.Sign(inc1.X), ScaledPoint.Y - Math.Sign(inc1.Y));
                    if (prev2.X == ScaledPoint.X && prev2.Y == ScaledPoint.Y)
                    {
                        prev2 = new Point(ScaledPoint.X - 1, ScaledPoint.Y - 1);
                    }
                    if (!Nodes.ContainsKey(prev2))
                    {
                        //Nodes.Add(prev2, GetNodePoint(new Point(int.MaxValue, int.MaxValue), prev2, ScaledPoint, HeightStart - HeightDecay * (i)));
                    }
                }


                Next = ScaledPoint;
                int n = 1;
                while (i + n < PointSize)
                {
                    Next = new Point(Points[i + n].X / DetailScaler, Points[i + n].Y / DetailScaler);
                    if (Next.X != ScaledPoint.X || Next.Y != ScaledPoint.Y)
                    {
                        break;
                    }
                    n++;
                }
                if (i + n >= PointSize)
                {
                    Next = new Point(Destination.X / DetailScaler, Destination.Y / DetailScaler);
                    if (Next.X == ScaledPoint.X && Next.Y == ScaledPoint.Y)
                    {
                        Next = new Point(ScaledPoint.X + Math.Sign(increment.X), ScaledPoint.Y + Math.Sign(increment.Y));
                        if (!Nodes.ContainsKey(Next))
                        {
                            //Nodes.Add(Next, GetNodePoint(ScaledPoint, Next, new Point(int.MaxValue, int.MaxValue), HeightStart - HeightDecay * (i + 2)));
                        }
                    }
                }
                if (Next.X == ScaledPoint.X && Next.Y == ScaledPoint.Y)
                {
                    Console.WriteLine("DERP NEXT");
                }
                NodePoint ScaledNodePoint = GetNodePoint(prev2, ScaledPoint, Next, HeightValue);

                if (!Nodes.ContainsKey(ScaledPoint))
                {
                    Nodes.Add(ScaledPoint, ScaledNodePoint);
                    prev2    = Previous;
                    Previous = ScaledPoint;
                }
                HeightMap[point.X, point.Y] = HeightValue;

                if (random.NextDouble() < 0.2 && Depth < Movement && Branching < 5)
                {
                    Branching++;
                    MakeBranch(Destination, Size, Movement, Roughness, Depth + 1);
                }
                //i++;
            }
        }
コード例 #21
0
    // Update is called once per frame
    void Update()
    {
        if (controls.TrackCreating.Start.triggered)
        {
            inMenu = !inMenu;
            if (inMenu)
            {
                FindObjectOfType <TrackUIManager>().ShowMenu();
            }
            else
            {
                FindObjectOfType <TrackUIManager>().HideMenu();
            }
        }

        if (!inMenu)
        {
            Cursor.lockState = CursorLockMode.Locked;
            Cursor.visible   = false;
            //adds a new road segment
            if (controls.TrackCreating.PlaceNode.triggered && !MovingObject)
            {
                AddPoint();
                //addNode = false;
                AS.PlayOneShot(placeNode);
            }

            //zooms in and out
            if (controls.TrackCreating.Zoom.triggered)
            {
                int value = (int)controls.TrackCreating.Zoom.ReadValue <float>();
                if ((int)ZoomLevel + value <= 4 && (int)ZoomLevel + value >= 1)
                {
                    ZoomLevel = ZoomLevel + value;
                    Zoom();
                }
            }


            //finds out if we're hovering over a node
            Ray ray = Camera.main.ScreenPointToRay(cursorPosition);
            ray.origin = new Vector3(RoundTo(ray.origin.x, (15f / 4) * (int)gridSize), RoundTo(ray.origin.y, 1), RoundTo(ray.origin.z, (15f / 4) * (int)gridSize));
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, 100f, nodeLayer))
            {
                NodePoint p = hit.collider.gameObject.GetComponent <NodePoint>();

                if (!p.LockedNode)
                {
                    //if we select the node to move it
                    if (controls.TrackCreating.Drag.triggered && !p.isSelected)
                    {
                        p.Select(true);
                        MovingObject = p.gameObject;
                    }
                    //when we deselect a node
                    else if (controls.TrackCreating.Drag.triggered && p.isSelected)
                    {
                        p.Select(false);
                        MovingObject = null;
                    }
                }

                //rotating the nodes around
                if (controls.TrackCreating.RotateRight.triggered)
                {
                    NodeManager.instance.Rotate(p.GetComponent <NodePoint>(), true);
                }

                if (controls.TrackCreating.RotateLeft.triggered)
                {
                    NodeManager.instance.Rotate(p.GetComponent <NodePoint>(), false);
                }

                if (controls.TrackCreating.Delete.triggered)
                {
                    NodeManager.instance.RemoveNode(p.GetComponent <NodePoint>());
                    AS.PlayOneShot(deleteNode);
                }
            }

            //moving a nodes position
            if (MovingObject)
            {
                Vector3 newPos = Camera.main.ScreenToWorldPoint((Vector3)cursorPosition + new Vector3(0, 0, Camera.main.transform.position.y - 1));
                newPos = new Vector3(RoundTo(newPos.x, (15f / 4) * (int)gridSize), RoundTo(newPos.y, 1), RoundTo(newPos.z, (15f / 4) * (int)gridSize));
                //MovingObject.transform.position = newPos;
                NodeManager.instance.UpdateNode(MovingObject.GetComponent <NodePoint>(), newPos);
            }

            if (controls.TrackCreating.TempReorder.triggered)
            {
                if (MovingObject)
                {
                    NodeManager.instance.ReOrder(MovingObject.GetComponent <NodePoint>(), (int)controls.TrackCreating.TempReorder.ReadValue <float>());
                }
            }

            if (controls.TrackCreating.ToogleLoop.triggered)
            {
                TG.ToggleLoop();
            }
        }
        else
        {
            //we're in the menu
            Cursor.lockState = CursorLockMode.None;
            Cursor.visible   = true;
        }
    }