mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 09:52:27 -04:00
*** empty log message ***
This commit is contained in:
parent
be2b62c779
commit
9b44311ec2
@ -4,9 +4,8 @@ CAM_MOVE_DURATION = 1.0
|
|||||||
Y_AXIS = Vec3(0,1,0)
|
Y_AXIS = Vec3(0,1,0)
|
||||||
|
|
||||||
class DirectCameraControl(PandaObject):
|
class DirectCameraControl(PandaObject):
|
||||||
def __init__(self, direct):
|
def __init__(self):
|
||||||
# Create the grid
|
# Create the grid
|
||||||
self.direct = direct
|
|
||||||
self.chan = direct.chan
|
self.chan = direct.chan
|
||||||
self.camera = self.chan.camera
|
self.camera = self.chan.camera
|
||||||
self.orthoViewRoll = 0.0
|
self.orthoViewRoll = 0.0
|
||||||
@ -31,19 +30,19 @@ class DirectCameraControl(PandaObject):
|
|||||||
# Hide the marker for this kind of motion
|
# Hide the marker for this kind of motion
|
||||||
self.coaMarker.hide()
|
self.coaMarker.hide()
|
||||||
# See if the shift key is pressed
|
# See if the shift key is pressed
|
||||||
if (self.direct.fShift):
|
if (direct.fShift):
|
||||||
# If shift key is pressed, just perform horiz and vert pan:
|
# If shift key is pressed, just perform horiz and vert pan:
|
||||||
self.spawnHPPan()
|
self.spawnHPPan()
|
||||||
else:
|
else:
|
||||||
# Otherwise, check for a hit point based on
|
# Otherwise, check for a hit point based on
|
||||||
# current mouse position
|
# current mouse position
|
||||||
# And then spawn task to determine mouse mode
|
# And then spawn task to determine mouse mode
|
||||||
numEntries = self.direct.iRay.pickGeom(
|
numEntries = direct.iRay.pickGeom(
|
||||||
render,chan.mouseX,chan.mouseY)
|
render,chan.mouseX,chan.mouseY)
|
||||||
# Filter out hidden nodes from entry list
|
# Filter out hidden nodes from entry list
|
||||||
indexList = []
|
indexList = []
|
||||||
for i in range(0,numEntries):
|
for i in range(0,numEntries):
|
||||||
entry = self.direct.iRay.cq.getEntry(i)
|
entry = direct.iRay.cq.getEntry(i)
|
||||||
node = entry.getIntoNode()
|
node = entry.getIntoNode()
|
||||||
if node.isHidden():
|
if node.isHidden():
|
||||||
pass
|
pass
|
||||||
@ -55,7 +54,7 @@ class DirectCameraControl(PandaObject):
|
|||||||
# Start off with first point
|
# Start off with first point
|
||||||
minPt = indexList[0]
|
minPt = indexList[0]
|
||||||
# Find hit point in camera's space
|
# Find hit point in camera's space
|
||||||
hitPt = self.direct.iRay.camToHitPt(minPt)
|
hitPt = direct.iRay.camToHitPt(minPt)
|
||||||
coa.set(hitPt[0],hitPt[1],hitPt[2])
|
coa.set(hitPt[0],hitPt[1],hitPt[2])
|
||||||
coaDist = Vec3(coa - self.zeroPoint).length()
|
coaDist = Vec3(coa - self.zeroPoint).length()
|
||||||
# Check other intersection points, sorting them
|
# Check other intersection points, sorting them
|
||||||
@ -63,7 +62,7 @@ class DirectCameraControl(PandaObject):
|
|||||||
if len(indexList) > 1:
|
if len(indexList) > 1:
|
||||||
for i in range(1,len(indexList)):
|
for i in range(1,len(indexList)):
|
||||||
entryNum = indexList[i]
|
entryNum = indexList[i]
|
||||||
hitPt = self.direct.iRay.camToHitPt(entryNum)
|
hitPt = direct.iRay.camToHitPt(entryNum)
|
||||||
dist = Vec3(hitPt - self.zeroPoint).length()
|
dist = Vec3(hitPt - self.zeroPoint).length()
|
||||||
if (dist < coaDist):
|
if (dist < coaDist):
|
||||||
coaDist = dist
|
coaDist = dist
|
||||||
@ -287,7 +286,7 @@ class DirectCameraControl(PandaObject):
|
|||||||
taskMgr.spawnTaskNamed(t, 'manipulateCamera')
|
taskMgr.spawnTaskNamed(t, 'manipulateCamera')
|
||||||
|
|
||||||
def XZTranslateOrHPPanTask(self, state):
|
def XZTranslateOrHPPanTask(self, state):
|
||||||
if self.direct.fShift:
|
if direct.fShift:
|
||||||
self.camera.setHpr(self.camera,
|
self.camera.setHpr(self.camera,
|
||||||
(0.5 * self.chan.mouseDeltaX *
|
(0.5 * self.chan.mouseDeltaX *
|
||||||
self.chan.fovH),
|
self.chan.fovH),
|
||||||
@ -368,7 +367,7 @@ class DirectCameraControl(PandaObject):
|
|||||||
taskMgr.removeTasksNamed('manipulateCamera')
|
taskMgr.removeTasksNamed('manipulateCamera')
|
||||||
|
|
||||||
# How big is the node?
|
# How big is the node?
|
||||||
nodeScale = self.direct.widget.scalingNode.getScale(render)
|
nodeScale = direct.widget.scalingNode.getScale(render)
|
||||||
maxScale = max(nodeScale[0],nodeScale[1],nodeScale[2])
|
maxScale = max(nodeScale[0],nodeScale[1],nodeScale[2])
|
||||||
maxDim = min(self.chan.nearWidth, self.chan.nearHeight)
|
maxDim = min(self.chan.nearWidth, self.chan.nearHeight)
|
||||||
|
|
||||||
@ -380,7 +379,7 @@ class DirectCameraControl(PandaObject):
|
|||||||
centerVec = Y_AXIS * camY
|
centerVec = Y_AXIS * camY
|
||||||
|
|
||||||
# Where is the node relative to the viewpoint
|
# Where is the node relative to the viewpoint
|
||||||
vWidget2Camera = self.direct.widget.getPos(self.camera)
|
vWidget2Camera = direct.widget.getPos(self.camera)
|
||||||
|
|
||||||
# How far do you move the camera to be this distance from the node?
|
# How far do you move the camera to be this distance from the node?
|
||||||
deltaMove = vWidget2Camera - centerVec
|
deltaMove = vWidget2Camera - centerVec
|
||||||
|
@ -2,14 +2,11 @@ from PandaObject import *
|
|||||||
from DirectGeometry import *
|
from DirectGeometry import *
|
||||||
|
|
||||||
class DirectGrid(NodePath,PandaObject):
|
class DirectGrid(NodePath,PandaObject):
|
||||||
def __init__(self, direct):
|
def __init__(self):
|
||||||
# Initialize superclass
|
# Initialize superclass
|
||||||
NodePath.__init__(self)
|
NodePath.__init__(self)
|
||||||
self.assign(hidden.attachNewNode( NamedNode('DirectGrid')))
|
self.assign(hidden.attachNewNode( NamedNode('DirectGrid')))
|
||||||
|
|
||||||
# Record handle to direct session
|
|
||||||
self.direct = direct
|
|
||||||
|
|
||||||
# Load up grid parts to initialize grid object
|
# Load up grid parts to initialize grid object
|
||||||
# Polygon used to mark grid plane
|
# Polygon used to mark grid plane
|
||||||
self.gridBack = loader.loadModel('models/misc/gridBack')
|
self.gridBack = loader.loadModel('models/misc/gridBack')
|
||||||
@ -60,7 +57,7 @@ class DirectGrid(NodePath,PandaObject):
|
|||||||
|
|
||||||
def selectGridBackParent(self, nodePath):
|
def selectGridBackParent(self, nodePath):
|
||||||
if nodePath.getName() == 'GridBack':
|
if nodePath.getName() == 'GridBack':
|
||||||
self.direct.select(self)
|
direct.select(self)
|
||||||
|
|
||||||
def updateGrid(self):
|
def updateGrid(self):
|
||||||
# Update grid lines based upon current grid spacing and grid size
|
# Update grid lines based upon current grid spacing and grid size
|
||||||
|
@ -5,12 +5,11 @@ MANIPULATION_MOVE_DELAY = 0.65
|
|||||||
VISIBLE_DISCS = ['x-disc-visible', 'y-disc-visible', 'z-disc-visible']
|
VISIBLE_DISCS = ['x-disc-visible', 'y-disc-visible', 'z-disc-visible']
|
||||||
|
|
||||||
class DirectManipulationControl(PandaObject):
|
class DirectManipulationControl(PandaObject):
|
||||||
def __init__(self, direct):
|
def __init__(self):
|
||||||
# Create the grid
|
# Create the grid
|
||||||
self.direct = direct
|
|
||||||
self.chan = direct.chan
|
self.chan = direct.chan
|
||||||
self.camera = self.chan.camera
|
self.camera = self.chan.camera
|
||||||
self.objectHandles = ObjectHandles(direct)
|
self.objectHandles = ObjectHandles()
|
||||||
self.hitPt = Point3(0)
|
self.hitPt = Point3(0)
|
||||||
self.prevHit = Vec3(0)
|
self.prevHit = Vec3(0)
|
||||||
self.rotationCenter = Point3(0)
|
self.rotationCenter = Point3(0)
|
||||||
@ -31,7 +30,7 @@ class DirectManipulationControl(PandaObject):
|
|||||||
# Start out in select mode
|
# Start out in select mode
|
||||||
self.mode = 'select'
|
self.mode = 'select'
|
||||||
# Check for a widget hit point
|
# Check for a widget hit point
|
||||||
numEntries = self.direct.iRay.pickWidget(
|
numEntries = direct.iRay.pickWidget(
|
||||||
render,chan.mouseX,chan.mouseY)
|
render,chan.mouseX,chan.mouseY)
|
||||||
# Did we hit a widget?
|
# Did we hit a widget?
|
||||||
if(numEntries):
|
if(numEntries):
|
||||||
@ -39,10 +38,10 @@ class DirectManipulationControl(PandaObject):
|
|||||||
# Entry 0 is the closest hit point if multiple hits
|
# Entry 0 is the closest hit point if multiple hits
|
||||||
minPt = 0
|
minPt = 0
|
||||||
# Find hit point in camera's space
|
# Find hit point in camera's space
|
||||||
self.hitPt = self.direct.iRay.camToHitPt(minPt)
|
self.hitPt = direct.iRay.camToHitPt(minPt)
|
||||||
self.hitPtDist = Vec3(self.hitPt - ZERO_POINT).length()
|
self.hitPtDist = Vec3(self.hitPt - ZERO_POINT).length()
|
||||||
# Get the associated collision queue object
|
# Get the associated collision queue object
|
||||||
entry = self.direct.iRay.cq.getEntry(minPt)
|
entry = direct.iRay.cq.getEntry(minPt)
|
||||||
# Extract the node
|
# Extract the node
|
||||||
node = entry.getIntoNode()
|
node = entry.getIntoNode()
|
||||||
# Constraint determined by nodes name
|
# Constraint determined by nodes name
|
||||||
@ -91,12 +90,12 @@ class DirectManipulationControl(PandaObject):
|
|||||||
# depending on flag.....
|
# depending on flag.....
|
||||||
if self.mode == 'select':
|
if self.mode == 'select':
|
||||||
# Check for object under mouse
|
# Check for object under mouse
|
||||||
numEntries = self.direct.iRay.pickGeom(
|
numEntries = direct.iRay.pickGeom(
|
||||||
render,self.chan.mouseX,self.chan.mouseY)
|
render,self.chan.mouseX,self.chan.mouseY)
|
||||||
# Pick out the closest object that isn't a widget
|
# Pick out the closest object that isn't a widget
|
||||||
index = -1
|
index = -1
|
||||||
for i in range(0,numEntries):
|
for i in range(0,numEntries):
|
||||||
entry = self.direct.iRay.cq.getEntry(i)
|
entry = direct.iRay.cq.getEntry(i)
|
||||||
node = entry.getIntoNode()
|
node = entry.getIntoNode()
|
||||||
if node.isHidden():
|
if node.isHidden():
|
||||||
pass
|
pass
|
||||||
@ -115,14 +114,14 @@ class DirectManipulationControl(PandaObject):
|
|||||||
if(index >= 0):
|
if(index >= 0):
|
||||||
# Yes!
|
# Yes!
|
||||||
# Find hit point in camera's space
|
# Find hit point in camera's space
|
||||||
self.hitPt = self.direct.iRay.camToHitPt(index)
|
self.hitPt = direct.iRay.camToHitPt(index)
|
||||||
self.hitPtDist = Vec3(self.hitPt - ZERO_POINT).length()
|
self.hitPtDist = Vec3(self.hitPt - ZERO_POINT).length()
|
||||||
# Find the node path from the node found above
|
# Find the node path from the node found above
|
||||||
nodePath = render.findPathDownTo(node)
|
nodePath = render.findPathDownTo(node)
|
||||||
# Select it
|
# Select it
|
||||||
self.direct.select(nodePath)
|
direct.select(nodePath)
|
||||||
else:
|
else:
|
||||||
self.direct.deselectAll()
|
direct.deselectAll()
|
||||||
else:
|
else:
|
||||||
self.manipulateObjectCleanup()
|
self.manipulateObjectCleanup()
|
||||||
|
|
||||||
@ -133,11 +132,11 @@ class DirectManipulationControl(PandaObject):
|
|||||||
self.fScaling = 0
|
self.fScaling = 0
|
||||||
if self.fSetCoa:
|
if self.fSetCoa:
|
||||||
self.objectHandles.manipModeColor()
|
self.objectHandles.manipModeColor()
|
||||||
self.direct.selected.highlightAll()
|
direct.selected.highlightAll()
|
||||||
self.objectHandles.showAllHandles()
|
self.objectHandles.showAllHandles()
|
||||||
self.objectHandles.hideGuides()
|
self.objectHandles.hideGuides()
|
||||||
# Restart followSelectedNodePath task
|
# Restart followSelectedNodePath task
|
||||||
if self.direct.selected.last:
|
if direct.selected.last:
|
||||||
self.spawnFollowSelectedNodePathTask()
|
self.spawnFollowSelectedNodePathTask()
|
||||||
messenger.send('manipulateObjectCleanup')
|
messenger.send('manipulateObjectCleanup')
|
||||||
|
|
||||||
@ -145,19 +144,19 @@ class DirectManipulationControl(PandaObject):
|
|||||||
# Where are the object handles relative to the selected object
|
# Where are the object handles relative to the selected object
|
||||||
pos = VBase3(0)
|
pos = VBase3(0)
|
||||||
hpr = VBase3(0)
|
hpr = VBase3(0)
|
||||||
decomposeMatrix(self.direct.selected.last.mCoa2Dnp,
|
decomposeMatrix(direct.selected.last.mCoa2Dnp,
|
||||||
VBase3(0), hpr, pos, CSDefault)
|
VBase3(0), hpr, pos, CSDefault)
|
||||||
# Create the task
|
# Create the task
|
||||||
t = Task.Task(self.followSelectedNodePathTask)
|
t = Task.Task(self.followSelectedNodePathTask)
|
||||||
# Update state variables
|
# Update state variables
|
||||||
t.pos = pos
|
t.pos = pos
|
||||||
t.hpr = hpr
|
t.hpr = hpr
|
||||||
t.base = self.direct.selected.last
|
t.base = direct.selected.last
|
||||||
# Spawn the task
|
# Spawn the task
|
||||||
taskMgr.spawnTaskNamed(t, 'followSelectedNodePath')
|
taskMgr.spawnTaskNamed(t, 'followSelectedNodePath')
|
||||||
|
|
||||||
def followSelectedNodePathTask(self, state):
|
def followSelectedNodePathTask(self, state):
|
||||||
self.direct.widget.setPosHpr(state.base, state.pos, state.hpr)
|
direct.widget.setPosHpr(state.base, state.pos, state.hpr)
|
||||||
return Task.cont
|
return Task.cont
|
||||||
|
|
||||||
def enableManipulation(self):
|
def enableManipulation(self):
|
||||||
@ -189,7 +188,7 @@ class DirectManipulationControl(PandaObject):
|
|||||||
|
|
||||||
def manipulateObject(self):
|
def manipulateObject(self):
|
||||||
# Only do this if something is selected
|
# Only do this if something is selected
|
||||||
if self.direct.selected:
|
if direct.selected:
|
||||||
# Remove the task to keep the widget attached to the object
|
# Remove the task to keep the widget attached to the object
|
||||||
taskMgr.removeTasksNamed('followSelectedNodePath')
|
taskMgr.removeTasksNamed('followSelectedNodePath')
|
||||||
# and the task to highlight the widget
|
# and the task to highlight the widget
|
||||||
@ -204,15 +203,15 @@ class DirectManipulationControl(PandaObject):
|
|||||||
self.objectHandles.coaModeColor()
|
self.objectHandles.coaModeColor()
|
||||||
|
|
||||||
# Record relationship between selected nodes and widget
|
# Record relationship between selected nodes and widget
|
||||||
self.direct.selected.getWrtAll()
|
direct.selected.getWrtAll()
|
||||||
|
|
||||||
# hide the bbox of the selected objects during interaction
|
# hide the bbox of the selected objects during interaction
|
||||||
self.direct.selected.dehighlightAll()
|
direct.selected.dehighlightAll()
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# Push the undo dcs for the selected objects
|
# Push the undo dcs for the selected objects
|
||||||
self.direct.undo.push(
|
direct.undo.push(
|
||||||
(self.direct.selected, 'dcs'))
|
(direct.selected, 'dcs'))
|
||||||
"""
|
"""
|
||||||
# Manipulate the real object with the constraint
|
# Manipulate the real object with the constraint
|
||||||
# The constraint is passed as the name of the node
|
# The constraint is passed as the name of the node
|
||||||
@ -236,17 +235,17 @@ class DirectManipulationControl(PandaObject):
|
|||||||
elif type == 'ring':
|
elif type == 'ring':
|
||||||
self.rotate1D()
|
self.rotate1D()
|
||||||
elif self.fFreeManip:
|
elif self.fFreeManip:
|
||||||
if self.fScaling & (not self.direct.fAlt):
|
if self.fScaling & (not direct.fAlt):
|
||||||
# We had been scaling and changed modes,
|
# We had been scaling and changed modes,
|
||||||
# reset object handles
|
# reset object handles
|
||||||
self.objectHandles.transferObjectHandlesScale()
|
self.objectHandles.transferObjectHandlesScale()
|
||||||
self.fScaling = 0
|
self.fScaling = 0
|
||||||
if self.direct.fControl:
|
if direct.fControl:
|
||||||
self.rotate2D()
|
self.rotate2D()
|
||||||
elif self.direct.fAlt:
|
elif direct.fAlt:
|
||||||
self.fScaling = 1
|
self.fScaling = 1
|
||||||
self.scale3D()
|
self.scale3D()
|
||||||
elif self.direct.fShift:
|
elif direct.fShift:
|
||||||
self.xlateCamXY()
|
self.xlateCamXY()
|
||||||
else:
|
else:
|
||||||
self.xlateCamXZ()
|
self.xlateCamXZ()
|
||||||
@ -256,12 +255,12 @@ class DirectManipulationControl(PandaObject):
|
|||||||
|
|
||||||
if self.fSetCoa:
|
if self.fSetCoa:
|
||||||
# Update coa based on current widget position
|
# Update coa based on current widget position
|
||||||
self.direct.selected.last.mCoa2Dnp.assign(
|
direct.selected.last.mCoa2Dnp.assign(
|
||||||
self.direct.widget.getMat(self.direct.selected.last)
|
direct.widget.getMat(direct.selected.last)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# Move the objects with the widget
|
# Move the objects with the widget
|
||||||
self.direct.selected.moveWrtWidgetAll()
|
direct.selected.moveWrtWidgetAll()
|
||||||
|
|
||||||
# Continue
|
# Continue
|
||||||
return Task.cont
|
return Task.cont
|
||||||
@ -281,7 +280,7 @@ class DirectManipulationControl(PandaObject):
|
|||||||
else:
|
else:
|
||||||
# Move widget to keep hit point as close to mouse as possible
|
# Move widget to keep hit point as close to mouse as possible
|
||||||
offset = self.hitPt - self.prevHit
|
offset = self.hitPt - self.prevHit
|
||||||
self.direct.widget.setPos(self.direct.widget, offset)
|
direct.widget.setPos(direct.widget, offset)
|
||||||
|
|
||||||
def xlate2D(self):
|
def xlate2D(self):
|
||||||
# Constrained 2D (planar) translation
|
# Constrained 2D (planar) translation
|
||||||
@ -289,7 +288,7 @@ class DirectManipulationControl(PandaObject):
|
|||||||
# to one of the three orthogonal planes on the widget.
|
# to one of the three orthogonal planes on the widget.
|
||||||
# This point tracks all subsequent mouse movements
|
# This point tracks all subsequent mouse movements
|
||||||
self.hitPt.assign(self.objectHandles.getWidgetIntersectPt(
|
self.hitPt.assign(self.objectHandles.getWidgetIntersectPt(
|
||||||
self.direct.widget, self.constraint[:1]))
|
direct.widget, self.constraint[:1]))
|
||||||
# use it to see how far to move the widget
|
# use it to see how far to move the widget
|
||||||
if self.fHitInit:
|
if self.fHitInit:
|
||||||
# First time through just record hit point
|
# First time through just record hit point
|
||||||
@ -297,7 +296,7 @@ class DirectManipulationControl(PandaObject):
|
|||||||
self.prevHit.assign(self.hitPt)
|
self.prevHit.assign(self.hitPt)
|
||||||
else:
|
else:
|
||||||
offset = self.hitPt - self.prevHit
|
offset = self.hitPt - self.prevHit
|
||||||
self.direct.widget.setPos(self.direct.widget, offset)
|
direct.widget.setPos(direct.widget, offset)
|
||||||
|
|
||||||
|
|
||||||
def xlateCamXZ(self):
|
def xlateCamXZ(self):
|
||||||
@ -307,17 +306,17 @@ class DirectManipulationControl(PandaObject):
|
|||||||
# (in case we later switch to another manipulation mode)
|
# (in case we later switch to another manipulation mode)
|
||||||
#self.fHitInit = 1
|
#self.fHitInit = 1
|
||||||
# Where is the widget relative to current camera view
|
# Where is the widget relative to current camera view
|
||||||
vWidget2Camera = self.direct.widget.getPos(self.camera)
|
vWidget2Camera = direct.widget.getPos(self.camera)
|
||||||
x = vWidget2Camera[0]
|
x = vWidget2Camera[0]
|
||||||
y = vWidget2Camera[1]
|
y = vWidget2Camera[1]
|
||||||
z = vWidget2Camera[2]
|
z = vWidget2Camera[2]
|
||||||
# Move widget (and objects) based upon mouse motion
|
# Move widget (and objects) based upon mouse motion
|
||||||
# Scaled up accordingly based upon widget distance
|
# Scaled up accordingly based upon widget distance
|
||||||
chan = self.chan
|
chan = self.chan
|
||||||
self.direct.widget.setX(
|
direct.widget.setX(
|
||||||
self.camera,
|
self.camera,
|
||||||
x + 0.5 * chan.mouseDeltaX * chan.nearWidth * (y/chan.near))
|
x + 0.5 * chan.mouseDeltaX * chan.nearWidth * (y/chan.near))
|
||||||
self.direct.widget.setZ(
|
direct.widget.setZ(
|
||||||
self.camera,
|
self.camera,
|
||||||
z + 0.5 * chan.mouseDeltaY * chan.nearHeight * (y/chan.near))
|
z + 0.5 * chan.mouseDeltaY * chan.nearHeight * (y/chan.near))
|
||||||
|
|
||||||
@ -325,7 +324,7 @@ class DirectManipulationControl(PandaObject):
|
|||||||
"""Constrained 2D motion perpendicular to camera's image plane
|
"""Constrained 2D motion perpendicular to camera's image plane
|
||||||
This moves the object in the camera's XY plane"""
|
This moves the object in the camera's XY plane"""
|
||||||
# Now, where is the widget relative to current camera view
|
# Now, where is the widget relative to current camera view
|
||||||
vWidget2Camera = self.direct.widget.getPos(self.camera)
|
vWidget2Camera = direct.widget.getPos(self.camera)
|
||||||
# If this is first time around, record initial y distance
|
# If this is first time around, record initial y distance
|
||||||
if self.fHitInit:
|
if self.fHitInit:
|
||||||
self.fHitInit = 0
|
self.fHitInit = 0
|
||||||
@ -338,7 +337,7 @@ class DirectManipulationControl(PandaObject):
|
|||||||
# Move widget (and objects) based upon mouse motion
|
# Move widget (and objects) based upon mouse motion
|
||||||
# Scaled up accordingly based upon widget distance
|
# Scaled up accordingly based upon widget distance
|
||||||
chan = self.chan
|
chan = self.chan
|
||||||
self.direct.widget.setPos(
|
direct.widget.setPos(
|
||||||
self.camera,
|
self.camera,
|
||||||
x + 0.5 * chan.mouseDeltaX * chan.nearWidth * (y/chan.near),
|
x + 0.5 * chan.mouseDeltaX * chan.nearWidth * (y/chan.near),
|
||||||
y + self.initY * chan.mouseDeltaY,
|
y + self.initY * chan.mouseDeltaY,
|
||||||
@ -359,7 +358,7 @@ class DirectManipulationControl(PandaObject):
|
|||||||
# widget's origin and one of the three principle axes
|
# widget's origin and one of the three principle axes
|
||||||
axis = self.constraint[:1]
|
axis = self.constraint[:1]
|
||||||
# First compute vector from eye through widget origin
|
# First compute vector from eye through widget origin
|
||||||
mWidget2Cam = self.direct.widget.getMat(self.camera)
|
mWidget2Cam = direct.widget.getMat(self.camera)
|
||||||
# And determine where the viewpoint is relative to widget
|
# And determine where the viewpoint is relative to widget
|
||||||
pos = VBase3(0)
|
pos = VBase3(0)
|
||||||
decomposeMatrix(mWidget2Cam, VBase3(0), VBase3(0), pos,
|
decomposeMatrix(mWidget2Cam, VBase3(0), VBase3(0), pos,
|
||||||
@ -385,7 +384,7 @@ class DirectManipulationControl(PandaObject):
|
|||||||
def getWidgetsNearProjectionPoint(self):
|
def getWidgetsNearProjectionPoint(self):
|
||||||
# Find the position of the projection of the specified node path
|
# Find the position of the projection of the specified node path
|
||||||
# on the near plane
|
# on the near plane
|
||||||
widgetOrigin = self.direct.widget.getPos(self.camera)
|
widgetOrigin = direct.widget.getPos(self.camera)
|
||||||
# project this onto near plane
|
# project this onto near plane
|
||||||
return widgetOrigin * (self.chan.near / widgetOrigin[1])
|
return widgetOrigin * (self.chan.near / widgetOrigin[1])
|
||||||
|
|
||||||
@ -424,23 +423,23 @@ class DirectManipulationControl(PandaObject):
|
|||||||
if self.fWidgetTop:
|
if self.fWidgetTop:
|
||||||
deltaAngle = -1 * deltaAngle
|
deltaAngle = -1 * deltaAngle
|
||||||
if self.rotateAxis == 'x':
|
if self.rotateAxis == 'x':
|
||||||
self.direct.widget.setP(self.direct.widget, deltaAngle)
|
direct.widget.setP(direct.widget, deltaAngle)
|
||||||
elif self.rotateAxis == 'y':
|
elif self.rotateAxis == 'y':
|
||||||
self.direct.widget.setR(self.direct.widget, -deltaAngle)
|
direct.widget.setR(direct.widget, -deltaAngle)
|
||||||
elif self.rotateAxis == 'z':
|
elif self.rotateAxis == 'z':
|
||||||
self.direct.widget.setH(self.direct.widget, deltaAngle)
|
direct.widget.setH(direct.widget, deltaAngle)
|
||||||
# Record crank angle for next time around
|
# Record crank angle for next time around
|
||||||
self.lastCrankAngle = newAngle
|
self.lastCrankAngle = newAngle
|
||||||
|
|
||||||
def relHpr(self, base, h, p, r):
|
def relHpr(self, base, h, p, r):
|
||||||
# Compute widget2newWidget relative to base coordinate system
|
# Compute widget2newWidget relative to base coordinate system
|
||||||
mWidget2Base = self.direct.widget.getMat(base)
|
mWidget2Base = direct.widget.getMat(base)
|
||||||
mBase2NewBase = Mat4()
|
mBase2NewBase = Mat4()
|
||||||
mBase2NewBase.composeMatrix(
|
mBase2NewBase.composeMatrix(
|
||||||
UNIT_VEC, VBase3(h,p,r), ZERO_VEC,
|
UNIT_VEC, VBase3(h,p,r), ZERO_VEC,
|
||||||
CSDefault)
|
CSDefault)
|
||||||
mBase2Widget = base.getMat(self.direct.widget)
|
mBase2Widget = base.getMat(direct.widget)
|
||||||
mWidget2Parent = self.direct.widget.getMat()
|
mWidget2Parent = direct.widget.getMat()
|
||||||
# Compose the result
|
# Compose the result
|
||||||
resultMat = mWidget2Base * mBase2NewBase
|
resultMat = mWidget2Base * mBase2NewBase
|
||||||
resultMat = resultMat * mBase2Widget
|
resultMat = resultMat * mBase2Widget
|
||||||
@ -449,7 +448,7 @@ class DirectManipulationControl(PandaObject):
|
|||||||
hpr = Vec3(0)
|
hpr = Vec3(0)
|
||||||
decomposeMatrix(resultMat, VBase3(), hpr, VBase3(),
|
decomposeMatrix(resultMat, VBase3(), hpr, VBase3(),
|
||||||
CSDefault)
|
CSDefault)
|
||||||
self.direct.widget.setHpr(hpr)
|
direct.widget.setHpr(hpr)
|
||||||
|
|
||||||
def rotate2D(self):
|
def rotate2D(self):
|
||||||
# Virtual trackball or arcball rotation of widget
|
# Virtual trackball or arcball rotation of widget
|
||||||
@ -469,13 +468,13 @@ class DirectManipulationControl(PandaObject):
|
|||||||
# From midpoint to edge doubles or halves objects scale
|
# From midpoint to edge doubles or halves objects scale
|
||||||
if self.fHitInit:
|
if self.fHitInit:
|
||||||
self.fHitInit = 0
|
self.fHitInit = 0
|
||||||
self.refNodePath.setPos(self.direct.widget, 0, 0, 0)
|
self.refNodePath.setPos(direct.widget, 0, 0, 0)
|
||||||
self.refNodePath.setHpr(self.camera, 0, 0, 0)
|
self.refNodePath.setHpr(self.camera, 0, 0, 0)
|
||||||
self.initScaleMag = Vec3(
|
self.initScaleMag = Vec3(
|
||||||
self.objectHandles.getWidgetIntersectPt(
|
self.objectHandles.getWidgetIntersectPt(
|
||||||
self.refNodePath, 'y')).length()
|
self.refNodePath, 'y')).length()
|
||||||
# record initial scale
|
# record initial scale
|
||||||
self.initScale = self.direct.widget.getScale()
|
self.initScale = direct.widget.getScale()
|
||||||
# Begin
|
# Begin
|
||||||
# Scale factor is ratio current mag with init mag
|
# Scale factor is ratio current mag with init mag
|
||||||
currScale = (
|
currScale = (
|
||||||
@ -484,7 +483,7 @@ class DirectManipulationControl(PandaObject):
|
|||||||
self.refNodePath, 'y').length() /
|
self.refNodePath, 'y').length() /
|
||||||
self.initScaleMag)
|
self.initScaleMag)
|
||||||
)
|
)
|
||||||
self.direct.widget.setScale(currScale)
|
direct.widget.setScale(currScale)
|
||||||
|
|
||||||
def clamp(self, val, min, max):
|
def clamp(self, val, min, max):
|
||||||
if val < min:
|
if val < min:
|
||||||
@ -496,9 +495,7 @@ class DirectManipulationControl(PandaObject):
|
|||||||
|
|
||||||
|
|
||||||
class ObjectHandles(NodePath,PandaObject):
|
class ObjectHandles(NodePath,PandaObject):
|
||||||
def __init__(self,direct):
|
def __init__(self):
|
||||||
# Record pointer to direct object
|
|
||||||
self.direct = direct
|
|
||||||
# Initialize the superclass
|
# Initialize the superclass
|
||||||
NodePath.__init__(self)
|
NodePath.__init__(self)
|
||||||
|
|
||||||
@ -718,9 +715,9 @@ class ObjectHandles(NodePath,PandaObject):
|
|||||||
def growToFit(self):
|
def growToFit(self):
|
||||||
taskMgr.removeTasksNamed('resizeObjectHandles')
|
taskMgr.removeTasksNamed('resizeObjectHandles')
|
||||||
# Increase handles scale until they cover 30% of the min dimension
|
# Increase handles scale until they cover 30% of the min dimension
|
||||||
pos = self.direct.widget.getPos(self.direct.camera)
|
pos = direct.widget.getPos(direct.camera)
|
||||||
minDim = min(self.direct.chan.nearWidth, self.direct.chan.nearHeight)
|
minDim = min(direct.chan.nearWidth, direct.chan.nearHeight)
|
||||||
sf = 0.15 * minDim * (pos[1]/self.direct.chan.near)
|
sf = 0.15 * minDim * (pos[1]/direct.chan.near)
|
||||||
self.ohScalingFactor = sf
|
self.ohScalingFactor = sf
|
||||||
self.scalingNode.lerpScale(sf,sf,sf, 0.5,
|
self.scalingNode.lerpScale(sf,sf,sf, 0.5,
|
||||||
blendType = 'easeInOut',
|
blendType = 'easeInOut',
|
||||||
@ -839,8 +836,8 @@ class ObjectHandles(NodePath,PandaObject):
|
|||||||
|
|
||||||
def getAxisIntersectPt(self, axis):
|
def getAxisIntersectPt(self, axis):
|
||||||
# Calc the xfrom from camera to widget
|
# Calc the xfrom from camera to widget
|
||||||
mCam2Widget = self.direct.camera.getMat(self.direct.widget)
|
mCam2Widget = direct.camera.getMat(direct.widget)
|
||||||
lineDir = Vec3(mCam2Widget.xformVec(self.direct.chan.nearVec))
|
lineDir = Vec3(mCam2Widget.xformVec(direct.chan.nearVec))
|
||||||
lineDir.normalize()
|
lineDir.normalize()
|
||||||
# And determine where the viewpoint is relative to widget
|
# And determine where the viewpoint is relative to widget
|
||||||
lineOrigin = VBase3(0)
|
lineOrigin = VBase3(0)
|
||||||
@ -887,7 +884,7 @@ class ObjectHandles(NodePath,PandaObject):
|
|||||||
# with the plane containing the 2D xlation or 1D rotation widgets
|
# with the plane containing the 2D xlation or 1D rotation widgets
|
||||||
|
|
||||||
# Calc the xfrom from camera to the nodePath
|
# Calc the xfrom from camera to the nodePath
|
||||||
mCam2NodePath = self.direct.camera.getMat(nodePath)
|
mCam2NodePath = direct.camera.getMat(nodePath)
|
||||||
|
|
||||||
# And determine where the viewpoint is relative to widget
|
# And determine where the viewpoint is relative to widget
|
||||||
lineOrigin = VBase3(0)
|
lineOrigin = VBase3(0)
|
||||||
@ -897,7 +894,7 @@ class ObjectHandles(NodePath,PandaObject):
|
|||||||
# Next we find the vector from viewpoint to the widget through
|
# Next we find the vector from viewpoint to the widget through
|
||||||
# the mouse's position on near plane.
|
# the mouse's position on near plane.
|
||||||
# This defines the intersection ray
|
# This defines the intersection ray
|
||||||
lineDir = Vec3(mCam2NodePath.xformVec(self.direct.chan.nearVec))
|
lineDir = Vec3(mCam2NodePath.xformVec(direct.chan.nearVec))
|
||||||
lineDir.normalize()
|
lineDir.normalize()
|
||||||
# Find the hit point
|
# Find the hit point
|
||||||
if plane == 'x':
|
if plane == 'x':
|
||||||
|
@ -46,8 +46,7 @@ class DirectNodePath(NodePath):
|
|||||||
|
|
||||||
|
|
||||||
class SelectedNodePaths(PandaObject):
|
class SelectedNodePaths(PandaObject):
|
||||||
def __init__(self,direct):
|
def __init__(self):
|
||||||
self.direct = direct
|
|
||||||
self.selectedDict = {}
|
self.selectedDict = {}
|
||||||
self.deselectedDict = {}
|
self.deselectedDict = {}
|
||||||
self.last = None
|
self.last = None
|
||||||
@ -131,13 +130,13 @@ class SelectedNodePaths(PandaObject):
|
|||||||
self.forEachSelectedNodePathDo(self.getWrt)
|
self.forEachSelectedNodePathDo(self.getWrt)
|
||||||
|
|
||||||
def getWrt(self, nodePath):
|
def getWrt(self, nodePath):
|
||||||
nodePath.mDnp2Widget.assign(nodePath.getMat(self.direct.widget))
|
nodePath.mDnp2Widget.assign(nodePath.getMat(direct.widget))
|
||||||
|
|
||||||
def moveWrtWidgetAll(self):
|
def moveWrtWidgetAll(self):
|
||||||
self.forEachSelectedNodePathDo(self.moveWrtWidget)
|
self.forEachSelectedNodePathDo(self.moveWrtWidget)
|
||||||
|
|
||||||
def moveWrtWidget(self, nodePath):
|
def moveWrtWidget(self, nodePath):
|
||||||
nodePath.setMat(self.direct.widget, nodePath.mDnp2Widget)
|
nodePath.setMat(direct.widget, nodePath.mDnp2Widget)
|
||||||
|
|
||||||
def deselectAll(self):
|
def deselectAll(self):
|
||||||
self.forEachSelectedNodePathDo(self.deselect)
|
self.forEachSelectedNodePathDo(self.deselect)
|
||||||
|
@ -5,10 +5,14 @@ from DirectSelection import *
|
|||||||
from DirectGrid import *
|
from DirectGrid import *
|
||||||
from DirectGeometry import *
|
from DirectGeometry import *
|
||||||
import OnscreenText
|
import OnscreenText
|
||||||
|
import __builtin__
|
||||||
|
|
||||||
class DirectSession(PandaObject):
|
class DirectSession(PandaObject):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
# Establish a global pointer to the direct object early on
|
||||||
|
# so dependant classes can access it in their code
|
||||||
|
__builtin__.direct = self
|
||||||
self.contextList = []
|
self.contextList = []
|
||||||
self.iRayList = []
|
self.iRayList = []
|
||||||
for camera in base.cameraList:
|
for camera in base.cameraList:
|
||||||
@ -17,14 +21,14 @@ class DirectSession(PandaObject):
|
|||||||
self.chan = self.getChanData(0)
|
self.chan = self.getChanData(0)
|
||||||
self.camera = base.cameraList[0]
|
self.camera = base.cameraList[0]
|
||||||
|
|
||||||
self.cameraControl = DirectCameraControl(self)
|
self.cameraControl = DirectCameraControl()
|
||||||
self.manipulationControl = DirectManipulationControl(self)
|
self.manipulationControl = DirectManipulationControl()
|
||||||
self.useObjectHandles()
|
self.useObjectHandles()
|
||||||
self.grid = DirectGrid(self)
|
self.grid = DirectGrid()
|
||||||
self.grid.disable()
|
self.grid.disable()
|
||||||
|
|
||||||
# Initialize the collection of selected nodePaths
|
# Initialize the collection of selected nodePaths
|
||||||
self.selected = SelectedNodePaths(self)
|
self.selected = SelectedNodePaths()
|
||||||
|
|
||||||
self.readout = OnscreenText.OnscreenText( '', 0.1, -0.95 )
|
self.readout = OnscreenText.OnscreenText( '', 0.1, -0.95 )
|
||||||
# self.readout.textNode.setCardColor(0.5, 0.5, 0.5, 0.5)
|
# self.readout.textNode.setCardColor(0.5, 0.5, 0.5, 0.5)
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
from ShowBaseGlobal import *
|
from ShowBaseGlobal import *
|
||||||
|
import __builtin__
|
||||||
|
|
||||||
# If specified in the user's Configrc, create the direct session
|
# If specified in the user's Configrc, create the direct session
|
||||||
if base.wantDIRECT:
|
if base.wantDIRECT:
|
||||||
from DirectSession import *
|
from DirectSession import *
|
||||||
direct = base.direct = DirectSession()
|
__builtin__.direct = base.direct = DirectSession()
|
||||||
else:
|
else:
|
||||||
# Otherwise set the values to None
|
# Otherwise set the values to None
|
||||||
direct = base.direct = None
|
__builtin__.direct = base.direct = None
|
||||||
|
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
"""instantiate global ShowBase object"""
|
"""instantiate global ShowBase object"""
|
||||||
|
|
||||||
from ShowBase import *
|
from ShowBase import *
|
||||||
|
import __builtin__
|
||||||
|
|
||||||
base = ShowBase()
|
__builtin__.base = ShowBase()
|
||||||
|
|
||||||
# Make some global aliases for convenience
|
# Make some global aliases for convenience
|
||||||
render2d = base.render2d
|
__builtin__.render2d = base.render2d
|
||||||
render = base.render
|
__builtin__.render = base.render
|
||||||
hidden = base.hidden
|
__builtin__.hidden = base.hidden
|
||||||
camera = base.camera
|
__builtin__.camera = base.camera
|
||||||
loader = base.loader
|
__builtin__.loader = base.loader
|
||||||
ostream = Notify.out()
|
__builtin__.ostream = Notify.out()
|
||||||
run = base.run
|
__builtin__.run = base.run
|
||||||
tkroot = base.tkroot
|
__builtin__.tkroot = base.tkroot
|
||||||
|
Loading…
x
Reference in New Issue
Block a user