PyQt5 und PYOPENGL landen von obj datein

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 würde gerne mit PyQt5 und Opengl obj dateien dartsellen(laden). Kann mir jemand helfen? Es geibt eben kein Tourtorial.
Hier meine GUI

Code: Alles auswählen

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'Graphiscvew_test.ui'
#
# Created by: PyQt5 UI code generator 5.15.6
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets

from PyQt5 import QtCore, QtWidgets
from OpenGLSkin import PyQtOpenGL
from time import sleep
import sys

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(800, 600)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.frame_gl = QtWidgets.QFrame(self.centralwidget)
        self.frame_gl.setGeometry(QtCore.QRect(400, 90, 300, 300))
        self.frame_gl.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame_gl.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame_gl.setObjectName("frame_gl")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 22))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

        open_gl = PyQtOpenGL(parent=self.frame_gl)
        open_gl.setMinimumSize(300, 500)
        open_gl.paint_0 = True
        open_gl.paint_1 = True
        open_gl.paint_2 = True
        open_gl.resize_lines = True
        open_gl.resize_lines = False
        open_gl.paint_rotation = True
        #open_gl.paint_rotation = False
#muss noch 3d machen video 12:35
    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())
__deets__
User
Beiträge: 14545
Registriert: Mittwoch 14. Oktober 2015, 14:29

Du nimmst dir sowas https://pypi.org/project/PyWavefront/ und baust Deine Display Listen aus den Koordinaten. Die haben auch Code für pyglet, den du dir anschauen kannst.
tryyan
User
Beiträge: 23
Registriert: Freitag 7. Oktober 2022, 13:08

Ok danke schaue mir das mal an
tryyan
User
Beiträge: 23
Registriert: Freitag 7. Oktober 2022, 13:08

Hi irgendwie schaffe ich das nicht kann mir bitte jemand helfen
__deets__
User
Beiträge: 14545
Registriert: Mittwoch 14. Oktober 2015, 14:29

Was probierst du denn? Denn "mal bitte helfen" heisst hier, dass sich wer anders ein paar Stunden hinsetzen muss. Das wird eher nicht passieren. Zeig, was du machst, und welche Probleme auftreten.

Oder benutz einfach gleich eine 3D-Engine, die mit Assets dieses (und aller anderen Formate) umgehen kann.
tryyan
User
Beiträge: 23
Registriert: Freitag 7. Oktober 2022, 13:08

Hi das ist mir klar und ich möchte auch nicht das jemand mir alles macht. Ich möchte in einer PYQT5 GUI ein 3D model anzeigen. Wieso PYQT5, da ich einen Minecraft Launcher mache in dem man den skin (3D Model anzeigen kann (Drehen und so.)). Ich habe leider kein Modul für das gefunden und bin deshalb auf Hilfe und Ideen angewiesen wie ich diese Problem lösen kann(welche module verwenden). Herzlichen Dank für die Hilfe
__deets__
User
Beiträge: 14545
Registriert: Mittwoch 14. Oktober 2015, 14:29

Ich meinte eher, was du konkret probiert hast. Ich habe dir doch ein Modul genannt, mit dem du aus OBJ die 3D-Daten in Python bekommst. Was genau hast du damit angestellt? Denn google bedienen kannst du ja selbst, du hast ja auch schon durch andere Probleme dich erfolgreich durchgearbeitet. Eine "bessere" Integration gibt's also eher nicht, du musst da eben viel Hand anlegen.
tryyan
User
Beiträge: 23
Registriert: Freitag 7. Oktober 2022, 13:08

Ah ok das modul das du mir geschickt hast kann auch obj file laden dann schaue ich mir das mal noch genauer an. Danke. Ich habe einfach viel gesuch aber nichts gefunden danke. Schreibe bann so gegen Samstag ein Update
tryyan
User
Beiträge: 23
Registriert: Freitag 7. Oktober 2022, 13:08

