【问题标题】:Why the other side of the plane is not being shown?为什么没有显示飞机的另一面?
【发布时间】:2020-05-05 12:03:09
【问题描述】:

我在 Blender 中创建了一个平面并将其添加为 QCustom3DItemQt chart

但是在旋转图表时我发现​​我看不到飞机的另一边,为什么?

#include <QtWidgets>
#include <Q3DBars>
#include <QCustom3DItem>

using namespace QtDataVisualization;

MainWidget::MainWidget(QWidget *parent) : QWidget(parent)
{
    resize(800,600);
    auto vLayout = new QVBoxLayout(this);
    auto graph = new Q3DBars;
    auto widget = QWidget::createWindowContainer(graph);
    vLayout->addWidget(widget);

    auto bar = new QCustom3DItem;
    bar->setMeshFile(":mesh/planey.obj");
    bar->setScaling(QVector3D(.1f,.8f,.1f));

    graph->addCustomItem(bar);
}

# Blender v2.81 (sub 16) OBJ File: ''
# www.blender.org
o Plane
v 0.000000 2.000000 1.000000
v -0.000000 0.000000 1.000000
v 0.000000 2.000000 -1.000000
v -0.000000 0.000000 -1.000000
vt 1.000000 0.000000
vt 0.000000 1.000000
vt 0.000000 0.000000
vt 1.000000 1.000000
vn 1.0000 -0.0000 0.0000
s off
f 2/1/1 3/2/1 1/3/1
f 2/1/1 4/4/1 3/2/1

【问题讨论】:

    标签: qt opengl 3d qt5 blender


    【解决方案1】:

    因为发生了面部剔除

    渲染器设置为仅显示法线朝向相机方向的三角形。朝向相反方向的三角形被视为“背面”,因此出于性能原因而被跳过。

    不幸的是,这在 Qt 中似乎是硬编码的,如类 abstract3drenderer.cpp 中所示:

    void Abstract3DRenderer::initializeOpenGL()
    {
        m_context = QOpenGLContext::currentContext();
        // Set OpenGL features
        glEnable(GL_DEPTH_TEST);
        glDepthFunc(GL_LESS);
        glEnable(GL_CULL_FACE);
        glCullFace(GL_BACK);
    
        // ...
    

    我不确定你是否可以覆盖它,因为 3D 渲染器是私有的。

    一种可能的解决方法是提供一个具有两个平面的 .obj 文件,一个具有面向一个方向的法线,另一个具有旋转 180° 的法线。虽然这可能会产生其他问题,例如 Z-fighting...

    【讨论】:

      猜你喜欢
      • 2012-07-03
      • 1970-01-01
      • 2014-03-30
      • 2017-04-09
      • 2014-11-30
      • 2020-06-13
      • 1970-01-01
      • 2021-06-01
      • 1970-01-01
      相关资源
      最近更新 更多