ProceduralMesh QML Type
支持通过 QML 创建几何体。更多...
| Import Statement: | import QtQuick3D.Helpers |
| Since: | Qt 6.6 |
| Inherits: |
属性
- 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>
详细说明
ProceduralMesh 是一种辅助类型,允许从 QML 创建 Geometry 实例。Geometry 组件是抽象的,通常由 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 }
}
}上述代码定义了一个名为 TorusMesh 的组件,该组件可作为 Geometry 用于与 Model 组件配合使用。当 ring、segments、radius 或 tubeRadius 属性发生更改时,几何体将随之更新。
ProceduralMesh 组件虽然不如在 C++ 中创建 Geometry 那样灵活或高效,但其便捷性和简单性弥补了这一不足。这些属性是固定的属性列表,填充后会自动生成必要的缓冲区。
属性文档
binormals : List<QVector3D>
保存双法线属性列表。
colors : List<QVector4D>
此属性定义了一组顶点颜色值的列表。
indexes : List<int>
该属性定义了属性列表的索引列表。如果该列表为空,则将直接使用顶点缓冲区的值。
joints : List<QVector4D>
此属性定义了用于蒙皮的关节索引列表。
normals : List<QVector3D>
保存法线属性列表。
positions : List<QVector3D>
“positions”属性列表。如果该列表为空,则不会生成任何几何体。
primitiveMode : enumeration [default: ProceduralMesh.Triangles]
此属性定义了渲染几何体时要使用的原始模式。
| 常量 | 描述 |
|---|---|
ProceduralMesh.Points | 使用“点”基元模式。 |
ProceduralMesh.LineStrip | 使用“线带”基元模式。 |
ProceduralMesh.Lines | 使用“线”原始模式。 |
ProceduralMesh.TriangleStrip | 使用“三角形条”基元模式。 |
ProceduralMesh.TriangleFan | 使用“扇形三角形”基元模式。 |
ProceduralMesh.Triangles | 使用“三角形”基元模式。 注意:并非 所有渲染后端都支持所有模式。 |
subsets : List<ProceduralMeshSubset>
该属性定义了一个子集列表,用于将几何体数据拆分为多个子集。每个子集都可以拥有自己的材质。当使用该几何体时,此数组的顺序与“模型”的材质列表相对应。
该属性为可选属性,若为空,则生成单个子集。
注意:任何 指定了超出可用顶点/索引值范围的子集都将被忽略。
tangents : List<QVector3D>
保存切线属性列表。
uv0s : List<QVector2D>
此属性定义了第一个 UV 通道(uv0)的 UV 坐标列表
uv1s : List<QVector2D>
此属性定义了第二个UV通道(uv1)的UV坐标列表
weights : List<QVector4D>
此属性定义了用于皮肤绑定的关节权重列表。
© 2026 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.