Icons as placeholders for far objects ?

Hi all,

I’m trying to do something that would be useful for many applications : giving objects icons that will be visible instead of the object itself when it is too far and it onscreen dimensions shrink under a given number of pixels…

For the moment, I’ve searched the forums and help, and found nothing about this particular subject.

The path I think of would be composed of 2 phases :

  • Computing the onscreen position and size of an object,
  • Replacing the object with its fixed-onscreen-size icon.

First phase could involve the bounding sphere and the perspective projection to get an onscreen bounding circle with center and radius. A little math could do the trick, but maybe there’s a function somewhere that does it already ?

Second phase could either use billboards or GUI elements, whichever is handier. Placing a billboard is easy but sizing it would be a mess, GUI elements are pre-sized but placing it wouldn’t be easy. So which one would you choose ?

I’ll keep on searching, but as it may be of use by many, if someone has already solved it, it may be good to have it posted somewhere on the forums…

Thanks for any hint and read you soon !

Neat idea, could be really cool if you drew a bounding box with the line drawing class…

Hmm, correct me if I’m wrong but placing a 2d object (gui elements) to the position of 3d objects is really easy, panda has the “setPos relative to” argument, aka:

guiNp.setPos(objectNp, x, y, z)

that set’s the gui objects position relative to the 3d objects position, so they’ll line up properly, I think anyway. Lmme know if it works :wink:


Hi powerpup118,

Thanks a lot, already a good element of answer ! Along with hints I’ve found about OnscreenImage, that may do the trick for the display part, either with OnscreenImage or a similar GUI elements.

Now the size part. I’ll search more in depth into the forum to find something like that…

Have you seen LODNode? It sounds like the sort of thing you’re talking about. You still have to compute for yourself the distance at which the alternate version should be switched in, but once you put both (or all) versions of your model under the LODNode with the appropriate switch distances set up, it will automatically render the appropriate one according to the distance from the camera.

For making a card of the appropriate size, you could indeed use OnscreenImage, but CardMaker might be easier as OnscreenImage is really intended for GUI elements. You could make it billboard with nodePath.setBillboardAxis(), but note that billboards tend to be more expensive than the polygons they replace.


Hi drwr,

Thanks for your answer !

I’ll see for LODNode and CardMaker properties and maybe test both, then choose one.

At first sight, CardMaker could be well suited, as I don’t see how to address the dimension issue with LODNode.

Excuse me for asking…Do you mean to put a 2d object other the far unseen 3d object??

[size=150]If[/size] so…you may face a problem about the shape of the 3d model when rendering it in 2d

[size=150]elif[/size] I get a wrong conclusion about your idea then could you give just an example in a game or a software that do that to just imagine the idea

Thanks and good luck

Hi D_A_M_H,

Thanks for the suggestion, I’ll try to explain better. For now I’ve got no game example. Some space sims should do that, but I don’t remember clearly on any.

I just intend to put an icon at the position of the object. When the object is, say, more than 32 px wide on the screen, it’s displayed as 3D, when it’s less than 32 px wide, the 3D model is invisible and it is replaced by a simple icon.

And in the IF, what’s the issue I would face ? Thanks in advance for any hints ^-^

I thought that:
when the 3d model is less than 32px and it becomes invisible then you will replace it with a 2d icon has its same shape (not a 3d icon) so the problem you face is that if you reparent this model to render2d or aspect2d then the figure of the model will be distorted and will not be good at all…Am I right about explaining the idea cause I didn’t see the idea before (maybe because I’m new in real programing)
Thanks for replaying

Hi D_A_M_H,

Thanks for the precision. But I’m not going to reparent anything.

First, a tree of non-graphics objects will store all orbital objects properties. I’ll maintain a parallel tree of 3D models and a list of 2D icons. Each orbital object will have a 3D object and an icon among it properties.

So when the orbital object’s 3D model will be drawn larger than 32px, I’ll just True its Visible attribute and False the associated icon’s Visible attribute. When it’ll become smaller, I’ll invert the booleans and the icon will appear in place of the 3D model.

However, it makes me think about one possible issue. I may have to manage the icons’ z-orders so that they keep the same z-order than the 3D models.

I understood what you seek to but:
should you compare the position of the camera to the position of the 3d model…if the camera get away from the 3d model then the 3d model will be far so that it couldn’t be seen

Using LOD would be way simpler and more efficient than any positioning calculations, IMHO.

If you persist on sprites, why don’t you define them as the lowest LOD?