2

This question and answer, in Oct 2015, implies it is possible to change Qt3D mesh and update it:

Question

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?

Answer

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.

Now, my question is about calling update(). Exactly what section of Qt3D API is referred to?

Megidd
  • 7,089
  • 6
  • 65
  • 142

1 Answers1

2

There is a test available at Qt installation directory on my Linux machine:

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

which I discovered by following this link when searching Google for qt3d mesh update keywords.


The above test is using Qt3DRender::QBuffer API to update mesh data:

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.

Code looks like this:

Qt3DRender::QBuffer *vertexDataBuffer;

// ...

QByteArray updateData;

// ...

vertexDataBuffer->updateData(pos,updateData);

// ...
Community
  • 1
  • 1
Megidd
  • 7,089
  • 6
  • 65
  • 142
  • I have this problem and I can't understand how should work with Buffer. how you estimate the value needed for buffer? It is difficult for me to understand its logic . – Parisa.H.R Jun 26 '21 at 11:16
  • @Parisa.H.R Did you take a look at the provided test link? – Megidd Jun 26 '21 at 12:09
  • if we have a geometry that has dynamic QVector3D vertexes . for example, a LineStrip that gets its vertexes from mouse, how should update this geometry? – Parisa.H.R Jun 27 '21 at 06:52
  • 1
    @Parisa.H.R You might want to update by [API](https://doc.qt.io/qt-5/qt3drender-qbuffer.html#updateData) whenever the QVector3D changes. Maybe by a signal-slot connection. – Megidd Jun 27 '21 at 08:30