|
|
@@ -15,7 +15,6 @@ class DirectCameraControl(DirectObject):
|
|
|
notify = DirectNotifyGlobal.directNotify.newCategory('DirectCameraControl')
|
|
|
|
|
|
def __init__(self):
|
|
|
- self.camera = base.direct.camera # [gjeon] initially it will control base.direct.camera
|
|
|
# Create the grid
|
|
|
self.startT = 0.0
|
|
|
self.startF = 0
|
|
|
@@ -75,10 +74,6 @@ class DirectCameraControl(DirectObject):
|
|
|
self.useMayaCamControls = 0
|
|
|
self.altDown = 0
|
|
|
|
|
|
- # [gjeon] you can change which camera will be controlled
|
|
|
- def setCamera(self, camera):
|
|
|
- self.camera = camera
|
|
|
-
|
|
|
def toggleMarkerVis(self):
|
|
|
## if base.direct.cameraControl.coaMarker.isHidden():
|
|
|
## base.direct.cameraControl.coaMarker.show()
|
|
|
@@ -121,7 +116,6 @@ class DirectCameraControl(DirectObject):
|
|
|
self.spawnXZTranslate()
|
|
|
self.altDown = 1
|
|
|
elif not self.useMayaCamControls:
|
|
|
- print base.direct.dr.mouseX
|
|
|
# Where are we in the display region?
|
|
|
if ((abs(base.direct.dr.mouseX) < 0.9) and (abs(base.direct.dr.mouseY) < 0.9)):
|
|
|
# MOUSE IS IN CENTRAL REGION
|
|
|
@@ -190,7 +184,7 @@ class DirectCameraControl(DirectObject):
|
|
|
# Spawn the new task
|
|
|
t = Task.Task(self.XZTranslateOrHPanYZoomTask)
|
|
|
# For HPanYZoom
|
|
|
- t.zoomSF = Vec3(self.coaMarker.getPos(self.camera)).length()
|
|
|
+ t.zoomSF = Vec3(self.coaMarker.getPos(base.direct.camera)).length()
|
|
|
taskMgr.add(t, 'manipulateCamera')
|
|
|
|
|
|
def spawnXZTranslateOrHPPan(self):
|
|
|
@@ -211,7 +205,7 @@ class DirectCameraControl(DirectObject):
|
|
|
taskMgr.remove('manipulateCamera')
|
|
|
# Spawn new task
|
|
|
t = Task.Task(self.HPanYZoomTask)
|
|
|
- t.zoomSF = Vec3(self.coaMarker.getPos(self.camera)).length()
|
|
|
+ t.zoomSF = Vec3(self.coaMarker.getPos(base.direct.camera)).length()
|
|
|
taskMgr.add(t, 'manipulateCamera')
|
|
|
|
|
|
def spawnHPPan(self):
|
|
|
@@ -235,9 +229,9 @@ class DirectCameraControl(DirectObject):
|
|
|
return self.XZTranslateTask(state)
|
|
|
|
|
|
def XZTranslateTask(self, state):
|
|
|
- coaDist = Vec3(self.coaMarker.getPos(self.camera)).length()
|
|
|
+ coaDist = Vec3(self.coaMarker.getPos(base.direct.camera)).length()
|
|
|
xlateSF = (coaDist / base.direct.dr.near)
|
|
|
- self.camera.setPos(self.camera,
|
|
|
+ base.direct.camera.setPos(base.direct.camera,
|
|
|
(-0.5 * base.direct.dr.mouseDeltaX *
|
|
|
base.direct.dr.nearWidth *
|
|
|
xlateSF),
|
|
|
@@ -249,13 +243,12 @@ class DirectCameraControl(DirectObject):
|
|
|
|
|
|
def HPanYZoomTask(self, state):
|
|
|
# If the cam is orthogonal, don't rotate or zoom.
|
|
|
- if (hasattr(self.camera.node(), "getLens") and
|
|
|
- self.camera.node().getLens().__class__.__name__ == "OrthographicLens"):
|
|
|
- print "Currently, ortho can't zoom either"
|
|
|
+ if (hasattr(base.direct.camera.node(), "getLens") and
|
|
|
+ base.direct.camera.node().getLens().__class__.__name__ == "OrthographicLens"):
|
|
|
return
|
|
|
|
|
|
if base.direct.fControl:
|
|
|
- moveDir = Vec3(self.coaMarker.getPos(self.camera))
|
|
|
+ moveDir = Vec3(self.coaMarker.getPos(base.direct.camera))
|
|
|
# If marker is behind camera invert vector
|
|
|
if moveDir[1] < 0.0:
|
|
|
moveDir.assign(moveDir * -1)
|
|
|
@@ -275,7 +268,7 @@ class DirectCameraControl(DirectObject):
|
|
|
|
|
|
hVal = 0.5 * base.direct.dr.mouseDeltaX * base.direct.dr.fovH
|
|
|
|
|
|
- self.camera.setPosHpr(self.camera,
|
|
|
+ base.direct.camera.setPosHpr(base.direct.camera,
|
|
|
moveDir[0],
|
|
|
moveDir[1],
|
|
|
moveDir[2],
|
|
|
@@ -283,12 +276,12 @@ class DirectCameraControl(DirectObject):
|
|
|
0.0, 0.0)
|
|
|
if (self.lockRoll == True):
|
|
|
# flatten roll
|
|
|
- self.camera.setR(0)
|
|
|
+ base.direct.camera.setR(0)
|
|
|
|
|
|
return Task.cont
|
|
|
|
|
|
def HPPanTask(self, state):
|
|
|
- self.camera.setHpr(self.camera,
|
|
|
+ base.direct.camera.setHpr(base.direct.camera,
|
|
|
(0.5 * base.direct.dr.mouseDeltaX *
|
|
|
base.direct.dr.fovH),
|
|
|
(-0.5 * base.direct.dr.mouseDeltaY *
|
|
|
@@ -301,7 +294,7 @@ class DirectCameraControl(DirectObject):
|
|
|
taskMgr.remove('manipulateCamera')
|
|
|
# Set at markers position in render coordinates
|
|
|
self.camManipRef.setPos(self.coaMarkerPos)
|
|
|
- self.camManipRef.setHpr(self.camera, ZERO_POINT)
|
|
|
+ self.camManipRef.setHpr(base.direct.camera, ZERO_POINT)
|
|
|
t = Task.Task(self.mouseRotateTask)
|
|
|
if abs(base.direct.dr.mouseX) > 0.9:
|
|
|
t.constrainedDir = 'y'
|
|
|
@@ -311,9 +304,8 @@ class DirectCameraControl(DirectObject):
|
|
|
|
|
|
def mouseRotateTask(self, state):
|
|
|
# If the cam is orthogonal, don't rotate.
|
|
|
- if (hasattr(self.camera.node(), "getLens") and
|
|
|
- self.camera.node().getLens().__class__.__name__ == "OrthographicLens"):
|
|
|
- print "orthogonal don't rotate"
|
|
|
+ if (hasattr(base.direct.camera.node(), "getLens") and
|
|
|
+ base.direct.camera.node().getLens().__class__.__name__ == "OrthographicLens"):
|
|
|
return
|
|
|
# If moving outside of center, ignore motion perpendicular to edge
|
|
|
if ((state.constrainedDir == 'y') and (abs(base.direct.dr.mouseX) > 0.9)):
|
|
|
@@ -326,17 +318,17 @@ class DirectCameraControl(DirectObject):
|
|
|
deltaX = base.direct.dr.mouseDeltaX
|
|
|
deltaY = base.direct.dr.mouseDeltaY
|
|
|
if base.direct.fShift:
|
|
|
- self.camera.setHpr(self.camera,
|
|
|
+ base.direct.camera.setHpr(base.direct.camera,
|
|
|
(deltaX * base.direct.dr.fovH),
|
|
|
(-deltaY * base.direct.dr.fovV),
|
|
|
0.0)
|
|
|
if (self.lockRoll == True):
|
|
|
# flatten roll
|
|
|
- self.camera.setR(0)
|
|
|
+ base.direct.camera.setR(0)
|
|
|
self.camManipRef.setPos(self.coaMarkerPos)
|
|
|
- self.camManipRef.setHpr(self.camera, ZERO_POINT)
|
|
|
+ self.camManipRef.setHpr(base.direct.camera, ZERO_POINT)
|
|
|
else:
|
|
|
- wrt = self.camera.getTransform(self.camManipRef)
|
|
|
+ wrt = base.direct.camera.getTransform(self.camManipRef)
|
|
|
self.camManipRef.setHpr(self.camManipRef,
|
|
|
(-1 * deltaX * 180.0),
|
|
|
(deltaY * 180.0),
|
|
|
@@ -344,7 +336,7 @@ class DirectCameraControl(DirectObject):
|
|
|
if (self.lockRoll == True):
|
|
|
# flatten roll
|
|
|
self.camManipRef.setR(0)
|
|
|
- self.camera.setTransform(self.camManipRef, wrt)
|
|
|
+ base.direct.camera.setTransform(self.camManipRef, wrt)
|
|
|
return Task.cont
|
|
|
|
|
|
def spawnMouseRollTask(self):
|
|
|
@@ -352,12 +344,12 @@ class DirectCameraControl(DirectObject):
|
|
|
taskMgr.remove('manipulateCamera')
|
|
|
# Set at markers position in render coordinates
|
|
|
self.camManipRef.setPos(self.coaMarkerPos)
|
|
|
- self.camManipRef.setHpr(self.camera, ZERO_POINT)
|
|
|
+ self.camManipRef.setHpr(base.direct.camera, ZERO_POINT)
|
|
|
t = Task.Task(self.mouseRollTask)
|
|
|
t.coaCenter = getScreenXY(self.coaMarker)
|
|
|
t.lastAngle = getCrankAngle(t.coaCenter)
|
|
|
# Store the camera/manipRef offset transform
|
|
|
- t.wrt = self.camera.getTransform(self.camManipRef)
|
|
|
+ t.wrt = base.direct.camera.getTransform(self.camManipRef)
|
|
|
taskMgr.add(t, 'manipulateCamera')
|
|
|
|
|
|
def mouseRollTask(self, state):
|
|
|
@@ -369,7 +361,7 @@ class DirectCameraControl(DirectObject):
|
|
|
if (self.lockRoll == True):
|
|
|
# flatten roll
|
|
|
self.camManipRef.setR(0)
|
|
|
- self.camera.setTransform(self.camManipRef, wrt)
|
|
|
+ base.direct.camera.setTransform(self.camManipRef, wrt)
|
|
|
return Task.cont
|
|
|
|
|
|
def lockCOA(self):
|
|
|
@@ -395,7 +387,7 @@ class DirectCameraControl(DirectObject):
|
|
|
self.cqEntries = self.cqEntries[1:] + self.cqEntries[:1]
|
|
|
# Filter out object's under camera
|
|
|
nodePath = entry.getIntoNodePath()
|
|
|
- if self.camera not in nodePath.getAncestors():
|
|
|
+ if base.direct.camera not in nodePath.getAncestors():
|
|
|
# Compute new hit point
|
|
|
hitPt = entry.getSurfacePoint(entry.getFromNodePath())
|
|
|
# Move coa marker to new point
|
|
|
@@ -411,7 +403,7 @@ class DirectCameraControl(DirectObject):
|
|
|
if self.fLockCOA:
|
|
|
# COA is locked, use existing point
|
|
|
# Use existing point
|
|
|
- coa.assign(self.coaMarker.getPos(self.camera))
|
|
|
+ coa.assign(self.coaMarker.getPos(base.direct.camera))
|
|
|
# Reset hit point count
|
|
|
self.nullHitPointCount = 0
|
|
|
elif entry:
|
|
|
@@ -424,7 +416,7 @@ class DirectCameraControl(DirectObject):
|
|
|
if ((hitPtDist < (1.1 * dr.near)) or
|
|
|
(hitPtDist > dr.far)):
|
|
|
# Just use existing point
|
|
|
- coa.assign(self.coaMarker.getPos(self.camera))
|
|
|
+ coa.assign(self.coaMarker.getPos(base.direct.camera))
|
|
|
# Reset hit point count
|
|
|
self.nullHitPointCount = 0
|
|
|
else:
|
|
|
@@ -469,7 +461,7 @@ class DirectCameraControl(DirectObject):
|
|
|
|
|
|
def updateCoaMarkerSize(self, coaDist = None):
|
|
|
if not coaDist:
|
|
|
- coaDist = Vec3(self.coaMarker.getPos(self.camera)).length()
|
|
|
+ coaDist = Vec3(self.coaMarker.getPos(base.direct.camera)).length()
|
|
|
# Nominal size based on default 30 degree vertical FOV
|
|
|
# Need to adjust size based on distance and current FOV
|
|
|
sf = COA_MARKER_SF * coaDist * (base.direct.drList.getCurrentDr().fovV/30.0)
|
|
|
@@ -490,19 +482,19 @@ class DirectCameraControl(DirectObject):
|
|
|
|
|
|
def homeCam(self):
|
|
|
# Record undo point
|
|
|
- base.direct.pushUndo([self.camera])
|
|
|
- self.camera.reparentTo(render)
|
|
|
- self.camera.clearMat()
|
|
|
+ base.direct.pushUndo([base.direct.camera])
|
|
|
+ base.direct.camera.reparentTo(render)
|
|
|
+ base.direct.camera.clearMat()
|
|
|
# Resize coa marker
|
|
|
self.updateCoaMarkerSize()
|
|
|
|
|
|
def uprightCam(self):
|
|
|
taskMgr.remove('manipulateCamera')
|
|
|
# Record undo point
|
|
|
- base.direct.pushUndo([self.camera])
|
|
|
+ base.direct.pushUndo([base.direct.camera])
|
|
|
# Pitch camera till upright
|
|
|
- currH = self.camera.getH()
|
|
|
- self.camera.lerpHpr(currH, 0, 0,
|
|
|
+ currH = base.direct.camera.getH()
|
|
|
+ base.direct.camera.lerpHpr(currH, 0, 0,
|
|
|
CAM_MOVE_DURATION,
|
|
|
other = render,
|
|
|
blendType = 'easeInOut',
|
|
|
@@ -511,10 +503,10 @@ class DirectCameraControl(DirectObject):
|
|
|
def orbitUprightCam(self):
|
|
|
taskMgr.remove('manipulateCamera')
|
|
|
# Record undo point
|
|
|
- base.direct.pushUndo([self.camera])
|
|
|
+ base.direct.pushUndo([base.direct.camera])
|
|
|
# Transform camera z axis to render space
|
|
|
mCam2Render = Mat4(Mat4.identMat()) # [gjeon] fixed to give required argument
|
|
|
- mCam2Render.assign(self.camera.getMat(render))
|
|
|
+ mCam2Render.assign(base.direct.camera.getMat(render))
|
|
|
zAxis = Vec3(mCam2Render.xformVec(Z_AXIS))
|
|
|
zAxis.normalize()
|
|
|
# Compute rotation angle needed to upright cam
|
|
|
@@ -535,8 +527,8 @@ class DirectCameraControl(DirectObject):
|
|
|
self.camManipRef.setPos(self.coaMarker, Vec3(0))
|
|
|
self.camManipRef.setHpr(render, rotAngle, 0, 0)
|
|
|
# Reparent Cam to ref Coordinate system
|
|
|
- parent = self.camera.getParent()
|
|
|
- self.camera.wrtReparentTo(self.camManipRef)
|
|
|
+ parent = base.direct.camera.getParent()
|
|
|
+ base.direct.camera.wrtReparentTo(self.camManipRef)
|
|
|
# Rotate ref CS to final orientation
|
|
|
t = self.camManipRef.lerpHpr(rotAngle, orbitAngle, 0,
|
|
|
CAM_MOVE_DURATION,
|
|
|
@@ -556,14 +548,14 @@ class DirectCameraControl(DirectObject):
|
|
|
def centerCamIn(self, t):
|
|
|
taskMgr.remove('manipulateCamera')
|
|
|
# Record undo point
|
|
|
- base.direct.pushUndo([self.camera])
|
|
|
+ base.direct.pushUndo([base.direct.camera])
|
|
|
# Determine marker location
|
|
|
- markerToCam = self.coaMarker.getPos(self.camera)
|
|
|
+ markerToCam = self.coaMarker.getPos(base.direct.camera)
|
|
|
dist = Vec3(markerToCam - ZERO_POINT).length()
|
|
|
scaledCenterVec = Y_AXIS * dist
|
|
|
delta = markerToCam - scaledCenterVec
|
|
|
- self.camManipRef.setPosHpr(self.camera, Point3(0), Point3(0))
|
|
|
- t = self.camera.lerpPos(Point3(delta),
|
|
|
+ self.camManipRef.setPosHpr(base.direct.camera, Point3(0), Point3(0))
|
|
|
+ t = base.direct.camera.lerpPos(Point3(delta),
|
|
|
CAM_MOVE_DURATION,
|
|
|
other = self.camManipRef,
|
|
|
blendType = 'easeInOut',
|
|
|
@@ -573,14 +565,14 @@ class DirectCameraControl(DirectObject):
|
|
|
def zoomCam(self, zoomFactor, t):
|
|
|
taskMgr.remove('manipulateCamera')
|
|
|
# Record undo point
|
|
|
- base.direct.pushUndo([self.camera])
|
|
|
+ base.direct.pushUndo([base.direct.camera])
|
|
|
# Find a point zoom factor times the current separation
|
|
|
# of the widget and cam
|
|
|
- zoomPtToCam = self.coaMarker.getPos(self.camera) * zoomFactor
|
|
|
+ zoomPtToCam = self.coaMarker.getPos(base.direct.camera) * zoomFactor
|
|
|
# Put a target nodePath there
|
|
|
- self.camManipRef.setPos(self.camera, zoomPtToCam)
|
|
|
+ self.camManipRef.setPos(base.direct.camera, zoomPtToCam)
|
|
|
# Move to that point
|
|
|
- t = self.camera.lerpPos(ZERO_POINT,
|
|
|
+ t = base.direct.camera.lerpPos(ZERO_POINT,
|
|
|
CAM_MOVE_DURATION,
|
|
|
other = self.camManipRef,
|
|
|
blendType = 'easeInOut',
|
|
|
@@ -591,7 +583,7 @@ class DirectCameraControl(DirectObject):
|
|
|
# Kill any existing tasks
|
|
|
taskMgr.remove('manipulateCamera')
|
|
|
# Record undo point
|
|
|
- base.direct.pushUndo([self.camera])
|
|
|
+ base.direct.pushUndo([base.direct.camera])
|
|
|
# Calc hprOffset
|
|
|
hprOffset = VBase3()
|
|
|
if view == 8:
|
|
|
@@ -620,7 +612,7 @@ class DirectCameraControl(DirectObject):
|
|
|
self.camManipRef.setPosHpr(self.coaMarker, ZERO_VEC,
|
|
|
hprOffset)
|
|
|
# Scale center vec by current distance to target
|
|
|
- offsetDistance = Vec3(self.camera.getPos(self.camManipRef) -
|
|
|
+ offsetDistance = Vec3(base.direct.camera.getPos(self.camManipRef) -
|
|
|
ZERO_POINT).length()
|
|
|
scaledCenterVec = Y_AXIS * (-1.0 * offsetDistance)
|
|
|
# Now put the camManipRef at that point
|
|
|
@@ -629,7 +621,7 @@ class DirectCameraControl(DirectObject):
|
|
|
ZERO_VEC)
|
|
|
# Record view for next time around
|
|
|
self.lastView = view
|
|
|
- t = self.camera.lerpPosHpr(ZERO_POINT,
|
|
|
+ t = base.direct.camera.lerpPosHpr(ZERO_POINT,
|
|
|
VBase3(0, 0, self.orthoViewRoll),
|
|
|
CAM_MOVE_DURATION,
|
|
|
other = self.camManipRef,
|
|
|
@@ -643,15 +635,15 @@ class DirectCameraControl(DirectObject):
|
|
|
taskMgr.remove('manipulateCamera')
|
|
|
|
|
|
# Record undo point
|
|
|
- base.direct.pushUndo([self.camera])
|
|
|
+ base.direct.pushUndo([base.direct.camera])
|
|
|
|
|
|
# Coincident with widget
|
|
|
self.camManipRef.setPos(self.coaMarker, ZERO_POINT)
|
|
|
# But aligned with render space
|
|
|
self.camManipRef.setHpr(ZERO_POINT)
|
|
|
|
|
|
- parent = self.camera.getParent()
|
|
|
- self.camera.wrtReparentTo(self.camManipRef)
|
|
|
+ parent = base.direct.camera.getParent()
|
|
|
+ base.direct.camera.wrtReparentTo(self.camManipRef)
|
|
|
|
|
|
manipTask = self.camManipRef.lerpHpr(VBase3(degrees, 0, 0),
|
|
|
CAM_MOVE_DURATION,
|
|
|
@@ -662,7 +654,7 @@ class DirectCameraControl(DirectObject):
|
|
|
manipTask.setUponDeath(self.reparentCam)
|
|
|
|
|
|
def reparentCam(self, state):
|
|
|
- self.camera.wrtReparentTo(state.parent)
|
|
|
+ base.direct.camera.wrtReparentTo(state.parent)
|
|
|
self.updateCoaMarkerSize()
|
|
|
|
|
|
def fitOnWidget(self, nodePath = 'None Given'):
|
|
|
@@ -682,20 +674,20 @@ class DirectCameraControl(DirectObject):
|
|
|
centerVec = Y_AXIS * camY
|
|
|
|
|
|
# Where is the node relative to the viewpoint
|
|
|
- vWidget2Camera = base.direct.widget.getPos(self.camera)
|
|
|
+ vWidget2Camera = base.direct.widget.getPos(base.direct.camera)
|
|
|
|
|
|
# How far do you move the camera to be this distance from the node?
|
|
|
deltaMove = vWidget2Camera - centerVec
|
|
|
|
|
|
# Move a target there
|
|
|
try:
|
|
|
- self.camManipRef.setPos(self.camera, deltaMove)
|
|
|
+ self.camManipRef.setPos(base.direct.camera, deltaMove)
|
|
|
except Exception:
|
|
|
self.notify.debug
|
|
|
|
|
|
- parent = self.camera.getParent()
|
|
|
- self.camera.wrtReparentTo(self.camManipRef)
|
|
|
- fitTask = self.camera.lerpPos(Point3(0, 0, 0),
|
|
|
+ parent = base.direct.camera.getParent()
|
|
|
+ base.direct.camera.wrtReparentTo(self.camManipRef)
|
|
|
+ fitTask = base.direct.camera.lerpPos(Point3(0, 0, 0),
|
|
|
CAM_MOVE_DURATION,
|
|
|
blendType = 'easeInOut',
|
|
|
task = 'manipulateCamera')
|
|
|
@@ -725,7 +717,7 @@ class DirectCameraControl(DirectObject):
|
|
|
# Spawn a task to move the widget
|
|
|
t = base.direct.widget.lerpPos(Point3(centerVec),
|
|
|
CAM_MOVE_DURATION,
|
|
|
- other = self.camera,
|
|
|
+ other = base.direct.camera,
|
|
|
blendType = 'easeInOut',
|
|
|
task = 'moveToFitTask')
|
|
|
t.setUponDeath(lambda state: taskMgr.remove('stickToWidget'))
|