Esempio n. 1
0
 void AddSpan(MeshConstructor mc, MeshVertex[,] mx, int latitudeSpanIndex, int longitudeSpanIndex, int submesh = 0)
 {
     MeshVertex topLeft = mx[latitudeSpanIndex + 1, longitudeSpanIndex];
     MeshVertex topRight = mx[latitudeSpanIndex + 1, longitudeSpanIndex + 1];
     MeshVertex bottomLeft = mx[latitudeSpanIndex, longitudeSpanIndex];
     MeshVertex bottomRight = mx[latitudeSpanIndex, longitudeSpanIndex + 1];
     mc.AddTriangle(topLeft, topRight, bottomLeft, submesh);
     mc.AddTriangle(bottomRight, bottomLeft, topRight, submesh);
 }
Esempio n. 2
0
    Mesh GenerateMesh()
    {
        var mc = new MeshConstructor();
        mc.mesh.name = name;
        mc.SetSubmeshCount(2);

        latitudes = latitudeSpans + 1;
        longitudes = longitudeSpans + 1;
        pictureLatitudeSpans = 2 * halfLatitudePictureSpans;
        pictureLongitudeSpans = 2 * halfLongitudePictureSpans;
        pictureLatitudes = pictureLatitudeSpans + 1;
        pictureLongitudes = pictureLongitudeSpans + 1;

        pictureSpans = new bool[latitudeSpans, longitudeSpans];
        baseMatrix = new MeshVertex[latitudes, longitudes];
        pictureMatrix = new MeshVertex[latitudes, longitudes];

        for (int latitudePictureSpanIndex = 0; latitudePictureSpanIndex < pictureLatitudeSpans; latitudePictureSpanIndex++) {
            for (int longitudePictureSpanIndex = 0; longitudePictureSpanIndex < pictureLongitudeSpans; longitudePictureSpanIndex++) {
                int latitudeSpanIndex = latitudes/2-halfLatitudePictureSpans+latitudePictureSpanIndex;
                int longitudeSpanIndex = Extensions.Modulo(-halfLongitudePictureSpans+longitudePictureSpanIndex, longitudeSpans);
                pictureSpans[latitudeSpanIndex, longitudeSpanIndex] = true;
            }
        }

        for (int latitudeIndex = 0; latitudeIndex <= latitudeSpans; latitudeIndex++) {
            for (int longitudeIndex = 0; longitudeIndex <= longitudeSpans; longitudeIndex++) {
                baseMatrix[latitudeIndex, longitudeIndex] = new MeshVertex(
                    position: getSpherePoint(latitudeIndex, longitudeIndex),
                    uv: new Vector2(1f * longitudeIndex / longitudeSpans, 1f * latitudeIndex / latitudeSpans),
                    normal: getSpherePoint(latitudeIndex, longitudeIndex).normalized
                );
            }
        }

        for (int pictureLatitudeIndex = 0; pictureLatitudeIndex <= 2 * halfLatitudePictureSpans; pictureLatitudeIndex++) {
            for (int pictureLongitudeIndex = 0; pictureLongitudeIndex <= 2 * halfLongitudePictureSpans; pictureLongitudeIndex++) {
                int latitudeIndex = latitudes/2 -halfLatitudePictureSpans + pictureLatitudeIndex;
                int longitudeIndex = Extensions.Modulo(-halfLongitudePictureSpans + pictureLongitudeIndex, longitudeSpans);

                //Debug.LogFormat("Adding picture vertex {0}, {1}", latitudeIndex, longitudeIndex);
                pictureMatrix[latitudeIndex, longitudeIndex] = new MeshVertex(
                    position: getSpherePoint(latitudeIndex, longitudeIndex),
                    uv: new Vector2(1f * pictureLongitudeIndex / pictureLongitudeSpans, 1f * pictureLatitudeIndex / pictureLatitudeSpans),
                    normal: getSpherePoint(latitudeIndex, longitudeIndex).normalized
                );

                if (longitudeIndex == 0) {
                    longitudeIndex = longitudes - 1;
                    //Debug.LogFormat("Adding picture vertex {0}, {1}", latitudeIndex, longitudeIndex);
                    pictureMatrix[latitudeIndex, longitudeIndex] = new MeshVertex(
                        position: getSpherePoint(latitudeIndex, longitudeIndex),
                        uv: new Vector2(1f * pictureLongitudeIndex / pictureLongitudeSpans, 1f * pictureLatitudeIndex / pictureLatitudeSpans),
                        normal: getSpherePoint(latitudeIndex, longitudeIndex).normalized
                    );
                }
            }
        }

        for (int latitudeSpanIndex = 0; latitudeSpanIndex < latitudeSpans; latitudeSpanIndex++) {
            for (int longitudeSpanIndex = 0; longitudeSpanIndex < longitudeSpans; longitudeSpanIndex++) {
                if (isPictureSpan(latitudeSpanIndex, longitudeSpanIndex)) {
                    AddSpan(mc, pictureMatrix, latitudeSpanIndex, longitudeSpanIndex, 1);
                }
                AddSpan(mc, baseMatrix, latitudeSpanIndex, longitudeSpanIndex);
            }
        }

        return mc.Done();
    }
Esempio n. 3
0
 public int GetIndex(MeshConstructor mc)
 {
     return index;
 }