from panda3d.core import *
from panda3d.direct import *
from direct.distributed.DistributedObjectOV import DistributedObjectOV
[docs]class DistributedCameraOV(DistributedObjectOV):
[docs] def __init__(self, cr):
DistributedObjectOV.__init__(self, cr)
self.parent = 0
self.fixtures = []
self.accept('refresh-fixture', self.refreshFixture)
[docs] def delete(self):
self.ignore('escape')
self.ignore('refresh-fixture')
DistributedObjectOV.delete(self)
[docs] def getObject(self):
return self.cr.getDo(self.getDoId())
[docs] def setCamParent(self, doId):
self.parent = doId
[docs] def setFixtures(self, fixtures):
self.fixtures = fixtures
[docs] def storeToFile(self, name):
f = open('cameras-%s.txt' % name, 'w')
f.writelines(self.getObject().pack())
f.close()
[docs] def unpackFixture(self, data):
data = data.strip().replace('Camera','')
pos,hpr,fov = eval(data)
return pos,hpr,fov
[docs] def loadFromFile(self, name):
self.b_setFixtures([])
f = open('cameras-%s.txt' % name, 'r')
for line in f.readlines():
pos,hpr,fov = self.unpackFixture(line)
self.addFixture([pos[0],pos[1],pos[2],
hpr[0],hpr[1],hpr[2],
fov[0],fov[1],
'Standby'])
f.close()
[docs] def refreshFixture(self, id, data):
pos,hpr,fov = self.unpackFixture(data)
fixture = self.fixtures[id]
fixture = [pos[0],pos[1],pos[2],
hpr[0],hpr[1],hpr[2],
fov[0],fov[1],
fixture[8]]
# distributed only
self.d_setFixtures(self.fixtures)
[docs] def b_setFixtures(self, fixtures):
self.getObject().setFixtures(fixtures)
self.setFixtures(fixtures)
self.d_setFixtures(fixtures)
[docs] def d_setFixtures(self, fixtures):
self.sendUpdate('setFixtures', [fixtures])
[docs] def addFixture(self, fixture, index = None):
if index is not None:
self.fixtures.insert(index, fixture)
else:
self.fixtures.append(fixture)
self.b_setFixtures(self.fixtures)
return self.fixtures.index(fixture)
[docs] def blinkFixture(self, index):
if index < len(self.fixtures):
fixture = self.fixtures[index]
fixture[6] = 'Blinking'
self.b_setFixtures(self.fixtures)
[docs] def standbyFixture(self, index):
if index < len(self.fixtures):
fixture = self.fixtures[index]
fixture[6] = 'Standby'
self.b_setFixtures(self.fixtures)
[docs] def testFixture(self, index):
if index < len(self.fixtures):
self.getObject().testFixture(index)
[docs] def removeFixture(self, index):
self.fixtures.pop(index)
self.b_setFixtures(self.fixtures)
[docs] def saveFixture(self, index = None):
"""
Position the camera with ~oobe, then call this to save its telemetry.
"""
parent = self.getObject().getCamParent()
pos = base.cam.getPos(parent)
hpr = base.cam.getHpr(parent)
return self.addFixture([pos[0], pos[1], pos[2],
hpr[0], hpr[1], hpr[2],
'Standby'],
index)
[docs] def startRecording(self):
self.accept('escape', self.stopRecording)
for fixture in self.fixtures:
fixture[6] = 'Recording'
self.b_setFixtures(self.fixtures)
[docs] def stopRecording(self):
self.ignore('escape')
for fixture in self.fixtures:
fixture[6] = 'Standby'
self.b_setFixtures(self.fixtures)