问题描述
我想将 QCullFace
设置为 FrontAndBack
,这就是我写这个的原因:
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)
上面的代码应该全局设置CullFace.但事实并非如此.我做错了什么?
The code above should set CullFace globally. But it does not. What did I do wrong?
推荐答案
我假设 python 绑定不会改变 Qt 在 C++ 中的工作方式.
I assume that the python binding does not change how Qt works in C++.
所以你可能在某处有一个 Qt3DWindow
(除非你渲染到屏幕外或你自己的表面).如果您希望您的剔除面处于活动状态,您必须通过调用 renderSettings()
从窗口中检索 QRenderSettings
.渲染设置保存活动帧图,即如果您希望任何渲染状态或与帧图相关的任何其他内容处于活动状态,则它必须是渲染设置作为活动帧图保存的节点的子节点.您可以通过调用 activeFramegraph()
或 setActiveFramegraph(QFramegraphNode*)
来获取和设置渲染设置上的活动帧图.
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*)
.
您使用 QRenderPass
有什么原因吗?因为如果是的话,你必须创建一个QRenderPassFilter
,以便在渲染设置上将其设置为活动的framegraph(QRenderPass
不继承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.
但是由于您希望剔除面在全局范围内处于活动状态,我建议您使用 QRenderStateSet
并在那里添加 QCullFace
.然后,您可以在 3D 窗口的渲染设置中将渲染状态设置为活动帧图.
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.
这篇关于通过 PySide2 在 Python 中的 Qt3D 中将 CullFace 设置为正面和背面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!