Hi Folks,
I’d like to create an animation of various objects moving around in front of the camera, sometimes changing their identity (loading a new model).
I got a single model to move in front of the cam by just abusing a code example from the tutorial, but I cannot get models to switch within the task loop.
I’ll post the buggy code, maybe you can see what I am trying to do and give me a pointer to the solution:
from math import pi, sin, cos
from direct.showbase.ShowBase import ShowBase
from direct.task import Task
p3dApp = ShowBase()
m = loader.loadModel("FOO.egg")
m.reparentTo(render)
m.setScale(15.0, 15.0, 15.0)
m.setHpr(m, 90.0,-90.0,0.0)
def moveCam(task):
if task.time%10 < 0.01:
scale = m.getScale()
pos = m.getPos()
hpr = m.getHpr()
# Here i want to remove the old m and insert a new one.
m.detachNode()
newM = random.choice(["FOO.egg","BAR.egg"])
m = loader.loadModel(newM)
m.reparentTo(render)
m.setPos(pos)
m.setHpr(hpr)
m.setScale(scale)
angleDegrees = task.time * 16.0
angleRadians = angleDegrees * (pi / 180.0)
p3dApp.camera.setPos(20 * sin(angleRadians), -20.0 * cos(angleRadians), 3)
p3dApp.camera.setHpr(angleDegrees, 0, 0)
return Task.cont
p3dApp.taskMgr.add(moveCam, "moveCam")
p3dApp.run()
Thanks in advance.
Best
Robert