在运行时更改和更新几何网格
Change and update geometry mesh at runtime
这个 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/
这是我在搜索 Google 的 qt3d mesh update
关键字时通过关注 this link 发现的。
以上测试使用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);
// ...
这个 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/
这是我在搜索 Google 的 qt3d mesh update
关键字时通过关注 this link 发现的。
以上测试使用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);
// ...