[EDIT] The original main question asked in this post has been answered. I’ve replaced it with two new questions, which can be found in the latest post.
Hi, I made a little test program where the camera follows an actor or possibly a 2D actor (just a sprite printed on a billboard card) around while the actor moves along a set interval. The camera moves smoothly, but the actor is a little glitchy visually. I was wondering if anyone could shed light on if or how it’s possible to fix it.
[SOLVED] Basically, once in a while (say, about every 3 seconds) the image of the moving actor kind of stutters left or right a little, like it’s being drawn in a slightly incorrect place for a split moment before it corrects. This happens even when I’m using a 3D model, although it’s more noticeable with a 2D one. Is there any particular reason I’m getting that graphical glitch? I’m using an i5-2500k CPU with a solid, recent model of video card, so presumably it’s not an issue of processing power.
Also, when I was using a specific test image (it’s Google’s first hit for Mario), the top of Mario’s mustache against the rest of his body gave an excellent example of that awkward, “swimming pixels” redrawing effect you see where a 3D object is moving away against a backdrop without anti-aliasing… except that it’s happening here on a 2D sprite. I’m assuming this has to do with the yresolution=600 in LoadImageAsPlane, but I can’t find a better way to scale down the texture, and in fact I can’t figure out why it starts out so big to begin with.
Sample program:
import sys, os
from direct.showbase.ShowBase import ShowBase
from direct.task import Task
from direct.actor.Actor import Actor
from direct.interval.IntervalGlobal import Sequence
from panda3d.core import Point3, NodePath, CardMaker, TransparencyAttrib, Texture, Vec4, Filename
GFX_PATH = Filename.fromOsSpecific(os.path.dirname(sys.argv[0]) + '/')
def LoadImageAsPlane(filepath, yresolution = 600):
"""Currently expects to be given a pre-padded sprite that has power-of-two dimensions, although the Mario sprite mentioned works fine. Copied from existing Panda3D snippet by preusser."""
tex = loader.loadTexture(filepath)
tex.setBorderColor(Vec4(0,0,0,0))
tex.setWrapU(Texture.WMBorderColor)
tex.setWrapV(Texture.WMBorderColor)
cm = CardMaker(str(filepath) + ' card')
cm.setFrame(-tex.getOrigFileXSize(), tex.getOrigFileXSize(), -tex.getOrigFileYSize(), tex.getOrigFileYSize())
card = NodePath(cm.generate())
card.setTexture(tex)
card.setScale(card.getScale()/ yresolution)
card.flattenLight()
return card
class MyApp(ShowBase):
def __init__(self):
ShowBase.__init__(self)
base.disableMouse()
self.environ = self.loader.loadModel("models/environment")
self.environ.reparentTo(self.render)
self.environ.setScale(0.25, 0.25, 0.25)
self.environ.setPos(-8, 42, 0)
self.camera.setPos(14, 12, 8)
self.taskMgr.add(self.LookAtActorTask, 'LookAtActorTask')
# Comment out one or the other to test.
#self.Use3dActor()
self.Use2dActor()
self.MakeActorMove()
def Use3dActor(self):
self.actor = Actor('panda-model')
self.actorZ = 3
#self.actor.setPos(0, 0, self.actorZ)
self.actor.setScale(.01, .01, .01)
self.actor.reparentTo(self.render)
def Use2dActor(self):
self.actor = LoadImageAsPlane(GFX_PATH + 'sprite.png')
self.actor.setTransparency(TransparencyAttrib.MAlpha)
self.actor.setBillboardAxis()
#self.actor.setBillboardPointWorld()
self.actorZ = 3.6
#self.actor.setPos(0, 0, self.actorZ)
self.actor.reparentTo(self.render)
def MakeActorMove(self):
actorPosInterval1 = self.actor.posInterval(6,
Point3(0, -8, self.actorZ),
startPos=Point3(0, 8, self.actorZ))
actorPosInterval2 = self.actor.posInterval(6,
Point3(0, 8, self.actorZ),
startPos=Point3(0, -8, self.actorZ))
self.actorPace = Sequence(actorPosInterval1, actorPosInterval2, name='ActorPace')
self.actorPace.loop()
def LookAtActorTask(self, task):
self.camera.lookAt(self.actor)
return Task.cont
app = MyApp()
app.run()