Example #1
0
    public void DeletePath(MPath path2)
    {
        var pathNum = paths.IndexOf(path2);

        Debug.Log("Delete Path " + pathNum);

        List <int> hom = null;

        foreach (var homClass in pathHomClasses)
        {
            if (homClass.Contains(pathNum))
            {
                hom = homClass;
                break;
            }
        }

        if (hom != null)
        {
            hom.Remove(pathNum);
            if (hom.Count == 0)
            {
                pathHomClasses.Remove(hom);
            }
        }
        paths.Remove(path2);
        particleSystems.RemoveAt(pathNum);
        Destroy(path2);
        if (homTextObj != null)
        {
            UpdateHomAlgebra();
        }
    }
Example #2
0
 void AddPathAlgebra(int i, MPath path)
 {
     if (path.Count > 3)
     {
         Debug.Log("Set Text " + i);
         var  textObj = Instantiate(textPrefab);
         Text text    = textObj.GetComponentInChildren <Text> ();
         var  str     = "f" + i;
         if (path.dotFrom.Equals(path.dotTo))
         {
             str += "; ";
             var dictionary = windingNumbersForObstacles[i];
             for (int j = 0; j < statics.Count; j++)
             {
                 var obstacle = statics[j];
                 str += "Ind(x" + j + ") = " + dictionary[j] + ", ";
             }
         }
         text.text = str;
         textObj.transform.SetParent(canvas.transform);
         Vector3 normal = Vector3.zero;
         var     k      = path.Count / 2;
         Debug.Log(path.Count);
         Debug.Log(k);
         normal = Vector3.Cross(path.GetPosition(k) - path.GetPosition(k - 1), Vector3.forward);
         var position = Camera.main.WorldToScreenPoint(path.GetPosition(k) + Statics.lineThickness * 2f * normal.normalized);
         textObj.transform.position = position + Vector3.right * dotPrefab.transform.lossyScale.x;
         UpdateHomAlgebra();
     }
 }
Example #3
0
    public IEnumerator AddParticleSystem(MPath path)
    {
        float timeSum      = 0f;
        bool  isOk         = true;
        var   nextPosition = 0;

        while (path != null && path.Count > 0 && isOk)
        {
            isOk = false;
            try {
                var m_currentParticleEffect            = path.gameObject.GetComponent <ParticleSystem> ();
                var numParticles                       = m_currentParticleEffect.particleCount;
                ParticleSystem.Particle[] ParticleList = new ParticleSystem.Particle[numParticles];
                m_currentParticleEffect.GetParticles(ParticleList);

                for (int i = 0; i < numParticles; ++i)
                {
                    if (path != null)
                    {
                        timeSum += Time.deltaTime;
                        ParticleList[i].position = path.GetPosition(nextPosition);
                        nextPosition             = nextPosition + 1 < path.Count ? nextPosition + 1 : 0;
                    }
                }

                m_currentParticleEffect.SetParticles(ParticleList, numParticles);
                isOk = true;
            } catch (MissingReferenceException ex) {
                Debug.Log(ex);
                yield break;
            }
            yield return(null);
        }
        yield break;
    }
Example #4
0
 public Homotopy(MPath p1, MPath pMidPath, Material mat)
 {
     matPrefab = mat;
     path1     = p1;
     midPath   = pMidPath;
     AddMesh();
 }
Example #5
0
        /// <summary>
        /// 构造静态的调用方法
        /// IPlanningAlgorithm接口
        /// </summary>
        /// <param name="iTaskIndex"></param>
        /// <returns></returns>
        public MPath BuildPathForSingleUAVInStatic(int iTaskIndex)
        {
            MPath mPath = new MPath();

            mPath.Waypoints = new List <MWaypoint>();
            mPath.Index     = AlgoInput.UAVTask[iTaskIndex].Index; //得到当前无人机编号,就是这条路径的编号
            int iWaypointIndex = 0;                                //所有阶段的点的集合的索引

            for (int iStageIndex = 0; iStageIndex < AlgoInput.UAVTask[iTaskIndex].Stages.Count; iStageIndex++)
            {
                //在每个阶段都先获取起始点和目标点,并进行处理
                var start = AlgoInput.UAVTask[iTaskIndex].Stages[iStageIndex].StartState.Location;
                var goal  = AlgoInput.UAVTask[iTaskIndex].Stages[iStageIndex].TargetState.Location;
                //第一次赋值给 HeursticInfo 刷入坐标
                HeursticInfo.StartNode  = new Node(GetRegulatedPos(start), null);
                HeursticInfo.TargetNode = new Node(GetRegulatedPos(goal), null);
                //第二次赋值给 HeursticInfo 刷入启发式参数(第一次直接刷启发式的话起点终点坐标不对)
                HeursticInfo.StartNode  = new Node(GetRegulatedPos(start), null, HeursticInfo);
                HeursticInfo.TargetNode = new Node(GetRegulatedPos(goal), null, HeursticInfo);

                //获取路径
                var mStagePath = BuildPathForSingleUavStageInStatic(iTaskIndex, out HashSet <Node> mCloseList);

                //为可视化输出保存
                _visualization.mPathForVisualizaition = mCloseList;
                if (!PathPlaningDataVisualization.PathPlaningDataVisualization.AlgoDataDict.ContainsKey(mPath.Index.ToString() + "-" + iStageIndex.ToString()))
                {
                    //为ResultShowForm分析窗口保存数据
                    PathPlaningDataVisualization.PathPlaningDataVisualization.AlgoDataDict.Add(mPath.Index.ToString() + "-" + iStageIndex.ToString(), _visualization.MyTreeNodeConverter(_visualization.mPathForVisualizaition));
                }
                else
                {
                    PathPlaningDataVisualization.PathPlaningDataVisualization.AlgoDataDict[mPath.Index.ToString() + "-" + iStageIndex.ToString()] = _visualization.MyTreeNodeConverter(_visualization.mPathForVisualizaition);
                }

                if (mStagePath == null)
                {
                    mPath.Waypoints = new List <MWaypoint>()
                    {
                        new MWaypoint(iWaypointIndex++, new Node(start, null).ConvertTreeNodeToUAVState(), iStageIndex),
                        new MWaypoint(iWaypointIndex++, new Node(goal, null).ConvertTreeNodeToUAVState(), iStageIndex)
                    };
                    return(mPath);
                }

                //输出格式处理
                for (int k = 0; k < mStagePath.Count - 1; k++)
                {
                    mPath.Waypoints.Add(new MWaypoint(iWaypointIndex++, mStagePath[k].ConvertTreeNodeToUAVState(), iStageIndex));
                }
                if (iStageIndex == AlgoInput.UAVTask[iTaskIndex].Stages.Count - 1)//如果到了最后一个阶段,不要忘记把最后一个点加进来
                {
                    mPath.Waypoints.Add(new MWaypoint(iWaypointIndex++, mStagePath[mStagePath.Count - 1].ConvertTreeNodeToUAVState(), AlgoInput.UAVTask[iTaskIndex].Stages.Count - 1));
                    //刷一个最后的点,防止不再运行~
                    mPath.Waypoints.Add(new MWaypoint(iWaypointIndex++, new Node(goal, null).ConvertTreeNodeToUAVState(), iStageIndex));
                }
            }

            return(mPath);
        }