Ich muss das Projekt aufgeben und als gescheitert betrachten, da ich es Komplet nicht verstehe wie ich obj file darstellen kann in PYQT5. Bin sehr dankbar wenn mir trotzdem jemand weiterhelfen kann. Das Problem inst pywavefront verstehe ich gar nicht und es gibt kein tutorial dazu. Wenn jemand Zeit und Lust hat mir zu helfen, können wir uns auf discord austauschen/ telefonieren.(discord name von mir try#0809 einfach melden).
tryyan
User
Beiträge: 23
Registriert: Freitag 7. Oktober 2022, 13:08

Hallo. Ich habe nun einen weg gefunden es umzusetzen habe nur ein kleines Problem, Ich möchte das 3D Modell nur auf etwa ein viertel des Fensters beschränkeng, das ich zum Beispiel noch push Buttons und so hinzufügen kann, kann mir jemand helfen. Es giebt eben immer einen Error. Ich habe ein ähnliches Beispiel gefunden mit push Buttons aber dieses ladet nicht ein obj File und ich kann das nicht einbauen HErzlichen dank
für die hilfe.

Code: Alles auswählen


import os
import sys

from PyQt5.QtCore import (pyqtProperty, pyqtSignal, QPropertyAnimation, QSize,
                          Qt, QUrl)
from PyQt5.QtGui import QColor, QGuiApplication, QMatrix4x4, QVector3D
from PyQt5.Qt3DCore import QEntity, QTransform
from PyQt5.Qt3DExtras import (Qt3DWindow, QDiffuseMapMaterial,
                              QFirstPersonCameraController, QNormalDiffuseMapAlphaMaterial,
                              QNormalDiffuseMapMaterial, QNormalDiffuseSpecularMapMaterial,
                              QPhongMaterial, QPlaneMesh)
from PyQt5.Qt3DRender import QCamera, QCameraLens, QMesh, QTextureImage
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton
from PyQt5.QtCore import pyqtSlot

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
# Change to the directory containing the example so that the path to the assets
# is correct.
os.chdir(os.path.dirname(os.path.abspath(__file__)))
app = QGuiApplication(sys.argv)
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)
normalDiffuseSpecularMapMaterial = QNormalDiffuseSpecularMapMaterial()
normalDiffuseSpecularMapMaterial.setTextureScale(10.0)
normalDiffuseSpecularMapMaterial.setShininess(80.0)
normalDiffuseSpecularMapMaterial.setAmbient(QColor.fromRgbF(0.2, 0.2, 0.2, 1.0))
# Chest.
chest = RenderableEntity(sceneRoot)
chest.transform().setScale(1)
chest.mesh().setSource(QUrl.fromLocalFile('assets/obj/model.obj'))
diffuseMapMaterial = QDiffuseMapMaterial()
diffuseMapMaterial.setSpecular(QColor.fromRgbF(0.2, 0.2, 0.2, 1.0))
diffuseMapMaterial.setShininess(80.0)

chestDiffuseImage = QTextureImage()

chestDiffuseImage.setSource(QUrl.fromLocalFile('assets/obj/Liyanix.png'))

diffuseMapMaterial.diffuse().addTextureImage(chestDiffuseImage)

chest.addComponent(diffuseMapMaterial)

view.setRootEntity(sceneRoot)
view.show()

sys.exit(app.exec_())


Code mit pushbutton

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
from PyQt5.QtGui import QColor, QQuaternion, QVector3D
from PyQt5.QtWidgets import (QApplication, QCheckBox, QCommandLinkButton,
        QHBoxLayout, QVBoxLayout, QWidget)
from PyQt5.Qt3DCore import QEntity, QTransform
from PyQt5.Qt3DExtras import (Qt3DWindow, QConeMesh, QCuboidMesh,
        QCylinderMesh, QFirstPersonCameraController, QPhongMaterial,
        QPlaneMesh, QSphereMesh, QTorusMesh)
from PyQt5.Qt3DInput import QInputAspect
from PyQt5.Qt3DRender import QCamera


