QML load and display .ply mesh with color attributes

萝らか妹 提交于 2020-08-10 05:00:07

问题


I am trying to load a simple cube with per-vertex color information from a Stanford PLY file using QML.

My entity looks like this:

Entity
{
    id: circle

    property Material materialPoint: Material {
        effect: Effect {
            techniques: Technique {
                renderPasses: RenderPass {
                    shaderProgram: ShaderProgram {
                        vertexShaderCode: loadSource("qrc:/imports/org/aid/shared/geometry/shaders/point.vert")
                        fragmentShaderCode: loadSource("qrc:/imports/org/aid/shared/geometry/shaders/point.frag")
                    }
                }
            }
        }
        parameters: Parameter { name: "pointSize"; value: 2 }
    }

    property alias translation: circleTransform.translation
    property alias rotation : circleTransform.rotationZ


    Mesh
    {
        id: circleMesh
        source: "qrc:/resources/models/rg.ply"
    }

    Transform
    {
        id: circleTransform
        scale : 1
    }


    components:
        [materialPoint, circleTransform, circleMesh]
}

I have also tried replacing the material property with the default Qt material purposely created to solve this problem: property Material materialPoint: PerVertexColorMaterial {}. Unfortunately, there are no per-vertex colors visible in the scene.

Is there any recommended way of importing a PLY file with vertex color data in QML? (I suppose it is possible to achieve this if one writes the logic in C++ and creates a specialized QML entity for doing so, but the functionality should be available already).


回答1:


Loading PLY in Qt3D doesn't include color as you've noticed. Par for the course for Qt3D at the moment, I'm afraid.

You can either:

build and load the Qt Assimp Sceneparser plugin which does support color attributes in PLY, or:

Write your own Qt3D geometry loader in C++. I have done similar when needing to load a custom OBJ model with extra data in each vertex. The loader code is pretty straightforward to work with, you need only modify it to read the extra data, and you can either modify the code in Qt3D itself, or create a plugin and load it in your application for this to work.

Note: it is not necessary to create a specialized QML entity. The loader will read your file in as QMesh.



来源:https://stackoverflow.com/questions/51786536/qml-load-and-display-ply-mesh-with-color-attributes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!