Esempio n. 1
0
        protected override void OnPopulateMesh(Mesh m)
        {
            if (mMesh == null)
            {
                mMesh = new WorldSpaceChartMesh(1);
            }
            else
            {
                mMesh.Clear();
            }
            int vPos = 0;

            mMinModifyIndex = 0; // not supported here
            foreach (UIVertex v in getVerices())
            {
                mTmpVerts[vPos++] = v;
                if (vPos == 4)
                {
                    vPos = 0;
                    mMesh.AddQuad(mTmpVerts[0], mTmpVerts[1], mTmpVerts[2], mTmpVerts[3]);
                }
            }

            mMesh.ApplyToMesh(m);
        }
        public void Generate(Vector3[] path, float radius, float curve)
        {
            if (EnsureMeshFilter() == false)    // No mesh filter attached
            {
                return;
            }

            mPath     = path;
            mPathRect = new Rect(-radius, -radius, radius * 2f, radius * 2f);
            mCurve    = curve;
            WorldSpaceChartMesh mesh = new WorldSpaceChartMesh(1);
            int origin = 0;

            foreach (UIVertex v in getVerices())
            {
                origin = mesh.AddVertex(v);
            }

            for (int i = 0; i < mPath.Length; i++)
            {
                int prev = i - 1;
                if (prev < 0)
                {
                    prev = mPath.Length - 1;
                }
                mesh.AddTringle(origin, i * Smoothing, prev * Smoothing);
            }

            for (int j = 1; j < Smoothing; j++)
            {
                int current = j;
                int prev    = j - 1;
                for (int i = 0; i < mPath.Length; i++)
                {
                    int prevI = i - 1;
                    if (prevI < 0)
                    {
                        prevI = mPath.Length - 1;
                    }
                    int a = (i * Smoothing) + current;
                    int b = (i * Smoothing) + prev;
                    int c = (prevI * Smoothing) + current;
                    int d = (prevI * Smoothing) + prev;
                    mesh.AddTringle(c, b, a);
                    mesh.AddTringle(b, c, d);
                }
            }

            Mesh newMesh = mesh.Generate();

            newMesh.hideFlags = HideFlags.DontSave;
            newMesh.RecalculateNormals();

            mFilter.sharedMesh = newMesh;
            ChartCommon.CleanMesh(newMesh, ref mCleanMesh);
        }
#pragma warning disable 0672
#if !UNITY_2017_1_OR_NEWER
        protected override void OnPopulateMesh(Mesh m)
        {
            m.Clear();
            if (mPopulated == false)
            {
                return;
            }
            WorldSpaceChartMesh chartmesh = new WorldSpaceChartMesh(true);

            FillChartMesh(chartmesh);
            chartmesh.ApplyToMesh(m);
        }
Esempio n. 4
0
#pragma warning disable 0672

        protected override void OnPopulateMesh(Mesh m)
        {
            WorldSpaceChartMesh mesh = new WorldSpaceChartMesh(1);
            int vPos = 0;

            foreach (UIVertex v in getVerices())
            {
                mTmpVerts[vPos++] = v;
                if (vPos == 4)
                {
                    vPos = 0;

                    mesh.AddQuad(mTmpVerts[0], mTmpVerts[1], mTmpVerts[2], mTmpVerts[3]);
                }
            }
            mesh.ApplyToMesh(m);
        }
        public void Generate(float startAngle, float angleSpan, float radius, float innerRadius, int segments, float outerDepth, float innerDepth)
        {
            WorldSpaceChartMesh mesh = new WorldSpaceChartMesh(1);
            float maxDepth           = Mathf.Max(outerDepth, innerDepth);

            if (maxDepth <= 0f)
            {
                PieMesh.Generate2dMesh(mesh, startAngle, angleSpan, radius, innerRadius, segments);
            }
            else
            {
                PieMesh.Generate3dMesh(mesh, startAngle, angleSpan, radius, innerRadius, segments, outerDepth, innerDepth);
            }

            if (mCleanMesh != null)
            {
                mCleanMesh.Clear();
                mesh.ApplyToMesh(mCleanMesh);
                MeshCollider collider = ChartCommon.EnsureComponent <MeshCollider>(gameObject);
                if (collider != null)
                {
                    collider.sharedMesh = null;
                    collider.sharedMesh = mCleanMesh;
                }
            }
            else
            {
                Mesh newMesh = mesh.Generate();
                newMesh.hideFlags = HideFlags.DontSave;
                if (mFilter == null)
                {
                    mFilter = GetComponent <MeshFilter>();
                }
                mFilter.sharedMesh = newMesh;
                MeshCollider collider = ChartCommon.EnsureComponent <MeshCollider>(gameObject);
                if (collider != null)
                {
                    collider.sharedMesh = newMesh;
                }
                ChartCommon.CleanMesh(newMesh, ref mCleanMesh);
            }
        }
Esempio n. 6
0
#pragma warning disable 0672
#if !UNITY_2017_1_OR_NEWER
        protected override void OnPopulateMesh(Mesh m)
        {
            if (mPath == null)
            {
                m.Clear();
                return;
            }
            WorldSpaceChartMesh mesh = new WorldSpaceChartMesh(1);

            foreach (UIVertex v in getVerices())
            {
                mesh.AddVertex(v);
            }
            for (int i = 0; i < mPath.Length; i++)
            {
                int prev = i - 1;
                if (prev < 0)
                {
                    prev = mPath.Length - 1;
                }
                mesh.AddTringle(prev, i, mPath.Length);
            }
            mesh.ApplyToMesh(m);
        }
