CullHint - LOD Optimalization

Hello!

I’m using 9 level LoD for my scene objects (houses, towers and all rest except terrain which has it’s own LoD control).
I also wanna do smth like that: if model is too far (distance much higher than that one for 9 level), set it invisible.

So here’s part of code which get distance between the camera and spatial from another method, and apply index level to geom.
[java] if (index == 10) {
((Geometry)spatial).setCullHint(CullHint.Always);
hidden = true;
} else if (index < ((Geometry)spatial).getMesh().getNumLodLevels()) {
((Geometry)spatial).setLodLevel(index);
if (hidden = true) {
((Geometry)spatial).setCullHint(CullHint.Never);
hidden = false;
}
}[/java]
Also here you can see that 10 index. My models disappear after they reach distance over 400 which work exactly as I want but if I will move back to them they don’t appear back again. Any suggestions/tips?

in your if statement youre assigning the value true to hidden, probably not intended (use == instead of = to for comparison)

secondly, you dont really need the hidden variable, why not just use getCullHint() to see if its hidden or not?

as for the issue. its possible a spatial higher up in the scene graph has CullHint always and overriding what your lower down spatial is doing… but its hard to tell really there could be a number of things causing issues outside that little snipper of code.

Hmm, tried with == but still no effect. I put debug print:

[java]if (index == 10) {
((Geometry)spatial).setCullHint(CullHint.Always);
hidden = true;
System.out.println("Hiding: " + ((Geometry)spatial) + hidden);
} else if (index < ((Geometry)spatial).getMesh().getNumLodLevels()) {
((Geometry)spatial).setLodLevel(index);
if (hidden = true) {
System.out.println("Unhiding: " + ((Geometry)spatial) + hidden);
((Geometry)spatial).setCullHint(CullHint.Never);
hidden = false;
}
}[/java]

but now it print me only Unhiding and my mdoels disappear ; /.

Bad Kitty

if(variable == true)

Good Kitty

if(variable) 

As variable is already a boolean, reduced code complexity is always good.

@Empire Phoenix said: Bad Kitty [code]if(variable == true)[/code]

It can’t work coz not statement. I tried with = and without any =. Still confused lol. Here’s all class: http://pastebin.com/WGVwJK6C

Dunno is there problem with that fking hidden variable or with CullHint

I can gurantee you that the cullhint works fine for me, and behaves as expected, so the basic idea you have should work, so its probably the code.

If i read your code right, and a model has for example 2 lod levels,

i go away from it, it goes from 1 to 2, then stays there till 10 and hides
now if a go nearer, your numLod check keeps it hidden till i reach the 2lod level distance yes?

Yes, so LoD works fine, but if it disappear it don’t appear again.

is the setCullhint(Nevcer) path actually executed? Did you test with a system.out.println or similar?

Yup, it print me Never

what about all of the parent spatials?

if parent/grandparent/etc has cullhint = always then the child is culled even if its cullhint = never

Also, generally if you want to show/hide something then you’d use CullHint.Always and CullHint.Inherit… because then normal bounds-based frustum culling is done when something is visible.

LOD kinds of defeats the purpose if you are always drawing everything not ‘low level’ even when facing away. Frustum culling will give way more of a performance boost than that.