2

Hey The meshviewer shows a default color which I know how to change as you can see below. But how can i change that color into the rgb data I get from my 3D camera using a Intel RealSense Camera? Does anyone have experience with this. I was looking in to Qt3D.Render but I can't figure it out.

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

Output Meshviewer

JKac
  • 76
  • 8
  • Maybe I don't get your question, but don't you need texture mapping in order to solve that? Otherwise setting color is per 3d object. https://doc.qt.io/qt-6/qml-qtquick3d-texture.html – iam_peter Oct 07 '22 at 12:34
  • does `ambient: Qt.rgba(1, 0, 0, 1)` work? – seleciii44 Oct 07 '22 at 12:34
  • @seleciii44 it does work isn't it the same with the Hex number, but basically in rgb. I try to use the RGB data the camera makes – JKac Oct 07 '22 at 13:17
  • @iam_peter isn't texture mapping putting a picture on the mesh. Is that same as giving each vector the rgb values? – JKac Oct 07 '22 at 13:20
  • Setting the color per vertex is a matter of setting up the VBO properly. The material is per 3d object, but not per vertex. Have a look at that SO question https://stackoverflow.com/questions/59324366/how-to-color-each-triangle-differently-using-vbo – iam_peter Oct 07 '22 at 13:31
  • @JKac by rgb data you mean a whole image? I thought you you were try to set only one pixel from that data. – seleciii44 Oct 07 '22 at 13:42
  • @seleciii44 Yeah thet intel realsense camera, is a 3d camera which gives 2 streams depth stream and a rgb stream. With that information i can make a 3D mesh. But the only problem I dont know how to impelement that RGB stream in Qt/QML which should be possible – JKac Oct 08 '22 at 16:19

1 Answers1

1

I've created an example project for you based on the Qt Quick 3D - Custom Geometry Example. It shows how to set a color per vertex using a vertex buffer. It uses QQuick3DGeometry to create a custom geometry that can be used in QML. The important part is to understand how to create the vertex buffer consisting of a position (x, y, z) and color (r, g, b, a). After setting the data the vertex buffer needs to be configured using the addAttribute() function. The documentation can be found here.

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);
}
iam_peter
  • 3,205
  • 1
  • 19
  • 31
  • Thanks alot, with this program you have written that you can decide what color you want. But i don't want to do that I would like to use the RGB Data I get from my Intel RealSense D415 camera, is that possible? I've done quite alot of research but I can't figure it out yet – JKac Oct 11 '22 at 09:57
  • I don't know how the data looks like. I don't own such a camera. I suspect that it outputs some kind of height maps and color textures. Can you provide sample data? – iam_peter Oct 11 '22 at 10:03
  • it creates a ply file which we import in the qml gui. Only for some reason it doesn't show the color. Here's a link how a ply file look like: http://paulbourke.net/dataformats/ply/ – JKac Oct 11 '22 at 10:19
  • You can use the cube rgb example below as reference. I want to show that on a GUI with the color if that's possible. – JKac Oct 11 '22 at 10:26
  • You can export a point cloud with colors from the Intel RealSense Viewer https://www.andreasjakl.com/capturing-3d-point-cloud-intel-realsense-converting-mesh-meshlab/ – iam_peter Oct 11 '22 at 10:34
  • Yes I know that but QML/Qt for some reason cant show the RGB data it shows one plain color. – JKac Oct 11 '22 at 10:51
  • This is why I want to get my hands on a sample ply to test it myself. – iam_peter Oct 11 '22 at 12:30
  • https://stackoverflow.com/questions/51786536/qml-load-and-display-ply-mesh-with-color-attributes – iam_peter Oct 11 '22 at 12:39
  • I came across that to thats 4 years ago so i thought maybe theres implementation still can't figure it out yet. Also if you want a sample ply you can use this link: http://paulbourke.net/dataformats/ply/ Down below under "Another Example" can you see a ply file which is a 3d cube with color, when you copy that file change the extension to ply(also remove the comments to the right). When you open it in MeshLab you can see the cube with color for test purposes – JKac Oct 11 '22 at 15:24
  • did it work out with the sample ply – JKac Oct 14 '22 at 12:42
  • The assimp integrated into QtQuick isn't capable of loading ply with vertex colors. The only option I see is to use my demo and write a custom loader based on libassimp. libassimp can load ply, but the conversion to a VBO and setting up the attribute information needs to be done extra. I didn't have time yet to write a demo application, but this would be also limited in its capabilities. You could write it yourself depending on what you actually want to support in terms of ply featuers. – iam_peter Oct 14 '22 at 13:12