Example #1
0
        public override void  SetupPoints()
        {
            Matrix4x4 matrixXZ = Matrix4x4.LookAt(Vector3.zero, Vector3.back, Vector3.down);
            Matrix4x4 matrixXY = Matrix4x4.LookAt(Vector3.zero, Vector3.down, Vector3.left);
            Matrix4x4 matrixYZ = Matrix4x4.LookAt(Vector3.zero, Vector3.left, Vector3.back);


            elements.ConstructionPoints.AddRange(TensegrityUtil.GetGoldenRectPoints(halfSize, matrixXZ));
            elements.ConstructionPoints.AddRange(TensegrityUtil.GetGoldenRectPoints(halfSize, matrixXY));
            elements.ConstructionPoints.AddRange(TensegrityUtil.GetGoldenRectPoints(halfSize, matrixYZ));
            int index = 0;

            for (int i = 0; i < elements.ConstructionPoints.Count; i++)
            {
                elements.ConstructionPoints[i] = TensegrityUtil.CleanUp(elements.ConstructionPoints[i]);
                var p  = elements.ConstructionPoints[i];
                var ep = Instantiate(prefabs.m_PointPrefab, transform);
                ep.transform.localPosition = p;
                ep.name  = "endpoint_" + index;
                ep.index = index;
                if (ep.GetComponentInChildren <Text> ())
                {
                    ep.GetComponentInChildren <Text>().text = $"{index}";
                }
                ep.UpdatePosition();
                elements.EndPoints.Add(ep);
                index++;
            }
            elements.center = Instantiate(prefabs.m_Center, transform);
            elements.center.defaultPosition = transform.position;
            elements.center.UpdateCenter(this);
        }
        public override void SetupPoints()
        {
            if (tetraPoints == null || tetraPoints.Length == 0)
            {
                tetraPoints = TensegrityUtil.GetTetraPoints(radius);
            }

            for (int i = 0; i < tetraPoints.Length; i++)
            {
                int to    = i;
                int from1 = i + 1 < tetraPoints.Length - 1 ? i + 1 : 0;
                int from2 = from1 + 1 < tetraPoints.Length - 1 ? from1 + 1 : 0;
                int from3 = i < tetraPoints.Length - 1 ? 3 : from2 + 1;
                var p0    = tetraPoints[to];
                var p1    = tetraPoints[from1];
                var p2    = tetraPoints[from2];
                var p3    = tetraPoints[from3];

                var cen = (p1 + p2 + p3) / 3;

                var d1 = cen - p1;
                var d2 = cen - p2;
                var d3 = cen - p3;
                elements.ConstructionPoints.Add(offsetParameter * d1 + cen);
                elements.ConstructionPoints.Add(offsetParameter * d2 + cen);
                elements.ConstructionPoints.Add(offsetParameter * d3 + cen);
            }

            int index = 0;

            for (int i = 0; i < elements.ConstructionPoints.Count; i++)
            {
                elements.ConstructionPoints[i] = TensegrityUtil.CleanUp(elements.ConstructionPoints[i]);
                var p  = elements.ConstructionPoints[i];
                var ep = Instantiate(prefabs.m_PointPrefab, transform);
                ep.transform.localPosition = p;
                ep.transform.localScale    = Vector3.one * param.PointSize;
                ep.name  = "endpoint_" + index;
                ep.index = index;
                if (ep.GetComponentInChildren <Text>())
                {
                    ep.GetComponentInChildren <Text>().text = $"{index}";
                }
                ep.UpdatePosition();
                elements.EndPoints.Add(ep);
                index++;
            }
            elements.center = Instantiate(prefabs.m_Center, transform);
            elements.center.defaultPosition = transform.position;
            elements.center.UpdateCenter(this);
        }
Example #3
0
        public void AttatchToBar(RigidElement bar, EndPointType pointType)
        {
            AttatchedBar            = bar;
            transform.parent        = bar.transform;
            transform.localPosition = TensegrityUtil.CleanUp(transform.localPosition);
            type = pointType;

            switch (pointType)
            {
            case EndPointType.IsStart:

                transform.localRotation = Quaternion.Euler(-90f, 0, 0);
                bar.startPoint          = this;
                break;

            case EndPointType.IsEnd:
                transform.localRotation = Quaternion.Euler(90f, 0, 0);
                bar.endPoint            = this;
                break;
            }
        }
