Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QWavefrontMesh Class Reference

#include <qwavefrontmesh_p.h>

+ Inheritance diagram for QWavefrontMesh:
+ Collaboration diagram for QWavefrontMesh:

Public Types

enum  Error {
  NoError , InvalidSourceError , UnsupportedFaceShapeError , UnsupportedIndexSizeError ,
  FileNotFoundError , NoAttributesError , MissingPositionAttributeError , MissingTextureCoordinateAttributeError ,
  MissingPositionAndTextureCoordinateAttributesError , TooManyAttributesError , InvalidPlaneDefinitionError
}
 

Signals

void sourceChanged ()
 
void lastErrorChanged ()
 
void projectionPlaneVChanged ()
 
void projectionPlaneWChanged ()
 
- Signals inherited from QQuickShaderEffectMesh
void geometryChanged ()
 
- Signals inherited from QObject
void destroyed (QObject *=nullptr)
 This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified, and cannot be blocked.
 
void objectNameChanged (const QString &objectName, QPrivateSignal)
 This signal is emitted after the object's name has been changed.
 

Public Member Functions

 QWavefrontMesh (QObject *parent=nullptr)
 \qmlmodule Qt.labs.wavefrontmesh 1.
 
 ~QWavefrontMesh () override
 
QUrl source () const
 \qmlproperty url WavefrontMesh::source
 
void setSource (const QUrl &url)
 
Error lastError () const
 \qmlproperty enumeration WavefrontMesh::lastError
 
void setLastError (Error lastError)
 
bool validateAttributes (const QList< QByteArray > &attributes, int *posIndex) override
 
QSGGeometryupdateGeometry (QSGGeometry *geometry, int attrCount, int posIndex, const QRectF &srcRect, const QRectF &rect) override
 
QString log () const override
 
QVector3D projectionPlaneV () const
 
void setProjectionPlaneV (const QVector3D &projectionPlaneV)
 \qmlproperty vector3d WavefrontMesh::projectionPlaneV
 
QVector3D projectionPlaneW () const
 
void setProjectionPlaneW (const QVector3D &projectionPlaneW)
 \qmlproperty vector3d WavefrontMesh::projectionPlaneW
 
- Public Member Functions inherited from QQuickShaderEffectMesh
 QQuickShaderEffectMesh (QObject *parent=nullptr)
 
virtual bool validateAttributes (const QVector< QByteArray > &attributes, int *posIndex)=0
 
- Public Member Functions inherited from QObject
Q_INVOKABLE QObject (QObject *parent=nullptr)
 Constructs an object with parent object parent.
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects.
 
virtual bool event (QEvent *event)
 This virtual function receives events to an object and should return true if the event e was recognized and processed.
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 Filters events if this object has been installed as an event filter for the watched object.
 
QString objectName () const
 
Q_WEAK_OVERLOAD void setObjectName (const QString &name)
 Sets the object's name to name.
 
void setObjectName (QAnyStringView name)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QBindable< QStringbindableObjectName ()
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false.
 
bool isWindowType () const
 Returns true if the object is a window; otherwise returns false.
 
bool isQuickItemType () const
 Returns true if the object is a QQuickItem; otherwise returns false.
 
bool signalsBlocked () const noexcept
 Returns true if signals are blocked; otherwise returns false.
 
bool blockSignals (bool b) noexcept
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it).
 
QThreadthread () const
 Returns the thread in which the object lives.
 
bool moveToThread (QThread *thread QT6_DECL_NEW_OVERLOAD_TAIL)
 Changes the thread affinity for this object and its children and returns true on success.
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 This is an overloaded function that will start a timer of type timerType and a timeout of interval milliseconds.
 
int startTimer (std::chrono::nanoseconds time, Qt::TimerType timerType=Qt::CoarseTimer)
 
void killTimer (int id)
 Kills the timer with timer identifier, id.
 
void killTimer (Qt::TimerId id)
 
