/// <summary> /// Creates a square 1x1 surface in XY but with variation of its Z depending on the /// result of a delegate. /// Returns a triangle array of the surface, which includes smooth normals and texture coordinates. /// </summary> /// <param name="pixelFunc">A delegate that takes the x and y and returns that pixel's height</param> /// <param name="numX">The number of X elements in a row</param> /// <param name="numY">The number of X elements in a row</param> /// <param name="mirrorY">Whether to invert Y</param> /// <param name="smooth">Whether to apply a 3x3 gaussian smoothing kernel, or not</param> /// <param name="noiseLevel">How much noise to add</param> /// <returns>Triangles of the surface, including smooth normals and teture coordinates</returns> static public VertexPositionNormalTexture[] CreatePlanarSurface ( XYToZDelegate pixelFunc, int numX = 256, int numY = 256, bool mirrorY = false, bool smooth = false, double noiseLevel = 0 ) { var heightMap = new double[numY, numX]; Parallel.For(0, numX, (x) => { Parallel.For(0, numY, (y) => { heightMap[y, x] = pixelFunc(x, y); }); }); return(CreatePlanarSurface(heightMap, mirrorY, smooth, noiseLevel)); }
/// <summary> /// Like the CreateCylindroid overload that takes a heightMap (see that method for details), /// but rather than a heightMap, this takes a delegate that defines the diameter multiplier. /// </summary> /// <param name="pixelFunc">A delegate that takes an x and y and returns the diameter multiplier</param> /// <param name="numHorizVertices">The number of horizontal vertices in a row</param> /// <param name="numVertVertices">The number of vertical vertices in a column</param> /// <param name="topDiameter">Diameter of top of cylindroid (if heightMap==null)</param> /// <param name="facetedNormals">If true, create normals per triangle. If false, create smooth normals</param> /// <param name="createBody">Whether to create the body of the cylindroid</param> /// <param name="createEndCaps">Whether to create a cap for each end</param> /// <param name="matrix">Matrix to transform each increment of y level from previous y level</param> /// <returns></returns> static public VertexPositionNormalTexture[] CreateCylindroid ( XYToZDelegate pixelFunc, int numHorizVertices = 32, int numVertVertices = 2, double topDiameter = 1, bool facetedNormals = false, bool createBody = true, bool createEndCaps = true, Matrix?matrix = null ) { var heightMap = new double[numVertVertices, numHorizVertices]; Parallel.For(0, numHorizVertices, (x) => { Parallel.For(0, numVertVertices, (y) => { heightMap[y, x] = pixelFunc(x, y); }); }); return(CreateCylindroid(numHorizVertices, numVertVertices, topDiameter, facetedNormals, heightMap, createBody, createEndCaps, matrix)); }