Example #4
0
        public override void SetupPoints()
        {
            if (tetraPoints == null || tetraPoints.Length == 0)
            {
                tetraPoints = TensegrityUtil.GetTetraPoints(radius);
            }

            /// <summary>
            ///  choose the type!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            /// </summary>
            /// <param name="v0"></param>
            /// <param name="v1"></param>
            /// <param name="v2"></param>
            /// <returns></returns>
            SetPointsByType();
            int index = 0;

            for (int i = 0; i < elements.ConstructionPoints.Count; i++)
            {
                elements.ConstructionPoints[i] = TensegrityUtil.CleanUp(elements.ConstructionPoints[i]);
                var p  = elements.ConstructionPoints[i];
                var ep = Instantiate(prefabs.m_PointPrefab, transform);
                ep.transform.localPosition = p;
                ep.transform.localScale    = Vector3.one * param.PointSize;
                ep.name  = "endpoint_" + index;
                ep.index = index;
                if (ep.GetComponentInChildren <Text>())
                {
                    ep.GetComponentInChildren <Text>().text = $"{index}";
                }
                ep.UpdatePosition();
                elements.EndPoints.Add(ep);
                index++;
            }
            elements.center = Instantiate(prefabs.m_Center, transform);
            elements.center.defaultPosition = transform.position;
            elements.center.UpdateCenter(this);
        }
        public override void SetupPoints()
        {
            SetTetraFrame();
            for (int n = 0; n < NonlinearTetra.Count; n++)
            {
                if (n == 0 || n == 2 || n == 4)
                {
                    for (int i = 0; i < NonlinearTetra[n].Length; i++)
                    {
                        int to    = i;
                        int from1 = i + 1 < NonlinearTetra[n].Length - 1 ? i + 1 : 0;
                        int from2 = from1 + 1 < NonlinearTetra[n].Length - 1 ? from1 + 1 : 0;
                        int from3 = i < NonlinearTetra[n].Length - 1 ? 3 : from2 + 1;
                        var p0    = NonlinearTetra[n][to];
                        var p1    = NonlinearTetra[n][from1];
                        var p2    = NonlinearTetra[n][from2];
                        var p3    = NonlinearTetra[n][from3];

                        var d1 = p0 - p1;
                        var d2 = p0 - p2;
                        var d3 = p0 - p3;
                        elements.ConstructionPoints.Add(offsetParameter * d1 + p1);
                        elements.ConstructionPoints.Add(offsetParameter * d2 + p2);
                        elements.ConstructionPoints.Add(offsetParameter * d3 + p3);
                    }
                    int index = 0;
                    for (int i = elements.ConstructionPoints.Count - 12; i < elements.ConstructionPoints.Count; i++)
                    {
                        elements.ConstructionPoints[i] = TensegrityUtil.CleanUp(elements.ConstructionPoints[i]);
                        var p  = elements.ConstructionPoints[i];
                        var ep = Instantiate(prefabs.m_PointPrefab, transform);
                        ep.transform.localPosition = p;
                        ep.transform.localScale    = Vector3.one * param.PointSize * 30;
                        ep.name  = "endpoint_" + n + "_" + index;
                        ep.index = index;
                        if (ep.GetComponentInChildren <Text>())
                        {
                            ep.GetComponentInChildren <Text>().text = $"{index}";
                        }
                        ep.UpdatePosition();
                        elements.EndPoints.Add(ep);
                        index++;
                    }
                    elements.center = Instantiate(prefabs.m_Center, transform);
                    elements.center.defaultPosition = transform.position;
                    elements.center.UpdateCenter(this);
                }
                if (n == 1 || n == 3)
                {
                    for (int i = 0; i < NonlinearTetra[n].Length; i++)
                    {
                        int to    = i;
                        int from1 = i + 1 < NonlinearTetra[n].Length - 1 ? i + 1 : 0;
                        int from2 = from1 + 1 < NonlinearTetra[n].Length - 1 ? from1 + 1 : 0;
                        int from3 = i < NonlinearTetra[n].Length - 1 ? 3 : from2 + 1;
                        var p0    = NonlinearTetra[n][to];
                        var p1    = NonlinearTetra[n][from1];
                        var p2    = NonlinearTetra[n][from2];
                        var p3    = NonlinearTetra[n][from3];
                        var cen   = (p1 + p2 + p3) / 3;
                        var d1    = cen - p1;
                        var d2    = cen - p2;
                        var d3    = cen - p3;
                        elements.ConstructionPoints.Add((1f - offsetParameter) * d1 + cen);
                        elements.ConstructionPoints.Add((1f - offsetParameter) * d2 + cen);
                        elements.ConstructionPoints.Add((1f - offsetParameter) * d3 + cen);
                    }
                    int index = 0;
                    for (int i = elements.ConstructionPoints.Count - 12; i < elements.ConstructionPoints.Count; i++)
                    {
                        elements.ConstructionPoints[i] = TensegrityUtil.CleanUp(elements.ConstructionPoints[i]);
                        var p  = elements.ConstructionPoints[i];
                        var ep = Instantiate(prefabs.m_PointPrefab, transform);
                        ep.transform.localPosition = p;
                        ep.transform.localScale    = Vector3.one * param.PointSize * 30;
                        ep.name  = "endpoint_" + n + "_" + index;
                        ep.index = index;
                        if (ep.GetComponentInChildren <Text>())
                        {
                            ep.GetComponentInChildren <Text>().text = $"{index}";
                        }
                        ep.UpdatePosition();
                        elements.EndPoints.Add(ep);
                        index++;
                    }
                    elements.center = Instantiate(prefabs.m_Center, transform);
                    elements.center.defaultPosition = transform.position;
                    elements.center.UpdateCenter(this);
                }
            }

            #region connect
            //1
            StringPointsFrom[0] = elements.EndPoints[21];
            StringPointsFrom[2] = elements.EndPoints[22];
            StringPointsFrom[4] = elements.EndPoints[23];

            StringPointsFrom[6]  = elements.EndPoints[15];
            StringPointsFrom[8]  = elements.EndPoints[16];
            StringPointsFrom[10] = elements.EndPoints[17];

            StringPointsFrom[12] = elements.EndPoints[45];
            StringPointsFrom[14] = elements.EndPoints[46];
            StringPointsFrom[16] = elements.EndPoints[47];

            StringPointsFrom[18] = elements.EndPoints[39];
            StringPointsFrom[20] = elements.EndPoints[40];
            StringPointsFrom[22] = elements.EndPoints[41];


            //no.2
            StringPointsFrom[1] = elements.EndPoints[14];
            StringPointsFrom[3] = elements.EndPoints[17];
            StringPointsFrom[5] = elements.EndPoints[20];

            StringPointsFrom[7]  = elements.EndPoints[12];
            StringPointsFrom[9]  = elements.EndPoints[19];
            StringPointsFrom[11] = elements.EndPoints[22];

            StringPointsFrom[13] = elements.EndPoints[38];
            StringPointsFrom[15] = elements.EndPoints[41];
            StringPointsFrom[17] = elements.EndPoints[44];

            StringPointsFrom[19] = elements.EndPoints[36];
            StringPointsFrom[21] = elements.EndPoints[43];
            StringPointsFrom[23] = elements.EndPoints[46];


            for (int i = 0; i < 24; i++)
            {
                elements.EndPoints.Add(StringPointsFrom[i]);
            }


            StringPointsTo[0] = elements.EndPoints[11];
            StringPointsTo[1] = elements.EndPoints[8];
            StringPointsTo[2] = elements.EndPoints[10];
            StringPointsTo[3] = elements.EndPoints[5];
            StringPointsTo[4] = elements.EndPoints[7];
            StringPointsTo[5] = elements.EndPoints[3];

            StringPointsTo[6]  = elements.EndPoints[25];
            StringPointsTo[7]  = elements.EndPoints[30];
            StringPointsTo[8]  = elements.EndPoints[27];
            StringPointsTo[9]  = elements.EndPoints[31];
            StringPointsTo[10] = elements.EndPoints[28];
            StringPointsTo[11] = elements.EndPoints[24];

            StringPointsTo[12] = elements.EndPoints[35];
            StringPointsTo[13] = elements.EndPoints[32];
            StringPointsTo[14] = elements.EndPoints[29];
            StringPointsTo[15] = elements.EndPoints[34];
            StringPointsTo[16] = elements.EndPoints[27];
            StringPointsTo[17] = elements.EndPoints[31];

            StringPointsTo[18] = elements.EndPoints[49];
            StringPointsTo[19] = elements.EndPoints[54];
            StringPointsTo[20] = elements.EndPoints[55];
            StringPointsTo[21] = elements.EndPoints[51];
            StringPointsTo[22] = elements.EndPoints[48];
            StringPointsTo[23] = elements.EndPoints[52];



            for (int i = 0; i < 24; i++)
            {
                elements.EndPoints.Add(StringPointsTo[i]);
            }

            #endregion
        }
        public override void SetupPoints()
        {
            if (tetraPoints == null || tetraPoints.Length == 0)
            {
                tetraPoints = TensegrityUtil.GetTetraPoints(radius);
            }

            Vector3[] PointsContainer = new Vector3[8];
            var       t0 = tetraPoints[0];
            var       t1 = tetraPoints[1];
            var       t2 = tetraPoints[2];
            var       t3 = tetraPoints[3];
            //print(tetraPoints.Length);
            var p4 = new Vector3();
            var p5 = new Vector3();
            var p6 = new Vector3();
            var p7 = new Vector3();

            for (int i = 0; i < tetraPoints.Length; i++)
            {
                PointsContainer[0] = (t0 - t1 + t2 - t1) * 0.5f * 0.25f + t1;
                PointsContainer[1] = (t1 - t0 + t3 - t0) * 0.5f * 0.25f + t0;
                PointsContainer[2] = (t0 - t3 + t2 - t3) * 0.5f * 0.25f + t3;
                PointsContainer[3] = (t1 - t2 + t3 - t2) * 0.5f * 0.25f + t2;

                p4 = (t1 - t2 + t3 - t2) * 0.5f * 0.75f + t2;
                p5 = (t1 - t0 + t3 - t0) * 0.5f * 0.75f + t0;
                p6 = (t0 - t1 + t2 - t1) * 0.5f * 0.75f + t1;
                p7 = (t0 - t3 + t2 - t3) * 0.5f * 0.75f + t3;

                PointsContainer[4] = p4 + (p4 - p6) * 0.5f;
                PointsContainer[5] = p5 + (p5 - p7) * 0.5f;
                PointsContainer[6] = p6 + (p6 - p4) * 0.5f;
                PointsContainer[7] = p7 + (p7 - p5) * 0.5f;
            }

            for (int i = 0; i < PointsContainer.Length; i++)
            {
                elements.ConstructionPoints.Add(PointsContainer[i]);
            }

            int index = 0;

            for (int i = 0; i < elements.ConstructionPoints.Count; i++)
            {
                elements.ConstructionPoints[i] = TensegrityUtil.CleanUp(elements.ConstructionPoints[i]);
                var p  = elements.ConstructionPoints[i];
                var ep = Instantiate(prefabs.m_PointPrefab, transform);
                ep.transform.localPosition = p;
                ep.transform.localScale    = Vector3.one * param.PointSize;
                ep.name  = "endpoint_" + index;
                ep.index = index;
                if (ep.GetComponentInChildren <Text>())
                {
                    ep.GetComponentInChildren <Text>().text = $"{index}";
                }
                ep.UpdatePosition();
                elements.EndPoints.Add(ep);
                index++;
            }
            elements.center = Instantiate(prefabs.m_Center, transform);
            elements.center.defaultPosition = transform.position;
            elements.center.UpdateCenter(this);
        }
