Frustum Culling + attachChild() problems

hi everyone!



I started making a small game with just pure LWJGL. I came pretty far, but then decided to switch to JME because of easier physics- and especially model-handeling. So now I’m trying to implement everything into jme, but I’m having some problems doing that:



I’m trying to get the terrain rendered, which consists of many objects. In my old version I just took the objects “near” the player and checked if they were in the frustum and then rendered them (so they got drawn for 1 game loop = 1 frame). Now in JME I don’t get along with the attachChild() and detachChild().

I tried attaching the important objects (near enough to player and in frustum) to the node. But I realised the game was kind of slow, because of course they stayed attached for ever.



Then I tried the following:

-detachAllChildren()-

-attach the important objects-

-RENDER-

-detachAllChildren()-

-attach the important objects-

-RENDER-



But it became even slower !!



Has anyone had a similiar problem? Or is there maybe an easy solution which I don’t know? I thought about detaching all the children maybe only every 10 frames or something, but I don’t know if that’s a good solution. Of course I can detach the children that don’t need to be rendered anymore, but I think this will be very expensive too if I do this every time (a lot of calculations and comparisons).



I hope someone can help. It would be very sad, if I would have to go back to plane lwjgl just because of a small problem like this ^^.

Don’t try to apply lwjgl knowledge to jME3, you don’t have to manually render anything in jME3. Best do the tutorials to see how jME3 works.

yes, I know… but I’m not rendering anything at all. I’m just attaching to nodes. With “render” I mean letting jME3 render it for me …

Why are you attaching and detaching them?

@clemo: Frustum Culling is done automatically in the game loop!

Yes the point of jme3 is that it keeps track of the world model or scene and the nodes are automatically culled as needed for each repaint depending on whether they are in the camera frustrum or not. You only need to add and remove stuff from the model whenever there is some change to your world, or if you are implementing some dynamic change like streaming the world from disk etc. A general optimization could be to bunch stuff in regional Nodes if you want the engine to automatically cull large amounts of nodes, although this is naturally only adviced for static nodes. And this is really only necessary if you get into many thousand nodes in your scene. Also look into geometry optimization to reduce a tree of equally textured nodes down to one mesh which greatly limits the amount of nodes that the engine has to process. I have used that with great results in my “play world”. :slight_smile:

Wow, thank you very much @ttrocha and @johncl :):):slight_smile:



I didn’t know that jme3 does frustum culling by its self. It is incredible !!

I left out all the frustum checking and stuff and simply attached all these nodes. It took a while to load, but then it worked perfectly… jme3 does everything automatically. This is great, I think I’m starting to fall in love ^^



But I noticed the automatic culling only renders thing that are completely inside the camera’s view frustum. How can I change it so that it also takes the ones that intersect?



Again, thank you very much… I didn’t think it would be this simple :wink:

It doesn’t just show them when they’re completely in. The bounds of your models seem to be wrong. Do you generate the meshes/geometry yourself?

@normen:

Ah yes, thank you! Some of my model bounds were wrong by 0.5 or 1.0 …



Great, I got everything working now. I am really beginning to like JME3…

Also very nice how fast I got help here :slight_smile:

with jme game writes itself

Yes you can use Mesh.updateBound() to have jME3 update the bound for you