class SceneModifier(QObject):

    def __init__(self, rootEntity):
        super(SceneModifier, self).__init__()

        self.m_rootEntity = rootEntity

        # Torus shape data.
        self.m_torus = QTorusMesh()
        self.m_torus.setRadius(1.0)
        self.m_torus.setMinorRadius(0.4)
        self.m_torus.setRings(100)
        self.m_torus.setSlices(20)

        # TorusMesh transform.
        torusTransform = QTransform()
        torusTransform.setScale(2.0)
        torusTransform.setRotation(
                QQuaternion.fromAxisAndAngle(QVector3D(0.0, 1.0, 0.0), 25.0))
        torusTransform.setTranslation(QVector3D(5.0, 4.0, 0.0))

        torusMaterial = QPhongMaterial()
        torusMaterial.setDiffuse(QColor(0xbeb32b))

        # Torus.
        self.m_torusEntity = QEntity(self.m_rootEntity)
        self.m_torusEntity.addComponent(self.m_torus)
        self.m_torusEntity.addComponent(torusMaterial)
        self.m_torusEntity.addComponent(torusTransform)

        # Cone shape data.
        cone = QConeMesh()
        cone.setTopRadius(0.5)
        cone.setBottomRadius(1)
        cone.setLength(3)
        cone.setRings(50)
        cone.setSlices(20)

        # ConeMesh transform.
        coneTransform = QTransform()
        coneTransform.setScale(1.5)
        coneTransform.setRotation(
                QQuaternion.fromAxisAndAngle(QVector3D(1.0, 0.0, 0.0), 45.0))
        coneTransform.setTranslation(QVector3D(0.0, 4.0, -1.5))

        coneMaterial = QPhongMaterial()
        coneMaterial.setDiffuse(QColor(0x928327))

        # Cone.
        self.m_coneEntity = QEntity(self.m_rootEntity)
        self.m_coneEntity.addComponent(cone)
        self.m_coneEntity.addComponent(coneMaterial)
        self.m_coneEntity.addComponent(coneTransform)

        # Cylinder shape data.
        cylinder = QCylinderMesh()
        cylinder.setRadius(1)
        cylinder.setLength(3)
        cylinder.setRings(100)
        cylinder.setSlices(20)

        # CylinderMesh transform.
        cylinderTransform = QTransform()
        cylinderTransform.setScale(1.5)
        cylinderTransform.setRotation(
                QQuaternion.fromAxisAndAngle(QVector3D(1.0, 0.0, 0.0), 45.0))
        cylinderTransform.setTranslation(QVector3D(-5.0, 4.0, -1.5))

        cylinderMaterial = QPhongMaterial()
        cylinderMaterial.setDiffuse(QColor(0x928327))

        # Cylinder.
        self.m_cylinderEntity = QEntity(self.m_rootEntity)
        self.m_cylinderEntity.addComponent(cylinder)
        self.m_cylinderEntity.addComponent(cylinderMaterial)
        self.m_cylinderEntity.addComponent(cylinderTransform)

        # Cuboid shape data.
        cuboid = QCuboidMesh()

        # CuboidMesh transform.
        cuboidTransform = QTransform()
        cuboidTransform.setScale(4.0)
        cuboidTransform.setTranslation(QVector3D(5.0, -4.0, 0.0))

        cuboidMaterial = QPhongMaterial()
        cuboidMaterial.setDiffuse(QColor(0x665423))

        # Cuboid.
        self.m_cuboidEntity = QEntity(self.m_rootEntity)
        self.m_cuboidEntity.addComponent(cuboid)
        self.m_cuboidEntity.addComponent(cuboidMaterial)
        self.m_cuboidEntity.addComponent(cuboidTransform)

        # Plane shape data.
        planeMesh = QPlaneMesh()
        planeMesh.setWidth(2)
        planeMesh.setHeight(2)

        # Plane mesh transform.
        planeTransform = QTransform()
        planeTransform.setScale(1.3)
        planeTransform.setRotation(
                QQuaternion.fromAxisAndAngle(QVector3D(1.0, 0.0, 0.0), 45.0))
        planeTransform.setTranslation(QVector3D(0.0, -4.0, 0.0))

        planeMaterial = QPhongMaterial()
        planeMaterial.setDiffuse(QColor(0xa69929))

        # Plane.
        self.m_planeEntity = QEntity(self.m_rootEntity)
        self.m_planeEntity.addComponent(planeMesh)
        self.m_planeEntity.addComponent(planeMaterial)
        self.m_planeEntity.addComponent(planeTransform)

        # Sphere shape data.
        sphereMesh = QSphereMesh()
        sphereMesh.setRings(20)
        sphereMesh.setSlices(20)
        sphereMesh.setRadius(2)

        # Sphere mesh transform.
        sphereTransform = QTransform()
        sphereTransform.setScale(1.3)
        sphereTransform.setTranslation(QVector3D(-5.0, -4.0, 0.0))

        sphereMaterial = QPhongMaterial()
        sphereMaterial.setDiffuse(QColor(0xa69929))

        # Sphere.
        self.m_sphereEntity = QEntity(self.m_rootEntity)
        self.m_sphereEntity.addComponent(sphereMesh)
        self.m_sphereEntity.addComponent(sphereMaterial)
        self.m_sphereEntity.addComponent(sphereTransform)

    @pyqtSlot(int)
    def enableTorus(self, enabled):
        self.m_torusEntity.setParent(self.m_rootEntity if enabled else None)

    @pyqtSlot(int)
    def enableCone(self, enabled):
        self.m_coneEntity.setParent(self.m_rootEntity if enabled else None)

    @pyqtSlot(int)
    def enableCylinder(self, enabled):
        self.m_cylinderEntity.setParent(self.m_rootEntity if enabled else None)

    @pyqtSlot(int)
    def enableCuboid(self, enabled):
        self.m_cuboidEntity.setParent(self.m_rootEntity if enabled else None)

    @pyqtSlot(int)
    def enablePlane(self, enabled):
        self.m_planeEntity.setParent(self.m_rootEntity if enabled else None)

    @pyqtSlot(int)
    def enableSphere(self, enabled):
        self.m_sphereEntity.setParent(self.m_rootEntity if enabled else None)


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, 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")
cylinderCB = QCheckBox(checked=True, text="Cylinder")
cuboidCB = QCheckBox(checked=True, text="Cuboid")
planeCB = QCheckBox(checked=True, text="Plane")
sphereCB = QCheckBox(checked=True, text="Sphere")

