alexoy Posted May 31, 2018 Share Posted May 31, 2018 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) Quote Link to comment Share on other sites More sharing options...
Wingnut Posted June 1, 2018 Share Posted June 1, 2018 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. Quote Link to comment Share on other sites More sharing options...
Guest Posted June 1, 2018 Share Posted June 1, 2018 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? Quote Link to comment Share on other sites More sharing options...
alexoy Posted June 1, 2018 Author Share Posted June 1, 2018 @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. Quote Link to comment Share on other sites More sharing options...
Guest Posted June 1, 2018 Share Posted June 1, 2018 even frustum won't give you support for occlusion unfortunately Quote Link to comment Share on other sites More sharing options...
alexoy Posted June 2, 2018 Author Share Posted June 2, 2018 @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 Quote Link to comment Share on other sites More sharing options...
alexoy Posted June 2, 2018 Author Share Posted June 2, 2018 I've found out you have a thing named "Occlusion Queries" - is it good for my task or too expensive (there could be many players around)? Demo - http://www.babylonjs-playground.com/#QDAZ80#14 (2'nd sphere is always on top to make it easier to see what's happening) Quote Link to comment Share on other sites More sharing options...
dbawel Posted June 3, 2018 Share Posted June 3, 2018 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 Quote Link to comment Share on other sites More sharing options...
alexoy Posted June 3, 2018 Author Share Posted June 3, 2018 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? Quote Link to comment Share on other sites More sharing options...
dbawel Posted June 4, 2018 Share Posted June 4, 2018 @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 Quote Link to comment Share on other sites More sharing options...
alexoy Posted June 4, 2018 Author Share Posted June 4, 2018 @dbawel, and what can you say about http://www.babylonjs-playground.com/#QDAZ80#14 ? With "Occlusion Queries" I mean official docs with this topic. In this demo check also happens on every frame, but could be done once every 60 frames too, like in your example. In your opinion this way is much slower or why you don't like it? Quote Link to comment Share on other sites More sharing options...
dbawel Posted June 4, 2018 Share Posted June 4, 2018 @alexoy I misunderstood - this method from the PG scene should work efficiently. ? DB Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.