Example #1
0
 public void AddEdgeObjs(TensileEdge Eobj)
 {
     if (!connectedEdgeObjs.Contains(Eobj))
     {
         connectedEdgeObjs.Add(Eobj);
     }
 }
Example #2
0
 public void addTensileEdgeObjs(TensileEdge _te)
 {
     if (!EdgeObjects.Contains(_te))
     {
         EdgeObjects.Add(_te);
     }
 }
    public void AddVertexEdgeTriangle(TensileEdge SE, int index)
    {
        int V0 = SE.StartVertice;
        int V1 = SE.EndVertice;

        if (SE.GetConnecetedTriangles().Count() == 1)
        {
            Vector3 _p = SE.PosToGrow(index);

            _edgeGraph.edgeGraph.AddVertex();

            int V = _edgeGraph.edgeGraph.VertexCount - 1;

            _edgeGraph.edgeGraph.AddEdge(V, V0);
            _edgeGraph.edgeGraph.AddEdge(V, V1);


            addPosition(_p);
            var tObj = Instantiate(TGVertexPrefab, transform);
            tObj.SetBarHolder(BarsHolder);
            tObj.SetStrHolder(StringHolder);
            tObj.transform.localPosition = _p;

            tObj.SetupStructure(Scale, DefState, V);

            _edgeGraph.TensileVertexObjects[V0].AddConnectedVertObjInLayer(tObj);
            _edgeGraph.TensileVertexObjects[V1].AddConnectedVertObjInLayer(tObj);

            _edgeGraph.TensileVertexObjects.Add(tObj);

            SE.AddDiagonalVertex(tObj);
            SE.NeighborVertexEnd = tObj;


            var eObj0 = Instantiate(TGEdgePrefab, transform);
            eObj0.SetBarHolder(BarsHolder);
            eObj0.SetStrHolder(StringHolder);
            eObj0.SetupStructure(Scale, DefState, V, V0, savedPositions);

            _edgeGraph.TensileEdgeObjects.Add(eObj0);

            var eObj1 = Instantiate(TGEdgePrefab, transform);
            eObj1.SetBarHolder(BarsHolder);
            eObj1.SetStrHolder(StringHolder);
            eObj1.SetupStructure(Scale, DefState, V, V1, savedPositions);

            _edgeGraph.TensileEdgeObjects.Add(eObj1);

            var tri = new TensileTriangle();

            tri.SetupTriangle(V, V0, V1, savedPositions);

            _edgeGraph.TensileTriangle.Add(tri);

            tri.addTensileEdgeObjs(SE);
            tri.addTensileEdgeObjs(eObj0);
            tri.addTensileEdgeObjs(eObj1);

            tri.addTensileVertexObjs(tObj);
            tri.addTensileVertexObjs(_edgeGraph.TensileVertexObjects[V0]);
            tri.addTensileVertexObjs(_edgeGraph.TensileVertexObjects[V1]);

            SE.AddTriangle(tri);

            eObj0.AddTriangle(tri);

            eObj0.AddConnectedVertex(tObj);
            eObj0.AddConnectedVertex(_edgeGraph.TensileVertexObjects[V0]);

            eObj0.AddDiagonalVertex(_edgeGraph.TensileVertexObjects[V1]);

            tObj.AddEdgeObjs(eObj0);
            _edgeGraph.TensileVertexObjects[V0].AddEdgeObjs(eObj0);



            eObj1.AddTriangle(tri);

            eObj1.AddDiagonalVertex(_edgeGraph.TensileVertexObjects[V0]);

            eObj1.AddConnectedVertex(tObj);
            eObj1.AddConnectedVertex(_edgeGraph.TensileVertexObjects[V1]);
            tObj.AddEdgeObjs(eObj1);
            _edgeGraph.TensileVertexObjects[V1].AddEdgeObjs(eObj1);

            List <TensileEdge> SharedPointEdges = new List <TensileEdge>();

            foreach (var e in _edgeGraph.TensileEdgeObjects)
            {
                if (e.GetPositionToGrow().Count != 0)
                {
                    var P = e.GetPositionToGrow()[index];

                    if (P == _p && e != SE)
                    {
                        SharedPointEdges.Add(e);
                        var tp = e.PosToGrow(index);
                    }
                }
            }

            if (SharedPointEdges.Count != 0)
            {
                foreach (var e in SharedPointEdges)
                {
                    var _v0 = e.StartVertice;
                    var _v1 = e.EndVertice;
                    int _v2 = V;

                    e.AddDiagonalVertex(_edgeGraph.TensileVertexObjects[V]);
                    TensileTriangle _tri = new TensileTriangle();

                    _tri.SetupTriangle(_v0, _v1, _v2, savedPositions);

                    e.AddTriangle(_tri);
                    _tri.addTensileEdgeObjs(e);

                    _tri.addTensileVertexObjs(_edgeGraph.TensileVertexObjects[_v0]);
                    _tri.addTensileVertexObjs(_edgeGraph.TensileVertexObjects[_v1]);
                    _tri.addTensileVertexObjs(_edgeGraph.TensileVertexObjects[_v2]);

                    TensileEdge ne;

                    List <TensileEdge> NearEdges = new List <TensileEdge>(2);

                    int NearEdgeCount = 0;

                    foreach (var ve in _edgeGraph.TensileVertexObjects[V].GetConnectedEdgeObjs())
                    {
                        if (ve.StartVertice == _v0 || ve.EndVertice == _v0)
                        {
                            NearEdgeCount++;
                            NearEdges.Add(ve);
                        }
                        else if (ve.StartVertice == _v1 || ve.EndVertice == _v1)
                        {
                            NearEdgeCount++;
                            NearEdges.Add(ve);
                        }
                    }

                    if (NearEdgeCount == 1)
                    {
                        foreach (var ve in _edgeGraph.TensileVertexObjects[V].GetConnectedEdgeObjs())
                        {
                            if (ve.StartVertice == _v0 || ve.EndVertice == _v0)
                            {
                                //NearEdgeCount++;
                                ne = ve;
                                ne.AddDiagonalVertex(_edgeGraph.TensileVertexObjects[_v1]);
                                ne.AddTriangle(_tri);
                                _tri.addTensileEdgeObjs(ne);

                                var eObj2 = Instantiate(TGEdgePrefab, transform);
                                eObj2.SetBarHolder(BarsHolder);
                                eObj2.SetStrHolder(StringHolder);

                                eObj2.SetupStructure(Scale, DefState, _v1, _v2, savedPositions);
                                eObj2.AddDiagonalVertex(_edgeGraph.TensileVertexObjects[_v0]);
                                _edgeGraph.edgeGraph.AddEdge(_v1, _v2);

                                eObj2.AddConnectedVertex(_edgeGraph.TensileVertexObjects[_v1]);
                                eObj2.AddConnectedVertex(_edgeGraph.TensileVertexObjects[_v2]);

                                eObj2.AddTriangle(_tri);
                                _tri.addTensileEdgeObjs(eObj2);

                                _edgeGraph.TensileEdgeObjects.Add(eObj2);

                                _edgeGraph.TensileVertexObjects[_v2].AddEdgeObjs(eObj2);
                                _edgeGraph.TensileVertexObjects[_v1].AddEdgeObjs(eObj2);
                                _edgeGraph.TensileVertexObjects[_v1].AddConnectedVertObjInLayer(_edgeGraph.TensileVertexObjects[_v2]);


                                break;
                            }
                            else if (ve.StartVertice == _v1 || ve.EndVertice == _v1)
                            {
                                // NearEdgeCount++;
                                ne = ve;
                                ne.AddDiagonalVertex(_edgeGraph.TensileVertexObjects[_v0]);
                                ne.AddTriangle(_tri);
                                _tri.addTensileEdgeObjs(ne);


                                var eObj2 = Instantiate(TGEdgePrefab, transform);
                                eObj2.SetBarHolder(BarsHolder);
                                eObj2.SetStrHolder(StringHolder);

                                eObj2.SetupStructure(Scale, DefState, _v0, _v2, savedPositions);
                                eObj2.AddDiagonalVertex(_edgeGraph.TensileVertexObjects[_v1]);
                                _edgeGraph.edgeGraph.AddEdge(_v0, _v2);

                                eObj2.AddConnectedVertex(_edgeGraph.TensileVertexObjects[_v0]);
                                eObj2.AddConnectedVertex(_edgeGraph.TensileVertexObjects[_v2]);

                                eObj2.AddTriangle(_tri);
                                _tri.addTensileEdgeObjs(eObj2);

                                _edgeGraph.TensileEdgeObjects.Add(eObj2);
                                _edgeGraph.TensileVertexObjects[_v2].AddEdgeObjs(eObj2);
                                _edgeGraph.TensileVertexObjects[_v0].AddEdgeObjs(eObj2);
                                _edgeGraph.TensileVertexObjects[_v0].AddConnectedVertObjInLayer(_edgeGraph.TensileVertexObjects[_v2]);

                                break;
                            }
                            else
                            {
                                continue;
                            }
                        }
                    }


                    if (NearEdgeCount == 0)
                    {
                        ne = Instantiate(TGEdgePrefab, transform);;
                        ne.SetBarHolder(BarsHolder);
                        ne.SetStrHolder(StringHolder);

                        ne.SetupStructure(Scale, DefState, _v1, _v2, savedPositions);
                        ne.AddDiagonalVertex(_edgeGraph.TensileVertexObjects[_v0]);
                        _edgeGraph.edgeGraph.AddEdge(_v1, _v2);

                        ne.AddConnectedVertex(_edgeGraph.TensileVertexObjects[_v1]);
                        ne.AddConnectedVertex(_edgeGraph.TensileVertexObjects[_v2]);

                        ne.AddTriangle(_tri);
                        _tri.addTensileEdgeObjs(ne);

                        _edgeGraph.TensileEdgeObjects.Add(ne);
                        _edgeGraph.TensileVertexObjects[_v2].AddEdgeObjs(ne);
                        _edgeGraph.TensileVertexObjects[_v1].AddEdgeObjs(ne);


                        var eObj2 = Instantiate(TGEdgePrefab, transform);
                        eObj2.SetBarHolder(BarsHolder);
                        eObj2.SetStrHolder(StringHolder);

                        eObj2.SetupStructure(Scale, DefState, _v0, _v2, savedPositions);
                        eObj2.AddDiagonalVertex(_edgeGraph.TensileVertexObjects[_v1]);
                        _edgeGraph.edgeGraph.AddEdge(_v0, _v2);

                        eObj2.AddConnectedVertex(_edgeGraph.TensileVertexObjects[_v0]);
                        eObj2.AddConnectedVertex(_edgeGraph.TensileVertexObjects[_v2]);

                        eObj2.AddTriangle(_tri);
                        _tri.addTensileEdgeObjs(eObj2);

                        _edgeGraph.TensileEdgeObjects.Add(eObj2);
                        _edgeGraph.TensileVertexObjects[_v2].AddEdgeObjs(eObj2);
                        _edgeGraph.TensileVertexObjects[_v0].AddEdgeObjs(eObj2);

                        _edgeGraph.TensileVertexObjects[_v0].AddConnectedVertObjInLayer(_edgeGraph.TensileVertexObjects[_v2]);
                        _edgeGraph.TensileVertexObjects[_v1].AddConnectedVertObjInLayer(_edgeGraph.TensileVertexObjects[_v2]);
                    }

                    if (NearEdgeCount == 2)
                    {
                        NearEdges[0].AddTriangle(_tri);
                        NearEdges[1].AddTriangle(_tri);

                        NearEdges[0].AddDiagonalVertex(_edgeGraph.TensileVertexObjects[_v1]);
                        NearEdges[1].AddDiagonalVertex(_edgeGraph.TensileVertexObjects[_v0]);

                        _tri.addTensileEdgeObjs(NearEdges[0]);
                        _tri.addTensileEdgeObjs(NearEdges[1]);

                        _edgeGraph.TensileVertexObjects[_v0].AddConnectedVertObjInLayer(_edgeGraph.TensileVertexObjects[_v2]);
                        _edgeGraph.TensileVertexObjects[_v1].AddConnectedVertObjInLayer(_edgeGraph.TensileVertexObjects[_v2]);
                    }
                }
            }
            if (_edgeGraph.TensileVertexObjects[V].GetConnectedEdgeObjs().Count() == 6)
            {
                List <TensileEdge> ToTriEdges = new List <TensileEdge>(2);
                foreach (var ce in _edgeGraph.TensileVertexObjects[V].GetConnectedEdgeObjs())
                {
                    if (ce.GetConnecetedTriangles().Count() == 1)
                    {
                        ToTriEdges.Add(ce);
                    }
                }

                int _vt0;
                int _vt1;

                if (ToTriEdges[0].StartVertice == V)
                {
                    _vt0 = ToTriEdges[0].EndVertice;
                }
                else
                {
                    _vt0 = ToTriEdges[0].StartVertice;
                }
                if (ToTriEdges[1].StartVertice == V)
                {
                    _vt1 = ToTriEdges[1].EndVertice;
                }
                else
                {
                    _vt1 = ToTriEdges[1].StartVertice;
                }

                TensileTriangle TT = new TensileTriangle();

                TT.SetupTriangle(_vt0, _vt1, V, savedPositions);

                ToTriEdges[0].AddDiagonalVertex(_edgeGraph.TensileVertexObjects[_vt1]);
                ToTriEdges[1].AddDiagonalVertex(_edgeGraph.TensileVertexObjects[_vt0]);

                ToTriEdges[0].AddTriangle(TT);
                ToTriEdges[1].AddTriangle(TT);

                var te = Instantiate(TGEdgePrefab, transform);
                te.SetBarHolder(BarsHolder);
                te.SetStrHolder(StringHolder);

                te.SetupStructure(Scale, DefState, _vt0, _vt1, savedPositions);
                te.AddDiagonalVertex(_edgeGraph.TensileVertexObjects[V]);
                _edgeGraph.edgeGraph.AddEdge(_vt0, _vt1);

                te.AddConnectedVertex(_edgeGraph.TensileVertexObjects[_vt0]);
                te.AddConnectedVertex(_edgeGraph.TensileVertexObjects[_vt1]);

                te.AddTriangle(TT);
                TT.addTensileEdgeObjs(te);

                _edgeGraph.TensileEdgeObjects.Add(te);
                _edgeGraph.TensileVertexObjects[_vt1].AddEdgeObjs(te);
                _edgeGraph.TensileVertexObjects[_vt0].AddEdgeObjs(te);

                _edgeGraph.TensileVertexObjects[_vt0].AddConnectedVertObjInLayer(_edgeGraph.TensileVertexObjects[_vt1]);
            }
        }
    }