Changing the size of a brush

Hello everyone,



I create a terrain Editor based on TerraMonkey an now i’m trying to implement a Brush system. I can set a brush and edit the terrain. But i dont know how can i change the size of the brush without changing the image.

[java]



public void adjustHeight(int x, int y, float height){



for (int i=x-brushSize/2; i<x+brushSize/2; i++) {

for (int j=y-brushSize/2; j<y+brushSize/2; j++) {



//Changing the area wich is aim by the pixel of the brush//

heightMap[i*heightMapSize+j] = heightMap[i*heightMapSize+j]+height*brush[(i-x+brushSize/2)*brushSize+(j-y+brushSize/2)];



}

}



m.clearBuffer(Type.Position);

m.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(createPosition(heightMap)));



}[/java]

[java]



public void setBrush(Texture brushTexture){



AbstractHeightMap brushHeight = new ImageBasedHeightMap(

ImageToAwt.convert(brushTexture.getImage(), false, true, 0), 1f);

brushHeight.load();

brushSize = brushTexture.getImage().getHeight();

brush = brushHeight.getHeightMap();

brush = negate(brush);



}[/java]

Take a look at the terrain editor plugin for JMP, it has a brush for modifying terrain hight.

It modifies the terrain height by using terrain.adjustHeght(float).

Mmmm you use a methode like this no ?



[java]



public void adjustHeight(int x, int y, float height, int radius){



for (int i=x-radius; i<x+radius; i++) {

for (int j=y-radius; j<y+radius; j++) {

if (FastMath.sqr(x-i)+FastMath.sqr(y-j) <= FastMath.sqr(radius)) {



heightMap[i*imageSize+j] = height+heightMap[i*imageSize+j];



}

}

}



m.clearBuffer(Type.Position);

m.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(createPosition(heightMap)));



}[/java]



But you dont use a brush image to do this. What i’ve want it’s to modify the scale of my brush without changing the brush.

When you say a brush image, do you mean a tool in an editor that you can see? Or an image passed down to the terrain to be used to adjust the height directly with the values in each pixel?

I’m guessing from your code above that you pass in a heightmap, that was generated by a brush image, and then use those height values modify the terrain height?

You want to scale that heightmap? To do that you will still have to load in the image using ImageBasedHeightmap, but then you can take the actual heightmap data, scale it by adding in some more points in a new heightmap array, and fill that new array with interpolated height values sampled from the first heightmap. Then you can iterate over that to adjust your height.

Ok my aim is to create an editor where the user can change and import brush. And it’s exactly what you say next. I’m getting the heightMap from a brush Image an interpolate with the current heightmap of the terrain. Wat do you think of this method ? (performance…)



An example of paintbrush am I using :







(I need to resize to 32*32px)

I think this method could work and the performance should be fine. Just iterate the size you desire your brush to be, then sample the image at those intervals to get the pixel at that location. So if your brush is 1/4 the size of the image, sample 1 every 4 pixels. If the brush is 4x the size of the image, then you will end up sampling each pixel 4x.