WavefrontMesh QML Type
WavefrontMesh 提供基于 Wavefront .obj 文件的网格。更多
Import Statement: | import Qt.labs.wavefrontmesh 1.9 |
属性
- lastError : enumeration
- projectionPlaneV : vector3d
- projectionPlaneW : vector3d
- source : url
详细说明
WavefrontMesh 从 Wavefront .obj 文件中读取几何体,并以此生成二维geometry 。如果 .obj 文件包含一个三维形状,它将被正投影到一个平面上。如果已定义,则由projectionPlaneV 和projectionPlaneW 给出。否则,将使用数据中遇到的第一个面来确定投影平面。
如果文件中包含纹理坐标,也将使用这些坐标。否则,将使用对象的顶点进行归一化处理。
可以在ShaderEffect 中使用网格来定义着色几何体。几何体在使用前将进行归一化处理,因此输入对象的位置和比例不会对结果产生影响。
注意: 某些 Wavefront 输出程序会在输出前更改源场景的坐标系。这可能会在 Qt 应用投影时造成意想不到的结果。如果视觉结果与预期不符,请尝试检查导出参数和编辑器工具的文档,看看是否存在这种情况。
例如,下面的示例采用了包含标准环的 .obj 文件,并将自动生成的纹理坐标可视化。
import QtQuick 2.\1 import Qt.labs.wavefrontmesh 1.\1 ShaderEffect { width: 200 height: 200 mesh: WavefrontMesh { source: "torus.obj" projectionPlaneV: Qt.vector3d(0, 1, 0) projectionPlaneW: Qt.vector3d(1, 0, 0) } vertexShader: " uniform highp mat4 qt_Matrix; attribute highp vec4 qt_Vertex; attribute highp vec2 qt_MultiTexCoord0; varying highp vec2 coord; void main() { coord = qt_MultiTexCoord0; gl_Position = qt_Matrix * qt_Vertex; }" fragmentShader: " varying highp vec2 coord; uniform lowp float qt_Opacity; void main() { gl_FragColor = vec4(coord.x, coord.y, 0.0, 1.0); }" } |
注意: 由于输入的是三维环面,我们需要定义投影面。如果使用二维形状作为输入,则无需这样做。在这种情况下,由于输入的方向,我们使用 XY 平面。
属性文档
lastError : enumeration |
此属性包含解析源代码或创建网格时发生的最后一次错误(如果有)。
- WavefrontMesh.NoError 未发生错误。
- WavefrontMesh.InvalidSourceError 源文件未被识别为有效的 .obj 文件。
- WavefrontMesh.UnsupportedFaceShapeError 源文件中的面是不支持的类型。WavefrontMesh 只支持三角形和凸四边形。
- WavefrontMesh.UnsupportedIndexSizeError 源形状太大。只支持 16 位索引。
- WavefrontMesh.FileNotFoundError 找不到源文件。
- WavefrontMesh.MissingPositionAttributeError 着色器中缺少 "qt_Vertex "属性。
- WavefrontMesh.MissingTextureCoordinateAttributeError 着色器中的纹理坐标属性命名错误。请使用 "qt_MultiTexCoord0"。
- WavefrontMesh.MissingPositionAndTextureCoordinateAttributesError 着色器中缺少 "qt_Vertex "和 "qt_MultiTexCoord0 "属性。
- WavefrontMesh.TooManyAttributesError 着色器期望的属性过多(最多两个:位置'qt_Vertex'和纹理坐标'qt_MultiTexCoord0')。
- WavefrontMesh.InvalidPlaneDefinitionError 平面中的 V 和 W 向量不能为空,也不能相互平行。
projectionPlaneV : vector3d |
由于 Wavefront .obj 格式描述的是三维空间中的对象,因此必须先将坐标投影到二维空间,然后才能在Qt Quick 中显示。
在WavefrontMesh 中,这将通过正投影到一个适当的平面来实现。
projectionPlaneV 是三维空间平面上的两个向量之一。如果此向量或projectionPlaneW 设置为 (0,0,0)(默认值),则将根据数据集中第一个遇到的面来检测平面。
注意: projectionPlaneV 和projectionPlaneW 不能是平行矢量。
projectionPlaneW : vector3d |
由于 Wavefront .obj 格式描述的是三维空间中的物体,因此必须先将坐标投影到二维空间,然后才能在Qt Quick 中显示。
在WavefrontMesh 中,这将通过正投影到一个适当的平面来完成。
projectionPlaneW 是三维空间平面上的两个向量之一。如果此向量或projectionPlaneV 设置为 (0,0,0)(默认值),则将根据数据集中第一个遇到的面来检测平面。
注意: projectionPlaneV 和 projectionPlaneW 不能是平行向量。
source : url |
此属性包含源文件的 URL。必须是本地文件或 qrc 文件。源文件将作为 Wavefront .obj 文件读取,几何图形将被更新。
© 2025 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.