예제 #1
0
파일: pyqt3d.py 프로젝트: nuipek/Pruebas
    def __init__(self):
        super(View3D, self).__init__()
        self.view = Qt3DWindow()
        self.container = self.createWindowContainer(self.view)

        vboxlayout = QHBoxLayout()
        vboxlayout.addWidget(self.container)
        self.setLayout(vboxlayout)

        scene = createScene()

        # Camera.
        initialiseCamera(self.view, scene)

        self.view.setRootEntity(scene)
예제 #2
0
    def __init__(self, robot_type, parent=None):
        super(View3D, self).__init__(parent)
        self.view = Qt3DWindow()
        self.parent = parent
        self.view.defaultFrameGraph().setClearColor(QColor(51, 51, 51))
        self.container = self.createWindowContainer(self.view)
        self.setStyleSheet('background-color: white')
        self.robot_type = robot_type
        self.robot_entity = None
        self.setMouseTracking(True)

        vboxlayout = QHBoxLayout()
        vboxlayout.addWidget(self.container)
        self.setLayout(vboxlayout)

        self.scene = self.createScene()

        # Camera.
        self.initialiseCamera(self.scene)

        self.view.setRootEntity(self.scene)
예제 #3
0
    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


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)
예제 #4
0
    def create3DWidget(self):
        view = Qt3DWindow()
        # view.defaultFramegraph().setClearColor(QColor(0x4d4d4f))
        container = QWidget.createWindowContainer(view)
        screenSize = view.screen().size()
        container.setMinimumSize(QSize(200, 100))
        container.setMaximumSize(screenSize)
        aspect = QInputAspect()
        view.registerAspect(aspect)
        # Root entity.
        self.rootEntity = QEntity()

        # Camera.
        cameraEntity = view.camera()

        cameraEntity.lens().setPerspectiveProjection(45.0, 16.0 / 9.0, 0.1,
                                                     1000.0)
        cameraEntity.setPosition(QVector3D(0.0, -50.0, -0.5))
        cameraEntity.setUpVector(QVector3D(0.0, -1.0, 0.0))
        cameraEntity.setViewCenter(QVector3D(0.0, 0.0, 0.0))

        # Light
        lightEntity = QEntity(self.rootEntity)
        light = QPointLight(lightEntity)
        light.setColor(QColor.fromRgbF(1.0, 1.0, 1.0, 1.0))
        light.setIntensity(1)
        lightEntity.addComponent(light)
        lightTransform = QTransform(lightEntity)
        lightTransform.setTranslation(QVector3D(10.0, -40.0, 0.0))
        lightEntity.addComponent(lightTransform)

        # For camera controls.
        camController = QFirstPersonCameraController(self.rootEntity)
        camController.setCamera(cameraEntity)

        # Set root object of the scene.
        view.setRootEntity(self.rootEntity)

        self.modifier = SceneModifier(self.rootEntity)

        moveLeft = QPushButton(text="Left")
        moveLeft.clicked.connect(self.modifier.transformLeft)
        moveLeft.setAutoRepeat(True)

        moveRight = QPushButton(text="Right")
        moveRight.clicked.connect(self.modifier.transformRight)
        moveRight.setAutoRepeat(True)

        moveUp = QPushButton(text="Up")
        moveUp.clicked.connect(self.modifier.transformUp)
        moveUp.setAutoRepeat(True)

        moveDown = QPushButton(text="Down")
        moveDown.clicked.connect(self.modifier.transformDown)
        moveDown.setAutoRepeat(True)

        moveX = QPushButton(text="RotateX")
        moveX.clicked.connect(self.modifier.rotateX)
        moveX.setAutoRepeat(True)

        moveY = QPushButton(text="RotateY")
        moveY.clicked.connect(self.modifier.rotateY)
        moveY.setAutoRepeat(True)

        moveZ = QPushButton(text="RotateZ")
        moveZ.clicked.connect(self.modifier.rotateZ)
        moveZ.setAutoRepeat(True)

        scaleDown = QPushButton(text="Scale Down")
        scaleDown.clicked.connect(self.modifier.scaleDown)
        scaleDown.setAutoRepeat(True)

        scaleUp = QPushButton(text="Scale Up")
        scaleUp.clicked.connect(self.modifier.scaleUp)
        scaleUp.setAutoRepeat(True)

        switchModel = QPushButton(text="Switch Model")
        switchModel.clicked.connect(self.modifier.handlePickerPress)

        loadModel = QPushButton(text="Load Model")
        loadModel.clicked.connect(self.modifier.loadscene)

        self.vLayout.addWidget(moveLeft)
        self.vLayout.addWidget(moveRight)
        self.vLayout.addWidget(moveUp)
        self.vLayout.addWidget(moveDown)
        self.vLayout.addWidget(moveX)
        self.vLayout.addWidget(moveY)
        self.vLayout.addWidget(moveZ)
        self.vLayout.addWidget(scaleUp)
        self.vLayout.addWidget(scaleDown)
        self.vLayout.addWidget(switchModel)
        self.vLayout.addWidget(loadModel)
        self.scribbleArea.modifier = self.modifier
        return container
