簡體   English   中英

使用Qt3D在QML中實現RGB

[英]Implementing RGB in QML using Qt3D

嘿,網格查看器顯示默認顏色,我知道如何更改,如下所示。 但是我怎樣才能將該顏色更改為我使用英特爾實感攝像頭從我的 3D 攝像頭獲得的 rgb 數據? 有人對這個有經驗么。 我正在查看 Qt3D.Render 但我無法弄清楚。

PhongMaterial {
    id: reconstructedMeshMaterial
    ambient: "#F6C6AF"
}

Output 網格查看器

我已經根據Qt 快速 3D - 自定義幾何示例為您創建了一個示例項目 它展示了如何使用頂點緩沖區設置每個頂點的顏色。 它使用QQuick3DGeometry創建一個可以在QML中使用的自定義幾何體。重要的部分是了解如何創建由一個position(x,y,z)和顏色(r,g,b,a)組成的頂點緩沖區。 設置數據后,需要使用addAttribute() function 配置頂點緩沖區。可以在此處找到文檔。

void ExampleTriangleGeometry::updateData()
{
    clear();

    // PositionSemantic: The attribute is a position. 3 components: x, y, and z
    // ColorSemantic: The attribute is a vertex color vector. 4 components: r, g, b, and a
    int stride = 7 * sizeof(float);

    // 3 vertices in total for the triangle
    QByteArray vertexData(3 * stride, Qt::Initialization::Uninitialized);
    float *p = reinterpret_cast<float *>(vertexData.data());

    // a triangle, front face = counter-clockwise
    *p++ = -1.0f; // x
    *p++ = -1.0f; // y
    *p++ = 0.0f;  // z

    *p++ = 1.0f; // r
    *p++ = 0.0f; // g
    *p++ = 0.0f; // b
    *p++ = 1.0f; // a

    *p++ = 1.0f;
    *p++ = -1.0f;
    *p++ = 0.0f;

    *p++ = 0.0f;
    *p++ = 1.0f;
    *p++ = 0.0f;
    *p++ = 1.0f;

    *p++ = 0.0f;
    *p++ = 1.0f;
    *p++ = 0.0f;

    *p++ = 0.0f;
    *p++ = 0.0f;
    *p++ = 1.0f;
    *p++ = 1.0f;

    setVertexData(vertexData);
    setStride(stride);
    setBounds(QVector3D(-1.0f, -1.0f, 0.0f), QVector3D(+1.0f, +1.0f, 0.0f));

    setPrimitiveType(QQuick3DGeometry::PrimitiveType::Triangles);

    addAttribute(QQuick3DGeometry::Attribute::PositionSemantic,
                 0,
                 QQuick3DGeometry::Attribute::F32Type);

    addAttribute(QQuick3DGeometry::Attribute::ColorSemantic,
                 3 * sizeof(float),
                 QQuick3DGeometry::Attribute::F32Type);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM