selective motion trail

Buddies

I’ve try to make a selective motion trail based in motion trail sample. I try setCameraMasks but i failed.
I want make just 1 actor in scene have motion trial.

Some ideas?
Thanx

Motion trail uses a motion camera. (it might be same as the real camera - so you might have to change that) The idea is that you show everything in the main camera and only things you want blued to the motion blur camera.

Hi Tree

My try is based in motion trail sample who´s coming in Panda.

When i call


bufferCamera=base.makeCamera2d(base.win, sort=-10)
bufferCameraNode=NodePath("bufferCamera")
bufferCamera.reparentTo(bufferCameraNode)
bufferCameraNode.setDepthTest(0)
bufferCameraNode.setDepthWrite(0)
bufferCamera.node().getDisplayRegion(0).setClearDepthActive(0)

bufferCamera.node().setCameraMask(BitMask32.bit(1))
base.cam.node().setCameraMask(BitMask32.bit(0))

bufferTexture=Texture()
base.win.addRenderTexture(bufferTexture, GraphicsOutput.RTMTriggeredCopyTexture)
...

def bufferTask(task): 
   base.win.triggerCopy()
   return task.Cont

taskMgr.add(bufferTask, "bufferTask")

and after


frowney=loader.loadModel("models/frowney")
frowney.reparentTo(render)
frowney.setPos(2,6,0)
frowney.hprInterval(5, Vec3(360,0,0)).loop()
frowney.hide(BitMask32.bit(1))
frowney.show(BitMask32.bit(0))

ghostLayer=base.win.getTextureCard()
ghostLayer.reparentTo(bufferCameraNode)
ghostLayer.setTransparency(True)
ghostLayer.setColor(1,1,1,.99)

I have motion trail in everything in my scene, include the frowney… exactlly who´s i dont want be in motion trail (i try hide it with camera mask).

See in bufferTask? base.win.triggerCopy(). I don´t konw if there´s some way to base.win trigger a copy but based in another camera. Is just speculation … i really don´t know :confused:

Hope you get this figured out as I’d like to do this also.

Basically I want to have 1 actor in the scene (possibly under user control) leave motion trails.

Best case, it would be a property on my own “character” class (which holds the actor object and other stats about the character). I then turn on motion trails when and on whom I need them.

Well buddy, at moment i can´t figure out it :confused:
Someone have ideas?
Cheers

The MT sample renders the entire output of base.win to a texture, which are :

  1. all 2d scenegraphs
  2. full 3d scenegraph

To solve this, you’d need a separated buffer to render only the 3d scenegraph, using additional 3dcamera.

import os
from panda3d.core import *
from direct.actor.Actor import Actor
from direct.interval.IntervalGlobal import *
from direct.gui.OnscreenText import OnscreenText
import direct.directbase.DirectStart

camera.setPos(-9.20, -51.41, 41.32)
camera.setHpr(-9.94, -35.25, -3.01)
mat4=Mat4(camera.getMat())
mat4.invertInPlace()
base.mouseInterfaceNode.setMat(mat4)

TRAIL_MASK = BitMask32.bit(1)

class MotionTrails():
  def __init__(self):

      self.trailParent = NodePath('')
      if (base.win.getGsg().getCopyTextureInverted()):
          self.trailParent.setSz(-1)

      fbp = FrameBufferProperties(base.win.getFbProperties())
      clearColor = Vec4(1)
      self.sceneBuffer = base.win.makeTextureBuffer('',1024,1024,Texture(),0,fbp)