Example #6
0
 public void StartConnector(MPath path1, MPath path2, int path1Num, int path2Num, LevelData level)
 {
     this.level  = level;
     this.path1  = path1;
     this.path2  = path2;
     isHomotopic = level.GetHomotopyClass(path2Num).Contains(path1Num);
     Debug.Log("Are homotopic? " + isHomotopic);
     StartCoroutine(drawConnector(true));
 }
Example #7
0
    private Vector3 GetNormalCenter(MPath path, List <Vector3> normals, List <Vector3> vertices)
    {
        var centerNormal = Vector3.zero;

        for (int i = 0; i < path.Count; i++)
        {
            centerNormal += normals[vertices.IndexOf(path.GetLocalPosition(i))];
        }
        return(centerNormal / (float)path.Count);
    }
Example #8
0
        public override bool Equals(object obj)
        {
            if (obj == null || !(obj is Media))
            {
                return(false);
            }
            var item = obj as Media;

            return(MPath.Equals(item.MPath));
        }
Example #9
0
    public void StartRetractor(MPath path, float maxTime)
    {
        this.maxTime = maxTime;
        this.path    = path;
        bool isHomotopic = true;

        if (isHomotopic)
        {
            StartCoroutine(retraction());
        }
    }
Example #10
0
    public void StopParticleSystem(MPath path)
    {
        var index = paths.IndexOf(path);

        if (index > -1)
        {
            StopCoroutine(particleSystems[index]);
        }
        else
        {
            StopCoroutine(particleSystems[paths.Count]);
        }
        path.gameObject.GetComponent <ParticleSystem> ().Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear);
    }
        /// <summary>
        /// 主要算法函数,求最后的所有阶段的路径集合
        /// </summary>
        /// <param name="iTaskIndex"></param>
        /// <returns></returns>
        protected MPath BuildPathForSingleUAV(int iTaskIndex)
        {
            //算法参数
            AStarOriginAlgorithmParameter mPara = AlgoParameter as AStarOriginAlgorithmParameter;

            #region 定义变量,需要再添加
            MPath mPath = new MPath();                             //初始化一条路径,最后得到的就是这个类中的一个list存放的路径序列
            mPath.Index     = AlgoInput.UAVTask[iTaskIndex].Index; //得到当前无人机编号,就是这条路径的编号
            mPath.Waypoints = new List <MWaypoint>();
            int iWaypointIndex = 0;                                //所有阶段的点的集合的索引
            #endregion

            #region ----------------------------对每一个阶段规划航路------------------------------------------
            for (int iStageIndex = 0; iStageIndex < AlgoInput.UAVTask[iTaskIndex].Stages.Count; iStageIndex++)
            {
                List <Node> openlist = null;
                var         FAPath   = BuildPathForSingleUAVwithSingleStageInStatic(iTaskIndex, iStageIndex, mPara, out openlist);

                #region  航迹可视化处理
                //为可视化输出保存
                Visualization.mPathForVisualizaition = openlist.Where(a => a.sign == true).ToList();
                if (!PathPlaningDataVisualization.PathPlaningDataVisualization.AlgoDataDict.ContainsKey(mPath.Index.ToString() + "-" + iStageIndex.ToString()))
                {
                    //为ResultShowForm分析窗口保存数据
                    //3.30.2018 刘洋添加
                    PathPlaningDataVisualization.PathPlaningDataVisualization.AlgoDataDict.Add(mPath.Index.ToString() + "-" + iStageIndex.ToString(), Visualization.MyTreeNodeConverter(Visualization.mPathForVisualizaition));
                }
                else
                {
                    PathPlaningDataVisualization.PathPlaningDataVisualization.AlgoDataDict[mPath.Index.ToString() + "-" + iStageIndex.ToString()] = Visualization.MyTreeNodeConverter(Visualization.mPathForVisualizaition);
                }
                #endregion

                #region 航迹保存
                //添加当前阶段航路到总航路(起始航路点为当前阶段, 此阶段的目标航路点为下一个阶段的起始航路点, 注意总航路的最后一个航路点属于最后一个阶段)
                for (int k = 0; k < FAPath.Count - 1; k++)
                {
                    mPath.Waypoints.Add(new MWaypoint(iWaypointIndex, FAPath[k].ConvertTreeNodeToUAVState(), iStageIndex));
                    iWaypointIndex = iWaypointIndex + 1;
                }
                if (iStageIndex == AlgoInput.UAVTask[iTaskIndex].Stages.Count - 1)//如果到了最后一个阶段,不要忘记把最后一个点加进来
                {
                    mPath.Waypoints.Add(new MWaypoint(iWaypointIndex, FAPath[FAPath.Count - 1].ConvertTreeNodeToUAVState(), AlgoInput.UAVTask[iTaskIndex].Stages.Count - 1));
                }
                #endregion
            }
            #endregion
            return(mPath);
        }
