1

I recently just tried to run the following demo code from https://github.com/zchen24/examples-Qt/blob/master/qt3d/qt3d-simple-example.py:

#!/usr/bin/env python
"""
This is a Python port of Qt 3D: Simple C++ Example code
https://doc.qt.io/qt-5.10/qt3d-simple-cpp-example.html
Tested on
Anaconda Python 3.6
pip install PyQt5 (Version 5.10)
"""

import sys
from OpenGL import GL
from PyQt5 import QtCore
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.Qt3DCore import *
from PyQt5.QtWidgets import *
from PyQt5.Qt3DExtras import *


class OrbitTransformController(QObject):
    def __init__(self, parent):
        super(OrbitTransformController, self).__init__(parent)
        self.m_target = QTransform()
        self.m_matrix = QMatrix4x4()
        self.m_radius = 1.0
        self.m_angle = 0

    def getTarget(self):
        return self.m_target

    def setTarget(self, target):
        if self.m_target != target:
            self.m_target = target
            self.targetChanged.emit()

    def getRadius(self):
        return self.m_radius

    def setRadius(self, radius):
        if not QtCore.qFuzzyCompare(self.m_radius, radius):
            self.m_radius = radius
            self.updateMatrix()
            self.radiusChanged.emit()

    def getAngle(self):
        return self.m_angle

    def setAngle(self, angle):
        if not QtCore.qFuzzyCompare(angle, self.m_angle):
            self.m_angle = angle
            self.updateMatrix()
            self.angleChanged.emit()

    def updateMatrix(self):
        self.m_matrix.setToIdentity()
        self.m_matrix.rotate(self.m_angle, QVector3D(0, 1, 0))
        self.m_matrix.translate(self.m_radius, 0, 0)
        self.m_target.setMatrix(self.m_matrix)

    # QSignal
    targetChanged = pyqtSignal()
    radiusChanged = pyqtSignal()
    angleChanged = pyqtSignal()

    # Qt properties
    target = pyqtProperty(QTransform, fget=getTarget, fset=setTarget)
    radius = pyqtProperty(float, fget=getRadius, fset=setRadius)
    angle = pyqtProperty(float, fget=getAngle, fset=setAngle)


def createScene():
    # root
    rootEntity = QEntity()
    material = QPhongMaterial(rootEntity)

    # torus
    torusEntity = QEntity(rootEntity)
    torusMesh = QTorusMesh()
    torusMesh.setRadius(5)
    torusMesh.setMinorRadius(1)
    torusMesh.setRings(100)
    torusMesh.setSlices(20)

    torusTransform = QTransform()
    torusTransform.setScale3D(QVector3D(1.5, 1.0, 0.5))
    torusTransform.setRotation(QQuaternion.fromAxisAndAngle(QVector3D(1, 0, 0), 45))

    torusEntity.addComponent(torusMesh)
    torusEntity.addComponent(torusTransform)
    torusEntity.addComponent(material)

    # sphere
    sphereEntity = QEntity(rootEntity)
    sphereMesh = QSphereMesh()
    sphereMesh.setRadius(3)

    sphereTransform = QTransform()
    controller = OrbitTransformController(sphereTransform)
    controller.setTarget(sphereTransform)
    controller.setRadius(20)

    sphereRotateTransformAnimation = QPropertyAnimation(sphereTransform)
    sphereRotateTransformAnimation.setTargetObject(controller)
    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

# container = QWidget.createWindowContainer(view)
# container.show()

app = QApplication(sys.argv)
view = Qt3DWindow()

scene = createScene()

# camera
camera = view.camera()
camera.lens().setPerspectiveProjection(45.0, 16.0/9.0, 0.1, 1000)
camera.setPosition(QVector3D(0, 0, 40))
camera.setViewCenter(QVector3D(0, 0, 0))

# for camera control
camController = QOrbitCameraController(scene)
camController.setLinearSpeed( 50.0 )
camController.setLookSpeed( 180.0 )
camController.setCamera(camera)

view.setRootEntity(scene)
view.show()

sys.exit(app.exec_())

with the following environment:

export QSG_INFO=1
export QT_QPA_EGLFS_DEBUG=1
export QT_LOGGING_RULES=qt.qpa.*=true
QT_QPA_PLATFORM=webgl:port=8998 python ./test.py

