Пример #1
0
    def flushRendering(self):
        new = QEntity()
        self.view.setRootEntity(new)
        camController = QFirstPersonCameraController(new)

        self.scene = new
        self.createScene()

        camController.setLinearSpeed(500.0)
        camController.setLookSpeed(180.0)
        camController.setCamera(self.camera)
Пример #2
0
 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)
Пример #3
0
    def initialiseCamera(self, view):
        # Camera.
        self.camera = view.camera()
        self.camera.lens().setPerspectiveProjection(45.0, 16.0 / 9.0, 0.1,
                                                    1000000.0)
        self.camera.setPosition(QVector3D(100, 100, 100))
        self.camera.setViewCenter(QVector3D(0.0, 0.0, 0.0))

        # For camera controls.
        camController = QFirstPersonCameraController(self.scene)
        camController.setLinearSpeed(500.0)
        camController.setLookSpeed(300.0)
        camController.setCamera(self.camera)
Пример #4
0
view = Qt3DWindow()

# Scene root.
sceneRoot = QEntity()

# Scene camera.
basicCamera = view.camera()
basicCamera.setProjectionType(QCameraLens.PerspectiveProjection)
basicCamera.setAspectRatio(view.width() / view.height())
basicCamera.setUpVector(QVector3D(0.0, 1.0, 0.0))
basicCamera.setViewCenter(QVector3D(0.0, 3.5, 0.0))
basicCamera.setPosition(QVector3D(0.0, 3.5, 25.0))

# Camera controls.
camController = QFirstPersonCameraController(sceneRoot)
camController.setCamera(basicCamera)

# Scene floor.
planeEntity = PlaneEntity(sceneRoot)
planeEntity.mesh().setHeight(100.0)
planeEntity.mesh().setWidth(100.0)
planeEntity.mesh().setMeshResolution(QSize(20, 20))

normalDiffuseSpecularMapMaterial = QNormalDiffuseSpecularMapMaterial()
normalDiffuseSpecularMapMaterial.setTextureScale(10.0)
normalDiffuseSpecularMapMaterial.setShininess(80.0)
normalDiffuseSpecularMapMaterial.setAmbient(QColor.fromRgbF(
    0.2, 0.2, 0.2, 1.0))

diffuseImage = QTextureImage()
diffuseImage.setSource(
Пример #5
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
Пример #6
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_())
Пример #7
0
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")
coneCB = QCheckBox(checked=True, text="Cone")