Giter Site home page Giter Site logo

qpanda3d's Introduction

QPanda3D

A working Panda3D wrapper for PyQt5 The objective is to be able to put on the same screen, panda3D and pyQT widgets.

This package is still a work in progress. What works :

  • Creating a panda3D world inside a seemlessly QWidget object that can be placed alog with other QT stuff
  • Full access to panda3D objects, lights ...
  • Keyboard press and up are supported starting from v 0.5 What doesn't work yet:
  • Mouse and timed keyboard interactions

Installation

pip install QPanda3D

Usage

1 - create your world by inheriting from Panda3DWorld

from QPanda3D.Panda3DWorld import Panda3DWorld
class MyWorld(Panda3DWorld):
        Panda3DWorld.__init__(self)
        # from this point, act as if you are defining a classic panda3D environment
        self.cam.setPos(0, -28, 6)
        self.testModel = loader.loadModel('panda')
        self.testModel.reparentTo(render)

2 - In your main, just create an instance of your world, create a Q

from QPanda3D.QPanda3DWidget import QPanda3DWidget
if __name__ == "__main__":
    world = MyWorld()
    
    app = QApplication(sys.argv)
    appw=QMainWindow()
    appw.setGeometry(50, 50, 800, 600)

    pandaWidget = QPanda3DWidget(world)
    appw.setCentralWidget(pandaWidget)
    appw.show()
    
    sys.exit(app.exec_())

Widget resizing policy

Starting from V 0.4, the widget is automatically resized without making any stretching artefacts. Resizing policy parameters (introduced in V 0.2) have been removed since they are no more needed.

from QPanda3D.QPanda3DWidget import QPanda3DWidget
if __name__ == "__main__":
    world = MyWorld()
    
    app = QApplication(sys.argv)
    appw=QMainWindow()
    appw.setGeometry(50, 50, 800, 600)

    pandaWidget = QPanda3DWidget(world)
    appw.setCentralWidget(pandaWidget)
    appw.show()
    
    sys.exit(app.exec_())

you can also tell the Panda3DWorld object what is the default view size that you prefer when creating it.

from QPanda3D.Panda3DWorld import Panda3DWorld
class MyWorld(Panda3DWorld):
        Panda3DWorld.__init__(self, width=1024, height=768)
        # from this point, act as if you are defining a classic panda3D environment
        self.cam.setPos(0, -28, 6)
        self.testModel = loader.loadModel('panda')
        self.testModel.reparentTo(render)

Just make sure that your ratio is adequate with your real widget size.

Mouse events handling

Mouse position is sent from PyQt interface to panda using messages. You can get these information using the following event handlers : mouse1 :Mouse Button 1 Pressed mouse2 :Mouse Button 2 Pressed mouse3 :Mouse Button 3 Pressed mouse1-up :Mouse Button 1 Released mouse2-up :Mouse Button 2 Released mouse3-up :Mouse Button 3 Released wheel_up :Mouse Wheel rolled upwards wheel_down :Mouse Wheel rolled downwards

When you handle those events, starting from version 0.2.9, you can add an event argument to your event handler method to receive relevent information about the actual position of the mouse in the PyQt 2D canvas.

here is an example of how you can use this. You can also find a complete example in the examples list

        #accept few mouse events
        self.accept('mouse1', self.mousePressEventLeft)
        self.accept("mouse2", self.wheelEvent)
        self.accept("mouse1-up", self.mouseReleaseEventLeft)
        self.accept("mouse-move", self.mouseMoveEvent)

    def mousePressEventLeft(self, evt:dict):
        le_key_evt.setText(f"press @ {evt['x']},{evt['y']}")
    def mouseReleaseEventLeft(self, evt:dict):
        le_key_evt.setText(f"release @ {evt['x']},{evt['y']}")
    def wheelEvent(self, evt:dict):
        le_key_evt.setText(f"Wheel with {evt['delta']}")
    def mouseMoveEvent(self, evt:dict):
        le_key_evt.setText(f"Mouse moved to  {evt['x']},{evt['y']}")

Special thanks

I want to thank all the contributers to this little opensource project. In chronological order :

  • Thanks to fraca7 for his commit (Change film size according to widget resize)
  • Many thanks to nmevenkamp for the valuable updates and bugfixes he apported to this project.
  • Also thanks to augasur for bringing to our knowledge problems he faced while using pyinstaller with qpanda3d (preblem solved).
  • Also thanks to arthurpdesimone for bringing to our knowledge problems he faced while using mouse interaction.

If other people want to contribute to this project, the're welcome.

qpanda3d's People

Contributors

parisneo avatar nmevenkamp avatar timozen avatar fraca7 avatar majabojarska avatar marekjansky avatar jakuhor avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.