The WavefrontMesh provides a mesh based on a Wavefront .obj file. 更多...
import 语句: | import Qt.labs.wavefrontmesh 1.15 |
Since: | Qt 5.12 |
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.
注意: 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); }" } |
注意: 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.
lastError : enumeration |
This property holds the last error, if any, that occurred when parsing the source or building the mesh.
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.
注意: 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.
注意: 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.