- Qt 6.7
- Qt Quick
- QML Types
- Qt.labs.wavefrontmesh
- WavefrontMesh
- Qt 6.7.1 Reference Documentation

# WavefrontMesh QML Type

The WavefrontMesh provides a mesh based on a Wavefront .obj file. More...

Import Statement: | import Qt.labs.wavefrontmesh 1.7

- List of all members, including inherited members

## Properties

- lastError : enumeration
- projectionPlaneV : vector3d
- projectionPlaneW : vector3d
- source : url

## Detailed Description

WavefrontMesh reads the geometry from a Wavefront .obj file and generates a two-dimensional geometry from this. If the .obj file contains a three-dimensional shape, it will be orthographically projected, onto a plane. If defined, this is given by projectionPlaneV and projectionPlaneW. Otherwise, the first face encountered in the data will be used to determine the projection plane.

If the file contains texture coordinates, these will also be used. Otherwise, the vertexes of the object will be normalized and used.

The mesh can be used in a ShaderEffect to define the shaded geometry. The geometry will be normalized before use, so the position and scale of the input objects have no impact on the result.

Note: Some Wavefront exporters will change the source scene's coordinate system before exporting it. This can cause unexpected results when Qt applies the projection. If the visual results are not as you expect, try checking the export parameters and the documentation of the editor tool to see if this is the case.

For instance, the following example takes an .obj file containing a standard torus and visualizes the automatically generated texture coordinates.

     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);
                 }"

     }

Note: Since the input is a 3D torus, we need to define the projection plane. This would not be necessary when using a 2D shape as input. We use the XY plane in this case, because of the orientation of the input.

## Property Documentation

lastError : enumeration

This property holds the last error, if any, that occurred when parsing the source or building the mesh.

- WavefrontMesh.NoError No error has occurred.
- WavefrontMesh.InvalidSourceError The source was not recognized as a valid .obj file.
- WavefrontMesh.UnsupportedFaceShapeError The faces in the source is of an unsupported type. WavefrontMesh only supports triangles and convex quads.
- WavefrontMesh.UnsupportedIndexSizeError The source shape is too large. Only 16 bit indexes are supported.
- WavefrontMesh.FileNotFoundError The source file was not found.
- WavefrontMesh.MissingPositionAttributeError The 'qt_Vertex' attribute is missing from the shaders.
- WavefrontMesh.MissingTextureCoordinateAttributeError The texture coordinate attribute in the shaders is wrongly named. Use 'qt_MultiTexCoord0'.
- WavefrontMesh.MissingPositionAndTextureCoordinateAttributesError Both the 'qt_Vertex' and 'qt_MultiTexCoord0' attributes are missing from the shaders.
- WavefrontMesh.TooManyAttributesError The shaders expect too many attributes (maximum is two: Position, 'qt_Vertex', and texture coordinate, 'qt_MultiTexCoord0').
- WavefrontMesh.InvalidPlaneDefinitionError The V and W vectors in the plane cannot be null, nor parallel to each other.

projectionPlaneV : vector3d

Since the Wavefront .obj format describes an object in 3D space, the coordinates have to be projected into 2D before they can be displayed in Qt Quick.

This will be done in WavefrontMesh by an orthographic projection onto an appropriate plane.

The projectionPlaneV is one of two vectors in the plane in 3D space. If either this, or projectionPlaneW is set to (0, 0, 0) (the default), then the plane will be detected based on the first encountered face in the data set.

Note: projectionPlaneV and projectionPlaneW cannot be parallel vectors.

projectionPlaneW : vector3d

Since the Wavefront .obj format describes an object in 3D space, the coordinates have to be projected into 2D before they can be displayed in Qt Quick.

This will be done in WavefrontMesh by an orthographic projection onto an appropriate plane.

The projectionPlaneW is one of two vectors in the plane in 3D space. If either this, or projectionPlaneV is set to (0, 0, 0) (the default), then the plane will be detected based on the first encountered face in the data set.

Note: projectionPlaneV and projectionPlaneW cannot be parallel vectors.

source : url

This property holds the URL of the source. This must be either a local file or in qrc. The source will be read as a Wavefront .obj file and the geometry will be updated.