RTS unit selection markers

Hi,

i was wondering if there is a good solution to draw the selection markes for units in an RTS.

For now i just add 2 more nodes to the scene (selection circle and healthbar). But even with an RigidBodyCombiner this solution is not really satisfying.

Is there a fast way to do this with shaders? Projetive texturing? decals?

Or any better ideas?

thx,

David

Incidentally I’ve done just that a few days ago. You will want a projected texture. Here is some very cheesy code that I have working right now:

class SelectionMarker():
    def __init__(self,projectTo,projectFrom):
        self.selectedObject = projectFrom
        self.tex = loader.loadTexture("models/selection.png")
        self.proj = render.attachNewNode(LensNode('proj'))
        self.lens = OrthographicLens()
        self.proj.node().setLens(self.lens)
        self.proj.reparentTo(render)
        self.proj.setPos(self.selectedObject.getX(), self.selectedObject.getX(), self.selectedObject.getZ()+1.5)
        self.proj.setHpr(0, -90, 0)
        self.tex.setWrapU(self.tex.WMClamp)
        self.tex.setWrapV(self.tex.WMClamp)
        self.tex.setBorderColor(Vec4(0.0, 0.0, 0.0, 0.0))
        self.ts = TextureStage('ts')
        self.ts.setSort(1)
        self.ts.setMode(TextureStage.MDecal)
        self.interval = LerpHprInterval(self.proj, 0.7, (360.0,-90.0,0.0), (0.0,-90.0,0.0))
        self.interval.loop()
        projectTo.projectTexture(self.ts, self.tex, self.proj)
        taskMgr.add(self.t_reposition,"repositionTask",sort=30)
        #tex.setScale(2.0)        

    def t_reposition(self,task):
        if (self.selectedObject):
            self.proj.setPos(self.selectedObject.getX(),self.selectedObject.getY(),self.selectedObject.getZ()+1.5)
        else:
            #self.hide()
            pass
        return task.cont

thx for your reply! I’ve tested your idea and it works, but unfortunately the performance is worse than using models + RigidBodyCombiner.

Also i can not project more than 6 textures… so i can only select 6 units. The other projections are not shown… strange.

a small hint: why don’t you reparent the ‘self.proj’ node to the ‘projectFrom’ node? So you can get rid of the ‘t_reposition’ task.

reparent… yeah, sometimes it’s so obvious. I have to make so many things work in such a small time that I don’t have time to think about individual optimization :slight_smile:

EDIT: no wait, now I remember. My tex is rotating and when I reparent the projector to the actor, the orientation will mess up. I.e. the projector rotates with the actor but it should not. That’s the whole reason why I just set the position.

Sorry for bumping, but a solution to the problem with parenting would be to insert a dummy node above the actor, then attach both the actor and projector to it. Rotation could be applied to the actor node and translation to the dummy node. In that way the projector node would rotate independently.

Cheers,
Thaago