#       self.sceneBuffer.setClearColor(clearColor)

      dr = self.sceneBuffer.makeMonoDisplayRegion()
      dr.setClearColor(clearColor)
      self.sceneCam = base.makeCamera(self.sceneBuffer, lens=base.camLens)
      self.sceneCam.node().setCameraMask(TRAIL_MASK)
      dr.setCamera(self.sceneCam)

      self.sceneCard = self.sceneBuffer.getTextureCard()
      self.sceneCard.reparentTo(self.trailParent)
      self.sceneCard.setTransparency(1)
      self.sceneCard.setAlphaScale(.9)

      dr = self.sceneBuffer.makeMonoDisplayRegion()
      dr.setClearColor(clearColor)
      self.trailcam = base.makeCamera2d(self.sceneBuffer, lens=base.cam2d.node().getLens())
      self.trailcam.reparentTo(self.trailParent)
      dr.setCamera(self.trailcam)

      trailCard = self.sceneBuffer.getTextureCard()
      trailCard.reparentTo(render2d)
      trailCard.setTransparency(1)

      trailWait = .02
      self.trailSeq = Sequence(
        Func(self.sceneBuffer.setActive,0), Wait(trailWait),
        Func(self.sceneBuffer.setActive,1),
      )
      self.trailSeq.loop()

  def adjustWait(self,delta):
      dur = self.trailSeq[1].getDuration()
      self.trailSeq.remove(self.trailSeq[1])
      self.trailSeq.insert(1,Wait(dur+delta))
      self.trailSeq.setT(self.trailSeq.getT())

t = MotionTrails()
render.hide(TRAIL_MASK)

g = loader.loadTexture('maps/envir-treetrunk.jpg')
b = loader.loadModel('box')
b.reparentTo(render)
b.setPos(-.5,-.5,-.5)
b.flattenLight()
b.setScale(1000)
b.setTexture(g,1)
b.setTwoSided(1)

character = Actor('panda',{'walk':'panda-walk'5;)
character.loop('walk')
character.reparentTo(render)
character.showThrough(TRAIL_MASK)
char=character.find('**/+Character')
char.setY(-15)
char.setH(-90)
character.hprInterval(2,Vec3(-360,0,0),blendType='easeInOut').loop()

smileys = render.attachNewNode('')
smiley = loader.loadModel('smiley')
smiley.getChild(0).setY(-8)
for z in range(5):
    s = smiley.copyTo(smileys)
    s.setZ(z*3)
    s.hprInterval(2,Vec3(360,0,0)).loop()

def cycle():
    global trailingSmiley
    for s in smileys.getChildren(): 
        s.hide(TRAIL_MASK)
    trailingSmiley=(trailingSmiley+1)%smileys.getNumChildren()
    smileys.getChild(trailingSmiley).showThrough(TRAIL_MASK)

trailingSmiley = -1
cycle()

base.accept('escape', os._exit, [0])
base.accept('space', cycle)
base.accept('wheel_up', t.adjustWait, [.001]) 
base.accept('wheel_down', t.adjustWait, [-.001]) 
run()

Wow awesome :slight_smile:
I´ll test later.
Very thanx
:laughing:

Thanks ynjh_jo,
This works great!
I’ve modified some of the parameters in the class a bit to get it to run fast with my models but I did have 2 followup questions:

  1. I have a problem when I switch to Directx (I usually use openGL, but test it with dx as I can’t guarantee what my users will have). The entire scene just seems to get darker and there is no trail effect. Is there something specific to OpenGL capabilities in this code?

  2. I have enabled the trail on some player characters. Issue is I get the effect even when jut panning the camera around which is distracting. I’d like for the effect to be triggered only when the characters move (i.e.e change position). Is there an easy way to switch it on and off everytime they move. For movement, I have code similar to Roaming Ralph (move task) and also a moveTo function that uses intervals for movements (for NPCs)

I don’t.

Just hide/show it to the trail camera, that’s all.
Try adding this :

def togglePandaTrail():
    global pandaTrail
    pandaTrail = not pandaTrail
    if pandaTrail:
       character.showThrough(TRAIL_MASK)
    else:
       character.hide(TRAIL_MASK)

pandaTrail = 1

base.accept('enter', togglePandaTrail)

Thanks again, I’ve implemented the character.hide part and it’s working great.

My dx issues must be driver or something, so I’ll check on that.