Пример #1
0
    public virtual SurfaceObjectCreator[] GenerateMeshDataFromSurfaceParametrizations(SurfaceGenerator.SurfaceParametrization[] faceParametrization)
    {
        int N = faceParametrization.GetLength(0);

        SurfaceObjectCreator[] objectCreators = new SurfaceObjectCreator[N];

        Action <int> generateFace = (int i) => {
            SurfaceGenerator gen = new SurfaceGenerator();
            SurfaceGenerator.SurfaceParametrization face = faceParametrization[i];

            gen.setParameters(X, Y, true, false);
            gen.setVerticesOutputArrays(new Vector3[X * Y], new Vector3[X * Y], new Vector2[X * Y], 0);
            gen.setIndicesOutputArray(new int[(X - 1) * (Y - 1) * 2 * 3], 0);
            gen.Generate((float x, float y) => withNoise(face(x, y), x, y));

            objectCreators[i] = new SurfaceObjectCreator(gen, this);
        };

        if (enableMultithreading)
        {
            Parallel.For(0, N, 1, generateFace);
        }
        else
        {
            for (int i = 0; i < N; ++i)
            {
                generateFace(i);
            }
        }

        return(objectCreators);
    }
Пример #2
0
    public virtual SurfaceObjectCreator[] GenerateMeshDataFromSurfaceParametrizations(SurfaceGenerator.SurfaceParametrization[] faceParametrization)
    {
        int N = faceParametrization.GetLength(0);

        SurfaceObjectCreator[] objectCreators = new SurfaceObjectCreator[N];

        Action <int> generateFace = (int i) => {
            SurfaceGenerator gen = new SurfaceGenerator();
            SurfaceGenerator.SurfaceParametrization face = faceParametrization[i];

            gen.setParameters(X, Y, true, false);
            gen.setVerticesOutputArrays(new Vector3[X * Y], new Vector3[X * Y], new Vector2[X * Y], 0);
            gen.setIndicesOutputArray(new int[(X - 1) * (Y - 1) * 2 * 3], 0);
            gen.setColorsOutputArray(new Color[X * Y], 0);
            gen.Generate((float x, float y) => {
                SurfaceGenerator.Vertex vert;
                vert.position = radius * face(x, y);
                vert.normal   = Vector3.zero;
                vert.uv       = new Vector2(x, y);
                vert.color    = Color.white;
                return(vert);
            });

            objectCreators[i] = new SurfaceObjectCreator(gen, this);
        };

        if (enableMultithreading)
        {
            Parallel.For(0, N, 1, generateFace);
        }
        else
        {
            for (int i = 0; i < N; ++i)
            {
                generateFace(i);
            }
        }

        return(objectCreators);
    }