问题
I wanted to set QCullFace
to FrontAndBack
and that is why I wrote this:
from PySide2.Qt3DRender import Qt3DRender
cull_face = Qt3DRender.QCullFace()
cull_face.setMode(Qt3DRender.QCullFace.FrontAndBack)
render_pass = Qt3DRender.QRenderPass()
render_pass.addRenderState(cull_face)
The code above should set CullFace globally. But it does not. What did I do wrong?
回答1:
I assume that the python binding does not change how Qt works in C++.
So you probably have a Qt3DWindow
somewhere (unless you render to an offscreen or your own surface). If you want your cull face to be active, you have to retrieve the QRenderSettings
from the window by calling renderSettings()
. The render settings hold the active framegraph, i.e. if you want any render states or anything else that is related to the framegraph to be active, it has to be a child of the node that the render settings hold as active framegraph. You can get and set the active framegraph on the render settings by calling activeFramegraph()
or setActiveFramegraph(QFramegraphNode*)
.
Is there a reason why you use QRenderPass
? Because if yes, you have to create a QRenderPassFilter
, in order to set it as the active framegraph on the render settings (QRenderPass
does not inherit QFramegraphNode
). This way you can filter out certain objects from the render pass.
But since you want the cull face to be active globally I'd suggest that you use a QRenderStateSet
and add the QCullFace
there. You can then set the render state set as the active framegraph on the render settings of the 3D window.
来源:https://stackoverflow.com/questions/49942635/set-cullface-to-front-and-back-in-qt3d-in-python-via-pyside2