vLayout.addWidget(info)
vLayout.addWidget(torusCB)
vLayout.addWidget(coneCB)
vLayout.addWidget(cylinderCB)
vLayout.addWidget(cuboidCB)
vLayout.addWidget(planeCB)
vLayout.addWidget(sphereCB)

torusCB.stateChanged.connect(modifier.enableTorus)
coneCB.stateChanged.connect(modifier.enableCone)
cylinderCB.stateChanged.connect(modifier.enableCylinder)
cuboidCB.stateChanged.connect(modifier.enableCuboid)
planeCB.stateChanged.connect(modifier.enablePlane)
sphereCB.stateChanged.connect(modifier.enableSphere)

# Show the window.
widget.show()
widget.resize(1200, 800)

sys.exit(app.exec_())
Benutzeravatar
__blackjack__
User
Beiträge: 13116
Registriert: Samstag 2. Juni 2018, 10:21
Wohnort: 127.0.0.1
Kontaktdaten:

@tryyan Das mit dem `m_`-Präfix und den trivialen Gettern macht man in Python nicht. Das `m_` wird in C++ als Konvention benutzt um Member-Variablen leichter erkennen zu können und macht in Python keinen Sinn, weil bei Attributen des Objekts *immer* ein ``self.`` davor steht was diese Aufgabe schon erfüllt.