Esempio n. 7
0
        public static void Generate3dMesh(WorldSpaceChartMesh mesh, float startAngle, float angleSpan, float radius, float innerRadius, int segments, float outerDepth, float innerDepth)
        {
            float maxDepth = Mathf.Max(outerDepth, innerDepth);
            float bottom   = maxDepth * 0.5f;
            float innerUp  = bottom - innerDepth;
            float outerUp  = bottom - outerDepth;
            //float halfDepth = maxDepth * 0.5f;
            float segmentAngle = angleSpan / segments;
            float currentAngle = startAngle;
            float segmenUv     = 1f / segments;
            float currentUv    = 0f;
            float cos          = Mathf.Cos(currentAngle);
            float sin          = Mathf.Sin(currentAngle);

            UIVertex innerV = ChartCommon.CreateVertex(new Vector3(cos * innerRadius, sin * innerRadius, innerUp), new Vector2(currentUv, 0f));
            UIVertex outerV = ChartCommon.CreateVertex(new Vector3(cos * radius, sin * radius, outerUp), new Vector2(currentUv, 1f));

            int currentInner      = mesh.AddVertex(innerV);
            int currentOuter      = mesh.AddVertex(outerV);
            int prevInnerVertex   = mesh.AddVertex(innerV);
            int prevOuterVertex   = mesh.AddVertex(outerV);
            int prevOpeningVertex = mesh.AddVertex(innerV);
            int prevClosingVertex = mesh.AddVertex(outerV);

            innerV.position.z = bottom;
            outerV.position.z = bottom;

            int currentInnerDeep    = mesh.AddVertex(innerV);
            int currentOuterDeep    = mesh.AddVertex(outerV);
            int prevInnerVertexDeep = mesh.AddVertex(innerV);
            int prevOuterVertexDeep = mesh.AddVertex(outerV);

            mesh.AddTringle(currentInner, currentOuter, currentOuterDeep);
            mesh.AddTringle(currentOuterDeep, currentInnerDeep, currentInner);

            int prevOpeningVertexDeep = mesh.AddVertex(innerV);
            int prevClosingVertexDeep = mesh.AddVertex(outerV);

            for (int i = 1; i <= segments; i++)
            {
                currentUv    += segmenUv;
                currentAngle += segmentAngle;
                cos           = Mathf.Cos(currentAngle);
                sin           = Mathf.Sin(currentAngle);

                UIVertex innerVertex = ChartCommon.CreateVertex(new Vector3(cos * innerRadius, sin * innerRadius, innerUp), new Vector2(currentUv, 0f));
                UIVertex outerVertex = ChartCommon.CreateVertex(new Vector3(cos * radius, sin * radius, outerUp), new Vector2(currentUv, 1f));

                int leftBottom       = -1;
                int rightBottomAdded = -1;
                if (innerRadius > 0f)
                {
                    rightBottomAdded = mesh.AddVertex(innerVertex);
                    leftBottom       = prevInnerVertex;
                }

                int leftTop       = prevOuterVertex;
                int rightTop      = mesh.AddVertex(outerVertex);
                int rightBottom   = mesh.AddVertex(innerVertex);
                int rightTopAdded = mesh.AddVertex(outerVertex);

                innerVertex.position.z = bottom;
                outerVertex.position.z = bottom;

                int leftBottomDeep = -1;
                if (innerRadius > 0f)
                {
                    leftBottomDeep = prevInnerVertexDeep;
                }

                int leftTopDeep       = prevOuterVertexDeep;
                int rightTopDeep      = mesh.AddVertex(outerVertex);
                int rightBottomDeep   = mesh.AddVertex(innerVertex);
                int rightTopAddedDeep = mesh.AddVertex(outerVertex);

                mesh.AddTringle(rightBottom, rightTop, leftTop);
                mesh.AddTringle(leftTopDeep, rightTopDeep, rightBottomDeep);

                mesh.AddTringle(prevClosingVertexDeep, prevClosingVertex, rightTopAdded);
                mesh.AddTringle(rightTopAdded, rightTopAddedDeep, prevClosingVertexDeep);

                prevClosingVertex     = rightTopAdded;
                prevClosingVertexDeep = rightTopAddedDeep;

                if (innerRadius > 0f)
                {
                    int rightBottomAddedDeep = mesh.AddVertex(innerVertex);
                    mesh.AddTringle(leftTop, leftBottom, rightBottom);
                    mesh.AddTringle(rightBottomDeep, leftBottomDeep, leftTopDeep);

                    mesh.AddTringle(rightBottomAdded, prevOpeningVertex, prevOpeningVertexDeep);
                    mesh.AddTringle(prevOpeningVertexDeep, rightBottomAddedDeep, rightBottomAdded);
                    prevOpeningVertexDeep = rightBottomAddedDeep;
                    prevOpeningVertex     = rightBottomAdded;
                }
                prevInnerVertex     = rightBottom;
                prevOuterVertex     = rightTop;
                prevInnerVertexDeep = rightBottomDeep;
                prevOuterVertexDeep = rightTopDeep;

                if (i == segments)
                {
                    rightTopDeep           = mesh.AddVertex(outerVertex);
                    rightBottomDeep        = mesh.AddVertex(innerVertex);
                    innerVertex.position.z = innerUp;
                    outerVertex.position.z = outerUp;
                    rightTop    = mesh.AddVertex(outerVertex);
                    rightBottom = mesh.AddVertex(innerVertex);
                    mesh.AddTringle(rightTopDeep, rightTop, rightBottom);
                    mesh.AddTringle(rightBottom, rightBottomDeep, rightTopDeep);
                }
            }
        }
Esempio n. 8
0
 public void ApplyToMesh(WorldSpaceChartMesh mesh)
 {
 }