*** empty log message ***

This commit is contained in:
Mark Mine 2000-10-31 07:58:54 +00:00
parent da2592c934
commit 97c64f8820
8 changed files with 3574 additions and 17 deletions

View File

@ -143,7 +143,7 @@ class DirectCameraControl(PandaObject):
def centerCamNow(self, chan):
self.centerCamIn(chan, 0.)
def centerCamIn(self, chan,t):
def centerCamIn(self, chan, t):
# Chan is a display region context
taskMgr.removeTasksNamed('manipulateCamera')
markerToCam = self.coaMarker.getPos( chan.camera )

View File

@ -42,6 +42,9 @@ class LineNodePath(NodePath):
def setColor( self, *_args ):
apply( self.lineSegs.setColor, _args )
def setVertex( self, *_args):
apply( self.lineSegs.setVertex, _args )
def setVertexColor( self, vertex, *_args ):
apply( self.lineSegs.setVertexColor, (vertex,) + _args )
@ -51,8 +54,8 @@ class LineNodePath(NodePath):
def getNumVertices( self ):
return self.lineSegs.getNumVertices()
def getVertex( self ):
return self.lineSegs.getVertex()
def getVertex( self, index ):
return self.lineSegs.getVertex(index)
def getVertexColor( self ):
return self.lineSegs.getVertexColor()

View File

@ -1,9 +1,134 @@
from PandaObject import *
class DirectGrid(NodePath):
def __init__(self, parent = None):
NodePath.__init__(self)
if parent is None:
parent = hidden
self.assign(parent.attachNewNode( NamedNode('grid') ))
from PandaObject import *
from DirectGeometry import *
class DirectGrid(NodePath,PandaObject):
def __init__(self, direct):
# Initialize superclass
NodePath.__init__(self)
self.assign(hidden.attachNewNode( NamedNode('DirectGrid')))
# Record handle to direct session
self.direct = direct
# Load up grid parts to initialize grid object
# Polygon used to mark grid plane
self.gridBack = loader.loadModel('misc/gridBack')
self.gridBack.reparentTo(self)
self.gridBack.setColor(0.5,0.5,0.5,0.5)
# Grid Lines
self.lines = self.attachNewNode(NamedNode('gridLines'))
self.minorLines = LineNodePath(self.lines)
self.minorLines.lineNode.setName('minorLines')
self.minorLines.setColor(VBase4(0.3,0.55,1,1))
self.minorLines.setThickness(1)
self.majorLines = LineNodePath(self.lines)
self.majorLines.lineNode.setName('majorLines')
self.majorLines.setColor(VBase4(0.3,0.55,1,1))
self.majorLines.setThickness(5)
self.centerLines = LineNodePath(self.lines)
self.centerLines.lineNode.setName('centerLines')
self.centerLines.setColor(VBase4(1,0,0,0))
self.centerLines.setThickness(3)
# Small marker to hilight snap-to-grid point
self.snapMarker = loader.loadModel('misc/sphere')
self.snapMarker.node().setName('gridSnapMarker')
self.snapMarker.reparentTo(self)
self.snapMarker.setColor(1,0,0,1)
self.snapMarker.setScale(0.3)
self.snapPos = Point3(0)
# Initialize Grid characteristics
self.fXyzSnap = 1
self.gridSize = 100.0
self.gridSpacing = 5.0
self.enable()
def enable(self):
self.reparentTo(render)
self.accept('selectedNodePath', self.selectGridBackParent)
self.updateGrid()
def disable(self):
self.reparentTo(hidden)
self.ignore('selectedNodePath')
def selectGridBackParent(self, nodePath):
if nodePath.getNodePathName() == 'GridBack':
self.direct.select(self)
def updateGrid(self):
# Update grid lines based upon current grid spacing and grid size
# First reset existing grid lines
self.minorLines.reset()
self.majorLines.reset()
self.centerLines.reset()
# Now redraw lines
numLines = math.ceil(self.gridSize/self.gridSpacing)
scaledSize = numLines * self.gridSpacing
center = self.centerLines
minor = self.minorLines
major = self.majorLines
for i in range(-numLines,numLines + 1):
if i == 0:
center.moveTo(i * self.gridSpacing, -scaledSize, 0)
center.drawTo(i * self.gridSpacing, scaledSize, 0)
center.moveTo(-scaledSize, i * self.gridSpacing, 0)
center.drawTo(scaledSize, i * self.gridSpacing, 0)
else:
if (i % 5) == 0:
major.moveTo(i * self.gridSpacing, -scaledSize, 0)
major.drawTo(i * self.gridSpacing, scaledSize, 0)
major.moveTo(-scaledSize, i * self.gridSpacing, 0)
major.drawTo(scaledSize, i * self.gridSpacing, 0)
else:
minor.moveTo(i * self.gridSpacing, -scaledSize, 0)
minor.drawTo(i * self.gridSpacing, scaledSize, 0)
minor.moveTo(-scaledSize, i * self.gridSpacing, 0)
minor.drawTo(scaledSize, i * self.gridSpacing, 0)
center.create()
minor.create()
major.create()
self.gridBack.setScale(scaledSize)
def roundTo(self, value, divisor):
return round(value/float(divisor)) * divisor
def setXyzSnap(self, fSnap):
self.fXyzSnap = fSnap
def getXyzSnap(self):
return self.fXyzSnap
def snapToGrid(self, point):
if self.fXyzSnap:
self.snapPos.set(
roundTo(point[0], self.gridSpacing),
roundTo(point[1], self.gridSpacing),
roundTo(point[2], self.gridSpacing))
else:
self.snapPos.assign(point)
# Move snap marker to this point
self.snapMarker.setPos(self.snapPos)
# Return the hit point
return self.snapPos
def setGridSpacing(self, spacing):
self.gridSpacing = spacing
self.updateGrid()
def getGridSpacing(self):
return self.gridSpacing
def setSize(self, size):
# Set size of grid back and redraw lines
self.gridSize = size
self.updateGrid()