In Python 3 braucht `super()` keine Argumente.

Dann bleibt von der Klasse nur noch das hier übrig:

Code: Alles auswählen

class RenderableEntity(QEntity):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.mesh = QMesh()
        self.transform = QTransform()
        self.addComponent(self.mesh)
        self.addComponent(self.transform)
Zumindest in dieser Form ist aber irgendwie fraglich ob man diese Klasse überhaupt benötigt.

Die Kommentare im Hauptprogramm die im Grunde nur den folgenden Variablennamen noch mal ”kommentieren” sind überflüssig.

`normalDiffuseSpecularMapMaterial` wird nirgends verwendet‽

Qt-Properties kann man schon beim erzeugen der Objekte angeben, dann spart man sich spätere `set*`-Aufrufe.

Ungetestet:

Code: Alles auswählen

def main():
    ...
    view = Qt3DWindow()

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

    sceneRoot = QEntity()
    QFirstPersonCameraController(sceneRoot, camera=camera)

    chest = QEntity(sceneRoot)
    chest.addComponent(
        QMesh(source=QUrl.fromLocalFile("assets/obj/model.obj"))
    )
    chest.addComponent(QTransform(scale=1))

    material = QDiffuseMapMaterial(
        specular=QColor.fromRgbF(0.2, 0.2, 0.2, 1.0), shininess=80
    )
    material.diffuse().addTextureImage(
        QTextureImage(source=QUrl.fromLocalFile("assets/obj/Liyanix.png"))
    )
    chest.addComponent(material)

    view.setRootEntity(sceneRoot)
    view.show()
    ...
„All religions are the same: religion is basically guilt, with different holidays.” — Cathy Ladman
tryyan
User
Beiträge: 23
Registriert: Freitag 7. Oktober 2022, 13:08

Guten Tag, danke für die Antwort, Sie beantwortet aber meine frage nicht wie kann ich die 3D Simulierung in einem Widget zeigen? Der Code, den du mir geschickt hast und aufgeräumter ist funktioniert nicht es gibt den Error Code Process finished with exit code -1073741819 (0xC0000005) wieder. Herzlcihen dank für die Antwort
Benutzeravatar
__blackjack__
User
Beiträge: 13116
Registriert: Samstag 2. Juni 2018, 10:21
Wohnort: 127.0.0.1
Kontaktdaten:

@tryyan: Was ist denn das konkrete Problem dabei? Du hast doch da Code gezeigt in dem das Fenster in ein Widged verpackt wird das man dann in einem anderen Fenster anzeigen kann.
„All religions are the same: religion is basically guilt, with different holidays.” — Cathy Ladman
tryyan
User
Beiträge: 23
Registriert: Freitag 7. Oktober 2022, 13:08

Das Problem ist das es nicht funktioniert. Ich habe das hier probiert und es geht nicht und ich habe keine Ahnung wieso es nicht geht. Herzlichen danke für die Antwort

Code: Alles auswählen

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

from skinminecraft import RenderableEntity


class SceneModifier(QObject):

    def __init__(self, rootEntity):
        super(SceneModifier, self).__init__()
        self.m_rootEntity = rootEntity
        
        chest = RenderableEntity(rootEntity)
        chest.transform().setScale(0.03)
        chest.mesh().setSource(QUrl.fromLocalFile('assets/chest/Chest.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('assets/chest/diffuse.webp'))
        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, 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.






# Show the window.
widget.show()
widget.resize(1200, 800)

sys.exit(app.exec_())
tryyan
User
Beiträge: 23
Registriert: Freitag 7. Oktober 2022, 13:08

Habe es geschaft !!!!!

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(sceneRoot)
        chest.transform().setScale(0.03)
        chest.mesh().setSource(QUrl.fromLocalFile('assets/chest/Chest.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('assets/chest/diffuse.webp'))
        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, 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")
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_())
Herzlichen dank für jede hilfe
Antworten