Example #12
0
 public void setMesh(List <Vector3> staticPositions, MPath path2)
 {
     if (Statics.isSphere)
     {
         setSphereMesh(staticPositions, path2);
     }
     else if (Statics.isTorus)
     {
         setTorusMesh(staticPositions, path2);
     }
     else
     {
         set2DMesh(staticPositions, path2);
     }
 }
Example #13
0
    public void StartParticleSystem(MPath path)
    {
        var index      = paths.IndexOf(path);
        var enumerator = particleSystems[index];

        if (index > -1)
        {
            StartCoroutine(particleSystems[index]);
        }
        else
        {
            StartCoroutine(particleSystems[paths.Count]);
        }
        path.gameObject.GetComponent <ParticleSystem> ().Play(true);
    }
Example #14
0
    public Homotopy newHomotopy(MPath path1, MPath midPath)
    {
        Homotopy hom = new Homotopy(path1, midPath, homotopyMaterial);

        Debug.Log(midPath.ToString());
        Debug.Log(midPath.Count.ToString());

        var color = path1.GetColor();

        midPath.SetColor(color);
        color.a = color.a / 3f;
        path1.SetColor(color);
        //		for (int i = 0; i < Statics.numHomotopyLines; i++) {
//			GameObject lineObj = new GameObject ();
//			var line = lineObj.AddComponent<LineRenderer> ();
//			line.positionCount = hom.counter;
//			line.startWidth = Statics.lineThickness / 3f;
//			line.endWidth = Statics.lineThickness / 3f;
//			line.numCornerVertices = 0;
//			line.GetComponent<Renderer> ().material = pathMaterial;
//			line.GetComponent<Renderer> ().material.SetColor ("_Color", Statics.homotopyColor);
////			hom.homotopyLines.Add (line);
//		}
        for (int i = 0; i < path1.Count; i++)
        {
            midPath.SetPosition(i, path1.GetPosition(i));
            if (path1.hasNormals)
            {
                midPath.SetNormal(i, path1.GetNormal(i));
            }
        }
        midPath.SetMesh();
//		int counter = 1;
//		float sum = 0f;
//		var length = midPath.Length ();
//		for (int i = 0; i < count - 1; i++) {
//			if (sum > counter * (length / (Statics.numHomotopyLines + 1))) {
//				var line = hom.homotopyLines [counter - 1];
//				line.SetPosition (0, midpath.GetPosition (i));
//				counter++;
//			}
//			sum += Vector3.Distance (midpath.GetPosition (i), midpath.GetPosition (i + 1));
//		}
        return(hom);
    }
Example #15
0
    public void Concatenate(MPath path2)
    {
        var list1 = GetPositions();
        var list2 = path2.GetPositions();

        list1.AddRange(list2);
        SetPositions(list1);

        var list1n = line.GetNormals();
        var list2n = path2.line.GetNormals();

        list1n.AddRange(list2n);
        line.SetNormals(list1n);
        Destroy(path2);
        dotTo = path2.dotTo;

        line.SetMesh();
    }
Example #16
0
    List <Vector3> getPoints(MPath path2)
    {
        var           points   = new List <Vector3> ();
        List <Vertex> vertices = new List <Vertex> ();

        for (int i = 0; i < path2.Count; i++)
        {
            var point = path2.GetPosition(i);
            points.Add(point);
        }
        for (int i = path1.Count - 2; i > 0; i--)
        {
            var point = path1.GetPosition(i);
            points.Add(point);
        }
        points = DouglasPeucker.DouglasPeuckerReduction(points, 0.01d);
        return(points);
    }
Example #17
0
    public IEnumerator SetParticleSystem(MPath path)
    {
        var pathObject = path.gameObject;
        var partsystem = pathObject.GetComponent <ParticleSystem> ();

        if (partsystem == null)
        {
            partsystem = pathObject.AddComponent <ParticleSystem> ();
        }
        var renderer = partsystem.GetComponent <ParticleSystemRenderer> ();

        renderer.maxParticleSize = 0.01f;
        renderer.minParticleSize = 0.01f;
        renderer.material        = partMaterial;
        var main = partsystem.main;

        main.maxParticles  = 1;
        main.startSpeed    = 0;
        main.startLifetime = 1000;
        main.playOnAwake   = true;
        var emission = partsystem.emission;

        emission.rateOverTime = 0.5f;
        renderer.sortingOrder = path.sortingOrder + 1;
        var enumerator = AddParticleSystem(path);

        var trails = partsystem.trails;

        trails.enabled  = true;
        trails.lifetime = 0.0003f;
        trailMaterial.SetColor("_Color", new Color(1f, 1f, 1f, 0.3f));
        renderer.trailMaterial = trailMaterial;

        AnimationCurve animationCurve = new AnimationCurve();

        animationCurve.AddKey(0f, Statics.lineThickness * 0.8f);
        animationCurve.AddKey(1f, 0f);
        ParticleSystem.MinMaxCurve minMaxCurve = new ParticleSystem.MinMaxCurve(1f, animationCurve);
        minMaxCurve.curve     = animationCurve;
        trails.widthOverTrail = minMaxCurve;

        StartCoroutine(enumerator);
        return(enumerator);
    }
Example #18
0
    public void AddCurveToBundle(PathFactory pf, int draggingPosition)
    {
        MPath path;

        if (curveBundle.Count == 0)
        {
            path = path1;
        }
        else
        {
            path = curveBundle[curveBundle.Count - 1];
        }
        if (Vector3.Distance(path.GetPosition(draggingPosition), midPath.GetPosition(draggingPosition)) > Statics.bundleDist)
        {
            MPath newPath = pf.newPath(path1.GetColor(), path1.dotFrom, path1.dotTo);
            newPath.SetPositions(midPath.GetPositions());
            curveBundle.Add(newPath);
        }
    }
