Why is JME culling models when they are still on the screen?

JMonkeyEngine is culling the towers, even though they are still on the screen.

Setting the CullHint to NEVER will “fix” the problem, however the performance impact is huge.

How can I solve this problem?

If JME is culling them then it means their bounding shape is messed up.

Though from your gif it seems like it may be a near/far plane issue but then I don’t know why your ground isn’t getting clipped.

Either way, we can’t tell how long your piece of string is without holding it in our hands.

Is definitely not a near/far plane issue.

How do I add a bounding box?

You don’t.

The point is that if JME is clipping them then their world bounds is somewhere they aren’t.

Since we can’t see any of your code we can only take random shots in the dark as to why that happens. They seem to be being culled based on distance which is why I thought it might be a near/far plane issue.

At any rate, we have none of the information necessary to help. Your best bet is to try to reproduce it in a single-class test case. When that test case works fine then you can figure out what’s different about your code.

Edit: actually, given that they still show their shadows it could be some weird viewport setup issue, too. Hard to say without code or more information.

What information do you need to help solve the issue? I don’t really feel any closer to knowing what the problem is, other than that JME believes that they’re not in the viewport anymore.

Barring that: all of your code… but we’re unlikely to want to go through all of that to find your issue when you should either a) be able to reproduce it in a simple test case, or b) fail to reproduce it in a simple test case in which case you will have something to use to find the issue yourself (devil is in the differences).

Strictly speaking, it’s not the viewport but the camera view frustum.

@pspeed I simply don’t have time to have to set up a test case for every minor issue, so I am going to have to set the cullhint to NEVER and just leave it at that for now. Thank you for the help, maybe in future I can investigate into the problem further.

Another thing you can try is to add some debug logging or printlns to show the world bounds of the towers. That may clue you into what the issue is also.

Edit: it’s also strange that your labels seem to lag the towers. Probably unrelated but it is a sign that your setup is unconventional.

Nah, he’s probably just doing the getScreenCoordinates thing before he moves the camera in each frame so there’s a 1 frame lag. I used to have the same problem with my icons until I moved the camera and icon updates into simpleRender.

No idea what could have caused this odd culling though.

I know he said it’s not, but we’ve seen no code and what pspeed said is the thing that instantly comes to mind


I use the following camera code:

Quaternion qua = new Quaternion();
qua.lookAt(new Vector3f(0, -1f, 0).normalize(), new Vector3f(0, 1, 0));

I’m not sure if this is the problem. I do notice that if I use:

Quaternion qua = Quaternion.DIRECTION_Z;

Objects do not get culled. Even if the tower is at the edge of the screen then I can still see it (even if the flag is just poking up). However of course that is facing the wrong way as i want the camera to look down.

It seems the lookAt() method is the problem? Do you have any suggestions?

Trying normalizing the quaternion after the lookAt(). It’s weird, though.

Have you tried setting the up vector to -UNIT_Z?
Usually the look direction and the up are perpendicular or at least not the same.

In your Code, we cant use the up vector to Set the Rotation along the looking direction.

Up should Simply be the Top of your screen so ±Z. X would also bei possible but that would be like 90 degrees rotated .

Plus you dont have to normalize unit vectors, they are already normalized (of length 1)



In other words, I believe we have our answer. The camera culling is normalizing the quaternion. In other words, the camera was looking at the non-normalized angle, but the culling was still occurring as if it was normalized.

By using:

Quaternion qua = new Quaternion();
qua.lookAt(new Vector3f(0, -0.8f, 0.5f), new Vector3f(0, 1, 0));

I can duplicate the same camera angle as the non-normalized, only this time I do not have a culling problem.

Well… Once the towers disappears off the screen, the shadow decides to disappear! I can’t win, can I? But at least we’ve found the problem and solution to this issue now. :slight_smile:

Thanks for the help all.

Normalizing shouldn’t change the direction, I think… at least not by much (unless it’s a very bad quaternion). It should only renormalize the 4D vector to make it a valid quaternion again.

Looking at the code, lookAt() shouldn’t produce bad quaternions either.

Edit: For example, print the quaternion before and after normalization.

1 Like