def create_gnomon_text(self): """ Prepares the gnomon text by creating text entities and then placing them at the ends of the cones. """ x_axis_text = Qt3DExtras.QText2DEntity(self.gnomon_root_entity) y_axis_text = Qt3DExtras.QText2DEntity(self.gnomon_root_entity) z_axis_text = Qt3DExtras.QText2DEntity(self.gnomon_root_entity) self.set_axis_label_text(x_axis_text, "X", AxisColors.X.value) # Pass "green" rather than the Y axis enum value because otherwise the text is too bright self.set_axis_label_text(y_axis_text, "Y", QColor("green")) self.set_axis_label_text(z_axis_text, "Z", AxisColors.Z.value) ( x_label_matrix, y_label_matrix, z_label_matrix, ) = self.create_axis_label_matrices( [self.x_text_vector, self.y_text_vector, self.z_text_vector]) self.x_text_transformation.setMatrix(x_label_matrix) self.y_text_transformation.setMatrix(y_label_matrix) self.z_text_transformation.setMatrix(z_label_matrix) x_axis_text.addComponent(self.x_text_transformation) y_axis_text.addComponent(self.y_text_transformation) z_axis_text.addComponent(self.z_text_transformation)
def create_material( ambient: QColor, diffuse: QColor, parent: Qt3DCore.QEntity, alpha: float = None, remove_shininess: bool = False, ) -> Qt3DRender.QMaterial: """ Creates a material and then sets its ambient, diffuse, alpha (if provided) properties. Sets shininess to zero if instructed. :param ambient: The desired ambient colour of the material. :param diffuse: The desired diffuse colour of the material. :param alpha: The desired alpha value of the material. Optional argument as not all material-types have this property. :param remove_shininess: Boolean indicating whether or not to remove shininess. This is used for the gnomon. :return A material that is now able to be added to an entity. """ if alpha is not None: material = Qt3DExtras.QPhongAlphaMaterial(parent) material.setAlpha(alpha) else: material = Qt3DExtras.QPhongMaterial(parent) if remove_shininess: material.setShininess(0) material.setAmbient(ambient) material.setDiffuse(diffuse) return material
def __init__(self, parentEntity): super(Cube, self).__init__() # build the cube side = 15 self.cubeEntity = Qt3DCore.QEntity(parentEntity) # init params of the 6 planes planeTranslations = [[0, -side / 2, 0], [0, +side / 2, 0], [-side / 2, 0, 0], [+side / 2, 0, 0], [0, 0, -side / 2], [0, 0, +side / 2]] planeRotations = [[0, 0, 180], [0, 0, 0], [0, 0, 90], [0, 0, 270], [270, 0, 0], [90, 0, 0]] # allocate planes self.planeEntities = [None for i in range(6)] self.planeMeshes = [None for i in range(6)] self.planeTransforms = [None for i in range(6)] self.materials = [None for i in range(6)] # build the planes for i in range(0, 6): self.planeMeshes[i] = Qt3DExtras.QPlaneMesh() self.planeMeshes[i].setWidth(side) self.planeMeshes[i].setHeight(side) self.planeTransforms[i] = Qt3DCore.QTransform() self.planeTransforms[i].setRotationX(planeRotations[i][0]) self.planeTransforms[i].setRotationY(planeRotations[i][1]) self.planeTransforms[i].setRotationZ(planeRotations[i][2]) self.planeTransforms[i].setTranslation( QVector3D(planeTranslations[i][0], planeTranslations[i][1], planeTranslations[i][2])) self.materials[i] = Qt3DExtras.QPhongMaterial(self.cubeEntity) self.materials[i].setAmbient( QColor(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))) self.planeEntities[i] = Qt3DCore.QEntity(self.cubeEntity) self.planeEntities[i].addComponent(self.planeMeshes[i]) self.planeEntities[i].addComponent(self.planeTransforms[i]) self.planeEntities[i].addComponent(self.materials[i]) #initial rotation self.yaw = -15 self.pitch = 15 self.yawSpeed = 0 self.pitchSpeed = 0 self.cubeTransform = Qt3DCore.QTransform() self.cubeEntity.addComponent(self.cubeTransform) self.rotate( 0, 0 ) #trigger the computation of the rotation matrix for the initial rotation
def showAll(self): self.rootEntity = Qt3DCore.QEntity() self.materialSquare = Qt3DExtras.QPhongMaterial(self.rootEntity) self.materialSphere = Qt3DExtras.QPhongMaterial(self.rootEntity) # self.material = Qt3DExtras.QPhongMaterial(self.rootEntity) with open('local2.csv', 'r') as file: reader = csv.reader(file) for row in reader: if row[0] == 's': self.sphereEntity = Qt3DCore.QEntity(self.rootEntity) self.sphereMesh = Qt3DExtras.QSphereMesh() self.name = row[1] self.materialSphere.setAmbient( QColor(int(row[2]), int(row[3]), int(row[4]), int(row[5]))) self.sphereMesh.setRadius(int(row[6])) self.QTransformSphere = Qt3DCore.QTransform() self.sphereEntity.addComponent(self.sphereMesh) self.sphereEntity.addComponent(self.materialSphere) self.sphereEntity.addComponent(self.QTransformSphere) sphereVector3D = QVector3D() sphereVector3D.setX(int(row[7])) sphereVector3D.setY(int(row[8])) sphereVector3D.setZ(int(row[9])) self.QTransformSphere.setTranslation(sphereVector3D) else: self.squareEntity = Qt3DCore.QEntity(self.rootEntity) self.squareMesh = Qt3DExtras.QCuboidMesh() self.name = row[1] self.materialSquare.setAmbient( QColor(int(row[2]), int(row[3]), int(row[4]), int(row[5]))) self.squareMesh.setXExtent(int(row[6])) self.squareMesh.setYExtent(int(row[7])) self.squareMesh.setZExtent(int(row[8])) self.QTransformSquare = Qt3DCore.QTransform() self.squareEntity.addComponent(self.squareMesh) self.squareEntity.addComponent(self.materialSquare) self.squareEntity.addComponent(self.QTransformSquare) squareVector3D = QVector3D() squareVector3D.setX(int(row[9])) squareVector3D.setY(int(row[10])) squareVector3D.setZ(int(row[11])) self.QTransformSquare.setTranslation(squareVector3D) self.QTransformSquare.setRotationX(int(row[12])) self.QTransformSquare.setRotationY(int(row[13])) self.QTransformSquare.setRotationZ(int(row[14]))
def __init__(self): super().__init__() #store objects into array self.i = 0 self.listOfObjects = [] with open('local2.csv', 'r') as file: reader = csv.reader(file) for row in reader: self.listOfObjects.append(row) print(self.listOfObjects) # Camera self.camera().lens().setPerspectiveProjection(45, 16 / 9, 0.1, 1000) #setting focus on selected object if self.listOfObjects[0][0] == 's': self.camera().setPosition( QVector3D(int(row[7]), int(row[8]), 50 + int(row[9]))) self.camera().setViewCenter( QVector3D(int(row[7]), int(row[8]), int(row[9]))) else: self.camera().setPosition( QVector3D(int(row[9]), int(row[10]), 50 + int(row[11]))) self.camera().setViewCenter( QVector3D(int(row[9]), int(row[10]), int(row[11]))) # For camera controls self.rootEntity = Qt3DCore.QEntity() self.showAll() self.camController = Qt3DExtras.QOrbitCameraController(self.rootEntity) self.camController.setLinearSpeed(50) self.camController.setLookSpeed(180) self.camController.setCamera(self.camera()) self.setRootEntity(self.rootEntity)
def __init__(self): super(Window, self).__init__() # Scene creation # Kuesa content must be child of a Kuesa.SceneEntity. # These entites are all themselves standard Qt3D::QEntity self.rootEntity = Kuesa.SceneEntity() # GLTF2Importer will load the glTF 2.0 content and add # it as a child in the SceneEntity. self.gltfImporter = Kuesa.GLTF2Importer(self.rootEntity) self.gltfImporter.setSceneEntity(self.rootEntity) self.gltfImporter.setSource(assetsUrl() + "/models/Box.glb") # Since Kuesa is based on a PBR pipeline, we need an environment map. self.rootEntity.addComponent(DefaultEnvMap(self.rootEntity)) # Camera. self.camera().setPosition(QVector3D(10, 1.5, 10)) self.camera().setViewCenter(QVector3D(0, .5, 0)) self.camera().setUpVector(QVector3D(0, 1, 0)) self.camera().setAspectRatio(16. / 9.) # Camera controls. self.camController = Qt3DExtras.QOrbitCameraController(self.rootEntity) self.camController.setCamera(self.camera()) # Frame graph. self.fg = Kuesa.ForwardRenderer() self.fg.setCamera(self.camera()) self.fg.setClearColor("white") self.setActiveFrameGraph(self.fg) self.setRootEntity(self.rootEntity)
def setup_neutrons(self): """ Sets up the neutrons and their animations by preparing their meshes and then giving offset and distance parameters to an animation controller. """ # Create lists of x, y, and time offsets for the neutron animations x_offsets = [0, 0, 0, 2, -2, 1.4, 1.4, -1.4, -1.4] y_offsets = [0, 2, -2, 0, 0, 1.4, -1.4, 1.4, -1.4] time_span_offsets = [0, -5, -7, 5, 7, 19, -19, 23, -23] neutron_radius = 1.5 for i in range(self.num_neutrons): mesh = Qt3DExtras.QSphereMesh(self.gnomon_root_entity) self.set_sphere_mesh_radius(mesh, neutron_radius) transform = Qt3DCore.QTransform(self.gnomon_root_entity) neutron_animation_controller = NeutronAnimationController( x_offsets[i] * 0.5, y_offsets[i] * 0.5, transform) neutron_animation_controller.set_target(transform) neutron_animation = QPropertyAnimation(transform) self.set_neutron_animation_properties( neutron_animation, neutron_animation_controller, self.neutron_animation_length, time_span_offsets[i], ) neutron_material = create_material(QColor("black"), QColor("grey"), self.gnomon_root_entity) create_qentity([mesh, neutron_material, transform], self.gnomon_root_entity)
def __init__(self): super(Window, self).__init__() # Since we are going to use animations, we need to register # the Qt3D animation aspect : self.animationAspect = Qt3DAnimation.QAnimationAspect(self) self.registerAspect(self.animationAspect) # Default set-up self.rootEntity = Kuesa.SceneEntity() self.rootEntity.addComponent(DefaultEnvMap(self.rootEntity)) self.camera().setPosition(QVector3D(25, 1.5, 25)) self.camera().setViewCenter(QVector3D(0, 3, 0)) self.camera().setUpVector(QVector3D(0, 1, 0)) self.camera().setAspectRatio(16. / 9.) self.camController = Qt3DExtras.QOrbitCameraController(self.rootEntity) self.camController.setCamera(self.camera()) self.fg = Kuesa.ForwardRenderer() self.fg.setCamera(self.camera()) self.fg.setClearColor("white") self.setActiveFrameGraph(self.fg) # Load a glTF model self.gltfImporter = Kuesa.GLTF2Importer(self.rootEntity) self.gltfImporter.setSceneEntity(self.rootEntity) self.gltfImporter.setSource(assetsUrl() + "/models/InterpolationTest.glb") self.gltfImporter.statusChanged.connect(self.on_sceneLoaded) self.setRootEntity(self.rootEntity)
def __init__(self): super(Window, self).__init__() self.animationAspect = Qt3DAnimation.QAnimationAspect(self) self.registerAspect(self.animationAspect) # Camera self.camera().setPosition(QVector3D(5.5, 1.5, 5.5)) self.camera().setViewCenter(QVector3D(0, .5, 0)) self.camera().setUpVector(QVector3D(0, 1, 0)) self.camera().setAspectRatio(4. / 3.) # For camera controls self.createScene() self.camController = Qt3DExtras.QOrbitCameraController(self.rootEntity) self.camController.setLinearSpeed(50) self.camController.setLookSpeed(180) self.camController.setCamera(self.camera()) self.fg = Kuesa.ForwardRenderer() self.fg.setCamera(self.camera()) self.fg.setClearColor("white") self.setActiveFrameGraph(self.fg) self.setRootEntity(self.rootEntity)
def __init__(self): super(Window, self).__init__() # Default set-up self.rootEntity = Kuesa.SceneEntity() self.rootEntity.addComponent(DefaultEnvMap(self.rootEntity)) self.camera().setPosition(QVector3D(5, 1.5, 5)) self.camera().setViewCenter(QVector3D(0, 0.5, 0)) self.camera().setUpVector(QVector3D(0, 1, 0)) self.camera().setAspectRatio(16. / 9.) self.camController = Qt3DExtras.QOrbitCameraController(self.rootEntity) self.camController.setCamera(self.camera()) self.fg = Kuesa.ForwardRenderer() self.fg.setCamera(self.camera()) self.fg.setClearColor("white") self.setActiveFrameGraph(self.fg) # Load a glTF model self.gltfImporter = Kuesa.GLTF2Importer(self.rootEntity) self.gltfImporter.setSceneEntity(self.rootEntity) self.gltfImporter.setSource(assetsUrl() + "/models/duck/Duck.glb") self.gltfImporter.statusChanged.connect(self.importerLoaded) # Skybox creation envmap_root = assetsUrl() + "/envmaps/pink_sunrise" envmap_name = "pink_sunrise" + ("_16f" if platform.system() == "Darwin" else "") + "_radiance" self.skybox = Kuesa.Skybox(self.rootEntity) self.skybox.setBaseName(envmap_root + "/" + envmap_name) self.skybox.setExtension(".dds") self.setRootEntity(self.rootEntity)
def __init__(self, mesh: OffMesh, root_entity: Qt3DCore.QEntity, nx_class: str): super().__init__(root_entity, nx_class) self.entities: List[Qt3DCore.QEntity] = [] self._mesh = mesh if nx_class not in MATERIAL_COLORS: self.default_material = Qt3DExtras.QPerVertexColorMaterial()
def createScene(self): # Root entity self.rootEntity = Qt3DCore.QEntity() # Material self.material = Qt3DExtras.QPhongMaterial(self.rootEntity) # Torus self.torusEntity = Qt3DCore.QEntity(self.rootEntity) self.torusMesh = Qt3DExtras.QTorusMesh() self.torusMesh.setRadius(5) self.torusMesh.setMinorRadius(1) self.torusMesh.setRings(100) self.torusMesh.setSlices(20) self.torusTransform = Qt3DCore.QTransform() self.torusTransform.setScale3D(QVector3D(1.5, 1, 0.5)) self.torusTransform.setRotation( QQuaternion.fromAxisAndAngle(QVector3D(1, 0, 0), 45)) self.torusEntity.addComponent(self.torusMesh) self.torusEntity.addComponent(self.torusTransform) self.torusEntity.addComponent(self.material) # Sphere self.sphereEntity = Qt3DCore.QEntity(self.rootEntity) self.sphereMesh = Qt3DExtras.QSphereMesh() self.sphereMesh.setRadius(3) self.sphereTransform = Qt3DCore.QTransform() self.controller = OrbitTransformController(self.sphereTransform) self.controller.setTarget(self.sphereTransform) self.controller.setRadius(20) self.sphereRotateTransformAnimation = QPropertyAnimation( self.sphereTransform) self.sphereRotateTransformAnimation.setTargetObject(self.controller) self.sphereRotateTransformAnimation.setPropertyName("angle") self.sphereRotateTransformAnimation.setStartValue(0) self.sphereRotateTransformAnimation.setEndValue(360) self.sphereRotateTransformAnimation.setDuration(10000) self.sphereRotateTransformAnimation.setLoopCount(-1) self.sphereRotateTransformAnimation.start() self.sphereEntity.addComponent(self.sphereMesh) self.sphereEntity.addComponent(self.sphereTransform) self.sphereEntity.addComponent(self.material)
def __init__(self, view: Qt3DExtras.Qt3DWindow) -> None: """ Initialize a new instance. Args: view: where to render the planetary sphere. """ self.root_entity = Qt3DCore.QEntity() ce = self.camera_entity = view.camera() ce.lens().setPerspectiveProjection(45.0, 1.0, 0.1, 1000.0) ce.setPosition(V3(0, 8, 8)) ce.setUpVector(V3(0, 1, 0)) ce.setViewCenter(V3(0, 0, 0)) self.light = Qt3DCore.QEntity(self.root_entity) self.point_light = Qt3DRender.QPointLight(self.light) self.point_light.setColor("white") self.point_light.setIntensity(1.0) self.light.addComponent(self.point_light) # Move the light to the camera's position - on-camera 'flash'! t = self.light_transform = Qt3DCore.QTransform(self.light) t.setTranslation(ce.position()) self.light.addComponent(t) self.mesh = Qt3DExtras.QSphereMesh() self.mesh.setRings(30) self.mesh.setSlices(30) self.mesh.setRadius(2) t = self.transform = Qt3DCore.QTransform() t.setScale(1.3) t.setTranslation(V3(0.0, 0.0, 0.0)) m = self.material = Qt3DExtras.QDiffuseSpecularMaterial() m.setAmbient(QColor(200, 200, 255)) m.setShininess(20.0) self.entity = Qt3DCore.QEntity(self.root_entity) self.entity.addComponent(self.mesh) self.entity.addComponent(self.material) self.entity.addComponent(self.transform) view.setRootEntity(self.root_entity) self.entity.setEnabled(True)
def __init__(self) -> None: super().__init__() self.setMinimumSize(640, 480) self._build_menus() self.view = Qt3DExtras.Qt3DWindow() self.view.defaultFrameGraph().setClearColor(QColor(0, 0, 0)) self.widget = QWidget.createWindowContainer(self.view) self.sphere_vc = SphereVC(self.view) self.setCentralWidget(self.widget) self._textures = AlbedoTextureMapper()
def add_acq_sphere(self, df, label): pos = df.loc[label, ["x", "y", "z"]].values*1000 # m to mm if label not in self.acq_coordinate_entities: self.acq_coordinate_meshes[label] = Qt3DExtras.QSphereMesh(rings=20, slices=20, radius=3) self.acq_coordinate_entities[label] = Qt3DCore.QEntity(self.root_entity) self.acq_coordinate_transforms[label] = Qt3DCore.QTransform(self.acq_coordinate_meshes[label]) self.acq_coordinate_entities[label].addComponent(self.acq_coordinate_meshes[label]) self.acq_coordinate_entities[label].addComponent(self.acq_coordinate_transforms[label]) self.acq_coordinate_entities[label].addComponent(self.acq_material) self.acq_coordinate_transforms[label].setTranslation(QtGui.QVector3D(*pos))
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. """ cube_mesh = Qt3DExtras.QCuboidMesh(self.component_root_entity) self.set_cube_mesh_dimensions(cube_mesh, *[0.1, 0.1, 0.1]) dark_red = QColor("#b00") sample_material = create_material( QColor("red"), dark_red, self.component_root_entity, alpha=0.5 ) self.component_entities["sample"] = create_qentity( [cube_mesh, sample_material], self.component_root_entity )
def __init__(self): super(Window, self).__init__() # Default set-up self.rootEntity = Kuesa.SceneEntity() self.rootEntity.addComponent(DefaultEnvMap(self.rootEntity)) self.camera().setPosition(QVector3D(5, 1.5, 5)) self.camera().setViewCenter(QVector3D(0, 0.5, 0)) self.camera().setUpVector(QVector3D(0, 1, 0)) self.camera().setAspectRatio(16. / 9.) self.camController = Qt3DExtras.QOrbitCameraController(self.rootEntity) self.camController.setCamera(self.camera()) self.fg = Kuesa.ForwardRenderer() self.fg.setCamera(self.camera()) self.fg.setClearColor("white") self.setActiveFrameGraph(self.fg) # Load a glTF model self.gltfImporter = Kuesa.GLTF2Importer(self.rootEntity) self.gltfImporter.setSceneEntity(self.rootEntity) self.gltfImporter.setSource(assetsUrl() + "/models/duck/Duck.glb") self.gltfImporter.statusChanged.connect(self.importerLoaded) # Skybox creation envmap_root = assetsUrl() + "/envmaps/pink_sunrise" envmap_name = "pink_sunrise" + ("_16f" if platform.system() == "Darwin" else "") + "_radiance" self.skybox = Kuesa.Skybox(self.rootEntity) self.skybox.setBaseName(envmap_root + "/" + envmap_name) self.skybox.setExtension(".dds") # Creation of a few post-processing effects self.blurFx = Kuesa.GaussianBlurEffect() self.blurFx.setBlurPassCount(8) self.dofFx = Kuesa.DepthOfFieldEffect() self.dofFx.setFocusRange(3.1) self.dofFx.setRadius(21.) self.dofFx.setFocusDistance(6.6) self.threshFx = Kuesa.ThresholdEffect() self.threshFx.setThreshold(.1) # self.fg.addPostProcessingEffect(self.blurFx) # self.fg.addPostProcessingEffect(self.dofFx) self.fg.addPostProcessingEffect(self.threshFx) self.setRootEntity(self.rootEntity)
def _create_source(self): cylinder_mesh = Qt3DExtras.QCylinderMesh(self.root_entity) cone_transform = Qt3DCore.QTransform(self.root_entity) self._set_cylinder_dimension(cylinder_mesh, self._source_radius, self._source_length) cone_transform.setMatrix(self._get_cylinder_transformation_matrix()) self.entities.append(( create_qentity( [cylinder_mesh, self.default_material, cone_transform], self.root_entity, ), self._get_cylinder_transformation_matrix(), ))
def createScene(self): # Root entity self.rootEntity = Qt3DCore.QEntity() # Material self.material = Qt3DExtras.QPhongMaterial(self.rootEntity) # Torus self.torusEntity = Qt3DCore.QEntity(self.rootEntity) self.torusMesh = Qt3DExtras.QTorusMesh() self.torusMesh.setRadius(5) self.torusMesh.setMinorRadius(1) self.torusMesh.setRings(100) self.torusMesh.setSlices(20) self.torusTransform = Qt3DCore.QTransform() self.torusTransform.setScale3D(QVector3D(1.5, 1, 0.5)) self.torusTransform.setRotation( QQuaternion.fromAxisAndAngle(QVector3D(1, 0, 0), 45)) self.torusEntity.addComponent(self.torusMesh) self.torusEntity.addComponent(self.torusTransform) self.torusEntity.addComponent(self.material) # Sphere self.sphereEntity = Qt3DCore.QEntity(self.rootEntity) self.sphereMesh = Qt3DExtras.QSphereMesh() self.sphereMesh.setRadius(3) self.sphereTransform = Qt3DCore.QTransform() self.controller = OrbitTransformController(self.sphereTransform) self.controller.setTarget(self.sphereTransform) self.controller.setRadius(20) self.sphereEntity.addComponent(self.sphereMesh) self.sphereEntity.addComponent(self.sphereTransform) self.sphereEntity.addComponent(self.material)
def __init__(self): super(Window, self).__init__() # Camera self.camera().lens().setPerspectiveProjection(45, 16 / 9, 0.1, 1000) self.camera().setPosition(QVector3D(0, 0, 40)) self.camera().setViewCenter(QVector3D(0, 0, 0)) # For camera controls self.createScene() self.camController = Qt3DExtras.QOrbitCameraController(self.rootEntity) self.camController.setLinearSpeed(50) self.camController.setLookSpeed(180) self.camController.setCamera(self.camera()) self.setRootEntity(self.rootEntity)
def __init__(self): super(Window, self).__init__() # Default set-up self.rootEntity = Kuesa.SceneEntity() self.rootEntity.addComponent(DefaultEnvMap(self.rootEntity)) self.camera().setPosition(QVector3D(5, 1.5, 5)) self.camera().setViewCenter(QVector3D(0, 0.5, 0)) self.camera().setUpVector(QVector3D(0, 1, 0)) self.camera().setAspectRatio(16. / 9.) self.camController = Qt3DExtras.QOrbitCameraController(self.rootEntity) self.camController.setCamera(self.camera()) self.fg = Kuesa.ForwardRenderer() self.fg.setCamera(self.camera()) self.fg.setClearColor("white") self.setActiveFrameGraph(self.fg) # Load a glTF model self.gltfImporter = Kuesa.GLTF2Importer(self.rootEntity) self.gltfImporter.setSceneEntity(self.rootEntity) self.gltfImporter.setSource(assetsUrl() + "/models/duck/Duck.glb") # Skybox creation envmap_root = assetsUrl() + "/envmaps/pink_sunrise" envmap_name = "pink_sunrise" + ("_16f" if platform.system() == "Darwin" else "") + "_radiance" self.skybox = Kuesa.Skybox(self.rootEntity) self.skybox.setBaseName(envmap_root + "/" + envmap_name) self.skybox.setExtension(".dds") # Tonemapping and gamma correction self.toneMapAlgorithm = Kuesa.ToneMappingAndGammaCorrectionEffect.ToneMapping( ) self.fg.setExposure(2) self.fg.setGamma(2.8) self.fg.setToneMappingAlgorithm(self.toneMapAlgorithm) # Cycle through the various tonemapping algorithms provided by Kuesa timer = QTimer(self) timer.setInterval(1000) timer.timeout.connect(self.changeTonemapping) timer.start() self.setRootEntity(self.rootEntity)
def setup_beam_cylinder(self): """ Sets up the beam cylinder by giving the cylinder entity a mesh, a material, and a transformation. """ # Initialise beam objects cylinder_mesh = Qt3DExtras.QCylinderMesh(self.gnomon_root_entity) cylinder_transform = Qt3DCore.QTransform(self.gnomon_root_entity) self.set_cylinder_mesh_dimensions(cylinder_mesh, 1.5, self.neutron_animation_length, 2) self.set_beam_transform(cylinder_transform, self.neutron_animation_length) beam_material = create_material(QColor("blue"), QColor("lightblue"), self.gnomon_root_entity, alpha=0.5) create_qentity([cylinder_mesh, beam_material, cylinder_transform], self.gnomon_root_entity)
def _setup_neutrons(self): neutron_radius = 0.1 for i in range(self._num_neutrons): mesh = Qt3DExtras.QSphereMesh(self.root_entity) mesh.setRadius(neutron_radius) transform = Qt3DCore.QTransform(self.root_entity) transform.setMatrix( self._get_sphere_transformation_matrix( self._neutron_offsets[i])) neutron_material = create_material(QColor("black"), QColor("grey"), self.root_entity) entity = create_qentity([mesh, neutron_material, transform], self.root_entity) self.entities.append(( entity, self._get_sphere_transformation_matrix( self._neutron_offsets[i]), ))
def __init__(self, rootEntity): super(SceneView, self).__init__() self.rootEntity = rootEntity self.defaultFrameGraph().setClearColor(QColor('#333')) # Camera self.camera().lens().setPerspectiveProjection(45, 16 / 9, 0.1, 1000) self.camera().setPosition(QVector3D(0, 0, 40)) self.camera().setViewCenter(QVector3D(0, 0, 0)) # For camera controls # self.createScene() self.camController = Qt3DExtras.QOrbitCameraController(self.rootEntity) self.camController.setLinearSpeed(60) self.camController.setLookSpeed(180) self.camController.setCamera(self.camera()) self.setRootEntity(self.rootEntity)
def add_sphere(self, radius, x, y, z, rings=10, slices=10): sphereEntity = Qt3DCore.QEntity(self.rootEntity) # Mesh sphereMesh = Qt3DExtras.QSphereMesh() sphereMesh.setRadius(radius) sphereMesh.setRings(rings) sphereMesh.setSlices(slices) # Transforms sphereTransform = Qt3DCore.QTransform() sphereTransform.setTranslation(QVector3D(x, y, z)) sphereEntity.addComponent(sphereMesh) sphereEntity.addComponent(self.material) sphereEntity.addComponent(sphereTransform) self.spheres.append(sphereEntity) self.meshes.append(sphereMesh) self.transforms.append(sphereTransform)
def create_gnomon_cones(self): """ Prepares the gnomon cones by configuring the meshes and then placing them at the ends of the cylinders. """ x_cone_matrix, y_cone_matrix, z_cone_matrix = self.create_cone_matrices( self.gnomon_cylinder_length) for matrix, material in [ (x_cone_matrix, self.x_material), (y_cone_matrix, self.y_material), (z_cone_matrix, self.z_material), ]: cone_mesh = Qt3DExtras.QConeMesh(self.gnomon_root_entity) self.configure_gnomon_cone(cone_mesh, self.gnomon_cylinder_length) cone_transformation = Qt3DCore.QTransform(self.gnomon_root_entity) cone_transformation.setMatrix(matrix) create_qentity([cone_mesh, cone_transformation, material], self.gnomon_root_entity)
def create_gnomon_cylinders(self): """ Configures three cylinder meshes and translates them in order to create a basic gnomon shape. """ x_axis_matrix, y_axis_matrix, z_axis_matrix = self.create_cylinder_matrices( self.gnomon_cylinder_length) for matrix, material in [ (x_axis_matrix, self.x_material), (y_axis_matrix, self.y_material), (z_axis_matrix, self.z_material), ]: axis_mesh = Qt3DExtras.QCylinderMesh(self.gnomon_root_entity) self.configure_gnomon_cylinder(axis_mesh, self.gnomon_cylinder_length) axis_transformation = Qt3DCore.QTransform(self.gnomon_root_entity) axis_transformation.setMatrix(matrix) create_qentity([axis_mesh, axis_transformation, material], self.gnomon_root_entity)
def __init__(self): super(Window, self).__init__() # Default set-up self.rootEntity = Kuesa.SceneEntity() self.rootEntity.addComponent(DefaultEnvMap(self.rootEntity)) self.camera().setPosition(QVector3D(25, 1.5, 25)) self.camera().setViewCenter(QVector3D(0, 3, 0)) self.camera().setUpVector(QVector3D(0, 1, 0)) self.camera().setAspectRatio(16. / 9.) self.camController = Qt3DExtras.QOrbitCameraController(self.rootEntity) self.camController.setCamera(self.camera()) self.fg = Kuesa.ForwardRenderer() self.fg.setCamera(self.camera()) self.fg.setClearColor("white") self.setActiveFrameGraph(self.fg) # Load a glTF model self.gltfImporter = Kuesa.GLTF2Importer(self.rootEntity) self.gltfImporter.setSceneEntity(self.rootEntity) self.gltfImporter.setSource(assetsUrl() + "/models/InterpolationTest.glb") # When opening this model in gltfEditor, we can see : # - Multiple entities : # Cube, Cube.001, Cube.002, Light, Plane... # - Multiple meshes : # Cube.001_0, Cube.002_0, ... # - Multiple materials : # Material, Material.001, ... # etc. # Let's use Kuesa to change one of these entities on-the-fly. # We need to wait for the glTF file to be fully loaded in order to do that : self.gltfImporter.statusChanged.connect(self.on_sceneLoaded) self.setRootEntity(self.rootEntity)
def __init__(self, args, parent=None): super().__init__(parent) ############################################################################## # UI初期化処理 self.ui = MainWindowUi.loader(os.path.join(os.getcwd(), 'ui/main.ui')) self.setWindowTitle('self.viewer test') self.setCentralWidget(self.ui.widgets) self.view = Qt3DExtras.Qt3DWindow() self.view.defaultFrameGraph().setClearColor(QtGui.QColor(0, 0, 0)) self.container = QWidget.createWindowContainer(self.view) screen_size = self.view.screen().size() self.ui.viewer.addWidget(self.container) self.container.setMinimumSize(QtCore.QSize(400, 600)) self.container.setMaximumSize(screen_size) # QSize screenSize = self.view -> screen() -> size(); # container -> setMinimumSize(QSize(200, 100)); # container -> setMaximumSize(screenSize); # vLayout -> setAlignment(Qt: : AlignTop); # hLayout -> addWidget(container, 1); # hLayout -> addLayout(vLayout); # input_aspect = Qt3DInput.QInputAspect() # self.view.registerAspect(input_aspect) # root entity self.root_entity: Qt3DCore.QEntity = Qt3DCore.QEntity() # draw grid and axis """ self.x_axis: Qt3DRender.QGeometry = Qt3DRender.QGeometry(self.root_entity) x_axis_pos: QtCore.QByteArray = QtCore.QByteArray() x_axis_pos.append(0) x_axis_pos.append(0) x_axis_pos.append(0) x_axis_pos.append(10) x_axis_pos.append(0) x_axis_pos.append(0) x_axis_buf: Qt3DRender.QBuffer = Qt3DRender.QBuffer(self.x_axis) x_axis_buf.setData(x_axis_pos) x_axis_attr: Qt3DRender.QAttribute = Qt3DRender.QAttribute(self.x_axis) x_axis_attr.setVertexBaseType(Qt3DRender.QAttribute.Float) x_axis_attr.setVertexSize(3) x_axis_attr.setAttributeType(Qt3DRender.QAttribute.VertexAttribute) x_axis_attr.setBuffer(x_axis_buf) x_axis_attr.setByteStride(3) x_axis_attr.setCount(2) self.x_axis.addAttribute(x_axis_attr) """ test_mtl = Qt3DExtras.QTextureMaterial(self.root_entity) self.test = Qt3DCore.QEntity(self.root_entity) self.test_mesh: Qt3DExtras.QTorusMesh = Qt3DExtras.QTorusMesh() self.test_mesh.setRadius(5) self.test_mesh.setMinorRadius(1) self.test_mesh.setRings(100) self.test_mesh.setSlices(20) self.test_tr = Qt3DCore.QTransform() self.test_tr.setTranslation(QtGui.QVector3D(0, 0, 0)) # test_tr.setScale3D() self.test.addComponent(self.test_mesh) self.test.addComponent(self.test_tr) self.test.addComponent(self.test_mtl) # camera entity camera_entity: Qt3DRender.QCamera = self.view.camera() camera_entity.lens().setPerspectiveProjection(45.0, 16.0 / 9.0, 0.1, 1000.0) camera_entity.setPosition(QtGui.QVector3D(0, 0, 20.0)) camera_entity.setUpVector(QtGui.QVector3D(0, 1, 0)) camera_entity.setViewCenter(QtGui.QVector3D(0, 0, 0)) light_entity = Qt3DCore.QEntity(self.root_entity) light = Qt3DRender.QPointLight(light_entity) light.setColor("white") light.setIntensity(1) light_entity.addComponent(light) light_transform = Qt3DCore.QTransform(light_entity) light_transform.setTranslation(camera_entity.position()) light_entity.addComponent(light_transform) # for camera controls cam_controller = Qt3DExtras.QFirstPersonCameraController(self.root_entity) cam_controller.setCamera(camera_entity) # set root object of the scene self.view.setRootEntity(self.root_entity)
def __init__(self, parent): super().__init__() self.root_entity = Qt3DCore.QEntity() # Make additional entities for the gnomon and instrument components self.combined_component_axes_entity = Qt3DCore.QEntity( self.root_entity) self.component_root_entity = Qt3DCore.QEntity( self.combined_component_axes_entity) self.axes_root_entity = Qt3DCore.QEntity( self.combined_component_axes_entity) self.gnomon_root_entity = Qt3DCore.QEntity(self.root_entity) # Create the 3DWindow and place it in a widget with a layout lay = QVBoxLayout(self) self.view = InstrumentZooming3DWindow(self.component_root_entity) self.view.defaultFrameGraph().setClearColor(QColor("lightgrey")) self.view.setRootEntity(self.root_entity) container = QWidget.createWindowContainer(self.view) lay.addWidget(container) # Set the properties of the instrument camera controller camera_entity = self.view.camera() cam_controller = Qt3DExtras.QFirstPersonCameraController( self.root_entity) cam_controller.setLinearSpeed(20) cam_controller.setCamera(camera_entity) # Enable the camera to see a large distance by giving it a small nearView and large farView self.view.camera().lens().setPerspectiveProjection( 45, 16 / 9, 0.01, 1000) # Set the camera view centre as the origin and position the camera so that it looks down at the initial sample self.view.camera().setPosition(QVector3D(6, 8, 30)) self.view.camera().setViewCenter(QVector3D(0, 0, 0)) # Make sure that the size of the gnomon stays the same when the 3D view is resized self.view.heightChanged.connect(self.update_gnomon_size) self.view.widthChanged.connect(self.update_gnomon_size) # Keep a reference to the gnomon viewport so that it can be resized to preserve the original size of the gnomon self.gnomon_viewport = None # Choose a fixed height and width for the gnomon so that this can be preserved when the 3D view is resized self.gnomon_height = self.gnomon_width = 140 # Create the gnomon resources self.gnomon = Gnomon(self.gnomon_root_entity, self.view.camera()) # Create the axes lines objects InstrumentViewAxes(self.axes_root_entity, self.view.camera().farPlane()) # Dictionary of components and transformations so that we can delete them later self.component_entities: Dict[str, EntityCollection] = {} self.transformations = {} # Create layers in order to allow one camera to only see the gnomon and one camera to only see the # components and axis lines self.create_layers() self.initialise_view() # Insert the beam cylinder last. This ensures that the semi-transparency works correctly. self.gnomon.setup_beam_cylinder() # Move the gnomon when the camera view changes self.view.camera().viewVectorChanged.connect(self.gnomon.update_gnomon)