Example #19
0
    public void ConstructCanonicalPath(MPath path)
    {
        path.canonicalPath = new List <int> ();
        for (int j = 0; j < path.Count - 1; j++)
        {
            var point1 = path.GetPosition(j);
            var point2 = path.GetPosition(j + 1);

            var comparedXIndex = CompareXIndex(point1, point2);
            if (comparedXIndex != -1)
            {
                bool over = overObstacle(comparedXIndex, point1, point2);
                if (over)
                {
                    path.canonicalPath.Add(comparedXIndex * 2 + 1);
                }
                else
                {
                    path.canonicalPath.Add(comparedXIndex * 2);
                }
            }
        }
        var can = path.canonicalPath;
        int i   = 0;

        while (i < can.Count - 1)
        {
            if (can[i] == can[i + 1])
            {
                can.RemoveAt(i);
                can.RemoveAt(i);
                if (i > 0)
                {
                    i = i - 1;
                }
            }
            else
            {
                i++;
            }
        }
    }
Example #20
0
    Vector3 OnMeshTriangle(int i, MPath path, out int triangleIndex)
    {
        RaycastHit hit;
        // Debug.Log ("At point " + i + " normals " + path.line.GetNormals ().Count + " path.line " + path.Count);
        var normal   = i < path.Count ? path.GetNormal(i) : path.GetNormal(0);
        var position = i < path.Count ? path.GetPosition(i) : path.GetPosition(0);
        Ray ray      = new Ray(position, -normal);

        if (manifold.gameObject.GetComponent <MeshCollider> ().Raycast(ray, out hit, 0.5f))
        {
            triangleIndex = hit.triangleIndex;
            return(hit.point);
        }
        else
        {
            Debug.LogWarning("Warning in OnMesh: Raycast not working, returning closest Point instead");
            triangleIndex = -1;
            return(GameObject.FindGameObjectWithTag("Sphere").GetComponent <MeshCollider> ().ClosestPoint(position));
        }
    }
Example #21
0
    public void addPath(MPath path)
    {
        var pathGroup = new List <int> ();

        pathGroup.Add(paths.Count);
        pathHomClasses.Add(pathGroup);

        paths.Add(path);

        Dictionary <int, int> dict = new Dictionary <int, int> ();
        var list = path.GetPositions();

        for (int i = 0; i < statics.Count; i++)
        {
            dict.Add(i, WindingNumber(list, statics[i].transform.position));
        }
        windingNumbersForObstacles.Add(dict);

        ConstructCanonicalPath(path);
        var canstring = "";

        foreach (var num in path.canonicalPath)
        {
            canstring += num + " ";
        }
        Debug.Log("Canonical path " + path.pathNumber + " is: " + canstring);

        for (int i = 0; i < paths.Count - 1; i++)
        {
            CheckIfHomotopic(i, paths.Count - 1);
        }

        if (Statics.showingAlgebra)
        {
            AddPathAlgebra(paths.Count - 1, path);
        }
        Last.Push(MType.Path);
    }
Example #22
0
    public IEnumerator Cap(MPath path)
    {
        while (buildingGraph)
        {
            yield return(new WaitForSeconds(0.01f));
        }

        mesh = manifold.gameObject.GetComponent <MeshFilter> ().mesh;
        var vertices  = mesh.vertices.ToList();
        var normals   = mesh.normals.ToList();
        var triangles = mesh.triangles.ToList();
        var normal    = GetNormalCenter(path, normals, vertices);

        normals.Add(normal);

        var center = path.GetCenterPosition() + normal.normalized * 0.1f;

        vertices.Add(center);

        var newVertex = vertices.IndexOf(center);

        for (int i = 0; i < path.Count; i++)
        {
            int vertex     = vertices.IndexOf(path.GetLocalPosition(i));
            int nextVertex = vertices.IndexOf(path.GetLocalPosition(i + 1 < path.Count ? i + 1 : 0));

            triangles.Add(vertex);
            triangles.Add(nextVertex);
            triangles.Add(newVertex);
        }
        mesh.vertices  = vertices.ToArray();
        mesh.triangles = triangles.ToArray();
        mesh.normals   = normals.ToArray();
        SetSwitchedManifold(manifold);

        manifold.gameObject.GetComponent <MeshCollider> ().sharedMesh = mesh;
    }
