Exemplo n.º 1
0
        //====================================================================================================
        // ■ CREATE MESH
        //====================================================================================================
        void CreateMesh()
        {
            if (ExplosionMesh == null)
            {
                ExplosionMesh = new MESH();
            }
            else
            {
                ExplosionMesh.Clear();
            }

            var vertexArray = new float3[PointCount * 2];
            var indexArray  = new int[(PointCount + 1) * 6];

            //Vertex
            for (int i = 0; i < PointCount; i++)
            {
                var p1 = ExplosionSize * PointArray[i];
                p1.z = PlanetRadius;
                p1   = math.normalize(p1) * PlanetRadius;

                var p2 = ExplosionSize * (1 + ExplosionWidth) * PointArray[i];
                p2.z = PlanetRadius;
                p2   = math.normalize(p2) * PlanetRadius;

                vertexArray[2 * i + 0] = p1;
                vertexArray[2 * i + 1] = p2;
            }

            //Index
            for (int i = 0; i < PointCount; i++)
            {
                var p0 = i * 2 + 0;
                var p1 = i * 2 + 1;

                var p2 = ((i + 1) % PointCount) * 2 + 0;
                var p3 = ((i + 1) % PointCount) * 2 + 1;

                indexArray[i * 6 + 0] = p0;
                indexArray[i * 6 + 1] = p1;
                indexArray[i * 6 + 2] = p3;
                indexArray[i * 6 + 3] = p3;
                indexArray[i * 6 + 4] = p2;
                indexArray[i * 6 + 5] = p0;
            }

            ExplosionMesh.vertices = vertexArray;
            ExplosionMesh.SetTriangleIndices(indexArray);

            GameObject.MeshFilter.sharedMesh = ExplosionMesh;
        }
Exemplo n.º 2
0
        //====================================================================================================
        // ■ CREATE MESH
        //====================================================================================================
        void CreateMesh()
        {
            if (PointList.Count >= 2)
            {
                if (WallMesh == null)
                {
                    WallMesh = new MESH();
                }
                else
                {
                    WallMesh.Clear();
                }

                int count = PointList.Count;

                var vertexArray = new float3[count * 4];
                var indexArray  = new int[(count - 1) * 18 + 12];

                //Vertex
                for (int i = 0; i < count; i++)
                {
                    var    p = PointList[i];
                    float3 tangent;

                    if (i - 1 >= 0)
                    {
                        var t = PointList[i - 1].Position;
                        tangent = math.normalize(p.Position - t);
                    }
                    else
                    {
                        var t = PointList[i + 1].Position;
                        tangent = math.normalize(t - p.Position);
                    }

                    var center = math.normalize(p.Position);

                    var normal = math.normalize(math.cross(tangent, center));

                    var gridPosition = p.Position - center * GridDistance;

                    vertexArray[4 * i + 0] = gridPosition - normal * WallWidth;
                    vertexArray[4 * i + 1] = gridPosition + center * WallHeight - normal * WallWidth;
                    vertexArray[4 * i + 2] = gridPosition + center * WallHeight + normal * WallWidth;
                    vertexArray[4 * i + 3] = gridPosition + normal * WallWidth;
                }

                //Index
                for (int i = 0; i < count - 1; i++)
                {
                    var p0 = i * 4 + 0;
                    var p1 = i * 4 + 1;
                    var p2 = i * 4 + 2;
                    var p3 = i * 4 + 3;

                    var p4 = (i + 1) * 4 + 0;
                    var p5 = (i + 1) * 4 + 1;
                    var p6 = (i + 1) * 4 + 2;
                    var p7 = (i + 1) * 4 + 3;

                    indexArray[i * 18 + 0] = p4;
                    indexArray[i * 18 + 1] = p5;
                    indexArray[i * 18 + 2] = p1;
                    indexArray[i * 18 + 3] = p1;
                    indexArray[i * 18 + 4] = p0;
                    indexArray[i * 18 + 5] = p4;

                    indexArray[i * 18 + 6]  = p1;
                    indexArray[i * 18 + 7]  = p5;
                    indexArray[i * 18 + 8]  = p6;
                    indexArray[i * 18 + 9]  = p6;
                    indexArray[i * 18 + 10] = p2;
                    indexArray[i * 18 + 11] = p1;

                    indexArray[i * 18 + 12] = p3;
                    indexArray[i * 18 + 13] = p2;
                    indexArray[i * 18 + 14] = p6;
                    indexArray[i * 18 + 15] = p6;
                    indexArray[i * 18 + 16] = p7;
                    indexArray[i * 18 + 17] = p3;
                }

                //begin, end close
                var v0 = 0 * 4 + 0;
                var v1 = 0 * 4 + 1;
                var v2 = 0 * 4 + 2;
                var v3 = 0 * 4 + 3;

                var v4 = (count - 1) * 4 + 0;
                var v5 = (count - 1) * 4 + 1;
                var v6 = (count - 1) * 4 + 2;
                var v7 = (count - 1) * 4 + 3;

                int j = count - 1;
                indexArray[j * 18 + 0] = v0;
                indexArray[j * 18 + 1] = v1;
                indexArray[j * 18 + 2] = v2;
                indexArray[j * 18 + 3] = v2;
                indexArray[j * 18 + 4] = v3;
                indexArray[j * 18 + 5] = v0;

                indexArray[j * 18 + 6]  = v7;
                indexArray[j * 18 + 7]  = v6;
                indexArray[j * 18 + 8]  = v5;
                indexArray[j * 18 + 9]  = v5;
                indexArray[j * 18 + 10] = v4;
                indexArray[j * 18 + 11] = v7;

                WallMesh.vertices = vertexArray;
                WallMesh.SetTriangleIndices(indexArray);

                GameObject.MeshFilter.sharedMesh = WallMesh;
            }
        }