General & simple Question about optimization

Guys,



if I have over 2000 nodes that keep moving around what is the best way to optimize?



1- I looked into LODs but even with low level (say 1 vertex) there is a LOT of nodes

2- I cannot batch them into one node as they keep moving and from this forum I understood that it’s more expensive to attach/detach rather than using them as different nodes for each.



what is recommended in games like that?

BatchNode

you batch using BatchNode right? cz thats what I used to batch my static nodes together. But what about the non static nodes?

BatchNode is for dynamic objects (that should move).

GeometryBatchFactory is for static objects.

BatchNode currently doesn’t handle normal maps well, however, so if you need those you’ll have to wait until they do, or help fix it.

Ah nice! what’s the drawback of using BatchNode for both static and non static?

Double memory (at the moment). GeometryBatchFactory is something you should use beforehand, thats why its built into the SDK/SceneComposer

2 Likes

thank guys

aaahhh… game development is not so easy… Every time I learn something new. BatchNode and GeometryBatchFactory…

Thanks for explanation.

is BatchNode working with the nightly build? It used to work with me with the stable version and now that I updated it doesn’t work. GeometryBatchFactory works fine.



I get alll the children of the parentNode detaching after they attached and then get a NullPointer exception

[java]

r 21, 2012 10:04:56 AM com.jme3.scene.Node detachChildAt

INFO: null (Node): Child removed.

Mar 21, 2012 10:04:56 AM com.jme3.scene.Node detachChildAt

INFO: null (Node): Child removed.

Mar 21, 2012 10:04:56 AM com.jme3.scene.Node detachChildAt

INFO: null (Node): Child removed.

Mar 21, 2012 10:04:56 AM com.jme3.scene.Node detachChildAt

INFO: null (Node): Child removed.

Mar 21, 2012 10:04:56 AM com.jme3.scene.Node detachChildAt

INFO: null (Node): Child removed.

Mar 21, 2012 10:04:56 AM com.jme3.scene.Node detachChildAt

INFO: null (Node): Child removed.

Mar 21, 2012 10:04:56 AM com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Root Node)

Mar 21, 2012 10:04:56 AM com.jme3.app.Application handleError

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.lang.NullPointerException

at com.sameo.simeo.RabbitGame.triggerCarsBatching(gameAnimation.java:669)[/java]





exactly at this line:



[java]

if(optimizeTag)

{

optimizeTag = false;

Material mateo = new Material(myApp.getAssetManager(), “Common/MatDefs/Misc/Unshaded.j3md”);

fPodsParent.setMaterial(mateo);

batch.attachChild(fPodsParent); <<<<<<<<<<<<<<<<<

batch.batch();

myApp.getRootNode().attachChild(batch);

}[/java]

Attach all things to one node, set the material on that node and then move them to the BatchNode, its a workaround necessary atm because each material is recognized as separate, even if its the same material in fact.

1 Like

just one more thing and I should be done with this optimization.



what on earth am I doing wrong with the following: the code below works great, objects are optimized but have no material.



[java]else if(type.equals(mop))

{



Material mateo = new Material(myApp.getAssetManager(), “Common/MatDefs/Misc/Unshaded.j3md”);

Geometry boxGeom = (Geometry) mySpatial;

boxGeom.setMaterial(mateo);

batch.attachChild(boxGeom);

}[/java]



So I thought I’d create my own (which is really c simple color with some shiningness) so I did and now the following code works but REALLY slow as if the BatchNode is not working.



[java]

{

Geometry boxGeom = (Geometry) mySpatial;

boxGeom.setMaterial(myApp.getAssetManager().loadMaterial("/Models/mopMat.j3m"));

batch.attachChild(boxGeom);

}[/java]







not an expert in material but here’s my material code:

[java]Material shiny bumpy rock : Common/MatDefs/Light/Lighting.j3md {

MaterialParameters {

Shininess: 8.0

NormalMap: Textures/bump_rock_normal.png

UseMaterialColors : true

Ambient : 0.0 0.0 0.0 1.0

Diffuse : 0.0 0.117 0.8 1.0

Specular : 0.0 0.0 0.0 1.0

}

}[/java]

Ok so I understood that for static objects you need to use GeometryFactory and use BatchNode for no-static/quasi static objects. But how about non static objects where I would have to change their materials (one of these thousands of objects) occasionally? what if I want want to color one of these nodes say red? I know I Can’t do that as I have already batched it so whats the solution? of course having these objects attached to rootNode individually is ridiculously bad for my fps.

1 Like

Manage the mesh yourself, like voxel engines (mine craft), you simply map an area of the texture that is red or white or grass or whatever to those vertices you add. Or if you go with BatchNode, you have multiple models with different texture coords already prepared, but they all use one texture atlas so they can all share one material.

1 Like

why me? I -1’d you cause you made me pull out my mobile for this @mention.

1 Like

hahaha my apologies to you sir



sometimes i get too excited while coding

I’ve been reading about it, and look like TextureAtlas is the way to go. Before I spend too much time looking into the best tools, any preferred way using by the monkeys here for creating Atlases?



thanks

Photoshop?

I dont have it. I already have the material needed setup in Blender, anyway I could export that?

and is there anything on the wiki like a link or tutorial explaining how to use it?

What do you mean “how to use it”, its a normal UV-mapping process. You have one big texture with lots of little parts like grass, wood etc. and then you just map your texture coords so that the right parts appear on your mesh. This way all meshes use one texture and you can thus use one material which in turn yields one single geometry.