private bool GenerateCurveMidpoint(float[] heightMap, Rect targetRect, ref float[] debugHeightmap) { List <Vector2> peaks = null; if (this.Midpoint.usePeaks) { peaks = this.PreparePeaks(this.Peaks.Count, 0f, true, targetRect); } int initialStep = Mathf.RoundToInt((float)heightMap.Length / (this.Midpoint.frequencyPerUnit * targetRect.width)); e2dMidpoint e2dMidpoint = new e2dMidpoint(heightMap.Length, initialStep, this.Midpoint.roughness, peaks); e2dMidpoint.Regenerate(); for (int i = 0; i < heightMap.Length; i++) { heightMap[i] = e2dMidpoint.GetValueAt(i); if (this.Midpoint.usePeaks) { heightMap[i] = Mathf.Clamp01(heightMap[i]); } } if (e2dUtils.DEBUG_GENERATOR_CURVE) { debugHeightmap = new float[heightMap.Length]; for (int j = 0; j < heightMap.Length; j++) { debugHeightmap[j] = e2dMidpoint.GetValueAt(j) * targetRect.height; } } return(!this.Midpoint.usePeaks); }
/// Produces a heightmap using the Midpoint generator. /// Returns true if the map must be renormalized. /// The debugHeightmap parameter is used for debug to display the generated curve (with higher precision). /// See e2dGeneratorCurveMethod for details. private bool GenerateCurveMidpoint(float[] heightMap, Rect targetRect, ref float[] debugHeightmap) { // prepare and normalize the custom peaks List <Vector2> peaks = null; if (Midpoint.usePeaks) { peaks = PreparePeaks(Peaks.Count, 0, true, targetRect); } // init the function int step = Mathf.RoundToInt(heightMap.Length / (Midpoint.frequencyPerUnit * targetRect.width)); e2dMidpoint function = new e2dMidpoint(heightMap.Length, step, Midpoint.roughness, peaks); // generate values function.Regenerate(); // fill the heightmap for (int i = 0; i < heightMap.Length; i++) { heightMap[i] = function.GetValueAt(i); if (Midpoint.usePeaks) { heightMap[i] = Mathf.Clamp01(heightMap[i]); } } // fill the heightmap for debug if (e2dUtils.DEBUG_GENERATOR_CURVE) { debugHeightmap = new float[heightMap.Length]; for (int i = 0; i < heightMap.Length; i++) { debugHeightmap[i] = function.GetValueAt(i) * targetRect.height; } } return(!Midpoint.usePeaks); }