示例#1
0
    public static Mesh SuperVolume(float radius, SuperShapeParams shape1, SuperShapeParams shape2, int lonRes, int latRes)
    {
        Vector3[] vertices     = new Vector3[lonRes * latRes];
        Color[]   colors       = new Color[lonRes * latRes];
        int[]     indices      = new int[6 * (lonRes - 1) * (latRes - 1)];
        int       indicesIndex = 0;

        for (int j = 0; j < lonRes; j++)
        {
            float teta  = -Mathf.PI + (float)j / (float)(lonRes - 1) * 2 * Mathf.PI;
            Color color = Color.HSVToRGB((float)j / ((float)lonRes - 1), 1, 1);
            float r1    = SuperShape(teta, 1, 1, shape1.n1, shape1.n2, shape1.n3, shape1.m1, shape1.m2);
            for (int i = 0; i < latRes; i++)
            {
                float sigma = -Mathf.PI / 2 + (float)i / (float)(latRes - 1) * Mathf.PI;
                float r2    = SuperShape(sigma, 1, 1, shape2.n1, shape2.n2, shape2.n3, shape2.m1, shape2.m2);
                float x     = radius * r1 * Mathf.Cos(teta) * r2 * Mathf.Cos(sigma);
                float z     = radius * r1 * Mathf.Sin(teta) * r2 * Mathf.Cos(sigma);
                float y     = radius * r2 * Mathf.Sin(sigma);
                vertices[GetIndex(j, i, lonRes)] = new Vector3(x, y, z);
                colors[GetIndex(j, i, lonRes)]   = color;
                if (i != latRes - 1)
                {
                    if (j != lonRes - 1)
                    {
                        indices[indicesIndex]     = GetIndex(j, i, lonRes);
                        indices[indicesIndex + 1] = GetIndex(j, i + 1, lonRes);
                        indices[indicesIndex + 2] = GetIndex(j + 1, i, lonRes);
                        indicesIndex += 3;
                    }
                    if (j != 0)
                    {
                        indices[indicesIndex]     = GetIndex(j, i, lonRes);
                        indices[indicesIndex + 1] = GetIndex(j - 1, i + 1, lonRes);
                        indices[indicesIndex + 2] = GetIndex(j, i + 1, lonRes);
                        indicesIndex += 3;
                    }
                }
            }
        }

        Mesh mesh = new Mesh();

        mesh.vertices = vertices;
        mesh.SetIndices(indices, MeshTopology.Triangles, 0, true);
        mesh.colors = colors;
        mesh.RecalculateBounds();
        mesh.RecalculateNormals();
        mesh.RecalculateTangents();
        return(mesh);
    }
示例#2
0
 private void InitializeShapeArrays()
 {
     _nextShapes    = new SuperShapeParams[_shapes.Length];
     _currentShapes = new SuperShapeParams[_shapes.Length];
     for (int i = 0; i < _shapes.Length; i++)
     {
         _nextShapes[i]       = new SuperShapeParams();
         _currentShapes[i]    = new SuperShapeParams();
         _currentShapes[i].n1 = _shapes[i].n1;
         _currentShapes[i].n2 = _shapes[i].n2;
         _currentShapes[i].n3 = _shapes[i].n3;
         _currentShapes[i].m1 = _shapes[i].m1;
         _currentShapes[i].m2 = _shapes[i].m2;
     }
 }
示例#3
0
    /// <summary>
    /// Update a mesh created with the SuperVolume methode
    /// lonRes and latRes must be the sames than during the SuperVolume creation
    /// </summary>
    public static void UpdateSuperVolume(ref Mesh svMesh, float radius, SuperShapeParams shape1, SuperShapeParams shape2, int lonRes, int latRes)
    {
        Vector3[] vertices = svMesh.vertices;
        for (int j = 0; j < lonRes; j++)
        {
            float teta  = -Mathf.PI + (float)j / (float)(lonRes - 1) * 2 * Mathf.PI;
            Color color = Color.HSVToRGB((float)j / ((float)lonRes - 1), 1, 1);
            float r1    = SuperShape(teta, 1, 1, shape1.n1, shape1.n2, shape1.n3, shape1.m1, shape1.m2);
            for (int i = 0; i < latRes; i++)
            {
                float sigma = -Mathf.PI / 2 + (float)i / (float)(latRes - 1) * Mathf.PI;
                float r2    = SuperShape(sigma, 1, 1, shape2.n1, shape2.n2, shape2.n3, shape2.m1, shape2.m2);
                float x     = radius * r1 * Mathf.Cos(teta) * r2 * Mathf.Cos(sigma);
                float z     = radius * r1 * Mathf.Sin(teta) * r2 * Mathf.Cos(sigma);
                float y     = radius * r2 * Mathf.Sin(sigma);
                vertices[GetIndex(j, i, lonRes)] = new Vector3(x, y, z);
            }
        }

        svMesh.vertices = vertices;
        svMesh.RecalculateBounds();
        svMesh.RecalculateNormals();
        svMesh.RecalculateTangents();
    }