Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-2255

Not able to inherit from QAbstractCameraController on PySide6

    XMLWordPrintable

Details

    • Linux/Wayland, macOS, Windows
    • 10b3c1626 (dev), f73f8562f (6.4)

    Description

      I'm using PySide6 on Python 3.11 on Mac, Windows and Linux. I'm trying to create a Trackball to Qt3D in Python based on this https://github.com/cjmdaixi/Qt3DTrackball. So I'm creating the `TrackballCameraController` inheriting from `QAbstractCameraController.moveCamera`. Here a simple sample:

      import sys
      from typing import Optional
      
      from PySide6.Qt3DCore import Qt3DCore
      from PySide6.Qt3DExtras import Qt3DExtras
      from PySide6.Qt3DInput import Qt3DInput
      from PySide6.Qt3DRender import Qt3DRender
      from PySide6.QtCore import QObject, QPoint, QSize, QUrl
      from PySide6.QtGui import QColor, QGuiApplication, QVector3D, qRgb
      from PySide6.QtWidgets import QApplication
      
      
      class TrackballCameraController(Qt3DExtras.QAbstractCameraController):
          def __init__(self, parent: Optional[Qt3DCore.QNode]=None):
              super().__init__(parent)
      
          def moveCamera(self, state: Qt3DExtras.QAbstractCameraController.InputState, dt: float):
              print("moveCamera")
      
      
      def create_sphere(parent: Qt3DCore.QEntity) -> Qt3DCore.QEntity:
          # Create sphere mesh
          sphere_mesh = Qt3DExtras.QSphereMesh(parent)
          sphere_mesh.setRadius(3.0)
      
          # Create sphere material
          sphere_material = Qt3DExtras.QPhongMaterial(parent)
          # sphere_material.setDiffuse(QColor(255, 0, 0))
          #
          sphere_transform = Qt3DCore.QTransform(parent)
          # sphere_transform.setTranslation(QVector3D(-3, -3, -3))
      
          # Create sphere entity
          sphere_entity = Qt3DCore.QEntity(parent)
          sphere_entity.addComponent(sphere_mesh)
          sphere_entity.addComponent(sphere_transform)
          sphere_entity.addComponent(sphere_material)
      
          return sphere_entity
      
      
      if __name__ == "__main__":
          # Create application
          app = QGuiApplication(sys.argv)
      
          # Create window
          window = Qt3DExtras.Qt3DWindow()
          window.setTitle("Sphere Example")
      
          # Create root entity
          root_entity = Qt3DCore.QEntity()
      
          # Create sphere entity
          sphere_entity = create_sphere(root_entity)
      
          print(sphere_entity.components())
      
          camera = window.camera()
          camera.setPosition(QVector3D(0.0, 0.0, 40.0))
          camera.setViewCenter(QVector3D(0.0, 0.0, 0.0))
          camera.lens().setPerspectiveProjection(45.0, 16.0 / 9.0, 0.1, 1000)
      
          camera_controller = TrackballCameraController(root_entity)
          camera_controller.setCamera(camera)
      
          # Set root entity as the root of the scene
          window.setRootEntity(root_entity)
          window.defaultFrameGraph().setClearColor(QColor(0, 0, 255))
          # Show window
          window.show()
      
          # Run application
          sys.exit(app.exec())
      

      On Mac I'm getting this error: 

      Qt3D.Renderer.RHI.Backend: Initializing RHI with Metal backend
      Traceback (most recent call last):
        File "/Users/thiago/Sources/qt3d_experiments/draw_sphere.py", line 73, in <module>
          sys.exit(app.exec())
                   ^^^^^^^^^^
      NotImplementedError: pure virtual method 'QAbstractCameraController.moveCamera' not implemented.
      

      But I implemented `moveCamera` in my child class... Is it correct to inherit from `QAbstractCameraController`? Do I need to do more things to inherit from `QAbstractCameraController`?

        If I run the sample code I posted in Linux the sphere doesn't show and when I close the window the process doesn't stop, I have to kill it. 

      On Windows this error happens:

      Qt3D.Renderer.RHI.Backend: Initializing RHI with DirectX backend
      Qt3D.Renderer.RHI.Backend: Can't create pipeline, incomplete SwapChain and no default Render Target
      

      If I comment the part that creates the TrackballCameraController this problem doesn't happen.

      Attachments

        1. pyside2255.py
          2 kB
        2. pyside2255_diag.diff
          2 kB
        3. pyside2255_log.txt
          0.5 kB

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              ctismer Christian Tismer
              manuelo Thiago Moraes
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes