PyQt5 und Pyqt3D

Hier werden alle anderen GUI-Toolkits sowie Spezial-Toolkits wie Spiele-Engines behandelt.
Antworten
tryyan
User
Beiträge: 23
Registriert: Freitag 7. Oktober 2022, 13:08

Hallo. Ich habe wieder ein neues problem beim PYQt3D.
Ich möchte ein 3D mbjekt(obj Datei), darstellen in einem PyQT5 Window. Das habe ich auch geschaft(code folgt). Jetzt möchte ich das aber nutzen beim laden einer Ui datei. Das Qwidget wird erkannt und eingefärbt aber das 3d modell fehlt und des gibt keineen error. kann mir jemand helfen.

Code ohne laden des UI files

Code: Alles auswählen

# Copyright (C) 2016 Riverbank Computing Limited
# Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
#
# Commercial License Usage
# Licensees holding valid commercial Qt licenses may use this file in
# accordance with the commercial license agreement provided with the
# Software or, alternatively, in accordance with the terms contained in
# a written agreement between you and The Qt Company. For licensing terms
# and conditions see https://www.qt.io/terms-conditions. For further
# information use the contact form at https://www.qt.io/contact-us.
#
# BSD License Usage
# Alternatively, you may use this file under the terms of the BSD license
# as follows:
#
# "Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#   * Redistributions of source code must retain the above copyright
#     notice, this list of conditions and the following disclaimer.
#   * Redistributions in binary form must reproduce the above copyright
#     notice, this list of conditions and the following disclaimer in
#     the documentation and/or other materials provided with the
#     distribution.
#   * Neither the name of The Qt Company Ltd nor the names of its
#     contributors may be used to endorse or promote products derived
#     from this software without specific prior written permission.
#
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."


import sys

from PyQt5.QtCore import pyqtSlot, QObject, QSize, Qt, QUrl
from PyQt5.QtGui import QColor, QQuaternion, QVector3D
from PyQt5.QtWidgets import (QApplication, QCheckBox, QCommandLinkButton,
                             QHBoxLayout, QVBoxLayout, QWidget, QPushButton)
from PyQt5.Qt3DCore import QEntity, QTransform
from PyQt5.Qt3DExtras import (Qt3DWindow, QConeMesh, QCuboidMesh,
                              QCylinderMesh, QFirstPersonCameraController, QPhongMaterial,
                              QPlaneMesh, QSphereMesh, QTorusMesh, QDiffuseMapMaterial)
from PyQt5.Qt3DInput import QInputAspect
from PyQt5.Qt3DRender import QCamera, QTextureImage, QMesh


class RenderableEntity(QEntity):

    def __init__(self, parent=None):
        super(RenderableEntity, self).__init__(parent)

        self.m_mesh = QMesh()
        self.m_transform = QTransform()

        self.addComponent(self.m_mesh)
        self.addComponent(self.m_transform)

    def mesh(self):
        return self.m_mesh

    def transform(self):
        return self.m_transform

class SceneModifier(QObject):

    def __init__(self, rootEntity):
        super(SceneModifier, self).__init__()
        self.m_rootEntity = rootEntity
        sceneRoot = QEntity(self.m_rootEntity)

        chest = RenderableEntity(self.m_rootEntity)
        chest.transform().setScale(0.03)
        chest.mesh().setSource(QUrl.fromLocalFile('../../Documents/programmieren/py/LYX-Launcher-3.00/PlayerSkinny.obj'))
        diffuseMapMaterial = QDiffuseMapMaterial()
        diffuseMapMaterial.setSpecular(QColor.fromRgbF(0.2, 0.2, 0.2, 1.0))
        diffuseMapMaterial.setShininess(2.0)

        chestDiffuseImage = QTextureImage()
        chestDiffuseImage.setSource(QUrl.fromLocalFile('./alex.png'))
        diffuseMapMaterial.diffuse().addTextureImage(chestDiffuseImage)

        chest.addComponent(diffuseMapMaterial)



app = QApplication(sys.argv)

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()
hLayout = QHBoxLayout(widget)
vLayout = QVBoxLayout()
vLayout.setAlignment(Qt.AlignTop)
hLayout.addWidget(container, 1)
hLayout.addLayout(vLayout)

