Qt3D - ess-dmsc/nexus-constructor GitHub Wiki

Transformations

The basic idea is to create a QTransform, then apply it to the QEntity. Like with QEntity, we have to keep hold of the QTransforms we create and not let them go out of scope. https://doc.qt.io/qt-5/qt3dcore-qtransform.html

QTransform has methods to set the orientation and position. Here is some code showing the, probably most convenient, way of setting these, in the context of hacking the InstrumentView.setup_sample_cube() method a little:

    def setup_sample_cube(self):
        """
        Sets up the cube that represents a sample in the 3D view by giving the cube entity a mesh and a material.
        """
        self.set_cube_mesh_dimensions(self.cube_mesh, *self.sample_cube_dimensions)
        self.cube_entity = create_qentity(
            [self.cube_mesh, self.red_material], self.component_root_entity
        )
        self.sample_cube_transform = Qt3DCore.QTransform()
        self.sample_cube_transform.setRotation(QQuaternion.fromAxisAndAngle(QVector3D(1, 0, 0), 45.0))
        self.sample_cube_transform.setTranslation(QVector3D(0.2, 0, 0))
        self.cube_entity.addComponent(self.sample_cube_transform)

Requires the following imports:

from PySide2.Qt3DCore import Qt3DCore
from PySide2.QtGui import QVector3D, QQuaternion

Instanced rendering

Creating a QEntity with it's own mesh and position for each pixel does not seem to scale well about ~10,000 pixels. Instanced rendering may solve this issue, but the only example we have for this in Qt3D uses QML and it isn't clear how/if this maps to non-QML and python: https://github.com/GarageGames/Qt/tree/master/qt-5/qt3d/examples/qt3d/bigscene-instanced-qml