Hello,
I need to show a lot of objects, and I wanted to use something like PVS. I red that in JME I can use Scenegraph, but I have no idea how to optimize it, in fact, actually, I simply stored a lot of objects in root node, and JME goes SLOW. See the main procedure (used to test optimization and performance):
[java]public void simpleInitApp() {
pivot = new Node[5];
// initKeys();
for(int i=1; i<10000; i++) {
String n = "Box" + i;
float posX = (float) (Math.random() * 1000.0f) + 10;
float posY = (float) (Math.random() * 1000.0f) + 10;
float posZ = (float) (Math.random() * 1000.0f) + 10;
Geometry geom = createCube(n, new Vector3f(posX, posY, posZ), new Vector3f(5, 5, 5));
rootNode.attachChild(geom);
}
Geometry geom = createCube("c1", new Vector3f(3, -100, -100), new Vector3f(1, 200, 200));
rootNode.attachChild(geom);
}[/java]
Even if I putted a BIG object in front of the camera, it is clear that JME is drawing small cubes, since I get a few FPS. I think the main object should have to hide the other small objects, so I was expected to get a high frame rate.
If I generate so many cubes, how can I do to avoid drawing cubes behind other cubes?
Thank you for your help!
The keywords are culling and geometry batching, lots of posts about it n the form already.
Thank you,
but geometry batching has a problem for me (I red some posts, even if I never tried it in JME 3 alpha-3):
- Geometry batching is “slow” (cannot be applied in real-time if the objects position changes)
- (I think…) that if I “join” the objects I will not be able any more to move them independently (I think batching process “attach” them as a big object). I can detect faces (e.g. using a ray collision) but I cannot distinguish a single cube/mesh
About culling… Can you give me a hint (sorry I’m new in JME)? I was looking for PVS but I did not find any exhaustive information. About culling I will search for “Frustum culling”.
You can cull any spatial by setting its CullHint to always. In e.g. a box world its easy to determine which boxes are not seen from a certain position and cull them. Geometry batching doesnt always have to mean that you have geometries and combine them, you could also modify the mesh directly, important thing is not to have many geometries.
Geometry batching doesn't always have to mean that you have geometries and combine them, you could also modify the mesh directly, important thing is not to have many geometries.
Please can you clarify me this? Please give me an hint or an article/blog/wiki to get more info. Until now, I red about "geometry batching" as a way (slow) to "merge" polygons.
About Culling: I used CullHint but...
1) If I use "always" simply I don't see anything! Every polygon disappear (something like "visible = false")
2) Using culling as "Dynamic" nothing happen (low frame rate). But I think it is logical: culling seems used only to detect if a polygon is inside the camera frustum, and not to check if a polygon is visible (inside camera frustum but completely hidden from another polygon).
Now I will try to put "near" polygons attached to root, and "far" polygons attached to near poly as child.
PVS will not work for this since you’re saying the scene is dynamic.
Just how dynamic is this scene? Are the cubes moving around like crazy or is there just some movement near a certain position? Also is the final product going to be about cubes or are you using cubes just for testing?
Momoko_Fan said:
PVS will not work for this since you're saying the scene is dynamic.
Just how dynamic is this scene? Are the cubes moving around like crazy or is there just some movement near a certain position? Also is the final product going to be about cubes or are you using cubes just for testing?
My scene is dynamic since pieces can be created and destroyed. No movement. I manage movements with other data structures.
About cubes: I can have cubes or other "basic" shapes like Pyramid, spheres, or other ones composed using basic polygons (imagine basic shapes similar to tetris pieces, or more complex ones like a "column", a door, a fence, etc...).
I was hoping that JME could avoid to "spend time" to draw polygons completely hidden from other polygons, not only out of the camera range (fustrum occlusion).
I red somewhere in the forum that Octree algorithm automatically do that, but...
1) ... or it does not work well (you can check it by creating a new SimpleGame, then replace the original simpleInitApp() with the one I published)
2) ... I don't create a good scenegraph to allow jme to manage the objects in the correct way.
Generally speaking I think this operation should be included in a 3d game engine since that is a "simple" but effective way to speed-up drawing. Other engines use other specific methods to achieve this: for example, as you know, indoor scenes are usually managed using the "portals" and sectors.
Can I check or see something else?
I was even thinking to group objects (batch convert) using a small amount of objects (for example, grouping 10 objects together, batching should be fast and I get a factor "10" for objects drawn on the screen), but in that case I think I will not able any more to find single objects (after batch grouping).
I think the best method should be the one I talked before: 3d engine should be able (using z-buffer and bounding box?) to avoid to draw objects completely hidden from other objects.
Forget about automatic culling of hidden objects, a generalized solution would be close to raycasting and thats simply not possible. Thats why I was taking the “boxworld” as an example. There its easy to determine which boxes can be culled, just check that each frame and set the cullhint to never.
What do you mean for “boxes”? Create large boxes and check visibility with a ray (in order to show/hide objects contained inside)?
Can I check them even if they are not visible (I cannot show them)?
One question more: I have jme3 alpha-3 and it seems there is no function for batch conversion: it is correct? I found a code somewhere in the web: do I need to use it?
EDIT 2: It seems some engines can automatically use hardware occlusion : is it possible to use it in jme?
No, not rays, thats exactly what I was saying, for lots of boxes (think Minecraft) the logic which box can be seen can be determined pretty easily w/o any ray checks (say you are on field 0/0/0 and on 0/0/1 theres a box then you wont see boxes 0/0/2 to 0/0/infinity and you can just cull those. So think about how that applies to your game or w/e (e.g. when you are in room1 you know one cannot see anything from room2).
Ok I understand what you say, but the algorithm is not so easy, in fact we don’t work using horizontal/vertical “rooms”: if you “see” (rotate camera) to “strange angles” (e.g. you see 30deg,18deg, 63deg), we need to use line algorithm to check which blocks intersect. Furthermore, if you have an object near to you, your view is occluded in “funny” ways:
.
. [==]object
.
.
.||wall
eye. ||
<). || [==]object
. ||
.||
.
. [==]object
.
.
the problem is even more complex if the "wall" is not one but two:
.
........o
.......o.......[==]object
......o.....
.....o
....o||wall
eyeo.....<
HOLE!..
<)o..||....[==]object
...o.||.
....o||
.....o
......o....[==]object
.......o
........o
The walls are two, divided by an "hole".
I red some info about hardware occlusion and I think that is only the viable way, or we could get serious artifacts.
Just implement the game and check where you get framerate drops, then cull at those locations. As said its dependent on how you setup your game. Theres no need to cull every single object you dont see as long as it doesnt cause too much overhead.
I cannot check locations with problems, since the environment is random-generated.
Is there any way to quickly group small objects in a big one (using batch grouping technique)?
you can use GeometryBatchFactory to combine geometry
Thank you, but it seems GeometryBatchFactory class does not exist in jme3 alpha-3.
I cannot find the “definitive” way to proceed. I will study the problem a little bit more.
Thank you!
You can just use that class from SVN or upgrade to nightly/SVN builds instead of using alpha3.
ok thank you!
It’s seem’s we are working on the same idea … another minecraft fork gg - http://www.ohloh.net/p/bloxel
Currently we have the same problem to resolve … how can we implement an “open world” with caves etc. in JME3.
I think these guys solved the problem : http://ardorlabs.se/ArdorCraft/ – but how?