Generating low poly trees

I’ve seen that in many games trees are represented with two normal planes textured with dds textures with lod levels. (like here)

Can someone help me to do this in jme3?

Is it a good approach?

Thanks in advance

truman said:
Is it a good approach?


If you define "good" as fast and relatively bad looking, then yes, it is good.

truman said:
Can someone help me to do this in jme3?


Have you tried using two normal planes textured with dds textures of a tree? You could even do this with textured quads if you don't want to use an external 3d program. Make sure you have an alpha channel and add it to the transparency bucket.

truman said:
with lod levels


I think you're misunderstanding the point. The textures don't have LOD levels; rather, the entire technique of using one/two planes to represent something is used as a LOD level, because it looks less bad from far away.

Hi Truman,



It seems what you want to do is generate sprites as trees. That seems fair enough. As KT said, you probably won’t get a high quality render, but good enough if they are far away where detail isn’t important.



I have used two approaches:


  1. the Billboard Control:

    This takes a spatial, such as a quad, and turns it toward the camera. The quad can have your tree on it with the non-tree parts being set to an alpha channel to give transparency. However, each tree is a spatial, each with its memory and processor requirements. You get a frame rate penalty with this one if you have many sprites.


  2. the Particle Emitter:

    The particle emitter is treated as a single object but with many particle “objects”. Each particle is a quad with a texture on it and it also uses alpha blending. You can iterate through the particle set and set the particle’s position, angle, etc. And the particles always face the camera. It may (or may not) work for you with trees. I used it for stars and could set out ten thousand stars to set positions with a frame rate of around five hundred. So I thought that was pretty good. However, I didn’t have to worry about orientation. The Spatial-with-Billboard approach gave me 01 fps for ten-thousand stars. Not really what I was looking for. :slight_smile:



    There is a whole tutorial on using the particle emitter. It’s pretty good. It gave me a good head start.



    If you are working on version one of your game (or version zero-point-one), you probably don’t have to be worried about state-of-the art graphics. If you can get the game working in a general sense with simplified graphics, the visuals can be upgraded later.



    Regards,



    Alf.

First of all, I thank alfinete and kidneytrader for detailed answers

to kidneytrader :

I’ve to learn how to use LOD levels, I know they’re related with meshes, my (confused :slight_smile: ) question was:

if I’ve a dds picture which contains same tree image at many resolution (applicable to each lod level), how to implement lod levels in this case in jme3 to tree mesh (for example increasing number of quads at low distance)?

to alfinete:

it’s not clear for me why should I use ParticleEmitters in this case? Would it improve performances?



I’ve used this solution:



[java]

private Node getTree(int i) {



Node tree=new Node(“Tree”+i);

int size=360,w=20,h=40,step=90;

Quad quadMesh = new Quad(w, h);

quadMesh.updateGeometry(w, h, false);

quadMesh.updateBound();

Box box=new Box(new Vector3f(0,15,0),10,20,1f);

Geometry[] quads=new Geometry[step];

int k=0;

for(int a=0;a<size;a+=step){

quads[k] = new Geometry(“Textured Quad”+k, quadMesh);

Quaternion q = new Quaternion();

float angle=(float) Math.toRadians(a);

q.fromAngleAxis(angle, new Vector3f(0, 1, 0));

Vector3f t=new Vector3f(-10FastMath.cos(angle),10,10FastMath.sin(angle));

quads[k].setLocalTranslation(t);

quads[k].setLocalRotation(q);

tree.attachChild(quads[k]);

//System.out.println(“a=”+a+":angle="+angle);

k++;

}

Material mat = new Material(assetManager, “Common/MatDefs/Light/Lighting.j3md”);

Texture tex=assetManager.loadTexture(“textures/tree”+i+"/diffuse.png",false,true,false,1);

mat.setTexture(“DiffuseMap”, tex);

//Texture texNormal=assetManager.loadTexture(“textures/trees/normal.png”,false,false,false,1);

// mat.setTexture(“NormalMap”, texNormal);

Texture texSpecular=assetManager.loadTexture(“textures/tree”+i+"/specular.png",false,true,false,1);

mat.setTexture(“SpecularMap”, texSpecular);



mat.setFloat(“Shininess”, 1f);

mat.setBoolean(“UseMaterialColors”, false);





mat.setBoolean(“VTangent”, true);

mat.setBoolean(“Minnaert”, false);

mat.setBoolean(“WardIso”, true);

mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);

mat.getAdditionalRenderState().setAlphaTest(true);

mat.getAdditionalRenderState().setAlphaFallOff(0.01f);



tree.setModelBound(new BoundingBox());

tree.updateModelBound();

TangentBinormalGenerator.generate(tree);

tree.updateGeometricState();

if(tree!=null){

tree.setQueueBucket(Bucket.Transparent);

tree.setMaterial(mat);



}



GeometryBatchFactory.optimize(tree);

return (Node) tree;

}

[/java]



modifying step variable value you can change number of quad used

result is not so bad (and performances too)



http://www.youtube.com/watch?v=Ht5nB_iedCo



obviously suggestions are welcome
bye
2 Likes

I think this looks MUCH better than I expected.

Great too considering your making a race game so getting too close to the trees is no problem.

Thanks for sharing code :slight_smile:

Looks like the HDR is going a bit crazy there… You can increase exposure a bit and increase the adjustment time

Momoko_Fan said:
Looks like the HDR is going a bit crazy there.. You can increase exposure a bit and increase the adjustment time

http://www.youtube.com/watch?v=FsPRHVdHLak


now I think is better
thanks