# ProceduralMesh QML Type

Allows creation of Geometry from QML. More...

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

## 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

Holds the binormals attribute list.

 colors : List

This property defines a list of vertex color values.

 indexes : List

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

This property defines a list of joint indices for skinning.

 normals : List

Holds the normals attribute list.

 positions : List

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.

ConstantDescription
`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

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

Holds the tangents attribute list.

 uv0s : List

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

 uv1s : List

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

 weights : List

This property defines a list of joint weights for skinning.

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.