Creating a new Forester plugin

The action of paging things in/out can apply to more than just trees though.

(Although I don’t know how generic this is at the moment).

How do I install this in JMonkey. Do I have to install “TheForester” plugin? Or is it something else?

Currently needs to be done manually as the devs have not yet added it ti the plugin repo list so it isn’t showing up in the list of plugins inside the SDK.
http://code.google.com/p/jmonkeyplatform-contributions/

Looks great. Where can i get the plugin?

manually from here by the looks https://code.google.com/p/jmonkeyplatform-contributions/source/browse/#svn%2Fforester-remake%2Frelease%2Flibs
looks like he missed the trunk though, probably need to fix that before it would join the plugins list…

@wabuilderman
Downloaded and installing all the stuff now. Also gonna dig up the old biomonkey code. I am sorry for postponing but I’ve been very busy. Lots of work this time of year (tourist stuff).

<cite>@jappie said:</cite> @wabuilderman why do you use: [java] int i = 0; while(i < somthing){ // loop logic i++; } [/java] for loops are cleaner in my opinion and more memory effiecient because the i variable only exists within the brackets of the loop. [java] for(int i =0; i < somthing; i++){ // loop logic } [/java]

Or am I missing somthing here.

Old C programmer? Hehe. You are forced to declare variables like that in ANSI C.

1 Like

Not very much code yet, I see. I look at this tho:

public TreeLayer CreateRandomHeightTrees(float Density, Spatial model, boolean solid, Vector2f terrainSize, int varying) { model.scale(1f, 0.1f + rand.nextInt(varying) / 10, 1f);
    this.terrain = terrain;
    Vector2f terrainSizeScale100th = terrainSize.divide(Density * 0.01f);
    int numTrees = (int) (terrainSizeScale100th.x + terrainSizeScale100th.y);
    int i = 0;
    while (i &lt; numTrees) {
        Spatial tempModel = model.clone();
        int x = rand.nextInt((int) terrainSize.x * 2) - (int) terrainSize.y;
        int z = rand.nextInt((int) terrainSize.y * 2) - (int) terrainSize.y;
        int y = (int) terrain.getHeight(new Vector2f(x, z)) - 100;
        tempModel.setLocalTranslation(x, y, z);
        foresterNode.attachChild(tempModel);
        if (solid) {
            CollisionShape tempModelShape =
                    CollisionShapeFactory.createMeshShape((Node) tempModel);
            RigidBodyControl tempModelControl = new RigidBodyControl(tempModelShape, 0);
            tempModel.addControl(tempModelControl);
            forPhy.getPhysicsSpace().add(tempModel);
        }
        i++;
    }
    return new TreeLayer();
}

I notice some things.

The collision stuff is not that efficient. It’s not wise to use a tree-model for collision shape to begin with. I did that myself but only for making it easy (as a “placeholder”). The correct thing is to have a specific collision model for the tree, and use that. I started working on supporting that myself, where you supplied collision models as arguments to a tree-layer.

It is also not good to generate a new mesh for each iteration. It would be better to make one based on the tree-model (on initiation) and then just clone rotated, scaled and displaced instances to the compound shape, however, that doesn’t work well with the jme bullet system (or at least it didnt when i tried), so perhaps leave it as is. Just want to mention.

I would not use java random for random numbers. There are better, faster implementations available. Mersenne twister and XORShift, are two examples. Very I prefer XORShift for these type of apps tho, since it’s tiny. Only a few lines of code, so you can just crap one out when you need it.

1 Like

Can’t seem to get the code in place. Anyways it’s “CreateRandomHeightTrees”

thx for the reply, and, incase anyones been wondering why i have made zero progress in the past 2-3 weeks, i was on vacation, but now i am back and working on the plugin.

1 Like

so, no one has had any issues or bugs with the plugin yet, or has no one download it, or is there some other problem?

@wabuilderman said: so, no one has had any issues or bugs with the plugin yet, or has no one download it, or is there some other problem?
It might not have gotten a lot of exposure as a plugin as of late due to our server issues.

You’d be better off relying on videos and direct (zip or svn) downloads for the time being to spread the word.

There is a reference to a material named “grassBase.j3md” in the GrassLayer.java but there does not seem to be any such file in the project. Is is the same from the old forester project?

Well, I managed to fix the code (besides fade) found at the forester remake repository. There were some loose ends, some wrong code sections. Have I looked at the right place for the code?

@wabuilderman is this the right repository? http://jmonkeyplatform-contributions.googlecode.com/svn/forester-remake

Anyway I played around with it to do some experimentation. My requirement is to be able to place grass etc. on any geometry surface. And here is the result of my experiment with the monkey head.

And this is how it looks on a mesh resembling more a terrain, the grass is created at loadtime of the terrain mesh quads.

I used the current lighting shader adjusted for the swaying code, and created one utility class to suit my grass placement which is not that far from your . My code does raycasting down the model to probe for a proper position (as I want to be able to place foliage on anything)

@wabuilderman if you are interrested in the code, drop me a line.

5 Likes

@ghoust An alternative to ray casting for placement is to get a random face (EDIT: Erm… triangle) from the mesh, find a random point in the triangle and then place the imposter however you need (unit_y, along the normal, etc) You can use the same method of dispersion you are using now, but it might be a little faster than the ray casting method.

Sorry… meant to also mention, you can store the triangle index + random offset, so when returning to a tile that is generated via noise function or the likes, you can easily place the objects back exactly where they were.

This is the general idea for how I had static particles following an animated mesh.

Come to think of it… that code is still out there. You all may want to consider using an emitter for vegetation placement… it worked really well for placing leaves on trees.

For reference… here is the vid using the emitter for imposter placement:

[video]http://youtu.be/fL8sbwommL8[/video]

awesome @ghoust!

<cite>@t0neg0d said:</cite> Come to think of it... that code is still out there. You all may want to consider using an emitter for vegetation placement... it worked really well for placing leaves on trees.

@t0neg0d where would I find the code?

The emitter stuff looks quite interresting. Currently my goal is only to populate a static mesh. The random mesh tile idea is also very interresting. For my terrain stuff I could also walk the whole buffer and check for placement. But I wanted to give it a shot how it would work on any geometry.

I thought about it as a plugin for the sdk, where artists could tweak and play with the settings, until they are confident with the foliage placement. My dynamic loading is just a playground, as my tiles are streamed in and the details (which foliage belongs to) are streamed in later, and a little delay is currently irrelevant.

I’m not sure where the original emitter implementations are (you can find them from t0neg0d’s original particles thread).

The ones I did are here:

http://code.google.com/p/jmonkeyplatform-contributions/source/browse/trunk/ParticleController/ParticleController/src/com/jme3/particles?spec=svn1015&r=1015#particles%2Fsource

MeshSource picks a random triangle then a random point in that triangle.
WeightedMeshSource weights the triangles by their size before picking so that all points on the mesh have equal probability even if the triangles are different sizes.

@ghoust Hah… I think he intentionally carries a bag of salt to pour in open wounds or something. @zarch I guess bases his code off of mine.and it sounds like what he has would work for this. Let me know if you have any problems with it… if ya do, I’ll dig up the source and send it to you.

Couple things it may not account for that you may find useful for vegetation placement:

  • If the meshes are animated, his static particle implementation may not follow the animated mesh
  • I doubt his allows for anchored movements of particles based on emission point either

Both of these are very useful for producing realistic movement for vegetation. Anyways… let me know how it goes with this.

EDIT:

Oh… another thing you may find useful for bringing a little more realism to the vegetation might be to have a look at the GPU animation shaders I put together. I can do some pretty cool stuff on the GPU side for mesh displacement.

EDIT 2:

Actually, one of the more useful feature was the ability to create particles based on a template mesh… if @zarch copied my source for this portion, his should also allow you to create AnimChannels for your particles. If not… then predefined animations per particle would be out for his “version”.