diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/core-components/qcamera.cpp | 91 | ||||
-rw-r--r-- | src/core/core-components/qcamera.h | 14 | ||||
-rw-r--r-- | src/core/core-components/qcamera_p.h | 16 | ||||
-rw-r--r-- | src/core/transforms/qtransform.cpp | 72 | ||||
-rw-r--r-- | src/core/transforms/qtransform.h | 16 | ||||
-rw-r--r-- | src/core/transforms/qtransform_p.h | 14 | ||||
-rw-r--r-- | src/plugins/sceneparsers/assimp/assimpparser.cpp | 13 | ||||
-rw-r--r-- | src/plugins/sceneparsers/gltf/gltfparser.cpp | 37 | ||||
-rw-r--r-- | src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp | 5 | ||||
-rw-r--r-- | src/quick3d/imports/render/defaults/qml/SkyboxEntity.qml | 3 | ||||
-rw-r--r-- | src/quick3d/quick3d/items/items.pri | 2 | ||||
-rw-r--r-- | src/quick3d/quick3d/items/quick3dtransform.cpp | 105 | ||||
-rw-r--r-- | src/quick3d/quick3d/items/quick3dtransform_p.h | 87 | ||||
-rw-r--r-- | src/render/defaults/qskyboxentity.cpp | 5 | ||||
-rw-r--r-- | src/render/defaults/qskyboxentity_p.h | 1 | ||||
-rw-r--r-- | src/render/frontend/qboundingvolumedebug.cpp | 17 |
16 files changed, 100 insertions, 398 deletions
diff --git a/src/core/core-components/qcamera.cpp b/src/core/core-components/qcamera.cpp index 8812235ac..bfbe90d26 100644 --- a/src/core/core-components/qcamera.cpp +++ b/src/core/core-components/qcamera.cpp @@ -47,9 +47,13 @@ namespace Qt3DCore { */ QCameraPrivate::QCameraPrivate() : QEntityPrivate() + , m_position(0.0f, 0.0f, 0.0f) + , m_viewCenter(0.0f, 0.0f, -100.0f) + , m_upVector(0.0f, 1.0f, 0.0f) + , m_cameraToCenter(m_viewCenter - m_position) + , m_viewMatrixDirty(false) , m_lens(new QCameraLens()) , m_transform(new QTransform()) - , m_lookAt(new QLookAtTransform()) { } @@ -61,8 +65,8 @@ QCameraPrivate::QCameraPrivate() \since 5.5 */ -QCamera::QCamera(QNode *parent) : - QEntity(*new QCameraPrivate, parent) +QCamera::QCamera(QNode *parent) + : QEntity(*new QCameraPrivate, parent) { QObject::connect(d_func()->m_lens, SIGNAL(projectionTypeChanged()), this, SIGNAL(projectionMatrixChanged())); QObject::connect(d_func()->m_lens, SIGNAL(nearPlaneChanged()), this, SIGNAL(nearPlaneChanged())); @@ -74,11 +78,7 @@ QCamera::QCamera(QNode *parent) : QObject::connect(d_func()->m_lens, SIGNAL(bottomChanged()), this, SIGNAL(bottomChanged())); QObject::connect(d_func()->m_lens, SIGNAL(topChanged()), this, SIGNAL(topChanged())); QObject::connect(d_func()->m_lens, SIGNAL(projectionMatrixChanged()), this, SIGNAL(projectionMatrixChanged())); - QObject::connect(d_func()->m_lookAt, SIGNAL(positionChanged()), this, SIGNAL(positionChanged())); - QObject::connect(d_func()->m_lookAt, SIGNAL(upVectorChanged()), this, SIGNAL(upVectorChanged())); - QObject::connect(d_func()->m_lookAt, SIGNAL(viewCenterChanged()), this, SIGNAL(viewCenterChanged())); - QObject::connect(d_func()->m_transform, SIGNAL(matrixChanged()), this, SIGNAL(matrixChanged())); - d_func()->m_transform->addTransform(d_func()->m_lookAt); + QObject::connect(d_func()->m_transform, SIGNAL(matrixChanged()), this, SIGNAL(viewMatrixChanged())); addComponent(d_func()->m_lens); addComponent(d_func()->m_transform); } @@ -102,11 +102,7 @@ QCamera::QCamera(QCameraPrivate &dd, QNode *parent) QObject::connect(d_func()->m_lens, SIGNAL(bottomChanged()), this, SIGNAL(bottomChanged())); QObject::connect(d_func()->m_lens, SIGNAL(topChanged()), this, SIGNAL(topChanged())); QObject::connect(d_func()->m_lens, SIGNAL(projectionMatrixChanged()), this, SIGNAL(projectionMatrixChanged())); - QObject::connect(d_func()->m_lookAt, SIGNAL(positionChanged()), this, SIGNAL(positionChanged())); - QObject::connect(d_func()->m_lookAt, SIGNAL(upVectorChanged()), this, SIGNAL(upVectorChanged())); - QObject::connect(d_func()->m_lookAt, SIGNAL(viewCenterChanged()), this, SIGNAL(viewCenterChanged())); - QObject::connect(d_func()->m_transform, SIGNAL(matrixChanged()), this, SIGNAL(matrixChanged())); - d_func()->m_transform->addTransform(d_func()->m_lookAt); + QObject::connect(d_func()->m_transform, SIGNAL(matrixChanged()), this, SIGNAL(viewMatrixChanged())); addComponent(d_func()->m_lens); addComponent(d_func()->m_transform); } @@ -123,20 +119,13 @@ QTransform *QCamera::transform() const return d->m_transform; } -QLookAtTransform *QCamera::lookAt() const -{ - Q_D(const QCamera); - return d->m_lookAt; -} - -void QCamera::translate( const QVector3D& vLocal, CameraTranslationOption option ) +void QCamera::translate(const QVector3D &vLocal, CameraTranslationOption option) { QVector3D viewVector = viewCenter() - position(); // From "camera" position to view center // Calculate the amount to move by in world coordinates QVector3D vWorld; - if (!qFuzzyIsNull(vLocal.x())) - { + if (!qFuzzyIsNull(vLocal.x())) { // Calculate the vector for the local x axis const QVector3D x = QVector3D::crossProduct(viewVector, upVector()).normalized(); vWorld += vLocal.x() * x; @@ -168,19 +157,19 @@ void QCamera::translate( const QVector3D& vLocal, CameraTranslationOption option setUpVector(QVector3D::crossProduct(x, viewVector).normalized()); } -void QCamera::translateWorld(const QVector3D& vWorld , CameraTranslationOption option ) +void QCamera::translateWorld(const QVector3D &vWorld, CameraTranslationOption option) { // Update the camera position using the calculated world vector setPosition(position() + vWorld); // May be also update the view center coordinates - if ( option == TranslateViewCenter ) + if (option == TranslateViewCenter) setViewCenter(viewCenter() + vWorld); } QQuaternion QCamera::tiltRotation(float angle) const { - const QVector3D viewVector = viewCenter() - position(); + const QVector3D viewVector = viewCenter() - position(); const QVector3D xBasis = QVector3D::crossProduct(upVector(), viewVector.normalized()).normalized(); return QQuaternion::fromAxisAndAngle(xBasis, -angle); } @@ -280,7 +269,6 @@ void QCamera::setProjectionType(QCameraLens::ProjectionType type) \value CameraLens.OrthographicProjection Orthographic projection \value CameraLens.PerspectiveProjection Perspective projection */ - QCameraLens::ProjectionType QCamera::projectionType() const { Q_D(const QCamera); @@ -296,7 +284,6 @@ void QCamera::setNearPlane(float nearPlane) /*! \qmlproperty float Qt3DCore::Camera::nearPlane */ - float QCamera::nearPlane() const { Q_D(const QCamera); @@ -312,7 +299,6 @@ void QCamera::setFarPlane(float farPlane) /*! \qmlproperty float Qt3DCore::Camera::farPlane */ - float QCamera::farPlane() const { Q_D(const QCamera); @@ -328,7 +314,6 @@ void QCamera::setFieldOfView(float fieldOfView) /*! \qmlproperty float Qt3DCore::Camera::fieldOfView */ - float QCamera::fieldOfView() const { Q_D(const QCamera); @@ -344,7 +329,6 @@ void QCamera::setAspectRatio(float aspectRatio) /*! \qmlproperty float Qt3DCore::Camera::aspectRatio */ - float QCamera::aspectRatio() const { Q_D(const QCamera); @@ -360,7 +344,6 @@ void QCamera::setLeft(float left) /*! \qmlproperty float Qt3DCore::Camera::left */ - float QCamera::left() const { Q_D(const QCamera); @@ -376,7 +359,6 @@ void QCamera::setRight(float right) /*! \qmlproperty float Qt3DCore::Camera::right */ - float QCamera::right() const { Q_D(const QCamera); @@ -392,7 +374,6 @@ void QCamera::setBottom(float bottom) /*! \qmlproperty float Qt3DCore::Camera::bottom */ - float QCamera::bottom() const { Q_D(const QCamera); @@ -408,7 +389,6 @@ void QCamera::setTop(float top) /*! \qmlproperty float Qt3DCore::Camera::top */ - float QCamera::top() const { Q_D(const QCamera); @@ -419,7 +399,6 @@ float QCamera::top() const \qmlproperty matrix4x4 Qt3DCore::Camera::projectionMatrix \readonly */ - QMatrix4x4 QCamera::projectionMatrix() const { Q_D(const QCamera); @@ -429,56 +408,74 @@ QMatrix4x4 QCamera::projectionMatrix() const void QCamera::setPosition(const QVector3D &position) { Q_D(QCamera); - d->m_lookAt->setPosition(position); + d->m_position = position; + d->m_cameraToCenter = d->m_viewCenter - position; + d->m_viewMatrixDirty = true; + emit positionChanged(); + emit viewVectorChanged(); + d->updateViewMatrix(); } /*! \qmlproperty vector3d Qt3DCore::Camera::position */ - QVector3D QCamera::position() const { Q_D(const QCamera); - return d->m_lookAt->position(); - + return d->m_position; } void QCamera::setUpVector(const QVector3D &upVector) { Q_D(QCamera); - d->m_lookAt->setUpVector(upVector); + d->m_upVector = upVector; + d->m_viewMatrixDirty = true; + emit upVectorChanged(); + d->updateViewMatrix(); } /*! \qmlproperty vector3d Qt3DCore::Camera::upVector */ - QVector3D QCamera::upVector() const { Q_D(const QCamera); - return d->m_lookAt->upVector(); + return d->m_upVector; } void QCamera::setViewCenter(const QVector3D &viewCenter) { Q_D(QCamera); - d->m_lookAt->setViewCenter(viewCenter); + d->m_viewCenter = viewCenter; + d->m_cameraToCenter = viewCenter - d->m_position; + d->m_viewMatrixDirty = true; + emit viewCenterChanged(); + emit viewVectorChanged(); + d->updateViewMatrix(); } /*! \qmlproperty vector3d Qt3DCore::Camera::viewCenter */ - QVector3D QCamera::viewCenter() const { Q_D(const QCamera); - return d->m_lookAt->viewCenter(); + return d->m_viewCenter; +} + +/*! + \qmlproperty vector3d Qt3DCore::Camera::viewVector +*/ +QVector3D QCamera::viewVector() const +{ + Q_D(const QCamera); + return d->m_cameraToCenter; } /*! - \qmlproperty matrix4x4 Qt3DCore::Camera::matrix + \qmlproperty matrix4x4 Qt3DCore::Camera::viewMatrix */ -QMatrix4x4 QCamera::matrix() const +QMatrix4x4 QCamera::viewMatrix() const { Q_D(const QCamera); return d->m_transform->matrix(); diff --git a/src/core/core-components/qcamera.h b/src/core/core-components/qcamera.h index 305cae930..e44f0778c 100644 --- a/src/core/core-components/qcamera.h +++ b/src/core/core-components/qcamera.h @@ -69,7 +69,8 @@ class QT3DCORESHARED_EXPORT QCamera : public QEntity Q_PROPERTY(QVector3D position READ position WRITE setPosition NOTIFY positionChanged) Q_PROPERTY(QVector3D upVector READ upVector WRITE setUpVector NOTIFY upVectorChanged) Q_PROPERTY(QVector3D viewCenter READ viewCenter WRITE setViewCenter NOTIFY viewCenterChanged) - Q_PROPERTY(QMatrix4x4 matrix READ matrix NOTIFY matrixChanged) + Q_PROPERTY(QVector3D viewVector READ viewVector NOTIFY viewVectorChanged) + Q_PROPERTY(QMatrix4x4 viewMatrix READ viewMatrix NOTIFY viewMatrixChanged) public: explicit QCamera(QNode *parent = 0); @@ -83,7 +84,6 @@ public: QCameraLens *lens() const; QTransform *transform() const; - QLookAtTransform *lookAt() const; QQuaternion tiltRotation(float angle) const; QQuaternion panRotation(float angle) const; @@ -91,10 +91,10 @@ public: QQuaternion rotation(float angle, const QVector3D &axis) const; // Translate relative to camera orientation axes - Q_INVOKABLE void translate(const QVector3D& vLocal, CameraTranslationOption option = TranslateViewCenter ); + Q_INVOKABLE void translate(const QVector3D& vLocal, CameraTranslationOption option = TranslateViewCenter); // Translate relative to world axes - Q_INVOKABLE void translateWorld(const QVector3D& vWorld, CameraTranslationOption option = TranslateViewCenter ); + Q_INVOKABLE void translateWorld(const QVector3D& vWorld, CameraTranslationOption option = TranslateViewCenter); Q_INVOKABLE void tilt(float angle); Q_INVOKABLE void pan(float angle); @@ -147,7 +147,8 @@ public: void setViewCenter(const QVector3D &viewCenter); QVector3D viewCenter() const; - QMatrix4x4 matrix() const; + QVector3D viewVector() const; + QMatrix4x4 viewMatrix() const; Q_SIGNALS: void projectionTypeChanged(); @@ -163,7 +164,8 @@ Q_SIGNALS: void positionChanged(); void upVectorChanged(); void viewCenterChanged(); - void matrixChanged(); + void viewVectorChanged(); + void viewMatrixChanged(); protected: Q_DECLARE_PRIVATE(QCamera) diff --git a/src/core/core-components/qcamera_p.h b/src/core/core-components/qcamera_p.h index 995ec7277..bb73a3f4e 100644 --- a/src/core/core-components/qcamera_p.h +++ b/src/core/core-components/qcamera_p.h @@ -64,9 +64,23 @@ public: Q_DECLARE_PUBLIC(QCamera) + void updateViewMatrix() + { + QMatrix4x4 m; + m.lookAt(m_position, m_viewCenter, m_upVector); + m_transform->setMatrix(m); + } + + QVector3D m_position; + QVector3D m_viewCenter; + QVector3D m_upVector; + + QVector3D m_cameraToCenter; // The vector from the camera position to the view center + bool m_viewMatrixDirty; + + // Components QCameraLens *m_lens; QTransform *m_transform; - QLookAtTransform *m_lookAt; }; } // namespace Qt3DCore diff --git a/src/core/transforms/qtransform.cpp b/src/core/transforms/qtransform.cpp index 0ca9f61de..2e177e3b2 100644 --- a/src/core/transforms/qtransform.cpp +++ b/src/core/transforms/qtransform.cpp @@ -51,56 +51,18 @@ namespace Qt3DCore { */ QTransformPrivate::QTransformPrivate() : QComponentPrivate() - , m_transformsDirty(false) , m_rotation() , m_scale(1.0f, 1.0f, 1.0f) , m_translation() + , m_matrixDirty(false) { } -void QTransformPrivate::_q_transformDestroyed(QObject *obj) -{ - QAbstractTransform *transform = static_cast<QAbstractTransform *>(obj); - if (m_transforms.removeOne(transform)) { - emit q_func()->transformsChanged(); - _q_update(); - } -} - -void QTransformPrivate::_q_update() -{ - if (!m_transformsDirty) - m_transformsDirty = true; - emit q_func()->matrixChanged(); -} - -QMatrix4x4 QTransformPrivate::applyTransforms() const -{ - QMatrix4x4 matrix; - Q_FOREACH (const QAbstractTransform *t, m_transforms) - matrix = t->transformMatrix() * matrix; - return matrix; -} - - QTransform::QTransform(QNode *parent) : QComponent(*new QTransformPrivate, parent) { } -QTransform::QTransform(QList<QAbstractTransform *> transforms, QNode *parent) - : QComponent(*new QTransformPrivate, parent) -{ - Q_FOREACH (QAbstractTransform *t, transforms) - addTransform(t); -} - -QTransform::QTransform(QAbstractTransform *transform, QNode *parent) - : QComponent(*new QTransformPrivate, parent) -{ - addTransform(transform); -} - /*! \internal */ QTransform::QTransform(QTransformPrivate &dd, QNode *parent) : QComponent(dd, parent) @@ -110,9 +72,6 @@ QTransform::QTransform(QTransformPrivate &dd, QNode *parent) QTransform::~QTransform() { QNode::cleanup(); - Q_D(QTransform); - // boost destruction by avoiding _q_update()-s - d->m_transforms.clear(); } void QTransform::copy(const QNode *ref) @@ -127,35 +86,6 @@ void QTransform::copy(const QNode *ref) d_func()->m_translation = transform->translation(); } -QList<QAbstractTransform *> QTransform::transforms() const -{ - Q_D(const QTransform); - return d->m_transforms; -} - -void QTransform::addTransform(QAbstractTransform *transform) -{ - Q_D(QTransform); - if (transform == Q_NULLPTR || d->m_transforms.contains(transform)) - return; - d->m_transforms.append(transform); - QObject::connect(transform, SIGNAL(transformMatrixChanged()), this, SLOT(_q_update())); - QObject::connect(transform, SIGNAL(destroyed(QObject*)), this, SLOT(_q_transformDestroyed(QObject*))); - emit transformsChanged(); - d->_q_update(); -} - -void QTransform::removeTransform(QAbstractTransform *transform) -{ - Q_D(QTransform); - if (!d->m_transforms.removeOne(transform)) - return; - QObject::disconnect(transform, SIGNAL(transformMatrixChanged()), this, SLOT(_q_update())); - QObject::disconnect(transform, SIGNAL(destroyed(QObject*)), this, SLOT(_q_transformDestroyed(QObject*))); - emit transformsChanged(); - d->_q_update(); -} - void QTransform::setMatrix(const QMatrix4x4 &m) { Q_D(QTransform); diff --git a/src/core/transforms/qtransform.h b/src/core/transforms/qtransform.h index 7a08d272e..80d680b7e 100644 --- a/src/core/transforms/qtransform.h +++ b/src/core/transforms/qtransform.h @@ -47,8 +47,6 @@ QT_BEGIN_NAMESPACE namespace Qt3DCore { -class QAbstractTransform; - class QTransformPrivate; class QT3DCORESHARED_EXPORT QTransform : public QComponent { @@ -61,8 +59,6 @@ class QT3DCORESHARED_EXPORT QTransform : public QComponent public: explicit QTransform(QNode *parent = 0); - QTransform(QList<QAbstractTransform *> transforms, QNode *parent = 0); - QTransform(QAbstractTransform *transform, QNode *parent = 0); ~QTransform(); float scale() const; @@ -84,27 +80,19 @@ public: QMatrix4x4 matrix() const; - QList<QAbstractTransform *> transforms() const; - void addTransform(QAbstractTransform *xform); - void removeTransform(QAbstractTransform *xform); - - public Q_SLOTS: void setScale(float scale); void setScale3D(const QVector3D &scale); void setRotation(const QQuaternion &rotation); void setTranslation(const QVector3D &translation); - void setMatrix(const QMatrix4x4 &matrix); Q_SIGNALS: - void matrixChanged(); - void transformsChanged(); - void scaleChanged(); void scale3DChanged(); void rotationChanged(); void translationChanged(); + void matrixChanged(); protected: QTransform(QTransformPrivate &dd, QNode *parent = 0); @@ -113,8 +101,6 @@ protected: private: Q_DECLARE_PRIVATE(QTransform) QT3D_CLONEABLE(QTransform) - Q_PRIVATE_SLOT(d_func(), void _q_transformDestroyed(QObject *obj)) - Q_PRIVATE_SLOT(d_func(), void _q_update()) }; } // namespace Qt3DCore diff --git a/src/core/transforms/qtransform_p.h b/src/core/transforms/qtransform_p.h index 523842d6e..1d98d901e 100644 --- a/src/core/transforms/qtransform_p.h +++ b/src/core/transforms/qtransform_p.h @@ -54,7 +54,6 @@ QT_BEGIN_NAMESPACE namespace Qt3DCore { -class QTransform; class QTransformPrivate : public QComponentPrivate { Q_DECLARE_PUBLIC(QTransform) @@ -62,22 +61,15 @@ class QTransformPrivate : public QComponentPrivate public: QTransformPrivate(); - void _q_transformDestroyed(QObject *obj); - void _q_update(); - QMatrix4x4 applyTransforms() const; - - mutable bool m_transformsDirty; - QList<QAbstractTransform*> m_transforms; - - mutable bool m_matrixDirty; - mutable QMatrix4x4 m_matrix; - // Stored in this order as QQuaternion is bigger than QVector3D // Operations are applied in the order of: // scale, rotation, translation QQuaternion m_rotation; QVector3D m_scale; QVector3D m_translation; + + mutable QMatrix4x4 m_matrix; + mutable bool m_matrixDirty; }; } // namespace Qt3DCore diff --git a/src/plugins/sceneparsers/assimp/assimpparser.cpp b/src/plugins/sceneparsers/assimp/assimpparser.cpp index 4c98e8c1e..6955bfc47 100644 --- a/src/plugins/sceneparsers/assimp/assimpparser.cpp +++ b/src/plugins/sceneparsers/assimp/assimpparser.cpp @@ -415,7 +415,8 @@ Qt3DCore::QEntity *AssimpParser::node(aiNode *node) // Add Transformations const QMatrix4x4 qTransformMatrix = aiMatrix4x4ToQMatrix4x4(node->mTransformation); - Qt3DCore::QTransform *transform = new Qt3DCore::QTransform(new QMatrixTransform(qTransformMatrix)); + Qt3DCore::QTransform *transform = new Qt3DCore::QTransform; + transform->setMatrix(qTransformMatrix); entityNode->addComponent(transform); // Add Camera @@ -724,12 +725,12 @@ void AssimpParser::loadCamera(uint cameraIndex) assimpCamera->mClipPlaneFar); camera->addComponent(lens); + QMatrix4x4 m; + m.lookAt(QVector3D(assimpCamera->mPosition.x, assimpCamera->mPosition.y, assimpCamera->mPosition.z), + QVector3D(assimpCamera->mLookAt.x, assimpCamera->mLookAt.y, assimpCamera->mLookAt.z), + QVector3D(assimpCamera->mUp.x, assimpCamera->mUp.y, assimpCamera->mUp.z)); Qt3DCore::QTransform *transform = new Qt3DCore::QTransform(); - QLookAtTransform *lookAt = new QLookAtTransform(); - lookAt->setPosition(QVector3D(assimpCamera->mPosition.x, assimpCamera->mPosition.y, assimpCamera->mPosition.z)); - lookAt->setViewCenter(QVector3D(assimpCamera->mLookAt.x, assimpCamera->mLookAt.y, assimpCamera->mLookAt.z)); - lookAt->setUpVector(QVector3D(assimpCamera->mUp.x, assimpCamera->mUp.y, assimpCamera->mUp.z)); - transform->addTransform(lookAt); + transform->setMatrix(m); camera->addComponent(transform); m_scene->m_cameras[cameraNode] = camera; diff --git a/src/plugins/sceneparsers/gltf/gltfparser.cpp b/src/plugins/sceneparsers/gltf/gltfparser.cpp index c35a08fb6..be1e08ebb 100644 --- a/src/plugins/sceneparsers/gltf/gltfparser.cpp +++ b/src/plugins/sceneparsers/gltf/gltfparser.cpp @@ -293,15 +293,14 @@ Qt3DCore::QEntity* GLTFParser::node(const QString &id) } // ADD MATRIX TRANSFORM COMPONENT TO ENTITY - if ( trans == Q_NULLPTR) + if (trans == Q_NULLPTR) trans = new Qt3DCore::QTransform; - trans->addTransform(new QMatrixTransform(m)); - + trans->setMatrix(m); } // Rotation quaternion if (jsonObj.contains(KEY_ROTATION)) { - if ( trans == Q_NULLPTR) + if (trans == Q_NULLPTR) trans = new Qt3DCore::QTransform; QJsonArray quaternionValues = jsonObj.value(KEY_ROTATION).toArray(); @@ -309,41 +308,29 @@ Qt3DCore::QEntity* GLTFParser::node(const QString &id) quaternionValues[1].toDouble(), quaternionValues[2].toDouble(), quaternionValues[3].toDouble()); - - QVector3D axis; - float angle; - quaternion.getAxisAndAngle(&axis, &angle); - - Qt3DCore::QRotateTransform *rotateTransform = new Qt3DCore::QRotateTransform; - rotateTransform->setAxis(axis); - rotateTransform->setAngleDeg(angle); - trans->addTransform(rotateTransform); + trans->setRotation(quaternion); } // Translation if (jsonObj.contains(KEY_TRANSLATION)) { - if ( trans == Q_NULLPTR) + if (trans == Q_NULLPTR) trans = new Qt3DCore::QTransform; QJsonArray translationValues = jsonObj.value(KEY_TRANSLATION).toArray(); - Qt3DCore::QTranslateTransform *translateTransform = new Qt3DCore::QTranslateTransform; - translateTransform->setDx(translationValues[0].toDouble()); - translateTransform->setDy(translationValues[1].toDouble()); - translateTransform->setDz(translationValues[2].toDouble()); - trans->addTransform(translateTransform); + trans->setTranslation(QVector3D(translationValues[0].toDouble(), + translationValues[1].toDouble(), + translationValues[2].toDouble())); } // Scale if (jsonObj.contains(KEY_SCALE)) { - if ( trans == Q_NULLPTR) + if (trans == Q_NULLPTR) trans = new Qt3DCore::QTransform; QJsonArray scaleValues = jsonObj.value(KEY_SCALE).toArray(); - Qt3DCore::QScaleTransform *scaleTransform = new Qt3DCore::QScaleTransform; - scaleTransform->setScale3D(QVector3D(scaleValues[0].toDouble(), - scaleValues[1].toDouble(), - scaleValues[2].toDouble())); - trans->addTransform(scaleTransform); + trans->setScale3D(QVector3D(scaleValues[0].toDouble(), + scaleValues[1].toDouble(), + scaleValues[2].toDouble())); } // Add the Transform component diff --git a/src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp b/src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp index ef724b3eb..b2b4245e7 100644 --- a/src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp +++ b/src/quick3d/imports/core/qt3dquick3dcoreplugin.cpp @@ -43,9 +43,9 @@ #include <Qt3DCore/qtranslatetransform.h> #include <Qt3DCore/qrotatetransform.h> #include <Qt3DCore/qabstractattribute.h> +#include <Qt3DCore/qtransform.h> #include <private/quick3dentity_p.h> #include <private/quick3dentityloader_p.h> -#include <private/quick3dtransform_p.h> #include <private/quick3dconfiguration_p.h> #include <private/quick3dnodeinstantiator_p.h> #include <private/qt3dquick_global_p.h> @@ -63,7 +63,8 @@ void Qt3DQuick3DCorePlugin::registerTypes(const char *uri) Qt3DCore::Quick::registerExtendedType<Qt3DCore::QEntity, Qt3DCore::Quick::Quick3DEntity>("QEntity", "Qt3D.Core/Entity", uri, 2, 0, "Entity"); qmlRegisterType<Qt3DCore::Quick::Quick3DEntityLoader>(uri, 2, 0, "EntityLoader"); qmlRegisterType<Qt3DCore::Quick::Quick3DNodeInstantiator>(uri, 2, 0, "NodeInstantiator"); - Qt3DCore::Quick::registerExtendedType<Qt3DCore::QTransform, Qt3DCore::Quick::Quick3DTransform>("QTransform", "Qt3D.Core/Transform", uri, 2, 0, "Transform"); + qmlRegisterType<Qt3DCore::QTransform>(uri, 2, 0, "Transform"); + // Ideally we want to make Node an uncreatable type // We would need qmlRegisterUncreatableExtendedType for that qmlRegisterExtendedUncreatableType<Qt3DCore::QNode, Qt3DCore::Quick::Quick3DNode>(uri, 2, 0, "Node", QStringLiteral("Node is a base class")); diff --git a/src/quick3d/imports/render/defaults/qml/SkyboxEntity.qml b/src/quick3d/imports/render/defaults/qml/SkyboxEntity.qml index bc1afc237..fac8ae8a9 100644 --- a/src/quick3d/imports/render/defaults/qml/SkyboxEntity.qml +++ b/src/quick3d/imports/render/defaults/qml/SkyboxEntity.qml @@ -39,7 +39,7 @@ import Qt3D.Render 2.0 Entity { - property alias cameraPosition: cameraTranslate.translation; + property alias cameraPosition: transform.translation; property string baseName: ""; property string extension: ".png" @@ -80,7 +80,6 @@ Entity { Transform { id: transform - Translate { id: cameraTranslate } } Material { diff --git a/src/quick3d/quick3d/items/items.pri b/src/quick3d/quick3d/items/items.pri index 6891b1e6a..17668085e 100644 --- a/src/quick3d/quick3d/items/items.pri +++ b/src/quick3d/quick3d/items/items.pri @@ -1,6 +1,5 @@ HEADERS += \ $$PWD/quick3dnodeinstantiator_p.h \ - $$PWD/quick3dtransform_p.h \ $$PWD/quick3dconfiguration_p.h \ $$PWD/quick3dentity_p.h \ $$PWD/quick3dentityloader_p_p.h \ @@ -11,7 +10,6 @@ SOURCES += \ $$PWD/quick3dnode.cpp \ $$PWD/quick3dentity.cpp \ $$PWD/quick3dentityloader.cpp \ - $$PWD/quick3dtransform.cpp \ $$PWD/quick3dconfiguration.cpp \ $$PWD/quick3dnodeinstantiator.cpp diff --git a/src/quick3d/quick3d/items/quick3dtransform.cpp b/src/quick3d/quick3d/items/quick3dtransform.cpp deleted file mode 100644 index e708cb04f..000000000 --- a/src/quick3d/quick3d/items/quick3dtransform.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "quick3dtransform_p.h" -#include <Qt3DCore/qabstracttransform.h> - -QT_BEGIN_NAMESPACE - -namespace Qt3DCore { -namespace Quick { - -/*! - \qmltype Transform - \inqmlmodule Qt3D.Core - \since 5.5 -*/ -Quick3DTransform::Quick3DTransform(QObject *parent) - : QObject(parent) -{ - Q_ASSERT(qobject_cast<Qt3DCore::QTransform *>(parent) != Q_NULLPTR); -} - -/*! - \qmlproperty matrix4x4 Qt3DCore::Transform::matrix - \readonly -*/ - -/*! - \qmlproperty list<QAbstractTransform> Qt3DCore::Transform::transforms - \default -*/ -QQmlListProperty<QAbstractTransform> Quick3DTransform::transformList() -{ - return QQmlListProperty<QAbstractTransform>(this, 0, - Quick3DTransform::qmlAppendTransform, - Quick3DTransform::transformCount, - Quick3DTransform::transformAt, - Quick3DTransform::qmlClearTransforms); -} - -void Quick3DTransform::qmlAppendTransform(QQmlListProperty<QAbstractTransform> *list, QAbstractTransform *obj ) -{ - if ( !obj ) - return; - - Quick3DTransform *self = static_cast<Quick3DTransform *>(list->object); - self->parentTransform()->addTransform(obj); -} - -QAbstractTransform* Quick3DTransform::transformAt(QQmlListProperty<QAbstractTransform> *list, int index) -{ - Quick3DTransform *self = static_cast<Quick3DTransform *>(list->object); - return self->parentTransform()->transforms().at(index); -} - -int Quick3DTransform::transformCount(QQmlListProperty<QAbstractTransform> *list) -{ - Quick3DTransform *self = static_cast<Quick3DTransform *>(list->object); - return self->parentTransform()->transforms().count(); -} - -void Quick3DTransform::qmlClearTransforms(QQmlListProperty<QAbstractTransform> *list) -{ - Quick3DTransform *self = static_cast<Quick3DTransform *>(list->object); - Q_FOREACH (QAbstractTransform *trans, self->parentTransform()->transforms()) - self->parentTransform()->removeTransform(trans); -} - -} // namespace Quick -} // namespace Qt3DCore - -QT_END_NAMESPACE diff --git a/src/quick3d/quick3d/items/quick3dtransform_p.h b/src/quick3d/quick3d/items/quick3dtransform_p.h deleted file mode 100644 index 8f1ffe282..000000000 --- a/src/quick3d/quick3d/items/quick3dtransform_p.h +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QT3D_QUICK_QUICK3DTRANSFORM_P_H -#define QT3D_QUICK_QUICK3DTRANSFORM_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <QtCore/QtGlobal> -#include <QQmlListProperty> -#include <Qt3DQuick/private/qt3dquick_global_p.h> -#include <Qt3DCore/qtransform.h> - -QT_BEGIN_NAMESPACE - -namespace Qt3DCore { - -class QTransform; - -namespace Quick { - -class QT3DQUICKSHARED_PRIVATE_EXPORT Quick3DTransform : public QObject -{ - Q_OBJECT - Q_PROPERTY(QQmlListProperty<Qt3DCore::QAbstractTransform> transforms READ transformList) - Q_CLASSINFO("DefaultProperty", "transforms") -public: - explicit Quick3DTransform(QObject *parent = 0); - QQmlListProperty<Qt3DCore::QAbstractTransform> transformList(); - - inline QTransform *parentTransform() const { return qobject_cast<Qt3DCore::QTransform *>(parent()); } - -private: - static void qmlAppendTransform(QQmlListProperty<Qt3DCore::QAbstractTransform> *list, Qt3DCore::QAbstractTransform *bar); - static QAbstractTransform* transformAt(QQmlListProperty<Qt3DCore::QAbstractTransform> *list, int index); - static int transformCount(QQmlListProperty<Qt3DCore::QAbstractTransform> *list); - static void qmlClearTransforms(QQmlListProperty<Qt3DCore::QAbstractTransform> *list); -}; - -} // namespace Quick -} // namespace Qt3DCore - -QT_END_NAMESPACE - -#endif // QT3D_QUICK_QUICK3DTRANSFORM_P_H diff --git a/src/render/defaults/qskyboxentity.cpp b/src/render/defaults/qskyboxentity.cpp index 8c9169f42..7834ec2aa 100644 --- a/src/render/defaults/qskyboxentity.cpp +++ b/src/render/defaults/qskyboxentity.cpp @@ -76,7 +76,6 @@ QSkyboxEntityPrivate::QSkyboxEntityPrivate() , m_gl3RenderPass(new QRenderPass()) , m_mesh(new QCuboidMesh()) , m_transform(new Qt3DCore::QTransform()) - , m_translate(new QTranslateTransform()) , m_textureParameter(new QParameter(QStringLiteral("skyboxTexture"), m_skyboxTexture)) , m_posXImage(new QTextureImage()) , m_posYImage(new QTextureImage()) @@ -140,8 +139,6 @@ void QSkyboxEntityPrivate::init() m_material->setEffect(m_effect); m_material->addParameter(m_textureParameter); - m_transform->addTransform(m_translate); - m_mesh->setXYMeshResolution(QSize(2, 2)); m_mesh->setXZMeshResolution(QSize(2, 2)); m_mesh->setYZMeshResolution(QSize(2, 2)); @@ -268,7 +265,7 @@ void QSkyboxEntity::setCameraPosition(const QVector3D &cameraPosition) Q_D(QSkyboxEntity); if (cameraPosition != d->m_position) { d->m_position = cameraPosition; - d->m_translate->setTranslation(d->m_position); + d->m_transform->setTranslation(d->m_position); emit cameraPositionChanged(); } } diff --git a/src/render/defaults/qskyboxentity_p.h b/src/render/defaults/qskyboxentity_p.h index f81bdc21d..b1ee4a506 100644 --- a/src/render/defaults/qskyboxentity_p.h +++ b/src/render/defaults/qskyboxentity_p.h @@ -93,7 +93,6 @@ class QSkyboxEntityPrivate : public Qt3DCore::QEntityPrivate QRenderPass *m_gl3RenderPass; QCuboidMesh *m_mesh; Qt3DCore::QTransform *m_transform; - Qt3DCore::QTranslateTransform *m_translate; QParameter *m_textureParameter; QTextureImage *m_posXImage; QTextureImage *m_posYImage; diff --git a/src/render/frontend/qboundingvolumedebug.cpp b/src/render/frontend/qboundingvolumedebug.cpp index 029f42272..e31897265 100644 --- a/src/render/frontend/qboundingvolumedebug.cpp +++ b/src/render/frontend/qboundingvolumedebug.cpp @@ -40,8 +40,6 @@ #include <Qt3DCore/qbackendscenepropertychange.h> #include <Qt3DRender/qspheremesh.h> #include <Qt3DCore/qtransform.h> -#include <Qt3DCore/qtranslatetransform.h> -#include <Qt3DCore/qscaletransform.h> #include <Qt3DRender/qphongalphamaterial.h> #include <Qt3DRender/qlayer.h> @@ -60,7 +58,6 @@ public: , m_debugSubtree(Q_NULLPTR) , m_sphereMesh(Q_NULLPTR) , m_transform(Q_NULLPTR) - , m_translate(Q_NULLPTR) , m_material(Q_NULLPTR) , m_layer(Q_NULLPTR) , m_bvRadius(0.0f) @@ -74,8 +71,6 @@ public: Qt3DCore::QEntity *m_debugSubtree; Qt3DRender::QSphereMesh *m_sphereMesh; Qt3DCore::QTransform *m_transform; - Qt3DCore::QTranslateTransform *m_translate; - Qt3DCore::QScaleTransform *m_scale; Qt3DRender::QMaterial *m_material; Qt3DRender::QLayer *m_layer; @@ -152,9 +147,7 @@ void QBoundingVolumeDebugPrivate::updateSubtree() m_debugSubtree = new Qt3DCore::QEntity(); m_sphereMesh = new Qt3DRender::QSphereMesh(); m_transform = new Qt3DCore::QTransform(); - m_translate = new Qt3DCore::QTranslateTransform(); m_material = new Qt3DRender::QPhongAlphaMaterial(); - m_scale = new Qt3DCore::QScaleTransform(); m_layer = new Qt3DRender::QLayer(); static_cast<QPhongAlphaMaterial *>(m_material)->setAlpha(0.3); @@ -162,15 +155,13 @@ void QBoundingVolumeDebugPrivate::updateSubtree() m_layer->setNames(QStringList() << QStringLiteral("debug")); - m_transform->addTransform(m_scale); - m_transform->addTransform(m_translate); m_debugSubtree->addComponent(m_sphereMesh); m_debugSubtree->addComponent(m_transform); m_debugSubtree->addComponent(m_material); m_debugSubtree->addComponent(m_layer); - m_translate->setTranslation(m_bvCenter); - m_scale->setScale(m_bvRadius * 2.0f); + m_transform->setTranslation(m_bvCenter); + m_transform->setScale(m_bvRadius * 2.0f); m_sphereMesh->setRadius(0.5f); m_sphereMesh->setRings(100); m_sphereMesh->setSlices(100); @@ -182,8 +173,8 @@ void QBoundingVolumeDebugPrivate::updateSubtree() } } else { // Just update the mesh - m_translate->setTranslation(m_bvCenter); - m_scale->setScale(m_bvRadius * 2.0f); + m_transform->setTranslation(m_bvCenter); + m_transform->setScale(m_bvRadius * 2.0f); } } |