Example #23
0
    // Update is called once per frame
    void Update()
    {
        int tapCount = Input.touchCount;

        if (tapCount == 2 && notOnGUI(2))
        {
            Touch touch1 = Input.GetTouch(0);
            Touch touch2 = Input.GetTouch(1);
            if (touch2.phase == TouchPhase.Began)
            {
                Ray        ray1 = Camera.main.ScreenPointToRay(touch1.position);
                Ray        ray2 = Camera.main.ScreenPointToRay(touch2.position);
                RaycastHit hitInfo1;
                RaycastHit hitInfo2;
                var        hit1 = this.gameObject.GetComponent <MeshCollider> ().Raycast(ray1, out hitInfo1, 100f);
                var        hit2 = this.gameObject.GetComponent <MeshCollider> ().Raycast(ray2, out hitInfo2, 100f);
                if (hit1 && hit2)
                {
                    Statics.isDragging = true;
                    touchPos           = touch2.position;
                }
            }
            else if (touch2.phase == TouchPhase.Moved && touchPos.x < float.PositiveInfinity)
            {
                var vector2 = touch2.position - touchPos;
                this.gameObject.transform.position += new Vector3(vector2.x, 0, vector2.y) * 0.02f;
                touchPos = touch2.position;
            }
            else if (touch2.phase == TouchPhase.Ended || touch2.phase == TouchPhase.Canceled)
            {
                Statics.isDragging = false;
                touchPos           = Vector2.positiveInfinity;
            }
        }
        else if (tapCount == 3 && notOnGUI(3))
        {
            Touch touch1 = Input.GetTouch(0);
            Touch touch2 = Input.GetTouch(1);
            Touch touch3 = Input.GetTouch(2);
            if (touch3.phase == TouchPhase.Began)
            {
                Ray        ray1 = Camera.main.ScreenPointToRay(touch1.position);
                Ray        ray2 = Camera.main.ScreenPointToRay(touch2.position);
                Ray        ray3 = Camera.main.ScreenPointToRay(touch3.position);
                RaycastHit hitInfo1;
                RaycastHit hitInfo2;
                RaycastHit hitInfo3;
                var        hit1 = this.gameObject.GetComponent <MeshCollider> ().Raycast(ray1, out hitInfo1, 100f);
                var        hit2 = this.gameObject.GetComponent <MeshCollider> ().Raycast(ray2, out hitInfo2, 100f);
                var        hit3 = this.gameObject.GetComponent <MeshCollider> ().Raycast(ray3, out hitInfo3, 100f);
                if (hit1 && hit2 && hit3)
                {
                    Statics.isDragging = true;
                    touchPos1          = touch1.position;
                    touchPos2          = touch2.position;
                    touchPos3          = touch3.position;
                    rotationCenter     = CircleCenterThrough3D(hitInfo1.point, hitInfo2.point, hitInfo3.point);
                    rotationTouchPoint = CircleCenterThrough2D(touch1.position, touch2.position, touch3.position);
                    normal             = Vector3.Cross(hitInfo3.point - hitInfo1.point, hitInfo2.point - hitInfo1.point);
                }
            }
            else if (touch3.phase == TouchPhase.Moved && touchPos1.x < float.PositiveInfinity)
            {
                var angle1 = Vector3.SignedAngle(touchPos1 - rotationTouchPoint, touch1.position - rotationTouchPoint, normal);
                var angle2 = Vector3.SignedAngle(touchPos2 - rotationTouchPoint, touch2.position - rotationTouchPoint, normal);
                var angle3 = Vector3.SignedAngle(touchPos3 - rotationTouchPoint, touch3.position - rotationTouchPoint, normal);
                var angle  = (angle1 + angle2 + angle3) / 3;
                touchPos1 = touch1.position;
                touchPos2 = touch2.position;
                touchPos3 = touch3.position;
                this.gameObject.transform.RotateAround(rotationCenter, normal, angle);
            }
            else if (touch3.phase == TouchPhase.Ended || touch3.phase == TouchPhase.Canceled)
            {
                Statics.isDragging = false;
                touchPos1          = Vector2.positiveInfinity;
                touchPos2          = Vector2.positiveInfinity;
                touchPos3          = Vector2.positiveInfinity;
            }
        }
        else if (tapCount == 4 && notOnGUI(4))
        {
            Touch touch1 = Input.GetTouch(0);
            Touch touch2 = Input.GetTouch(1);
            Touch touch3 = Input.GetTouch(2);
            Touch touch4 = Input.GetTouch(3);
            if (touch4.phase == TouchPhase.Began)
            {
                Ray        ray1 = Camera.main.ScreenPointToRay(touch1.position);
                Ray        ray2 = Camera.main.ScreenPointToRay(touch2.position);
                Ray        ray3 = Camera.main.ScreenPointToRay(touch3.position);
                Ray        ray4 = Camera.main.ScreenPointToRay(touch4.position);
                RaycastHit hitInfo1;
                RaycastHit hitInfo2;
                RaycastHit hitInfo3;
                RaycastHit hitInfo4;
                var        hit1 = this.gameObject.GetComponent <MeshCollider> ().Raycast(ray1, out hitInfo1, 100f);
                var        hit2 = this.gameObject.GetComponent <MeshCollider> ().Raycast(ray2, out hitInfo2, 100f);
                var        hit3 = this.gameObject.GetComponent <MeshCollider> ().Raycast(ray3, out hitInfo3, 100f);
                var        hit4 = this.gameObject.GetComponent <MeshCollider> ().Raycast(ray4, out hitInfo4, 100f);
                if (hit1 && hit2 && hit3 && hit4)
                {
                    Statics.isDragging = true;
                    touchPos           = touch2.position;
                    touchPos22         = touch4.position;
                    var freeDragging3D = Camera.main.GetComponent <FreeDragging3D> ();
                    var m1             = this.gameObject.GetComponent <Manifold> ();

                    m2 = GameObject.Instantiate(m1.gameObject).AddComponent <Manifold> ();
                    // m2.boundaryCurves = m1.getBoundariesClone ();

                    m2.gameObject.name = m1.gameObject.name + " Duplicate";
                    m2.ClearObjects();
                    var newDots = new Dictionary <GameObject, GameObject> ();
                    foreach (var item in freeDragging3D.level.dots)
                    {
                        Transform parent = item.transform.parent;
                        if (parent == m1.gameObject.transform)
                        {
                            var copy = GameObject.Instantiate(item);
                            copy.transform.parent = m2.gameObject.transform;
                            newDots[item]         = copy;
                        }
                    }
                    var newPaths = new List <MPath> ();
                    foreach (var item in freeDragging3D.level.paths)
                    {
                        if (item.parentManifold.Equals(m1))
                        {
                            newPaths.Add(item);
                        }
                    }
                    foreach (var item in newPaths)
                    {
                        MPath path = freeDragging3D.level.NewPath(newDots[item.dotFrom], newDots[item.dotTo]);
                        Destroy(path.gameObject);
                        path.gameObject.transform.position = m2.gameObject.transform.position;
                        path.SetPositions(item.GetPositions());
                        path.SetNormals(item.GetNormals());
                        path.AttachTo(m2);
                        freeDragging3D.level.addPath(path);
                    }
                    freeDragging3D.manifolds.Add(m2);
                }
            }
            else if (touch2.phase == TouchPhase.Moved && touchPos.x < float.PositiveInfinity)
            {
                var vector2 = touch2.position - touchPos;
                this.gameObject.transform.position += new Vector3(vector2.x, 0, vector2.y) * 0.02f;
                touchPos = touch2.position;

                var vector22 = touch4.position - touchPos22;
                m2.gameObject.transform.position += new Vector3(vector22.x, 0, vector22.y) * 0.02f;
                touchPos22 = touch4.position;
            }
            else if (touch2.phase == TouchPhase.Ended || touch2.phase == TouchPhase.Canceled)
            {
                touchPos           = Vector2.positiveInfinity;
                touchPos22         = Vector2.positiveInfinity;
                Statics.isDragging = false;
            }
        }
    }
