Jump to content

GUI label net rendered when parent mesh is not visible


alexoy
 Share

Recommended Posts

Hi all,

Is there a flag in a BJS GUI system to automatically disable rendering of the GUI labels when the mesh they are attached to is not visible?

 

Simple use case: you use labels to show user's names, and you shouldn't see the labels of the enemies which are not visible at the moment. Well.. because you shouldn't know where they are (behind the wall) :)

Link to comment
Share on other sites

Hiya A.

https://www.babylonjs-playground.com/#XCPP9Y#535

There's no simple boolean flag, AFAIK.  Lines 53-60 is a renderLoop wedge... that should work.

A smarter person might create a custom Observer/Notify thing... where label is observing _linkedMesh.isVisible.   When _linkedMesh.isVisible onValueChange triggers, handler sets the label.isVisible == _linkedMesh.isVisible.  BJS built-in observer polling system (is that what it is called?)  :)  ...would be doing the same work as that renderLoop thing.

*shrug*.  Hope this helps.  Stay tuned... others may have more/better comments.

Link to comment
Share on other sites

I like the idea!

As @Wingnut mentioned, we could add an observable that you can observe and react accordingly. 

But just to make sure: do you want something about mesh.isVisible or something about mesh not being in the camera frustum?

Link to comment
Share on other sites

@Deltakosh,

I mean whether I'm able to see the enemy directly, whether he is literally visible in front of my camera. While moving sometimes he is in front of me - then the label should be visible. If he goes behind the wall/house/etc - the label should disappear.

Testing shows, that being behind the second mesh doesn't make the first one "isVisible = false", so probably the answer to you question is using frustum.

Link to comment
Share on other sites

@Deltakosh, you mean even if in front of camera there is a small mesh behind the second bigger mesh, so not visible to the viewer, frustum calculations will state that both meshes are in the same visibility state just because mathematically they are in front of camera?

 

If Yes, what can I do then? I hope you agree that seeing the nickname of not visible enemy is bad

Link to comment
Share on other sites

I would avoid the above approach. But you should find the answer to your question in the following post:

This doesn't specifically answer your question, but with a little effort to apply to your specific needs, I believe the answer is there. 

DB

Link to comment
Share on other sites

Hi @dbawel,

I remember this post. Actually some answers are mine. What method do you suggest as a base? Because rays calculations could be even more expensive - you need to cast them on every frame for every label/enemy, then find whether there is another mesh in between. Also going through all frustum meshes and finding the closest or comparing the distances doesn't make any sense in my case.

 

But why you would avoid a "Occlusion Queries" method?

Link to comment
Share on other sites

@alexoy

Perhaps we're speaking of different methods when talking about "Occlusion Queries"; which I was also worried about firing too many rays. However, what I was eluding to as a possible solution is not to fire a ray every frame, but to fire a ray at intervals from the camera to a null which is a child of each enemy mesh - perhaps once every 60 frames. And if that ray collides with another object (not every mesh but perhaps defined as a member of a specific group), then the # of rays is minimal and I can't see any significant resources which would be used.

This is what I've done in the past on projects with different needs, but it worked well. Otherwise, it would be great to have a tools which makes this simpler as a function in the framework with parameters which could simply be set. That's the best I could think of for past projects.

DB

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...