Unfortunately, I tried to access 8998 with chrome and firefox, and never managed to see something different from a loading icone.

Here are the logs on server side:

qt.qpa.webgl: WebGL QPA Plugin created qt.qpa.input.methods.serialize: QIBusEngineDesc::fromDBusArgument() "(sa{sv}ssssssssussssssss)" qt.qpa.input.methods: socketWatcher.addPath "/home/user/.config/ibus/bus/57acbc52de7a41f6bcba53d2d3273731-unix-1" qt.qpa.webgl.httpserver: Listening in port 8998 qt.qpa.webgl: New offscreen surface 0x7ffd22b01a70 qt.qpa.webgl: 0x7ffd22b01a60 qt.qpa.webgl.context: Creating context 1 qt.qpa.webgl.context: 0x5565618246a0 qt.qpa.webgl: 0x7ff8080053b0 qt.qpa.webgl.context: Creating context 2 qt.qpa.webgl: 0x7ff808005730 qt.qpa.webgl.context: Creating context 3 qt.qpa.webgl: Creating platform window for: 0x556561810910 qt.qpa.webgl: New offscreen surface 0x556561879f70 qt.qpa.webgl.window: Destroying -1 qt.qpa.webgl.httpserver: ::1 requested: / qt.qpa.webgl.httpserver: ::1 requested: /webqt.js qt.qpa.webgl.websocketserver: Sending connect to  QWebSocket(0x7ff80c00a490) QMap(("debug", QVariant(bool, false))("loadingScreen", QVariant(QByteArray, ""))("mouseTracking", QVariant(QByteArray, ""))("supportedFunctions", QVariant(QStringList, ("activeTexture", "attachShader", "bindAttribLocation", "bindBuffer", "bindFramebuffer", "bindRenderbuffer", "bindTexture", "blendColor", "blendEquation", "blendEquationSeparate", "blendFunc", "blendFuncSeparate", "bufferData", "bufferSubData", "checkFramebufferStatus", "clear", "clearColor", "clearDepthf", "clearStencil", "colorMask", "compileShader", "compressedTexImage2D", "compressedTexSubImage2D", "copyTexImage2D", "copyTexSubImage2D", "createProgram", "createShader", "cullFace", "deleteBuffers", "deleteFramebuffers", "deleteProgram", "deleteRenderbuffers", "deleteShader", "deleteTextures", "depthFunc", "depthMask", "depthRangef", "detachShader", "disableVertexAttribArray", "drawArrays", "drawElements", "enableVertexAttribArray", "finish", "flush", "framebufferRenderbuffer", "framebufferTexture2D", "frontFace", "genBuffers", "genFramebuffers", "genRenderbuffers", "genTextures", "generateMipmap", "getActiveAttrib", "getActiveUniform", "getAttachedShaders", "getAttribLocation", "getString", "getIntegerv", "getBooleanv", "enable", "disable", "getBufferParameteriv", "getError", "getParameter", "getFramebufferAttachmentParameteriv", "getProgramInfoLog", "getProgramiv", "getRenderbufferParameteriv", "getShaderInfoLog", "getShaderPrecisionFormat", "getShaderSource", "getShaderiv", "getTexParameterfv", "getTexParameteriv", "getUniformLocation", "getUniformfv", "getUniformiv", "getVertexAttribPointerv", "getVertexAttribfv", "getVertexAttribiv", "hint", "isBuffer", "isEnabled", "isFramebuffer", "isProgram", "isRenderbuffer", "isShader", "isTexture", "lineWidth", "linkProgram", "pixelStorei", "polygonOffset", "readPixels", "releaseShaderCompiler", "renderbufferStorage", "sampleCoverage", "scissor", "shaderBinary", "shaderSource", "stencilFunc", "stencilFuncSeparate", "stencilMask", "stencilMaskSeparate", "stencilOp", "stencilOpSeparate", "texImage2D", "texParameterf", "texParameterfv", "texParameteri", "texParameteriv", "texSubImage2D", "uniform1f", "uniform1fv", "uniform1i", "uniform1iv", "uniform2f", "uniform2fv", "uniform2i", "uniform2iv", "uniform3f", "uniform3fv", "uniform3i", "uniform3iv", "uniform4f", "uniform4fv", "uniform4i", "uniform4iv", "uniformMatrix2fv", "uniformMatrix3fv", "uniformMatrix4fv", "useProgram", "validateProgram", "vertexAttrib1f", "vertexAttrib1fv", "vertexAttrib2f", "vertexAttrib2fv", "vertexAttrib3f", "vertexAttrib3fv", "vertexAttrib4f", "vertexAttrib4fv", "vertexAttribPointer", "viewport", "blitFramebufferEXT", "renderbufferStorageMultisampleEXT", "getTexLevelParameteriv", "makeCurrent", "swapBuffers")))("sysinfo", QVariant(QVariantMap, QMap(("buildAbi", QVariant(QString, "x86_64-little_endian-lp64"))("buildCpuArchitecture", QVariant(QString, "x86_64"))("currentCpuArchitecture", QVariant(QString, "x86_64"))("kernelType", QVariant(QString, "linux"))("machineHostName", QVariant(QString, "supercomputer"))("prettyProductName", QVariant(QString, "Ubuntu
20.04.2 LTS"))("productType", QVariant(QString, "ubuntu"))("productVersion", QVariant(QString, "20.04")))))) qt.qpa.webgl: 0x7ff80c00a490, Size: 1848x912. Physical Size:
490.755838x242.191193 qt.qpa.webgl.httpserver: ::1 requested: /favicon.png qt.qpa.webgl: Connecting first client in the queue (0x7ff80c00a490) qt.qpa.webgl: Creating platform window for: 0x556561810910 qt.qpa.webgl.window: Window 1 created qt.qpa.webgl: Created platform window 0x5565618b7890 for: 0x556561810910 qt.qpa.webgl.websocketserver: Sending create_canvas to  QWebSocket(0x7ff80c00a490) QMap(("height", QVariant(int, 912))("title", QVariant(QString, "test.py"))("width", QVariant(int, 1848))("winId", QVariant(qulonglong, 1))("x", QVariant(int, 0))("y", QVariant(int, 0))) qt.qpa.webgl.context: 0x5565618b7890 qt.qpa.webgl.websocketserver: Sending gl_command makeCurrent to 0x7ff80c00a490 with 4 parameters qt.qpa.webgl.websocketserver: Sending gl_command glGetIntegerv to 0x7ff80c00a490 with 1 parameters qt.qpa.webgl: gl_response message received QJsonObject({"id":1,"type":"gl_response","value":32}) qt.qpa.webgl.websocketserver: Sending gl_command glGetIntegerv to 0x7ff80c00a490 with 1 parameters qt.qpa.webgl: gl_response message received QJsonObject({"id":2,"type":"gl_response","value":null})

On client side, some js logs:

VM20 webqt.js:919 Calling: gl.getIntegerv [36664] 0: 36664 length: 1 proto: Array(0) VM20 webqt.js:921 WebGL: INVALID_ENUM: getParameter: invalid parameter name

WebGL warning: getParameter: pname: Invalid enum value <enum 0x8f38>

It looks like the above warning is linked to the value sent not being correct with respect to this set of definitions (example for opengl): https://www.khronos.org/registry/OpenGL-Refpages/es3/html/glGet.xhtml

or as part of webgl: https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Constants#standard_webgl_1_constants https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Constants#additional_constants_defined_webgl_2 https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Constants#constants_defined_in_webgl_extensions

However I don't see 8F38 (=36664) anywhere there, I suppose there is an issue there.

A first getIntegerv succeed, as the pname used is "gl.MAX_TEXTURE_IMAGE_UNITS (34930)" but the property 36664 does not correspond to a valid pname, so I guess there is a protocol version mismatch somewhere

But I am not sure if this is the biggest issue

In the end, I only see a green loading sign that cycles forever, and not the actual 3d webgl rendering I was expecting. Any idea ?

Edit: I tried to check what was happening on the client side. Basically, javascript is stuck on the following function from webqt.js

window.onload = function ()

Edit2: I checked and validated support for webgl2 for my webbrowser on https://get.webgl.org/webgl2/

Tobbey
  • 469
  • 1
  • 4
  • 18

0 Answers0