Example #24
0
 public override string ToString()
 => $@"<animateMotion dur=""{Dur}"" repeatCount=""{RepeatCount}"" {(MPath == null ? "/>" : ">" + MPath.ToString() + "</animationMotion >")}";
        /// <summary>
        /// 实时调用方法
        /// ICompletePlanningAlgorithm接口
        /// </summary>
        /// <param name="iTaskIndex"></param>
        /// <param name="mWaypoint"></param>
        /// <param name="mPath"></param>
        /// <returns></returns>
        public MPath BuildPathForSingleUAVForRealTime(int iTaskIndex, MWaypoint mWaypoint, MPath mPath)
        {
            //移除起始航路点之后(含)的所有航路点
            if (mPath.Waypoints != null)
            {
                mPath.Waypoints.RemoveRange(mWaypoint.Index, mPath.Waypoints.Count - mWaypoint.Index);
                //从数据库移除
            }

            //以当前航路点为当前阶段的起始状态点(以后的阶段均不变), 构建新的阶段
            List <MStage> mNewStages  = new List <MStage>();
            var           mFirstStage = new MStage()
            {
                StageIndex  = mWaypoint.StageIndex,
                StartState  = new MKeyState(mWaypoint.State),
                TargetState = AlgoInput.UAVTask[iTaskIndex].Stages[mWaypoint.StageIndex].TargetState
            };

            mNewStages.Add(mFirstStage);
            for (int i = mWaypoint.StageIndex + 1; i < AlgoInput.UAVTask[iTaskIndex].Stages.Count; ++i)
            {
                var mTempStage = AlgoInput.UAVTask[iTaskIndex].Stages[i];
                mNewStages.Add(mTempStage);
            }

            //当前航路点编号
            int iWaypointIndex = mWaypoint.Index;

            //对每一个阶段规划航路
            //Alex Liu评价:原来的FOR写的真糟糕。。。。。
            //for (int iStageIndex = mNewStages[0].StageIndex; iStageIndex < mNewStages[0].StageIndex + mNewStages.Count; ++iStageIndex)
            foreach (var mStage in mNewStages)
            {
                //在每个阶段都先获取起始点和目标点,并进行处理
                var start       = mStage.StartState.Location;
                var goal        = mStage.TargetState.Location;
                var iStageIndex = mStage.StageIndex;

                HeursticInfo.StartNode  = new Node(GetRegulatedPos(start), null);
                HeursticInfo.TargetNode = new Node(GetRegulatedPos(goal), null);

                HashSet <Node> mCloseList = null;
                //获取路径
                var mStagePath = BuildPathForSingleUAVwithSingleStageInStatic(iTaskIndex, out mCloseList);

                //输出格式处理
                for (int k = 0; k < mStagePath.Count - 1; k++)
                {
                    mPath.Waypoints.Add(new MWaypoint(iWaypointIndex++, mStagePath[k].ConvertTreeNodeToUAVState(), iStageIndex));
                }
                if (iStageIndex == AlgoInput.UAVTask[iTaskIndex].Stages.Count - 1)//如果到了最后一个阶段,不要忘记把最后一个点加进来
                {
                    mPath.Waypoints.Add(new MWaypoint(iWaypointIndex++, mStagePath[mStagePath.Count - 1].ConvertTreeNodeToUAVState(), AlgoInput.UAVTask[iTaskIndex].Stages.Count - 1));
                    //刷一个最后的点,防止不再运行~
                    mPath.Waypoints.Add(new MWaypoint(iWaypointIndex++, new Node(goal, null).ConvertTreeNodeToUAVState(), iStageIndex));
                }
            }

            return(mPath);
        }
Example #26
0
 void setTorusMesh(List <Vector3> staticPositions, MPath path2)
 {
 }
Example #27
0
        /// <summary>
        /// Initializes the Project class.
        /// </summary>
        /// <param name="projectName">Name of the project.</param>
        /// <param name="projectType">Type of the project.</param>
        public void Initialize(string projectName, ProjectType projectType)
        {
            ProjectName = projectName;
            ProjectType = projectType;
            ProjectFilePath = null;

            if (projectType == ProjectType.Queue)
            {
                QueueObject = new MQueue();
                PathObject = null;
            }
            else
            {
                PathObject = new MPath();
                QueueObject = null;
            }
        }
