def createScene(): # Root entity. rootEntity = QEntity() # Material. material = QPhongMaterial(rootEntity) # Torus. torusEntity = QEntity(rootEntity) torusMesh = QTorusMesh() torusMesh.setRadius(5) torusMesh.setMinorRadius(1) torusMesh.setRings(100) torusMesh.setSlices(20) torusTransform = QTransform() torusTransform.setScale3D(QVector3D(1.5, 1.0, 0.5)) torusTransform.setRotation( QQuaternion.fromAxisAndAngle(QVector3D(1.0, 0.0, 0.0), 45.0)) torusEntity.addComponent(torusMesh) torusEntity.addComponent(torusTransform) torusEntity.addComponent(material) # Sphere. sphereEntity = QEntity(rootEntity) sphereMesh = QSphereMesh() sphereMesh.setRadius(3) sphereEntity.addComponent(sphereMesh) sphereEntity.addComponent(material) return rootEntity
def createScene(): # Root entity rootEntity = QEntity() # Material material = QPhongMaterial(rootEntity) # Torus torusEntity = QEntity(rootEntity) # Qt3DExtras.QTorusMesh * torusMesh = QTorusMesh() torusMesh.setRadius(5) torusMesh.setMinorRadius(1) torusMesh.setRings(100) torusMesh.setSlices(20) # Qt3DCore.QTransform * torusTransform = QTransform() torusTransform.setScale3D(QVector3D(1.5, 1, 0.5)) torusTransform.setRotation( QQuaternion.fromAxisAndAngle(QVector3D(1, 0, 0), 45.0)) torusEntity.addComponent(torusMesh) torusEntity.addComponent(torusTransform) torusEntity.addComponent(material) # Sphere sphereEntity = QEntity(rootEntity) sphereMesh = QSphereMesh() sphereMesh.setRadius(3) # Qt3DCore.QTransform * sphereTransform = QTransform() # OrbitTransformController * controller = OrbitTransformController(sphereTransform) controller.setTarget(sphereTransform) controller.setRadius(20.0) # QPropertyAnimation * sphereRotateTransformAnimation = QPropertyAnimation(sphereTransform) sphereRotateTransformAnimation.setTargetObject(controller) sphereRotateTransformAnimation.setPropertyName(b"angle") sphereRotateTransformAnimation.setStartValue(0) sphereRotateTransformAnimation.setEndValue(360) sphereRotateTransformAnimation.setDuration(10000) sphereRotateTransformAnimation.setLoopCount(-1) sphereRotateTransformAnimation.start() sphereEntity.addComponent(sphereMesh) sphereEntity.addComponent(sphereTransform) sphereEntity.addComponent(material) return rootEntity
def create_plane(root_entity, vector_1: np.ndarray, vector_2: np.ndarray): material = QDiffuseSpecularMaterial(root_entity) material.setDiffuse(QColor(200, 200, 200)) material.setAmbient(QColor(200, 200, 200)) plane_entity = QEntity(root_entity) plane_mesh = QPlaneMesh() plane_transform = QTransform() plane_mesh.setWidth(np.linalg.norm(vector_1)) plane_mesh.setHeight(np.linalg.norm(vector_2)) plane_mesh.setMirrored(False) translation_vector = (vector_1 + vector_2) / 2 plane_transform.setRotation(_get_quaternion(np.cross(vector_1, vector_2))) plane_transform.setTranslation(QVector3D(*translation_vector)) plane_entity.addComponent(plane_mesh) plane_entity.addComponent(plane_transform) plane_entity.addComponent(material)
def createScene(self): # root rootEntity = QSkyboxEntity() material = QPhongMaterial(rootEntity) #skybox = QSkyboxEntity(rootEntity) # torus cubeEntity = QEntity(rootEntity) cubeMesh = QCuboidMesh() cubeTransform = QTransform() #cubeMaterial = getRgbCubeMaterial(cubeEntity) cubeMaterial = QPhongMaterial(cubeEntity) cubeTransform.setTranslation(QVector3D(5.0, -4.0, 0.0)) cubeTransform.setScale(4.0) cubeTransform.setRotation(QQuaternion.fromAxisAndAngle(QVector3D(1, 0, 0), 45)) cubeEntity.addComponent(cubeMesh) cubeEntity.addComponent(cubeTransform) cubeEntity.addComponent(cubeMaterial) return rootEntity
def add_path(self, *pts, color=util.hsl(0, 0, 50)): """ Helper method to add a path to the scene. Arguments: pts: list of QVector3D's, the points in the path Returns: a list of the entities added to the scene """ path_material = QPhongMaterial(self.scene) path_material.setDiffuse(color) # make a bunch of cylinder objects aligned along the path entities = [] prev_pt = None for pt in pts: if prev_pt is not None: if prev_pt != pt: # for each adjacent pair of points that are different # make a cylinder path_entity = QEntity(self.scene) path_mesh = QCylinderMesh() path_mesh.setRadius(0.05) # very thin path_mesh.setLength((prev_pt - pt).length()) # length is the distance between the points path_entity.addComponent(path_mesh) path_transform = QTransform(self.scene) path_transform.setRotation(QQuaternion.fromDirection(QVector3D(0, 0, -1), prev_pt - pt)) # rotate to point along path path_transform.setTranslation((pt + prev_pt) / 2) # center between points path_entity.addComponent(path_transform) path_entity.addComponent(path_material) entities.append(path_entity) prev_pt = pt return entities
def create_cylinder(root_entity, center, direction): material = QDiffuseSpecularMaterial(root_entity) material.setDiffuse(QColor(200, 200, 200, 50)) material.setAmbient(QColor(200, 200, 200, 50)) cylinder_entity = QEntity(root_entity) cylinder_mesh = QCylinderMesh() length = np.linalg.norm(direction) translate_vector = center + direction / 2 cylinder_mesh.setLength(length) cylinder_mesh.setRadius(0.02) cylinder_transform = QTransform() cylinder_transform.setRotation(_get_quaternion(direction)) cylinder_transform.setTranslation(QVector3D(*translate_vector)) cylinder_entity.addComponent(cylinder_mesh) cylinder_entity.addComponent(cylinder_transform) cylinder_entity.addComponent(material)
def __init__(self, rootEntity): super(SceneModifier, self).__init__() self.m_rootEntity = rootEntity # Torus shape data. self.m_torus = QTorusMesh() self.m_torus.setRadius(1.0) self.m_torus.setMinorRadius(0.4) self.m_torus.setRings(100) self.m_torus.setSlices(20) # TorusMesh transform. torusTransform = QTransform() torusTransform.setScale(2.0) torusTransform.setRotation( QQuaternion.fromAxisAndAngle(QVector3D(0.0, 1.0, 0.0), 25.0)) torusTransform.setTranslation(QVector3D(5.0, 4.0, 0.0)) torusMaterial = QPhongMaterial() torusMaterial.setDiffuse(QColor(0xbeb32b)) # Torus. self.m_torusEntity = QEntity(self.m_rootEntity) self.m_torusEntity.addComponent(self.m_torus) self.m_torusEntity.addComponent(torusMaterial) self.m_torusEntity.addComponent(torusTransform) # Cone shape data. cone = QConeMesh() cone.setTopRadius(0.5) cone.setBottomRadius(1) cone.setLength(3) cone.setRings(50) cone.setSlices(20) # ConeMesh transform. coneTransform = QTransform() coneTransform.setScale(1.5) coneTransform.setRotation( QQuaternion.fromAxisAndAngle(QVector3D(1.0, 0.0, 0.0), 45.0)) coneTransform.setTranslation(QVector3D(0.0, 4.0, -1.5)) coneMaterial = QPhongMaterial() coneMaterial.setDiffuse(QColor(0x928327)) # Cone. self.m_coneEntity = QEntity(self.m_rootEntity) self.m_coneEntity.addComponent(cone) self.m_coneEntity.addComponent(coneMaterial) self.m_coneEntity.addComponent(coneTransform) # Cylinder shape data. cylinder = QCylinderMesh() cylinder.setRadius(1) cylinder.setLength(3) cylinder.setRings(100) cylinder.setSlices(20) # CylinderMesh transform. cylinderTransform = QTransform() cylinderTransform.setScale(1.5) cylinderTransform.setRotation( QQuaternion.fromAxisAndAngle(QVector3D(1.0, 0.0, 0.0), 45.0)) cylinderTransform.setTranslation(QVector3D(-5.0, 4.0, -1.5)) cylinderMaterial = QPhongMaterial() cylinderMaterial.setDiffuse(QColor(0x928327)) # Cylinder. self.m_cylinderEntity = QEntity(self.m_rootEntity) self.m_cylinderEntity.addComponent(cylinder) self.m_cylinderEntity.addComponent(cylinderMaterial) self.m_cylinderEntity.addComponent(cylinderTransform) # Cuboid shape data. cuboid = QCuboidMesh() # CuboidMesh transform. cuboidTransform = QTransform() cuboidTransform.setScale(4.0) cuboidTransform.setTranslation(QVector3D(5.0, -4.0, 0.0)) cuboidMaterial = QPhongMaterial() cuboidMaterial.setDiffuse(QColor(0x665423)) # Cuboid. self.m_cuboidEntity = QEntity(self.m_rootEntity) self.m_cuboidEntity.addComponent(cuboid) self.m_cuboidEntity.addComponent(cuboidMaterial) self.m_cuboidEntity.addComponent(cuboidTransform) # Plane shape data. planeMesh = QPlaneMesh() planeMesh.setWidth(2) planeMesh.setHeight(2) # Plane mesh transform. planeTransform = QTransform() planeTransform.setScale(1.3) planeTransform.setRotation( QQuaternion.fromAxisAndAngle(QVector3D(1.0, 0.0, 0.0), 45.0)) planeTransform.setTranslation(QVector3D(0.0, -4.0, 0.0)) planeMaterial = QPhongMaterial() planeMaterial.setDiffuse(QColor(0xa69929)) # Plane. self.m_planeEntity = QEntity(self.m_rootEntity) self.m_planeEntity.addComponent(planeMesh) self.m_planeEntity.addComponent(planeMaterial) self.m_planeEntity.addComponent(planeTransform) # Sphere shape data. sphereMesh = QSphereMesh() sphereMesh.setRings(20) sphereMesh.setSlices(20) sphereMesh.setRadius(2) # Sphere mesh transform. sphereTransform = QTransform() sphereTransform.setScale(1.3) sphereTransform.setTranslation(QVector3D(-5.0, -4.0, 0.0)) sphereMaterial = QPhongMaterial() sphereMaterial.setDiffuse(QColor(0xa69929)) # Sphere. self.m_sphereEntity = QEntity(self.m_rootEntity) self.m_sphereEntity.addComponent(sphereMesh) self.m_sphereEntity.addComponent(sphereMaterial) self.m_sphereEntity.addComponent(sphereTransform)