Sure. It’s in lua.
The code for creating the Terrain is almost the same as in the examples, but storing the image in a variable.
[code] – Create heightmap terrain
terrainNode = scene_:CreateChild(“Terrain”)
terrainNode.position = Vector3(0.0, 0.0, 0.0)
local terrain = terrainNode:CreateComponent(“Terrain”)
terrain.patchSize = 64
terrain.spacing = Vector3(2.0, 0.5, 2.0) – Spacing between vertices and vertical resolution of the height map
terrain.smoothing = true
heightMapImage = cache:GetResource(“Image”, “Textures/HeightMap.png”)
terrain.heightMap = heightMapImage
terrain.material = cache:GetResource("Material", "Materials/Terrain.xml")
-- The terrain consists of large triangles, which fits well for occlusion rendering, as a hill can occlude all
-- terrain patches and other objects behind it
terrain.occluder = true[/code]
Then the painting itself. This is just an example, not a real brush, it increases +10% the height on each point.
[code]function PaintBrush(center, radius)
radius = radius or 80.0
center = center or Vector3(.0,.0,.0)
local terrain = terrainNode:GetComponent(“Terrain”)
center.x = (center.x + heightMapImage.width) / terrain.spacing.x
center.z = (center.z - heightMapImage.height)/ terrain.spacing.z * (-1.0)
radius = radius / terrain.spacing.x
radiusSquare = radius * radius or 400.0
local x_min = center.x - radius
local y_min = center.z - radius
local x_max = center.x + radius
local y_max = center.z + radius
for i=x_min, x_max do
for j=y_min, y_max do
if ((i - center.x) * (i - center.x) + (j - center.z) * (j - center.z)) <= radiusSquare then
heightMapImage:SetPixel(i,j, heightMapImage:GetPixel(i,j) * 1.1)
end
end
end
terrain.heightMap = heightMapImage
end[/code]
You should be able to add that to the water or vehicle example and execute the paint through console, both arguments are optional, it will paint a 80 radius circle on the centre of the map.
I don’t think it’s weird that it takes a second, it’s reconstructing all the vertex in the terrain from scratch, instead of just the ones being modified.