mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 09:52:27 -04:00
Added importing wxPandashell
This commit is contained in:
parent
065b130d64
commit
c300a5911f
@ -1,145 +1,146 @@
|
|||||||
"""
|
"""
|
||||||
This is the module for curve edit
|
This is the module for curve edit
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from pandac.PandaModules import *
|
from pandac.PandaModules import *
|
||||||
from direct.showbase.DirectObject import *
|
from direct.wxwidgets.WxPandaShell import *
|
||||||
from direct.directtools.DirectSelection import SelectionRay
|
from direct.showbase.DirectObject import *
|
||||||
from direct.showutil.Rope import Rope
|
from direct.directtools.DirectSelection import SelectionRay
|
||||||
from ActionMgr import *
|
from direct.showutil.Rope import Rope
|
||||||
from direct.task import Task
|
from ActionMgr import *
|
||||||
import ObjectGlobals as OG
|
from direct.task import Task
|
||||||
|
import ObjectGlobals as OG
|
||||||
class CurveEditor(DirectObject):
|
|
||||||
""" CurveEditor will create and edit the curve """
|
class CurveEditor(DirectObject):
|
||||||
def __init__(self, editor):
|
""" CurveEditor will create and edit the curve """
|
||||||
self.editor = editor
|
def __init__(self, editor):
|
||||||
self.i = 0
|
self.editor = editor
|
||||||
self.ropeNum = 0
|
self.i = 0
|
||||||
self.curve = []
|
self.ropeNum = 0
|
||||||
self.curveControl = []
|
self.curve = []
|
||||||
self.currentRope = None
|
self.curveControl = []
|
||||||
self.degree = 3
|
self.currentRope = None
|
||||||
|
self.degree = 3
|
||||||
def createCurve(self):
|
|
||||||
if self.editor.mode == self.editor.CREATE_CURVE_MODE:
|
def createCurve(self):
|
||||||
self.view = self.editor.ui.currentView
|
if self.editor.mode == self.editor.CREATE_CURVE_MODE:
|
||||||
|
self.view = self.editor.ui.currentView
|
||||||
#Get the mouse position
|
|
||||||
x = base.direct.dr.mouseX
|
#Get the mouse position
|
||||||
y = base.direct.dr.mouseY
|
x = base.direct.dr.mouseX
|
||||||
|
y = base.direct.dr.mouseY
|
||||||
if self.editor.fMoveCamera == False and self.view != None:
|
|
||||||
self.createControler(x,y)
|
if self.editor.fMoveCamera == False and self.view != None:
|
||||||
if self.currentRope != None:
|
self.createControler(x,y)
|
||||||
self.currentRope.detachNode()
|
if self.currentRope != None:
|
||||||
self.ropeUpdate(self.curve)
|
self.currentRope.detachNode()
|
||||||
self.accept("DIRECT-enter", self.onBaseMode)
|
self.ropeUpdate(self.curve)
|
||||||
|
self.accept("DIRECT-enter", self.onBaseMode)
|
||||||
self.accept("DIRECT-enter", self.onBaseMode)
|
|
||||||
|
self.accept("DIRECT-enter", self.onBaseMode)
|
||||||
def editCurve(self, task):
|
|
||||||
if self.editor.mode == self.editor.EDIT_CURVE_MODE:
|
def editCurve(self, task):
|
||||||
if self.editor.fMoveCamera == False:
|
if self.editor.mode == self.editor.EDIT_CURVE_MODE:
|
||||||
self.selected = None
|
if self.editor.fMoveCamera == False:
|
||||||
self.selected = base.direct.selected.last
|
self.selected = None
|
||||||
if self.selected != None:
|
self.selected = base.direct.selected.last
|
||||||
for item in self.curveControl:
|
if self.selected != None:
|
||||||
if item[1] == self.selected:
|
for item in self.curveControl:
|
||||||
self.point = item #temporarily save the controler information for further use
|
if item[1] == self.selected:
|
||||||
self.currentCurve = self.currentRope.ropeNode.getCurve()
|
self.point = item #temporarily save the controler information for further use
|
||||||
self.currentCurve.setVertex(item[0], self.selected.getPos())
|
self.currentCurve = self.currentRope.ropeNode.getCurve()
|
||||||
self.accept("DIRECT-delete", self.onControlerDelete)
|
self.currentCurve.setVertex(item[0], self.selected.getPos())
|
||||||
return task.cont
|
self.accept("DIRECT-delete", self.onControlerDelete)
|
||||||
|
return task.cont
|
||||||
def onControlerDelete(self):
|
|
||||||
if self.editor.mode == self.editor.EDIT_CURVE_MODE:
|
def onControlerDelete(self):
|
||||||
self.curve.remove(self.curve[self.point[0]])
|
if self.editor.mode == self.editor.EDIT_CURVE_MODE:
|
||||||
#reset the controller list
|
self.curve.remove(self.curve[self.point[0]])
|
||||||
for item in self.curveControl:
|
#reset the controller list
|
||||||
if item[0] > self.point[0]:
|
for item in self.curveControl:
|
||||||
newname = 'controler%d' % (item[0]-1)
|
if item[0] > self.point[0]:
|
||||||
item[1].setName(newname)
|
newname = 'controler%d' % (item[0]-1)
|
||||||
self.curveControl[item[0]] = (item[0]-1, item[1])
|
item[1].setName(newname)
|
||||||
self.curveControl.remove(self.point)
|
self.curveControl[item[0]] = (item[0]-1, item[1])
|
||||||
self.currentRope.setup(self.degree,self.curve)
|
self.curveControl.remove(self.point)
|
||||||
|
self.currentRope.setup(self.degree,self.curve)
|
||||||
def ropeUpdate(self, curve):
|
|
||||||
self.currentRope = Rope()
|
def ropeUpdate(self, curve):
|
||||||
self.currentRope.setup(self.degree, curve)
|
self.currentRope = Rope()
|
||||||
self.currentRope.reparentTo(render)
|
self.currentRope.setup(self.degree, curve)
|
||||||
|
self.currentRope.reparentTo(render)
|
||||||
def onBaseMode(self):
|
|
||||||
self.editor.preMode = self.editor.mode
|
def onBaseMode(self):
|
||||||
self.editor.mode = self.editor.BASE_MODE
|
self.editor.preMode = self.editor.mode
|
||||||
self.editor.ui.editCurveMenuItem.Check(False)
|
self.editor.mode = self.editor.BASE_MODE
|
||||||
self.editor.ui.createCurveMenuItem.Check(False)
|
self.editor.ui.editCurveMenuItem.Check(False)
|
||||||
self.i = 0
|
self.editor.ui.createCurveMenuItem.Check(False)
|
||||||
for item in self.curveControl:
|
self.i = 0
|
||||||
item[1].hide()
|
for item in self.curveControl:
|
||||||
if self.editor.preMode == self.editor.BASE_MODE :
|
item[1].hide()
|
||||||
pass
|
if self.editor.preMode == self.editor.BASE_MODE :
|
||||||
if self.editor.preMode == self.editor.CREATE_CURVE_MODE :
|
pass
|
||||||
self.updateScene()
|
if self.editor.preMode == self.editor.CREATE_CURVE_MODE :
|
||||||
if self.editor.preMode == self.editor.EDIT_CURVE_MODE :
|
self.updateScene()
|
||||||
self.doneEdit()
|
if self.editor.preMode == self.editor.EDIT_CURVE_MODE :
|
||||||
self.curveControl = []
|
self.doneEdit()
|
||||||
self.curve = []
|
self.curveControl = []
|
||||||
self.currentRope = None
|
self.curve = []
|
||||||
base.direct.manipulationControl.enableManipulation()
|
self.currentRope = None
|
||||||
self.editor.ui.createCurveMenuItem.Check(False)
|
base.direct.manipulationControl.enableManipulation()
|
||||||
self.editor.ui.editCurveMenuItem.Check(False)
|
self.editor.ui.createCurveMenuItem.Check(False)
|
||||||
|
self.editor.ui.editCurveMenuItem.Check(False)
|
||||||
def updateScene(self):
|
|
||||||
curveObjNP = self.editor.objectMgr.addNewCurve(self.curveControl, self.degree, nodePath=self.currentRope)
|
def updateScene(self):
|
||||||
curveObj = self.editor.objectMgr.findObjectByNodePath(curveObjNP)
|
curveObjNP = self.editor.objectMgr.addNewCurve(self.curveControl, self.degree, nodePath=self.currentRope)
|
||||||
for item in self.curveControl:
|
curveObj = self.editor.objectMgr.findObjectByNodePath(curveObjNP)
|
||||||
item[1].reparentTo(curveObjNP)
|
for item in self.curveControl:
|
||||||
self.editor.objectMgr.updateObjectPropValue(curveObj, 'Degree', self.degree, fSelectObject=False, fUndo=False)
|
item[1].reparentTo(curveObjNP)
|
||||||
|
self.editor.objectMgr.updateObjectPropValue(curveObj, 'Degree', self.degree, fSelectObject=False, fUndo=False)
|
||||||
def doneEdit(self):
|
|
||||||
base.direct.selected.last = None
|
def doneEdit(self):
|
||||||
|
base.direct.selected.last = None
|
||||||
def createControler(self, x, y):
|
|
||||||
if self.view != None:
|
def createControler(self, x, y):
|
||||||
self.controler = render.attachNewNode("controler")
|
if self.view != None:
|
||||||
self.controler = loader.loadModel('models/misc/smiley')
|
self.controler = render.attachNewNode("controler")
|
||||||
controlerPathname = 'controler%d' % self.i
|
self.controler = loader.loadModel('models/misc/smiley')
|
||||||
self.controler.setName(controlerPathname)
|
controlerPathname = 'controler%d' % self.i
|
||||||
self.controler.setColor(0, 0, 0, 1)
|
self.controler.setName(controlerPathname)
|
||||||
self.controler.setScale(0.2)
|
self.controler.setColor(0, 0, 0, 1)
|
||||||
self.controler.reparentTo(render)
|
self.controler.setScale(0.2)
|
||||||
self.controler.setTag('OBJRoot','1')
|
self.controler.reparentTo(render)
|
||||||
self.controler.setTag('Controller','1') #controller Tag
|
self.controler.setTag('OBJRoot','1')
|
||||||
self.i += 1
|
self.controler.setTag('Controller','1') #controller Tag
|
||||||
|
self.i += 1
|
||||||
iRay = SelectionRay(self.view.camera)
|
|
||||||
iRay.collider.setFromLens(self.view.camNode, x, y)
|
iRay = SelectionRay(self.view.camera)
|
||||||
iRay.collideWithBitMask(BitMask32.bit(21))
|
iRay.collider.setFromLens(self.view.camNode, x, y)
|
||||||
iRay.ct.traverse(self.view.collPlane)
|
iRay.collideWithBitMask(BitMask32.bit(21))
|
||||||
if iRay.getNumEntries() > 0:
|
iRay.ct.traverse(self.view.collPlane)
|
||||||
entry = iRay.getEntry(0)
|
if iRay.getNumEntries() > 0:
|
||||||
hitPt = entry.getSurfacePoint(entry.getFromNodePath())
|
entry = iRay.getEntry(0)
|
||||||
|
hitPt = entry.getSurfacePoint(entry.getFromNodePath())
|
||||||
if hitPt:
|
|
||||||
# create a temp nodePath to get the position
|
if hitPt:
|
||||||
np = NodePath('temp')
|
# create a temp nodePath to get the position
|
||||||
np.setPos(self.view.camera, hitPt)
|
np = NodePath('temp')
|
||||||
|
np.setPos(self.view.camera, hitPt)
|
||||||
if base.direct.manipulationControl.fGridSnap:
|
|
||||||
snappedPos = self.view.grid.computeSnapPoint(np.getPos())
|
if base.direct.manipulationControl.fGridSnap:
|
||||||
np.setPos(snappedPos)
|
snappedPos = self.view.grid.computeSnapPoint(np.getPos())
|
||||||
|
np.setPos(snappedPos)
|
||||||
# update temp nodePath's HPR and scale with newobj's
|
|
||||||
np.setHpr(self.controler.getHpr())
|
# update temp nodePath's HPR and scale with newobj's
|
||||||
np.setScale(self.controler.getScale())
|
np.setHpr(self.controler.getHpr())
|
||||||
|
np.setScale(self.controler.getScale())
|
||||||
# transform newobj to cursor position
|
|
||||||
self.controler.setMat(Mat4(np.getMat()))
|
# transform newobj to cursor position
|
||||||
np.remove()
|
self.controler.setMat(Mat4(np.getMat()))
|
||||||
iRay.collisionNodePath.removeNode()
|
np.remove()
|
||||||
del iRay
|
iRay.collisionNodePath.removeNode()
|
||||||
|
del iRay
|
||||||
self.curve.append((None, self.controler.getPos()))
|
|
||||||
self.curveControl.append((self.i-1, self.controler))
|
self.curve.append((None, self.controler.getPos()))
|
||||||
|
self.curveControl.append((self.i-1, self.controler))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user