[SOLVED]Attaching object/image to the camera?

Hello,

I’d like to display an object in front of the camera and have that object move together with the camera. In other words, it always needs to be in front of the camera. I think I need to reparent it to the camera somehow.

Could someone help please?

object.reparentTo(base.cam)
object.setPos(5, 0, 0)

That should do the trick :slight_smile:

EDIT: Post #151 - a palindrome :slight_smile:

Hm, I must be missing something. No error is displayed, yet no model is rendered either.

Here is part of the code snippet:

        self.accept("t", self.pressp)

    def pressp(self):
        self.Actor1= Actor("models/model01",
                                {"walkanim": "models/model01"})
        self.Actor1.reparentTo(self.render)
        self.Actor1.setPlayRate(2, "walkanim")
        self.Actor1.loop("walkanim")
        self.Actor1.reparentTo(base.cam)
        self.Actor1.setPos(5, 0, 0)

Should I or shouldn’t I include reparentTo(self.render)?

BTW the model renders OK when I just add it without trying to reparent to the camera. The file is included in the proper folder, all that. In other words the following code works alright:

        self.accept("t", self.pressp)

    def pressp(self):
        self.Actor1= Actor("models/model01",
                                {"walkanim": "models/model01"})
        self.Actor1.reparentTo(self.render)
        self.Actor1.setPlayRate(2, "walkanim")
        self.Actor1.loop("walkanim")
        self.Actor1.setPos(450, -200, 20)

FYI the model and the animation is part of one file, which seems to work.

i am pretty sure that this line moves the model out of the cameras view by moving it right. try moving it in front.

How? :laughing:

Whatever I do, nothing seems to be rendered. As you point out, the object is probably out of the camera’s view.

The only solution which I can think of is to play around with base.camera.getX() getY() coords as well as heading. Or am I mistaken?

Hm, I think I know what the problem is. I basically want the object to start out of the camera’s view and the animation will bring it into the view.

For whatever reason Panda doesn’t seem to render the object if its starting position is outside of the camera’s view.

Any ideas what I could do?

Here is the code snippet:

    def pressp(self):
        self.Actor1= Actor("models/model01",
                                {"walkanim": "models/model01"})
        self.Actor1.reparentTo(self.render)
        self.Actor1.setPlayRate(2, "walkanim")
        self.Actor1.loop("walkanim")
        #self.Actor1.reparentTo(base.cam)
        self.Actor1.setPos(base.camera.getX(), (base.camera.getY() + 20), 20)

Notice the # in the reparentTo camera line. As it is now, the object will appear in front of the camera (it will not follow the camera of course). And as I walk close to the object it keeps disappearing.

Well, it’s kind of strange to expect to see something that’s outside of the camera’s field of view :wink:.

When ThomasEgi told you to move the object forward, he meant moving it on the Y axis. In Panda, Y is front/back, X is left/right and Z is up/down.

node.reparentTo(base.camera) # or base.cam
node.setPos(Vec3(0, 2, 0))

and your object should be visible. Assuming, obviously, that it’s not large enough for the camera to be stuck inside it in this setup and so on.

Also, and this is a bit subtle, when you have an actor’s animation responsible for moving it in front of the camera, it’s true that Panda won’t necessarily make it visible when it gets there. The reason for this is complicated but has to do with the automatic bounding boxes that Panda uses to perform view-frustum culling.

To work around it, you have to tell Panda not to perform view-frustum culling on your actor. To do this, do:

actor.node().setBounds(OmniBoundingVolume())
actor.node().setFinal(True)

David

Thank you both. Yes, both issues need to be addressed to have it solved.

I seem to struggle with the proper syntax to disable view-frustum culling. Could you please help?

The following code works fine:

    def pressp(self):
        self.Actor1= Actor("models/model01",
                                {"walkanim": "models/model01"})
        self.Actor1.reparentTo(self.render)
        self.Actor1.setPlayRate(2, "walkanim")
        self.Actor1.play("walkanim")
        self.Actor1.reparentTo(base.cam)
        self.Actor1.setPos(0, 15, 0)

Notice that if I input anything lower than 15, the object is not rendered.

And here is the code, where I try to disable view-frustum culling:

    def pressp(self):
        self.Actor1= Actor("models/model01",
                                {"walkanim": "models/model01"})
        self.Actor1.reparentTo(self.render)
        self.Actor1.setPlayRate(2, "walkanim")
        self.Actor1.play("walkanim")
        self.Actor1.setPos(base.camera.getX(), (base.camera.getY() + 20), 20)
        self.Actor1.node().setBounds(OmniBoundingVolume())
        self.Actor1.node().setFinal(True)

It says global name OmniBoundingVolume() not defined.

You need to import OmniBoundingVolume from panda3d.core. At the top of your file, put either this:

from panda3d.core import OmniBoundingVolume

or this:

from panda3d.core import *

The second form will bring in almost all of the Panda3D symbols so you don’t have to explicitly import anything else you might want to use.

David

Wow, works like a charm! Many thanks.

We can consider this problem solved.

I’d like to comment that it’s probably a poor practice to use an Actor’s animation to move it around. You’ll have your actors wandering away from the coords that they will report if you getPos(), and that can make coding any sorts of interaction very difficult. Also any collision nodes you reparent to them won’t move with them unless you reparent them to exposed joints. I’m sure there area a bunch of other issues that could crop up as well.

You’re much better off having the model stay in the same place relative to the root/origin in the animations, and then move the actor around with setPos() instead. It can sometimes be tricky to get the amount of movement to match the animation, but it’s worth the effort.

Good point. Thanks for this comment, something to keep in mind.

I didn’t play around with actors in this particular example. I wanted to display a menu not with just OnScreenImage, but make it more dynamic. The manu sort of slides in in the animation.

It works well, yet the quality of the image rendered is worse than the one displayed using OnscreenImage.