Exemplo n.º 1
0
        void CreateInner()
        {
            using (var vh = new VertexHelper()) {
                int   numTris     = Mathf.CeilToInt(diameter * Mathf.PI / MAX_FRAGMENT_LENGTH);
                float centerAngle = 2 * Mathf.PI / numTris;
                Color c           = Color.white;

                // create verticies
                vh.AddVert(Vector3.zero, c, Vector2.zero); // midpoint
                for (int i = 0; i < numTris; i++)
                {
                    float angle = centerAngle * i;
                    float x     = Mathf.Cos(angle) * 0.5f;
                    float y     = Mathf.Sin(angle) * 0.5f;
                    vh.AddVert(new Vector3(x, y, 0), c, Vector2.zero);
                }

                // create triangles
                for (int i = 0; i < numTris - 1; i++)
                {
                    vh.AddTriangle(0, i + 2, i + 1);
                }
                // come around
                vh.AddTriangle(0, 1, numTris);
                MeshUtil.UpdateMesh(innerMeshFilter, vh);
            }
        }
Exemplo n.º 2
0
 void CreateSolid()
 {
     Debug.Log("solid line");
     using (var vh = new VertexHelper()) {
         MeshUtil.AddRect(BoundsUtil.UnitBounds, vh);
         MeshUtil.UpdateMesh(GetComponent <MeshFilter>(), vh);
     }
 }
Exemplo n.º 3
0
        void CreateBorderSolid()
        {
            using (var vh = new VertexHelper()) {
                int   numQuads              = Mathf.CeilToInt(diameter * Mathf.PI / MAX_FRAGMENT_LENGTH);
                float centerAngle           = 2 * Mathf.PI / numQuads;
                float scaledBorderThickness = property.border.thickness / property.diameter;
                Color c = Color.white;

                for (int i = 0; i < numQuads; i++)
                {
                    float angle = centerAngle * i;
                    float x     = Mathf.Cos(angle) * 0.5f;
                    float y     = Mathf.Sin(angle) * 0.5f;

                    float scaledInnerRadius = 1; // default = outer

                    switch (property.border.position)
                    {
                    case BorderPosition.Center:
                        scaledInnerRadius -= scaledBorderThickness / 2;
                        break;

                    case BorderPosition.Inside:
                        scaledInnerRadius -= scaledBorderThickness;
                        break;
                    }

                    float scaledOuterRadius = scaledInnerRadius + scaledBorderThickness;

                    vh.AddVert(new Vector3(x * scaledInnerRadius, y * scaledInnerRadius, 0),
                               c, Vector2.zero);

                    vh.AddVert(new Vector3(x * scaledOuterRadius, y * scaledOuterRadius, 0),
                               c, Vector2.zero);
                }

                for (int i = 0; i < numQuads - 1; i++)
                {
                    int idxBase = 2 * i; // two new vertices per quad
                    vh.AddTriangle(idxBase, idxBase + 2, idxBase + 1);
                    vh.AddTriangle(idxBase + 1, idxBase + 2, idxBase + 3);
                }

                int finalIdxBase = 2 * numQuads - 2; // last two vertices
                vh.AddTriangle(finalIdxBase, 0, finalIdxBase + 1);
                vh.AddTriangle(finalIdxBase + 1, 0, 1);

                MeshUtil.UpdateMesh(borderMeshFilter, vh);
            }
        }
Exemplo n.º 4
0
        void CreateDashed()
        {
            float fullSegmentLength = (property.border.dashLength + property.border.gapLength);
            int   numFragments      = Mathf.CeilToInt(property.length / fullSegmentLength);

            if (numFragments > MAX_FRAGMENTS)
            {
                Debug.LogError("Line has too many fragments (" + numFragments + ")");
                return;
            }

            using (var vh = new VertexHelper()) {
                for (int i = 0; i < numFragments; i++)
                {
                    float deltaX = i * fullSegmentLength / property.length;
                    var   min    = new Vector2(-0.5f + deltaX, -0.5f);
                    var   max    = new Vector2(-0.5f + deltaX + property.border.dashLength / property.length, 0.5f);
                    MeshUtil.AddRect(new Bounds().WithMinMax(min, max), vh);
                }
                MeshUtil.UpdateMesh(GetComponent <MeshFilter>(), vh);
            }
        }
Exemplo n.º 5
0
 /***** PRIVATE: RENDERING *****/
 void RemoveBorder()
 {
     using (var vh = new VertexHelper()) {
         MeshUtil.UpdateMesh(borderMeshFilter, vh);
     }
 }