template<typename T >
findChild (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 Returns the child of this object that can be cast into type T and that is called name, or \nullptr if there is no such object.
 
template<typename T >
QList< T > findChildren (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects.
 
template<typename T >
findChild (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename T >
QList< T > findChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
const QObjectListchildren () const
 Returns a list of child objects.
 
void setParent (QObject *parent)
 Makes the object a child of parent.
 
void installEventFilter (QObject *filterObj)
 Installs an event filter filterObj on this object.
 
void removeEventFilter (QObject *obj)
 Removes an event filter object obj from this object.
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const
 
bool disconnect (const QObject *receiver, const char *member=nullptr) const
 
void dumpObjectTree () const
 Dumps a tree of children to the debug output.
 
void dumpObjectInfo () const
 Dumps information about signal connections, etc.
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value.
 
bool setProperty (const char *name, QVariant &&value)
 
QVariant property (const char *name) const
 Returns the value of the object's name property.
 
QList< QByteArraydynamicPropertyNames () const
 
QBindingStoragebindingStorage ()
 
const QBindingStoragebindingStorage () const
 
QObjectparent () const
 Returns a pointer to the parent object.
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false.
 

Protected Slots

void readData ()
 

Properties

QUrl source
 
Error lastError
 
QVector3D projectionPlaneV
 
QVector3D projectionPlaneW
 
- Properties inherited from QObject
QString objectName
 the name of this object
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 \threadsafe
 
- Static Public Member Functions inherited from QObject
static QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 \threadsafe
 
static QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::ContextTypeForFunctor< Func2 >::ContextType *context, Func2 &&slot, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 &&slot)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 \threadsafe
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static bool disconnect (const QMetaObject::Connection &)
 Disconnect a connection.
 
template<typename Func1 , typename Func2 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot)
 
template<typename Func1 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero)
 
- Protected Member Functions inherited from QQuickShaderEffectMesh
 QQuickShaderEffectMesh (QObjectPrivate &dd, QObject *parent=nullptr)
 
- Protected Member Functions inherited from QObject
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns \nullptr.
 
int senderSignalIndex () const
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal.
 
bool isSignalConnected (const QMetaMethod &signal) const
 
virtual void timerEvent (QTimerEvent *event)
 This event handler can be reimplemented in a subclass to receive timer events for the object.
 
virtual void childEvent (QChildEvent *event)
 This event handler can be reimplemented in a subclass to receive child events.
 
virtual void customEvent (QEvent *event)
 This event handler can be reimplemented in a subclass to receive custom events.
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
 QObject (QObjectPrivate &dd, QObject *parent=nullptr)
 
- Protected Attributes inherited from QObject
QScopedPointer< QObjectDatad_ptr
 

Detailed Description

Definition at line 28 of file qwavefrontmesh_p.h.

Member Enumeration Documentation

◆ Error

Enumerator
NoError 
InvalidSourceError 
UnsupportedFaceShapeError 
UnsupportedIndexSizeError 
FileNotFoundError 
NoAttributesError 
MissingPositionAttributeError 
MissingTextureCoordinateAttributeError 
MissingPositionAndTextureCoordinateAttributesError 
TooManyAttributesError 
InvalidPlaneDefinitionError 

Definition at line 39 of file qwavefrontmesh_p.h.

Constructor & Destructor Documentation

◆ QWavefrontMesh()

QWavefrontMesh::QWavefrontMesh ( QObject * parent = nullptr)

\qmlmodule Qt.labs.wavefrontmesh 1.

\QtMinorVersion \title Qt Labs WavefrontMesh QML Types

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

To use this module, import the module with the following line:

\qml import Qt.labs.wavefrontmesh \endqml

\qmltype WavefrontMesh
\inqmlmodule Qt.labs.wavefrontmesh

! \instantiates QWavefrontMesh

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

Since
5.12

WavefrontMesh reads the geometry from a Wavefront .obj file and generates a two-dimensional \l{QSGGeometry}{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 \l projectionPlaneV and \l 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.

\table \row

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

} \endqml \endtable

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.

Definition at line 133 of file qwavefrontmesh.cpp.

References QObject::connect(), QQuickShaderEffectMesh::geometryChanged(), projectionPlaneVChanged(), projectionPlaneWChanged(), readData(), and sourceChanged().

+ Here is the call graph for this function:

◆ ~QWavefrontMesh()

QWavefrontMesh::~QWavefrontMesh ( )
override

Definition at line 141 of file qwavefrontmesh.cpp.

Member Function Documentation

◆ lastError()

QWavefrontMesh::Error QWavefrontMesh::lastError ( ) const

\qmlproperty enumeration WavefrontMesh::lastError

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

\list

  • 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. \endlist

Definition at line 166 of file qwavefrontmesh.cpp.

References d.

◆ lastErrorChanged

void QWavefrontMesh::lastErrorChanged ( )
signal

Referenced by setLastError().

+ Here is the caller graph for this function:

◆ log()