widget.setWindowTitle("Basic shapes")

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, 100.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")
cylinderCB = QCheckBox(checked=True, text="Cylinder")
cuboidCB = QCheckBox(checked=True, text="Cuboid")
planeCB = QCheckBox(checked=True, text="Plane")
sphereCB = QCheckBox(checked=True, text="Sphere")
button = QPushButton('PyQt5 button')
vLayout.addWidget(info)
vLayout.addWidget(torusCB)
vLayout.addWidget(coneCB)
vLayout.addWidget(cylinderCB)
vLayout.addWidget(cuboidCB)
vLayout.addWidget(planeCB)
vLayout.addWidget(sphereCB)
vLayout.addWidget(button)


# Show the window.
widget.show()
widget.resize(1200, 800)
sys.exit(app.exec_())
code mit laden des UI files

Code: Alles auswählen

import zipfile

from PyQt5.Qt3DCore import QEntity, QTransform
from PyQt5.Qt3DExtras import QDiffuseMapMaterial, Qt3DWindow, QFirstPersonCameraController
from PyQt5.Qt3DInput import QInputAspect
from PyQt5.Qt3DRender import QMesh, QTextureImage
from PyQt5.QtCore import QTime, QTimer, QObject, QUrl, QSize, Qt
from PyQt5.QtGui import QColor, QVector3D
from PyQt5.QtWidgets import QMainWindow, QApplication, QPushButton, QProgressBar, QLabel, QCheckBox, QWidget, \
    QVBoxLayout, QHBoxLayout
from tqdm import tqdm

import login


from scripts import download_requyet_files, get_work_directory, run_minecraft, json_functions, test_pass, get_download_size
from scripts.GetPlayerInfos import getSkinTexture
import scripts.get_work_directory

from qtpy import uic
import sys, os


#get ui type
from scripts.download_requyet_files import download_files
from scripts.unzipping import ZipFileCustom

uifile_1 = 'assets/UI/GUI_LYX_MAIN.ui'
form_1, base_1 = uic.loadUiType(uifile_1)

class RenderableEntity(QEntity):

    def __init__(self, parent=None):
        super(RenderableEntity, self).__init__(parent)

        self.m_mesh = QMesh()
        self.m_transform = QTransform()

        self.addComponent(self.m_mesh)
        self.addComponent(self.m_transform)

    def mesh(self):
        return self.m_mesh

    def transform(self):
        return self.m_transform

class SceneModifier(QObject):

    def __init__(self, rootEntity):
        super(SceneModifier, self).__init__()
        self.m_rootEntity = rootEntity
        sceneRoot = QEntity(self.m_rootEntity)

        chest = RenderableEntity(sceneRoot)
        chest.transform().setScale(0.03)
        chest.mesh().setSource(QUrl.fromLocalFile('PlayerSkinny.obj'))
        diffuseMapMaterial = QDiffuseMapMaterial()
        diffuseMapMaterial.setSpecular(QColor.fromRgbF(0.2, 0.2, 0.2, 1.0))
        diffuseMapMaterial.setShininess(2.0)

        chestDiffuseImage = QTextureImage()
        chestDiffuseImage.setSource(QUrl.fromLocalFile('alex.png'))
        diffuseMapMaterial.diffuse().addTextureImage(chestDiffuseImage)

        chest.addComponent(diffuseMapMaterial)
class UI(form_1, base_1):

    def __init__(self):
        super(UI, self).__init__()
        uic.loadUi("assets/UI/GUI_LYX_MAIN.ui", self)
        self.Launch_button = self.findChild(QPushButton, "launch_button")
        self.Login_button = self.findChild(QPushButton, "ChangeAccount")
        self.Launch_button.clicked.connect(self.run)
        self.Login_button.clicked.connect(self.show_login_screen)
        self.progressbar = self.findChild(QProgressBar, "Progressbar")

        self.offline_mode = self.findChild(QCheckBox, "offline_mod")
        self.d3wighet = self.findChild(QWidget, "d3wig")


        rootEntity = QEntity()







        view = Qt3DWindow()
        view.defaultFrameGraph().setClearColor(QColor(0x4d4d4f))
        container = self.d3wighet.createWindowContainer(view)
        screenSize = view.screen().size()
        container.setMinimumSize(QSize(10, 650))
        container.setMaximumSize(screenSize)
        hLayout = QHBoxLayout(self.d3wighet)
        vLayout = QVBoxLayout(self.d3wighet)
        vLayout.setAlignment(Qt.AlignTop)
        hLayout.addWidget(container, 1)
        hLayout.addLayout(vLayout)
        aspect = QInputAspect()
        view.registerAspect(aspect)

        # Root entity.


        # 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)

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



if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = UI()
    ex.show()
    sys.exit(app.exec_())
    
Antworten