ProceduralMesh QML Type | Qt Quick 3D | Qt 6.10.3
Description: Allows creation of Geometry from QML.

- Qt 6.10
- Qt Quick 3D
- QML Types
- QtQuick3D.Helpers
- ProceduralMesh
- Qt Quick 3D | Commercial or GPLv3

# ProceduralMesh QML Type

Allows creation of Geometry from QML. More...

Import Statement: | `import QtQuick3D.Helpers`
Since: | Qt 6.6
Inherits: | Geometry

- List of all members, including inherited members

## Properties

- binormals : List<QVector3D>
- colors : List<QVector4D>
- indexes : List<int>
- joints : List<QVector4D>
- normals : List<QVector3D>
- positions : List<QVector3D>
- primitiveMode : enumeration
- subsets : List<ProceduralMeshSubset>
- tangents : List<QVector3D>
- uv0s : List<QVector2D>
- uv1s : List<QVector2D>
- weights : List<QVector4D>

## Detailed Description

ProceduralMesh is a helper type that allows creation of Geometry instances from QML. The Geometry component is Abstract, and is usually created from C++.

     component TorusMesh : ProceduralMesh {
         property real rings: 50
         property real segments: 50
         property real radius: 100.0
         property real tubeRadius: 10.0
         property var meshArrays: generateTorus(rings, segments, radius, tubeRadius)
         positions: meshArrays.verts
         normals: meshArrays.normals
         uv0s: meshArrays.uvs
         indexes: meshArrays.indices

         function generateTorus(rings: real, segments: real, radius: real, tubeRadius: real) {
             let verts = []
             let normals = []
             let uvs = []
             let indices = []

             for (let i = 0; i <= rings; ++i) {
                 for (let j = 0; j <= segments; ++j) {
                     let u = i / rings * Math.PI * 2;
                     let v = j / segments * Math.PI * 2;

                     let centerX = radius * Math.cos(u);
                     let centerZ = radius * Math.sin(u);

                     let posX = centerX + tubeRadius * Math.cos(v) * Math.cos(u);
                     let posY = tubeRadius * Math.sin(v);
                     let posZ = centerZ + tubeRadius * Math.cos(v) * Math.sin(u);

                     verts.push(Qt.vector3d(posX, posY, posZ));

                     let normal = Qt.vector3d(posX - centerX, posY, posZ - centerZ).normalized();
                     normals.push(normal);

                     uvs.push(Qt.vector2d(i / rings, j / segments));
                 }
             }

             for (let i = 0; i < rings; ++i) {
                 for (let j = 0; j < segments; ++j) {
                     let a = (segments + 1) * i + j;
                     let b = (segments + 1) * (i + 1) + j;
                     let c = (segments + 1) * (i + 1) + j + 1;
                     let d = (segments + 1) * i + j + 1;

                     // Generate two triangles for each quad in the mesh
                     // Adjust order to be counter-clockwise
                     indices.push(a, d, b);
                     indices.push(b, d, c);
                 }
             }
             return { verts: verts, normals: normals, uvs: uvs, indices: indices }
         }
     }

The above code defines a component TorusMesh that can be used as Geometry for use with a Model component. When the ring, segments, radius or tubeRadius properties are modified the geometry will be updated.

The ProceduralMesh component is not as flexible nor as performant as creating Geometry in C++, but makes up for it in convenience and simplicity. The properties are fixed attribute lists that when filled will automatically generate the necessary buffers.

## Property Documentation

binormals : List<QVector3D>

Holds the binormals attribute list.

colors : List<QVector4D>

This property defines a list of vertex color values.

indexes : List<int>

This property defines a list of indexes into the attribute lists. If this list remains empty the vertex buffer values will be used directly.

joints : List<QVector4D>

This property defines a list of joint indices for skinning.

normals : List<QVector3D>

Holds the normals attribute list.

positions : List<QVector3D>

The positions attribute list. If this list remains empty nothing no geometry will be generated.

primitiveMode : enumeration `[default: ProceduralMesh.Triangles]`

This property defines the primitive mode to use when rendering the geometry.

Constant | Description
--- | ---
`ProceduralMesh.Points` | The points primitive mode is used.
`ProceduralMesh.LineStrip` | The line strip primitive mode is used.
`ProceduralMesh.Lines` | The lines primitive mode is used.
`ProceduralMesh.TriangleStrip` | The triangles strip primitive mode is used.
`ProceduralMesh.TriangleFan` | The triangle fan primitive mode is used.
`ProceduralMesh.Triangles` | The triangles primitive mode is used.

Note: Not all modes are supported on all rendering backends.

subsets : List<ProceduralMeshSubset>

This property defines a list of subsets to split the geometry data into. Each subset can have it's own material. The order of this array corresponds to the materials list of Model when using this geometry.

This property is optional and when empty results in a single subset.

Note: Any subset that specifies values outside of the range of available vertex/index values will lead to that subset being ignored.

tangents : List<QVector3D>

Holds the tangents attribute list.

uv0s : List<QVector2D>

This property defines a list of uv coordinates for the first uv channel (uv0)

uv1s : List<QVector2D>

This property defines a list of uv coordinates for the second uv channel (uv1)

weights : List<QVector4D>

This property defines a list of joint weights for skinning.