How to Grass ? Reborn the Forest**!

Should be a plugin I think. Unless we have a core developer ready to take full responsibility for it.

2 Likes

@JOnathanJOnes

You can do whatever you want with it, I don’t mind. But if you find bug or some improvement feel free to tell me.

For everyone, be aware that this project is still in development. And might be full of unknown bugs… And at this point, isn’t even ready to be a plugin I think. My aim right now,

  1. Find why sometimes the framerate is going down
  2. Fix the grass lightning (which is a mess right now)
  3. Make the grass more easily editable and find how to follow the TerrainQuad heightmap change without recreating the whole GrassArea
  4. Rework the GrassAreaControl update method to be more efficient in terms of performance
1 Like

I agree it should be a plugin

1 Like

What has been updated (still not committed)

Grass lightning is still a pain to do for me. So I just deleted everything that I didn’t understand the lightning is now close to nothing except an ambient color depending on the main directional light color and intensities.

The grass is now easily editable with 4 more method

/**
 * This method update the GrassBlade y position of the grass holder at the given location
 * @param x The x position
 * @param z The z position
 */
public void updateAt(float x, float z);

/**
 * This method update all the GrassBlade y position in a rectangle starting from pointA to pointB
 * @param pointA Starting position of the square
 * @param pointB End position of the square
 */
public void updateAt(Vector2f pointA, Vector2f pointB);

/**
 * Same as updateAt but this time the GrassBlades are generated
 * @param x The x position
 * @param z The z position
 */
public void generateAt(float x, float z);

/**
 * Same as updateAt but this time the GrassBlades are generated
 * @param pointA Starting position of the square
 * @param pointB End position of the square
 */    
public void generateAt(Vector2f pointA, Vector2f pointB);

I think I found why sometimes the fps drop down.

The issue is inside :

public void createMesh(List<GrassBlade> grassBlades)

In this method, I recreate all the VertexBuffer every frame. I don’t know how I can reuse the current mesh buffer since the number of GrassBlades change over time. I tried to fix the number of GrassBlades to a maximum number and then reuse all the mesh buffer. And its worked pretty well. No more framerate issues, but still I can’t do that because of the density variation which lead to an higher or lower number of grass.

https://github.com/Stomrage/GrassArea/blob/master/GrassArea/src/mygame/GrassArea/GrassArea.java

1 Like

Hey guys !

I added one really cool features for the GrassArea. A function to manipulate the density map ! I also make a little change on the adjustAt and generateAt, they now take a Vector2f instead of 2 float value ! (What a change :smiley:)

public void updateAt(Vector2f pointA);
public void generateAt(Vector2f pointA);

/**
 * This function is use to adjust the density map at the given point with
 * an array of float value which will influence the density map
 * Warning : The array must be a 2D array with the same size float[size][size]
 * @param densityMap The density map to change
 * @param colorChannel The color channel to modify
 * @param height An array of float (+ or -) of the density to add
 * @param size The size of the 2D array
 * @param at The location of modification
 */
public void adjustDensity(DensityMap densityMap, ColorChannel colorChannel, float[][] height, int size, Vector2f at){
    GrassFactory.getInstance().adjustHeight(densityMap.ordinal(), colorChannel.ordinal(), height, size, at);
    this.generateAt(at, at.add(new Vector2f(size,size)));
}

A video to show what you can do with a really simple example

PS : Maybe in 5-10 years JMonkey will have a really nice vegetation system more artist friendly ? Wait… Sorry, non programmer friendly !

5 Likes

Nice work man! Keep going this.

Also, this feature would be amazing if it works together with TerraMonkey.

I saw what you did there…

Thanks @afonsolage :smiley:
I’ll keep going for it don’t worry (until I reach my next school year) ! But there will be a point where I’ll need people’s help to fix performance issue and bugs and features to add, etc…

What do you mean exactly by working together with TerraMonkey ? If you mean detecting heightmap change of TerraMonkey, right now I can’t. The only solution is to modify the core of TerraMonkey… The only decent solution I found is to call my updateAt function after the heightmap modification.

A new version is available at GitHub - Stomrage/GrassArea

Edit : For me, this is the final version in terms of features, I don’t know what else people’s need. So, I’ll start to create a plugin for it and only change miner things.

Add this as plugin to Terrain Editor please

@Skatty

Can you explain what do you mean by that ?

Do you mean something like this ?

terrain.addGrassDensityMap(...);
terrain.setGrassColorMap(...);
terrain.addGrassLayer(...);

I think he means the actual terrain editor in the SDK but its not really made to be extended. However editing controls in the SceneExplorer is completely extensible.

Yeap I didn’t realise @Skatty edited the post.

:rainbow:@normen :rainbow:
I’m not planning to do something integrated with the SDK right now. I’m not sure, but having it inside the scene explorer means to integrate the library inside the core ? And I have no idea of how to do it… But thanks for the tips :blush:.

One more thing and if you have time. Can you give me some tips about publishing a plugin inside the repo ? (A link for it, or a good practice or anything useful)

Edit : I want something flexible enough to let everyone do whatever they want with it but not limited to a single editor

Creating a jar library that can be included in projects:
http://wiki.jmonkeyengine.org/doku.php/sdk:development:extension_library

Creating a specialized “Add Control” command:
http://wiki.jmonkeyengine.org/doku.php/sdk:development:sceneexplorer#control_example

If people just include your library they can already add your Controls to their Scenes in the SDK using the “Add Custom Control” command and specifying the class name - if they have a default (empty) constructor. They can then edit all default (Strings, Vectors etc) properties that have proper getters and setters.

Making a plugin that allows adding your Controls in the SDK via a dedicated menu entry (possibly with a wizard) and having a special wrapper to edit special things about them is easy as well (see second link). Having some kind of brush to paint it on terrain isn’t quite as easy but it would be possible as well.

1 Like

I’ll definitely look into this ! Sounds interesting to manipulate the SDK.

By the way, can you give me the right to put my plugin into the repo ?

Sure, PM me your google account email

The plugin should be accessible. I can’t check it by myself, because I got a weird bug since I installed the platform that doesn’t allow me to update.

https://code.google.com/p/jmonkeyplatform-contributions/source/browse/#svn%2Ftrunk%2Fgrassy-banana

i got this too some time ago, update the nb ide to 8+ and with the needed JRE

Still has to be entered in the main project list in the trunk/nbproject folder so it can be built. But I can do that for you if you want.

By update you mean the SDK? If you’re on Linux try chowning everything in jdk/jre/bin to +x

@RatKod

I’ll try it !

@normen

I’m on Windows. And I’m pretty sure the problem came from my computer and has nothing to do with JMonkey Platform so I’ll leave it like this. It doesn’t really matter I just upload the library manually.

And yep I would really appreciate if you can do it. I don’t want to break anything outside of my plugin folder. Even if the process seems pretty simple I’m too scared :pig: :sheep:

Edit : If I understand correctly once you done that, everytime I update the source new jar,doc,source jar,zip folder will be created with the current version ?

Yes

1 Like