Example #28
0
    void setSphereMesh(List <Vector3> staticPositions, MPath path2)
    {
        foreach (var meshFilter in parentMeshObject.GetComponentsInChildren <MeshFilter> ())
        {
            GameObject.Destroy(meshFilter.gameObject);
        }
        meshes.Clear();
        var  points     = getPoints(path2);
        var  northLists = new List <List <Vector3> > ();
        var  southLists = new List <List <Vector3> > ();
        bool fromNorth  = points[0].z > 0 ? true : false;

        if (fromNorth)
        {
            northLists.Add(new List <Vector3> ());
        }
        else
        {
            southLists.Add(new List <Vector3> ());
        }
        List <int> switchedBefore = new List <int> ();

        for (int i = 0; i < points.Count; i++)
        {
            var vector = points[i];
            if (vector.z > 0)
            {
                if (!fromNorth)
                {
                    switchedBefore.Add(i);
                    fromNorth = true;
                    northLists.Add(new List <Vector3> ());
                }
                northLists[northLists.Count - 1].Add(vector);
            }
            else
            {
                if (fromNorth)
                {
                    switchedBefore.Add(i);
                    fromNorth = false;
                    southLists.Add(new List <Vector3> ());
                }
                southLists[southLists.Count - 1].Add(vector);
            }
        }

        UnityEngine.Debug.Log("Number Northlists: " + northLists.Count);
        UnityEngine.Debug.Log("Switched before: ");
        foreach (var point in switchedBefore)
        {
            UnityEngine.Debug.Log(point);
        }
        for (int i = 0; i < switchedBefore.Count / 2; i++)
        {
            var cross11 = points[switchedBefore[2 * i] - 1];
            var cross12 = points[switchedBefore[2 * i]];
            var mid1    = Vector3.Lerp(cross11, cross12, 0.5f);
            mid1.z = 0;

            var cross21 = points[switchedBefore[2 * i + 1] - 1];
            var cross22 = points[switchedBefore[2 * i + 1]];
            var mid2    = Vector3.Lerp(cross21, cross22, 0.5f);
            mid2.z = 0;
        }
        foreach (var pointsNorth in northLists)
        {
            var verticesNorth = ToVertex(pointsNorth);
            if (verticesNorth.Count > 0)
            {
                var polygonNorth = new Polygon();
                UnityEngine.Debug.Log("Number of vertices north: " + verticesNorth.Count);
                var contourNorth = new Contour(verticesNorth);

                Point point = null;
                for (int i = 0; i < staticPositions.Count; i++)
                {
                    if (IsPointInPolygon(staticPositions[i], verticesNorth))
                    {
                        point = new Point(staticPositions[i].x, staticPositions[i].y);
                        UnityEngine.Debug.Log("Is inside");
                        break;
                    }
                    else
                    {
                        if (IsPointInPolygon(constpoint, verticesNorth))
                        {
                            UnityEngine.Debug.Log(constpoint + " Is inside");
                        }
                    }
                }
                if (point != null)
                {
                    polygonNorth.Add(contourNorth, point);
                }
                else
                {
                    polygonNorth.Add(contourNorth);
                }

                List <int>     trianglesNorth;
                List <Vector3> meshVerticesNorth;
                SetMesh(polygonNorth, out meshVerticesNorth, out trianglesNorth);
                var meshNorth = AddMesh();
                meshNorth.vertices  = meshVerticesNorth.ToArray();
                meshNorth.triangles = trianglesNorth.ToArray();

                Vector3[] normals = meshNorth.normals;
                for (int i = 0; i < normals.Length; i++)
                {
                    normals[i] = -normals[i];
                }
                meshNorth.normals = normals;
                for (int m = 0; m < meshNorth.subMeshCount; m++)
                {
                    int[] triangles2 = meshNorth.GetTriangles(m);
                    for (int i = 0; i < triangles2.Length; i += 3)
                    {
                        int temp = triangles2[i + 0];
                        triangles2[i + 0] = triangles2[i + 1];
                        triangles2[i + 1] = temp;
                    }
                    meshNorth.SetTriangles(triangles2, m);
                }
            }
        }
        UnityEngine.Debug.Log("Number Southlists: " + southLists.Count);
        foreach (var pointsSouth in southLists)
        {
            var verticesSouth = ToVertex(pointsSouth);
            if (verticesSouth.Count > 0)
            {
                var polygonSouth = new Polygon();
                UnityEngine.Debug.Log("Number of vertices south: " + verticesSouth.Count);
                var contourSouth = new Contour(verticesSouth);

                Point point = null;
                for (int i = 0; i < staticPositions.Count; i++)
                {
                    if (IsPointInPolygon(staticPositions[i], verticesSouth))
                    {
                        point = new Point(staticPositions[i].x, staticPositions[i].y);
                        UnityEngine.Debug.Log("Is inside");
                        break;
                    }
                    else
                    {
                        if (IsPointInPolygon(constpoint, verticesSouth))
                        {
                            UnityEngine.Debug.Log(constpoint + " Is inside");
                        }
                    }
                }
                if (point != null)
                {
                    polygonSouth.Add(contourSouth, point);
                }
                else
                {
                    polygonSouth.Add(contourSouth);
                }

                List <int>     trianglesSouth;
                List <Vector3> meshVerticesSouth;
                SetMesh(polygonSouth, out meshVerticesSouth, out trianglesSouth);
                var meshSouth = AddMesh();
                meshSouth.vertices  = meshVerticesSouth.ToArray();
                meshSouth.triangles = trianglesSouth.ToArray();
            }
        }
    }
Example #29
0
    void set2DMesh(List <Vector3> staticPositions, MPath path2)
    {
        var mesh = meshes[0];

        mesh.Clear();
        var   polygon  = new Polygon();
        var   points   = getPoints(path2);
        var   vertices = ToVertex(points);
        var   contour  = new Contour(vertices);
        Point point    = null;

        for (int i = 0; i < staticPositions.Count; i++)
        {
            if (IsPointInPolygon(staticPositions[i], vertices))
            {
                point = new Point(staticPositions[i].x, staticPositions[i].y);
                UnityEngine.Debug.Log("Is inside");
                break;
            }
            else
            {
                if (IsPointInPolygon(constpoint, vertices))
                {
                    UnityEngine.Debug.Log(constpoint + " Is inside");
                }
            }
        }
        if (point != null)
        {
            polygon.Add(contour, point);
        }
        else
        {
            polygon.Add(contour);
        }
        var options = new ConstraintOptions()
        {
        };
        var quality = new QualityOptions()
        {
            //			MinimumAngle = 25,
            //			MaximumArea = 0.01d
        };
        // Triangulate the polygon
        var            polyMesh      = polygon.Triangulate(options, quality);
        var            polyVertices  = polyMesh.Vertices;
        var            polyTriangles = polyMesh.Triangles;
        List <Vector3> meshVertices  = new List <Vector3> ();
        List <int>     triangles     = getTriangles(polyTriangles, meshVertices);

        mesh.vertices  = meshVertices.ToArray();
        mesh.triangles = triangles.ToArray();
        //		Vector3[] normals = mesh.normals;
        //		for (int i = 0; i < normals.Length; i++)
        //			normals [i] = -normals [i];
        //		mesh.normals = normals;
        //		for (int m = 0; m < mesh.subMeshCount; m++) {
        //			int[] triangles2 = mesh.GetTriangles (m);
        //			for (int i = 0; i < triangles2.Length; i += 3) {
        //				int temp = triangles2 [i + 0];
        //				triangles2 [i + 0] = triangles2 [i + 1];
        //				triangles2 [i + 1] = temp;
        //			}
        //			mesh.SetTriangles (triangles2, m);
        //		}
    }