QString QWavefrontMesh::log ( ) const
overridevirtual

◆ projectionPlaneV()

QVector3D QWavefrontMesh::projectionPlaneV ( ) const

Definition at line 623 of file qwavefrontmesh.cpp.

References d.

◆ projectionPlaneVChanged

void QWavefrontMesh::projectionPlaneVChanged ( )
signal

Referenced by QWavefrontMesh(), and setProjectionPlaneV().

+ Here is the caller graph for this function:

◆ projectionPlaneW()

QVector3D QWavefrontMesh::projectionPlaneW ( ) const

Definition at line 655 of file qwavefrontmesh.cpp.

References d.

◆ projectionPlaneWChanged

void QWavefrontMesh::projectionPlaneWChanged ( )
signal

Referenced by QWavefrontMesh(), and setProjectionPlaneW().

+ Here is the caller graph for this function:

◆ readData

void QWavefrontMesh::readData ( )
protectedslot

Definition at line 204 of file qwavefrontmesh.cpp.

References QByteArray::at(), d, emit, file, FileNotFoundError, QQuickShaderEffectMesh::geometryChanged(), InvalidSourceError, ok, QFile::open(), p1, p2, Q_ASSERT, Q_UNLIKELY, qMakePair(), QIODeviceBase::ReadOnly, QString::reserve(), setLastError(), Qt::SkipEmptyParts, QStringView::split(), t2, t3, t4, UnsupportedFaceShapeError, UnsupportedIndexSizeError, and QQmlFile::urlToLocalFileOrQrc().

Referenced by QWavefrontMesh().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setLastError()

void QWavefrontMesh::setLastError ( Error lastError)

Definition at line 172 of file qwavefrontmesh.cpp.

References d, emit, lastError, and lastErrorChanged().

Referenced by readData(), and updateGeometry().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setProjectionPlaneV()

void QWavefrontMesh::setProjectionPlaneV ( const QVector3D & v)

\qmlproperty vector3d WavefrontMesh::projectionPlaneV

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 \l 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 \l projectionPlaneW cannot be parallel vectors.

Definition at line 613 of file qwavefrontmesh.cpp.

References d, emit, and projectionPlaneVChanged().

+ Here is the call graph for this function:

◆ setProjectionPlaneW()

void QWavefrontMesh::setProjectionPlaneW ( const QVector3D & w)

\qmlproperty vector3d WavefrontMesh::projectionPlaneW

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 \l 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
\l projectionPlaneV and projectionPlaneW cannot be parallel vectors.

Definition at line 645 of file qwavefrontmesh.cpp.

References d, emit, and projectionPlaneWChanged().

+ Here is the call graph for this function:

◆ setSource()

void QWavefrontMesh::setSource ( const QUrl & url)

Definition at line 194 of file qwavefrontmesh.cpp.

References d, emit, source, and sourceChanged().

+ Here is the call graph for this function:

◆ source()

QUrl QWavefrontMesh::source ( ) const

\qmlproperty url WavefrontMesh::source

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.

Definition at line 188 of file qwavefrontmesh.cpp.

References d.

◆ sourceChanged

void QWavefrontMesh::sourceChanged ( )
signal

Referenced by QWavefrontMesh(), and setSource().

+ Here is the caller graph for this function:

◆ updateGeometry()

◆ validateAttributes()

bool QWavefrontMesh::validateAttributes ( const QList< QByteArray > & attributes,
int * posIndex )
override

Definition at line 438 of file qwavefrontmesh.cpp.

References d, MissingPositionAndTextureCoordinateAttributesError, MissingPositionAttributeError, MissingTextureCoordinateAttributeError, NoAttributesError, qtPositionAttributeName(), qtTexCoordAttributeName(), and TooManyAttributesError.

+ Here is the call graph for this function:

Property Documentation

◆ lastError

Error QWavefrontMesh::lastError
read

Definition at line 32 of file qwavefrontmesh_p.h.

Referenced by setLastError().

◆ projectionPlaneV

QVector3D QWavefrontMesh::projectionPlaneV
readwrite

Definition at line 33 of file qwavefrontmesh_p.h.

◆ projectionPlaneW

QVector3D QWavefrontMesh::projectionPlaneW
readwrite

Definition at line 34 of file qwavefrontmesh_p.h.

◆ source

QUrl QWavefrontMesh::source
readwrite

Definition at line 31 of file qwavefrontmesh_p.h.

Referenced by setSource().


The documentation for this class was generated from the following files: