Beispiel #1
0
    def __init__(self, parent=None, gui=None):
        # First phase: load the configurations.
        if gui == "dgui":
            from dgui.pConfig import Config
        elif gui == "wxgui":
            from wxgui.pConfig import Config
        if gui is not None:
            Config.loadConfig()

        # Second phase: initialize the window manager (which starts ShowBase)
        from core.pWindow import WindowManager
        if gui == "dgui":
            WindowManager.startBase(showDefaultWindow=True,
                                    allowMultipleWindows=False)
        elif gui == "wxgui":
            WindowManager.startBase(showDefaultWindow=False,
                                    allowMultipleWindows=True)
        else:
            from direct.directbase import DirectStart

        if parent is None:
            parent = render

        self.editorGui = False
        self.guiType = gui

        self.editModeEnabled = False

        soundManager.enable()

        self.treeParent = SceneNodeWrapper.onCreateInstance(
            None, 'default.egg')
 def exitDisabled(self):
     # backup settings
     self.backupSettings()
     # start control of camera
     WindowManager.getDefaultCamera().reparentTo(self.cameraRotPivot)
     WindowManager.getDefaultCamera().setY(-STARTUP_CAMERA_DISTANCE)
     self.posPivotModel.show()
 def __init__(self, parent=None, gui=None):
   # First phase: load the configurations.
   if gui == "dgui":
     from dgui.pConfig import Config
   elif gui == "wxgui":
     from wxgui.pConfig import Config
   if gui is not None:
     Config.loadConfig()
   
   # Second phase: initialize the window manager (which starts ShowBase)
   from core.pWindow import WindowManager
   if gui == "dgui":
     WindowManager.startBase(showDefaultWindow = True, allowMultipleWindows = False)
   elif gui == "wxgui":
     WindowManager.startBase(showDefaultWindow = False, allowMultipleWindows = True)
   else:
     from direct.directbase import DirectStart
   
   if parent is None:
     parent = render
   
   self.editorGui = False
   self.guiType = gui
   
   self.editModeEnabled = False
   
   soundManager.enable()
   
   self.treeParent = SceneNodeWrapper.onCreateInstance(None, 'default.egg')
Beispiel #4
0
 def mouseNodeTask(self, task):
   if WindowManager.hasMouse():
     x=WindowManager.getMouseX()
     y=WindowManager.getMouseY()
     # the mouse position is read relative to render2d, so set it accordingly
     self.mouseNode.setPos( render2d, x, 0, y )
   return task.cont
 def exitDisabled( self ):
   # backup settings
   self.backupSettings()
   # start control of camera
   WindowManager.getDefaultCamera().reparentTo( self.cameraRotPivot )
   WindowManager.getDefaultCamera().setY( -STARTUP_CAMERA_DISTANCE )
   self.posPivotModel.show()
 def restoreSettings(self):
     # doesnt work
     # base.camera.reparentTo(self.prevCamParent)
     # this works
     base.camera = WindowManager.getDefaultCamera()
     base.camera.reparentTo(self.prevCamParent)
     base.camera.setPos(self.prevCameraPos)
     if self.prevMouseEnabled:
         base.enableMouse()
 def restoreSettings(self):
   # doesnt work
   # base.camera.reparentTo(self.prevCamParent)
   # this works
   base.camera = WindowManager.getDefaultCamera()
   base.camera.reparentTo(self.prevCamParent)
   base.camera.setPos(self.prevCameraPos)
   if self.prevMouseEnabled:
     base.enableMouse()
 def zoomIn( self ):
   camera = WindowManager.getDefaultCamera()
   if type(camera.node().getLens()) == PerspectiveLens:
     camera.setY( min( -MIN_CAMERA_DISTANCE
             , max( -MAX_CAMERA_DISTANCE
             , camera.getY() + 1 * MOUSE_ZOOM_SPEED ) ) )
   elif type(camera.node().getLens()) == OrthographicLens:
     lens = camera.node().getLens()
     filmSize = lens.getFilmSize()
     lens.setFilmSize(filmSize*0.75)
 def __enableEditor(self):
   ''' the gui will call this function and enabled the core editor using it
   '''
   if self.guiType is not None:
     if self.editModeEnabled is False:
       print "I: core.EditorClass.__enableEditor:"
       
       WindowManager.getDefaultCamera().node().getLens().setFar(5000)
       
       self.sceneHelperModels = NodePath('editor-helper-models')
       self.sceneHelperModels.reparentTo(render)
       self.sceneHelperModels.setLightOff()
       
       # the axis model at 0/0/0
       axis = loader.loadModel( 'zup-axis.egg' )
       axis.reparentTo( self.sceneHelperModels )
       
       scenePicker.toggleEditmode(True)
       #print "I: core.EditorClass.enterWorldEditMode:", modelModificator.__class__.__name__
       modelModificator.toggleEditmode(True)
       
       # enable the texturePainter
       #texturePainter.enableEditor()
       
       # a grid model
       gridNp = DirectGrid(parent=self.sceneHelperModels)
       
       # enable editmode on the object tree
       self.treeParent.setEditmodeEnabled()
       
       # refresh the scenegraphbrowser
       #messenger.send(EVENT_SCENEGRAPH_REFRESH)
       messenger.send(EVENT_SCENEGRAPH_CHANGE_ROOT, [self.treeParent])
       
       messenger.send(EVENT_MODELCONTROLLER_SELECT_OBJECT, [None])
       messenger.send(EVENT_SCENEGRAPH_REFRESH)
       
       self.editModeEnabled = True
     else:
       print "I: core.EditorClass.__enableEditor: editmode already enabled"
   else:
     print "I: core.EditorClass.__enableEditor: editmode unavailable if no gui type defined"
Beispiel #10
0
    def __enableEditor(self):
        ''' the gui will call this function and enabled the core editor using it
    '''
        if self.guiType is not None:
            if self.editModeEnabled is False:
                print "I: core.EditorClass.__enableEditor:"

                WindowManager.getDefaultCamera().node().getLens().setFar(5000)

                self.sceneHelperModels = NodePath('editor-helper-models')
                self.sceneHelperModels.reparentTo(render)
                self.sceneHelperModels.setLightOff()

                # the axis model at 0/0/0
                axis = loader.loadModel('zup-axis.egg')
                axis.reparentTo(self.sceneHelperModels)

                scenePicker.toggleEditmode(True)
                #print "I: core.EditorClass.enterWorldEditMode:", modelModificator.__class__.__name__
                modelModificator.toggleEditmode(True)

                # enable the texturePainter
                #texturePainter.enableEditor()

                # a grid model
                gridNp = DirectGrid(parent=self.sceneHelperModels)

                # enable editmode on the object tree
                self.treeParent.setEditmodeEnabled()

                # refresh the scenegraphbrowser
                #messenger.send(EVENT_SCENEGRAPH_REFRESH)
                messenger.send(EVENT_SCENEGRAPH_CHANGE_ROOT, [self.treeParent])

                messenger.send(EVENT_MODELCONTROLLER_SELECT_OBJECT, [None])
                messenger.send(EVENT_SCENEGRAPH_REFRESH)

                self.editModeEnabled = True
            else:
                print "I: core.EditorClass.__enableEditor: editmode already enabled"
        else:
            print "I: core.EditorClass.__enableEditor: editmode unavailable if no gui type defined"
 def toggleLens(self):
     camera = WindowManager.getDefaultCamera()
     print type(camera.node())
     print type(camera.node().getLens())
     if type(camera.node().getLens()) == PerspectiveLens:
         lens = OrthographicLens()
         lens.setFilmSize(Vec2(10, 10))
         camera.node().setLens(lens)
     elif type(camera.node().getLens()) == OrthographicLens:
         lens = PerspectiveLens()
         camera.node().setLens(lens)
 def toggleLens(self):
   camera = WindowManager.getDefaultCamera()
   print type(camera.node())
   print type(camera.node().getLens())
   if type(camera.node().getLens()) == PerspectiveLens:
     lens = OrthographicLens()
     lens.setFilmSize(Vec2(10,10))
     camera.node().setLens(lens)
   elif type(camera.node().getLens()) == OrthographicLens:
     lens = PerspectiveLens()
     camera.node().setLens(lens)
 def zoomIn(self):
     camera = WindowManager.getDefaultCamera()
     if type(camera.node().getLens()) == PerspectiveLens:
         camera.setY(
             min(
                 -MIN_CAMERA_DISTANCE,
                 max(-MAX_CAMERA_DISTANCE,
                     camera.getY() + 1 * MOUSE_ZOOM_SPEED)))
     elif type(camera.node().getLens()) == OrthographicLens:
         lens = camera.node().getLens()
         filmSize = lens.getFilmSize()
         lens.setFilmSize(filmSize * 0.75)
 def taskMouseButton3Pressed( self, task ):
   # this is needed because the task might be called once more after the exit
   # function has been called
   # also skip first frame
   mx,my = mouseHandler.getMousePos()
   if self.taskMouseButton3PressedRunning and task.frame:
     diffPos = WindowManager.getDefaultCamera().getPos( render ) - self.cameraPosPivot.getPos( render )
     diffPos.normalize()
     self.cameraPosPivot.setX( self.cameraPosPivot.getX() \
                             - mx * diffPos.getY() * MOUSE_MOVEMENT_SPEED
                             - my * diffPos.getX() * MOUSE_MOVEMENT_SPEED )
     self.cameraPosPivot.setY( self.cameraPosPivot.getY() \
                             - my * diffPos.getY() * MOUSE_MOVEMENT_SPEED
                             + mx * diffPos.getX() * MOUSE_MOVEMENT_SPEED )
   return task.cont
 def taskMouseButton3Pressed(self, task):
     # this is needed because the task might be called once more after the exit
     # function has been called
     # also skip first frame
     mx, my = mouseHandler.getMousePos()
     if self.taskMouseButton3PressedRunning and task.frame:
         diffPos = WindowManager.getDefaultCamera().getPos(
             render) - self.cameraPosPivot.getPos(render)
         diffPos.normalize()
         self.cameraPosPivot.setX( self.cameraPosPivot.getX() \
                                 - mx * diffPos.getY() * MOUSE_MOVEMENT_SPEED
                                 - my * diffPos.getX() * MOUSE_MOVEMENT_SPEED )
         self.cameraPosPivot.setY( self.cameraPosPivot.getY() \
                                 - my * diffPos.getY() * MOUSE_MOVEMENT_SPEED
                                 + mx * diffPos.getX() * MOUSE_MOVEMENT_SPEED )
     return task.cont
 def movePivotTask(self, task):
   ''' move the camera pivot by keypresses
   '''
   #print "I: CameraController.movePivotTask:", task.time
   # the movement the camera pivot should make
   moveVec = Vec3(0)
   for key, active in self.pressedKeys.items():
     if active:
       moveVec += self.moveActions[key]
   # move relative to camera viewport
   cam = WindowManager.getDefaultCamera()
   relVec = self.cameraPosPivot.getRelativeVector(cam, moveVec)
   self.cameraPosPivot.setPos(self.cameraPosPivot, relVec*globalClock.getDt())
   # send a event with the new position of the pivot
   pivotPos = Vec3(self.cameraPosPivot.getPos(render))
   messenger.send(EVENT_CAMERAPIVOT_POSITION_CHANGE, [pivotPos])
   return task.cont
 def movePivotTask(self, task):
     ''' move the camera pivot by keypresses
 '''
     #print "I: CameraController.movePivotTask:", task.time
     # the movement the camera pivot should make
     moveVec = Vec3(0)
     for key, active in self.pressedKeys.items():
         if active:
             moveVec += self.moveActions[key]
     # move relative to camera viewport
     cam = WindowManager.getDefaultCamera()
     relVec = self.cameraPosPivot.getRelativeVector(cam, moveVec)
     self.cameraPosPivot.setPos(self.cameraPosPivot,
                                relVec * globalClock.getDt())
     # send a event with the new position of the pivot
     pivotPos = Vec3(self.cameraPosPivot.getPos(render))
     messenger.send(EVENT_CAMERAPIVOT_POSITION_CHANGE, [pivotPos])
     return task.cont
