示例#1
0
文件: cwindow.py 项目: nuipek/Pruebas
 def __init__(self):
     super().__init__()
     lay = QVBoxLayout(self)
     self.view = Qt3DWindow()
     container = QWidget.createWindowContainer(self.view)
     lay.addWidget(container)
     self.rootEntity = QEntity()
     cameraEntity = self.view.camera()
     camController = QFirstPersonCameraController(self.rootEntity)
     camController.setCamera(cameraEntity)
     self.view.setRootEntity(self.rootEntity)
示例#2
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_())
示例#3
0
aspect = QInputAspect()
view.registerAspect(aspect)

# Root entity.
rootEntity = QEntity()

# Camera.
cameraEntity = view.camera()

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

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

# Scene modifier.
modifier = SceneModifier(rootEntity)

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

# Create control widgets.
info = QCommandLinkButton(text="Qt3D ready-made meshes")
info.setDescription("Qt3D provides several ready-made meshes, like torus, "
                    "cylinder, cone, cube, plane and sphere.")
info.setIconSize(QSize(0, 0))

torusCB = QCheckBox(checked=True, text="Torus")