Example #30
0
 public Homotopy NewHomotopy(MPath p1, MPath midPath)
 {
     return(homotopyFactory.newHomotopy(p1, midPath));
 }
Example #31
0
    internal bool IdentifyCuts(MPath path)
    {
        onMeshPositions = new List <Vector3> ();
        triangleIndices = new List <int> ();
        onVertex        = new Dictionary <int, int> ();
        int indexNotNeeded;
        var oldVertex = isNearVertex(OnMeshTriangle(path.Count - 1, path, out indexNotNeeded));

        for (int i = 0; i < path.Count; i++)
        {
            int     index;
            Vector3 onMeshPosition = OnMeshTriangle(i, path, out index);
            int     vertex         = isNearVertex(onMeshPosition);
            if (vertex != -1)
            {
                if (vertex != oldVertex)
                {
                    Debug.Log("Move vertex " + i + " to " + vertex);
                    onMeshPositions.Add(vertices[vertex]);
                    // Misc.DebugSphere (onMeshPositions.Last (), Color.red, "On Mesh On Vertex" + i);
                    triangleIndices.Add(index);
                    onVertex[onMeshPositions.Count - 1] = vertex;
                }
            }
            else
            {
                onMeshPositions.Add(onMeshPosition);
                triangleIndices.Add(index);
                // Misc.DebugSphere (onMeshPositions.Last (), Color.red, "On Mesh " + i);
                // DebugAtTriangle (index, Color.blue);
            }
            oldVertex = vertex;
        }

        // for (int i = 0; i < onMeshPositions.Count; i++) {
        //     Misc.DebugSphere (onMeshPositions[i], Color.red, "Position " + i + " in triangle " + triangleIndices[i].First () + "/" + triangleIndices[i].Count);
        // }

        cutAlongEdges = new Dictionary <int, PolygonSide> ();
        var cutThroughTriangles = new Dictionary <int, Pair <PolygonSide> > ();

        cutPointType = new List <string> ();
        // var sinside = "Inside";
        cutPoints    = new List <Vector3> ();
        cutEdges     = new Dictionary <int, PolygonSide> ();
        cutNodes     = new Dictionary <int, int> ();
        cutTriangles = new Dictionary <int, int> ();
        for (int i = 1; i < onMeshPositions.Count; i++)
        {
            // bool addedCutPoint = false;
            GetIntersection(i);
        }
        // Set cutAlongEdges
        for (int i = 1; i < cutPoints.Count; i++)
        {
            if (cutEdges.ContainsKey(i - 1) && cutEdges.ContainsKey(i))
            {
                var e1 = cutEdges[i - 1];
                var e2 = cutEdges[i];
                if (e1.SameAs(e2))
                {
                    Debug.Log("Cut edges are same for " + i + ", as they are " + e1 + " and " + e2);
                    // cutAlongEdges[i] = new Pair<int> (i - 1, i);
                    cutAlongEdges[i] = e1;
                }
            }
            // Misc.DebugSphere (cutPoints[i], Color.red, "Cut Point " + i + " " + cutPointType[i]);
        }
        //INSERT MID CUTPOINTS
        // for (int i = 0; i < cutPoints.Count; i++) {
        //     bool insertMid = false;
        //     if (cutEdges.ContainsKey (i - 1) && cutEdges.ContainsKey (i)) {
        //         var e1 = cutEdges[i - 1];
        //         var e2 = cutEdges[i];
        //         if (e1.SameAs (e2)) {
        //             Debug.Log ("Cut edges are same for " + i + ", as they are " + e1 + " and " + e2);
        //             insertMid = true;
        //         }
        //     } else if (cutEdges.ContainsKey (i - 1) && cutNodes.ContainsKey (i)) {
        //         var e1 = cutEdges[i - 1];
        //         if (e1.Contains (cutNodes[i])) {
        //             insertMid = true;
        //         }
        //     } else if (cutNodes.ContainsKey (i - 1) && cutEdges.ContainsKey (i)) {
        //         var e1 = cutEdges[i];
        //         if (e1.Contains (cutNodes[i - 1])) {
        //             insertMid = true;
        //         }
        //     }

        //     if (insertMid) {
        //         int c1 = path.line.GetNearestPointTo (cutPoints[i - 1]);
        //         int c2 = path.line.GetNearestPointTo (cutPoints[i]);
        //         Debug.Log ("Insert point at " + i);
        //         AddCutPoint (cutPoints, cutPointType, onMeshPositions[(c1 + c2) / 2], sinside);
        //     }
        // }
        return(true);
    }
        public OvlModelSearcher(MQueue queueObject, MPath pathObject)
        {
            if (queueObject == null && pathObject == null)
                throw new ArgumentNullException("Either queueObject or pathObject must be initialized");

            _queue = queueObject;
            _path = pathObject;

            _regex = new Regex(RegexPattern, RegexOptions.IgnoreCase);

            Reset();
        }