new
typealias MeshColor = SIMD3<Float>
// You can provide custom locationRandomizer and turbulencyRandomizer for advanced usage
var meshRandomizer = MeshRandomizer(colorRandomizer: MeshRandomizer.arrayBasedColorRandomizer(availableColors: meshColors))
private var meshColors: [simd_float3] { return [ MeshRandomizer.randomColor(), MeshRandomizer.randomColor(), MeshRandomizer.randomColor(), ] }
// This methods prepares the grid model that will be sent to metal for rendering func generatePlainGrid(size: Int = 6) -> Grid<ControlPoint> { let preparationGrid = Grid<MeshColor>(repeating: .zero, width: size, height: size)
// At first we create grid without randomisation. This is smooth mesh gradient without // any turbulency and overlaps var result = MeshGenerator.generate(colorDistribution: preparationGrid)
// And here we shuffle the grid using randomizer that we created for x in stride(from: 0, to: result.width, by: 1) { for y in stride(from: 0, to: result.height, by: 1) { meshRandomizer.locationRandomizer(&result[x, y].location, x, y, result.width, result.height) meshRandomizer.turbulencyRandomizer(&result[x, y].uTangent, x, y, result.width, result.height) meshRandomizer.turbulencyRandomizer(&result[x, y].vTangent, x, y, result.width, result.height)
meshRandomizer.colorRandomizer(&result[x, y].color, result[x, y].color, x, y, result.width, result.height)
} }
return result }