QML 加载并显示具有颜色属性的 .ply 网格 [英] QML load and display .ply mesh with color attributes

查看:16
本文介绍了QML 加载并显示具有颜色属性的 .ply 网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 QML 从斯坦福 PLY 文件加载一个带有每个顶点颜色信息的简单立方体.

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

我的实体如下所示:

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]
}

我也试过用默认的 Qt 材质替换材质属性来解决这个问题:property Material 材质点:PerVertexColorMaterial {}.不幸的是,场景中没有可见的逐顶点颜色.

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.

是否有任何推荐的方法可以在 QML 中导入带有顶点颜色数据的 PLY 文件?(我想如果用 C++ 编写逻辑并为此创建专门的 QML 实体,则可以实现这一点,但该功能应该已经可用).

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).

推荐答案

在 Qt3D 中加载 PLY 不包括您已经注意到的颜色.恐怕目前与 Qt3D 课程相当.

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

您可以:

构建并加载QtAssimp Sceneparser 插件,它支持 PLY 中的颜色属性,或者:

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

用 C++ 编写您自己的 Qt3D 几何加载器.当需要在每个顶点加载带有额外数据的自定义 OBJ 模型时,我做了类似的事情.加载器代码使用起来非常简单,您只需修改它以读取额外数据,您可以修改 Qt3D 本身中的代码,或者创建一个插件并将其加载到您的应用程序中以使其工作.

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.

注意:创建专门的 QML 实体没有必要.加载器会以 QMesh 的形式读取你的文件.

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

这篇关于QML 加载并显示具有颜色属性的 .ply 网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