Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to Optimize Memory Usage When Displaying Custom 3D Models in Quick3D?

How to Optimize Memory Usage When Displaying Custom 3D Models in Quick3D?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 258 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aaron tian
    wrote on 17 Jul 2024, 02:36 last edited by
    #1

    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.

    J 1 Reply Last reply 20 Jul 2024, 04:18
    0
    • A aaron tian
      17 Jul 2024, 02:36

      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.

      J Offline
      J Offline
      johngod
      wrote on 20 Jul 2024, 04:18 last edited by
      #2

      @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 ?

      A 1 Reply Last reply 24 Jul 2024, 15:22
      0
      • J johngod
        20 Jul 2024, 04:18

        @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 ?

        A Offline
        A Offline
        aaron tian
        wrote on 24 Jul 2024, 15:22 last edited by
        #3

        @johngod

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

        2024-07-24_23-00-58.png

        Delete GeoData
        2024-07-24_23-05-22.png

        1 Reply Last reply
        0

        1/3

        17 Jul 2024, 02:36

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved