How to Optimize Memory Usage When Displaying Custom 3D Models in Quick3D?
-
wrote on 17 Jul 2024, 02:36 last edited by
I am using view3D in Quick3D to display a customized 3D model. I read an STL file in C++ and store it in my custom MyObj data structure, then convert it to a QQuick3DGeometry data structure to link and display it with QML. This results in having two sets of data (MyObj and QQuick3DGeometry). If QQuick3DGeometry has already sent the data to the GPU via setVertexData and setIndexData, can I delete the QQuick3DGeometry data after view3D displays it? If not, the software will occupy memory for both sets of data. Do you have any other suggestions? Should I use Qt3D instead? Thank you.
-
I am using view3D in Quick3D to display a customized 3D model. I read an STL file in C++ and store it in my custom MyObj data structure, then convert it to a QQuick3DGeometry data structure to link and display it with QML. This results in having two sets of data (MyObj and QQuick3DGeometry). If QQuick3DGeometry has already sent the data to the GPU via setVertexData and setIndexData, can I delete the QQuick3DGeometry data after view3D displays it? If not, the software will occupy memory for both sets of data. Do you have any other suggestions? Should I use Qt3D instead? Thank you.
wrote on 20 Jul 2024, 04:18 last edited by@aaron-tian said in How to Optimize Memory Usage When Displaying Custom 3D Models in Quick3D?:
If QQuick3DGeometry has already sent the data to the GPU via setVertexData and setIndexData, can I delete the QQuick3DGeometry data after view3D displays it?
Yes you can, you can delete data right after setVertexData() and setIndexData(), no need to wait for view3D to display it. Maybe you can also delete data from MyObj after convert it to QQuick3DGeometry, depending on your use case, and unless you need to use it else where ?
-
@aaron-tian said in How to Optimize Memory Usage When Displaying Custom 3D Models in Quick3D?:
If QQuick3DGeometry has already sent the data to the GPU via setVertexData and setIndexData, can I delete the QQuick3DGeometry data after view3D displays it?
Yes you can, you can delete data right after setVertexData() and setIndexData(), no need to wait for view3D to display it. Maybe you can also delete data from MyObj after convert it to QQuick3DGeometry, depending on your use case, and unless you need to use it else where ?
wrote on 24 Jul 2024, 15:22 last edited byI have deleted the Vertex and Index data, but after emitting geodataChanged and updating the display, the memory usage continues to increase. If I delete the geo data, the memory doesn't increase, but the display doesn't update either.
Create GEO
void GeometryData::setMesh(const Mesh &mesh) { // _mesh = mesh; clear(); int stride = sizeof(Vertex); QByteArray vertexData(mesh.vertices.count() * stride, Qt::Initialization::Uninitialized); memcpy(vertexData.data(), mesh.vertices.constData(), vertexData.size()); setVertexData(vertexData); QByteArray indexData(mesh.indices.count()*sizeof(quint32), Qt::Initialization::Uninitialized); memcpy(indexData.data(), mesh.indices.constData(), indexData.size()); setIndexData(indexData); setStride(stride); setBounds(mesh.boundsMin, mesh.boundsMax); setPrimitiveType(QQuick3DGeometry::PrimitiveType::Triangles); addAttribute(Attribute::PositionSemantic, 0, Attribute::ComponentType::F32Type); addAttribute(Attribute::NormalSemantic, sizeof(QVector3D), Attribute::ComponentType::F32Type); addAttribute(Attribute::IndexSemantic, 0, Attribute::ComponentType::U32Type); vertexData.clear(); indexData.clear(); }
QML
Model { id: modeltest scale: Qt.vector3d(10, 10, 10) geometry: viewmanager.geodata materials: [ DefaultMaterial { diffuseColor: "blue" } ] }
1/3