Example #7
0
        public override void SetupPoints()
        {
            if (tetraPoints == null || tetraPoints.Length == 0)
            {
                tetraPoints = TensegrityUtil.GetTetraPoints(radius);
            }

            List <Vector3> PointsContainer = new List <Vector3>();
            var            p1 = new Vector3();
            var            p2 = new Vector3();
            var            p3 = new Vector3();

            print(tetraPoints.Length);


            for (int i = 0; i < tetraPoints.Length; i++)
            {
                var cenPoint = new Vector3();

                if (i + 1 < 3)
                {
                    cenPoint = (tetraPoints[i] + tetraPoints[i + 1] + tetraPoints[i + 2]) / 3.0f;
                    p1       = -(tetraPoints[i] - cenPoint) * offsetParameter;
                    p2       = -(tetraPoints[i + 1] - cenPoint) * offsetParameter;
                    p3       = -(tetraPoints[i + 2] - cenPoint) * offsetParameter;
                }
                else if (i + 1 == 3)
                {
                    cenPoint = (tetraPoints[i] + tetraPoints[i + 1] + tetraPoints[i - 2]) / 3.0f;
                    p1       = -(tetraPoints[i] - cenPoint) * offsetParameter;
                    p2       = -(tetraPoints[i + 1] - cenPoint) * offsetParameter;
                    p3       = -(tetraPoints[i - 2] - cenPoint) * offsetParameter;
                }
                else if (i + 1 > 3)
                {
                    cenPoint = (tetraPoints[i] + tetraPoints[i - 2] + tetraPoints[i - 3]) / 3.0f;
                    p1       = -(tetraPoints[i] - cenPoint) * offsetParameter;
                    p2       = -(tetraPoints[i - 3] - cenPoint) * offsetParameter;
                    p3       = -(tetraPoints[i - 2] - cenPoint) * offsetParameter;
                }
                PointsContainer.Add(p1);
                PointsContainer.Add(p2);
                PointsContainer.Add(p3);
            }

            //int no = 0;
            //foreach (var pc in PointsContainer)
            //{
            //    GameObject poingt = Instantiate(GameObject.CreatePrimitive(PrimitiveType.Sphere), pc, Quaternion.identity);
            //    poingt.name = "no." + no;
            //    no++;
            //}
            elements.ConstructionPoints.Add(PointsContainer[9]);
            elements.ConstructionPoints.Add(PointsContainer[7]);
            elements.ConstructionPoints.Add(PointsContainer[5]);
            elements.ConstructionPoints.Add(PointsContainer[6]);
            elements.ConstructionPoints.Add(PointsContainer[2]);
            elements.ConstructionPoints.Add(PointsContainer[4]);
            elements.ConstructionPoints.Add(PointsContainer[1]);
            elements.ConstructionPoints.Add(PointsContainer[11]);
            elements.ConstructionPoints.Add(PointsContainer[3]);
            elements.ConstructionPoints.Add(PointsContainer[0]);
            elements.ConstructionPoints.Add(PointsContainer[10]);
            elements.ConstructionPoints.Add(PointsContainer[8]);

            int index = 0;

            for (int i = 0; i < elements.ConstructionPoints.Count; i++)
            {
                elements.ConstructionPoints[i] = TensegrityUtil.CleanUp(elements.ConstructionPoints[i]);
                var p  = elements.ConstructionPoints[i];
                var ep = Instantiate(prefabs.m_PointPrefab, transform);
                ep.transform.localPosition = p;
                ep.transform.localScale    = Vector3.one * param.PointSize;
                ep.name  = "endpoint_" + index;
                ep.index = index;
                if (ep.GetComponentInChildren <Text>())
                {
                    ep.GetComponentInChildren <Text>().text = $"{index}";
                }
                ep.UpdatePosition();
                elements.EndPoints.Add(ep);
                index++;
            }
            elements.center = Instantiate(prefabs.m_Center, transform);
            elements.center.defaultPosition = transform.position;
            elements.center.UpdateCenter(this);
        }