View File

@ -2,6 +2,7 @@ from PandaObject import *
from DirectCameraControl import *
from DirectManipulation import *
from DirectSelection import *
from DirectGrid import *
from DirectGeometry import *
import OnscreenText
@ -20,6 +21,8 @@ class DirectSession(PandaObject):
self.cameraControl = DirectCameraControl(self)
self.manipulationControl = DirectManipulationControl(self)
self.useObjectHandles()
self.grid = DirectGrid(self)
self.grid.disable()
# Initialize the collection of selected nodePaths
self.selected = SelectedNodePaths(self)
@ -72,10 +75,9 @@ class DirectSession(PandaObject):
self.cameraControl.updateCoa(coa)
# Adjust widgets size
self.widget.setScale(dnp.getRadius())
# This is the additional scaling factor used to grow and
# shrink the widget
self.widget.setScalingFactor(1.0)
# This uses the additional scaling factor used to grow and
# shrink the widget
self.widget.setScalingFactor(dnp.getRadius())
# Spawn task to have object handles follow the selected object
taskMgr.removeTasksNamed('followSelectedNodePath')

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,111 @@
from PandaObject import *
from DirectGeometry import *
class PieMenu(NodePath, PandaObject):
def __init__(self, direct, menu, action = None, fUpdateOnlyOnChange = 1):
NodePath.__init__(self)
# Become the menu
self.assign(menu)
# Initialize instance variables
self.direct = direct
self.numItems = self.getNumChildren()
self.degreesPerItem = 360.0/self.numItems
self.sfx = self.getSx()
self.sfz = self.getSz()
# Record target and action
self.action = action
self.initialState = None
# Marking lines
self.lines = LineNodePath(self)
self.lines.setColor(VBase4(1))
self.lines.setThickness(1)
# Set flags
self.fUpdateOnlyOnChange = fUpdateOnlyOnChange
self.itemOffset = 0
def performAction(self, value):
if action:
action(value)
def removePieMenuTask(self):
taskMgr.removeTasksNamed('pieMenuTask')
self.reparentTo(hidden)
self.lines.reset()
def spawnPieMenuTask(self):
# Make sure no errant tasks lying around
taskMgr.removeTasksNamed('pieMenuTask')
# Where did the user press the button?
self.originX = self.direct.chan.mouseX
self.originY = self.direct.chan.mouseY
# Pop up menu
self.reparentTo(render2d)
self.setPos(self.originX,0.0,self.originY)
# Start drawing the selection line
self.lines.reset()
self.lines.moveTo(0,0,0)
self.lines.drawTo(0,0,0)
self.lines.create()
# Spawn task to update line and select new texture
self.currItem = -1
t = Task.Task(self.pieMenuTask)
taskMgr.spawnTaskNamed(t, 'pieMenuTask')
def pieMenuTask(self,state):
mouseX = self.direct.chan.mouseX
mouseY = self.direct.chan.mouseY
deltaX = mouseX - self.originX
deltaY = mouseY - self.originY
# Update the line
self.lines.setVertex(1,(deltaX/sfx),0.0,(deltaY / sfz))
# How far from starting point has user moved the cursor?
if ((abs(deltaX) < 0.1) & (abs(deltaY) < 0.1)):
# In the center
if self.fUpdateOnlyOnChange:
# Only do this when things change
if (self.currItem != -1):
self.performAction(-1)
else:
# Alway let use know mouse is in the center
self.performAction(-1)
self.currItem = -1
# Interacting with menu
# subtract half a slice to effectively center item
menuAngle = rad2Deg(math.atan2(deltaY, deltaX)) + self.itemOffset
if menuAngle < 0.0:
menuAngle = menuAngle + 360.0
menuAngle = menuAngle % 360.0
newItem = math.floor(menuAngle / self.degreesPerItem)
if self.fUpdateOnlyOnChange:
if (self.currItem != newItem):
self.performAction(newItem)
else:
self.performAction(newItem)
self.currItem = newItem
# Continue task
return Task.cont
def setInitialState(self,state):
self.initialState = state
def getInitialState(self):
return self.initialState
def setItemOffset(self,newOffset):
self.itemOffset = newOffset
def setNumItems(self,num):
self.numItems = num
self.degreesPerItem = 360.0 / self.numItems
self.itemOffset = self.degreesPerItem / 2.0
def setUpdateOnlyOnChange(self,flag):
self.fUpdateOnlyOnChange = flag

View File

@ -0,0 +1,3 @@
// For now, since we are not installing Python files, this file can
// remain empty.

View File

@ -15,7 +15,7 @@ class OnscreenText(PandaObject, NodePath):
NodePath.__init__(self)
# make a text node
textNode = TextNode()
self.textNode = textNode = TextNode()
textNode.setBillboard(0)
textNode.setTextColor(0.0, 0.0, 0.0, 1.0)
textNode.setCardColor(1.0, 1.0, 1.0, 1.0)
@ -51,3 +51,6 @@ class OnscreenText(PandaObject, NodePath):
"""
# render2d has x across and z up
self.setPos(x, 0.0, y)
def setColor(self, color):
self.textNode.setCardColor(color[0],color[1],color[2],color[3])