How to get the CardMaker pos?

I use this function to display one frame image. But when I try to getMat or getPos, the card return
as if it is on (0,0,0)

def create_image(self, frame, s_to_t=None):
        if s_to_t is None:
            s_to_t = np.eye(4)
        height, width = frame.shape[:2]
        cm = CardMaker('card')
        p1 = LVector3(*np.matmul(s_to_t, np.array([-width / 2, height, 0, 1]))[:3]) # 
        p2 = LVector3(*np.matmul(s_to_t, np.array([width / 2, height, 0, 1]))[:3])
        p3 = LVector3(*np.matmul(s_to_t, np.array([width / 2, 0, 0, 1]))[:3])
        p4 = LVector3(*np.matmul(s_to_t, np.array([-width / 2, 0, 0, 1]))[:3])
        cm.setFrame(p4, p3, p2, p1) # ll, lr, ur, ul  # vertical flip

        card = self.render.attachNewNode(cm.generate())
        tex = Texture()


        tex.setup2dTexture(width, height, Texture.T_unsigned_byte, Texture.F_rgba8)
        frame=rgb2rgba(frame)
        buf = frame.tobytes()
        tex.setRamImage(buf)
        card.setTexture(tex)
        card.hide()
        card.setTransparency(TransparencyAttrib.M_alpha)
        # card.setMat(self.np4ToM4(s_to_t))   # if I set the mat, I can get the Mat, but the frame display at another position
        return card

Greetings, and welcome to the forum! I hope that you find your time here to be positive! :slight_smile:

As to your question… Well, looking at your code, I don’t see anything that sets the position of the card being produced by the CardMaker, and the default position for a node is (0, 0, 0), so indeed, that’s what I’d expect to be reported by “getPos”.

That is to say: Calling “getPos” (or “getMat”) is indeed the way to find the position of a card made by CardMaker–as with any NodePath. It’s just that your card is in fact at (0, 0, 0), and thus that’s the value reported by those methods.

Thank you very much, I solved this problem which was caused by setting Mat to the texture while not the card.

1 Like