mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-29 08:15:18 -04:00
*** empty log message ***
This commit is contained in:
parent
74de944083
commit
be485738fa
@ -1,298 +1,297 @@
|
|||||||
from PandaObject import *
|
from PandaObject import *
|
||||||
from DirectCameraControl import *
|
from DirectCameraControl import *
|
||||||
from DirectManipulation import *
|
from DirectManipulation import *
|
||||||
from DirectSelection import *
|
from DirectSelection import *
|
||||||
from DirectGrid import *
|
from DirectGrid import *
|
||||||
from DirectGeometry import *
|
from DirectGeometry import *
|
||||||
import OnscreenText
|
import OnscreenText
|
||||||
|
|
||||||
|
class DirectSession(PandaObject):
|
||||||
class DirectSession(PandaObject):
|
|
||||||
|
def __init__(self):
|
||||||
def __init__(self):
|
self.contextList = []
|
||||||
self.contextList = []
|
self.iRayList = []
|
||||||
self.iRayList = []
|
for camera in base.cameraList:
|
||||||
for camera in base.cameraList:
|
self.contextList.append(DisplayRegionContext(base.win, camera))
|
||||||
self.contextList.append(DisplayRegionContext(base.win, camera))
|
self.iRayList.append(SelectionRay(camera))
|
||||||
self.iRayList.append(SelectionRay(camera))
|
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)
|
self.manipulationControl = DirectManipulationControl(self)
|
||||||
self.manipulationControl = DirectManipulationControl(self)
|
self.useObjectHandles()
|
||||||
self.useObjectHandles()
|
self.grid = DirectGrid(self)
|
||||||
self.grid = DirectGrid(self)
|
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)
|
|
||||||
|
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)
|
self.readout.reparentTo( hidden )
|
||||||
self.readout.reparentTo( hidden )
|
|
||||||
|
self.fControl = 0
|
||||||
self.fControl = 0
|
self.fAlt = 0
|
||||||
self.fAlt = 0
|
self.fShift = 0
|
||||||
self.fShift = 0
|
|
||||||
|
self.pos = VBase3()
|
||||||
self.pos = VBase3()
|
self.hpr = VBase3()
|
||||||
self.hpr = VBase3()
|
self.scale = VBase3()
|
||||||
self.scale = VBase3()
|
|
||||||
|
self.iRay = self.iRayList[0]
|
||||||
self.iRay = self.iRayList[0]
|
self.hitPt = Point3(0.0)
|
||||||
self.hitPt = Point3(0.0)
|
|
||||||
|
# One run through the context task to init everything
|
||||||
# One run through the context task to init everything
|
for context in self.contextList:
|
||||||
for context in self.contextList:
|
context.contextTask(None)
|
||||||
context.contextTask(None)
|
|
||||||
|
self.actionEvents = [('select', self.select),
|
||||||
self.actionEvents = [('select', self.select),
|
('deselect', self.deselect),
|
||||||
('deselect', self.deselect),
|
('deselectAll', self.deselectAll),
|
||||||
('deselectAll', self.deselectAll),
|
('highlightAll', self.selected.highlightAll),
|
||||||
('highlightAll', self.selected.highlightAll),
|
('preRemoveNodePath', self.deselect)]
|
||||||
('preRemoveNodePath', self.deselect)]
|
self.keyEvents = ['left', 'right', 'up', 'down',
|
||||||
self.keyEvents = ['left', 'right', 'up', 'down',
|
'escape', 'space', 'delete',
|
||||||
'escape', 'space', 'delete',
|
'shift', 'shift-up', 'alt', 'alt-up',
|
||||||
'shift', 'shift-up', 'alt', 'alt-up',
|
'control', 'control-up',
|
||||||
'control', 'control-up',
|
'b', 'c', 'f', 'l', 't', 'v', 'w']
|
||||||
'b', 'c', 'f', 'l', 't', 'v', 'w']
|
self.mouseEvents = ['mouse1', 'mouse1-up',
|
||||||
self.mouseEvents = ['mouse1', 'mouse1-up',
|
'mouse2', 'mouse2-up',
|
||||||
'mouse2', 'mouse2-up',
|
'mouse3', 'mouse3-up']
|
||||||
'mouse3', 'mouse3-up']
|
|
||||||
|
def select(self, nodePath):
|
||||||
def select(self, nodePath):
|
dnp = self.selected.select(nodePath)
|
||||||
dnp = self.selected.select(nodePath)
|
if dnp:
|
||||||
if dnp:
|
messenger.send('preSelectNodePath', [dnp])
|
||||||
messenger.send('preSelectNodePath', [dnp])
|
# Update the readout
|
||||||
# Update the readout
|
self.readout.reparentTo(render2d)
|
||||||
self.readout.reparentTo(render2d)
|
self.readout.setText(dnp.name)
|
||||||
self.readout.setText(dnp.name)
|
# Show the manipulation widget
|
||||||
# Show the manipulation widget
|
self.widget.reparentTo(render)
|
||||||
self.widget.reparentTo(render)
|
# Update camera controls coa to this point
|
||||||
# Update camera controls coa to this point
|
# Coa2Camera = Coa2Dnp * Dnp2Camera
|
||||||
# Coa2Camera = Coa2Dnp * Dnp2Camera
|
mCoa2Camera = dnp.mCoa2Dnp * dnp.getMat(base.camera)
|
||||||
mCoa2Camera = dnp.mCoa2Dnp * dnp.getMat(base.camera)
|
row = mCoa2Camera.getRow(3)
|
||||||
row = mCoa2Camera.getRow(3)
|
coa = Vec3(row[0], row[1], row[2])
|
||||||
coa = Vec3(row[0], row[1], row[2])
|
self.cameraControl.updateCoa(coa)
|
||||||
self.cameraControl.updateCoa(coa)
|
# Adjust widgets size
|
||||||
# Adjust widgets size
|
# This uses the additional scaling factor used to grow and
|
||||||
# This uses the additional scaling factor used to grow and
|
# shrink the widget
|
||||||
# shrink the widget
|
self.widget.setScalingFactor(dnp.getRadius())
|
||||||
self.widget.setScalingFactor(dnp.getRadius())
|
# Spawn task to have object handles follow the selected object
|
||||||
# Spawn task to have object handles follow the selected object
|
taskMgr.removeTasksNamed('followSelectedNodePath')
|
||||||
taskMgr.removeTasksNamed('followSelectedNodePath')
|
t = Task.Task(self.followSelectedNodePathTask)
|
||||||
t = Task.Task(self.followSelectedNodePathTask)
|
t.dnp = dnp
|
||||||
t.dnp = dnp
|
taskMgr.spawnTaskNamed(t, 'followSelectedNodePath')
|
||||||
taskMgr.spawnTaskNamed(t, 'followSelectedNodePath')
|
# Send an message marking the event
|
||||||
# Send an message marking the event
|
messenger.send('selectedNodePath', [dnp])
|
||||||
messenger.send('selectedNodePath', [dnp])
|
|
||||||
|
def followSelectedNodePathTask(self, state):
|
||||||
def followSelectedNodePathTask(self, state):
|
mCoa2Render = state.dnp.mCoa2Dnp * state.dnp.getMat(render)
|
||||||
mCoa2Render = state.dnp.mCoa2Dnp * state.dnp.getMat(render)
|
decomposeMatrix(mCoa2Render,
|
||||||
decomposeMatrix(mCoa2Render,
|
self.scale,self.hpr,self.pos,
|
||||||
self.scale,self.hpr,self.pos,
|
CSDefault)
|
||||||
CSDefault)
|
self.widget.setPosHpr(self.pos,self.hpr)
|
||||||
self.widget.setPosHpr(self.pos,self.hpr)
|
return Task.cont
|
||||||
return Task.cont
|
|
||||||
|
def deselect(self, nodePath):
|
||||||
def deselect(self, nodePath):
|
dnp = self.selected.deselect(nodePath)
|
||||||
dnp = self.selected.deselect(nodePath)
|
if dnp:
|
||||||
if dnp:
|
# Hide the manipulation widget
|
||||||
# Hide the manipulation widget
|
self.widget.reparentTo(hidden)
|
||||||
self.widget.reparentTo(hidden)
|
self.readout.reparentTo(hidden)
|
||||||
self.readout.reparentTo(hidden)
|
self.readout.setText(' ')
|
||||||
self.readout.setText(' ')
|
taskMgr.removeTasksNamed('followSelectedNodePath')
|
||||||
taskMgr.removeTasksNamed('followSelectedNodePath')
|
# Send an message marking the event
|
||||||
# Send an message marking the event
|
messenger.send('deselectedNodePath', [dnp])
|
||||||
messenger.send('deselectedNodePath', [dnp])
|
|
||||||
|
def deselectAll(self):
|
||||||
def deselectAll(self):
|
self.selected.deselectAll()
|
||||||
self.selected.deselectAll()
|
# Hide the manipulation widget
|
||||||
# Hide the manipulation widget
|
self.widget.reparentTo(hidden)
|
||||||
self.widget.reparentTo(hidden)
|
self.readout.reparentTo(hidden)
|
||||||
self.readout.reparentTo(hidden)
|
self.readout.setText(' ')
|
||||||
self.readout.setText(' ')
|
taskMgr.removeTasksNamed('followSelectedNodePath')
|
||||||
taskMgr.removeTasksNamed('followSelectedNodePath')
|
|
||||||
|
def enable(self):
|
||||||
def enable(self):
|
# Make sure old tasks are shut down
|
||||||
# Make sure old tasks are shut down
|
self.disable()
|
||||||
self.disable()
|
# Start all display region context tasks
|
||||||
# Start all display region context tasks
|
for context in self.contextList:
|
||||||
for context in self.contextList:
|
context.spawnContextTask()
|
||||||
context.spawnContextTask()
|
# Turn on mouse Flying
|
||||||
# Turn on mouse Flying
|
self.cameraControl.enableMouseFly()
|
||||||
self.cameraControl.enableMouseFly()
|
# Turn on object manipulation
|
||||||
# Turn on object manipulation
|
self.manipulationControl.enableManipulation()
|
||||||
self.manipulationControl.enableManipulation()
|
# Accept appropriate hooks
|
||||||
# Accept appropriate hooks
|
self.enableKeyEvents()
|
||||||
self.enableKeyEvents()
|
self.enableMouseEvents()
|
||||||
self.enableMouseEvents()
|
self.enableActionEvents()
|
||||||
self.enableActionEvents()
|
|
||||||
|
def disable(self):
|
||||||
def disable(self):
|
# Shut down all display region context tasks
|
||||||
# Shut down all display region context tasks
|
for context in self.contextList:
|
||||||
for context in self.contextList:
|
context.removeContextTask()
|
||||||
context.removeContextTask()
|
# Turn off camera fly
|
||||||
# Turn off camera fly
|
self.cameraControl.disableMouseFly()
|
||||||
self.cameraControl.disableMouseFly()
|
# Turn off object manipulation
|
||||||
# Turn off object manipulation
|
self.manipulationControl.disableManipulation()
|
||||||
self.manipulationControl.disableManipulation()
|
self.disableKeyEvents()
|
||||||
self.disableKeyEvents()
|
self.disableMouseEvents()
|
||||||
self.disableMouseEvents()
|
self.disableActionEvents()
|
||||||
self.disableActionEvents()
|
|
||||||
|
def minimumConfiguration(self):
|
||||||
def minimumConfiguration(self):
|
# Remove context task
|
||||||
# Remove context task
|
for context in self.contextList:
|
||||||
for context in self.contextList:
|
context.removeContextTask()
|
||||||
context.removeContextTask()
|
# Turn off camera fly
|
||||||
# Turn off camera fly
|
self.cameraControl.disableMouseFly()
|
||||||
self.cameraControl.disableMouseFly()
|
# Ignore keyboard and action events
|
||||||
# Ignore keyboard and action events
|
self.disableKeyEvents()
|
||||||
self.disableKeyEvents()
|
self.disableActionEvents()
|
||||||
self.disableActionEvents()
|
# But let mouse events pass through
|
||||||
# But let mouse events pass through
|
self.enableMouseEvents()
|
||||||
self.enableMouseEvents()
|
|
||||||
|
def destroy(self):
|
||||||
def destroy(self):
|
self.disable()
|
||||||
self.disable()
|
|
||||||
|
def restart(self):
|
||||||
def restart(self):
|
self.enable()
|
||||||
self.enable()
|
|
||||||
|
def enableActionEvents(self):
|
||||||
def enableActionEvents(self):
|
for event, method in self.actionEvents:
|
||||||
for event, method in self.actionEvents:
|
self.accept(event, method)
|
||||||
self.accept(event, method)
|
|
||||||
|
def enableKeyEvents(self):
|
||||||
def enableKeyEvents(self):
|
for event in self.keyEvents:
|
||||||
for event in self.keyEvents:
|
self.accept(event, self.inputHandler, [event])
|
||||||
self.accept(event, self.inputHandler, [event])
|
|
||||||
|
def enableMouseEvents(self):
|
||||||
def enableMouseEvents(self):
|
for event in self.mouseEvents:
|
||||||
for event in self.mouseEvents:
|
self.accept(event, self.inputHandler, [event])
|
||||||
self.accept(event, self.inputHandler, [event])
|
|
||||||
|
def disableActionEvents(self):
|
||||||
def disableActionEvents(self):
|
for event, method in self.actionEvents:
|
||||||
for event, method in self.actionEvents:
|
self.ignore(event)
|
||||||
self.ignore(event)
|
|
||||||
|
def disableKeyEvents(self):
|
||||||
def disableKeyEvents(self):
|
for event in self.keyEvents:
|
||||||
for event in self.keyEvents:
|
self.ignore(event)
|
||||||
self.ignore(event)
|
|
||||||
|
def disableMouseEvents(self):
|
||||||
def disableMouseEvents(self):
|
for event in self.mouseEvents:
|
||||||
for event in self.mouseEvents:
|
self.ignore(event)
|
||||||
self.ignore(event)
|
|
||||||
|
def useObjectHandles(self):
|
||||||
def useObjectHandles(self):
|
self.widget = self.manipulationControl.objectHandles
|
||||||
self.widget = self.manipulationControl.objectHandles
|
|
||||||
|
def hideReadout(self):
|
||||||
def hideReadout(self):
|
self.readout.reparentTo(hidden)
|
||||||
self.readout.reparentTo(hidden)
|
|
||||||
|
def getChanData(self, index):
|
||||||
def getChanData(self, index):
|
return self.contextList[index]
|
||||||
return self.contextList[index]
|
|
||||||
|
def inputHandler(self, input):
|
||||||
def inputHandler(self, input):
|
# Deal with keyboard and mouse input
|
||||||
# Deal with keyboard and mouse input
|
if input == 'mouse1':
|
||||||
if input == 'mouse1':
|
messenger.send('handleMouse1')
|
||||||
messenger.send('handleMouse1')
|
elif input == 'mouse1-up':
|
||||||
elif input == 'mouse1-up':
|
messenger.send('handleMouse1Up')
|
||||||
messenger.send('handleMouse1Up')
|
elif input == 'mouse2':
|
||||||
elif input == 'mouse2':
|
messenger.send('handleMouse2')
|
||||||
messenger.send('handleMouse2')
|
elif input == 'mouse2-up':
|
||||||
elif input == 'mouse2-up':
|
messenger.send('handleMouse2Up')
|
||||||
messenger.send('handleMouse2Up')
|
elif input == 'mouse3':
|
||||||
elif input == 'mouse3':
|
messenger.send('handleMouse3')
|
||||||
messenger.send('handleMouse3')
|
elif input == 'mouse3-up':
|
||||||
elif input == 'mouse3-up':
|
messenger.send('handleMouse3Up')
|
||||||
messenger.send('handleMouse3Up')
|
elif input == 'shift':
|
||||||
elif input == 'shift':
|
self.fShift = 1
|
||||||
self.fShift = 1
|
elif input == 'shift-up':
|
||||||
elif input == 'shift-up':
|
self.fShift = 0
|
||||||
self.fShift = 0
|
elif input == 'control':
|
||||||
elif input == 'control':
|
self.fControl = 1
|
||||||
self.fControl = 1
|
elif input == 'control-up':
|
||||||
elif input == 'control-up':
|
self.fControl = 0
|
||||||
self.fControl = 0
|
elif input == 'alt':
|
||||||
elif input == 'alt':
|
self.fAlt = 1
|
||||||
self.fAlt = 1
|
elif input == 'alt-up':
|
||||||
elif input == 'alt-up':
|
self.fAlt = 0
|
||||||
self.fAlt = 0
|
elif input == 'escape':
|
||||||
elif input == 'escape':
|
self.deselectAll()
|
||||||
self.deselectAll()
|
elif input == 'l':
|
||||||
elif input == 'l':
|
if self.selected.last:
|
||||||
if self.selected.last:
|
self.select(self.selected.last)
|
||||||
self.select(self.selected.last)
|
elif input == 'delete':
|
||||||
elif input == 'delete':
|
self.selected.removeAll()
|
||||||
self.selected.removeAll()
|
elif input == 'v':
|
||||||
elif input == 'v':
|
self.selected.toggleVizAll()
|
||||||
self.selected.toggleVizAll()
|
elif input == 'b':
|
||||||
elif input == 'b':
|
base.toggleBackface()
|
||||||
base.toggleBackface()
|
elif input == 't':
|
||||||
elif input == 't':
|
base.toggleTexture()
|
||||||
base.toggleTexture()
|
elif input == 'w':
|
||||||
elif input == 'w':
|
base.toggleWireframe()
|
||||||
base.toggleWireframe()
|
|
||||||
|
class DisplayRegionContext(PandaObject):
|
||||||
class DisplayRegionContext(PandaObject):
|
def __init__(self, win, camera):
|
||||||
def __init__(self, win, camera):
|
self.win = win
|
||||||
self.win = win
|
self.camera = camera
|
||||||
self.camera = camera
|
self.cam = camera.getChild(0)
|
||||||
self.cam = camera.getChild(0)
|
self.camNode = self.cam.getNode(0)
|
||||||
self.camNode = self.cam.getNode(0)
|
self.nearVec = Vec3(0)
|
||||||
self.nearVec = Vec3(0)
|
self.mouseX = 0.0
|
||||||
self.mouseX = 0.0
|
self.mouseY = 0.0
|
||||||
self.mouseY = 0.0
|
|
||||||
|
def __getitem__(self,key):
|
||||||
def __getitem__(self,key):
|
return self.__dict__[key]
|
||||||
return self.__dict__[key]
|
|
||||||
|
def start(self):
|
||||||
def start(self):
|
# First shutdown any existing task
|
||||||
# First shutdown any existing task
|
self.stop()
|
||||||
self.stop()
|
# Start a new context task
|
||||||
# Start a new context task
|
self.spawnContextTask()
|
||||||
self.spawnContextTask()
|
|
||||||
|
def stop(self):
|
||||||
def stop(self):
|
# Kill the existing context task
|
||||||
# Kill the existing context task
|
taskMgr.removeTasksNamed('DIRECTContextTask')
|
||||||
taskMgr.removeTasksNamed('DIRECTContextTask')
|
|
||||||
|
def spawnContextTask(self):
|
||||||
def spawnContextTask(self):
|
taskMgr.spawnTaskNamed(Task.Task(self.contextTask),
|
||||||
taskMgr.spawnTaskNamed(Task.Task(self.contextTask),
|
'DIRECTContextTask')
|
||||||
'DIRECTContextTask')
|
|
||||||
|
def removeContextTask(self):
|
||||||
def removeContextTask(self):
|
taskMgr.removeTasksNamed('DIRECTContextTask')
|
||||||
taskMgr.removeTasksNamed('DIRECTContextTask')
|
|
||||||
|
def contextTask(self, state):
|
||||||
def contextTask(self, state):
|
# Window Data
|
||||||
# Window Data
|
self.width = self.win.getWidth()
|
||||||
self.width = self.win.getWidth()
|
self.height = self.win.getHeight()
|
||||||
self.height = self.win.getHeight()
|
self.near = self.camNode.getNear()
|
||||||
self.near = self.camNode.getNear()
|
self.far = self.camNode.getFar()
|
||||||
self.far = self.camNode.getFar()
|
self.fovH = self.camNode.getHfov()
|
||||||
self.fovH = self.camNode.getHfov()
|
self.fovV = self.camNode.getVfov()
|
||||||
self.fovV = self.camNode.getVfov()
|
self.nearWidth = math.tan(deg2Rad(self.fovH / 2.0)) * self.near * 2.0
|
||||||
self.nearWidth = math.tan(deg2Rad(self.fovH / 2.0)) * self.near * 2.0
|
self.nearHeight = math.tan(deg2Rad(self.fovV / 2.0)) * self.near * 2.0
|
||||||
self.nearHeight = math.tan(deg2Rad(self.fovV / 2.0)) * self.near * 2.0
|
self.left = -self.nearWidth/2.0
|
||||||
self.left = -self.nearWidth/2.0
|
self.right = self.nearWidth/2.0
|
||||||
self.right = self.nearWidth/2.0
|
self.top = self.nearHeight/2.0
|
||||||
self.top = self.nearHeight/2.0
|
self.bottom = -self.nearHeight/2.0
|
||||||
self.bottom = -self.nearHeight/2.0
|
# Mouse Data
|
||||||
# Mouse Data
|
# Last frame
|
||||||
# Last frame
|
self.mouseLastX = self.mouseX
|
||||||
self.mouseLastX = self.mouseX
|
self.mouseLastY = self.mouseY
|
||||||
self.mouseLastY = self.mouseY
|
# Values for this frame
|
||||||
# Values for this frame
|
# This ranges from -1 to 1
|
||||||
# This ranges from -1 to 1
|
if (base.mouseWatcher.node().hasMouse()):
|
||||||
if (base.mouseWatcher.node().hasMouse()):
|
self.mouseX = base.mouseWatcher.node().getMouseX()
|
||||||
self.mouseX = base.mouseWatcher.node().getMouseX()
|
self.mouseY = base.mouseWatcher.node().getMouseY()
|
||||||
self.mouseY = base.mouseWatcher.node().getMouseY()
|
# Delta percent of window the mouse moved
|
||||||
# Delta percent of window the mouse moved
|
self.mouseDeltaX = self.mouseX - self.mouseLastX
|
||||||
self.mouseDeltaX = self.mouseX - self.mouseLastX
|
self.mouseDeltaY = self.mouseY - self.mouseLastY
|
||||||
self.mouseDeltaY = self.mouseY - self.mouseLastY
|
self.nearVec.set((self.nearWidth/2.0) * self.mouseX,
|
||||||
self.nearVec.set((self.nearWidth/2.0) * self.mouseX,
|
self.near,
|
||||||
self.near,
|
(self.nearHeight/2.0) * self.mouseY)
|
||||||
(self.nearHeight/2.0) * self.mouseY)
|
# Continue the task
|
||||||
# Continue the task
|
return Task.cont
|
||||||
return Task.cont
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user