qt - 在运行时更改和更新几何网格

标签 qt qt3d

这个question and answer ,2015 年 10 月,意味着可以更改 Qt3D 网格并更新它:

问题

I want to use Qt3d in a situation that involves dynamic runtime changes of geometric data on the application side.

What is the best way to dynamically change a mesh for an entity?

I'd rather do all this on the C++ side, but QMesh doesn't seem to provide an API for changing the mesh data.

I looked at some other examples of making a custom QAbstractMesh class and QAbstractMeshFunctor. It looks like I could possibly make a custom mesh type to do what I need but I have a question. If I keep a reference to the QMeshDataPtr that I make from the functor, can I simply modify the mesh data whenever I want and the entities that reference it will update automatically?

回答

The API for this has changed a little in 5.6. The geometric data is now contained in one or more QBuffer objects and is referenced by one or more QAttributes that describe the data layout in the buffers. The QAttributes are rendered by adding them to a QGeometryRenderer component.

You can either update the above objects on the main thread and call update() or as before you can also use a functor to have the backend generate the dynamic data.

现在,我的问题是关于调用update()。到底引用了 Qt3D API 的哪一部分?

最佳答案

我的 Linux 机器上的 Qt 安装目录中有一个可用的测试:

/home/{user}/Qt5.12.6/5.12.6/Src/qt3d/tests/manual/custom-mesh-update-data-cpp/

我通过关注 this link 发现的在 Google 中搜索 qt3d mesh update 关键字时。


以上测试使用Qt3DRender::QBuffer API更新网格数据:

void QBuffer::updateData(int offset, const QByteArray &bytes)

Updates the data by replacing it with bytes at offset.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

代码如下所示:

Qt3DRender::QBuffer *vertexDataBuffer;

// ...

QByteArray updateData;

// ...

vertexDataBuffer->updateData(pos,updateData);

// ...

关于qt - 在运行时更改和更新几何网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59819708/

相关文章:

c++ - 将 QMultiSampleAntiAliasing 添加到 QForwardRenderer

c++ - Qt3D 中的 QPaintedTextureImage (Qt 5.8)

qml - 带有 QML 的 FbxGeometryLoader

ios - 如何从命令行使用 Qt 5.2 和 qmake 构建 ios 可执行文件?

qt - QString 删除最后一个字符

c++ - Qt3D QAbstractTextureImage 像素化

qt - QML 加载并显示具有颜色属性的 .ply 网格

c++ - 部署后 QT 缺少 dll

qt - 为什么我的线宽在具有相同 QPen 宽度的 QGraphicsScene 中看起来不同?

c++ - Qt vtable错误