summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2017-10-05 14:26:26 +0100
committerSean Harmer <sean.harmer@kdab.com>2017-10-05 14:26:26 +0100
commite743158b0b17335ef321c2c378bacfe2697ba5f1 (patch)
treeaadf16da9ddc60ce0b2e84c1b0777e87f9cd080e
parentd4fb24c0871320667640f100b743f34f702db6cf (diff)
parent835db3b72e0f14ef80afb22dd084bfc038383481 (diff)
Merge branch '5.9' into 5.10
Conflicts: src/animation/backend/animationutils.cpp Change-Id: I6bd0d1d15da00537a0bb064fc828b2460584b8e8
-rw-r--r--src/animation/backend/animationutils.cpp54
-rw-r--r--src/animation/backend/fcurve_p.h25
-rw-r--r--tests/manual/bigscene-cpp/entity.cpp33
-rw-r--r--tests/manual/bigscene-cpp/entity.h14
-rw-r--r--tests/manual/bigscene-cpp/main.cpp30
5 files changed, 109 insertions, 47 deletions
diff --git a/src/animation/backend/animationutils.cpp b/src/animation/backend/animationutils.cpp
index d05d96f38..3e255308b 100644
--- a/src/animation/backend/animationutils.cpp
+++ b/src/animation/backend/animationutils.cpp
@@ -148,6 +148,17 @@ double phaseFromGlobalTime(double t_global, double t_start_global,
return t_local / duration;
}
+/*!
+ \internal
+
+ Calculates the indices required to map from the component ordering within the
+ provided \a channel, into the standard channel orderings expected by Qt types.
+
+ For example, given a channel representing a rotation with the components ordered
+ as X, Y, Z, Y, this function will return the indices [3, 0, 1, 2] which can then
+ later be used as part of the format vector in the formatClipResults() function to
+ remap the channels into the standard W, X, Y, Z order required by QQuaternion.
+*/
ComponentIndices channelComponentsToIndices(const Channel &channel, int dataType, int offset)
{
#if defined Q_COMPILER_UNIFORM_INIT
@@ -171,9 +182,9 @@ ComponentIndices channelComponentsToIndices(const Channel &channel, int dataType
}
ComponentIndices channelComponentsToIndicesHelper(const Channel &channel,
- int dataType,
- int offset,
- const QVector<char> &suffixes)
+ int dataType,
+ int offset,
+ const QVector<char> &suffixes)
{
const int expectedComponentCount = componentsForType(dataType);
const int actualComponentCount = channel.channelComponents.size();
@@ -183,21 +194,37 @@ ComponentIndices channelComponentsToIndicesHelper(const Channel &channel,
}
ComponentIndices indices(expectedComponentCount);
+
+ // Generate the set of channel suffixes
+ QVector<char> channelSuffixes;
+ channelSuffixes.reserve(expectedComponentCount);
for (int i = 0; i < expectedComponentCount; ++i) {
const QString &componentName = channel.channelComponents[i].name;
+
// An unset component name indicates that the no mapping is necessary
// and the index can be used as-is.
if (componentName.isEmpty()) {
indices[i] = i + offset;
continue;
}
- char suffix = componentName.at(componentName.length() - 1).toLatin1();
- int index = suffixes.indexOf(suffix);
+
+ char channelSuffix = componentName.at(componentName.length() - 1).toLatin1();
+ channelSuffixes.push_back(channelSuffix);
+ }
+
+ // We can short-circuit if the channels were all unnamed (in order)
+ if (channelSuffixes.isEmpty())
+ return indices;
+
+ // Find index of standard index in channel indexes
+ for (int i = 0; i < expectedComponentCount; ++i) {
+ int index = channelSuffixes.indexOf(suffixes[i]);
if (index != -1)
indices[i] = index + offset;
else
indices[i] = -1;
}
+
return indices;
}
@@ -642,16 +669,14 @@ ComponentIndices generateClipFormatIndices(const QVector<ChannelNameAndType> &ta
const int componentCount = targetIndices[i].size();
if (clipChannelIndex != -1) {
- // Found a matching channel in the clip. Get the base channel
- // component index and populate the format indices for this channel.
+ // Found a matching channel in the clip. Populate the corresponding
+ // entries in the format vector with the *source indices*
+ // needed to build the formatted results.
const int baseIndex = clip->channelComponentBaseIndex(clipChannelIndex);
-
- // Within this group, match channel names with index ordering
const auto channelIndices = channelComponentsToIndices(clip->channels()[clipChannelIndex],
targetChannel.type,
baseIndex);
std::copy(channelIndices.begin(), channelIndices.end(), formatIt);
-
} else {
// No such channel in this clip. We'll use default values when
// mapping from the clip to the formatted clip results.
@@ -673,11 +698,16 @@ ClipResults formatClipResults(const ClipResults &rawClipResults,
ClipResults formattedClipResults(elementCount);
// Perform a gather operation to format the data
+
// TODO: For large numbers of components do this in parallel with
// for e.g. a parallel_for() like construct
+ // TODO: We could potentially avoid having holes in these intermediate
+ // vectors by adjusting the component indices stored in the MappingData
+ // and format vectors. Needs careful investigation!
for (int i = 0; i < elementCount; ++i) {
- const float value = format[i] != -1 ? rawClipResults[format[i]] : 0.0f;
- formattedClipResults[i] = value;
+ if (format[i] == -1)
+ continue;
+ formattedClipResults[i] = rawClipResults[format[i]];
}
return formattedClipResults;
diff --git a/src/animation/backend/fcurve_p.h b/src/animation/backend/fcurve_p.h
index f2148d1e9..8c5cdd54d 100644
--- a/src/animation/backend/fcurve_p.h
+++ b/src/animation/backend/fcurve_p.h
@@ -98,14 +98,27 @@ private:
inline QDebug operator<<(QDebug dbg, const FCurve &fcurve)
{
QDebugStateSaver saver(dbg);
- dbg << "Keyframe Count =" << fcurve.keyframeCount() << endl;
+ dbg << "Keyframe Count = " << fcurve.keyframeCount() << endl;
for (int i = 0; i < fcurve.keyframeCount(); ++i) {
const Keyframe &kf = fcurve.keyframe(i);
- dbg << "t =" << fcurve.localTime(i)
- << "value =" << kf.value
- << "leftHandle =" << kf.leftControlPoint
- << "rightHandle =" << kf.rightControlPoint
- << endl;
+ switch (kf.interpolation) {
+ case QKeyFrame::BezierInterpolation: {
+ dbg << "t = " << fcurve.localTime(i)
+ << ", value = " << kf.value
+ << ", leftHandle = " << kf.leftControlPoint
+ << ", rightHandle = " << kf.rightControlPoint
+ << endl;
+ break;
+ }
+
+ case QKeyFrame::ConstantInterpolation:
+ case QKeyFrame::LinearInterpolation: {
+ dbg << "t = " << fcurve.localTime(i)
+ << ", value = " << kf.value
+ << endl;
+ break;
+ }
+ }
}
return dbg;
}
diff --git a/tests/manual/bigscene-cpp/entity.cpp b/tests/manual/bigscene-cpp/entity.cpp
index 9a4ecae3b..876a2d171 100644
--- a/tests/manual/bigscene-cpp/entity.cpp
+++ b/tests/manual/bigscene-cpp/entity.cpp
@@ -51,22 +51,21 @@
#include "entity.h"
#include <Qt3DExtras/QCylinderMesh>
-#include <Qt3DExtras/QPhongMaterial>
+#include <Qt3DRender/QMaterial>
+#include <Qt3DRender/QParameter>
#include <Qt3DCore/QTransform>
#include <QMatrix4x4>
-Entity::Entity(Qt3DCore::QNode *parent)
+Entity::Entity(Qt3DRender::QEffect *effect, Qt3DCore::QNode *parent)
: QEntity(parent)
, m_transform(new Qt3DCore::QTransform())
- , m_mesh(new Qt3DExtras::QCylinderMesh())
- , m_material(new Qt3DExtras::QPhongMaterial())
+ , m_material(new Qt3DRender::QMaterial())
+ , m_diffuseColorParam(new Qt3DRender::QParameter())
{
- m_mesh->setRings(50.0f);
- m_mesh->setSlices(30.0f);
- m_mesh->setRadius(2.5f);
- m_mesh->setLength(5.0f);
+ m_diffuseColorParam->setName(QLatin1String("kd"));
+ m_material->addParameter(m_diffuseColorParam);
+ m_material->setEffect(effect);
- addComponent(m_mesh);
addComponent(m_transform);
addComponent(m_material);
}
@@ -97,26 +96,30 @@ QVector3D Entity::position() const
QColor Entity::diffuseColor() const
{
- return m_material->diffuse();
+ return m_diffuseColorParam->value().value<QColor>();
}
void Entity::setTheta(float theta)
{
- if (m_theta == theta)
+ if (qFuzzyCompare(m_theta, theta))
return;
m_theta = theta;
+ const bool wasBlocked = blockNotifications(true);
emit thetaChanged(theta);
+ blockNotifications(wasBlocked);
updateTransform();
}
void Entity::setPhi(float phi)
{
- if (m_phi == phi)
+ if (qFuzzyCompare(m_phi, phi))
return;
m_phi = phi;
+ const bool wasBlocked = blockNotifications(true);
emit phiChanged(phi);
+ blockNotifications(wasBlocked);
updateTransform();
}
@@ -132,9 +135,11 @@ void Entity::setPosition(QVector3D position)
void Entity::setDiffuseColor(QColor diffuseColor)
{
- if (m_material->diffuse() == diffuseColor)
+ if (m_diffuseColorParam->value().value<QColor>() == diffuseColor)
return;
- m_material->setDiffuse(diffuseColor);
+ m_diffuseColorParam->setValue(QVariant::fromValue(diffuseColor));
+ const bool wasBlocked = blockNotifications(true);
emit diffuseColorChanged(diffuseColor);
+ blockNotifications(wasBlocked);
}
diff --git a/tests/manual/bigscene-cpp/entity.h b/tests/manual/bigscene-cpp/entity.h
index 04dcbbcb3..656511cdc 100644
--- a/tests/manual/bigscene-cpp/entity.h
+++ b/tests/manual/bigscene-cpp/entity.h
@@ -61,9 +61,11 @@ namespace Qt3DCore {
class QTransform;
}
-namespace Qt3DExtras {
-class QCylinderMesh;
-class QPhongMaterial;
+namespace Qt3DRender {
+class QEffect;
+class QGeometryRenderer;
+class QMaterial;
+class QParameter;
}
QT_END_NAMESPACE
@@ -77,7 +79,7 @@ class Entity : public Qt3DCore::QEntity
Q_PROPERTY(QColor diffuseColor READ diffuseColor WRITE setDiffuseColor NOTIFY diffuseColorChanged)
public:
- Entity(Qt3DCore::QNode *parent = 0);
+ Entity(Qt3DRender::QEffect *effect, Qt3DCore::QNode *parent = 0);
float theta() const;
float phi() const;
@@ -101,8 +103,8 @@ private:
private:
Qt3DCore::QTransform *m_transform;
- Qt3DExtras::QCylinderMesh *m_mesh;
- Qt3DExtras::QPhongMaterial *m_material;
+ Qt3DRender::QMaterial *m_material;
+ Qt3DRender::QParameter *m_diffuseColorParam;
float m_theta;
float m_phi;
QVector3D m_position;
diff --git a/tests/manual/bigscene-cpp/main.cpp b/tests/manual/bigscene-cpp/main.cpp
index 791aeb19d..ef296e04d 100644
--- a/tests/manual/bigscene-cpp/main.cpp
+++ b/tests/manual/bigscene-cpp/main.cpp
@@ -81,6 +81,17 @@ int main(int ac, char **av)
QEntity *root = new QEntity();
+ // Mesh
+ auto *mesh = new Qt3DExtras::QCylinderMesh(root);
+ mesh->setRings(50.0f);
+ mesh->setSlices(30.0f);
+ mesh->setRadius(2.5f);
+ mesh->setLength(5.0f);
+
+ // Material
+ auto phongMaterial = new Qt3DExtras::QPhongMaterial(root);
+ auto effect = phongMaterial->effect();
+
// Camera
QCamera *cameraEntity = view.camera();
cameraEntity->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 1000.0f);
@@ -92,17 +103,20 @@ int main(int ac, char **av)
Qt3DExtras::QFirstPersonCameraController *camController = new Qt3DExtras::QFirstPersonCameraController(root);
camController->setCamera(cameraEntity);
- const float radius = 100.0f;
+ const double radius = 100.0;
const int max = 1000;
- const float det = 1.0f / max;
+ const double det = 1.0 / max;
// Scene
for (int i = 0; i < max; i++) {
- Entity *e = new Entity();
- const float angle = M_PI * 2.0f * i * det * 10.;
-
- e->setDiffuseColor(QColor(qFabs(qCos(angle)) * 255, 204, 75));
- e->setPosition(QVector3D(radius * qCos(angle), -200.* i * det, radius * qSin(angle)));
+ Entity *e = new Entity(effect, root);
+ e->addComponent(mesh);
+ const double angle = M_PI * 2.0 * double(i) * det * 10.;
+
+ e->setDiffuseColor(QColor(int(qFabs(qCos(angle)) * 255.0), 204, 75));
+ e->setPosition(QVector3D(float(radius * qCos(angle)),
+ float(-200.0 * i * det),
+ float(radius * qSin(angle))));
e->setTheta(30.0f * i);
e->setPhi(45.0f * i);
@@ -119,8 +133,6 @@ int main(int ac, char **av)
animZ->setEndValue(QVariant::fromValue((i + 1) * 380.0f));
animZ->setLoopCount(-1);
animZ->start();
-
- e->setParent(root);
}
view.setRootEntity(root);