Beispiel #18
0
from pandac.PandaModules import TextNode, Vec3
from direct.gui.DirectGui import DirectFrame,DirectButton,DirectScrolledFrame,DGG

from core.pWindow import WindowManager
if __name__ == '__main__':
  # to test the directWindow independantly
  WindowManager.startBase(showDefaultWindow = True, allowMultipleWindows = False)

# define model path, required if this settings is missing in the Config.pp
from pandac.PandaModules import *
for path in ['../data', './dgui/directWindow/data', './src/dgui/directWindow/data']:
  getModelPath( ).appendPath( path )


DEFAULT_TITLE_TEXTURE_LEFT   = 'titleLeft.png'
DEFAULT_TITLE_TEXTURE_CENTER = 'titleCenter.png'
DEFAULT_TITLE_TEXTURE_RIGHT  = None
DEFAULT_TITLE_GEOM_RIGHT  = 'titleRight.egg'
DEFAULT_RESIZE_GEOM       = 'resize.png'


Y_INVERTED = True

class DirectWindow( DirectFrame ):
  def __init__( self
              , pos         = ( -.5, .5)
              , title       = 'Title'
              , bgColor  = (.5,.5,.5,1)
              , buttonColor = (1,1,1,1) #( .6, .6, .6, 1 )
              #, minSize     = ( .5, .5 )
              #, maxSize     = ( 1, 1 )
 def _getCurrentMousePos(self):
     if WindowManager.hasMouse():
         mpos = WindowManager.getMouse()
         if mpos != None:
             return mpos.getX(), mpos.getY()
     return 0, 0
 def _getCurrentMousePos(self):
     if WindowManager.hasMouse():
         mpos = WindowManager.getMouse()
         if mpos != None:
             return mpos.getX(), mpos.getY()
     return 0, 0