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
da2592c934
commit
97c64f8820
@ -42,6 +42,9 @@ class LineNodePath(NodePath):
|
|||||||
def setColor( self, *_args ):
|
def setColor( self, *_args ):
|
||||||
apply( self.lineSegs.setColor, _args )
|
apply( self.lineSegs.setColor, _args )
|
||||||
|
|
||||||
|
def setVertex( self, *_args):
|
||||||
|
apply( self.lineSegs.setVertex, _args )
|
||||||
|
|
||||||
def setVertexColor( self, vertex, *_args ):
|
def setVertexColor( self, vertex, *_args ):
|
||||||
apply( self.lineSegs.setVertexColor, (vertex,) + _args )
|
apply( self.lineSegs.setVertexColor, (vertex,) + _args )
|
||||||
|
|
||||||
@ -51,8 +54,8 @@ class LineNodePath(NodePath):
|
|||||||
def getNumVertices( self ):
|
def getNumVertices( self ):
|
||||||
return self.lineSegs.getNumVertices()
|
return self.lineSegs.getNumVertices()
|
||||||
|
|
||||||
def getVertex( self ):
|
def getVertex( self, index ):
|
||||||
return self.lineSegs.getVertex()
|
return self.lineSegs.getVertex(index)
|
||||||
|
|
||||||
def getVertexColor( self ):
|
def getVertexColor( self ):
|
||||||
return self.lineSegs.getVertexColor()
|
return self.lineSegs.getVertexColor()
|
||||||
|
@ -1,9 +1,134 @@
|
|||||||
from PandaObject import *
|
from PandaObject import *
|
||||||
|
from DirectGeometry import *
|
||||||
|
|
||||||
class DirectGrid(NodePath):
|
class DirectGrid(NodePath,PandaObject):
|
||||||
def __init__(self, parent = None):
|
def __init__(self, direct):
|
||||||
|
# Initialize superclass
|
||||||
NodePath.__init__(self)
|
NodePath.__init__(self)
|
||||||
if parent is None:
|
self.assign(hidden.attachNewNode( NamedNode('DirectGrid')))
|
||||||
parent = hidden
|
|
||||||
self.assign(parent.attachNewNode( NamedNode('grid') ))
|
|
||||||
|
|
||||||
|
# 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()
|
||||||
|
@ -2,6 +2,7 @@ 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 DirectGeometry import *
|
from DirectGeometry import *
|
||||||
import OnscreenText
|
import OnscreenText
|
||||||
|
|
||||||
@ -20,6 +21,8 @@ class DirectSession(PandaObject):
|
|||||||
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.disable()
|
||||||
|
|
||||||
# Initialize the collection of selected nodePaths
|
# Initialize the collection of selected nodePaths
|
||||||
self.selected = SelectedNodePaths(self)
|
self.selected = SelectedNodePaths(self)
|
||||||
@ -72,10 +75,9 @@ class DirectSession(PandaObject):
|
|||||||
self.cameraControl.updateCoa(coa)
|
self.cameraControl.updateCoa(coa)
|
||||||
|
|
||||||
# Adjust widgets size
|
# Adjust widgets size
|
||||||
self.widget.setScale(dnp.getRadius())
|
# This uses the additional scaling factor used to grow and
|
||||||
# This is the additional scaling factor used to grow and
|
|
||||||
# shrink the widget
|
# shrink the widget
|
||||||
self.widget.setScalingFactor(1.0)
|
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')
|
||||||
|
3310
direct/src/leveleditor/LevelEditor.py
Normal file
3310
direct/src/leveleditor/LevelEditor.py
Normal file
File diff suppressed because it is too large
Load Diff
111
direct/src/leveleditor/PieMenu.py
Normal file
111
direct/src/leveleditor/PieMenu.py
Normal 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
|
3
direct/src/leveleditor/Sources.pp
Normal file
3
direct/src/leveleditor/Sources.pp
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
// For now, since we are not installing Python files, this file can
|
||||||
|
// remain empty.
|
||||||
|
|
@ -15,7 +15,7 @@ class OnscreenText(PandaObject, NodePath):
|
|||||||
NodePath.__init__(self)
|
NodePath.__init__(self)
|
||||||
|
|
||||||
# make a text node
|
# make a text node
|
||||||
textNode = TextNode()
|
self.textNode = textNode = TextNode()
|
||||||
textNode.setBillboard(0)
|
textNode.setBillboard(0)
|
||||||
textNode.setTextColor(0.0, 0.0, 0.0, 1.0)
|
textNode.setTextColor(0.0, 0.0, 0.0, 1.0)
|
||||||
textNode.setCardColor(1.0, 1.0, 1.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
|
# render2d has x across and z up
|
||||||
self.setPos(x, 0.0, y)
|
self.setPos(x, 0.0, y)
|
||||||
|
|
||||||
|
def setColor(self, color):
|
||||||
|
self.textNode.setCardColor(color[0],color[1],color[2],color[3])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user