[qt6][components] Update Scene3DHelper and TrackballController

Call the `QGeometry` objects from the correct module, and initialize
correctly the Camera object upon the construction of the
TrackballController object.
This commit is contained in:
Candice Bentéjac 2024-10-01 16:35:20 +02:00
parent 138cc18864
commit 2a7844480b

View file

@ -41,14 +41,14 @@ class Scene3DHelper(QObject):
def faceCount(self, entity): def faceCount(self, entity):
""" Returns face count based on children QGeometry buffers size.""" """ Returns face count based on children QGeometry buffers size."""
count = 0 count = 0
for geo in entity.findChildren(Qt3DRender.QGeometry): for geo in entity.findChildren(Qt3DCore.QGeometry):
count += sum([attr.count() for attr in geo.attributes() if attr.name() == "vertexPosition"]) count += sum([attr.count() for attr in geo.attributes() if attr.name() == "vertexPosition"])
return count / 3 return count / 3
@Slot(Qt3DCore.QEntity, result=int) @Slot(Qt3DCore.QEntity, result=int)
def vertexColorCount(self, entity): def vertexColorCount(self, entity):
count = 0 count = 0
for geo in entity.findChildren(Qt3DRender.QGeometry): for geo in entity.findChildren(Qt3DCore.QGeometry):
count += sum([attr.count() for attr in geo.attributes() if attr.name() == "vertexColor"]) count += sum([attr.count() for attr in geo.attributes() if attr.name() == "vertexColor"])
return count return count
@ -59,10 +59,12 @@ class TrackballController(QObject):
Based on the C++ version from https://github.com/cjmdaixi/Qt3DTrackball Based on the C++ version from https://github.com/cjmdaixi/Qt3DTrackball
""" """
_windowSize = QSize() def __init__(self, parent=None):
_camera = None super().__init__(parent)
_trackballSize = 1.0 self._windowSize = QSize()
_rotationSpeed = 5.0 self._camera = None
self._trackballSize = 1.0
self._rotationSpeed = 5.0
def projectToTrackball(self, screenCoords): def projectToTrackball(self, screenCoords):
sx = screenCoords.x() sx = screenCoords.x()
@ -98,7 +100,7 @@ class TrackballController(QObject):
windowSizeChanged = Signal() windowSizeChanged = Signal()
windowSize = makeProperty(QSize, '_windowSize', windowSizeChanged) windowSize = makeProperty(QSize, '_windowSize', windowSizeChanged)
cameraChanged = Signal() cameraChanged = Signal()
camera = makeProperty(Qt3DRender.QCamera, '_camera', cameraChanged) camera = makeProperty(QObject, '_camera', cameraChanged)
trackballSizeChanged = Signal() trackballSizeChanged = Signal()
trackballSize = makeProperty(float, '_trackballSize', trackballSizeChanged) trackballSize = makeProperty(float, '_trackballSize', trackballSizeChanged)
rotationSpeedChanged = Signal() rotationSpeedChanged = Signal()