def create_window(self): app = QApplication(sys.argv) view = Qt3DWindow() view.setTitle("Inverse Kinematic Controls") scene = self.createScene() # # fig = mpl_canvas() # fig.initialize_graph() # bot = fig.create_body() # # bot.graph(fig.sp) # bot.update(fig.sp) # fig.draw() self.camera = view.camera() self.camera.lens().setPerspectiveProjection(30, 4.0 / 3.0, 0.1, 1000.0) self.camera.setPosition(QVector3D(0, 0, 40.0)) self.camera.setViewCenter(QVector3D(1., 1., 1.)) # For camera controls camController = QOrbitCameraController(scene) camController.setLinearSpeed(25.0) camController.setLookSpeed(90.0) camController.setCamera(self.camera) view.setRootEntity(scene) view.show() # fig.show() app.exec_()
def _init_camera_control(self): cam_controller = QOrbitCameraController(self._scene) cam_controller.setLinearSpeed(0) cam_controller.setLookSpeed(200) cam_controller.setCamera(self.camera()) return cam_controller
def __init__(self): super().__init__() self.scene = self.createScene() # camera camera = self.camera() camera.lens().setPerspectiveProjection(45.0, 16.0 / 9.0, 0.1, 1000) camera.setPosition(QVector3D(0, 0, 40)) camera.setViewCenter(QVector3D(0, 0, 0)) # for camera control self.camController = QOrbitCameraController(self.scene) self.camController.setLinearSpeed(50.0) self.camController.setLookSpeed(180.0) self.camController.setCamera(camera) self.setRootEntity(self.scene) self.show()
def initialiseCamera(view, scene): # Camera. camera = view.camera() camera.lens().setPerspectiveProjection(45.0, 16.0 / 9.0, 0.1, 1000.0) camera.setPosition(QVector3D(0.0, 0.0, 40.0)) camera.setViewCenter(QVector3D(0.0, 0.0, 0.0)) # For camera controls. camController = QOrbitCameraController(scene) camController.setLinearSpeed(50.0) camController.setLookSpeed(180.0) camController.setCamera(camera)
def __init__(self, parent=None): super().__init__() self.view = PyQt5.Qt3DExtras.Qt3DWindow(parent) self.scene = self.createScene() # Camera self.camera = self.view.camera() self.camera.lens().setPerspectiveProjection(45.0, 16.0 / 9.0, 0.1, 1000.0) self.camera.setPosition(QVector3D(0, 0, 40.0)) self.camera.setViewCenter(QVector3D(0, 0, 0)) # For camera controls self.camController = QOrbitCameraController(self.scene) self.camController.setLinearSpeed(50.0) self.camController.setLookSpeed(180.0) self.camController.setCamera(self.camera) self.view.defaultFrameGraph().setClearColor( PyQt5.QtGui.QColor(60, 250, 60)) self.view.setRootEntity(self.scene)
class ThreeDeeCubeWindow(Qt3DWindow): def __init__(self): super().__init__() self.scene = self.createScene() # camera camera = self.camera() camera.lens().setPerspectiveProjection(45.0, 16.0 / 9.0, 0.1, 1000) camera.setPosition(QVector3D(0, 0, 40)) camera.setViewCenter(QVector3D(0, 0, 0)) # for camera control self.camController = QOrbitCameraController(self.scene) self.camController.setLinearSpeed(50.0) self.camController.setLookSpeed(180.0) self.camController.setCamera(camera) self.setRootEntity(self.scene) self.show() 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
sphereRotateTransformAnimation.start() sphereEntity.addComponent(sphereMesh) sphereEntity.addComponent(sphereTransform) sphereEntity.addComponent(material) return rootEntity app = QGuiApplication(sys.argv) view = Qt3DWindow() scene = createScene() # Camera. camera = view.camera() camera.lens().setPerspectiveProjection(45.0, 16.0 / 9.0, 0.1, 1000.0) camera.setPosition(QVector3D(0.0, 0.0, 40.0)) camera.setViewCenter(QVector3D(0.0, 0.0, 0.0)) # For camera controls. camController = QOrbitCameraController(scene) camController.setLinearSpeed(50.0) camController.setLookSpeed(180.0) camController.setCamera(camera) view.setRootEntity(scene) view.show() sys.exit(app.exec_())
class View3D(PyQt5.QtCore.QObject): def __init__(self, parent=None): super().__init__() self.view = PyQt5.Qt3DExtras.Qt3DWindow(parent) self.scene = self.createScene() # Camera self.camera = self.view.camera() self.camera.lens().setPerspectiveProjection(45.0, 16.0 / 9.0, 0.1, 1000.0) self.camera.setPosition(QVector3D(0, 0, 40.0)) self.camera.setViewCenter(QVector3D(0, 0, 0)) # For camera controls self.camController = QOrbitCameraController(self.scene) self.camController.setLinearSpeed(50.0) self.camController.setLookSpeed(180.0) self.camController.setCamera(self.camera) self.view.defaultFrameGraph().setClearColor( PyQt5.QtGui.QColor(60, 250, 60)) self.view.setRootEntity(self.scene) @staticmethod 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 activate_camera(self, scene): # # For camera controls. camController = QOrbitCameraController(scene) camController.setLinearSpeed(250.0) camController.setLookSpeed(250.0) camController.setCamera(self.camera)