예제 #5
0
    def __init__(self, app):
        view = Qt3DWindow()
        # view.defaultFramegraph().setClearColor(QColor(0x4d4d4f))
        container = QWidget.createWindowContainer(view)
        screenSize = view.screen().size()
        container.setMinimumSize(QSize(200, 100))
        container.setMaximumSize(screenSize)

        widget = QWidget()
        self.hLayout = QHBoxLayout(widget)
        self.vLayout = QVBoxLayout()
        self.vLayout.setAlignment(Qt.AlignTop)
        self.hLayout.addWidget(container, 1)
        self.hLayout.addLayout(self.vLayout)

        widget.setWindowTitle("3D Viewer")

        aspect = QInputAspect()
        view.registerAspect(aspect)

        # Root entity.
        self.rootEntity = QEntity()

        # Camera.
        cameraEntity = view.camera()

        cameraEntity.lens().setPerspectiveProjection(45.0, 16.0 / 9.0, 0.1,
                                                     1000.0)
        cameraEntity.setPosition(QVector3D(0.0, -50.0, -0.5))
        cameraEntity.setUpVector(QVector3D(0.0, 1.0, 0.0))
        cameraEntity.setViewCenter(QVector3D(0.0, 0.0, 0.0))

        # Light
        lightEntity = QEntity(self.rootEntity)
        light = QPointLight(lightEntity)
        light.setColor(QColor.fromRgbF(1.0, 1.0, 1.0, 1.0))
        light.setIntensity(1)
        lightEntity.addComponent(light)
        lightTransform = QTransform(lightEntity)
        lightTransform.setTranslation(QVector3D(10.0, 40.0, 0.0))
        lightEntity.addComponent(lightTransform)

        # For camera controls.
        camController = QFirstPersonCameraController(self.rootEntity)
        camController.setCamera(cameraEntity)

        # Set root object of the scene.
        view.setRootEntity(self.rootEntity)

        modifier = SceneModifier(self.rootEntity)

        moveLeft = QPushButton(text="Left")
        moveLeft.clicked.connect(modifier.transformLeft)
        moveLeft.setAutoRepeat(True)

        moveRight = QPushButton(text="Right")
        moveRight.clicked.connect(modifier.transformRight)
        moveRight.setAutoRepeat(True)

        moveUp = QPushButton(text="Up")
        moveUp.clicked.connect(modifier.transformUp)
        moveUp.setAutoRepeat(True)

        moveDown = QPushButton(text="Down")
        moveDown.clicked.connect(modifier.transformDown)
        moveDown.setAutoRepeat(True)

        scaleDown = QPushButton(text="Scale Down")
        scaleDown.clicked.connect(modifier.scaleDown)
        scaleDown.setAutoRepeat(True)

        scaleUp = QPushButton(text="Scale Up")
        scaleUp.clicked.connect(modifier.scaleUp)
        scaleUp.setAutoRepeat(True)

        switchModel = QPushButton(text="Switch Model")
        switchModel.clicked.connect(self.modifier.handlePickerPress)

        loadModel = QPushButton(text="Load Model")
        loadModel.clicked.connect(self.modifier.loadscene)

        self.vLayout.addWidget(moveLeft)
        self.vLayout.addWidget(moveRight)
        self.vLayout.addWidget(moveUp)
        self.vLayout.addWidget(moveDown)
        self.vLayout.addWidget(scaleUp)
        self.vLayout.addWidget(scaleDown)
        self.vLayout.addWidget(switchModel)
        self.vLayout.addWidget(loadModel)

        # Show the window.
        widget.show()
        widget.resize(1200, 800)
        sys.exit(app.exec_())