Esempio n. 1
0
        private void AddTrianglesToMesh()
        {
            //create cap verticies
            Vector3 normal         = Quaternion.Inverse(_ownRotation) * _splitPlane.Normal;
            Vector3 invNormal      = -normal;
            int     capVertexCount = triList.Count;

            int[] capUpperOrder = new int[capVertexCount];
            int[] capLowerOrder = new int[capVertexCount];

            if (UseCapUV)
            {
                for (int i = 0; i < capVertexCount; i++)
                {
                    int     triIndex = triList[i];
                    Vector2 capUV    = uvList[i];
                    capUpperOrder[i] = _mesh.AddCapVertex(triIndex, invNormal, capUV);
                    capLowerOrder[i] = _mesh.AddCapVertex(triIndex, normal, capUV);
                }
            }
            else
            {
                for (int i = 0; i < capVertexCount; i++)
                {
                    int triIndex = triList[i];
                    capUpperOrder[i] = _mesh.AddCapVertex(triIndex, invNormal);
                    capLowerOrder[i] = _mesh.AddCapVertex(triIndex, normal);
                }
            }

            for (int i = 2; i < capVertexCount; i += 3)
            {
                _mesh.trisUp.Add(capUpperOrder[i - 2]);
                _mesh.trisUp.Add(capUpperOrder[i]);
                _mesh.trisUp.Add(capUpperOrder[i - 1]);

                _mesh.trisDown.Add(capLowerOrder[i - 2]);
                _mesh.trisDown.Add(capLowerOrder[i - 1]);
                _mesh.trisDown.Add(capLowerOrder[i]);
            }
        }
Esempio n. 2
0
        public void MeshCreateCaps(bool split)
        {
            if (capInds.Count == 0)
            {
                return;
            }

            CreateCap();

            int newCapCount = capsSorted.Length;

            if (CustomUV)
            {
                float offX = CapUVMin.x, offY = CapUVMin.y;
                float dX = CapUVMax.x - CapUVMin.x, dY = CapUVMax.y - CapUVMin.y;
                for (int i = 0; i < newCapCount; i++)
                {
                    capsUV[i].x = (capsUV[i].x * dX) + offX;
                    capsUV[i].y = (capsUV[i].y * dY) + offY;
                }
            }

            //create cap verticies
            Vector3 normal    = Quaternion.Inverse(_ownRotation) * _splitPlane.Normal;
            Vector3 invNormal = -normal;

            int[] capUpperOrder = new int[capsSorted.Length];
            int[] capLowerOrder = new int[capsSorted.Length];
            if (UseCapUV)
            {
                for (int i = 0; i < newCapCount; i++)
                {
                    capUpperOrder[i] = _mesh.AddCapVertex(capsSorted[i], invNormal, capsUV[i]);
                    capLowerOrder[i] = _mesh.AddCapVertex(capsSorted[i], normal, capsUV[i]);
                }
            }
            else
            {
                for (int i = 0; i < newCapCount; i++)
                {
                    capUpperOrder[i] = _mesh.AddCapVertex(capsSorted[i], invNormal);
                    capLowerOrder[i] = _mesh.AddCapVertex(capsSorted[i], normal);
                }
            }

            int capOderCount = capUpperOrder.Length;

            for (int i = 2; i < capOderCount; i++)
            {
                if (split)
                {
                    _mesh.capUp.Add(capUpperOrder[0]);
                    _mesh.capUp.Add(capUpperOrder[i - 1]);
                    _mesh.capUp.Add(capUpperOrder[i]);

                    _mesh.capDown.Add(capLowerOrder[0]);
                    _mesh.capDown.Add(capLowerOrder[i]);
                    _mesh.capDown.Add(capLowerOrder[i - 1]);
                }
                else
                {
                    _mesh.trisUp.Add(capUpperOrder[0]);
                    _mesh.trisUp.Add(capUpperOrder[i - 1]);
                    _mesh.trisUp.Add(capUpperOrder[i]);

                    _mesh.trisDown.Add(capLowerOrder[0]);
                    _mesh.trisDown.Add(capLowerOrder[i]);
                    _mesh.trisDown.Add(capLowerOrder[i - 1]);
                }
            }

#if UNITY_EDITOR
            // debug draw
            if (ShowDebug)
            {
                for (int i = 2; i < capUpperOrder.Length; i++)
                {
                    Debug.DrawLine(GetVertPos(capUpperOrder[0]), GetVertPos(capUpperOrder[i - 1]), Color.yellow, 2f);
                    Debug.DrawLine(GetVertPos(capUpperOrder[i - 1]), GetVertPos(capUpperOrder[i]), Color.yellow, 2f);
                    Debug.DrawLine(GetVertPos(capUpperOrder[i]), GetVertPos(capUpperOrder[0]), Color.yellow, 2f);
                }
            }
#endif
        }